当前位置: 首页 > 学习 > 电脑学习 > 操作系统 > MacOSX > 技巧教程 > 正文

MAC OS X Cocoa NSToolbar 的使用

http://www.zk168.com.cn  招考学习网 2006-2-28 21:48:18
-----------------------------------------------------------[交流]-[打印]-[发送]-[收藏]--

//向NSToolbar控件添加自定义的NSToolbarItem项
- (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];
}

//返回程序加载后的默认的NSToolbarItem的集合。
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{ // return an array of the items found in the default toolbar
return [NSArray arrayWithObjects:
NSToolbarSeparatorItemIdentifier,
NSFontToolbarItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
nil];
}


//以下是作为NSToolbarItem出现的自定义类
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

-----------------------------------------------------------[交流]-[打印]-[发送]-[收藏]--
最新入库:
 
·国外生活必备的英文词汇
·实用生活英语句子 174句
·唬老外的常用赞誉之辞语
·日常生活中商店译名参考
·在美生存常用习语
·实用生活英语二十六句
·年轻人常用口头禅
·去银行会用到的十句话
·中国文化的艺术精神_语言教育
·论苏拭的现实主义词风_语言教育
相关内容:
 
·大众传媒·大众文化·文化危机——丹
·知美·好美·乐美—谈美育的三个境界
·English Language: American or British?_语言教育
·How to improve the ability of listening, speaking,
·AN ANALYSIS OF LANGUAG_语言教育
·Published by the Corco_语言教育
·Language and Culture_语言教育
·教育与education探源_语言教育
·开口ABC 之 挑选礼物_语言教育
·闻言察意说CET听力_语言教育
网友点评:
 
会员名称:
密码:匿名 ·注册·忘记密码?
评论内容:
(最多300个字符)
  查看评论
友情提醒:
 1.库中的资料大都来自互联网、网友上传、各类书籍,在录入的过程中难免会出现错误,恳请网
 友来信指正!
 2.如果网友在本库中未能找到所需要的材料,请登陆到我们的论坛《招考学习网》版块!
 3.考友想加入招考学习网的编辑部,请发信到XueXiWang#Gmail.com(#改为@)附带个人简历
 4.如需转载请注明出处及作者,谢谢合作!
 5.如果您有更好的建议或意见请EMAIL:XueXiWang#Gmail.com (#改为@)
 6.凡标题中有注有“[NO]”字样均不含答案且答案整理中.
 7.如本库中转载文章涉及版权等问题,请相关网站或作者在两周内发邮件通知(EMAIL:  XueXiWang#Gmail.com (#改为@))我们,我们接到通知后立即删除该文章及链接!
你问我答 更多>>