• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

Fl_Native_File_Chooser.H

Go to the documentation of this file.
00001 //
00002 // "$Id$"
00003 //
00004 // FLTK native OS file chooser widget
00005 //
00006 // Copyright 1998-2014 by Bill Spitzak and others.
00007 // Copyright 2004 Greg Ercolano.
00008 //
00009 // This library is free software. Distribution and use rights are outlined in
00010 // the file "COPYING" which should have been included with this file.  If this
00011 // file is missing or damaged, see the license at:
00012 //
00013 //     http://www.fltk.org/COPYING.php
00014 //
00015 // Please report all bugs and problems on the following page:
00016 //
00017 //     http://www.fltk.org/str.php
00018 //
00019 
00023 #ifndef FL_NATIVE_FILE_CHOOSER_H
00024 #define FL_NATIVE_FILE_CHOOSER_H
00025 
00026 // Use Windows' chooser
00027 #ifdef WIN32
00028 // #define _WIN32_WINNT 0x0501  // needed for OPENFILENAME's 'FlagsEx'
00029 #if defined(FL_LIBRARY) || FLTK_ABI_VERSION < 10304
00030 #  include <windows.h>
00031 #  include <commdlg.h>          // OPENFILENAMEW, GetOpenFileName()
00032 #  include <shlobj.h>           // BROWSEINFOW, SHBrowseForFolder()
00033 typedef OPENFILENAMEW fl_OPENFILENAMEW;
00034 typedef BROWSEINFOW fl_BROWSEINFOW;
00035 #else
00036 typedef void fl_OPENFILENAMEW;
00037 typedef void fl_BROWSEINFOW;
00038 #endif
00039 #endif
00040 
00041 // Use Apple's chooser
00042 #ifdef __APPLE__
00043 #  define MAXFILTERS    80
00044 #endif
00045 
00046 // All else falls back to FLTK's own chooser
00047 #if ! defined(__APPLE__) && !defined(WIN32)
00048 #  include <FL/Fl_File_Chooser.H>
00049 #else
00050 #  include <FL/filename.H>      // FL_EXPORT
00051 #endif
00052 
00053 class Fl_FLTK_File_Chooser;
00054 class Fl_GTK_File_Chooser;
00055 
00111 class FL_EXPORT Fl_Native_File_Chooser {
00112 public:
00113   enum Type {
00114     BROWSE_FILE = 0,                    
00115     BROWSE_DIRECTORY,                   
00116     BROWSE_MULTI_FILE,                  
00117     BROWSE_MULTI_DIRECTORY,             
00118     BROWSE_SAVE_FILE,                   
00119     BROWSE_SAVE_DIRECTORY               
00120   };
00121   enum Option {
00122     NO_OPTIONS     = 0x0000,            
00123     SAVEAS_CONFIRM = 0x0001,            
00124     NEW_FOLDER     = 0x0002,            
00125     PREVIEW        = 0x0004,            
00126     USE_FILTER_EXT = 0x0008             
00127   };
00129   static const char *file_exists_message;
00130   
00131 public:
00132   Fl_Native_File_Chooser(int val=BROWSE_FILE);
00133   ~Fl_Native_File_Chooser();
00134   
00135   // Public methods
00136   void type(int t);
00137   int type() const ;
00138   void options(int o);
00139   int options() const;
00140   int count() const;
00141   const char *filename() const ;
00142   const char *filename(int i) const ;
00143   void directory(const char *val) ;
00144   const char *directory() const;
00145   void title(const char *t);
00146   const char* title() const;
00147   const char *filter() const ;
00148   void filter(const char *f);
00149   int filters() const ;
00150   void filter_value(int i) ;
00151   int filter_value() const ;
00152   void preset_file(const char*f) ;
00153   const char* preset_file() const;
00154   const char *errmsg() const ;
00155   int show() ;
00156   
00157 #ifdef WIN32
00158 private:
00159   int  _btype;                  // kind-of browser to show()
00160   int  _options;                // general options
00161 #if FLTK_ABI_VERSION >= 10304
00162   fl_OPENFILENAMEW *_ofn_ptr;   // GetOpenFileName() & GetSaveFileName() struct
00163   fl_BROWSEINFOW   *_binf_ptr;  // SHBrowseForFolder() struct
00164   WCHAR            *_wpattern;  // pattern buffer for filter
00165 #else
00166   fl_OPENFILENAMEW _ofn;
00167   fl_BROWSEINFOW   _binf;
00168 #endif
00169   char  **_pathnames;           // array of pathnames
00170   int     _tpathnames;          // total pathnames
00171   char   *_directory;           // default pathname to use
00172   char   *_title;               // title for window
00173   char   *_filter;              // user-side search filter
00174   char   *_parsedfilt;          // filter parsed for Windows dialog
00175   int     _nfilters;            // number of filters parse_filter counted
00176   char   *_preset_file;         // the file to preselect
00177   char   *_errmsg;              // error message
00178   
00179   // Private methods
00180   void errmsg(const char *msg);
00181   
00182   void clear_pathnames();
00183   void set_single_pathname(const char *s);
00184   void add_pathname(const char *s);
00185   
00186   void ClearOFN();
00187   void ClearBINF();
00188   void Win2Unix(char *s);
00189   void Unix2Win(char *s);
00190   int showfile();
00191   int showdir();
00192   
00193   void parse_filter(const char *);
00194   void clear_filters();
00195   void add_filter(const char *, const char *);
00196 #endif
00197 
00198 #ifdef __APPLE__
00199 private:
00200   int             _btype;               // kind-of browser to show()
00201   int             _options;             // general options
00202   void           *_panel;
00203   char          **_pathnames;           // array of pathnames
00204   int             _tpathnames;          // total pathnames
00205   char           *_directory;           // default pathname to use
00206   char           *_title;               // title for window
00207   char           *_preset_file;         // the 'save as' filename
00208   
00209   char           *_filter;              // user-side search filter, eg:
00210   // C Files\t*.[ch]\nText Files\t*.txt"
00211   
00212   char           *_filt_names;          // filter names (tab delimited)
00213   // eg. "C Files\tText Files"
00214   
00215   char           *_filt_patt[MAXFILTERS];
00216   // array of filter patterns, eg:
00217   //     _filt_patt[0]="*.{cxx,h}"
00218   //     _filt_patt[1]="*.txt"
00219   
00220   int             _filt_total;          // parse_filter() # of filters loaded
00221   int             _filt_value;          // index of the selected filter
00222   char           *_errmsg;              // error message
00223   
00224   // Private methods
00225   void errmsg(const char *msg);
00226   void clear_pathnames();
00227   void set_single_pathname(const char *s);
00228   int get_saveas_basename(void);
00229   void clear_filters();
00230   void add_filter(const char *, const char *);
00231   void parse_filter(const char *from);
00232   int post();
00233   int runmodal();
00234 #endif
00235 
00236 #if ! defined(__APPLE__) && !defined(WIN32)
00237 private:
00238 #if FLTK_ABI_VERSION <= 10302
00239   int   _btype;                 // kind-of browser to show()
00240   int   _options;               // general options
00241   int   _nfilters;
00242   char *_filter;                // user supplied filter
00243   char *_parsedfilt;            // parsed filter
00244   int   _filtvalue;             // selected filter
00245   char *_preset_file;
00246   char *_prevvalue;             // Returned filename
00247   char *_directory;
00248   char *_errmsg;                // error message
00249 #endif
00250   static int have_looked_for_GTK_libs;
00251   union {
00252     Fl_FLTK_File_Chooser *_x11_file_chooser;
00253     Fl_GTK_File_Chooser *_gtk_file_chooser;
00254   };
00255 #endif
00256 };
00257 
00258 #if !defined(__APPLE__) && !defined(WIN32)
00259 class FL_EXPORT Fl_FLTK_File_Chooser {
00260   friend class Fl_Native_File_Chooser;
00261 protected:
00262   int   _btype;                 // kind-of browser to show()
00263   int   _options;               // general options
00264   int   _nfilters;
00265   char *_filter;                // user supplied filter
00266   char *_parsedfilt;            // parsed filter
00267   int   _filtvalue;             // selected filter
00268   char *_preset_file;
00269   char *_prevvalue;             // Returned filename
00270   char *_directory;
00271   char *_errmsg;                // error message
00272   Fl_FLTK_File_Chooser(int val);
00273   virtual ~Fl_FLTK_File_Chooser();
00274   void errmsg(const char *msg);
00275   int type_fl_file(int);
00276   void parse_filter();
00277   int exist_dialog();
00278   Fl_File_Chooser *_file_chooser;
00279   virtual void type(int);
00280   int type() const;
00281   void options(int);
00282   int options() const;
00283   virtual int count() const;
00284   virtual const char *filename() const;
00285   virtual const char *filename(int i) const;
00286   void directory(const char *val);
00287   const char *directory() const;
00288   virtual void title(const char *);
00289   virtual const char* title() const;
00290   const char *filter() const;
00291   void filter(const char *);
00292   int filters() const;
00293   void filter_value(int i);
00294   int filter_value() const;
00295   void preset_file(const char*);
00296   const char* preset_file() const;
00297   const char *errmsg() const;
00298   virtual int show();
00299 };
00300 
00301 
00302 class FL_EXPORT Fl_GTK_File_Chooser : public Fl_FLTK_File_Chooser {
00303   friend class Fl_Native_File_Chooser;
00304 private:
00305   typedef struct _GtkWidget GtkWidget;
00306   typedef struct _GtkFileFilterInfo GtkFileFilterInfo;
00307   struct pair {
00308     Fl_GTK_File_Chooser* running; // the running Fl_GTK_File_Chooser
00309     const char *filter; // a filter string of the chooser
00310     pair(Fl_GTK_File_Chooser* c, const char *f) {
00311       running = c; 
00312       filter = strdup(f);
00313     };
00314     ~pair() {
00315       free((char*)filter);
00316     };
00317   };
00318   GtkWidget *gtkw_ptr; // used to hold a GtkWidget* without pulling GTK into everything...
00319   void *gtkw_slist; // used to hold a GLib GSList...
00320   unsigned gtkw_count; // number of files read back - if any
00321   mutable char *gtkw_filename; // last name we read back
00322   char *gtkw_title; // the title to be applied to the dialog
00323   const char *previous_filter;
00324   
00325   int fl_gtk_chooser_wrapper(); // method that wraps the GTK widget
00326   Fl_GTK_File_Chooser(int val);
00327   virtual ~Fl_GTK_File_Chooser();
00328   static int did_find_GTK_libs;
00329   static void probe_for_GTK_libs(void);
00330   virtual void type(int);
00331   virtual int count() const;
00332   virtual const char *filename() const;
00333   virtual const char *filename(int i) const;
00334   virtual void title(const char *);
00335   virtual const char* title() const;
00336   virtual int show();
00337   void changed_output_type(const char *filter);
00338   
00339   static int custom_gtk_filter_function(const GtkFileFilterInfo*, Fl_GTK_File_Chooser::pair*);
00340   static void free_pair(pair *p);
00341 };
00342 #endif // !defined(__APPLE__) && !defined(WIN32)
00343 
00344 #endif /*FL_NATIVE_FILE_CHOOSER_H*/
00345 
00346 //
00347 // End of "$Id$".
00348 //
  • © 1998-2016 by Bill Spitzak and others.     FLTK

  • © 1998-2016 by Bill Spitzak and others.     FLTK

    Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.