File: NativeFileChooser.html

package info (click to toggle)
imview 1.1.9h-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,528 kB
  • sloc: cpp: 32,590; sh: 2,664; ansic: 1,900; makefile: 811; exp: 112; python: 88
file content (361 lines) | stat: -rw-r--r-- 12,265 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<html>
<head>
<title>[Fltk-2.x] NativeFileChooser</title>
</head>
<body>
<H1>[Fltk-2.x] NativeFileChooser</H1>

<h2>class fltk::NativeFileChooser</a></h2>
<!--
<h3>Class Hierarchy</h3>
<ul>
  <pre>
  NativeFileChooser
  </pre>
</ul>
-->

<h3>Include Files</h3>
<ul>
  <pre>
  #include &lt;fltk/NativeFileChooser.h&gt;
  </pre>
</ul>
Dowload latest source from <a href="http://seriss.com/people/erco/fltk/Fl_NativeFileChooser/">here</a>.
<br>
<h3>Description</h3>
This class lets an FLTK2 application easily and consistently access
the local operating system's native file chooser. Some operating systems
have very complex and specific file choosers that many users want access
to specifically, instead of FLTK2's default file chooser(s).
<p>
<h3>Methods</h3>
<center>
<table width="90%" summary="fltk::NativeFileChooser methods">
<tr><td align="left" valign="top">
<ul>
  <li> <a href="#NativeFileChooser">NativeFileChooser</a>
  <li> <a href="#~NativeFileChooser">~NativeFileChooser</a>
  <li> <a href="#count">count</a>
</ul>
</td><td align="left" valign="top">
<ul>
  <li> <a href="#directory">directory</a>
  <li> <a href="#errmsg">errmsg</a>
  <li> <a href="#filename">filename</a>
</ul>
</td><td align="left" valign="top">
<ul>
  <li> <a href="#filter">filter</a>
  <li> <a href="#filter_value">filter_value</a>
  <li> <a href="#filters">filters</a>
</ul>
</td><td align="left" valign="top">
<ul>
  <li> <a href="#options">options</a>
  <li> <a href="#preset_file">preset_file</a>
  <li> <a href="#show">show</a>
</ul>
</td><td align="left" valign="top">
<ul>
  <li> <a href="#title">title</a>
  <li> <a href="#type">type</a>
</ul>
&nbsp;<br>
&nbsp;<br>
</td> </tr> </table>
</center>

<h4><a name="NativeFileChooser">
fltk::NativeFileChooser::NativeFileChooser()<br>
fltk::NativeFileChooser::NativeFileChooser(type)
</h4>
<ul>
    The constructor for the fltk::NativeFileChooser.
    <p>
    If the optional <tt>type</tt> is not specified,
    BROWSE_FILE (browse to open a file) is assumed.  
    The type can also be set later with <a href="#type">type()</a>.
</ul>

<h4><a name="~NativeFileChooser">
fltk::NativeFileChooser::~NativeFileChooser()
</h4>
<ul>
    The destructor; destroys any resources allocated to this widget.
</ul>

<h4>
<a name="count"></a>
int fltk::NativeFileChooser::count() const
</h4>
<ul>
    Returns the number of filenames (or directory names) the user
    selected. These are zero-indexed. 
    See this example of <a href="#multi_example">how to retrieve
    multiple filenames</a>.
</ul>


<h4>
<a name="directory"></a>
void fltk::NativeFileChooser::directory(const char*)<br>
const char* fltk::NativeFileChooser::directory() const;<br>
</h4>
<ul>
    Sets the directory with which to start the chooser.
    If NULL is passed, or if no directory is specified,
    the chooser will attempt to use the last non-cancelled folder.<br>
</ul>

<h4>
<a name="errmsg"></a>
const char *fltk::NativeFileChooser::errmsg() const<br>
</h4>
<ul>
    Returns a system dependent error message for the last
    method that failed. This message should at least be flagged
    to the user in a dialog box, or to some kind of error log.
</ul>

<h4>
<a name="filename"></a>
const char *fltk::NativeFileChooser::filename() const<br>
const char *fltk::NativeFileChooser::filename(int) const<br>
</h4>
<ul>
    The first form returns the single filename selected
    by the user from the browser. (In a multiple browser
    context, this returns the first filename the user selected).
    <p>
    The second form should be used to return multiple filenames,
    and is normally used inside a loop to retrieve all the files
    the user selected, eg:
    <p>
    <a name="multi_example">
    <pre>
        if ( <b>chooser->show()</b> == 0 ) {
            // HANDLE MULTIPLE FILENAMES
            for (int n = 0; n &lt; <b>chooser->count()</b>; n++ ) {
      	        fprintf(stderr, "%d) '%s'\n", n, <b>chooser->filename(n)</b>);
            }
	}
    </pre>
    You can preset the directory with 
    <a href="#directory">directory()</a> method, and the filename using the
    <a href="#preset_file">preset_file()</a> method.<br>
