Mac OS X Cocoa Nstoolbar

xiaoxiao2021-03-06  14

// add custom items to NSToolbarItem NSToolbar Control - (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar: (BOOL) willBeInserted {// Required delegate method Given an item identifier, self method returns an item // The toolbar will use self method to obtain toolbar items that can be displayed in the customization sheet, or in the toolbar itself NSToolbarItem * toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];

IF ([Itemident ISEQUAL: SQUAREDOTVIEWIDENTINDENTIFIER]) {SquareDotView * DV = [[SquareDotView Alloc] INITWITHFRAME: NSMAKERECT (0,0,100,32)];

[ToolbarItem SetView: DV];

// set a reasonable minimum size [ToolbarItem SetMinsize: NSMakeSize (100, 32)]; // set a maximum size That Allows US to Stretch. [ToolbarItem SetMaxSize: NSMakeSize (300, 32)];

[ToolbarItem setLabel: @ "dot view"]; [ToolbarItem set "]; [ToolbarItem SetTooltip: @" this is a dot view "];} .....} // Return Click Can be selected and a collection of NSToolBarItem that is highlighted. - (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar {// return an array of all the items that can be highlight display after selected return [NSArray arrayWithObjects: NSColorToolbarItemIdentifier, NSFontToolbarItemIdentifier, nil];} // default return to the program after loading Collection of NSTOOLBARITEMs. - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {// return an array of the items found in the default toolbar return [NSArray arrayWithObjects: NSToolbarSeparatorItemIdentifier, NSFontToolbarItemIdentifier, NSToolbarCustomizeToolbarItemIdentifier, nil];} // The following are occurring from a NSToolbarItem Define class The "SquareDotView" Class:

@Interface SquareDotView: nsview {@Private float sdside; nspoint squartion;} @ End @Mplementation SquareDotView

#define start_side 10 # define start_location nsmakepoint (10, 10)

- (ID) INITWITHFRAME: (NSRECT) frame {self = [super initwithframe: frame]; if (self) {sdside = start_side; sdlocation = start_location;} return self;}

- (void) mousedown: (nsevent *) Theevent {sdlocation = [Self ConvertPoint: [TheEvent locationinwindow] fromview: nil]; [Self setneedsdisplay: yes];}

- (void) DrawRect: (nSRECT) Rect {[NSColor RedColor] set]; [NSBezierPath BezierPathwithRect: nsmakerect (sdlocation.x, sdlocation.y, sdside, sdside) fill];

[[NSCOLOR BlackColor] set]; [[NSBezierPath BezierPathwithRect: [Self Bounds]] stroke];

- (ID) INITWIDER: (nscoder *) CODER {Self = [Super INITWITWIDER: CODER]; if (self) {[CODER DECODEVALUESOBJCTYPES: "FFF", & SDSIDE, & SDLOCATION.x, & SDLocation.y];} Return Self;

- (void) EncodeWithcoder: (nscoder *) CODER {[Super EncodeWithcoder: CODER]; if (self) {[CODER EncodeValeSofobjctypes: "FFF", & SDSIDE, & SDLocation.x, & SDLocation.y];}

@end

转载请注明原文地址:https://www.9cbs.com/read-50864.html

New Post(0)