NSWindow States
NSWindow States
- Subject: NSWindow States
- From: Dimitri Bouniol <email@hidden>
- Date: Wed, 7 Jun 2006 19:06:29 -0700
I have an object that is the delegate of a window. I use the delegate
methods:
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
[statusBarView setWindowIsKey:[[aNotification object] isKeyWindow]];
[statusBarView setWindowIsMain:[[aNotification object] isMainWindow]];
}
- (void)windowDidBecomeMain:(NSNotification *)aNotification
{
[statusBarView setWindowIsKey:[[aNotification object] isKeyWindow]];
[statusBarView setWindowIsMain:[[aNotification object] isMainWindow]];
}
- (void)windowDidResignKey:(NSNotification *)aNotification
{
[statusBarView setWindowIsKey:[[aNotification object] isKeyWindow]];
[statusBarView setWindowIsMain:[[aNotification object] isMainWindow]];
}
- (void)windowDidResignMain:(NSNotification *)aNotification
{
[statusBarView setWindowIsKey:[[aNotification object] isKeyWindow]];
[statusBarView setWindowIsMain:[[aNotification object] isMainWindow]];
}
To update a view (statusBarView) so it could show the corresponding
image for the window's state (key, main and inactive) so it is the
same as the title bar.
In my statusBarView, I have the following for drawRect: :
- (void)drawRect:(NSRect)rect
{
NSRect bounds = [self bounds];
NSImage *statusImage;
if ([self windowIsKey]) {
statusImage = [NSImage imageNamed:@"StatusBarBackingKey"];
} else if ([self windowIsMain]) {
statusImage = [NSImage imageNamed:@"StatusBarBackingMain"];
} else {
statusImage = [NSImage imageNamed:@"StatusBarBacking"];
}
[statusImage drawInRect:bounds fromRect:NSMakeRect(0.0, 0.0, 10.0,
20.0) operation:NSCompositeSourceOver fraction:1.0];
NSLog(@"key: %d; main %d", [self windowIsKey], [self windowIsMain]);
}
Everything works as expected, until I control clicked the dock icon
to get a menu. NSLog() reported that 'key: 0; main 1' (which should
make the title bar white-ish) even thought the window's title bar
didn't change color. Is there another way to check the window's state
other than isKeyWindow and isMainWindow ?
--
Dimitri Bouniol
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden