00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00023 #ifndef FL_NATIVE_FILE_CHOOSER_H
00024 #define FL_NATIVE_FILE_CHOOSER_H
00025
00026
00027 #ifdef WIN32
00028
00029 #if defined(FL_LIBRARY) || FLTK_ABI_VERSION < 10304
00030 # include <windows.h>
00031 # include <commdlg.h>
00032 # include <shlobj.h>
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
00042 #ifdef __APPLE__
00043 # define MAXFILTERS 80
00044 #endif
00045
00046
00047 #if ! defined(__APPLE__) && !defined(WIN32)
00048 # include <FL/Fl_File_Chooser.H>
00049 #else
00050 # include <FL/filename.H>
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
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;
00160 int _options;
00161 #if FLTK_ABI_VERSION >= 10304
00162 fl_OPENFILENAMEW *_ofn_ptr;
00163 fl_BROWSEINFOW *_binf_ptr;
00164 WCHAR *_wpattern;
00165 #else
00166 fl_OPENFILENAMEW _ofn;
00167 fl_BROWSEINFOW _binf;
00168 #endif
00169 char **_pathnames;
00170 int _tpathnames;
00171 char *_directory;
00172 char *_title;
00173 char *_filter;
00174 char *_parsedfilt;
00175 int _nfilters;
00176 char *_preset_file;
00177 char *_errmsg;
00178
00179
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;
00201 int _options;
00202 void *_panel;
00203 char **_pathnames;
00204 int _tpathnames;
00205 char *_directory;
00206 char *_title;
00207 char *_preset_file;
00208
00209 char *_filter;
00210
00211
00212 char *_filt_names;
00213
00214
00215 char *_filt_patt[MAXFILTERS];
00216
00217
00218
00219
00220 int _filt_total;
00221 int _filt_value;
00222 char *_errmsg;
00223
00224
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;
00240 int _options;
00241 int _nfilters;
00242 char *_filter;
00243 char *_parsedfilt;
00244 int _filtvalue;
00245 char *_preset_file;
00246 char *_prevvalue;
00247 char *_directory;
00248 char *_errmsg;
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;
00263 int _options;
00264 int _nfilters;
00265 char *_filter;
00266 char *_parsedfilt;
00267 int _filtvalue;
00268 char *_preset_file;
00269 char *_prevvalue;
00270 char *_directory;
00271 char *_errmsg;
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;
00309 const char *filter;
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;
00319 void *gtkw_slist;
00320 unsigned gtkw_count;
00321 mutable char *gtkw_filename;
00322 char *gtkw_title;
00323 const char *previous_filter;
00324
00325 int fl_gtk_chooser_wrapper();
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
00345
00346
00347
00348