</ul>

<h4>
<a name="filter"></a>
const char *fltk::NativeFileChooser::filter() const<br>
void fltk::NativeFileChooser::filter(const char*)
</h4>
<ul>
    Gets or sets the filename filters used for browsing.
    The default is NULL, which browses all files.
    <p>
    The filter string can be any of:
    <p>
    <ul>
        <li> A single wildcard (eg. "*.txt")
	     </li>
	<li> Multiple wildcards (eg. "*.{cxx,h,H})
	     </li>
	<li> A descriptive name followed by a '\t' and a wildcard
	     (eg. "Text&nbsp;Files\t*.txt")
	     </li>
	<li> A list of separate wildcards with a \n between each (eg. "*.{cxx,H}\n*.txt")
	     </li>
	<li> A list of descriptive names and wildcards 
	     (eg. "C++ Files\t*.{cxx,H}\nTxt Files\t*.txt")
	     </li>
    </ul>
    <p>
    The format of each filter is a wildcard, or an optional
    user description followed by '\t' and the wildcard.
    <p>
    On most platforms, each filter is available to the user
    via a pulldown menu in the file chooser. The 'All Files'
    option is always available to the user.
</ul>

<h4>
<a name="filter_value"></a>
void fltk::NativeFileChooser::filter_value(int)<br>
int fltk::NativeFileChooser::filter_value()<br>
</h4>
<ul>
    The first form sets which filter will be initially selected.<br>
    The second returns which filter was chosen. This is only valid
    if the chooser returns success.<br>
    <p>
    The first filter is indexed as 0. If filter_value()==filters(),
    then "All Files" was chosen. If filter_value() > filters(), then
    a custom filter was set.<br>
</ul>

<h4>
<a name="filters"></a>
int fltk::NativeFileChooser::filters()<br>
</h4>
<ul>
    Gets how many filters were available, not including "All Files"
</ul>

<h4>
<a name="options"></a>
void fltk::NativeFileChooser::options(int)<br>
int fltk::NativeFileChooser::options()<br>
</h4>
<ul>
    Sets/gets the platform specific chooser options.
    <p>
    Some platforms have file choosers with specific functions
    that can be enabled/disabled via this method.
    <p>
    Flags can be ORed together to enable several features. Flags currently supported:
    <p>
    <center><table cellpadding=3>
        <tr><td BGCOLOR=#8888cc align=left>Flag          </td><td BGCOLOR=#8888cc>Description                                                        </td><td BGCOLOR=#8888cc>Win</td><td BGCOLOR=#8888cc>Mac</td><td BGCOLOR=#8888cc>Other</td></tr>
        <tr><td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::SAVEAS_CONFIRM</td><td BGCOLOR=#dddddd>With a BROWSE_SAVEAS chooser, prompts a confirmation if file exists</td><td BGCOLOR=#dddddd>Ignored </td><td BGCOLOR=#88dd88>Used   </td><td BGCOLOR=#dddddd>Ignored</td></tr>
        <tr><td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::NEW_FOLDER    </td><td BGCOLOR=#dddddd>Shows the 'New Folder' button                                      </td><td BGCOLOR=#dddddd>Ignored </td><td BGCOLOR=#dddddd>Ignored</td><td BGCOLOR=#88dd88>Used</td></tr>
        <tr><td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::PREVIEW       </td><td BGCOLOR=#dddddd>Enables the 'Preview' mode by default                              </td><td BGCOLOR=#dddddd>Ignored </td><td BGCOLOR=#dddddd>Ignored</td><td BGCOLOR=#88dd88>Used</td></tr>
    </table></center>
</ul>

<h4>
<a name="preset_file"></a>
void fltk::NativeFileChooser::preset_file(const char*)<br>
const char* fltk::NativeFileChooser::preset_file()<br>
</h4>
<ul>
    Sets a default filename for the chooser. 
    (Use <a href="#directory">directory()</a> to set the default directory)
    <br>
    Mainly used to preset the filename for save dialogs, 
    and on most platforms can be used for opening files as well.
</ul>

<h4>
<a name="show"></a>
int fltk::NativeFileChooser::show() const<br>
</h4>
<ul>
    Opens the current file chooser on the screen. This method
    will block until the user has chosen something, or cancelled.
    <p>
    Return value:
    <ul type=disc>
        <li> 0 - user picked a file, filename() will have the result
        <li> 1 - user hit 'cancel'
        <li>-1 - failed; <a href="#errmsg">errmsg()</a> has reason
    </ul>
</ul>

<h4>
<a name="title"></a>
const char *fltk::NativeFileChooser::title() const<br>
void fltk::NativeFileChooser::title(const char*)
</h4>
<ul>
    Gets or sets the title of the file chooser's window.
    <p>
    The default title varies according to the platform, so you
    are advised to set the title explicitly.
</ul>

<h4><a name="type"></a>
int fltk::NativeFileChooser::type() const<br>
fltk::NativeFileChooser::type(int)
</h4>
<ul>
    Gets or sets the current type of browser. Possible choices are:
    <p>
    <center><table cellpadding=3>
        <tr>
	  <td BGCOLOR=#8888cc align=left>Flag</td>
	  <td BGCOLOR=#8888cc>Description</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_FILE</td>
	  <td BGCOLOR=#dddddd>Browse for a single file</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_DIRECTORY</td>
	  <td BGCOLOR=#dddddd>Browse for a single directory</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_MULTI_FILE</td>
	  <td BGCOLOR=#dddddd>Browse for multiple files</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_MULTI_DIRECTORY</td>
	  <td BGCOLOR=#dddddd>Browse for multiple directories (implementation varies)</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_SAVE_FILE</td>
	  <td BGCOLOR=#dddddd>Browse to save a single file</td>
	</tr><tr>
	  <td BGCOLOR=#dddddd align=left><tt>fltk::NativeFileChooser::BROWSE_SAVE_DIRECTORY</td>
	  <td BGCOLOR=#dddddd>Browse for a directory, allowing creation</td>
        </tr>
    </table></center>
    <p>
    These may be changed in future versions of fltk::NativeFileChooser.
</ul>

<h3>Typical Usage</h3>
<ul>
    <pre>
#include &lt;fltk/NativeFileChooser.h&gt;
:
fltk::NativeFileChooser *chooser = <b>new fltk::NativeFileChooser</b>();
<b>chooser-&gt;type</b>(fltk::NativeFileChooser::BROWSE_FILE);   <i>// let user browse a single file</i>
<b>chooser-&gt;title</b>("Open a file");                           <i>// optional title</i>
<b>chooser-&gt;preset_file</b>("/var/tmp/somefile.txt");           <i>// optional filename preset</i>
<b>chooser-&gt;filter</b>("Text Files\t*.txt");                    <i>// optional filter</i>
switch ( <b>chooser-&gt;show</b>() ) {
    case -1:    // ERROR
	fprintf(stderr, "*** ERROR show() failed:%s\n", <b>chooser-&gt;errmsg</b>());
	break;
    case 1:     // CANCEL
	fprintf(stderr, "*** CANCEL\n");
	break;
    default:    // USER PICKED A FILE
        fprintf(stderr, "Filename was '%s'\n", <b>chooser-&gt;filename</b>());
	break;
}
<p><hr><p>
<b>// EXAMPLE 'SAVEAS' FILE BROWSER</b>
#include &lt;fltk/NativeFileChooser.h&gt;
:
fltk::NativeFileChooser *chooser = <b>new fltk::NativeFileChooser</b>();
<b>chooser-&gt;type</b>(fltk::NativeFileChooser::BROWSE_SAVE_FILE);   <i>// 'saveas' browser</i>
<b>chooser-&gt;title</b>("Save As..");                                  <i>// optional title for chooser window</i>
<b>chooser-&gt;directory</b>("/var/tmp");                               <i>// optional starting directory</i>
<b>chooser-&gt;preset_file</b>("untitled.txt");                         <i>// optional default filename</i>
<b>chooser-&gt;filter</b>("Text Files\t*.txt");                         <i>// optional filter</i>
switch ( <b>chooser-&gt;show</b>() ) {
    case -1:    // ERROR
	fprintf(stderr, "*** ERROR show() failed:%s\n", <b>chooser-&gt;errmsg</b>());
	break;
    case 1:     // CANCEL
	fprintf(stderr, "*** CANCEL\n");
	break;
    default:    // USER PICKED A FILE
        fprintf(stderr, "Filename was '%s'\n", <b>chooser-&gt;filename</b>());
	break;
}
    </pre>
</ul>

<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>

<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>

<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>
<br> <br> <br> <br> <br> <br>

</body>
</html>