RE:Window title bar accessory view
RE:Window title bar accessory view
There is already some info in the list on this.
http://www.cocoabuilder.com/archive/message/cocoa/2004/11/11/121369
The following can be added to an NSWindow category
/*
window toolbar height
*/
- (float) toolbarHeight
{
return NSHeight([NSWindow contentRectForFrameRect:[self frame]
styleMask:[self styleMask]]) NSHeight([[self contentView] frame]);
}
/*
window title bar height
*/
- (float) titleBarHeight
{
return NSHeight([self frame]) -
NSHeight([[self contentView] frame]) -
[self toolbarHeight];
}
#define kIconSpacing 8.0 // h-space between the icon and the toolbar
button
/*
add icon to toolbar
*/
- (NSImageView*) addIconToTitleBar:(NSImage*) icon
{
id superview = [[self standardWindowButton:NSWindowToolbarButton]
superview];
// assume toolbarbutton present
NSRect toolbarButtonFrame = [[self
standardWindowButton:NSWindowToolbarButton] frame];
NSRect iconFrame;
iconFrame.size = [icon size];
iconFrame.origin.y = NSMaxY([superview frame]) -
(iconFrame.size.height + ceil(([self titleBarHeight] -
iconFrame.size.height) / 2.0));
iconFrame.origin.x = NSMinX(toolbarButtonFrame) -
iconFrame.size.width -
kIconSpacing;
NSImageView* iconView = [[[NSImageView alloc]
initWithFrame:iconFrame]
autorelease];
[iconView setImage:icon];
[iconView setEditable:NO];
[iconView setImageFrameStyle:NSImageFrameNone];
[iconView setImageScaling:NSScaleNone];
[iconView setImageAlignment:NSImageAlignCenter];
[iconView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
[superview addSubview:iconView];
return iconView;
}
/*
add icon to toolbar
*/
- (void) addViewToTitleBar:(NSView*)view xoffset:(CGFloat)xoffset
{
id superview = [[self standardWindowButton:NSWindowToolbarButton]
superview];
NSRect toolbarButtonFrame = [[self
standardWindowButton:NSWindowToolbarButton] frame];
NSRect iconFrame;
iconFrame.size = [view bounds].size;
iconFrame.origin.y = NSMaxY([superview frame]) -
(iconFrame.size.height + ceil(([self titleBarHeight] -
iconFrame.size.height) / 2.0));
iconFrame.origin.x = NSMinX(toolbarButtonFrame) -
iconFrame.size.width - kIconSpacing;
if (xoffset > 0) {
iconFrame.origin.x -= (xoffset + kIconSpacing);
}
[view setFrame:iconFrame];
[view setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
[superview addSubview:view];
return;
}
Jonathan Mitchell
Central Conscious Unit
http://www.mugginsoft.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden