summaryrefslogtreecommitdiff
path: root/src/Fl_Native_File_Chooser_GTK.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-04-05 11:25:35 +0000
committerManolo Gouy <Manolo>2016-04-05 11:25:35 +0000
commitfa67aafa9d0c169daf38bc76cef6be3a6ea80d50 (patch)
treeaa0f9fe4941e6d22b103162549b13af7b683829f /src/Fl_Native_File_Chooser_GTK.cxx
parent1dfe31199894a488c1b10eca6c2ee538ebec9ea0 (diff)
Rewrite the Fl_File_Native_Chooser class under the driver model.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11529 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Native_File_Chooser_GTK.cxx')
-rw-r--r--src/Fl_Native_File_Chooser_GTK.cxx109
1 files changed, 87 insertions, 22 deletions
diff --git a/src/Fl_Native_File_Chooser_GTK.cxx b/src/Fl_Native_File_Chooser_GTK.cxx
index 2a972856b..4f10ea4ab 100644
--- a/src/Fl_Native_File_Chooser_GTK.cxx
+++ b/src/Fl_Native_File_Chooser_GTK.cxx
@@ -16,9 +16,11 @@
// http://www.fltk.org/str.php
//
-#include <FL/x.H>
+#include <config.h>
#ifdef USE_X11
+#include <FL/x.H>
+#include <FL/Fl_Native_File_Chooser.H>
#if HAVE_DLSYM && HAVE_DLFCN_H
#include <dlfcn.h> // for dlopen et al
@@ -93,7 +95,51 @@ typedef void (*GClosureNotify)(gpointer data, GClosure *closure);
/* --------------------- End of Type definitions from GLIB and GTK --------------------- */
-int Fl_GTK_File_Chooser::did_find_GTK_libs = 0;
+
+class FL_EXPORT Fl_Native_File_Chooser_GTK_Driver : public Fl_Native_File_Chooser_FLTK_Driver {
+ friend class Fl_Native_File_Chooser;
+private:
+ static int have_looked_for_GTK_libs;
+ typedef struct _GtkWidget GtkWidget;
+ typedef struct _GtkFileFilterInfo GtkFileFilterInfo;
+ struct pair {
+ Fl_Native_File_Chooser_GTK_Driver* running; // the running Fl_GTK_File_Chooser
+ const char *filter; // a filter string of the chooser
+ pair(Fl_Native_File_Chooser_GTK_Driver* 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_Native_File_Chooser_GTK_Driver(int val);
+ virtual ~Fl_Native_File_Chooser_GTK_Driver();
+ 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_Native_File_Chooser_GTK_Driver::pair*);
+ static void free_pair(pair *p);
+};
+
+
+int Fl_Native_File_Chooser_GTK_Driver::did_find_GTK_libs = 0;
/* These are the GTK/GLib methods we want to load, but not call by name...! */
@@ -245,7 +291,26 @@ typedef void (*XX_gtk_toggle_button_set_active)(GtkToggleButton *, gboolean);
static XX_gtk_toggle_button_set_active fl_gtk_toggle_button_set_active = NULL;
-Fl_GTK_File_Chooser::Fl_GTK_File_Chooser(int val) : Fl_FLTK_File_Chooser(-1)
+int Fl_Native_File_Chooser_GTK_Driver::have_looked_for_GTK_libs = 0;
+
+
+Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) {
+ if (Fl_Native_File_Chooser_GTK_Driver::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_Native_File_Chooser_GTK_Driver::probe_for_GTK_libs();
+ }
+#endif
+ Fl_Native_File_Chooser_GTK_Driver::have_looked_for_GTK_libs = -1;
+ }
+ // if we found all the GTK functions we need, we will use the GtkFileChooserDialog
+ if (Fl_Native_File_Chooser_GTK_Driver::did_find_GTK_libs) platform_fnfc = new Fl_Native_File_Chooser_GTK_Driver(val);
+ else platform_fnfc = new Fl_Native_File_Chooser_FLTK_Driver(val);
+}
+
+
+Fl_Native_File_Chooser_GTK_Driver::Fl_Native_File_Chooser_GTK_Driver(int val) : Fl_Native_File_Chooser_FLTK_Driver(-1)
{
gtkw_ptr = NULL; // used to hold a GtkWidget*
gtkw_slist = NULL; // will hold the returned file names in a multi-selection...
@@ -256,7 +321,7 @@ Fl_GTK_File_Chooser::Fl_GTK_File_Chooser(int val) : Fl_FLTK_File_Chooser(-1)
previous_filter = NULL;
}
-Fl_GTK_File_Chooser::~Fl_GTK_File_Chooser()
+Fl_Native_File_Chooser_GTK_Driver::~Fl_Native_File_Chooser_GTK_Driver()
{
// Should free up resources taken for...
if(gtkw_ptr) {
@@ -280,15 +345,15 @@ Fl_GTK_File_Chooser::~Fl_GTK_File_Chooser()
gtkw_title = strfree(gtkw_title);
}
-void Fl_GTK_File_Chooser::type(int val) {
+void Fl_Native_File_Chooser_GTK_Driver::type(int val) {
_btype = val;
}
-int Fl_GTK_File_Chooser::count() const {
+int Fl_Native_File_Chooser_GTK_Driver::count() const {
return gtkw_count;
}
-const char *Fl_GTK_File_Chooser::filename() const
+const char *Fl_Native_File_Chooser_GTK_Driver::filename() const
{
if(gtkw_ptr) {
if(fl_gtk_file_chooser_get_select_multiple((GtkFileChooser *)gtkw_ptr) == FALSE) {
@@ -303,7 +368,7 @@ const char *Fl_GTK_File_Chooser::filename() const
return("");
}
-const char *Fl_GTK_File_Chooser::filename(int i) const
+const char *Fl_Native_File_Chooser_GTK_Driver::filename(int i) const
{
if(fl_gtk_file_chooser_get_select_multiple((GtkFileChooser *)gtkw_ptr) == FALSE) {
return gtkw_filename;
@@ -318,19 +383,19 @@ const char *Fl_GTK_File_Chooser::filename(int i) const
return("");
}
-void Fl_GTK_File_Chooser::title(const char *val)
+void Fl_Native_File_Chooser_GTK_Driver::title(const char *val)
{
strfree(gtkw_title);
gtkw_title = strnew(val);
}
-const char* Fl_GTK_File_Chooser::title() const
+const char* Fl_Native_File_Chooser_GTK_Driver::title() const
{
return gtkw_title;
}
/* changes the extension of the outfile in the chooser according to newly selected filter */
-void Fl_GTK_File_Chooser::changed_output_type(const char *filter)
+void Fl_Native_File_Chooser_GTK_Driver::changed_output_type(const char *filter)
{
if ( !(options()&Fl_Native_File_Chooser::USE_FILTER_EXT) ) return;
if (strchr(filter, '(') || strchr(filter, '{') || strchr(filter+1, '*') || strncmp(filter, "*.", 2)) return;
@@ -348,7 +413,7 @@ void Fl_GTK_File_Chooser::changed_output_type(const char *filter)
/* Filters files before display in chooser.
Also used to detect when the filter just changed */
-gboolean Fl_GTK_File_Chooser::custom_gtk_filter_function(const GtkFileFilterInfo *info, Fl_GTK_File_Chooser::pair* p)
+gboolean Fl_Native_File_Chooser_GTK_Driver::custom_gtk_filter_function(const GtkFileFilterInfo *info, Fl_Native_File_Chooser_GTK_Driver::pair* p)
{
if (p->running->previous_filter != p->filter) {
p->running->changed_output_type(p->filter);
@@ -357,7 +422,7 @@ gboolean Fl_GTK_File_Chooser::custom_gtk_filter_function(const GtkFileFilterInfo
return (gboolean)fl_filename_match(fl_filename_name(info->filename), p->filter);
}
-void Fl_GTK_File_Chooser::free_pair(Fl_GTK_File_Chooser::pair *p)
+void Fl_Native_File_Chooser_GTK_Driver::free_pair(Fl_Native_File_Chooser_GTK_Driver::pair *p)
{
delete p;
}
@@ -368,7 +433,7 @@ static void hidden_files_cb(GtkToggleButton *togglebutton, gpointer user_data)
fl_gtk_file_chooser_set_show_hidden((GtkFileChooser*)user_data, state);
}
-int Fl_GTK_File_Chooser::show()
+int Fl_Native_File_Chooser_GTK_Driver::show()
{
// The point here is that after running a GTK dialog, the calling program's current locale is modified.
// To avoid that, we memorize the calling program's current locale, and the locale as modified
@@ -424,7 +489,7 @@ static void run_response_handler(GtkDialog *dialog, gint response_id, gpointer d
}
-int Fl_GTK_File_Chooser::fl_gtk_chooser_wrapper()
+int Fl_Native_File_Chooser_GTK_Driver::fl_gtk_chooser_wrapper()
{
int result = 1;
static int have_gtk_init = 0;
@@ -521,9 +586,9 @@ int Fl_GTK_File_Chooser::fl_gtk_chooser_wrapper()
char *q = strchr(p, ')'); *q = 0;
fl_gtk_file_filter_add_custom(filter_tab[count],
GTK_FILE_FILTER_FILENAME,
- (GtkFileFilterFunc)Fl_GTK_File_Chooser::custom_gtk_filter_function,
- new Fl_GTK_File_Chooser::pair(this, p),
- (GDestroyNotify)Fl_GTK_File_Chooser::free_pair);
+ (GtkFileFilterFunc)Fl_Native_File_Chooser_GTK_Driver::custom_gtk_filter_function,
+ new Fl_Native_File_Chooser_GTK_Driver::pair(this, p),
+ (GDestroyNotify)Fl_Native_File_Chooser_GTK_Driver::free_pair);
fl_gtk_file_chooser_add_filter((GtkFileChooser *)gtkw_ptr, filter_tab[count]);
p = strtok(NULL, "\t");
count++;
@@ -642,14 +707,14 @@ static void* fl_dlopen(const char *filename1, const char *filename2)
if (!ptr) ptr = dlopen(filename2, RTLD_LAZY | RTLD_GLOBAL);
return ptr;
}
-#endif
+#endif // HAVE_DLSYM && HAVE_DLFCN_H
/*
* Use dlopen to see if we can load the gtk dynamic libraries that
* will allow us to create a GtkFileChooserDialog() on the fly,
* without linking to the GTK libs at compile time.
*/
-void Fl_GTK_File_Chooser::probe_for_GTK_libs(void) {
+void Fl_Native_File_Chooser_GTK_Driver::probe_for_GTK_libs(void) {
#if HAVE_DLSYM && HAVE_DLFCN_H
void *ptr_glib = NULL;
void *ptr_gtk = NULL;
@@ -728,10 +793,10 @@ void Fl_GTK_File_Chooser::probe_for_GTK_libs(void) {
GET_SYM(gtk_toggle_button_set_active, ptr_gtk);
did_find_GTK_libs = 1;
-#endif
+#endif // HAVE_DLSYM && HAVE_DLFCN_H
} // probe_for_GTK_libs
-#endif
+#endif // USE_X11
//
// End of "$Id$".