> I need to get notifications for 2 events for a NSwindow.
> How do I set up the notification manager to get "application became active"
> and "window was resized"?
> > I need to get notifications for 2 events for a NSwindow.
> > How do I set up the notification manager to get "application became active"
[quoted text clipped - 40 lines]
> NSApplicationDidBecomeActiveNotification. for that second one, you wouldn't
> need to use anything for the "object:" parameter, you could leave it nil.
it's still not working...
in initialize routine I have:
myNotificationCenter = [NSNotificationCenter defaultCenter];
the routines are:
-(void)initReqsWindow;
{
reqswindow = [[NSWindow alloc] initWithContentRect: reqswindowlocation styleMask: (NSTitledWindowMask | NSResizableWindowMask) backing: NSBackingStoreBuffered defer: NO screen: [myScreens objectAtIndex: reqswindowscreen]];
[reqswindow setTitle: @"Reqs"];
reqsdata = [[NSTextView alloc] initWithFrame: NSMakeRect(20, 20, reqswindowlocation.size.width-40, reqswindowlocation.size.height-40)];
NSView *reqswindowview = [reqswindow contentView];
[reqswindowview addSubview: reqsdata];
[reqsdata setString: @"Reqs data here!"];
[reqsdata setSelectable: YES];
[reqsdata setEditable: NO];
[reqsdata setRichText: NO];
[reqsdata setBackgroundColor: [NSColor whiteColor]];
[reqsdata setTextColor: [NSColor blackColor]];
[reqsdata setFont: [NSFont userFixedPitchFontOfSize: windowFontSize]];
[reqsdata sizeToFit];
[reqswindow setViewsNeedDisplay: YES];
[reqswindow makeKeyAndOrderFront: self];
[reqswindow display];
[reqswindowview display];
[reqsdata display];
[openAndCloseReqsWindowItem setState: NSOnState];
[myNotificationCenter addObserver: self selector: @selector(activateReqsWindow:) name: NSApplicationWillBecomeActiveNotification object: nil];
[myNotificationCenter addObserver: self selector: @selector(activateReqsWindow:) name: NSWindowDidResizeNotification object: reqswindow];
};
-(void)activateReqsWindow: (id) myobject;
{
[reqsdata setFrame: NSMakeRect(20, 20, reqswindowlocation.size.width-40, reqswindowlocation.size.height-40)];
[reqswindow display];
[reqsdata display];
};
-(void)openAndCloseReqsWindow: (id) menu;
{
NSMenuItem *myLocalMenuItem = menu;
if (reqswindowvisible)
{
reqswindowvisible = NO;
reqswindowlocation = [reqswindow frame];
reqswindowlocation.size.height = reqswindowlocation.size.height-22;
[myNotificationCenter removeObserver: self name: NSApplicationWillBecomeActiveNotification object: reqswindow];
[myNotificationCenter removeObserver: self name: NSWindowDidResizeNotification object: reqswindow];
[reqswindow close];
}
else
{
reqswindowvisible = YES;
[self initReqsWindow];
}
if (reqswindowvisible)
{
[myLocalMenuItem setState: NSOnState];
}
else
{
[myLocalMenuItem setState: NSOffState];
}
[self saveprefs];
};
Allen Brunson - 26 Sep 2005 02:37 GMT
> it's still not working...
i don't see anything obviously wrong in the code, except that there's no need
to cache a pointer to the default NSNotificationCenter. global and instance
variables are just one more thing to keep track of, and any that can be
eliminated, should be.
also, this is wrong:
[myNotificationCenter removeObserver: self name:
NSApplicationWillBecomeActiveNotification object: reqswindow];
because you used 'nil' for "object:" when you were setting up the call.
that's an unexplained crash waiting to happen.
could be a problem in something you're not showing. myNotificationCenter
might not be getting set before it's used, or you're clobbering its value
somewhere. yet another reason not to cache a pointer to it.
Santa Claus - 26 Sep 2005 11:37 GMT
> > it's still not working...
>
[quoted text clipped - 14 lines]
> might not be getting set before it's used, or you're clobbering its value
> somewhere. yet another reason not to cache a pointer to it.
you're suggesting it can move all of it's own?