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-1.x] Fl_Native_File_Chooser</title>
</head>
<body>
<H1>[Fltk-1.x] Fl_Native_File_Chooser</H1>
<h2>class Fl_Native_File_Chooser</a></h2>
<!--
<h3>Class Hierarchy</h3>
<ul>
<pre>
Fl_Native_File_Chooser
</pre>
</ul>
-->
<h3>Include Files</h3>
<ul>
<pre>
#include <FL/Fl_Native_File_Chooser.H>
</pre>
</ul>
Dowload latest source from <a href="http://seriss.com/people/erco/fltk/Fl_Native_File_Chooser/">here</a>.
<br>
<h3>Description</h3>
This class lets an FLTK 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 FLTK's default file chooser(s).
<p>
<h3>Methods</h3>
<center>
<table width="90%" summary="Fl_Native_File_Chooser methods">
<tr><td align="left" valign="top">
<ul>
<li> <a href="#Fl_Native_File_Chooser">Fl_Native_File_Chooser</a>
<li> <a href="#~Fl_Native_File_Chooser">~Fl_Native_File_Chooser</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>
<br>
<br>
</td> </tr> </table>
</center>
<h4><a name="Fl_Native_File_Chooser">
Fl_Native_File_Chooser::Fl_Native_File_Chooser()<br>
Fl_Native_File_Chooser::Fl_Native_File_Chooser(type)
</h4>
<ul>
The constructor for the Fl_Native_File_Chooser.
<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="~Fl_Native_File_Chooser">
Fl_Native_File_Chooser::~Fl_Native_File_Chooser()
</h4>
<ul>
The destructor; destroys any resources allocated to this widget.
</ul>
<h4>
<a name="count"></a>
int Fl_Native_File_Chooser::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 Fl_Native_File_Chooser::directory(const char*)<br>
const char* Fl_Native_File_Chooser::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 *Fl_Native_File_Chooser::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 *Fl_Native_File_Chooser::filename() const<br>
const char *Fl_Native_File_Chooser::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 < <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 *Fl_Native_File_Chooser::filter() const<br>
void Fl_Native_File_Chooser::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 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 Fl_Native_File_Chooser::filter_value(int)<br>
int Fl_Native_File_Chooser::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 Fl_Native_File_Chooser::filters()<br>
</h4>
<ul>
Gets how many filters were available, not including "All Files"
</ul>
<h4>
<a name="options"></a>
void Fl_Native_File_Chooser::options(int)<br>
int Fl_Native_File_Chooser::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>Fl_Native_File_Chooser::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>Fl_Native_File_Chooser::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>Fl_Native_File_Chooser::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 Fl_Native_File_Chooser::preset_file(const char*)<br>
const char* Fl_Native_File_Chooser::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 Fl_Native_File_Chooser::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 *Fl_Native_File_Chooser::title() const<br>
void Fl_Native_File_Chooser::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 Fl_Native_File_Chooser::type() const<br>
Fl_Native_File_Chooser::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>Fl_Native_File_Chooser::BROWSE_FILE</td>
<td BGCOLOR=#dddddd>Browse for a single file</td>
</tr><tr>
<td BGCOLOR=#dddddd align=left><tt>Fl_Native_File_Chooser::BROWSE_DIRECTORY</td>
<td BGCOLOR=#dddddd>Browse for a single directory</td>
</tr><tr>
<td BGCOLOR=#dddddd align=left><tt>Fl_Native_File_Chooser::BROWSE_MULTI_FILE</td>
<td BGCOLOR=#dddddd>Browse for multiple files</td>
</tr><tr>
<td BGCOLOR=#dddddd align=left><tt>Fl_Native_File_Chooser::BROWSE_MULTI_DIRECTORY</td>
<td BGCOLOR=#dddddd>Browse for multiple directories (implementation varies)</td>
</tr><tr>
<td BGCOLOR=#dddddd align=left><tt>Fl_Native_File_Chooser::BROWSE_SAVE_FILE</td>
<td BGCOLOR=#dddddd>Browse to save a single file</td>
</tr><tr>
<td BGCOLOR=#dddddd align=left><tt>Fl_Native_File_Chooser::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 Fl_Native_File_Chooser.
</ul>
<h3>Typical Usage</h3>
<ul>
<pre>
#include <Fl_Native_File_Chooser.H>
:
Fl_Native_File_Chooser *chooser = <b>new Fl_Native_File_Chooser</b>();
<b>chooser->type</b>(Fl_Native_File_Chooser::BROWSE_FILE); <i>// let user browse a single file</i>
<b>chooser->title</b>("Open a file"); <i>// optional title</i>
<b>chooser->preset_file</b>("/var/tmp/somefile.txt"); <i>// optional filename preset</i>
<b>chooser->filter</b>("Text Files\t*.txt"); <i>// optional filter</i>
switch ( <b>chooser->show</b>() ) {
case -1: // ERROR
fprintf(stderr, "*** ERROR show() failed:%s\n", <b>chooser->errmsg</b>());
break;
case 1: // CANCEL
fprintf(stderr, "*** CANCEL\n");
break;
default: // USER PICKED A FILE
fprintf(stderr, "Filename was '%s'\n", <b>chooser->filename</b>());
break;
}
<p><hr><p>
<b>// EXAMPLE 'SAVEAS' FILE BROWSER</b>
#include <Fl_Native_File_Chooser.H>
:
Fl_Native_File_Chooser *chooser = <b>new Fl_Native_File_Chooser</b>();
<b>chooser->type</b>(Fl_Native_File_Chooser::BROWSE_SAVE_FILE); <i>// 'saveas' browser</i>
<b>chooser->title</b>("Save As.."); <i>// optional title for chooser window</i>
<b>chooser->directory</b>("/var/tmp"); <i>// optional starting directory</i>
<b>chooser->preset_file</b>("untitled.txt"); <i>// optional default filename</i>
<b>chooser->filter</b>("Text Files\t*.txt"); <i>// optional filter</i>
switch ( <b>chooser->show</b>() ) {
case -1: // ERROR
fprintf(stderr, "*** ERROR show() failed:%s\n", <b>chooser->errmsg</b>());
break;
case 1: // CANCEL
fprintf(stderr, "*** CANCEL\n");
break;
default: // USER PICKED A FILE
fprintf(stderr, "Filename was '%s'\n", <b>chooser->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>
|