> Again thank you for your answers. I did not expect to receive so fast a
> response, which is in par with the quality of your tools.
>
> However, I have eventually discovered what was wrong. When I load a FLTK
> window, then a window of my own (within my COCOA application), then again a
> FLTK window, then the deletion of a FLTK window does not go through
> windowShouldClose anymore, but only through anyWindowWillClose, hence the
> lockFocus error later on. The reason is that the FLTK NSApp delegate is a
> little bit stirred by the external call of another type of window, so I guess.
>
> The solution I came up with is to reinitialize the place where the
> setDelegate is done the very first time.
>
> I have implemented a fltk_reinit function, which I call before
> launching a Fl::run...
In FLTK, a single object of the FLTK-defined type FLDelegate is used
as application delegate and as delegate of all FLTK-created windows.
It's also declared as observer of NSWindowWillCloseNotification
triggered whenever any window (FLTK or not) closes.
What you describe suggests that your application changes the
application delegate to another object. When a new window is created
the statement
[cw setDelegate:[NSApp delegate]];
assigns to this new window (cw here) the application delegate as
window delegate. If the application delegate has changed, the
window delegate will also change, and the windowShouldClose message won't call
the proper FLTK code defined by the FLDelegate object.
My conclusion at this point is to ask whether you could make
your application not change the application delegate, because
FLTK does not like that. Please, note that FLTK can live with
non-FLTK created windows (e.g., open, save and print dialogs create
such non FLTK windows) without problem.
If the application delegate is changed at somepoint and you just want
to reset it as before, you could do:
fl_open_display(); // at program start, before any window is created
id true_delegate = [NSApp delegate];
....
//the delegate is changed somehow
....
[NSApp setDelegate:true_delegate]; // reset the delegate as needed
If you need your own application delegate, I would suggest you make it
a subclass of FLTK's FLDelegate, and call FLTK's
implementation of each delegate function in addition to your own
implementaton of such function. This would be something like that:
@interface FLDelegate : NSObject
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
<NSWindowDelegate, NSApplicationDelegate>
#endif
{
BOOL seen_open_file;
}
@end
@interface ClaudeDelegate : FLDelegate
- (void)applicationDidBecomeActive:(NSNotification *)notify;
@end
@implementation ClaudeDelegate
- (void)applicationDidBecomeActive:(NSNotification *)notify {
.. do your own stuff ...
[super applicationDidBecomeActive:notify];
}
@end
And, once, at application start, do:
fl_open_display();
[NSApp setDelegate:[[ClaudeDelegate alloc] init]];
which will make your own object as application delegate.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk