Fl_Native_File_Chooser_WIN32.H 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // "$Id: Fl_Native_File_Chooser_WIN32.H 7003 2010-01-14 20:47:59Z greg.ercolano $"
  3. //
  4. // FLTK native OS file chooser widget
  5. //
  6. // Copyright 1998-2005 by Bill Spitzak and others.
  7. // Copyright 2004 by Greg Ercolano.
  8. // April 2005 - API changes, improved filter processing by Nathan Vander Wilt
  9. //
  10. // This library is free software; you can redistribute it and/or
  11. // modify it under the terms of the GNU Library General Public
  12. // License as published by the Free Software Foundation; either
  13. // version 2 of the License, or (at your option) any later version.
  14. //
  15. // This library is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. // Library General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU Library General Public
  21. // License along with this library; if not, write to the Free Software
  22. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  23. // USA.
  24. //
  25. // Please report all bugs and problems to:
  26. //
  27. // http://www.fltk.org/str.php
  28. //
  29. #ifndef FL_DOXYGEN // PREVENT DOXYGEN'S USE OF THIS FILE
  30. // #define _WIN32_WINNT 0x0501 // needed for OPENFILENAME's 'FlagsEx'
  31. #include <stdio.h>
  32. #include <stdlib.h> // malloc
  33. #include <windows.h>
  34. #include <commdlg.h> // OPENFILENAME, GetOpenFileName()
  35. #include <shlobj.h> // BROWSEINFO, SHBrowseForFolder()
  36. class Fl_Native_File_Chooser {
  37. public:
  38. enum Type {
  39. BROWSE_FILE = 0,
  40. BROWSE_DIRECTORY,
  41. BROWSE_MULTI_FILE,
  42. BROWSE_MULTI_DIRECTORY,
  43. BROWSE_SAVE_FILE,
  44. BROWSE_SAVE_DIRECTORY
  45. };
  46. enum Option {
  47. NO_OPTIONS = 0x0000, // no options enabled
  48. SAVEAS_CONFIRM = 0x0001, // Show native 'Save As' overwrite confirm dialog (if supported)
  49. NEW_FOLDER = 0x0002, // Show 'New Folder' icon (if supported)
  50. PREVIEW = 0x0004, // enable preview mode
  51. };
  52. private:
  53. int _btype; // kind-of browser to show()
  54. int _options; // general options
  55. OPENFILENAMEW _ofn; // GetOpenFileName() & GetSaveFileName() struct
  56. BROWSEINFO _binf; // SHBrowseForFolder() struct
  57. char **_pathnames; // array of pathnames
  58. int _tpathnames; // total pathnames
  59. char *_directory; // default pathname to use
  60. char *_title; // title for window
  61. char *_filter; // user-side search filter
  62. char *_parsedfilt; // filter parsed for Windows dialog
  63. int _nfilters; // number of filters parse_filter counted
  64. char *_preset_file; // the file to preselect
  65. char *_errmsg; // error message
  66. // Private methods
  67. void errmsg(const char *msg);
  68. void clear_pathnames();
  69. void set_single_pathname(const char *s);
  70. void add_pathname(const char *s);
  71. void FreePIDL(ITEMIDLIST *pidl);
  72. void ClearOFN();
  73. void ClearBINF();
  74. void Win2Unix(char *s);
  75. void Unix2Win(char *s);
  76. int showfile();
  77. static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
  78. int showdir();
  79. void parse_filter(const char *);
  80. void clear_filters();
  81. void add_filter(const char *, const char *);
  82. public:
  83. Fl_Native_File_Chooser(int val = BROWSE_FILE);
  84. ~Fl_Native_File_Chooser();
  85. // Public methods
  86. void type(int val);
  87. int type() const;
  88. void options(int);
  89. int options() const;
  90. int count() const;
  91. const char *filename() const;
  92. const char *filename(int i) const;
  93. void directory(const char *val);
  94. const char *directory() const;
  95. void title(const char *val);
  96. const char *title() const;
  97. const char *filter() const;
  98. void filter(const char *val);
  99. int filters() const { return _nfilters; }
  100. void filter_value(int i);
  101. int filter_value() const;
  102. void preset_file(const char *);
  103. const char *preset_file() const;
  104. const char *errmsg() const;
  105. int show();
  106. };
  107. #endif /*!FL_DOXYGEN*/
  108. //
  109. // End of "$Id: Fl_Native_File_Chooser_WIN32.H 7003 2010-01-14 20:47:59Z greg.ercolano $".
  110. //