FLTK 1.3.0
|
00001 // 00002 // "$Id$" 00003 // 00004 // FLTK native OS file chooser widget 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // Copyright 2004 Greg Ercolano. 00008 // 00009 // This library is free software. Distribution and use rights are outlined in 00010 // the file "COPYING" which should have been included with this file. If this 00011 // file is missing or damaged, see the license at: 00012 // 00013 // http://www.fltk.org/COPYING.php 00014 // 00015 // Please report all bugs and problems on the following page: 00016 // 00017 // http://www.fltk.org/str.php 00018 // 00019 00023 #ifndef FL_NATIVE_FILE_CHOOSER_H 00024 #define FL_NATIVE_FILE_CHOOSER_H 00025 00026 /* \file 00027 Fl_Native_File_Chooser widget. */ 00028 00029 // Use Windows' chooser 00030 #ifdef WIN32 00031 // #define _WIN32_WINNT 0x0501 // needed for OPENFILENAME's 'FlagsEx' 00032 #include <stdio.h> 00033 #include <stdlib.h> // malloc 00034 #include <windows.h> 00035 #include <commdlg.h> // OPENFILENAME, GetOpenFileName() 00036 #include <shlobj.h> // BROWSEINFO, SHBrowseForFolder() 00037 #endif 00038 00039 // Use Apple's chooser 00040 #ifdef __APPLE__ 00041 #define MAXFILTERS 80 00042 #endif 00043 00044 // All else falls back to FLTK's own chooser 00045 #if ! defined(__APPLE__) && !defined(WIN32) 00046 #include <FL/Fl_File_Chooser.H> 00047 #include <unistd.h> // _POSIX_NAME_MAX 00048 #else 00049 #include <FL/filename.H> // FL_EXPORT 00050 #endif 00051 00052 00099 class FL_EXPORT Fl_Native_File_Chooser { 00100 public: 00101 enum Type { 00102 BROWSE_FILE = 0, 00103 BROWSE_DIRECTORY, 00104 BROWSE_MULTI_FILE, 00105 BROWSE_MULTI_DIRECTORY, 00106 BROWSE_SAVE_FILE, 00107 BROWSE_SAVE_DIRECTORY 00108 }; 00109 enum Option { 00110 NO_OPTIONS = 0x0000, 00111 SAVEAS_CONFIRM = 0x0001, 00112 NEW_FOLDER = 0x0002, 00113 PREVIEW = 0x0004 00114 }; 00116 static const char *file_exists_message; 00117 00118 public: 00119 Fl_Native_File_Chooser(int val=BROWSE_FILE); 00120 ~Fl_Native_File_Chooser(); 00121 00122 // Public methods 00123 void type(int); 00124 int type() const; 00125 void options(int); 00126 int options() const; 00127 int count() const; 00128 const char *filename() const; 00129 const char *filename(int i) const; 00130 void directory(const char *val); 00131 const char *directory() const; 00132 void title(const char *); 00133 const char* title() const; 00134 const char *filter() const; 00135 void filter(const char *); 00136 int filters() const; 00137 void filter_value(int i); 00138 int filter_value() const; 00139 void preset_file(const char*); 00140 const char* preset_file() const; 00141 const char *errmsg() const; 00142 int show(); 00143 00144 #ifdef WIN32 00145 private: 00146 int _btype; // kind-of browser to show() 00147 int _options; // general options 00148 OPENFILENAMEW _ofn; // GetOpenFileName() & GetSaveFileName() struct 00149 BROWSEINFO _binf; // SHBrowseForFolder() struct 00150 char **_pathnames; // array of pathnames 00151 int _tpathnames; // total pathnames 00152 char *_directory; // default pathname to use 00153 char *_title; // title for window 00154 char *_filter; // user-side search filter 00155 char *_parsedfilt; // filter parsed for Windows dialog 00156 int _nfilters; // number of filters parse_filter counted 00157 char *_preset_file; // the file to preselect 00158 char *_errmsg; // error message 00159 00160 // Private methods 00161 void errmsg(const char *msg); 00162 00163 void clear_pathnames(); 00164 void set_single_pathname(const char *s); 00165 void add_pathname(const char *s); 00166 00167 void FreePIDL(LPITEMIDLIST pidl); 00168 void ClearOFN(); 00169 void ClearBINF(); 00170 void Win2Unix(char *s); 00171 void Unix2Win(char *s); 00172 int showfile(); 00173 static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data); 00174 int showdir(); 00175 00176 void parse_filter(const char *); 00177 void clear_filters(); 00178 void add_filter(const char *, const char *); 00179 #endif 00180 00181 #ifdef __APPLE__ 00182 private: 00183 int _btype; // kind-of browser to show() 00184 int _options; // general options 00185 void *_panel; 00186 char **_pathnames; // array of pathnames 00187 int _tpathnames; // total pathnames 00188 char *_directory; // default pathname to use 00189 char *_title; // title for window 00190 char *_preset_file; // the 'save as' filename 00191 00192 char *_filter; // user-side search filter, eg: 00193 // C Files\t*.[ch]\nText Files\t*.txt" 00194 00195 char *_filt_names; // filter names (tab delimited) 00196 // eg. "C Files\tText Files" 00197 00198 char *_filt_patt[MAXFILTERS]; 00199 // array of filter patterns, eg: 00200 // _filt_patt[0]="*.{cxx,h}" 00201 // _filt_patt[1]="*.txt" 00202 00203 int _filt_total; // parse_filter() # of filters loaded 00204 int _filt_value; // index of the selected filter 00205 char *_errmsg; // error message 00206 00207 // Private methods 00208 void errmsg(const char *msg); 00209 void clear_pathnames(); 00210 void set_single_pathname(const char *s); 00211 int get_saveas_basename(void); 00212 void clear_filters(); 00213 void add_filter(const char *, const char *); 00214 void parse_filter(const char *from); 00215 int post(); 00216 #endif 00217 00218 #if ! defined(__APPLE__) && !defined(WIN32) 00219 private: 00220 int _btype; // kind-of browser to show() 00221 int _options; // general options 00222 int _nfilters; 00223 char *_filter; // user supplied filter 00224 char *_parsedfilt; // parsed filter 00225 int _filtvalue; // selected filter 00226 char *_preset_file; 00227 char *_prevvalue; // Returned filename 00228 char *_directory; 00229 char *_errmsg; // error message 00230 Fl_File_Chooser *_file_chooser; 00231 00232 // Private methods 00233 void errmsg(const char *msg); 00234 int type_fl_file(int); 00235 void parse_filter(); 00236 void keeplocation(); 00237 int exist_dialog(); 00238 #endif 00239 }; 00240 00241 00242 #endif /*FL_NATIVE_FILE_CHOOSER_H*/ 00243 00244 // 00245 // End of "$Id$". 00246 //