STR #3088: make Fl_Native_File_Chooser use the standard GTK file dialog when available.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10186 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy
2014-06-07 12:01:59 +00:00
parent 460544455d
commit baebff2227
7 changed files with 1169 additions and 320 deletions
+4 -1
View File
@@ -1,7 +1,10 @@
CHANGES IN FLTK 1.3.3 RELEASED: MMM DD YYYY CHANGES IN FLTK 1.3.3 RELEASED: MMM DD YYYY
- on Linux/Unix, class Fl_Native_File_Chooser uses file dialogs of the Gnome
environment (provided by the libgtk dynamic library), when this is available,
and falls back to FLTK's Fl_File_Chooser, when it's not (STR #3088).
- added class Fl_Copy_Surface allowing to copy graphical data to the clipboard - added class Fl_Copy_Surface allowing to copy graphical data to the clipboard
in a cross-platform way. in a cross-platform way (STR #3058).
- added support for pasting graphical data from the clipboard to an FLTK widget. - added support for pasting graphical data from the clipboard to an FLTK widget.
- added class Fl_Image_Surface allowing to draw into an Fl_Image object. - added class Fl_Image_Surface allowing to draw into an Fl_Image object.
- removed constraint that lines are limited to 1024 chars in widget labels and browser lines (STR #2990). - removed constraint that lines are limited to 1024 chars in widget labels and browser lines (STR #2990).
+8 -4
View File
@@ -173,7 +173,7 @@ public:
/// a text in a text widget will change focus to the next text widget. /// a text in a text widget will change focus to the next text widget.
/// (This is considered 'old' behavior) /// (This is considered 'old' behavior)
/// ///
/// When switched off, the cursor will stop at the end of the text. /// When switched off (default), the cursor will stop at the end of the text.
/// Pressing Tab or Ctrl-Tab will advance the keyboard focus. /// Pressing Tab or Ctrl-Tab will advance the keyboard focus.
/// ///
/// See also: Fl_Input_::tab_nav() /// See also: Fl_Input_::tab_nav()
@@ -189,19 +189,23 @@ public:
// decides to choose the file. // decides to choose the file.
// \todo implement me // \todo implement me
//OPTION_FILECHOOSER_PREVIEW, //OPTION_FILECHOOSER_PREVIEW,
/// If visible focus is switched on, FLTK will draw a dotted rectangle /// If visible focus is switched on (default), FLTK will draw a dotted rectangle
/// inside the widget that will receive the next keystroke. If switched /// inside the widget that will receive the next keystroke. If switched
/// off, no such indicator will be drawn and keyboard navigation /// off, no such indicator will be drawn and keyboard navigation
/// is disabled. /// is disabled.
OPTION_VISIBLE_FOCUS, OPTION_VISIBLE_FOCUS,
/// If text drag-and-drop is enabled, the user can select and drag text /// If text drag-and-drop is enabled (default), the user can select and drag text
/// from any text widget. If disabled, no dragging is possible, however /// from any text widget. If disabled, no dragging is possible, however
/// dropping text from other applications still works. /// dropping text from other applications still works.
OPTION_DND_TEXT, OPTION_DND_TEXT,
/// If tooltips are enabled, hovering the mouse over a widget with a /// If tooltips are enabled (default), hovering the mouse over a widget with a
/// tooltip text will open a little tooltip window until the mouse leaves /// tooltip text will open a little tooltip window until the mouse leaves
/// the widget. If disabled, no tooltip is shown. /// the widget. If disabled, no tooltip is shown.
OPTION_SHOW_TOOLTIPS, OPTION_SHOW_TOOLTIPS,
/// When switched on (default), Fl_Native_File_Chooser runs GTK file dialogs
/// if the GTK library is available on the platform (linux/unix only).
/// When switched off, GTK file dialogs aren't used even if the GTK library is available.
OPTION_FNFC_USES_GTK,
// don't change this, leave it always as the last element // don't change this, leave it always as the last element
/// For internal use only. /// For internal use only.
OPTION_LAST OPTION_LAST
+153 -67
View File
@@ -3,7 +3,7 @@
// //
// FLTK native OS file chooser widget // FLTK native OS file chooser widget
// //
// Copyright 1998-2010 by Bill Spitzak and others. // Copyright 1998-2014 by Bill Spitzak and others.
// Copyright 2004 Greg Ercolano. // Copyright 2004 Greg Ercolano.
// //
// This library is free software. Distribution and use rights are outlined in // This library is free software. Distribution and use rights are outlined in
@@ -23,47 +23,46 @@
#ifndef FL_NATIVE_FILE_CHOOSER_H #ifndef FL_NATIVE_FILE_CHOOSER_H
#define FL_NATIVE_FILE_CHOOSER_H #define FL_NATIVE_FILE_CHOOSER_H
/* \file
Fl_Native_File_Chooser widget. */
// Use Windows' chooser // Use Windows' chooser
#ifdef WIN32 #ifdef WIN32
// #define _WIN32_WINNT 0x0501 // needed for OPENFILENAME's 'FlagsEx' // #define _WIN32_WINNT 0x0501 // needed for OPENFILENAME's 'FlagsEx'
#include <stdio.h> # include <stdio.h>
#include <stdlib.h> // malloc # include <stdlib.h> // malloc
#include <windows.h> # include <windows.h>
#include <commdlg.h> // OPENFILENAME, GetOpenFileName() # include <commdlg.h> // OPENFILENAME, GetOpenFileName()
#include <shlobj.h> // BROWSEINFO, SHBrowseForFolder() # include <shlobj.h> // BROWSEINFO, SHBrowseForFolder()
#endif #endif
// Use Apple's chooser // Use Apple's chooser
#ifdef __APPLE__ #ifdef __APPLE__
#define MAXFILTERS 80 # define MAXFILTERS 80
#endif #endif
// All else falls back to FLTK's own chooser // All else falls back to FLTK's own chooser
#if ! defined(__APPLE__) && !defined(WIN32) #if ! defined(__APPLE__) && !defined(WIN32)
#include <FL/Fl_File_Chooser.H> # include <FL/Fl_File_Chooser.H>
#include <unistd.h> // _POSIX_NAME_MAX # include <unistd.h> // _POSIX_NAME_MAX
#else #else
#include <FL/filename.H> // FL_EXPORT # include <FL/filename.H> // FL_EXPORT
#endif #endif
class Fl_FLTK_File_Chooser;
class Fl_GTK_File_Chooser;
/** /**
This class lets an FLTK application easily and consistently access This class lets an FLTK application easily and consistently access
the operating system's native file chooser. Some operating systems the operating system's native file chooser. Some operating systems
have very complex and specific file choosers that many users want have very complex and specific file choosers that many users want
access to specifically, instead of FLTK's default file chooser(s). access to specifically, instead of FLTK's default file chooser(s).
In cases where there is no native file browser, FLTK's own file browser In cases where there is no native file browser, FLTK's own file browser
is used instead. is used instead.
To use this widget, use the following include in your code: To use this widget, use the following include in your code:
\code \code
#include <FL/Fl_Native_File_Chooser.H> #include <FL/Fl_Native_File_Chooser.H>
\endcode \endcode
The following example shows how to pick a single file: The following example shows how to pick a single file:
\code \code
// Create and post the local native file chooser // Create and post the local native file chooser
@@ -82,25 +81,28 @@
default: printf("PICKED: %s\n", fnfc.filename()); break; // FILE CHOSEN default: printf("PICKED: %s\n", fnfc.filename()); break; // FILE CHOSEN
} }
\endcode \endcode
The Fl_Native_File_Chooser widget transmits UTF-8 encoded filenames to its user. It is The Fl_Native_File_Chooser widget transmits UTF-8 encoded filenames to its user. It is
recommended to open files that may have non-ASCII names with the fl_fopen() or recommended to open files that may have non-ASCII names with the fl_fopen() or
fl_open() utility functions that handle these names in a cross-platform way fl_open() utility functions that handle these names in a cross-platform way
(whereas the standard fopen()/open() functions fail on the MSWindows platform (whereas the standard fopen()/open() functions fail on the MSWindows platform
to open files with a non-ASCII name). to open files with a non-ASCII name).
<B>Platform Specific Caveats</B> <B>Platform Specific Caveats</B>
- Under X windows, it's best if you call Fl_File_Icon::load_system_icons() - Under X windows, and if Fl::OPTION_FNFC_USES_GTK has not been switched off,
the widget attempts to use standard GTK file chooser dialogs if they are
available at run-time on the platform, and falls back to use FLTK's Fl_File_Chooser if they are not.
In the latter case, it's best if you call Fl_File_Icon::load_system_icons()
at the start of main(), to enable the nicer looking file browser widgets. at the start of main(), to enable the nicer looking file browser widgets.
Use the static public attributes of class Fl_File_Chooser to localize Use the static public attributes of class Fl_File_Chooser to localize
the browser. the browser.
- Some operating systems support certain OS specific options; see - Some operating systems support certain OS specific options; see
Fl_Native_File_Chooser::options() for a list. Fl_Native_File_Chooser::options() for a list.
\image html Fl_Native_File_Chooser.png "The Fl_Native_File_Chooser on different platforms." \image html Fl_Native_File_Chooser.png "The Fl_Native_File_Chooser on different platforms."
\image latex Fl_Native_File_Chooser.png "The Fl_Native_File_Chooser on different platforms" width=14cm \image latex Fl_Native_File_Chooser.png "The Fl_Native_File_Chooser on different platforms" width=14cm
*/ */
class FL_EXPORT Fl_Native_File_Chooser { class FL_EXPORT Fl_Native_File_Chooser {
public: public:
@@ -121,39 +123,39 @@ public:
}; };
/** Localizable message */ /** Localizable message */
static const char *file_exists_message; static const char *file_exists_message;
public: public:
Fl_Native_File_Chooser(int val=BROWSE_FILE); Fl_Native_File_Chooser(int val=BROWSE_FILE);
~Fl_Native_File_Chooser(); ~Fl_Native_File_Chooser();
// Public methods // Public methods
void type(int); void type(int t);
int type() const; int type() const ;
void options(int); void options(int o);
int options() const; int options() const;
int count() const; int count() const;
const char *filename() const; const char *filename() const ;
const char *filename(int i) const; const char *filename(int i) const ;
void directory(const char *val); void directory(const char *val) ;
const char *directory() const; const char *directory() const;
void title(const char *); void title(const char *t);
const char* title() const; const char* title() const;
const char *filter() const; const char *filter() const ;
void filter(const char *); void filter(const char *f);
int filters() const; int filters() const ;
void filter_value(int i); void filter_value(int i) ;
int filter_value() const; int filter_value() const ;
void preset_file(const char*); void preset_file(const char*f) ;
const char* preset_file() const; const char* preset_file() const;
const char *errmsg() const; const char *errmsg() const ;
int show(); int show() ;
#ifdef WIN32 #ifdef WIN32
private: private:
int _btype; // kind-of browser to show() int _btype; // kind-of browser to show()
int _options; // general options int _options; // general options
OPENFILENAMEW _ofn; // GetOpenFileName() & GetSaveFileName() struct OPENFILENAMEW _ofn; // GetOpenFileName() & GetSaveFileName() struct
BROWSEINFOW _binf; // SHBrowseForFolder() struct BROWSEINFOW _binf; // SHBrowseForFolder() struct
char **_pathnames; // array of pathnames char **_pathnames; // array of pathnames
int _tpathnames; // total pathnames int _tpathnames; // total pathnames
char *_directory; // default pathname to use char *_directory; // default pathname to use
@@ -163,14 +165,14 @@ private:
int _nfilters; // number of filters parse_filter counted int _nfilters; // number of filters parse_filter counted
char *_preset_file; // the file to preselect char *_preset_file; // the file to preselect
char *_errmsg; // error message char *_errmsg; // error message
// Private methods // Private methods
void errmsg(const char *msg); void errmsg(const char *msg);
void clear_pathnames(); void clear_pathnames();
void set_single_pathname(const char *s); void set_single_pathname(const char *s);
void add_pathname(const char *s); void add_pathname(const char *s);
void FreePIDL(LPITEMIDLIST pidl); void FreePIDL(LPITEMIDLIST pidl);
void ClearOFN(); void ClearOFN();
void ClearBINF(); void ClearBINF();
@@ -179,7 +181,7 @@ private:
int showfile(); int showfile();
static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data); static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
int showdir(); int showdir();
void parse_filter(const char *); void parse_filter(const char *);
void clear_filters(); void clear_filters();
void add_filter(const char *, const char *); void add_filter(const char *, const char *);
@@ -195,22 +197,22 @@ private:
char *_directory; // default pathname to use char *_directory; // default pathname to use
char *_title; // title for window char *_title; // title for window
char *_preset_file; // the 'save as' filename char *_preset_file; // the 'save as' filename
char *_filter; // user-side search filter, eg: char *_filter; // user-side search filter, eg:
// C Files\t*.[ch]\nText Files\t*.txt" // C Files\t*.[ch]\nText Files\t*.txt"
char *_filt_names; // filter names (tab delimited) char *_filt_names; // filter names (tab delimited)
// eg. "C Files\tText Files" // eg. "C Files\tText Files"
char *_filt_patt[MAXFILTERS]; char *_filt_patt[MAXFILTERS];
// array of filter patterns, eg: // array of filter patterns, eg:
// _filt_patt[0]="*.{cxx,h}" // _filt_patt[0]="*.{cxx,h}"
// _filt_patt[1]="*.txt" // _filt_patt[1]="*.txt"
int _filt_total; // parse_filter() # of filters loaded int _filt_total; // parse_filter() # of filters loaded
int _filt_value; // index of the selected filter int _filt_value; // index of the selected filter
char *_errmsg; // error message char *_errmsg; // error message
// Private methods // Private methods
void errmsg(const char *msg); void errmsg(const char *msg);
void clear_pathnames(); void clear_pathnames();
@@ -225,6 +227,7 @@ private:
#if ! defined(__APPLE__) && !defined(WIN32) #if ! defined(__APPLE__) && !defined(WIN32)
private: private:
#if FLTK_ABI_VERSION <= 10302
int _btype; // kind-of browser to show() int _btype; // kind-of browser to show()
int _options; // general options int _options; // general options
int _nfilters; int _nfilters;
@@ -235,17 +238,100 @@ private:
char *_prevvalue; // Returned filename char *_prevvalue; // Returned filename
char *_directory; char *_directory;
char *_errmsg; // error message char *_errmsg; // error message
Fl_File_Chooser *_file_chooser; #endif
static int have_looked_for_GTK_libs;
// Private methods union {
void errmsg(const char *msg); Fl_FLTK_File_Chooser *_x11_file_chooser;
int type_fl_file(int); Fl_GTK_File_Chooser *_gtk_file_chooser;
void parse_filter(); };
void keeplocation();
int exist_dialog();
#endif #endif
}; };
#if !defined(__APPLE__) && !defined(WIN32)
class Fl_FLTK_File_Chooser {
friend class Fl_Native_File_Chooser;
protected:
int _btype; // kind-of browser to show()
int _options; // general options
int _nfilters;
char *_filter; // user supplied filter
char *_parsedfilt; // parsed filter
int _filtvalue; // selected filter
char *_preset_file;
char *_prevvalue; // Returned filename
char *_directory;
char *_errmsg; // error message
Fl_FLTK_File_Chooser(int val);
virtual ~Fl_FLTK_File_Chooser();
void errmsg(const char *msg);
int type_fl_file(int);
void parse_filter();
int exist_dialog();
Fl_File_Chooser *_file_chooser;
virtual void type(int);
int type() const;
void options(int);
int options() const;
virtual int count() const;
virtual const char *filename() const;
virtual const char *filename(int i) const;
void directory(const char *val);
const char *directory() const;
virtual void title(const char *);
virtual const char* title() const;
const char *filter() const;
void filter(const char *);
int filters() const;
void filter_value(int i);
int filter_value() const;
void preset_file(const char*);
const char* preset_file() const;
const char *errmsg() const;
virtual int show();
};
class Fl_GTK_File_Chooser : public Fl_FLTK_File_Chooser {
friend class Fl_Native_File_Chooser;
private:
typedef struct _GtkWidget GtkWidget;
typedef struct _GtkFileFilterInfo GtkFileFilterInfo;
struct pair {
Fl_GTK_File_Chooser* running; // the running Fl_GTK_File_Chooser
const char *filter; // a filter string of the chooser
pair(Fl_GTK_File_Chooser* c, const char *f) {
running = c;
filter = strdup(f);
};
~pair() {
free((char*)filter);
};
};
GtkWidget *gtkw_ptr; // used to hold a GtkWidget* without pulling GTK into everything...
void *gtkw_slist; // used to hold a GLib GSList...
unsigned gtkw_count; // number of files read back - if any
mutable char *gtkw_filename; // last name we read back
char *gtkw_title; // the title to be applied to the dialog
const char *previous_filter;
int fl_gtk_chooser_wrapper(); // method that wraps the GTK widget
Fl_GTK_File_Chooser(int val);
virtual ~Fl_GTK_File_Chooser();
static int did_find_GTK_libs;
static void probe_for_GTK_libs(void);
virtual void type(int);
virtual int count() const;
virtual const char *filename() const;
virtual const char *filename(int i) const;
virtual void title(const char *);
virtual const char* title() const;
virtual int show();
void changed_output_type(const char *filter);
static int custom_gtk_filter_function(const GtkFileFilterInfo*, Fl_GTK_File_Chooser::pair*);
static void free_pair(pair *p);
};
#endif // !defined(__APPLE__) && !defined(WIN32)
#endif /*FL_NATIVE_FILE_CHOOSER_H*/ #endif /*FL_NATIVE_FILE_CHOOSER_H*/
Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 401 KiB

