FLTK 1.3.0
Fl_Native_File_Chooser.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl_Native_File_Chooser.H 8380 2011-02-06 10:07:28Z manolo $"
3 //
4 // FLTK native OS file chooser widget
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 // Copyright 2004 Greg Ercolano.
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Library General Public
11 // License as published by the Free Software Foundation; either
12 // version 2 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Library General Public License for more details.
18 //
19 // You should have received a copy of the GNU Library General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 // USA.
23 //
24 // Please report all bugs and problems on the following page:
25 //
26 // http://www.fltk.org/str.php
27 //
28 
83 #ifndef FL_NATIVE_FILE_CHOOSER_H
84 #define FL_NATIVE_FILE_CHOOSER_H
85 
86 /* \file
87  Fl_Native_File_Chooser widget. */
88 
89 // Use Windows' chooser
90 #ifdef WIN32
91 // #define _WIN32_WINNT 0x0501 // needed for OPENFILENAME's 'FlagsEx'
92 #include <stdio.h>
93 #include <stdlib.h> // malloc
94 #include <windows.h>
95 #include <commdlg.h> // OPENFILENAME, GetOpenFileName()
96 #include <shlobj.h> // BROWSEINFO, SHBrowseForFolder()
97 #endif
98 
99 // Use Apple's chooser
100 #ifdef __APPLE__
101 #include <FL/filename.H>
102 #define MAXFILTERS 80
103 #endif
104 
105 // All else falls back to FLTK's own chooser
106 #if ! defined(__APPLE__) && !defined(WIN32)
107 #include <FL/Fl_File_Chooser.H>
108 #include <unistd.h> // _POSIX_NAME_MAX
109 #endif
110 
111 
158 class FL_EXPORT Fl_Native_File_Chooser {
159 public:
160  enum Type {
161  BROWSE_FILE = 0,
166  BROWSE_SAVE_DIRECTORY
167  };
168  enum Option {
169  NO_OPTIONS = 0x0000,
170  SAVEAS_CONFIRM = 0x0001,
171  NEW_FOLDER = 0x0002,
172  PREVIEW = 0x0004
173  };
175  static const char *file_exists_message;
176 
177 public:
178  Fl_Native_File_Chooser(int val=BROWSE_FILE);
180 
181  // Public methods
182  void type(int);
183  int type() const;
184  void options(int);
185  int options() const;
186  int count() const;
187  const char *filename() const;
188  const char *filename(int i) const;
189  void directory(const char *val);
190  const char *directory() const;
191  void title(const char *);
192  const char* title() const;
193  const char *filter() const;
194  void filter(const char *);
195  int filters() const;
196  void filter_value(int i);
197  int filter_value() const;
198  void preset_file(const char*);
199  const char* preset_file() const;
200  const char *errmsg() const;
201  int show();
202 
203 #ifdef WIN32
204 private:
205  int _btype; // kind-of browser to show()
206  int _options; // general options
207  OPENFILENAMEW _ofn; // GetOpenFileName() & GetSaveFileName() struct
208  BROWSEINFO _binf; // SHBrowseForFolder() struct
209  char **_pathnames; // array of pathnames
210  int _tpathnames; // total pathnames
211  char *_directory; // default pathname to use
212  char *_title; // title for window
213  char *_filter; // user-side search filter
214  char *_parsedfilt; // filter parsed for Windows dialog
215  int _nfilters; // number of filters parse_filter counted
216  char *_preset_file; // the file to preselect
217  char *_errmsg; // error message
218 
219  // Private methods
220  void errmsg(const char *msg);
221 
222  void clear_pathnames();
223  void set_single_pathname(const char *s);
224  void add_pathname(const char *s);
225 
226  void FreePIDL(ITEMIDLIST *pidl);
227  void ClearOFN();
228  void ClearBINF();
229  void Win2Unix(char *s);
230  void Unix2Win(char *s);
231  int showfile();
232  static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
233  int showdir();
234 
235  void parse_filter(const char *);
236  void clear_filters();
237  void add_filter(const char *, const char *);
238 #endif
239 
240 #ifdef __APPLE__
241 private:
242  int _btype; // kind-of browser to show()
243  int _options; // general options
244  void *_panel;
245  char **_pathnames; // array of pathnames
246  int _tpathnames; // total pathnames
247  char *_directory; // default pathname to use
248  char *_title; // title for window
249  char *_preset_file; // the 'save as' filename
250 
251  char *_filter; // user-side search filter, eg:
252  // C Files\t*.[ch]\nText Files\t*.txt"
253 
254  char *_filt_names; // filter names (tab delimited)
255  // eg. "C Files\tText Files"
256 
257  char *_filt_patt[MAXFILTERS];
258  // array of filter patterns, eg:
259  // _filt_patt[0]="*.{cxx,h}"
260  // _filt_patt[1]="*.txt"
261 
262  int _filt_total; // parse_filter() # of filters loaded
263  int _filt_value; // index of the selected filter
264  char *_errmsg; // error message
265 
266  // Private methods
267  void errmsg(const char *msg);
268  void clear_pathnames();
269  void set_single_pathname(const char *s);
270  int get_saveas_basename(void);
271  void clear_filters();
272  void add_filter(const char *, const char *);
273  void parse_filter(const char *from);
274  int post();
275 #endif
276 
277 #if ! defined(__APPLE__) && !defined(WIN32)
278 private:
279  int _btype; // kind-of browser to show()
280  int _options; // general options
281  int _nfilters;
282  char *_filter; // user supplied filter
283  char *_parsedfilt; // parsed filter
284  int _filtvalue; // selected filter
285  char *_preset_file;
286  char *_prevvalue; // Returned filename
287  char *_directory;
288  char *_errmsg; // error message
289  Fl_File_Chooser *_file_chooser;
290 
291  // Private methods
292  void errmsg(const char *msg);
293  int type_fl_file(int);
294  void parse_filter();
295  void keeplocation();
296  int exist_dialog();
297 #endif
298 };
299 
300 
301 #endif /*FL_NATIVE_FILE_CHOOSER_H*/
302 
303 //
304 // End of "$Id: Fl_Native_File_Chooser.H 8380 2011-02-06 10:07:28Z manolo $".
305 //