久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

MAC OS X Cocoa NSToolbar 的使用

瀏覽:115日期:2024-07-23 13:36:36

//向NSToolbar控件添加自定義的NSToolbarItem項(xiàng) - (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: SquareDotViewItemIdentifier]) { 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 setPaletteLabel: @'A Dot View']; [toolbarItem setToolTip: @'This is a dot view']; } ..... } //返回單擊后能被選中且為高亮顯示的NSToolbarItem的集合。 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar {// return an array of all the items that can be highlight display after selected return [NSArray arrayWithObjects: NSColorToolbarItemIdentifier, NSFontToolbarItemIdentifier,nil]; } //返回程序加載后的默認(rèn)的NSToolbarItem的集合。 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar { // return an array of the items found in the default toolbar return [NSArray arrayWithObjects: NSToolbarSeparatorItemIdentifier, NSFontToolbarItemIdentifier, NSToolbarCustomizeToolbarItemIdentifier, nil]; } //以下是作為NSToolbarItem出現(xiàn)的自定義類(lèi) The 'SquareDotView' class:

@interface SquareDotView : NSView { @private float sdSide; NSPoint sdLocation; } @end

@implementation 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)initWithCoder:(NSCoder *)coder { self = [super initWithCoder: coder]; if (self) { [coder decodeValuesOfObjCTypes: 'fff', &sdSide, &sdLocation.x, &sdLocation.y]; } return self; }

- (void)encodeWithCoder:(NSCoder *)coder { [super encodeWithCoder: coder]; if (self) { [coder encodeValuesOfObjCTypes: 'fff', &sdSide, &sdLocation.x, &sdLocation.y]; } }

@end

標(biāo)簽: Mac OS系統(tǒng)
主站蜘蛛池模板: 封开县| 道真| 金堂县| 绥德县| 广昌县| 浦东新区| 临沭县| 柏乡县| 敖汉旗| 磐石市| 黄山市| 安国市| 麻栗坡县| 石阡县| 武鸣县| 沭阳县| 大厂| 祁东县| 灌南县| 云龙县| 连江县| 铜陵市| 哈尔滨市| 永寿县| 商都县| 和静县| 吉林省| 望奎县| 栖霞市| 紫金县| 竹北市| 庄河市| 阿克| 房山区| 叶城县| 依安县| 东乌珠穆沁旗| 云龙县| 同江市| 达日县| 隆子县|