FLTK 1.3.4

Fl_Native_File_Chooser.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl_Native_File_Chooser.H 11188 2016-02-18 04:21:27Z greg.ercolano $"
3 //
4 // FLTK native OS file chooser widget
5 //
6 // Copyright 1998-2014 by Bill Spitzak and others.
7 // Copyright 2004 Greg Ercolano.
8 //
9 // This library is free software. Distribution and use rights are outlined in
10 // the file "COPYING" which should have been included with this file. If this
11 // file is missing or damaged, see the license at:
12 //
13 // http://www.fltk.org/COPYING.php
14 //
15 // Please report all bugs and problems on the following page:
16 //
17 // http://www.fltk.org/str.php
18 //
19
23 #ifndef FL_NATIVE_FILE_CHOOSER_H
24 #define FL_NATIVE_FILE_CHOOSER_H
25
26 // Use Windows' chooser
27 #ifdef WIN32
28 // #define _WIN32_WINNT 0x0501 // needed for OPENFILENAME's 'FlagsEx'
29 #if defined(FL_LIBRARY) || FLTK_ABI_VERSION < 10304
30 # include <windows.h>
31 # include <commdlg.h> // OPENFILENAMEW, GetOpenFileName()
32 # include <shlobj.h> // BROWSEINFOW, SHBrowseForFolder()
33 typedef OPENFILENAMEW fl_OPENFILENAMEW;
34 typedef BROWSEINFOW fl_BROWSEINFOW;
35 #else
36 typedef void fl_OPENFILENAMEW;
37 typedef void fl_BROWSEINFOW;
38 #endif
39 #endif
40
41 // Use Apple's chooser
42 #ifdef __APPLE__
43 # define MAXFILTERS 80
44 #endif
45
46 // All else falls back to FLTK's own chooser
47 #if ! defined(__APPLE__) && !defined(WIN32)
48 # include <FL/Fl_File_Chooser.H>
49 #else
50 # include <FL/filename.H> // FL_EXPORT
51 #endif
52
53 class Fl_FLTK_File_Chooser;
54 class Fl_GTK_File_Chooser;
55
111 class FL_EXPORT Fl_Native_File_Chooser {
112 public:
113 enum Type {
114 BROWSE_FILE = 0,
115 BROWSE_DIRECTORY,
116 BROWSE_MULTI_FILE,
117 BROWSE_MULTI_DIRECTORY,
118 BROWSE_SAVE_FILE,
119 BROWSE_SAVE_DIRECTORY
120 };
121 enum Option {
122 NO_OPTIONS = 0x0000,
123 SAVEAS_CONFIRM = 0x0001,
124 NEW_FOLDER = 0x0002,
125 PREVIEW = 0x0004,
126 USE_FILTER_EXT = 0x0008
127 };
129 static const char *file_exists_message;
130
131 public:
132 Fl_Native_File_Chooser(int val=BROWSE_FILE);
133 ~Fl_Native_File_Chooser();
134
135 // Public methods
136 void type(int t);
137 int type() const ;
138 void options(int o);
139 int options() const;
140 int count() const;
141 const char *filename() const ;
142 const char *filename(int i) const ;
143 void directory(const char *val) ;
144 const char *directory() const;
145 void title(const char *t);
146 const char* title() const;
147 const char *filter() const ;
148 void filter(const char *f);
149 int filters() const ;
150 void filter_value(int i) ;
151 int filter_value() const ;
152 void preset_file(const char*f) ;
153 const char* preset_file() const;
154 const char *errmsg() const ;
155 int show() ;
156
157 #ifdef WIN32
158 private:
159 int _btype; // kind-of browser to show()
160 int _options; // general options
161 #if FLTK_ABI_VERSION >= 10304
162 fl_OPENFILENAMEW *_ofn_ptr; // GetOpenFileName() & GetSaveFileName() struct
163 fl_BROWSEINFOW *_binf_ptr; // SHBrowseForFolder() struct
164 WCHAR *_wpattern; // pattern buffer for filter
165 #else
166 fl_OPENFILENAMEW _ofn;
167 fl_BROWSEINFOW _binf;
168 #endif
169 char **_pathnames; // array of pathnames
170 int _tpathnames; // total pathnames
171 char *_directory; // default pathname to use
172 char *_title; // title for window
173 char *_filter; // user-side search filter
174 char *_parsedfilt; // filter parsed for Windows dialog
175 int _nfilters; // number of filters parse_filter counted
176 char *_preset_file; // the file to preselect
177 char *_errmsg; // error message
178
179 // Private methods
180 void errmsg(const char *msg);
181
182 void clear_pathnames();
183 void set_single_pathname(const char *s);
184 void add_pathname(const char *s);
185
186 void ClearOFN();
187 void ClearBINF();
188 void Win2Unix(char *s);
189 void Unix2Win(char *s);
190 int showfile();
191 int showdir();
192
193 void parse_filter(const char *);
194 void clear_filters();
195 void add_filter(const char *, const char *);
196 #endif
197
198 #ifdef __APPLE__
199 private:
200 int _btype; // kind-of browser to show()
201 int _options; // general options
202 void *_panel;
203 char **_pathnames; // array of pathnames
204 int _tpathnames; // total pathnames
205 char *_directory; // default pathname to use
206 char *_title; // title for window
207 char *_preset_file; // the 'save as' filename
208
209 char *_filter; // user-side search filter, eg:
210 // C Files\t*.[ch]\nText Files\t*.txt"
211
212 char *_filt_names; // filter names (tab delimited)
213 // eg. "C Files\tText Files"
214
215 char *_filt_patt[MAXFILTERS];
216 // array of filter patterns, eg:
217 // _filt_patt[0]="*.{cxx,h}"
218 // _filt_patt[1]="*.txt"
219
220 int _filt_total; // parse_filter() # of filters loaded
221 int _filt_value; // index of the selected filter
222 char *_errmsg; // error message
223
224 // Private methods
225 void errmsg(const char *msg);
226 void clear_pathnames();
227 void set_single_pathname(const char *s);
228 int get_saveas_basename(void);
229 void clear_filters();
230 void add_filter(const char *, const char *);
231 void parse_filter(const char *from);
232 int post();
233 int runmodal();
234 #endif
235
236 #if ! defined(__APPLE__) && !defined(WIN32)
237 private:
238 #if FLTK_ABI_VERSION <= 10302
239 int _btype; // kind-of browser to show()
240 int _options; // general options
241 int _nfilters;
242 char *_filter; // user supplied filter
243 char *_parsedfilt; // parsed filter
244 int _filtvalue; // selected filter
245 char *_preset_file;
246 char *_prevvalue; // Returned filename
247 char *_directory;
248 char *_errmsg; // error message
249 #endif
250 static int have_looked_for_GTK_libs;
251 union {
252 Fl_FLTK_File_Chooser *_x11_file_chooser;
253 Fl_GTK_File_Chooser *_gtk_file_chooser;
254 };
255 #endif
256 };
257
258 #if !defined(__APPLE__) && !defined(WIN32)
259 class FL_EXPORT Fl_FLTK_File_Chooser {
260 friend class Fl_Native_File_Chooser;
261 protected:
262 int _btype; // kind-of browser to show()
263 int _options; // general options
264 int _nfilters;
265 char *_filter; // user supplied filter
266 char *_parsedfilt; // parsed filter
267 int _filtvalue; // selected filter
268 char *_preset_file;
269 char *_prevvalue; // Returned filename
270 char *_directory;
271 char *_errmsg; // error message
272 Fl_FLTK_File_Chooser(int val);
273 virtual ~Fl_FLTK_File_Chooser();
274 void errmsg(const char *msg);
275 int type_fl_file(int);
276 void parse_filter();
277 int exist_dialog();
278 Fl_File_Chooser *_file_chooser;
279 virtual void type(int);
280 int type() const;
281 void options(int);
282 int options() const;
283 virtual int count() const;
284 virtual const char *filename() const;
285 virtual const char *filename(int i) const;
286 void directory(const char *val);
287 const char *directory() const;
288 virtual void title(const char *);
289 virtual const char* title() const;
290 const char *filter() const;
291 void filter(const char *);
292 int filters() const;
293 void filter_value(int i);
294 int filter_value() const;
295 void preset_file(const char*);
296 const char* preset_file() const;
297 const char *errmsg() const;
298 virtual int show();
299 };
300
301
302 class FL_EXPORT Fl_GTK_File_Chooser : public Fl_FLTK_File_Chooser {
303 friend class Fl_Native_File_Chooser;
304 private:
305 typedef struct _GtkWidget GtkWidget;
306 typedef struct _GtkFileFilterInfo GtkFileFilterInfo;
307 struct pair {
308 Fl_GTK_File_Chooser* running; // the running Fl_GTK_File_Chooser
309 const char *filter; // a filter string of the chooser
310 pair(Fl_GTK_File_Chooser* c, const char *f) {
311 running = c;
312 filter = strdup(f);
313 };
314 ~pair() {
315 free((char*)filter);
316 };
317 };
318 GtkWidget *gtkw_ptr; // used to hold a GtkWidget* without pulling GTK into everything...
319 void *gtkw_slist; // used to hold a GLib GSList...
320 unsigned gtkw_count; // number of files read back - if any
321 mutable char *gtkw_filename; // last name we read back
322 char *gtkw_title; // the title to be applied to the dialog
323 const char *previous_filter;
324
325 int fl_gtk_chooser_wrapper(); // method that wraps the GTK widget
326 Fl_GTK_File_Chooser(int val);
327 virtual ~Fl_GTK_File_Chooser();
328 static int did_find_GTK_libs;
329 static void probe_for_GTK_libs(void);
330 virtual void type(int);
331 virtual int count() const;
332 virtual const char *filename() const;
333 virtual const char *filename(int i) const;
334 virtual void title(const char *);
335 virtual const char* title() const;
336 virtual int show();
337 void changed_output_type(const char *filter);
338
339 static int custom_gtk_filter_function(const GtkFileFilterInfo*, Fl_GTK_File_Chooser::pair*);
340 static void free_pair(pair *p);
341 };
342 #endif // !defined(__APPLE__) && !defined(WIN32)
343
344 #endif /*FL_NATIVE_FILE_CHOOSER_H*/
345
346 //
347 // End of "$Id: Fl_Native_File_Chooser.H 11188 2016-02-18 04:21:27Z greg.ercolano $".
348 //
Fl_Native_File_Chooser::Option
Option
Definition: Fl_Native_File_Chooser.H:121
Fl_Native_File_Chooser
This class lets an FLTK application easily and consistently access the operating system&#39;s native file...
Definition: Fl_Native_File_Chooser.H:111
Fl_Native_File_Chooser::Type
Type
Definition: Fl_Native_File_Chooser.H:113
Fl_Native_File_Chooser::errmsg
const char * errmsg() const
Returns a system dependent error message for the last method that failed.
Definition: Fl_Native_File_Chooser_FLTK.cxx:233
filename.H
File names and URI utility functions.
Fl_GTK_File_Chooser
Definition: Fl_Native_File_Chooser.H:302
Fl_Native_File_Chooser::filename
const char * filename() const
Return the filename the user chose.
Definition: Fl_Native_File_Chooser_FLTK.cxx:126
Fl_Native_File_Chooser::filter_value
int filter_value() const
Returns which filter value was last selected by the user.
Definition: Fl_Native_File_Chooser_FLTK.cxx:213
Fl_Native_File_Chooser::preset_file
const char * preset_file() const
Get the preset filename.
Definition: Fl_Native_File_Chooser_FLTK.cxx:226
Fl_Native_File_Chooser::options
int options() const
Gets the platform specific Fl_Native_File_Chooser::Option flags.
Definition: Fl_Native_File_Chooser_FLTK.cxx:103
Fl_Native_File_Chooser::show
int show()
Post the chooser&#39;s dialog.
Definition: Fl_Native_File_Chooser_FLTK.cxx:242
Fl_Native_File_Chooser::file_exists_message
static const char * file_exists_message
Localizable message.
Definition: Fl_Native_File_Chooser.H:129
Fl_File_Chooser
The Fl_File_Chooser widget displays a standard file selection dialog that supports various selection ...
Definition: Fl_File_Chooser.H:48
Fl_FLTK_File_Chooser
Definition: Fl_Native_File_Chooser.H:259
Fl_Native_File_Chooser::title
const char * title() const
Get the title of the file chooser&#39;s dialog window.
Definition: Fl_Native_File_Chooser_FLTK.cxx:167
Fl_Native_File_Chooser::directory
const char * directory() const
Returns the current preset directory() value.
Definition: Fl_Native_File_Chooser_FLTK.cxx:154
Fl_Native_File_Chooser::filters
int filters() const
Gets how many filters were available, not including "All Files".
Definition: Fl_Native_File_Chooser_FLTK.cxx:198
Fl_Native_File_Chooser::BROWSE_MULTI_FILE
browse files (lets user choose multiple files)
Definition: Fl_Native_File_Chooser.H:116
Fl_Native_File_Chooser::type
int type() const
Gets the current Fl_Native_File_Chooser::Type of browser.
Definition: Fl_Native_File_Chooser_FLTK.cxx:82
Fl_Native_File_Chooser::BROWSE_MULTI_DIRECTORY
browse directories (lets user choose multiple directories)
Definition: Fl_Native_File_Chooser.H:117
Fl_Native_File_Chooser::BROWSE_DIRECTORY
browse directories (lets user choose one directory)
Definition: Fl_Native_File_Chooser.H:115
Fl_Native_File_Chooser::filter
const char * filter() const
Returns the filter string last set.
Definition: Fl_Native_File_Chooser_FLTK.cxx:173
Fl_Native_File_Chooser::count
int count() const
Returns the number of filenames (or directory names) the user selected.
Definition: Fl_Native_File_Chooser_FLTK.cxx:118
Fl_Native_File_Chooser::BROWSE_SAVE_FILE
browse to save a file
Definition: Fl_Native_File_Chooser.H:118
- © 1998-2016 by Bill Spitzak and others.