• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE:Window title bar accessory view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE:Window title bar accessory view


  • Subject: RE:Window title bar accessory view
  • From: "email@hidden" <email@hidden>
  • Date: Wed, 19 Nov 2008 15:12:39 +0000

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


  • Prev by Date: Re: How to get notification of rerun application
  • Next by Date: Programmatic NSTableView selection changes
  • Previous by thread: Re: Window title bar accessory view
  • Next by thread: NSArrayController - Remove all objects?
  • Index(es):
    • Date
    • Thread