Author: manolo
Date: 2012-09-27 06:15:26 -0700 (Thu, 27 Sep 2012)
New Revision: 9686
Log:
Removed several deprecation warnings.
Modified:
branches/branch-3.0/include/fltk3/NativeFileChooser.h
branches/branch-3.0/src/fltk3/Device.cxx
branches/branch-3.0/src/fltk3/cocoa.mm
branches/branch-3.0/src/fltk3/cocoaNativeFileChooser.mm
Modified: branches/branch-3.0/include/fltk3/NativeFileChooser.h
===================================================================
--- branches/branch-3.0/include/fltk3/NativeFileChooser.h 2012-09-27
12:49:39 UTC (rev 9685)
+++ branches/branch-3.0/include/fltk3/NativeFileChooser.h 2012-09-27
13:15:26 UTC (rev 9686)
@@ -223,6 +223,7 @@
void add_filter(const char *, const char *);
void parse_filter(const char *from);
int post();
+ int runmodal();
#endif
#if ! defined(__APPLE__) && !defined(WIN32)
Modified: branches/branch-3.0/src/fltk3/Device.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Device.cxx 2012-09-27 12:49:39 UTC (rev
9685)
+++ branches/branch-3.0/src/fltk3/Device.cxx 2012-09-27 13:15:26 UTC (rev
9686)
@@ -71,15 +71,6 @@
}
fltk3::DisplayDevice::DisplayDevice(fltk3::GraphicsDriver *graphics_driver) :
fltk3::SurfaceDevice( graphics_driver) {
-#ifdef __APPLE__
- SInt32 versionMajor = 0;
- SInt32 versionMinor = 0;
- SInt32 versionBugFix = 0;
- Gestalt( gestaltSystemVersionMajor, &versionMajor );
- Gestalt( gestaltSystemVersionMinor, &versionMinor );
- Gestalt( gestaltSystemVersionBugFix, &versionBugFix );
- fl_mac_os_version = versionMajor * 10000 + versionMinor * 100 +
versionBugFix;
-#endif
this->set_current();
_display = this;
}
Modified: branches/branch-3.0/src/fltk3/cocoa.mm
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa.mm 2012-09-27 12:49:39 UTC (rev
9685)
+++ branches/branch-3.0/src/fltk3/cocoa.mm 2012-09-27 13:15:26 UTC (rev
9686)
@@ -86,6 +86,7 @@
static void createAppleMenu(void);
static fltk3::Region MacRegionMinusRect(fltk3::Region r, int x,int y,int w,int
h);
static void cocoaMouseHandler(NSEvent *theEvent);
+static int calc_mac_os_version();
static fltk3::QuartzGraphicsDriver fl_quartz_driver;
static fltk3::DisplayDevice fl_quartz_display(&fl_quartz_driver);
@@ -98,7 +99,7 @@
//int fl_disable_transient_for; // secret method of removing
TRANSIENT_FOR
Window fl_window;
fltk3::Window *fltk3::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;
@@ -1307,21 +1308,13 @@
if ( !GetCurrentProcess( &cur_psn ) && !GetFrontProcess( &front_psn ) &&
!SameProcess( &front_psn, &cur_psn, &same_psn ) && !same_psn ) {
// only transform the application type for unbundled apps
- CFBundleRef bundle = CFBundleGetMainBundle();
- if ( bundle ) {
- FSRef execFs;
- CFURLRef execUrl = CFBundleCopyExecutableURL( bundle );
- CFURLGetFSRef( execUrl, &execFs );
-
- FSRef bundleFs;
- GetProcessBundleLocation( &cur_psn, &bundleFs );
-
- if ( !FSCompareFSRefs( &execFs, &bundleFs ) )
- bundle = NULL;
-
- CFRelease(execUrl);
+ NSBundle *bundle = [NSBundle mainBundle];
+ if (bundle) {
+ NSString *exe = [bundle executablePath];
+ NSString *bpath = [bundle bundlePath];
+ if ([bpath isEqualToString:exe]) bundle = nil;
}
-
+
if ( !bundle )
{
// Earlier versions of this code tried to use weak linking, however it
@@ -3225,6 +3218,16 @@
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__
//
Modified: branches/branch-3.0/src/fltk3/cocoaNativeFileChooser.mm
===================================================================
--- branches/branch-3.0/src/fltk3/cocoaNativeFileChooser.mm 2012-09-27
12:49:39 UTC (rev 9685)
+++ branches/branch-3.0/src/fltk3/cocoaNativeFileChooser.mm 2012-09-27
13:15:26 UTC (rev 9686)
@@ -352,11 +352,12 @@
#define UNLIKELYPREFIX "___fl_very_unlikely_prefix_"
int fltk3::NativeFileChooser::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);
@@ -494,6 +495,33 @@
return popup;
}
+int fltk3::NativeFileChooser::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.
@@ -560,36 +588,21 @@
[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) ) {
@@ -597,26 +610,16 @@
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];
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit