Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXFileSelector.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                  F i l e   S e l e c t i o n   W i d g e t                    *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXFileSelector.h,v 1.75 2009/01/06 13:07:24 fox Exp $                    *
00022 ********************************************************************************/
00023 #ifndef FXFILESELECTOR_H
00024 #define FXFILESELECTOR_H
00025 
00026 #ifndef FXPACKER_H
00027 #include "FXPacker.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 class FXFileDict;
00033 class FXFileList;
00034 class FXTextField;
00035 class FXComboBox;
00036 class FXDirBox;
00037 class FXButton;
00038 class FXMenuButton;
00039 class FXIcon;
00040 class FXMenuPane;
00041 class FXCheckButton;
00042 class FXMatrix;
00043 class FXHorizontalFrame;
00044 
00045 
00046 /// File selection modes
00047 enum {
00048   SELECTFILE_ANY,             /// A single file, existing or not (to save to)
00049   SELECTFILE_EXISTING,        /// An existing file (to load)
00050   SELECTFILE_MULTIPLE,        /// Multiple existing files
00051   SELECTFILE_MULTIPLE_ALL,    /// Multiple existing files or directories, but not '.' and '..'
00052   SELECTFILE_DIRECTORY        /// Existing directory, including '.' or '..'
00053   };
00054 
00055 
00056 /// File selection widget
00057 class FXAPI FXFileSelector : public FXPacker {
00058   FXDECLARE(FXFileSelector)
00059 protected:
00060   FXFileList        *filebox;           // File list widget
00061   FXTextField       *filename;          // File name entry field
00062   FXComboBox        *filefilter;        // Combobox for pattern list
00063   FXMenuPane        *bookmarkmenu;      // Menu for bookmarks
00064   FXHorizontalFrame *navbuttons;        // Navigation buttons
00065   FXHorizontalFrame *fileboxframe;      // Frame around file list
00066   FXMatrix          *entryblock;        // Entry block
00067   FXCheckButton     *readonly;          // Open file as read only
00068   FXDirBox          *dirbox;            // Directory hierarchy list
00069   FXButton          *accept;            // Accept button
00070   FXButton          *cancel;            // Cancel button
00071   FXIcon            *updiricon;         // Up directory icon
00072   FXIcon            *listicon;          // List mode icon
00073   FXIcon            *detailicon;        // Detail mode icon
00074   FXIcon            *iconsicon;         // Icon mode icon
00075   FXIcon            *homeicon;          // Go home icon
00076   FXIcon            *workicon;          // Go home icon
00077   FXIcon            *shownicon;         // Files shown icon
00078   FXIcon            *hiddenicon;        // Files hidden icon
00079   FXIcon            *markicon;          // Book mark icon
00080   FXIcon            *clearicon;         // Book clear icon
00081   FXIcon            *newicon;           // New directory icon
00082   FXIcon            *renameicon;        // Rename file icon
00083   FXIcon            *copyicon;          // Copy file icon
00084   FXIcon            *moveicon;          // Rename file icon
00085   FXIcon            *linkicon;          // Link file icon
00086   FXIcon            *deleteicon;        // Delete file icon
00087   FXRecentFiles      bookmarks;         // Bookmarked places
00088   FXuint             selectmode;        // Select mode
00089   FXbool             navigable;         // May navigate
00090 protected:
00091   FXFileSelector(){}
00092   FXString *getSelectedFiles() const;
00093   FXString *getSelectedFilesOnly() const;
00094 private:
00095   FXFileSelector(const FXFileSelector&);
00096   FXFileSelector &operator=(const FXFileSelector&);
00097 public:
00098   long onCmdAccept(FXObject*,FXSelector,void*);
00099   long onCmdFilter(FXObject*,FXSelector,void*);
00100   long onCmdItemDblClicked(FXObject*,FXSelector,void*);
00101   long onCmdItemSelected(FXObject*,FXSelector,void*);
00102   long onCmdItemDeselected(FXObject*,FXSelector,void*);
00103   long onCmdDirectoryUp(FXObject*,FXSelector,void*);
00104   long onUpdDirectoryUp(FXObject*,FXSelector,void*);
00105   long onCmdDirTree(FXObject*,FXSelector,void*);
00106   long onCmdHome(FXObject*,FXSelector,void*);
00107   long onCmdWork(FXObject*,FXSelector,void*);
00108   long onCmdBookmark(FXObject*,FXSelector,void*);
00109   long onCmdVisit(FXObject*,FXSelector,void*);
00110   long onCmdNew(FXObject*,FXSelector,void*);
00111   long onUpdNew(FXObject*,FXSelector,void*);
00112   long onCmdRename(FXObject*,FXSelector,void*);
00113   long onCmdCopy(FXObject*,FXSelector,void*);
00114   long onCmdMove(FXObject*,FXSelector,void*);
00115   long onCmdLink(FXObject*,FXSelector,void*);
00116   long onCmdRemove(FXObject*,FXSelector,void*);
00117   long onUpdSelected(FXObject*,FXSelector,void*);
00118   long onPopupMenu(FXObject*,FXSelector,void*);
00119   long onCmdImageSize(FXObject*,FXSelector,void*);
00120   long onUpdImageSize(FXObject*,FXSelector,void*);
00121   long onUpdNavigable(FXObject*,FXSelector,void*);
00122 public:
00123   enum {
00124     ID_FILEFILTER=FXPacker::ID_LAST,
00125     ID_ACCEPT,
00126     ID_FILELIST,
00127     ID_DIRECTORY_UP,
00128     ID_DIRTREE,
00129     ID_NORMAL_SIZE,
00130     ID_MEDIUM_SIZE,
00131     ID_GIANT_SIZE,
00132     ID_HOME,
00133     ID_WORK,
00134     ID_BOOKMARK,
00135     ID_BOOKMENU,
00136     ID_VISIT,
00137     ID_NEW,
00138     ID_RENAME,
00139     ID_COPY,
00140     ID_MOVE,
00141     ID_LINK,
00142     ID_REMOVE,
00143     ID_LAST
00144     };
00145 public:
00146 
00147   /// Constructor
00148   FXFileSelector(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
00149 
00150   /// Return a pointer to the "Accept" button
00151   FXButton *acceptButton() const { return accept; }
00152 
00153   /// Return a pointer to the "Cancel" button
00154   FXButton *cancelButton() const { return cancel; }
00155 
00156   /// Change file name
00157   void setFilename(const FXString& path);
00158 
00159   /// Return file name, if any
00160   FXString getFilename() const;
00161 
00162   /**
00163   * Return array of strings containing the selected file names, terminated
00164   * by an empty string.  This string array must be freed using delete [].
00165   * If no files were selected, a NULL is returned.
00166   */
00167   FXString* getFilenames() const;
00168 
00169   /// Change file pattern
00170   void setPattern(const FXString& ptrn);
00171 
00172   /// Return file pattern
00173   FXString getPattern() const;
00174 
00175   /**
00176   * Change the list of file patterns shown in the file dialog.
00177   * Each pattern comprises an optional name, followed by a pattern in
00178   * parentheses.  The patterns are separated by newlines.
00179   * For example,
00180   *
00181   *  "*\n*.cpp,*.cc\n*.hpp,*.hh,*.h"
00182   *
00183   * and
00184   *
00185   *  "All Files (*)\nC++ Sources (*.cpp,*.cc)\nC++ Headers (*.hpp,*.hh,*.h)"
00186   *
00187   * will set the same three patterns, but the former shows no pattern names.
00188   */
00189   void setPatternList(const FXString& patterns);
00190 
00191   /// Return list of patterns
00192   FXString getPatternList() const;
00193 
00194   /**
00195   * After setting the list of patterns, this call will
00196   * initially select pattern n as the active one.
00197   */
00198   void setCurrentPattern(FXint n);
00199 
00200   /// Return current pattern number
00201   FXint getCurrentPattern() const;
00202 
00203   /// Get pattern text for given pattern number
00204   FXString getPatternText(FXint patno) const;
00205 
00206   /// Change pattern text for pattern number
00207   void setPatternText(FXint patno,const FXString& text);
00208 
00209   /// Return number of patterns
00210   FXint getNumPatterns() const;
00211 
00212   /// Allow pattern entry
00213   void allowPatternEntry(FXbool flag);
00214 
00215   /// Return true if pattern entry is allowed
00216   FXbool allowPatternEntry() const;
00217 
00218   /**
00219   * Given filename pattern of the form "GIF Format (*.gif)",
00220   * returns the pattern only, i.e. "*.gif" in this case.
00221   * If the parentheses are not found then returns the entire
00222   * input pattern.
00223   */
00224   static FXString patternFromText(const FXString& pattern);
00225 
00226   /**
00227   * Given a pattern of the form "*.gif,*.GIF", return
00228   * the first extension of the pattern, i.e. "gif" in this
00229   * example. Returns empty string if it doesn't work out.
00230   */
00231   static FXString extensionFromPattern(const FXString& pattern);
00232 
00233   /// Change directory
00234   void setDirectory(const FXString& path);
00235 
00236   /// Return directory
00237   FXString getDirectory() const;
00238 
00239   /// Set the inter-item spacing (in pixels)
00240   void setItemSpace(FXint s);
00241 
00242   /// Return the inter-item spacing (in pixels)
00243   FXint getItemSpace() const;
00244 
00245   /// Change file list style
00246   void setFileBoxStyle(FXuint style);
00247 
00248   /// Return file list style
00249   FXuint getFileBoxStyle() const;
00250 
00251   /// Change file selection mode
00252   void setSelectMode(FXuint mode);
00253 
00254   /// Return file selection mode
00255   FXuint getSelectMode() const { return selectmode; }
00256 
00257   /// Change wildcard matching mode
00258   void setMatchMode(FXuint mode);
00259 
00260   /// Return wildcard matching mode
00261   FXuint getMatchMode() const;
00262 
00263   /// Return true if showing hidden files
00264   FXbool showHiddenFiles() const;
00265 
00266   /// Show or hide hidden files
00267   void showHiddenFiles(FXbool flag);
00268 
00269   /// Return true if image preview on
00270   FXbool showImages() const;
00271 
00272   /// Show or hide preview images
00273   void showImages(FXbool flag);
00274 
00275   /// Return images preview size
00276   FXint getImageSize() const;
00277 
00278   /// Change images preview size
00279   void setImageSize(FXint size);
00280 
00281   /// Show readonly button
00282   void showReadOnly(FXbool flag);
00283 
00284   /// Return true if readonly is shown
00285   FXbool shownReadOnly() const;
00286 
00287   /// Set initial state of readonly button
00288   void setReadOnly(FXbool flag);
00289 
00290   /// Get readonly state
00291   FXbool getReadOnly() const;
00292 
00293   /// Allow or disallow navigation
00294   void allowNavigation(FXbool flag){ navigable=flag; }
00295 
00296   /// Change file associations; delete old ones if owned
00297   void setAssociations(FXFileDict* assoc,FXbool owned=false);
00298 
00299   /// Return file associations
00300   FXFileDict* getAssociations() const;
00301 
00302   /// Is navigation allowed?
00303   FXbool allowNavigation() const { return navigable; }
00304 
00305   /// Set draggable files
00306   void setDraggableFiles(FXbool flag);
00307 
00308   /// Are draggable files
00309   FXbool getDraggableFiles() const;
00310 
00311   /// Save object to a stream
00312   virtual void save(FXStream& store) const;
00313 
00314   /// Load object from a stream
00315   virtual void load(FXStream& store);
00316 
00317   /// Destructor
00318   virtual ~FXFileSelector();
00319   };
00320 
00321 }
00322 
00323 #endif

Copyright © 1997-2009 Jeroen van der Zijp