+4
View File
@@ -2069,6 +2069,8 @@ bool Fl::option(Fl_Option opt)
options_[OPTION_DND_TEXT] = tmp; options_[OPTION_DND_TEXT] = tmp;
opt_prefs.get("ShowTooltips", tmp, 1); // default: on opt_prefs.get("ShowTooltips", tmp, 1); // default: on
options_[OPTION_SHOW_TOOLTIPS] = tmp; options_[OPTION_SHOW_TOOLTIPS] = tmp;
opt_prefs.get("FNFCUsesGTK", tmp, 1); // default: on
options_[OPTION_FNFC_USES_GTK] = tmp;
} }
{ // next, check the user preferences { // next, check the user preferences
// override system options only, if the option is set ( >= 0 ) // override system options only, if the option is set ( >= 0 )
@@ -2086,6 +2088,8 @@ bool Fl::option(Fl_Option opt)
if (tmp >= 0) options_[OPTION_DND_TEXT] = tmp; if (tmp >= 0) options_[OPTION_DND_TEXT] = tmp;
opt_prefs.get("ShowTooltips", tmp, -1); opt_prefs.get("ShowTooltips", tmp, -1);
if (tmp >= 0) options_[OPTION_SHOW_TOOLTIPS] = tmp; if (tmp >= 0) options_[OPTION_SHOW_TOOLTIPS] = tmp;
opt_prefs.get("FNFCUsesGTK", tmp, -1);
if (tmp >= 0) options_[OPTION_FNFC_USES_GTK] = tmp;
} }
{ // now, if the developer has registered this app, we could as for per-application preferences { // now, if the developer has registered this app, we could as for per-application preferences
} }
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff