diff options
Diffstat (limited to 'src/Fl_Native_File_Chooser_FLTK.cxx')
| -rw-r--r-- | src/Fl_Native_File_Chooser_FLTK.cxx | 255 |
1 files changed, 29 insertions, 226 deletions
diff --git a/src/Fl_Native_File_Chooser_FLTK.cxx b/src/Fl_Native_File_Chooser_FLTK.cxx index c72ee74d0..5c3727134 100644 --- a/src/Fl_Native_File_Chooser_FLTK.cxx +++ b/src/Fl_Native_File_Chooser_FLTK.cxx @@ -16,216 +16,21 @@ // http://www.fltk.org/str.php // -#include <config.h> #include <FL/Fl_Native_File_Chooser.H> +#include <FL/Fl_File_Chooser.H> #include <FL/Fl_File_Icon.H> #define FLTK_CHOOSER_SINGLE Fl_File_Chooser::SINGLE #define FLTK_CHOOSER_DIRECTORY Fl_File_Chooser::DIRECTORY #define FLTK_CHOOSER_MULTI Fl_File_Chooser::MULTI #define FLTK_CHOOSER_CREATE Fl_File_Chooser::CREATE -#include "Fl_Native_File_Chooser_common.cxx" -#include "Fl_Native_File_Chooser_GTK.cxx" - #include <sys/stat.h> #include <string.h> -#if defined(FL_PORTING) -# pragma message "FL_PORTING: implement Fl_Native_File_Chooser" -int Fl_Native_File_Chooser::show() { return 0; } -void Fl_Native_File_Chooser::type(int t) { } -void Fl_Native_File_Chooser::title(const char *t) { } -void Fl_Native_File_Chooser::filter(const char *f) { } -void Fl_Native_File_Chooser::options(int val) { } -const char *Fl_Native_File_Chooser::filename() const { return 0; } -Fl_Native_File_Chooser::Fl_Native_File_Chooser(int) { } -Fl_Native_File_Chooser::~Fl_Native_File_Chooser() { } -#else - -int Fl_Native_File_Chooser::have_looked_for_GTK_libs = 0; - -/** - The constructor. Internally allocates the native widgets. - Optional \p val presets the type of browser this will be, - which can also be changed with type(). - */ -Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) { - if (have_looked_for_GTK_libs == 0) { - // First Time here, try to find the GTK libs if they are installed -#if HAVE_DLSYM && HAVE_DLFCN_H - if (Fl::option(Fl::OPTION_FNFC_USES_GTK)) { - Fl_GTK_File_Chooser::probe_for_GTK_libs(); - } -#endif - have_looked_for_GTK_libs = -1; - } - // if we found all the GTK functions we need, we will use the GtkFileChooserDialog - if (Fl_GTK_File_Chooser::did_find_GTK_libs) _gtk_file_chooser = new Fl_GTK_File_Chooser(val); - else _x11_file_chooser = new Fl_FLTK_File_Chooser(val); -} -/** - Destructor. - Deallocates any resources allocated to this widget. - */ -Fl_Native_File_Chooser::~Fl_Native_File_Chooser() { - delete _x11_file_chooser; -} -/** - Sets the current Fl_Native_File_Chooser::Type of browser. - */ -void Fl_Native_File_Chooser::type(int t) { return _x11_file_chooser->type(t); } -/** - Gets the current Fl_Native_File_Chooser::Type of browser. - */ -int Fl_Native_File_Chooser::type() const { return _x11_file_chooser->type(); } -/** - Sets the platform specific chooser options to \p val. - \p val is expected to be one or more Fl_Native_File_Chooser::Option flags ORed together. - Some platforms have OS-specific functions that can be enabled/disabled via this method. - <P> - \code - Flag Description Win Mac Other - -------------- ----------------------------------------------- ------- ------- ------- - NEW_FOLDER Shows the 'New Folder' button. Ignored Used Used - PREVIEW Enables the 'Preview' mode by default. Ignored Ignored Used - SAVEAS_CONFIRM Confirm dialog if BROWSE_SAVE_FILE file exists. Used Used Used - USE_FILTER_EXT Chooser filter pilots the output file extension. Ignored Used Used (GTK) -\endcode - */ -void Fl_Native_File_Chooser::options(int o) { _x11_file_chooser->options(o); } -/** - Gets the platform specific Fl_Native_File_Chooser::Option flags. - */ -int Fl_Native_File_Chooser::options() const { return _x11_file_chooser->options(); } - -/** - Returns the number of filenames (or directory names) the user selected. - <P> - \b Example: - \code - if ( fnfc->show() == 0 ) { - // Print all filenames user selected - for (int n=0; n<fnfc->count(); n++ ) { - printf("%d) '%s'\n", n, fnfc->filename(n)); - } - } - \endcode - */ -int Fl_Native_File_Chooser::count() const { return _x11_file_chooser->count(); } -/** - Return the filename the user chose. - Use this if only expecting a single filename. - If more than one filename is expected, use filename(int) instead. - Return value may be "" if no filename was chosen (eg. user cancelled). - */ -const char *Fl_Native_File_Chooser::filename() const { return _x11_file_chooser->filename(); } -/** - Return one of the filenames the user selected. - Use count() to determine how many filenames the user selected. - <P> - \b Example: - \code - if ( fnfc->show() == 0 ) { - // Print all filenames user selected - for (int n=0; n<fnfc->count(); n++ ) { - printf("%d) '%s'\n", n, fnfc->filename(n)); - } - } - \endcode - */ -const char *Fl_Native_File_Chooser::filename(int i) const { return _x11_file_chooser->filename(i); } -/** - Preset the directory the browser will show when opened. - If \p val is NULL, or no directory is specified, the chooser will attempt - to use the last non-cancelled folder. - */ -void Fl_Native_File_Chooser::directory(const char *val) { _x11_file_chooser->directory(val); } -/** - Returns the current preset directory() value. - */ -const char *Fl_Native_File_Chooser::directory() const { return _x11_file_chooser->directory(); } -/** - Set the title of the file chooser's dialog window. - Can be NULL if no title desired. - The default title varies according to the platform, so you are advised to set the title explicitly. - */ -void Fl_Native_File_Chooser::title(const char *t) { _x11_file_chooser->title(t); } -/** - Get the title of the file chooser's dialog window. - Return value may be NULL if no title was set. - */ -const char* Fl_Native_File_Chooser::title() const { return _x11_file_chooser->title(); } -/** - Returns the filter string last set. - Can be NULL if no filter was set. - */ -const char *Fl_Native_File_Chooser::filter() const { return _x11_file_chooser->filter(); } -/** - Sets the filename filters used for browsing. - The default is NULL, which browses all files. - <P> - The filter string can be any of: - <P> - - A single wildcard (eg. "*.txt") - - Multiple wildcards (eg. "*.{cxx,h,H}") - - A descriptive name followed by a "\t" and a wildcard (eg. "Text Files\t*.txt") - - A list of separate wildcards with a "\n" between each (eg. "*.{cxx,H}\n*.txt") - - A list of descriptive names and wildcards (eg. "C++ Files\t*.{cxx,H}\nTxt Files\t*.txt") - <P> - The format of each filter is a wildcard, or an optional user description - followed by '\\t' and the wildcard. - <P> - On most platforms, each filter is available to the user via a pulldown menu - in the file chooser. The 'All Files' option is always available to the user. - */ -void Fl_Native_File_Chooser::filter(const char *f) { _x11_file_chooser->filter(f); } -/** - Gets how many filters were available, not including "All Files" - */ -int Fl_Native_File_Chooser::filters() const { return _x11_file_chooser->filters(); } -/** - Sets which filter will be initially selected. - - The first filter is indexed as 0. - If filter_value()==filters(), then "All Files" was chosen. - If filter_value() > filters(), then a custom filter was set. - */ -void Fl_Native_File_Chooser::filter_value(int i) { _x11_file_chooser->filter_value(i); } -/** - Returns which filter value was last selected by the user. - This is only valid if the chooser returns success. - */ -int Fl_Native_File_Chooser::filter_value() const { return _x11_file_chooser->filter_value(); } -/** - Sets the default filename for the chooser. - Use directory() to set the default directory. - Mainly used to preset the filename for save dialogs, - and on most platforms can be used for opening files as well. - */ -void Fl_Native_File_Chooser::preset_file(const char* f) { _x11_file_chooser->preset_file(f); } -/** - Get the preset filename. - */ -const char* Fl_Native_File_Chooser::preset_file() const { return _x11_file_chooser->preset_file(); } -/** - Returns a system dependent error message for the last method that failed. - This message should at least be flagged to the user in a dialog box, or to some kind of error log. - Contents will be valid only for methods that document errmsg() will have info on failures. - */ -const char *Fl_Native_File_Chooser::errmsg() const { return _x11_file_chooser->errmsg(); } -/** - Post the chooser's dialog. Blocks until dialog has been completed or cancelled. - \returns - - 0 -- user picked a file - - 1 -- user cancelled - - -1 -- failed; errmsg() has reason - */ -int Fl_Native_File_Chooser::show() { return _x11_file_chooser->show(); } - - -Fl_FLTK_File_Chooser::Fl_FLTK_File_Chooser(int val) { +Fl_Native_File_Chooser_FLTK_Driver::Fl_Native_File_Chooser_FLTK_Driver(int val) : + Fl_Native_File_Chooser_Driver(val) { _btype = 0; _options = 0; _filter = NULL; @@ -243,7 +48,7 @@ Fl_FLTK_File_Chooser::Fl_FLTK_File_Chooser(int val) { _nfilters = 0; } -Fl_FLTK_File_Chooser::~Fl_FLTK_File_Chooser() { +Fl_Native_File_Chooser_FLTK_Driver::~Fl_Native_File_Chooser_FLTK_Driver() { delete _file_chooser; _file_chooser = NULL; _filter = strfree(_filter); @@ -256,13 +61,13 @@ Fl_FLTK_File_Chooser::~Fl_FLTK_File_Chooser() { // PRIVATE: SET ERROR MESSAGE -void Fl_FLTK_File_Chooser::errmsg(const char *msg) { +void Fl_Native_File_Chooser_FLTK_Driver::errmsg(const char *msg) { _errmsg = strfree(_errmsg); _errmsg = strnew(msg); } // PRIVATE: translate Native types to Fl_File_Chooser types -int Fl_FLTK_File_Chooser::type_fl_file(int val) { +int Fl_Native_File_Chooser_FLTK_Driver::type_fl_file(int val) { switch (val) { case Fl_Native_File_Chooser::BROWSE_FILE: return(Fl_File_Chooser::SINGLE); @@ -281,24 +86,24 @@ int Fl_FLTK_File_Chooser::type_fl_file(int val) { } } -void Fl_FLTK_File_Chooser::type(int val) { +void Fl_Native_File_Chooser_FLTK_Driver::type(int val) { _btype = val; _file_chooser->type(type_fl_file(val)); } -int Fl_FLTK_File_Chooser::type() const { +int Fl_Native_File_Chooser_FLTK_Driver::type() const { return(_btype); } -void Fl_FLTK_File_Chooser::options(int val) { +void Fl_Native_File_Chooser_FLTK_Driver::options(int val) { _options = val; } -int Fl_FLTK_File_Chooser::options() const { +int Fl_Native_File_Chooser_FLTK_Driver::options() const { return(_options); } -int Fl_FLTK_File_Chooser::show() { +int Fl_Native_File_Chooser_FLTK_Driver::show() { // FILTER if ( _parsedfilt ) { @@ -345,7 +150,7 @@ int Fl_FLTK_File_Chooser::show() { // HANDLE SHOWING 'SaveAs' CONFIRM if ( options() & Fl_Native_File_Chooser::SAVEAS_CONFIRM && type() == Fl_Native_File_Chooser::BROWSE_SAVE_FILE ) { struct stat buf; - if ( stat(_file_chooser->value(), &buf) != -1 ) { + if ( fl_stat(_file_chooser->value(), &buf) != -1 ) { if ( buf.st_mode & S_IFREG ) { // Regular file + exists? if ( exist_dialog() == 0 ) { return(1); @@ -359,63 +164,63 @@ int Fl_FLTK_File_Chooser::show() { else return(1); } -const char *Fl_FLTK_File_Chooser::errmsg() const { +const char *Fl_Native_File_Chooser_FLTK_Driver::errmsg() const { return(_errmsg ? _errmsg : "No error"); } -const char* Fl_FLTK_File_Chooser::filename() const { +const char* Fl_Native_File_Chooser_FLTK_Driver::filename() const { if ( _file_chooser->count() > 0 ) { return(_file_chooser->value()); } return(""); } -const char* Fl_FLTK_File_Chooser::filename(int i) const { +const char* Fl_Native_File_Chooser_FLTK_Driver::filename(int i) const { if ( i < _file_chooser->count() ) return(_file_chooser->value(i+1)); // convert fltk 1 based to our 0 based return(""); } -void Fl_FLTK_File_Chooser::title(const char *val) { +void Fl_Native_File_Chooser_FLTK_Driver::title(const char *val) { _file_chooser->label(val); } -const char *Fl_FLTK_File_Chooser::title() const { +const char *Fl_Native_File_Chooser_FLTK_Driver::title() const { return(_file_chooser->label()); } -void Fl_FLTK_File_Chooser::filter(const char *val) { +void Fl_Native_File_Chooser_FLTK_Driver::filter(const char *val) { _filter = strfree(_filter); _filter = strnew(val); parse_filter(); } -const char *Fl_FLTK_File_Chooser::filter() const { +const char *Fl_Native_File_Chooser_FLTK_Driver::filter() const { return(_filter); } -int Fl_FLTK_File_Chooser::filters() const { +int Fl_Native_File_Chooser_FLTK_Driver::filters() const { return(_nfilters); } -void Fl_FLTK_File_Chooser::filter_value(int val) { +void Fl_Native_File_Chooser_FLTK_Driver::filter_value(int val) { _filtvalue = val; } -int Fl_FLTK_File_Chooser::filter_value() const { +int Fl_Native_File_Chooser_FLTK_Driver::filter_value() const { return _filtvalue; } -int Fl_FLTK_File_Chooser::count() const { +int Fl_Native_File_Chooser_FLTK_Driver::count() const { return _file_chooser->count(); } -void Fl_FLTK_File_Chooser::directory(const char *val) { +void Fl_Native_File_Chooser_FLTK_Driver::directory(const char *val) { _directory = strfree(_directory); _directory = strnew(val); } -const char *Fl_FLTK_File_Chooser::directory() const { +const char *Fl_Native_File_Chooser_FLTK_Driver::directory() const { return _directory; } @@ -429,7 +234,7 @@ const char *Fl_FLTK_File_Chooser::directory() const { // Returns a modified version of the filter that the caller is responsible // for freeing with strfree(). // -void Fl_FLTK_File_Chooser::parse_filter() { +void Fl_Native_File_Chooser_FLTK_Driver::parse_filter() { _parsedfilt = strfree(_parsedfilt); // clear previous parsed filter (if any) _nfilters = 0; char *in = _filter; @@ -492,21 +297,19 @@ void Fl_FLTK_File_Chooser::parse_filter() { //NOTREACHED } -void Fl_FLTK_File_Chooser::preset_file(const char* val) { +void Fl_Native_File_Chooser_FLTK_Driver::preset_file(const char* val) { _preset_file = strfree(_preset_file); _preset_file = strnew(val); } -const char* Fl_FLTK_File_Chooser::preset_file() const { +const char* Fl_Native_File_Chooser_FLTK_Driver::preset_file() const { return _preset_file; } -int Fl_FLTK_File_Chooser::exist_dialog() { +int Fl_Native_File_Chooser_FLTK_Driver::exist_dialog() { return fl_choice("%s", fl_cancel, fl_ok, NULL, Fl_Native_File_Chooser::file_exists_message); } -#endif - // // End of "$Id$". // |
