Using font panel in NSObject subclass


- (void)sharedFontPanel
{
    theFontPanel = [[NSFontManager sharedFontManager] fontPanel:YES];
}

- (void)awakeFromNib
{
    [[NSFontManager sharedFontManager] setDelegate:self];
    [self performSelectorOnMainThread:@selector(sharedFontPanel) withObject:nil
                                            waitUntilDone:YES];
    [theFontPanel setDelegate:self];
    [theFontPanel setBecomesKeyOnlyIfNeeded:NO];
}

- (IBAction)ShowFontPanel:(id)sender
{
    [theFontPanel orderFront:sender];
}

- (void)changeFont:(id)sender
{
    NSLog(@"changeFont");
}

Blogged with the Flock Browser

Tags: , , , , , ,

Advertisements

How to get the current user name?

Cocoa :
NSUserName();

C :
int userid = geteuid();
struct passwd *userst= getpwuid(userid);
userst->pw_name;

Blogged with the Flock Browser

Tags: , , , , , ,

Posted in COcoa, MAc. 1 Comment »

What is different about NIB loading in a Cocoa Touch application

Top level NIB objects are auto-released. (In Mac OS X, top levels objects are retained by default, and hence must be released explicitly on that platform.)

Outlets are set using the setValue:forKey: method. This method retains outlets automatically, so if you use it, you must release those outlets in the object’s dealloc method.

The awakeFromNib message is sent to each object that was created as a side effect of loading the nib. This means that on the iPhone OS File’s Owner and other proxy objects do not receive this message. Please refer to the CocoaTouch or Cocoa documentation for a complete list of methods available for configuring your UI objects after NIB loading has occurred.

Blogged with the Flock Browser

Tags: , , , , , , ,

Posted in iPHone. 1 Comment »

How to popup context menu when clicked on button.

    NSRect frame = [(NSButton *)sender frame];
    NSPoint menuOrigin = [[(NSButton *)sender superview] convertPoint:NSMakePoint(frame.origin.x, frame.origin.y+frame.size.height+40)
                                                               toView:nil];

    NSEvent *event =  [NSEvent mouseEventWithType:NSLeftMouseDown
                                         location:menuOrigin
                                    modifierFlags:NSLeftMouseDownMask // 0x100
                                        timestamp:nil
                                     windowNumber:[[
(NSButton *)sender window] windowNumber]
                                          context:[[
(NSButton *)sender window] graphicsContext]
                                      eventNumber:0
                                       clickCount:1
                                         pressure:1];
   
    NSMenu *menu = [[NSMenu alloc] init];
    [menu insertItemWithTitle:@"add"
                       action:@selector(add:)
                keyEquivalent:@""
                      atIndex:0];

    [NSMenu popUpContextMenu:menu withEvent:event forView:(NSButton *)sender];

Blogged with the Flock Browser

Tags: , , , , ,

Posted in COcoa. 2 Comments »

Why Byte Ordering Matters

The byte ordering of multibyte data in memory matters if you are reading data written on one architecture from a system that uses a different architecture and you access the data on a byte-by-byte basis. For example, if your application is written to access the second byte of the myOptions variable, then when you read the data from a system that uses the opposite byte ordering scheme, you’ll end up retrieving the first byte of the myOptions variable instead of the second one.

Network-Related Data
Network-related data typically uses big-endian format (also known as network byte order), so you may need to swap bytes when communicating between the network and an Intel-based Macintosh computer. You probably never had to adjust your PowerPC code when you transmitted data to, or received data from, the network. On an Intel-based Macintosh computer you must look closely at your networking code and ensure that you always send network-related data in the appropriate byte order. You must also handle data received from the network appropriately, swapping the bytes of values to the endian format appropriate to the host microprocessor.

You can use the following POSIX functions to convert between network byte order and host byte order. (Other byte-swapping functions, such as those defined in the OSByteOrder.h and CFByteOrder.h header files, can also be useful for handling network data.)

network to host:
uint32_t ntohl (uint32_t netlong);

uint16_t ntohs (uint16_t netshort);
host to network:
uint32_t htonl (uint32_t hostlong);

uint16_t htons (uint16_t hostshort);

These functions are documented in Mac OS X Man Pages.

Blogged with the Flock Browser

Tags: , , , , , , , , , ,