fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Native_File_Chooser_FLTK.cxx
Go to the documentation of this file.
1 // "$Id$"
2 //
3 // FLTK native file chooser widget wrapper for GTK's GtkFileChooserDialog
4 //
5 // Copyright 1998-2014 by Bill Spitzak and others.
6 // Copyright 2012 IMM
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems to:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 #include <config.h>
21 #include <FL/Fl_File_Icon.H>
22 #define FLTK_CHOOSER_SINGLE Fl_File_Chooser::SINGLE
23 #define FLTK_CHOOSER_DIRECTORY Fl_File_Chooser::DIRECTORY
24 #define FLTK_CHOOSER_MULTI Fl_File_Chooser::MULTI
25 #define FLTK_CHOOSER_CREATE Fl_File_Chooser::CREATE
26 
29 
30 #include <sys/stat.h>
31 #include <string.h>
32 
34 
41 #if FLTK_ABI_VERSION <= 10302
42  _btype = val;
44  _filter = NULL;
45  _filtvalue = 0;
46  _parsedfilt = NULL;
48  _prevvalue = NULL;
49  _directory = NULL;
50  _errmsg = NULL;
51 #endif // FLTK_ABI_VERSION
52  if (have_looked_for_GTK_libs == 0) {
53  // First Time here, try to find the GTK libs if they are installed
54 #if HAVE_DLSYM && HAVE_DLFCN_H
57  }
58 #endif
60  }
61  // if we found all the GTK functions we need, we will use the GtkFileChooserDialog
64 }
65 
71  delete _x11_file_chooser;
72 }
73 
78 
83 
99 
104 
119 
127 
142 const char *Fl_Native_File_Chooser::filename(int i) const { return _x11_file_chooser->filename(i); }
143 
150 
155 
162 
167 const char* Fl_Native_File_Chooser::title() const { return _x11_file_chooser->title(); }
168 
173 const char *Fl_Native_File_Chooser::filter() const { return _x11_file_chooser->filter(); }
174 
194 
199 
208 
214 
222 
227 
233 const char *Fl_Native_File_Chooser::errmsg() const { return _x11_file_chooser->errmsg(); }
234 
243 
245  _btype = 0;
246  _options = 0;
247  _filter = NULL;
248  _filtvalue = 0;
249  _parsedfilt = NULL;
250  _preset_file = NULL;
251  _prevvalue = NULL;
252  _directory = NULL;
253  _errmsg = NULL;
255  if (val >= 0) {
257  type(val); // do this after _file_chooser created
258  }
259  _nfilters = 0;
260 }
261 
263  delete _file_chooser;
271 }
272 
273 
274 // PRIVATE: SET ERROR MESSAGE
275 void Fl_FLTK_File_Chooser::errmsg(const char *msg) {
277  _errmsg = strnew(msg);
278 }
279 
280 // PRIVATE: translate Native types to Fl_File_Chooser types
282  switch (val) {
284  return(Fl_File_Chooser::SINGLE);
288  return(Fl_File_Chooser::MULTI);
295  default:
296  return(Fl_File_Chooser::SINGLE);
297  }
298 }
299 
301  _btype = val;
303 }
304 
306  return(_btype);
307 }
308 
310  _options = val;
311 }
312 
314  return(_options);
315 }
316 
318 
319  // FILTER
320  if ( _parsedfilt ) {
322  }
323 
324  // FILTER VALUE
325  // Set this /after/ setting the filter
326  //
328 
329  // DIRECTORY
330  if ( _directory && _directory[0] ) {
332  } else {
334  }
335 
336  // PRESET FILE
337  if ( _preset_file ) {
339  }
340 
341  // OPTIONS: PREVIEW
343 
344  // OPTIONS: NEW FOLDER
347 
348  // SHOW
349  _file_chooser->show();
350 
351  // BLOCK WHILE BROWSER SHOWN
352  while ( _file_chooser->shown() ) {
353  Fl::wait();
354  }
355 
356  if ( _file_chooser->value() && _file_chooser->value()[0] ) {
359  _filtvalue = _file_chooser->filter_value(); // update filter value
360 
361  // HANDLE SHOWING 'SaveAs' CONFIRM
363  struct stat buf;
364  if ( stat(_file_chooser->value(), &buf) != -1 ) {
365  if ( buf.st_mode & S_IFREG ) { // Regular file + exists?
366  if ( exist_dialog() == 0 ) {
367  return(1);
368  }
369  }
370  }
371  }
372  }
373 
374  if ( _file_chooser->count() ) return(0);
375  else return(1);
376 }
377 
378 const char *Fl_FLTK_File_Chooser::errmsg() const {
379  return(_errmsg ? _errmsg : "No error");
380 }
381 
382 const char* Fl_FLTK_File_Chooser::filename() const {
383  if ( _file_chooser->count() > 0 ) {
384  return(_file_chooser->value());
385  }
386  return("");
387 }
388 
389 const char* Fl_FLTK_File_Chooser::filename(int i) const {
390  if ( i < _file_chooser->count() )
391  return(_file_chooser->value(i+1)); // convert fltk 1 based to our 0 based
392  return("");
393 }
394 
395 void Fl_FLTK_File_Chooser::title(const char *val) {
396  _file_chooser->label(val);
397 }
398 
399 const char *Fl_FLTK_File_Chooser::title() const {
400  return(_file_chooser->label());
401 }
402 
403 void Fl_FLTK_File_Chooser::filter(const char *val) {
405  _filter = strnew(val);
406  parse_filter();
407 }
408 
409 const char *Fl_FLTK_File_Chooser::filter() const {
410  return(_filter);
411 }
412 
414  return(_nfilters);
415 }
416 
418  _filtvalue = val;
419 }
420 
422  return _filtvalue;
423 }
424 
426  return _file_chooser->count();
427 }
428 
429 void Fl_FLTK_File_Chooser::directory(const char *val) {
431  _directory = strnew(val);
432 }
433 
434 const char *Fl_FLTK_File_Chooser::directory() const {
435  return _directory;
436 }
437 
438 // PRIVATE: Convert our filter format to fltk's chooser format
439 // FROM TO (FLTK)
440 // ------------------------- --------------------------
441 // "*.cxx" "*.cxx Files(*.cxx)"
442 // "C Files\t*.{cxx,h}" "C Files(*.{cxx,h})"
443 // "C Files\t*.{cxx,h}\nText Files\t*.txt" "C Files(*.{cxx,h})\tText Files(*.txt)"
444 //
445 // Returns a modified version of the filter that the caller is responsible
446 // for freeing with strfree().
447 //
449  _parsedfilt = strfree(_parsedfilt); // clear previous parsed filter (if any)
450  _nfilters = 0;
451  char *in = _filter;
452  if ( !in ) return;
453 
454  int has_name = strchr(in, '\t') ? 1 : 0;
455 
456  char mode = has_name ? 'n' : 'w'; // parse mode: n=title, w=wildcard
457  char wildcard[1024] = ""; // parsed wildcard
458  char name[1024] = "";
459 
460  // Parse filter user specified
461  for ( ; 1; in++ ) {
462  /*** DEBUG
463  printf("WORKING ON '%c': mode=<%c> name=<%s> wildcard=<%s>\n",
464  *in, mode, name, wildcard);
465  ***/
466 
467  switch (*in) {
468  // FINISHED PARSING NAME?
469  case '\t':
470  if ( mode != 'n' ) goto regchar;
471  mode = 'w';
472  break;
473  // ESCAPE NEXT CHAR
474  case '\\':
475  ++in;
476  goto regchar;
477  // FINISHED PARSING ONE OF POSSIBLY SEVERAL FILTERS?
478  case '\r':
479  case '\n':
480  case '\0':
481  // APPEND NEW FILTER TO LIST
482  if ( wildcard[0] ) {
483  // OUT: "name(wild)\tname(wild)"
484  char comp[2048];
485  sprintf(comp, "%s%.511s(%.511s)", ((_parsedfilt)?"\t":""),
486  name, wildcard);
487  _parsedfilt = strapp(_parsedfilt, comp);
488  _nfilters++;
489  //DEBUG printf("DEBUG: PARSED FILT NOW <%s>\n", _parsedfilt);
490  }
491  // RESET
492  wildcard[0] = name[0] = '\0';
493  mode = strchr(in, '\t') ? 'n' : 'w';
494  // DONE?
495  if ( *in == '\0' ) return; // done
496  else continue; // not done yet, more filters
497 
498  // Parse all other chars
499  default: // handle all non-special chars
500  regchar: // handle regular char
501  switch ( mode ) {
502  case 'n': chrcat(name, *in); continue;
503  case 'w': chrcat(wildcard, *in); continue;
504  }
505  break;
506  }
507  }
508  //NOTREACHED
509 }
510 
511 void Fl_FLTK_File_Chooser::preset_file(const char* val) {
513  _preset_file = strnew(val);
514 }
515 
517  return _preset_file;
518 }
519 
522 }
523 
524 //
525 // End of "$Id$".
526 //
Fl_FLTK_File_Chooser::options
void options(int)
Definition: Fl_Native_File_Chooser_FLTK.cxx:309
Fl_FLTK_File_Chooser::errmsg
const char * errmsg() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:378
Fl_Native_File_Chooser::_errmsg
char * _errmsg
Definition: Fl_Native_File_Chooser.H:248
buf
static char * buf
Definition: fl_encoding_mac_roman.cxx:76
Fl_Native_File_Chooser::_gtk_file_chooser
Fl_GTK_File_Chooser * _gtk_file_chooser
Definition: Fl_Native_File_Chooser.H:253
Fl_Native_File_Chooser::_parsedfilt
char * _parsedfilt
Definition: Fl_Native_File_Chooser.H:243
Fl_Native_File_Chooser::errmsg
const char * errmsg() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:233
Fl_FLTK_File_Chooser::preset_file
void preset_file(const char *)
Definition: Fl_Native_File_Chooser_FLTK.cxx:511
Fl_Native_File_Chooser::NO_OPTIONS
no options enabled
Definition: Fl_Native_File_Chooser.H:122
Fl_Native_File_Chooser::_filtvalue
int _filtvalue
Definition: Fl_Native_File_Chooser.H:244
Fl_File_Chooser::preview
void preview(int e)
Definition: Fl_File_Chooser2.cxx:1097
Fl_Native_File_Chooser::_x11_file_chooser
Fl_FLTK_File_Chooser * _x11_file_chooser
Definition: Fl_Native_File_Chooser.H:252
Fl_File_Chooser::CREATE
Definition: Fl_File_Chooser.H:50
Fl_FLTK_File_Chooser
Definition: Fl_Native_File_Chooser.H:259
Fl_Native_File_Chooser::options
int options() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:103
Fl_Native_File_Chooser::BROWSE_MULTI_FILE
browse files (lets user choose multiple files)
Definition: Fl_Native_File_Chooser.H:116
Fl_File_Chooser::show
void show()
Definition: Fl_File_Chooser2.cxx:1597
Fl_Native_File_Chooser::filter
const char * filter() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:173
Fl_FLTK_File_Chooser::show
virtual int show()
Definition: Fl_Native_File_Chooser_FLTK.cxx:317
Fl_File_Chooser::label
void label(const char *l)
Definition: Fl_File_Chooser.cxx:369
Fl_FLTK_File_Chooser::type
virtual void type(int)
Definition: Fl_Native_File_Chooser_FLTK.cxx:300
NULL
#define NULL
Definition: forms.H:34
Fl_Native_File_Chooser::BROWSE_MULTI_DIRECTORY
browse directories (lets user choose multiple directories)
Definition: Fl_Native_File_Chooser.H:117
Fl_FLTK_File_Chooser::filter_value
int filter_value() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:421
Fl_FLTK_File_Chooser::options
int options() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:313
Fl_FLTK_File_Chooser::preset_file
const char * preset_file() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:516
Fl_Native_File_Chooser::Fl_Native_File_Chooser
Fl_Native_File_Chooser(int val=BROWSE_FILE)
Definition: Fl_Native_File_Chooser_FLTK.cxx:40
Fl_File_Chooser::value
const char * value(int f=1)
Definition: Fl_File_Chooser2.cxx:1477
Fl_File_Chooser::SINGLE
Definition: Fl_File_Chooser.H:50
Fl_Native_File_Chooser::BROWSE_SAVE_DIRECTORY
browse to save a directory
Definition: Fl_Native_File_Chooser.H:119
Fl_FLTK_File_Chooser::_filter
char * _filter
Definition: Fl_Native_File_Chooser.H:265
Fl_File_Chooser::filter
void filter(const char *p)
Definition: Fl_File_Chooser2.cxx:1010
strfree
static char * strfree(char *val)
Definition: Fl_Native_File_Chooser_common.cxx:35
fl_choice
int fl_choice(const char *q, const char *b0, const char *b1, const char *b2,...)
Definition: fl_ask.cxx:459
Fl_Native_File_Chooser::file_exists_message
static const char * file_exists_message
Definition: Fl_Native_File_Chooser.H:129
chrcat
static void chrcat(char *s, char c)
Definition: Fl_Native_File_Chooser_common.cxx:69
strnew
static char * strnew(const char *val)
Definition: Fl_Native_File_Chooser_common.cxx:25
Fl_FLTK_File_Chooser::_nfilters
int _nfilters
Definition: Fl_Native_File_Chooser.H:264
Fl_Native_File_Chooser::_preset_file
char * _preset_file
Definition: Fl_Native_File_Chooser.H:245
Fl_GTK_File_Chooser::did_find_GTK_libs
static int did_find_GTK_libs
Definition: Fl_Native_File_Chooser.H:328
Fl_Native_File_Chooser::filters
int filters() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:198
Fl_FLTK_File_Chooser::_parsedfilt
char * _parsedfilt
Definition: Fl_Native_File_Chooser.H:266
Fl_GTK_File_Chooser
Definition: Fl_Native_File_Chooser.H:302
Fl_Native_File_Chooser::count
int count() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:118
Fl_Native_File_Chooser::_btype
int _btype
Definition: Fl_Native_File_Chooser.H:239
Fl_Native_File_Chooser_GTK.cxx
Fl_FLTK_File_Chooser::parse_filter
void parse_filter()
Definition: Fl_Native_File_Chooser_FLTK.cxx:448
Fl_FLTK_File_Chooser::count
virtual int count() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:425
Fl_FLTK_File_Chooser::exist_dialog
int exist_dialog()
Definition: Fl_Native_File_Chooser_FLTK.cxx:520
Fl_Native_File_Chooser::BROWSE_SAVE_FILE
browse to save a file
Definition: Fl_Native_File_Chooser.H:118
Fl::option
static bool option(Fl_Option opt)
FLTK library options management.
Definition: Fl.cxx:2182
Fl_FLTK_File_Chooser::_filtvalue
int _filtvalue
Definition: Fl_Native_File_Chooser.H:267
Fl_FLTK_File_Chooser::_prevvalue
char * _prevvalue
Definition: Fl_Native_File_Chooser.H:269
Fl_File_Chooser::filter_value
int filter_value()
Definition: Fl_File_Chooser.cxx:348
Fl_FLTK_File_Chooser::filename
virtual const char * filename() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:382
Fl_Native_File_Chooser::filename
const char * filename() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:126
Fl_Native_File_Chooser::filter_value
int filter_value() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:213
Fl_File_Chooser::shown
int shown()
Definition: Fl_File_Chooser.cxx:390
fl_ok
const char * fl_ok
string pointer used in common dialogs, you can change it to another language
Definition: fl_ask.cxx:273
Fl_FLTK_File_Chooser::_errmsg
char * _errmsg
Definition: Fl_Native_File_Chooser.H:271
Fl_Native_File_Chooser::directory
const char * directory() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:154
Fl_Native_File_Chooser::preset_file
const char * preset_file() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:226
Fl_FLTK_File_Chooser::title
virtual void title(const char *)
Definition: Fl_Native_File_Chooser_FLTK.cxx:395
Fl::OPTION_FNFC_USES_GTK
Definition: Fl.H:224
Fl_FLTK_File_Chooser::title
virtual const char * title() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:399
Fl_Native_File_Chooser_common.cxx
Fl_File_Chooser::count
int count()
Definition: Fl_File_Chooser2.cxx:421
Fl_FLTK_File_Chooser::errmsg
void errmsg(const char *msg)
Definition: Fl_Native_File_Chooser_FLTK.cxx:275
Fl_File_Icon.H
Fl_Native_File_Chooser::BROWSE_DIRECTORY
browse directories (lets user choose one directory)
Definition: Fl_Native_File_Chooser.H:115
Fl_File_Chooser::DIRECTORY
Definition: Fl_File_Chooser.H:50
Fl_File_Chooser
Definition: Fl_File_Chooser.H:48
Fl_Native_File_Chooser::have_looked_for_GTK_libs
static int have_looked_for_GTK_libs
Definition: Fl_Native_File_Chooser.H:250
Fl_Native_File_Chooser::type
int type() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:82
Fl_GTK_File_Chooser::probe_for_GTK_libs
static void probe_for_GTK_libs(void)
Definition: Fl_Native_File_Chooser_GTK.cxx:649
Fl_File_Chooser::directory
void directory(const char *d)
Definition: Fl_File_Chooser2.cxx:458
Fl_Native_File_Chooser::title
const char * title() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:167
Fl_FLTK_File_Chooser::_btype
int _btype
Definition: Fl_Native_File_Chooser.H:262
Fl::wait
static int wait()
Definition: Fl.cxx:666
Fl_FLTK_File_Chooser::Fl_FLTK_File_Chooser
Fl_FLTK_File_Chooser(int val)
Definition: Fl_Native_File_Chooser_FLTK.cxx:244
Fl_FLTK_File_Chooser::filters
int filters() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:413
Fl_FLTK_File_Chooser::_directory
char * _directory
Definition: Fl_Native_File_Chooser.H:270
Fl_FLTK_File_Chooser::~Fl_FLTK_File_Chooser
virtual ~Fl_FLTK_File_Chooser()
Definition: Fl_Native_File_Chooser_FLTK.cxx:262
Fl_Native_File_Chooser::BROWSE_FILE
browse files (lets user choose one file)
Definition: Fl_Native_File_Chooser.H:114
Fl_FLTK_File_Chooser::_file_chooser
Fl_File_Chooser * _file_chooser
Definition: Fl_Native_File_Chooser.H:278
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
Fl_Native_File_Chooser.H
Fl_FLTK_File_Chooser::filter
const char * filter() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:409
Fl_FLTK_File_Chooser::directory
void directory(const char *val)
Definition: Fl_Native_File_Chooser_FLTK.cxx:429
fl_cancel
const char * fl_cancel
string pointer used in common dialogs, you can change it to another language
Definition: fl_ask.cxx:274
Fl_FLTK_File_Chooser::_options
int _options
Definition: Fl_Native_File_Chooser.H:263
Fl_FLTK_File_Chooser::type_fl_file
int type_fl_file(int)
Definition: Fl_Native_File_Chooser_FLTK.cxx:281
Fl_Native_File_Chooser::_directory
char * _directory
Definition: Fl_Native_File_Chooser.H:247
Fl_FLTK_File_Chooser::filter_value
void filter_value(int i)
Definition: Fl_Native_File_Chooser_FLTK.cxx:417
Fl_FLTK_File_Chooser::directory
const char * directory() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:434
Fl_File_Chooser::MULTI
Definition: Fl_File_Chooser.H:50
Fl_Native_File_Chooser::_prevvalue
char * _prevvalue
Definition: Fl_Native_File_Chooser.H:246
Fl_FLTK_File_Chooser::type
int type() const
Definition: Fl_Native_File_Chooser_FLTK.cxx:305
Fl_FLTK_File_Chooser::_preset_file
char * _preset_file
Definition: Fl_Native_File_Chooser.H:268
Fl_File_Chooser::type
void type(int t)
Definition: Fl_File_Chooser.cxx:418
name
static const char * name
Definition: Fl_arg.cxx:53
Fl_Native_File_Chooser::~Fl_Native_File_Chooser
~Fl_Native_File_Chooser()
Definition: Fl_Native_File_Chooser_FLTK.cxx:70
Fl_Native_File_Chooser::SAVEAS_CONFIRM
Show native 'Save As' overwrite confirm dialog.
Definition: Fl_Native_File_Chooser.H:123
Fl_Native_File_Chooser::show
int show()
Definition: Fl_Native_File_Chooser_FLTK.cxx:242
Fl_Native_File_Chooser::NEW_FOLDER
Show 'New Folder' icon (if supported)
Definition: Fl_Native_File_Chooser.H:124
strapp
static char * strapp(char *s, const char *val)
Definition: Fl_Native_File_Chooser_common.cxx:51
Fl_Native_File_Chooser::_options
int _options
Definition: Fl_Native_File_Chooser.H:240
Fl_Native_File_Chooser::PREVIEW
enable preview mode (if supported)
Definition: Fl_Native_File_Chooser.H:125
Fl_Native_File_Chooser::_filter
char * _filter
Definition: Fl_Native_File_Chooser.H:242