From 74496aa2ccb5f00bdd6b4ec0789691acc8ae4592 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Thu, 27 Sep 2012 12:49:39 +0000 Subject: Removed several deprecation warnings. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9685 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Device.cxx | 22 ------------- src/Fl_Native_File_Chooser_MAC.mm | 67 ++++++++++++++++++++------------------- src/Fl_cocoa.mm | 13 +++++++- 3 files changed, 47 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/Fl_Device.cxx b/src/Fl_Device.cxx index cde8156ed..83658edca 100644 --- a/src/Fl_Device.cxx +++ b/src/Fl_Device.cxx @@ -70,28 +70,6 @@ void Fl_Graphics_Driver::text_extents(const char*t, int n, int& dx, int& dy, int } Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device( graphics_driver) { -#ifdef __APPLE__ - SInt32 versionMajor = 0; - SInt32 versionMinor = 0; - SInt32 versionBugFix = 0; - SInt32 version; - Gestalt( gestaltSystemVersion, &version); -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - if (version >= 0x1040) { - Gestalt( gestaltSystemVersionMajor, &versionMajor ); - Gestalt( gestaltSystemVersionMinor, &versionMinor ); - Gestalt( gestaltSystemVersionBugFix, &versionBugFix ); - } - else { -#endif - versionMajor = 10; - versionMinor = (version / 0x10) % 0x10; - versionBugFix = version % 0x10; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - } -#endif - fl_mac_os_version = versionMajor * 10000 + versionMinor * 100 + versionBugFix; -#endif this->set_current(); }; diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm index 764e4261c..1dc4a2298 100644 --- a/src/Fl_Native_File_Chooser_MAC.mm +++ b/src/Fl_Native_File_Chooser_MAC.mm @@ -343,11 +343,12 @@ int Fl_Native_File_Chooser::filters() const { #define UNLIKELYPREFIX "___fl_very_unlikely_prefix_" int Fl_Native_File_Chooser::get_saveas_basename(void) { - char *q = strdup( [[(NSSavePanel*)_panel filename] fileSystemRepresentation] ); + char *q = strdup( [[[(NSSavePanel*)_panel URL] path] UTF8String] ); id delegate = [(NSSavePanel*)_panel delegate]; if (delegate != nil) { - const char *d = [[(NSSavePanel*)_panel directory] fileSystemRepresentation]; + const char *d = [[[[(NSSavePanel*)_panel URL] path] stringByDeletingLastPathComponent] UTF8String]; int l = strlen(d) + 1; + if (strcmp(d, "/") == 0) l = 1; int lu = strlen(UNLIKELYPREFIX); // Remove UNLIKELYPREFIX between directory and filename parts memmove(q + l, q + l + lu, strlen(q + l + lu) + 1); @@ -484,7 +485,34 @@ static NSPopUpButton *createPopupAccessory(NSSavePanel *panel, const char *filte [panel setAccessoryView:view]; return popup; } - + +int Fl_Native_File_Chooser::runmodal() +{ + NSString *dir = nil; + NSString *fname = nil; + NSString *preset = nil; + int retval; + if (_preset_file) { + preset = [[NSString alloc] initWithUTF8String:_preset_file]; + if (strchr(_preset_file, '/') != NULL) { + dir = [[NSString alloc] initWithString:[preset stringByDeletingLastPathComponent]]; + } + fname = [preset lastPathComponent]; + } + if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory]; + if (fl_mac_os_version >= 100600) { + if (dir) [(NSSavePanel*)_panel setDirectoryURL:[NSURL fileURLWithPath:dir]]; + if (fname) [(NSSavePanel*)_panel setNameFieldStringValue:fname]; + retval = [(NSSavePanel*)_panel runModal]; + } + else { + retval = [(id)_panel runModalForDirectory:dir file:fname]; + } + [dir release]; + [preset release]; + return retval; +} + // POST BROWSER // Internal use only. // Assumes '_opts' has been initialized. @@ -551,36 +579,21 @@ int Fl_Native_File_Chooser::post() { [openDelegate setPopup:popup filter_pattern:_filt_patt]; [(NSOpenPanel*)_panel setDelegate:openDelegate]; } - NSString *dir = nil; - NSString *fname = nil; - NSString *preset = nil; - if (_preset_file) { - preset = [[NSString alloc] initWithUTF8String:_preset_file]; - if (strchr(_preset_file, '/') != NULL) - dir = [[NSString alloc] initWithString:[preset stringByDeletingLastPathComponent]]; - fname = [preset lastPathComponent]; - } - if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory]; - retval = [(NSOpenPanel*)_panel runModalForDirectory:dir file:fname types:nil]; - [dir release]; - [preset release]; + retval = runmodal(); if (_filt_total) { _filt_value = [popup indexOfSelectedItem]; } if ( retval == NSOKButton ) { clear_pathnames(); - NSArray *array = [(NSOpenPanel*)_panel filenames]; + NSArray *array = [(NSOpenPanel*)_panel URLs]; _tpathnames = [array count]; _pathnames = new char*[_tpathnames]; for(int i = 0; i < _tpathnames; i++) { - _pathnames[i] = strnew([(NSString*)[array objectAtIndex:i] fileSystemRepresentation]); + _pathnames[i] = strnew([[(NSURL*)[array objectAtIndex:i] path] UTF8String]); } } } else { - NSString *dir = nil; - NSString *fname = nil; - NSString *preset = nil; NSPopUpButton *popup = nil; [(NSSavePanel*)_panel setAllowsOtherFileTypes:YES]; if ( !(_options & SAVEAS_CONFIRM) ) { @@ -588,26 +601,16 @@ int Fl_Native_File_Chooser::post() { if (saveDelegate == nil)saveDelegate = [[FLsaveDelegate alloc] init]; // not to be ever freed [(NSSavePanel*)_panel setDelegate:saveDelegate]; } - if (_preset_file) { - preset = [[NSString alloc] initWithUTF8String:_preset_file]; - if (strchr(_preset_file, '/') != NULL) { - dir = [[NSString alloc] initWithString:[preset stringByDeletingLastPathComponent]]; - } - fname = [preset lastPathComponent]; - } - if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory]; if (_filt_total) { if (_filt_value >= _filt_total) _filt_value = _filt_total - 1; char *t = prepareMacFilter(_filt_total, _filter, _filt_patt); popup = createPopupAccessory((NSSavePanel*)_panel, t, [[(NSSavePanel*)_panel nameFieldLabel] UTF8String], _filt_value); delete[] t; } - retval = [(NSSavePanel*)_panel runModalForDirectory:dir file:fname]; + retval = runmodal(); if (_filt_total) { _filt_value = [popup indexOfSelectedItem]; } - [dir release]; - [preset release]; if ( retval == NSOKButton ) get_saveas_basename(); } [key makeKeyWindow]; diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index d4a1c553d..4c938394b 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -87,6 +87,7 @@ static void convert_crlf(char * string, size_t len); static void createAppleMenu(void); static Fl_Region MacRegionMinusRect(Fl_Region r, int x,int y,int w,int h); static void cocoaMouseHandler(NSEvent *theEvent); +static int calc_mac_os_version(); static Fl_Quartz_Graphics_Driver fl_quartz_driver; static Fl_Display_Device fl_quartz_display(&fl_quartz_driver); @@ -102,7 +103,7 @@ bool fl_show_iconic; // true if called from iconize() - shows //int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR Window fl_window; Fl_Window *Fl_Window::current_; -int fl_mac_os_version = 0; // the version number of the running Mac OS X (e.g., 100604 for 10.6.4) +int fl_mac_os_version = calc_mac_os_version(); // the version number of the running Mac OS X (e.g., 100604 for 10.6.4) // forward declarations of variables in this file static int got_events = 0; @@ -3455,6 +3456,16 @@ void *Fl_X::get_carbon_function(const char *function_name) { return f; } +/* Returns the version of the running Mac OS as an int such as 100802 for 10.8.2 + */ +static int calc_mac_os_version() { + int M, m, b = 0; + NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; + const char *s = [[sv objectForKey:@"ProductVersion"] UTF8String]; + sscanf(s, "%d.%d.%d", &M, &m, &b); + return M*10000 + m*100 + b; +} + #endif // __APPLE__ // -- cgit v1.2.3