FLTK 1.4.4

Loading...
Searching...
No Matches
Fl_Native_File_Chooser.H
Go to the documentation of this file.
1//
2// FLTK native OS file chooser widget
3//
4// Copyright 2004 Greg Ercolano.
5// Copyright 2005-2024 by Bill Spitzak and others.
6//
7// This library is free software. Distribution and use rights are outlined in
8// the file "COPYING" which should have been included with this file. If this
9// file is missing or damaged, see the license at:
10//
11// https://www.fltk.org/COPYING.php
12//
13// Please see the following page on how to report bugs and issues:
14//
15// https://www.fltk.org/bugs.php
16//
17
20
21/* Implementation note:
22
23 class Fl_Native_File_Chooser <== public API used by applications
24
25 class Fl_Native_File_Chooser_Driver <== virtual API that a platform may implement
26 this API has a do-nothing default implementation
27
28 class Fl_Native_File_Chooser_FLTK_Driver <== this API implementation is the default FLTK file chooser
29 class Fl_GTK_Native_File_Chooser_Driver <== this API implementation runs a GTK file chooser
30 class Fl_Kdialog_Native_File_Chooser_Driver <== this API implementation runs a KDE file chooser
31 it is determined at run-time if the GTK dynamic libraries are available
32 and the KDE file chooser runs under the KDE desktop
33
34 class Fl_Quartz_Native_File_Chooser_Driver <== this API implementation runs a Mac OS X file chooser
35
36 class Fl_WinAPI_Native_File_Chooser_Driver <== this API implementation runs a Windows file chooser
37
38
39 Each platform must implement the constructor of the Fl_Native_File_Chooser class.
40 This particular implementation:
41
42 Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) {
43 platform_fnfc = new Fl_Native_File_Chooser_FLTK_Driver(val);
44 }
45
46 can be used by any platform.
47 No more code is required. The cross-platform Fl_Native_File_Chooser_FLTK.cxx file must be compiled in libfltk,
48 and the default FLTK file chooser will be used.
49
50 This other implementation:
51 Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) {
52 platform_fnfc = 0;
53 }
54 can be used by a platform that needs no file chooser.
55 */
56
57#ifndef FL_NATIVE_FILE_CHOOSER_H
58#define FL_NATIVE_FILE_CHOOSER_H
59
60#include <FL/Fl_Export.H>
61#include <FL/Fl_File_Chooser.H>
62
63 class Fl_Native_File_Chooser_Driver;
64
130 class FL_EXPORT Fl_Native_File_Chooser {
131 private:
132 Fl_Native_File_Chooser_Driver *platform_fnfc;
133 public:
134 enum Type {
135 BROWSE_FILE = 0,
136 BROWSE_DIRECTORY,
137 BROWSE_MULTI_FILE,
138 BROWSE_MULTI_DIRECTORY,
139 BROWSE_SAVE_FILE,
140 BROWSE_SAVE_DIRECTORY
141 };
142 enum Option {
143 NO_OPTIONS = 0x0000,
144 SAVEAS_CONFIRM = 0x0001,
145 NEW_FOLDER = 0x0002,
146 PREVIEW = 0x0004,
147 USE_FILTER_EXT = 0x0008
148 };
149 static const char *file_exists_message;
150
156 Fl_Native_File_Chooser(int val = BROWSE_FILE); // each platorm implements it
157 ~Fl_Native_File_Chooser();
158 void type(int t);
159 int type() const ;
160 void options(int o);
161 int options() const;
162 int count() const;
163 const char *filename() const ;
164 const char *filename(int i) const ;
165 void directory(const char *val) ;
166 const char *directory() const;
167 void title(const char *t);
168 const char* title() const;
169 const char *filter() const ;
170 void filter(const char *f);
171 int filters() const ;
172 void filter_value(int i) ;
173 int filter_value() const ;
174 void preset_file(const char*f) ;
175 const char* preset_file() const;
176 const char *errmsg() const ;
177 int show() ;
178 };
179
185
192 class Fl_Native_File_Chooser_Driver {
193 protected:
194 static void chrcat(char *s, char c);
195 static char *strapp(char *s, const char *val);
196 static char *strfree(char *val);
197 static char *strnew(const char *val);
198 public:
199 Fl_Native_File_Chooser_Driver(int) {}
200 virtual ~Fl_Native_File_Chooser_Driver() {}
201 virtual void type(int) {}
202 virtual int type() const {return 0;}
203 virtual void options(int) {}
204 virtual int options() const {return 0;}
205 virtual int count() const {return 0;}
206 virtual const char *filename() const {return 0;}
207 virtual const char *filename(int) const {return 0;}
208 virtual void directory(const char *) {}
209 virtual const char *directory() const {return 0;}
210 virtual void title(const char *) {}
211 virtual const char* title() const {return 0;}
212 virtual const char *filter() const {return 0;}
213 virtual void filter(const char *) {}
214 virtual int filters() const {return 0;}
215 virtual void filter_value(int) {}
216 virtual int filter_value() const {return 0;}
217 virtual void preset_file(const char*) {}
218 virtual const char* preset_file() const {return 0;}
219 virtual const char *errmsg() const {return 0;}
220 virtual int show() {return 1;}
221};
222
234 class Fl_Native_File_Chooser_FLTK_Driver : public Fl_Native_File_Chooser_Driver {
235 private:
236 void errmsg(const char *msg);
237 int type_fl_file(int val);
238 int exist_dialog();
239 void parse_filter();
240 protected:
241 int _btype; // kind-of browser to show()
242 int _options; // general options
243 int _nfilters;
244 char *_filter; // user supplied filter
245 char *_parsedfilt; // parsed filter
246 int _filtvalue; // selected filter
247 char *_preset_file;
248 char *_prevvalue; // Returned filename
249 char *_directory;
250 char *_errmsg; // error message
251 Fl_File_Chooser *_file_chooser;
252 public:
253 Fl_Native_File_Chooser_FLTK_Driver(int val);
254 virtual ~Fl_Native_File_Chooser_FLTK_Driver();
255 void type(int t) FL_OVERRIDE;
256 int type() const FL_OVERRIDE;
257 void options(int o) FL_OVERRIDE;
258 int options() const FL_OVERRIDE;
259 int count() const FL_OVERRIDE;
260 const char *filename() const FL_OVERRIDE;
261 const char *filename(int i) const FL_OVERRIDE;
262 void directory(const char *val) FL_OVERRIDE;
263 const char *directory() const FL_OVERRIDE;
264 void title(const char *t) FL_OVERRIDE;
265 const char* title() const FL_OVERRIDE;
266 const char *filter() const FL_OVERRIDE;
267 void filter(const char *f) FL_OVERRIDE;
268 int filters() const FL_OVERRIDE;
269 void filter_value(int i) FL_OVERRIDE;
270 int filter_value() const FL_OVERRIDE;
271 void preset_file(const char*f) FL_OVERRIDE;
272 const char* preset_file() const FL_OVERRIDE;
273 const char *errmsg() const FL_OVERRIDE;
274 int show() FL_OVERRIDE;
275};
276
281
282
283#endif /*FL_NATIVE_FILE_CHOOSER_H*/
Fl_Native_File_Chooser::file_exists_message
static const char * file_exists_message
Localizable message.
Definition Fl_Native_File_Chooser.H:149
Fl_Native_File_Chooser::filter
const char * filter() const
Returns the filter string last set.
Definition Fl_Native_File_Chooser.cxx:153
Fl_Native_File_Chooser::title
void title(const char *t)
Set the title of the file chooser's dialog window.
Definition Fl_Native_File_Chooser.cxx:137
Fl_Native_File_Chooser::directory
void directory(const char *val)
Preset the directory the browser will show when opened.
Definition Fl_Native_File_Chooser.cxx:121
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.cxx:254
Fl_Native_File_Chooser::type
void type(int t)
Sets the current Fl_Native_File_Chooser::Type of browser.
Definition Fl_Native_File_Chooser.cxx:35
Fl_Native_File_Chooser::options
void options(int o)
Sets the platform specific chooser options to val.
Definition Fl_Native_File_Chooser.cxx:60
Fl_Native_File_Chooser::filename
const char * filename() const
Return the filename the user chose.
Definition Fl_Native_File_Chooser.cxx:94
Fl_Native_File_Chooser::Fl_Native_File_Chooser
Fl_Native_File_Chooser(int val=BROWSE_FILE)
The constructor.
Definition Fl_Native_File_Chooser_GTK.cxx:924
Fl_Native_File_Chooser::filters
int filters() const
Gets how many filters were available, not including "All Files".
Definition Fl_Native_File_Chooser.cxx:182
Fl_Native_File_Chooser::Type
Type
Definition Fl_Native_File_Chooser.H:134
Fl_Native_File_Chooser::BROWSE_DIRECTORY
@ BROWSE_DIRECTORY
browse directories (lets user choose one directory)
Definition Fl_Native_File_Chooser.H:136
Fl_Native_File_Chooser::BROWSE_MULTI_FILE
@ BROWSE_MULTI_FILE
browse files (lets user choose multiple files)
Definition Fl_Native_File_Chooser.H:137
Fl_Native_File_Chooser::BROWSE_SAVE_FILE
@ BROWSE_SAVE_FILE
browse to save a file
Definition Fl_Native_File_Chooser.H:139
Fl_Native_File_Chooser::BROWSE_SAVE_DIRECTORY
@ BROWSE_SAVE_DIRECTORY
browse to save a directory
Definition Fl_Native_File_Chooser.H:140
Fl_Native_File_Chooser::BROWSE_MULTI_DIRECTORY
@ BROWSE_MULTI_DIRECTORY
browse directories (lets user choose multiple directories)
Definition Fl_Native_File_Chooser.H:138
Fl_Native_File_Chooser::BROWSE_FILE
@ BROWSE_FILE
browse files (lets user choose one file)
Definition Fl_Native_File_Chooser.H:135
Fl_Native_File_Chooser::show
int show()
Post the chooser's dialog.
Definition Fl_Native_File_Chooser.cxx:265
Fl_Native_File_Chooser::Option
Option
Definition Fl_Native_File_Chooser.H:142
Fl_Native_File_Chooser::NEW_FOLDER
@ NEW_FOLDER
Show 'New Folder' icon (if supported).
Definition Fl_Native_File_Chooser.H:145
Fl_Native_File_Chooser::NO_OPTIONS
@ NO_OPTIONS
no options enabled
Definition Fl_Native_File_Chooser.H:143
Fl_Native_File_Chooser::PREVIEW
@ PREVIEW
enable preview mode (if supported)
Definition Fl_Native_File_Chooser.H:146
Fl_Native_File_Chooser::USE_FILTER_EXT
@ USE_FILTER_EXT
Chooser filter presets the output file extension (if supported).
Definition Fl_Native_File_Chooser.H:147
Fl_Native_File_Chooser::SAVEAS_CONFIRM
@ SAVEAS_CONFIRM
Show native 'Save As' overwrite confirm dialog.
Definition Fl_Native_File_Chooser.H:144
Fl_Native_File_Chooser::preset_file
void preset_file(const char *f)
Sets the default filename for the chooser.
Definition Fl_Native_File_Chooser.cxx:238
Fl_Native_File_Chooser::filter_value
void filter_value(int i)
Sets which filter will be initially selected.
Definition Fl_Native_File_Chooser.cxx:206
Fl_Native_File_Chooser::count
int count() const
Returns the number of filenames (or directory names) the user selected.
Definition Fl_Native_File_Chooser.cxx:84
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46