Author: manolo
Date: 2013-01-07 08:16:45 -0800 (Mon, 07 Jan 2013)
New Revision: 9787
Log:
Mac OS: divided the FLDelegate object in two objects, FLWindowDelegate and
FLAppDelegate.
This might help mixing FLTK and other window-creating systems.
Modified:
branches/branch-3.0/src/fltk3/cocoa.mm
Modified: branches/branch-3.0/src/fltk3/cocoa.mm
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa.mm 2013-01-07 15:56:14 UTC (rev
9786)
+++ branches/branch-3.0/src/fltk3/cocoa.mm 2013-01-07 16:16:45 UTC (rev
9787)
@@ -972,13 +972,11 @@
}
-@interface FLDelegate : NSObject
+@interface FLWindowDelegate : NSObject
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-<NSWindowDelegate, NSApplicationDelegate>
+<NSWindowDelegate>
#endif
-{
- BOOL seen_open_file;
-}
++ (FLWindowDelegate*)createOnce;
- (void)windowDidMove:(NSNotification *)notif;
- (void)windowDidResize:(NSNotification *)notif;
- (void)windowDidResignKey:(NSNotification *)notif;
@@ -987,18 +985,18 @@
- (void)windowDidDeminiaturize:(NSNotification *)notif;
- (void)windowDidMiniaturize:(NSNotification *)notif;
- (BOOL)windowShouldClose:(id)fl;
+- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client;
- (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;
-- (BOOL)application:(NSApplication *)theApplication openFile:(NSString
*)filename;
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
@end
-@implementation FLDelegate
+@implementation FLWindowDelegate
++ (FLWindowDelegate*)createOnce
+{
+ static FLWindowDelegate* delegate = nil;
+ if (!delegate) {
+ delegate = [[FLWindowDelegate alloc] init];
+ }
+ return delegate;
+}
- (void)windowDidMove:(NSNotification *)notif
{
fl_lock_function();
@@ -1090,6 +1088,18 @@
fl_unlock_function();
return NO; // the system doesn't need to send [fl close] because FLTK does
it when needed
}
+- (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
{
fl_lock_function();
@@ -1106,6 +1116,25 @@
}
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
{
fl_lock_function();
@@ -1237,18 +1266,6 @@
}
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
{
seen_open_file = YES;
@@ -1316,7 +1333,7 @@
if (need_new_nsapp) [NSApplication sharedApplication];
NSAutoreleasePool *localPool;
localPool = [[NSAutoreleasePool alloc] init]; // never released
- [NSApp setDelegate:[[FLDelegate alloc] init]];
+ [NSApp setDelegate:[[FLAppDelegate alloc] init]];
if (need_new_nsapp) [NSApp finishLaunching];
// empty the event queue but keep system events for drag&drop of files at
launch
@@ -1363,7 +1380,7 @@
}
if (![NSApp servicesMenu]) createAppleMenu();
main_screen_height = [[[NSScreen screens] objectAtIndex:0]
frame].size.height;
- [[NSNotificationCenter defaultCenter] addObserver:[NSApp delegate]
+ [[NSNotificationCenter defaultCenter] addObserver:[FLWindowDelegate
createOnce]
selector:@selector(anyWindowWillClose:)
name:NSWindowWillCloseNotification
object:nil];
@@ -2216,7 +2233,7 @@
w->set_visible();
if ( w->border() || (!w->modal() && !w->tooltip_window()) )
fltk3::handle(fltk3::FOCUS, w);
fltk3::first_window(w);
- [cw setDelegate:[NSApp delegate]];
+ [cw setDelegate:[FLWindowDelegate createOnce]];
if (fl_show_iconic) {
fl_show_iconic = 0;
[cw miniaturize:nil];
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit