FLTK 1.3.3: Fl_Native_File_Chooser.H Source File

FLTK 1.3.3

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

Fl_Native_File_Chooser.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl_Native_File_Chooser.H 10408 2014-10-29 20:05:05Z cand $"
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 # include <stdio.h>
30 # include <stdlib.h> // malloc
31 # include <windows.h>
32 # include <commdlg.h> // OPENFILENAME, GetOpenFileName()
33 # include <shlobj.h> // BROWSEINFO, SHBrowseForFolder()
34 #endif
35
36 // Use Apple's chooser
37 #ifdef __APPLE__
38 # define MAXFILTERS 80
39 #endif
40
41 // All else falls back to FLTK's own chooser
42 #if ! defined(__APPLE__) && !defined(WIN32)
43 # include <FL/Fl_File_Chooser.H>
44 # include <unistd.h> // _POSIX_NAME_MAX
45 #else
46 # include <FL/filename.H> // FL_EXPORT
47 #endif
48
49 class Fl_FLTK_File_Chooser;
50 class Fl_GTK_File_Chooser;
51
107 class FL_EXPORT Fl_Native_File_Chooser {
108 public:
109 enum Type {
110 BROWSE_FILE = 0,
111 BROWSE_DIRECTORY,
112 BROWSE_MULTI_FILE,
113 BROWSE_MULTI_DIRECTORY,
114 BROWSE_SAVE_FILE,
115 BROWSE_SAVE_DIRECTORY
116 };
117 enum Option {
118 NO_OPTIONS = 0x0000,
119 SAVEAS_CONFIRM = 0x0001,
120 NEW_FOLDER = 0x0002,
121 PREVIEW = 0x0004,
122 USE_FILTER_EXT = 0x0008
123 };
125 static const char *file_exists_message;
126
127 public:
128 Fl_Native_File_Chooser(int val=BROWSE_FILE);
129 ~Fl_Native_File_Chooser();
130
131 // Public methods
132 void type(int t);
133 int type() const ;
134 void options(int o);
135 int options() const;
136 int count() const;
137 const char *filename() const ;
138 const char *filename(int i) const ;
139 void directory(const char *val) ;
140 const char *directory() const;
141 void title(const char *t);
142 const char* title() const;
143 const char *filter() const ;
144 void filter(const char *f);
145 int filters() const ;
146 void filter_value(int i) ;
147 int filter_value() const ;
148 void preset_file(const char*f) ;
149 const char* preset_file() const;
150 const char *errmsg() const ;
151 int show() ;
152
153 #ifdef WIN32
154 private:
155 int _btype; // kind-of browser to show()
156 int _options; // general options
157 OPENFILENAMEW _ofn; // GetOpenFileName() & GetSaveFileName() struct
158 BROWSEINFOW _binf; // SHBrowseForFolder() struct
159 char **_pathnames; // array of pathnames
160 int _tpathnames; // total pathnames
161 char *_directory; // default pathname to use
162 char *_title; // title for window
163 char *_filter; // user-side search filter
164 char *_parsedfilt; // filter parsed for Windows dialog
165 int _nfilters; // number of filters parse_filter counted
166 char *_preset_file; // the file to preselect
167 char *_errmsg; // error message
168
169 // Private methods
170 void errmsg(const char *msg);
171
172 void clear_pathnames();
173 void set_single_pathname(const char *s);
174 void add_pathname(const char *s);
175
176 void FreePIDL(LPITEMIDLIST pidl);
177 void ClearOFN();
178 void ClearBINF();
179 void Win2Unix(char *s);
180 void Unix2Win(char *s);
181 int showfile();
182 static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
183 int showdir();
184
185 void parse_filter(const char *);
186 void clear_filters();
187 void add_filter(const char *, const char *);
188 #endif
189
190 #ifdef __APPLE__
191 private:
192 int _btype; // kind-of browser to show()
193 int _options; // general options
194 void *_panel;
195 char **_pathnames; // array of pathnames
196 int _tpathnames; // total pathnames
197 char *_directory; // default pathname to use
198 char *_title; // title for window
199 char *_preset_file; // the 'save as' filename
200
201 char *_filter; // user-side search filter, eg:
202 // C Files\t*.[ch]\nText Files\t*.txt"
203
204 char *_filt_names; // filter names (tab delimited)
205 // eg. "C Files\tText Files"
206
207 char *_filt_patt[MAXFILTERS];
208 // array of filter patterns, eg:
209 // _filt_patt[0]="*.{cxx,h}"
210 // _filt_patt[1]="*.txt"
211
212 int _filt_total; // parse_filter() # of filters loaded
213 int _filt_value; // index of the selected filter
214 char *_errmsg; // error message
215
216 // Private methods
217 void errmsg(const char *msg);
218 void clear_pathnames();
219 void set_single_pathname(const char *s);
220 int get_saveas_basename(void);
221 void clear_filters();
222 void add_filter(const char *, const char *);
223 void parse_filter(const char *from);
224 int post();
225 int runmodal();
226 #endif
227
228 #if ! defined(__APPLE__) && !defined(WIN32)
229 private:
230 #if FLTK_ABI_VERSION <= 10302
231 int _btype; // kind-of browser to show()
232 int _options; // general options
233 int _nfilters;
234 char *_filter; // user supplied filter
235 char *_parsedfilt; // parsed filter
236 int _filtvalue; // selected filter
237 char *_preset_file;
238 char *_prevvalue; // Returned filename
239 char *_directory;
240 char *_errmsg; // error message
241 #endif
242 static int have_looked_for_GTK_libs;
243 union {
244 Fl_FLTK_File_Chooser *_x11_file_chooser;
245 Fl_GTK_File_Chooser *_gtk_file_chooser;
246 };
247 #endif
248 };
249
250 #if !defined(__APPLE__) && !defined(WIN32)
251 class FL_EXPORT Fl_FLTK_File_Chooser {
252 friend class Fl_Native_File_Chooser;
253 protected:
254 int _btype; // kind-of browser to show()
255 int _options; // general options
256 int _nfilters;
257 char *_filter; // user supplied filter
258 char *_parsedfilt; // parsed filter
259 int _filtvalue; // selected filter
260 char *_preset_file;
261 char *_prevvalue; // Returned filename
262 char *_directory;
263 char *_errmsg; // error message
264 Fl_FLTK_File_Chooser(int val);
265 virtual ~Fl_FLTK_File_Chooser();
266 void errmsg(const char *msg);
267 int type_fl_file(int);
268 void parse_filter();
269 int exist_dialog();
270 Fl_File_Chooser *_file_chooser;
271 virtual void type(int);
272 int type() const;
273 void options(int);
274 int options() const;
275 virtual int count() const;
276 virtual const char *filename() const;
277 virtual const char *filename(int i) const;
278 void directory(const char *val);
279 const char *directory() const;
280 virtual void title(const char *);
281 virtual const char* title() const;
282 const char *filter() const;
283 void filter(const char *);
284 int filters() const;
285 void filter_value(int i);
286 int filter_value() const;
287 void preset_file(const char*);
288 const char* preset_file() const;
289 const char *errmsg() const;
290 virtual int show();
291 };
292
293
294 class FL_EXPORT Fl_GTK_File_Chooser : public Fl_FLTK_File_Chooser {
295 friend class Fl_Native_File_Chooser;
296 private:
297 typedef struct _GtkWidget GtkWidget;
298 typedef struct _GtkFileFilterInfo GtkFileFilterInfo;
299 struct pair {
300 Fl_GTK_File_Chooser* running; // the running Fl_GTK_File_Chooser
301 const char *filter; // a filter string of the chooser
302 pair(Fl_GTK_File_Chooser* c, const char *f) {
303 running = c;
304 filter = strdup(f);
305 };
306 ~pair() {
307 free((char*)filter);
308 };
309 };
310 GtkWidget *gtkw_ptr; // used to hold a GtkWidget* without pulling GTK into everything...
311 void *gtkw_slist; // used to hold a GLib GSList...
312 unsigned gtkw_count; // number of files read back - if any
313 mutable char *gtkw_filename; // last name we read back
314 char *gtkw_title; // the title to be applied to the dialog
315 const char *previous_filter;
316
317 int fl_gtk_chooser_wrapper(); // method that wraps the GTK widget
318 Fl_GTK_File_Chooser(int val);
319 virtual ~Fl_GTK_File_Chooser();
320 static int did_find_GTK_libs;
321 static void probe_for_GTK_libs(void);
322 virtual void type(int);
323 virtual int count() const;
324 virtual const char *filename() const;
325 virtual const char *filename(int i) const;
326 virtual void title(const char *);
327 virtual const char* title() const;
328 virtual int show();
329 void changed_output_type(const char *filter);
330
331 static int custom_gtk_filter_function(const GtkFileFilterInfo*, Fl_GTK_File_Chooser::pair*);
332 static void free_pair(pair *p);
333 };
334 #endif // !defined(__APPLE__) && !defined(WIN32)
335
336 #endif /*FL_NATIVE_FILE_CHOOSER_H*/
337
338 //
339 // End of "$Id: Fl_Native_File_Chooser.H 10408 2014-10-29 20:05:05Z cand $".
340 //
Fl_Native_File_Chooser::Option
Option
Definition: Fl_Native_File_Chooser.H:117
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:107
Fl_Native_File_Chooser::Type
Type
Definition: Fl_Native_File_Chooser.H:109
Fl_Native_File_Chooser::directory
const char * directory() const
Returns the current preset directory() value.
Definition: Fl_Native_File_Chooser_FLTK.cxx:147
filename.H
File names and URI utility functions.
Fl_GTK_File_Chooser
Definition: Fl_Native_File_Chooser.H:294
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:199
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:100
Fl_Native_File_Chooser::filename
const char * filename() const
Return the filename the user chose.
Definition: Fl_Native_File_Chooser_FLTK.cxx:122
Fl_Native_File_Chooser::show
int show()
Post the chooser&#39;s dialog.
Definition: Fl_Native_File_Chooser_FLTK.cxx:224
Fl_Native_File_Chooser::file_exists_message
static const char * file_exists_message
Localizable message.
Definition: Fl_Native_File_Chooser.H:125
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:216
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_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:115
Fl_Native_File_Chooser::preset_file
const char * preset_file() const
Get the preset filename.
Definition: Fl_Native_File_Chooser_FLTK.cxx:210
Fl_FLTK_File_Chooser
Definition: Fl_Native_File_Chooser.H:251
Fl_Native_File_Chooser::filter
const char * filter() const
Returns the filter string last set.
Definition: Fl_Native_File_Chooser_FLTK.cxx:163
Fl_Native_File_Chooser::BROWSE_MULTI_FILE
browse files (lets user choose multiple files)
Definition: Fl_Native_File_Chooser.H:112
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:186
Fl_Native_File_Chooser::BROWSE_MULTI_DIRECTORY
browse directories (lets user choose multiple directories)
Definition: Fl_Native_File_Chooser.H:113
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:158
Fl_Native_File_Chooser::BROWSE_DIRECTORY
browse directories (lets user choose one directory)
Definition: Fl_Native_File_Chooser.H:111
Fl_Native_File_Chooser::BROWSE_SAVE_FILE
browse to save a file
Definition: Fl_Native_File_Chooser.H:114
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:81
- © 1998-2014 by Bill Spitzak and others.