Mac OS: divided the FLDelegate object in two objects, FLWindowDelegate and FLAppDelegate.

This might help mixing FLTK and other window-creating systems.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9786 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy
2013-01-07 15:56:14 +00:00
parent 369bde4474
commit 31e49fcf12
+49 -32
View File
@@ -993,13 +993,11 @@ void fl_open_callback(void (*cb)(const char *)) {
} }
@interface FLDelegate : NSObject @interface FLWindowDelegate : NSObject
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
<NSWindowDelegate, NSApplicationDelegate> <NSWindowDelegate>
#endif #endif
{ + (FLWindowDelegate*)createOnce;
BOOL seen_open_file;
}
- (void)windowDidMove:(NSNotification *)notif; - (void)windowDidMove:(NSNotification *)notif;
- (void)windowDidResize:(NSNotification *)notif; - (void)windowDidResize:(NSNotification *)notif;
- (void)windowDidResignKey:(NSNotification *)notif; - (void)windowDidResignKey:(NSNotification *)notif;
@@ -1008,18 +1006,18 @@ void fl_open_callback(void (*cb)(const char *)) {
- (void)windowDidDeminiaturize:(NSNotification *)notif; - (void)windowDidDeminiaturize:(NSNotification *)notif;
- (void)windowDidMiniaturize:(NSNotification *)notif; - (void)windowDidMiniaturize:(NSNotification *)notif;
- (BOOL)windowShouldClose:(id)fl; - (BOOL)windowShouldClose:(id)fl;
- (void)anyWindowWillClose:(NSNotification *)notif;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
- (void)applicationDidBecomeActive:(NSNotification *)notify;
- (void)applicationDidChangeScreenParameters:(NSNotification *)aNotification;
- (void)applicationWillResignActive:(NSNotification *)notify;
- (void)applicationWillHide:(NSNotification *)notify;
- (void)applicationWillUnhide:(NSNotification *)notify;
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client; - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client;
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename; - (void)anyWindowWillClose:(NSNotification *)notif;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
@end @end
@implementation FLDelegate @implementation FLWindowDelegate
+ (FLWindowDelegate*)createOnce
{
static FLWindowDelegate* delegate = nil;
if (!delegate) {
delegate = [[FLWindowDelegate alloc] init];
}
return delegate;
}
- (void)windowDidMove:(NSNotification *)notif - (void)windowDidMove:(NSNotification *)notif
{ {
fl_lock_function(); fl_lock_function();
@@ -1061,7 +1059,7 @@ void fl_open_callback(void (*cb)(const char *)) {
FLWindow *nsw = (FLWindow*)[notif object]; FLWindow *nsw = (FLWindow*)[notif object];
Fl_Window *window = [nsw getFl_Window]; Fl_Window *window = [nsw getFl_Window];
/* Fullscreen windows obscure all other windows so we need to return /* Fullscreen windows obscure all other windows so we need to return
to a "normal" level when the user switches to another window */ to a "normal" level when the user switches to another window */
if (window->fullscreen_active()) if (window->fullscreen_active())
[nsw setLevel:NSNormalWindowLevel]; [nsw setLevel:NSNormalWindowLevel];
Fl::handle( FL_UNFOCUS, window); Fl::handle( FL_UNFOCUS, window);
@@ -1112,6 +1110,18 @@ void fl_open_callback(void (*cb)(const char *)) {
// the system doesn't need to send [fl close] because FLTK does it when needed // the system doesn't need to send [fl close] because FLTK does it when needed
return NO; return NO;
} }
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client
{
if (fl_mac_os_version < 100600) {
static FLTextView *view = nil;
if (!view) {
NSRect rect={{0,0},{20,20}};
view = [[FLTextView alloc] initWithFrame:rect];
}
return view;
}
return nil;
}
- (void)anyWindowWillClose:(NSNotification *)notif - (void)anyWindowWillClose:(NSNotification *)notif
{ {
fl_lock_function(); fl_lock_function();
@@ -1121,13 +1131,32 @@ void fl_open_callback(void (*cb)(const char *)) {
Fl_Window *w = Fl::first_window(); Fl_Window *w = Fl::first_window();
while (w && (w->parent() || !w->border() || !w->visible())) { while (w && (w->parent() || !w->border() || !w->visible())) {
w = Fl::next_window(w); w = Fl::next_window(w);
} }
if (w) { if (w) {
[Fl_X::i(w)->xid makeKeyWindow]; [Fl_X::i(w)->xid makeKeyWindow];
} }
} }
fl_unlock_function(); fl_unlock_function();
} }
@end
@interface FLAppDelegate : NSObject
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
<NSApplicationDelegate>
#endif
{
BOOL seen_open_file;
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
- (void)applicationDidBecomeActive:(NSNotification *)notify;
- (void)applicationDidChangeScreenParameters:(NSNotification *)aNotification;
- (void)applicationWillResignActive:(NSNotification *)notify;
- (void)applicationWillHide:(NSNotification *)notify;
- (void)applicationWillUnhide:(NSNotification *)notify;
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
@end
@implementation FLAppDelegate
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
{ {
fl_lock_function(); fl_lock_function();
@@ -1259,18 +1288,6 @@ void fl_open_callback(void (*cb)(const char *)) {
} }
fl_unlock_function(); fl_unlock_function();
} }
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client
{
if (fl_mac_os_version < 100600) {
static FLTextView *view = nil;
if (!view) {
NSRect rect={{0,0},{20,20}};
view = [[FLTextView alloc] initWithFrame:rect];
}
return view;
}
return nil;
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{ {
seen_open_file = YES; seen_open_file = YES;
@@ -1338,7 +1355,7 @@ void fl_open_display() {
if (need_new_nsapp) [NSApplication sharedApplication]; if (need_new_nsapp) [NSApplication sharedApplication];
NSAutoreleasePool *localPool; NSAutoreleasePool *localPool;
localPool = [[NSAutoreleasePool alloc] init]; // never released localPool = [[NSAutoreleasePool alloc] init]; // never released
[NSApp setDelegate:[[FLDelegate alloc] init]]; [NSApp setDelegate:[[FLAppDelegate alloc] init]];
if (need_new_nsapp) [NSApp finishLaunching]; if (need_new_nsapp) [NSApp finishLaunching];
// empty the event queue but keep system events for drag&drop of files at launch // empty the event queue but keep system events for drag&drop of files at launch
@@ -1386,7 +1403,7 @@ void fl_open_display() {
if (![NSApp servicesMenu]) createAppleMenu(); if (![NSApp servicesMenu]) createAppleMenu();
fl_system_menu = [NSApp mainMenu]; fl_system_menu = [NSApp mainMenu];
main_screen_height = [[[NSScreen screens] objectAtIndex:0] frame].size.height; main_screen_height = [[[NSScreen screens] objectAtIndex:0] frame].size.height;
[[NSNotificationCenter defaultCenter] addObserver:[NSApp delegate] [[NSNotificationCenter defaultCenter] addObserver:[FLWindowDelegate createOnce]
selector:@selector(anyWindowWillClose:) selector:@selector(anyWindowWillClose:)
name:NSWindowWillCloseNotification name:NSWindowWillCloseNotification
object:nil]; object:nil];
@@ -2244,7 +2261,7 @@ void Fl_X::make(Fl_Window* w)
w->set_visible(); w->set_visible();
if ( w->border() || (!w->modal() && !w->tooltip_window()) ) Fl::handle(FL_FOCUS, w); if ( w->border() || (!w->modal() && !w->tooltip_window()) ) Fl::handle(FL_FOCUS, w);
Fl::first_window(w); Fl::first_window(w);
[cw setDelegate:[NSApp delegate]]; [cw setDelegate:[FLWindowDelegate createOnce]];
if (fl_show_iconic) { if (fl_show_iconic) {
fl_show_iconic = 0; fl_show_iconic = 0;
[cw miniaturize:nil]; [cw miniaturize:nil];