MacOS: improve handling of dropped files at launch time for MacOS 10.13

Because opening a file can call the event loop and thus access the list of dropped files,
 it's necessary to remove the object from the list before opening the file.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12522 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy
2017-10-22 06:29:04 +00:00
parent 1a41a89e94
commit cf13e6c2cd
+18 -16
View File
@@ -88,6 +88,7 @@ static void cocoaMouseHandler(NSEvent *theEvent);
static void clipboard_check(void); static void clipboard_check(void);
static unsigned make_current_counts = 0; // if > 0, then Fl_Window::make_current() can be called only once static unsigned make_current_counts = 0; // if > 0, then Fl_Window::make_current() can be called only once
static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h); static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h);
static void drain_dropped_files_list(void);
int fl_mac_os_version = Fl_Darwin_System_Driver::calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4) int fl_mac_os_version = Fl_Darwin_System_Driver::calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4)
@@ -117,7 +118,6 @@ static NSString *UTF8_pasteboard_type = (fl_mac_os_version >= 100600 ? NSPastebo
static bool in_nsapp_run = false; // true during execution of [NSApp run] static bool in_nsapp_run = false; // true during execution of [NSApp run]
static NSMutableArray *dropped_files_list = nil; // list of files dropped at app launch static NSMutableArray *dropped_files_list = nil; // list of files dropped at app launch
typedef void (*open_cb_f_type)(const char *); typedef void (*open_cb_f_type)(const char *);
static open_cb_f_type get_open_cb();
#if CONSOLIDATE_MOTION #if CONSOLIDATE_MOTION
static Fl_Window* send_motion; static Fl_Window* send_motion;
@@ -847,19 +847,6 @@ static int do_queued_events( double time = 0.0 )
return got_events; return got_events;
} }
static void drain_dropped_files_list() {
open_cb_f_type open_cb = get_open_cb();
NSString *s;
if ( (s = (NSString*)[dropped_files_list firstObject]) != nil) {
if (open_cb) open_cb([s UTF8String]);
[dropped_files_list removeObjectAtIndex:0];
}
if ([dropped_files_list count] == 0) {
[dropped_files_list release];
dropped_files_list = nil;
}
}
double Fl_Cocoa_Screen_Driver::wait(double time_to_wait) double Fl_Cocoa_Screen_Driver::wait(double time_to_wait)
{ {
if (dropped_files_list) { // when the list of dropped files is not empty, open one and remove it from list if (dropped_files_list) { // when the list of dropped files is not empty, open one and remove it from list
@@ -1680,8 +1667,23 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
} }
@end @end
static open_cb_f_type get_open_cb() { static void drain_dropped_files_list() {
return ((FLAppDelegate*)[NSApp delegate])->open_cb; open_cb_f_type open_cb = ((FLAppDelegate*)[NSApp delegate])->open_cb;
if (!open_cb) {
[dropped_files_list removeAllObjects];
[dropped_files_list release];
dropped_files_list = nil;
return;
}
NSString *s = (NSString*)[dropped_files_list objectAtIndex:0];
char *fname = strdup([s UTF8String]);
[dropped_files_list removeObjectAtIndex:0];
if ([dropped_files_list count] == 0) {
[dropped_files_list release];
dropped_files_list = nil;
}
open_cb(fname);
free(fname);
} }
/* /*