1 #ifndef FILEDIALOG_H 2 #define FILEDIALOG_H 3 4 #include "DialogBox.h" 5 #include "FileList.h" 6 #include "PathLinker.h" 7 8 class FileSelector; 9 class FileList; 10 11 12 // Additional mode for file selection : same as SELECTFILE_DIRECTORY but with the ability to also select files 13 enum 14 { 15 SELECT_FILE_ANY, // A single file, existing or not (to save to) 16 SELECT_FILE_EXISTING, // An existing file (to load), but not '.' and '..' 17 SELECT_FILE_MULTIPLE, // Multiple existing files 18 SELECT_FILE_MULTIPLE_ALL, // Multiple existing files or directories, but not '.' and '..' 19 SELECT_FILE_DIRECTORY, // Existing directory, including '.' or '..' 20 SELECT_FILE_MIXED, // An existing file or directory, including '.' and '..' 21 }; 22 23 24 // File selection widget 25 class FXAPI FileSelector : public FXPacker 26 { 27 FXDECLARE(FileSelector) 28 protected: 29 FileList* list; // File list widget 30 FXTextField* filename; // File name entry field 31 FXComboBox* filefilter; // Combobox for pattern list 32 FXCheckButton* readonly; // Open file as read only 33 FXButton* accept; // Accept button 34 FXButton* cancel; // Cancel button 35 FXuint selectmode; // Select mode 36 FXArrowButton* btnbackhist; // Back history 37 FXArrowButton* btnforwardhist; // Forward history 38 PathLinker* pathlink; 39 TextLabel* pathtext; 40 protected: FileSelector()41 FileSelector() : list(NULL), filename(NULL), filefilter(NULL), readonly(NULL), accept(NULL), cancel(NULL), 42 selectmode(0), btnbackhist(NULL), btnforwardhist(NULL), pathlink(NULL), pathtext(NULL) 43 {} 44 virtual void create(); 45 static FXString patternFromText(const FXString& pattern); 46 static FXString extensionFromPattern(const FXString& pattern); 47 48 private: 49 FileSelector(const FileSelector&); 50 FileSelector& operator=(const FileSelector&); 51 52 public: 53 long onCmdAccept(FXObject*, FXSelector, void*); 54 long onCmdFilter(FXObject*, FXSelector, void*); 55 long onCmdItemDoubleClicked(FXObject*, FXSelector, void*); 56 long onCmdItemClicked(FXObject*, FXSelector, void*); 57 long onCmdItemSelected(FXObject*, FXSelector, void*); 58 long onCmdItemDeselected(FXObject*, FXSelector, void*); 59 long onCmdDirUp(FXObject*, FXSelector, void*); 60 long onUpdDirUp(FXObject*, FXSelector, void*); 61 long onCmdDirBack(FXObject*, FXSelector, void*); 62 long onUpdDirBack(FXObject*, FXSelector, void*); 63 long onCmdDirForward(FXObject*, FXSelector, void*); 64 long onUpdDirForward(FXObject*, FXSelector, void*); 65 long onCmdDirBackHist(FXObject*, FXSelector, void*); 66 long onUpdDirBackHist(FXObject*, FXSelector, void*); 67 long onCmdDirForwardHist(FXObject*, FXSelector, void*); 68 long onUpdDirForwardHist(FXObject*, FXSelector, void*); 69 long onCmdHome(FXObject*, FXSelector, void*); 70 long onCmdWork(FXObject*, FXSelector, void*); 71 long onCmdNewDir(FXObject*, FXSelector, void*); 72 long onCmdNewFile(FXObject*, FXSelector, void*); 73 long onCmdPopupMenu(FXObject*, FXSelector, void*); 74 long onCmdKeyPress(FXObject*, FXSelector, void*); 75 long onCmdKeyRelease(FXObject*, FXSelector, void*); 76 public: 77 enum 78 { 79 ID_FILEFILTER=FXPacker::ID_LAST, 80 ID_ACCEPT, 81 ID_FILELIST, 82 ID_POPUP_MENU, 83 ID_DIR_UP, 84 ID_DIR_BACK, 85 ID_DIR_FORWARD, 86 ID_DIR_BACK_HIST, 87 ID_DIR_FORWARD_HIST, 88 ID_HOME, 89 ID_WORK, 90 ID_NEWDIR, 91 ID_NEWFILE, 92 ID_LAST 93 }; 94 public: 95 96 // Constructor 97 FileSelector(FXComposite* p, FXObject* tgt = NULL, FXSelector sel = 0, FXuint opts = 0, int x = 0, int y = 0, int w = 0, int h = 0); 98 99 // Return a pointer to the "Accept" button acceptButton()100 FXButton* acceptButton() const 101 { 102 return(accept); 103 } 104 105 // Return a pointer to the "Cancel" button cancelButton()106 FXButton* cancelButton() const 107 { 108 return(cancel); 109 } 110 111 // Change file name 112 void setFilename(const FXString& path); 113 114 // Return file name, if any 115 FXString getFilename() const; 116 117 // Return array of strings containing the selected file names, terminated 118 // by an empty string. This string array must be freed using delete []. 119 // If no files were selected, a NULL is returned. 120 FXString* getFilenames() const; 121 122 // Change file pattern 123 void setPattern(const FXString& ptrn); 124 125 // Return file pattern 126 FXString getPattern() const; 127 128 // Change the list of file patterns shown in the file dialog. 129 // Each pattern comprises an optional name, followed by a pattern in 130 // parentheses. The patterns are separated by newlines. 131 // For example, 132 // 133 // "*\n*.cpp,*.cc\n*.hpp,*.hh,*.h" 134 // 135 // and 136 // 137 // "All Files (*)\nC++ Sources (*.cpp,*.cc)\nC++ Headers (*.hpp,*.hh,*.h)" 138 // 139 // will set the same three patterns, but the former shows no pattern names. 140 void setPatternList(const FXString& patterns); 141 142 // Set list of patterns as name,pattern pairs. 143 // The list should be terminated with a final NULL string. 144 // (DEPRECATED) 145 void setPatternList(const char** ptrns); 146 147 // Return list of patterns 148 FXString getPatternList() const; 149 150 // After setting the list of patterns, this call will 151 // initially select pattern n as the active one. 152 void setCurrentPattern(int n); 153 154 // Return current pattern number 155 int getCurrentPattern() const; 156 157 // Get pattern text for given pattern number 158 FXString getPatternText(int patno) const; 159 160 // Change pattern text for pattern number 161 void setPatternText(int patno, const FXString& text); 162 163 // Change directory 164 void setDirectory(const FXString& path); 165 166 // Return directory 167 FXString getDirectory() const; 168 169 // Set the inter-item spacing (in pixels) 170 void setItemSpace(int s); 171 172 // Return the inter-item spacing (in pixels) 173 int getItemSpace() const; 174 175 // Change file list style 176 void setFileBoxStyle(FXuint style); 177 178 // Return file list style 179 FXuint getFileBoxStyle() const; 180 181 // Change file selection mode 182 void setSelectMode(FXuint mode); 183 184 // Return file selection mode getSelectMode()185 FXuint getSelectMode() const 186 { 187 return(selectmode); 188 } 189 190 // Show readonly button 191 void showReadOnly(FXbool show); 192 193 // Return true if readonly is shown 194 FXbool shownReadOnly() const; 195 196 // Set initial state of readonly button 197 void setReadOnly(FXbool state); 198 199 // Get readonly state 200 FXbool getReadOnly() const; 201 202 // Return true if hidden files are shown 203 FXbool shownHiddenFiles() const; 204 205 // Return true if thumbnails are shown 206 FXbool shownThumbnails() const; 207 208 // Change show hidden files mode 209 void showHiddenFiles(FXbool shown); 210 211 // Change show thumbnails files mode 212 void showThumbnails(FXbool shown); 213 214 // Destructor 215 virtual ~FileSelector(); 216 }; 217 218 219 // File Dialog object 220 class FXAPI FileDialog : public DialogBox 221 { FXDECLARE(FileDialog)222 FXDECLARE(FileDialog) 223 protected: 224 FileSelector* list; 225 protected: 226 FileDialog() : list(NULL) 227 {} 228 private: 229 FileDialog(const FileDialog&); 230 FileDialog& operator=(const FileDialog&); 231 232 public: 233 234 // Construct File Dialog Box 235 FileDialog(FXWindow* owner, const FXString& name, FXuint opts = 0, int x = 0, int y = 0, int w = 500, int h = 300); 236 237 // Change file name 238 void setFilename(const FXString& path); 239 240 // Return file name, if any 241 FXString getFilename() const; 242 243 // Return empty-string terminated list of selected file names, or NULL if none selected 244 FXString* getFilenames() const; 245 246 // Change file pattern 247 void setPattern(const FXString& ptrn); 248 249 // Return file pattern 250 FXString getPattern() const; 251 252 // Change the list of file patterns shown in the file dialog. 253 // Each pattern comprises an optional name, followed by a pattern in 254 // parentheses. The patterns are separated by newlines. 255 // For example, 256 // 257 // "*\n*.cpp,*.cc\n*.hpp,*.hh,*.h" 258 // 259 // and 260 // 261 // "All Files (*)\nC++ Sources (*.cpp,*.cc)\nC++ Headers (*.hpp,*.hh,*.h)" 262 // 263 // will set the same three patterns, but the former shows no pattern names. 264 void setPatternList(const FXString& patterns); 265 266 // Set list of patterns as name,pattern pairs. 267 // The list should be terminated with a final NULL string. 268 // (DEPRECATED) 269 void setPatternList(const char** ptrns); 270 271 // Return list of patterns 272 FXString getPatternList() const; 273 274 // After setting the list of patterns, this call will 275 // initially select pattern n as the active one. 276 void setCurrentPattern(int n); 277 278 // Return current pattern number 279 int getCurrentPattern() const; 280 281 // Get pattern text for given pattern number 282 FXString getPatternText(int patno) const; 283 284 // Change pattern text for pattern number 285 void setPatternText(int patno, const FXString& text); 286 287 // Change directory 288 void setDirectory(const FXString& path); 289 290 // Return directory 291 FXString getDirectory() const; 292 293 // Set the inter-item spacing (in pixels) 294 void setItemSpace(int s); 295 296 // Return the inter-item spacing (in pixels) 297 int getItemSpace() const; 298 299 // Change File List style 300 void setFileBoxStyle(FXuint style); 301 302 // Return File List style 303 FXuint getFileBoxStyle() const; 304 305 // Change file selection mode 306 void setSelectMode(FXuint mode); 307 308 // Return file selection mode 309 FXuint getSelectMode() const; 310 311 // Show readonly button 312 void showReadOnly(FXbool show); 313 314 // Return true if readonly is shown 315 FXbool shownReadOnly() const; 316 317 // Return true if hidden files are shown 318 FXbool shownHiddenFiles() const; 319 320 // Return true if thumbnails are shown 321 FXbool shownThumbnails() const; 322 323 // Change show hidden files mode 324 void showHiddenFiles(FXbool shown); 325 326 // Change show thumbnails files mode 327 void showThumbnails(FXbool shown); 328 329 // Set initial state of readonly button 330 void setReadOnly(FXbool state); 331 332 // Get readonly state 333 FXbool getReadOnly() const; 334 335 // Open existing filename 336 static FXString getOpenFilename(FXWindow* owner, const FXString& caption, const FXString& path, const FXString& patterns = "*", int initial = 0); 337 338 // Open multiple existing files 339 static FXString* getOpenFilenames(FXWindow* owner, const FXString& caption, const FXString& path, const FXString& patterns = "*", int initial = 0); 340 341 // Save to filename 342 static FXString getSaveFilename(FXWindow* owner, const FXString& caption, const FXString& path, const FXString& patterns = "*", int initial = 0); 343 344 // Open directory name 345 static FXString getOpenDirectory(FXWindow* owner, const FXString& caption, const FXString& path); 346 347 // Destructor 348 virtual ~FileDialog(); 349 }; 350 351 352 #endif 353