From ca4601031cd7540b1a0e8108cb2939b40d8ad57d Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Mon, 25 Jun 2018 10:22:17 +0000 Subject: [PATCH] Give private member variable _panel of class Fl_Quartz_Native_File_Chooser_Driver its true type, NSSavePanel*. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12971 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Native_File_Chooser_MAC.mm | 46 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm index 413692b8a..26aee3a7c 100644 --- a/src/Fl_Native_File_Chooser_MAC.mm +++ b/src/Fl_Native_File_Chooser_MAC.mm @@ -29,12 +29,13 @@ #include #include #define MAXFILTERS 80 +#import class Fl_Quartz_Native_File_Chooser_Driver : public Fl_Native_File_Chooser_Driver { private: int _btype; // kind-of browser to show() int _options; // general options - void *_panel; + NSSavePanel *_panel; char **_pathnames; // array of pathnames int _tpathnames; // total pathnames char *_directory; // default pathname to use @@ -399,13 +400,12 @@ int Fl_Quartz_Native_File_Chooser_Driver::filters() const { return(_filt_total); } -#import #define UNLIKELYPREFIX "___fl_very_unlikely_prefix_" int Fl_Quartz_Native_File_Chooser_Driver::get_saveas_basename(void) { - char *q = strdup( [[[(NSSavePanel*)_panel URL] path] UTF8String] ); + char *q = strdup( [[[_panel URL] path] UTF8String] ); if ( !(_options & Fl_Native_File_Chooser::SAVEAS_CONFIRM) ) { - const char *d = [[[[(NSSavePanel*)_panel URL] path] stringByDeletingLastPathComponent] UTF8String]; + const char *d = [[[[_panel URL] path] stringByDeletingLastPathComponent] UTF8String]; int l = (int)strlen(d) + 1; if (strcmp(d, "/") == 0) l = 1; int lu = strlen(UNLIKELYPREFIX); @@ -604,7 +604,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal() if (fl_mac_os_version >= 100600) { bool usepath = false; NSString *path = nil; - if (dir && fname && [(NSSavePanel*)_panel isKindOfClass:[NSOpenPanel class]]) { + if (dir && fname && [_panel isKindOfClass:[NSOpenPanel class]]) { // STR #3406: If both dir + fname specified, combine and pass to setDirectoryURL path = [[NSString alloc] initWithFormat:@"%@/%@", dir, fname]; // dir+fname -> path // See if full path to file exists @@ -613,15 +613,15 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal() // if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) usepath = true; } - if (usepath) { - // Set only if full path exists - [(NSSavePanel*)_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:path]]; - } else { // didn't setDirectoryURL to full path? Set dir + fname separately.. - if (dir) [(NSSavePanel*)_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:dir]]; - if (fname) [(NSSavePanel*)_panel performSelector:@selector(setNameFieldStringValue:) withObject:fname]; - } - [path release]; - retval = [(NSSavePanel*)_panel runModal]; + if (usepath) { + // Set only if full path exists + [_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:path]]; + } else { // didn't setDirectoryURL to full path? Set dir + fname separately.. + if (dir) [_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:dir]]; + if (fname) [_panel performSelector:@selector(setNameFieldStringValue:) withObject:fname]; + } + [path release]; + retval = [_panel runModal]; } else { retval = [(id)_panel runModalForDirectory:dir file:fname]; @@ -660,11 +660,11 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() { _panel = [NSSavePanel savePanel]; break; } - BOOL is_open_panel = [(NSSavePanel*)_panel isKindOfClass:[NSOpenPanel class]]; + BOOL is_open_panel = [_panel isKindOfClass:[NSOpenPanel class]]; if (_title) { SEL title_or_message = (is_open_panel && fl_mac_os_version >= 101200) ? @selector(setMessage:) : @selector(setTitle:); - [(NSSavePanel*)_panel performSelector:title_or_message withObject:[NSString stringWithUTF8String:_title]]; + [_panel performSelector:title_or_message withObject:[NSString stringWithUTF8String:_title]]; } switch (_btype) { case Fl_Native_File_Chooser::BROWSE_MULTI_FILE: @@ -677,7 +677,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() { [(NSOpenPanel*)_panel setCanChooseDirectories:YES]; break; case Fl_Native_File_Chooser::BROWSE_SAVE_DIRECTORY: - [(NSSavePanel*)_panel setCanCreateDirectories:YES]; + [_panel setCanCreateDirectories:YES]; break; } @@ -687,7 +687,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() { if ( is_open_panel ) { if (_filt_total) { char *t = prepareMacFilter(_filt_total, _filter, _filt_patt); - popup = createPopupAccessory((NSSavePanel*)_panel, t, Fl_File_Chooser::show_label, 0); + popup = createPopupAccessory(_panel, t, Fl_File_Chooser::show_label, 0); delete[] t; [[popup menu] addItem:[NSMenuItem separatorItem]]; [popup addItemWithTitle:[NSString stringWithUTF8String:Fl_File_Chooser::all_files_label]]; @@ -695,25 +695,25 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() { [popup setTarget:(NSObject*)_panel]; FLopenDelegate *openDelegate = [[[FLopenDelegate alloc] init] autorelease]; [openDelegate setPopup:popup filter_pattern:_filt_patt]; - [(NSOpenPanel*)_panel setDelegate:openDelegate]; + [_panel setDelegate:openDelegate]; } } else { FLsaveDelegate *saveDelegate = [[[FLsaveDelegate alloc] init] autorelease]; - [(NSSavePanel*)_panel setAllowsOtherFileTypes:YES]; - [(NSSavePanel*)_panel setDelegate:saveDelegate]; + [_panel setAllowsOtherFileTypes:YES]; + [_panel setDelegate:saveDelegate]; [saveDelegate option:(_options & Fl_Native_File_Chooser::SAVEAS_CONFIRM)]; 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); + popup = createPopupAccessory(_panel, t, [[_panel nameFieldLabel] UTF8String], _filt_value); delete[] t; if (_options & Fl_Native_File_Chooser::USE_FILTER_EXT) { [popup setAction:@selector(changedPopup:)]; [popup setTarget:saveDelegate]; [saveDelegate panel:(NSSavePanel*)_panel]; } - [(NSSavePanel*)_panel setCanSelectHiddenExtension:YES]; + [_panel setCanSelectHiddenExtension:YES]; } } int retval = runmodal();