forms_fselect.cxx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // "$Id: forms_fselect.cxx 8864 2011-07-19 04:49:30Z greg.ercolano $"
  3. //
  4. // Forms file selection routines for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  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 on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. // Emulate the Forms file chooser using the fltk file chooser.
  19. #include <FL/forms.H>
  20. #include "flstring.h"
  21. static char fl_directory[FL_PATH_MAX];
  22. static const char *fl_pattern; // assumed passed value is static
  23. static char fl_filename[FL_PATH_MAX];
  24. char* fl_show_file_selector(const char *message,const char *dir,
  25. const char *pat,const char *fname) {
  26. if (dir && dir[0]) strlcpy(fl_directory,dir,sizeof(fl_directory));
  27. if (pat && pat[0]) fl_pattern = pat;
  28. if (fname && fname[0]) strlcpy(fl_filename,fname,sizeof(fl_filename));
  29. char *p = fl_directory+strlen(fl_directory);
  30. if (p > fl_directory && *(p-1)!='/'
  31. #ifdef WIN32
  32. && *(p-1)!='\\' && *(p-1)!=':'
  33. #endif
  34. ) *p++ = '/';
  35. strlcpy(p,fl_filename,sizeof(fl_directory) - (p - fl_directory));
  36. const char *q = fl_file_chooser(message,fl_pattern,fl_directory);
  37. if (!q) return 0;
  38. strlcpy(fl_directory, q, sizeof(fl_directory));
  39. p = (char *)fl_filename_name(fl_directory);
  40. strlcpy(fl_filename, p, sizeof(fl_filename));
  41. if (p > fl_directory+1) p--;
  42. *p = 0;
  43. return (char *)q;
  44. }
  45. char* fl_get_directory() {return fl_directory;}
  46. char* fl_get_pattern() {return (char *)fl_pattern;}
  47. char* fl_get_filename() {return fl_filename;}
  48. //
  49. // End of "$Id: forms_fselect.cxx 8864 2011-07-19 04:49:30Z greg.ercolano $".
  50. //