Re: Title bar on left of Panel
Re: Title bar on left of Panel
- Subject: Re: Title bar on left of Panel
- From: Guy English <email@hidden>
- Date: Wed, 3 Oct 2007 18:58:10 -0400
Do not do what follows. It's evil. It works. But it's evil.
-------------------
@interface MyLeftAlignedTitleTextFieldCell : NSTextFieldCell
// do not add any ivars. not even a little tiny one. really. we class
swizzle this in and if you do add an ivar you'll regret it.
@end
@implementation MyLeftAlignedTitleTextFieldCell
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView
*)controlView
{
NSColor *textColor;
if ( [[controlView window] isMainWindow] )
{
textColor = [NSColor blackColor];
}
else
{
textColor = [NSColor disabledControlTextColor];
}
NSRect frame = [self titleRectForBounds: cellFrame];
NSButton *zoomButton =[[controlView window] standardWindowButton:
NSWindowZoomButton];
if ( zoomButton )
{
frame.origin.x = NSMaxX( [zoomButton frame] );
}
frame.origin.x += 6; // just some padding
frame.origin.y -= 1;
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
textColor, NSForegroundColorAttributeName,
[NSFont titleBarFontOfSize: 0], NSFontAttributeName,
nil];
[[self stringValue] drawInRect: frame withAttributes: attrs];
}
@end
// somewhere early in your startup code but after the nib has been
loaded.
// here we have a cascade of evil, each step nuttier than the one
before.
if ( [theWindow respondsToSelector: @selector( _borderView )] )
{
if ( [[(id) theWindow _borderView] respondsToSelector:
@selector( titleCell )] )
{
if ( [[(id)[(id) theWindow _borderView] titleCell] isKindOfClass:
[NSTextFieldCell class]] )
{
[(id)[(id) theWindow _borderView] titleCell]->isa =
[MyLeftAlignedTitleTextFieldCell class]; // yikes!
}
}
}
Later,
Guy
_______________________________________________
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