Main Page | Class Hierarchy | Class List | File List | Class Members

Flu_File_Chooser.h

00001 // $Id: Flu_File_Chooser.h,v 1.63 2004/10/18 15:14:58 jbryan Exp $
00002 
00003 /***************************************************************
00004  *                FLU - FLTK Utility Widgets 
00005  *  Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
00006  *
00007  * This file and its content is protected by a software license.
00008  * You should have received a copy of this license with this file.
00009  * If not, please contact the Ohio Supercomputer Center immediately:
00010  * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
00011  * 
00012  ***************************************************************/
00013 
00014 
00015 
00016 #ifndef _FLU_FILE_CHOOSER_H
00017 #define _FLU_FILE_CHOOSER_H
00018 
00019 #include <FL/Fl_Double_Window.H>
00020 #include <FL/Fl_Input.H>
00021 #include <FL/Fl_Menu_Button.H>
00022 #include <FL/Fl_Tile.H>
00023 #include <FL/Fl_Pack.H>
00024 #include <FL/Fl_Scroll.H>
00025 #include <FL/Fl_Check_Button.H>
00026 
00027 #include "FLU/Flu_Button.h"
00028 #include "FLU/Flu_Return_Button.h"
00029 #include "FLU/Flu_Wrap_Group.h"
00030 #include "FLU/Flu_Combo_Tree.h"
00031 #include "FLU/Flu_Combo_List.h"
00032 #include "FLU/flu_export.h"
00033 #include "FLU/FluSimpleString.h"
00034 #include "FLU/FluVectorClass.h"
00035 
00036 FluMakeVectorClass( FluSimpleString, FluStringVector );
00037 
00038 FLU_EXPORT const char* flu_file_chooser( const char *message, const char *pattern, const char *filename );
00039 FLU_EXPORT int flu_multi_file_chooser( const char *message, const char *pattern, const char *filename, FluStringVector *filelist );
00040 FLU_EXPORT const char* flu_save_chooser( const char *message, const char *pattern, const char *filename );
00041 FLU_EXPORT const char* flu_dir_chooser( const char *message, const char *filename );
00042 FLU_EXPORT const char* flu_dir_chooser( const char *message, const char *filename, bool showFiles );
00043 FLU_EXPORT const char* flu_file_and_dir_chooser( const char *message, const char *filename );
00044 
00046 class FLU_EXPORT Flu_File_Chooser : public Fl_Double_Window
00047 {
00048 
00049   friend class FileInput;
00050   class FileInput : public Fl_Input
00051     {
00052     public:
00053       FileInput( int x, int y, int w, int h, const char *l, Flu_File_Chooser *c );
00054       ~FileInput();
00055 
00056       int handle( int event );
00057     protected:
00058       Flu_File_Chooser *chooser;
00059     };
00060 
00061  public:
00062 
00064 
00065   static FluSimpleString favoritesTxt;
00066   static FluSimpleString desktopTxt;
00067   static FluSimpleString myComputerTxt;
00068   static FluSimpleString myDocumentsTxt;
00069 
00070   static FluSimpleString filenameTxt;
00071   static FluSimpleString okTxt;
00072   static FluSimpleString cancelTxt;
00073   static FluSimpleString locationTxt;
00074   static FluSimpleString showHiddenTxt;
00075   static FluSimpleString fileTypesTxt;
00076   static FluSimpleString directoryTxt;
00077   static FluSimpleString allFilesTxt;
00078   static FluSimpleString defaultFolderNameTxt;
00079 
00080   static FluSimpleString backTTxt;
00081   static FluSimpleString forwardTTxt;
00082   static FluSimpleString upTTxt;
00083   static FluSimpleString reloadTTxt;
00084   static FluSimpleString trashTTxt;
00085   static FluSimpleString newDirTTxt;
00086   static FluSimpleString addFavoriteTTxt;
00087   static FluSimpleString previewTTxt;
00088   static FluSimpleString listTTxt;
00089   static FluSimpleString wideListTTxt;
00090   static FluSimpleString detailTTxt;
00091 
00092   static FluSimpleString detailTxt[4];
00093   static FluSimpleString contextMenuTxt[3];
00094   static FluSimpleString diskTypesTxt[6];
00095 
00096   static FluSimpleString createFolderErrTxt;
00097   static FluSimpleString deleteFileErrTxt;
00098   static FluSimpleString fileExistsErrTxt;
00099   static FluSimpleString renameErrTxt;
00100 
00102 
00109   class FLU_EXPORT PreviewWidgetBase : public Fl_Group
00110     {
00111     public:
00112       PreviewWidgetBase();
00113       virtual ~PreviewWidgetBase();
00114       virtual int preview( const char *filename ) = 0;
00115     };
00116 
00118   enum { 
00119     ENTRY_NONE = 1,         
00120     ENTRY_DIR = 2,          
00121     ENTRY_FILE = 4,         
00122     ENTRY_FAVORITE = 8,     
00123     ENTRY_DRIVE = 16,       
00124     ENTRY_MYDOCUMENTS = 32, 
00125     ENTRY_MYCOMPUTER = 64   
00126   };
00127 
00129   enum { 
00130     SINGLE = 0,            
00131     MULTI = 1,             
00132     DIRECTORY = 4,         
00133     DEACTIVATE_FILES = 8,  
00134     SAVING = 16,           
00135     STDFILE = 32           
00136   };
00137 
00139   struct FileTypeInfo
00140   {
00141     Fl_Image *icon;
00142     FluSimpleString extensions;
00143     FluSimpleString type, shortType;
00144   };
00145 
00147   Flu_File_Chooser( const char *path, const char *pattern, int type, const char *title );
00148 
00150   ~Flu_File_Chooser();
00151 
00153 
00157   static void add_context_handler( int type, const char *ext, const char *name,
00158                                    void (*cb)(const char*,int,void*), void *cbd );
00159 
00161   static void add_preview_handler( PreviewWidgetBase *w );
00162 
00164 
00168   static void add_type( const char *extensions, const char *short_description, Fl_Image *icon = NULL );
00169 
00171   inline void allow_file_editing( bool b )
00172     { fileEditing = b; }
00173 
00175   inline bool allow_file_editing() const
00176     { return fileEditing; }
00177 
00179   inline void case_insensitive_sort( bool b )
00180     { caseSort = !b; }
00181 
00183   inline bool case_insensitive_sort() const
00184     { return !caseSort; }
00185 
00187   void cd( const char *path );
00188 
00190   void clear_history();
00191 
00193   int count();
00194 
00196   inline void default_file_icon( Fl_Image* i )
00197     { defaultFileIcon = i; }
00198 
00200   inline void directory( const char *d )
00201     { cd( d ); }
00202 
00204   inline void filter( const char *p )
00205     { pattern( p ); }
00206 
00208   inline const char* filter() const
00209     { return pattern(); }
00210 
00212   static FileTypeInfo *find_type( const char *extension );
00213 
00215   inline const char* get_current_directory() const
00216     { return currentDir.c_str(); }
00217 
00219   int handle( int event );
00220 
00222   void pattern( const char *p );
00223 
00225   inline const char* pattern() const
00226     { return rawPattern.c_str(); }
00227 
00229   inline void preview( bool b )
00230     { previewBtn->value(b); previewBtn->do_callback(); }
00231 
00233   inline int preview() const
00234     { return previewBtn->value(); }
00235 
00237   inline void rescan() { reloadCB(); }
00238 
00240   void resize( int x, int y, int w, int h );
00241 
00243   void select_all();
00244 
00246   inline void set_sort_function( int (*cb)(const char*,const char*) )
00247     { customSort = cb; rescan(); }
00248 
00250   inline void type( int t )
00251     { selectionType = t; rescan(); }
00252 
00254   inline int type( int t ) const
00255     { return selectionType; }
00256 
00258   void unselect_all();
00259 
00261   void value( const char *v );
00262 
00264   const char *value();
00265 
00267   const char *value( int n );
00268 
00269   FileInput filename;
00270   // the <Enter> key behavior is not correct for versions before 1.1.4rc2
00271 #if FL_MAJOR_VERSION >= 1 && FL_MINOR_VERSION >= 1 && FL_PATCH_VERSION >= 4
00272   Flu_Return_Button ok;
00273 #else
00274   Flu_Button ok;
00275 #endif
00276   Flu_Button cancel;
00277 
00278   // apparently there is a bug in VC6 that prevents friend classes from accessing
00279   // non-public members. stupid windows
00280   // several other compilers were reported to have a problem with this too, so 
00281   // i'm just making the whole class public to eliminate potential problems.
00282   // bad c++ - i know...
00283   //#ifndef WIN32
00284   //protected:
00285   //#endif
00286 
00287   class ContextHandler
00288     {
00289     public:
00290       FluSimpleString ext, name;
00291       int type;
00292       void (*callback)(const char*,int,void*);
00293       void *callbackData;
00294       inline ContextHandler& operator =( const ContextHandler &c )
00295       { ext = c.ext; name = c.name; type = c.type; callback = c.callback; callbackData = c.callbackData; return *this; }
00296     };
00297   FluMakeVectorClass( ContextHandler, ContextHandlerVector );
00298   static ContextHandlerVector contextHandlers;
00299 
00300   typedef PreviewWidgetBase* pPreviewWidgetBase;
00301   FluMakeVectorClass( pPreviewWidgetBase, PreviewHandlerVector );
00302   static PreviewHandlerVector previewHandlers;
00303 
00304   Fl_Check_Button *hiddenFiles;
00305   Flu_Combo_Tree *location;
00306 
00307   inline static void _backCB( Fl_Widget *w, void *arg )
00308     { ((Flu_File_Chooser*)arg)->backCB(); }
00309   void backCB();
00310 
00311   inline static void _forwardCB( Fl_Widget *w, void *arg )
00312     { ((Flu_File_Chooser*)arg)->forwardCB(); }
00313   void forwardCB();
00314 
00315   inline static void _sortCB( Fl_Widget *w, void *arg )
00316     { ((Flu_File_Chooser*)arg)->sortCB( w ); }
00317   void sortCB( Fl_Widget *w );
00318 
00319   inline static void _previewCB( Fl_Widget*, void *arg )
00320     { ((Flu_File_Chooser*)arg)->previewCB(); }
00321   void previewCB();
00322 
00323   inline static void _listModeCB( Fl_Widget *w, void *arg )
00324     { ((Flu_File_Chooser*)arg)->listModeCB(); }
00325   void listModeCB();
00326 
00327   inline static void _filenameCB( Fl_Widget *w, void *arg )
00328     { ((Flu_File_Chooser*)arg)->filenameCB(); }
00329   void filenameCB();
00330 
00331   inline static void _locationCB( Fl_Widget *w, void *arg )
00332     { ((Flu_File_Chooser*)arg)->locationCB( ((Flu_Combo_Tree*)w)->value() ); }
00333   void locationCB( const char *path );
00334 
00335   inline static void _locationQJCB( Fl_Widget *w, void *arg )
00336     { ((Flu_File_Chooser*)arg)->cd( ((Fl_Button*)w)->label() ); }
00337 
00338   inline static void delayedCdCB( void *arg )
00339     { ((Flu_File_Chooser*)arg)->cd( ((Flu_File_Chooser*)arg)->delayedCd.c_str() ); }
00340 
00341   inline static void selectCB( void *arg )
00342     { ((Flu_File_Chooser*)arg)->okCB(); }
00343 
00344   inline static void _cancelCB( Fl_Widget*, void *arg )
00345     { ((Flu_File_Chooser*)arg)->cancelCB(); }
00346   void cancelCB();
00347 
00348   inline static void _okCB( Fl_Widget*, void *arg )
00349     { ((Flu_File_Chooser*)arg)->okCB(); }
00350   void okCB();
00351 
00352   inline static void _trashCB( Fl_Widget*, void *arg )
00353     { ((Flu_File_Chooser*)arg)->trashCB(); }
00354   void trashCB( bool recycle = true );
00355 
00356   inline static void _newFolderCB( Fl_Widget*, void *arg )
00357     { ((Flu_File_Chooser*)arg)->newFolderCB(); }
00358   void newFolderCB();
00359 
00360   inline static void upDirCB( Fl_Widget*, void *arg )
00361     { ((Flu_File_Chooser*)arg)->cd( "../" ); }
00362 
00363   inline static void reloadCB( Fl_Widget*, void *arg )
00364     { ((Flu_File_Chooser*)arg)->reloadCB(); }
00365   void reloadCB();
00366 
00367   inline static void _homeCB( Fl_Widget*, void *arg )
00368     { ((Flu_File_Chooser*)arg)->homeCB(); }
00369   void homeCB();
00370 
00371   inline static void _desktopCB( Fl_Widget*, void *arg )
00372     { ((Flu_File_Chooser*)arg)->desktopCB(); }
00373   void desktopCB();
00374 
00375   inline static void _favoritesCB( Fl_Widget*, void *arg )
00376     { ((Flu_File_Chooser*)arg)->favoritesCB(); }
00377   void favoritesCB();
00378 
00379   inline static void _myComputerCB( Fl_Widget*, void *arg )
00380     { ((Flu_File_Chooser*)arg)->myComputerCB(); }
00381   void myComputerCB();
00382 
00383   inline static void _addToFavoritesCB( Fl_Widget*, void *arg )
00384     { ((Flu_File_Chooser*)arg)->addToFavoritesCB(); }
00385   void addToFavoritesCB();
00386 
00387   inline static void _documentsCB( Fl_Widget*, void *arg )
00388     { ((Flu_File_Chooser*)arg)->documentsCB(); }
00389   void documentsCB();
00390 
00391   inline static void _hideCB( Fl_Widget*, void *arg )
00392     { ((Flu_File_Chooser*)arg)->hideCB(); }
00393   void hideCB();
00394   void do_callback();
00395 
00396   enum {
00397     SORT_NAME = 1,
00398     SORT_SIZE = 2,
00399     SORT_TYPE = 4,
00400     SORT_DATE = 8,
00401     SORT_REVERSE = 16 
00402   };
00403   static void _qSort( int how, bool caseSort, Fl_Widget **array, int low, int high );
00404 
00405   friend class Entry;
00406   class Entry : public Fl_Input
00407     {
00408     public:
00409       Entry( const char* name, int t, bool d, Flu_File_Chooser *c );
00410       ~Entry();
00411 
00412       int handle( int event );
00413       void draw();
00414 
00415       void updateSize();
00416       void updateIcon();
00417 
00418       FluSimpleString filename, date, filesize, shortname, 
00419         description, shortDescription, toolTip, altname;
00420       //FluSimpleString permissions;
00421       //unsigned char pU, pG, pO; // 3-bit unix style permissions
00422       unsigned int type, idate;
00423       unsigned long isize;
00424       bool selected;
00425       int editMode;
00426       Flu_File_Chooser *chooser;
00427       Fl_Image *icon;
00428 
00429       int nameW, typeW, sizeW, dateW;
00430       bool details;
00431 
00432       inline static void _inputCB( Fl_Widget *w, void *arg )
00433         { ((Entry*)arg)->inputCB(); }
00434       void inputCB();
00435 
00436       inline static void _editCB( void *arg )
00437         { ((Entry*)arg)->editCB(); }
00438       void editCB();
00439     };
00440 
00441   friend class FileList;
00442   class FileList : public Flu_Wrap_Group
00443     {
00444     public:
00445       FileList( int x, int y, int w, int h, Flu_File_Chooser *c );
00446       ~FileList();
00447 
00448       int handle( int event );
00449       void sort( int numDirs = -1 );
00450 
00451       inline Fl_Widget *child(int n) const
00452         { return Flu_Wrap_Group::child(n); }
00453 
00454       inline int children() const
00455         { return Flu_Wrap_Group::children(); }
00456 
00457       int numDirs;
00458       Flu_File_Chooser *chooser;
00459     };
00460 
00461   friend class FileDetails;
00462   class FileDetails : public Fl_Pack
00463     {
00464     public:
00465       FileDetails( int x, int y, int w, int h, Flu_File_Chooser *c );
00466       ~FileDetails();
00467 
00468       int handle( int event );
00469       void sort( int numDirs = -1 );
00470 
00471       void scroll_to( Fl_Widget *w );
00472       Fl_Widget* next( Fl_Widget* w );
00473       Fl_Widget* previous( Fl_Widget* w );
00474 
00475       int numDirs;
00476       Flu_File_Chooser *chooser;
00477     };
00478 
00479   friend class CBTile;
00480   class CBTile : public Fl_Tile
00481     {
00482     public:
00483       CBTile( int x, int y, int w, int h, Flu_File_Chooser *c );
00484       int handle( int event );
00485       Flu_File_Chooser *chooser;
00486     };
00487 
00488   friend class FileColumns;
00489   class FileColumns : public Fl_Tile
00490     {
00491     public:
00492       FileColumns( int x, int y, int w, int h, Flu_File_Chooser *c );
00493       ~FileColumns();
00494 
00495       int handle( int event );
00496       void resize( int x, int y, int w, int h );
00497       Flu_File_Chooser *chooser;
00498       int W1, W2, W3, W4;
00499     };
00500 
00501   friend class PreviewTile;
00502   class PreviewTile : public Fl_Tile
00503     {
00504     public:
00505       PreviewTile( int x, int y, int w, int h, Flu_File_Chooser *c );
00506       int handle( int event );
00507       Flu_File_Chooser *chooser;
00508       int last;
00509     };
00510 
00511   class ImgTxtPreview : public PreviewWidgetBase
00512     {
00513     public:
00514       int preview( const char *filename );
00515       unsigned char previewTxt[1024];
00516     };
00517 
00518   friend class PreviewGroup;
00519   class PreviewGroup : public Fl_Group
00520     {
00521     public:
00522       PreviewGroup( int x, int y, int w, int h, Flu_File_Chooser *c );
00523       void draw();
00524       Flu_File_Chooser *chooser;
00525       FluSimpleString lastFile, file;
00526       PreviewWidgetBase* handled;
00527     };
00528 
00529   Fl_Group *getEntryGroup();
00530   Fl_Group *getEntryContainer();
00531 
00532   void win2unix( FluSimpleString &s );
00533 
00534   void cleanupPath( FluSimpleString &s );
00535 
00536   bool correctPath( FluSimpleString &path );
00537 
00538   void updateEntrySizes();
00539 
00540   void buildLocationCombo();
00541 
00542   void updateLocationQJ();
00543 
00544   void addToHistory();
00545 
00546   FluSimpleString formatDate( const char *d );
00547 
00548   void recursiveScan( const char *dir, FluStringVector *files );
00549 
00550   bool stripPatterns( FluSimpleString s, FluStringVector* patterns );
00551 
00552   int popupContextMenu( Entry *entry );
00553 
00554   FluSimpleString commonStr();
00555 
00556   static ImgTxtPreview *imgTxtPreview;
00557 
00558   static int (*customSort)(const char*,const char*);
00559 
00560   PreviewGroup *previewGroup;
00561   PreviewTile *previewTile;
00562   Fl_Group *fileGroup, *locationQuickJump;
00563   Fl_Menu_Button entryPopup;
00564   Fl_Image *defaultFileIcon;
00565   Entry *lastSelected;
00566   FileList *filelist;
00567   FileColumns *filecolumns;
00568   Fl_Group *fileDetailsGroup;
00569   Fl_Scroll *filescroll;
00570   FileDetails *filedetails;
00571   Flu_Button *detailNameBtn, *detailTypeBtn, *detailSizeBtn, *detailDateBtn;
00572   FluSimpleString currentDir, delayedCd, rawPattern;
00573   FluSimpleString configFilename;
00574   FluSimpleString userHome, userDesktop, userDocs;
00575   FluSimpleString drives[26];
00576   Fl_Pixmap* driveIcons[26];
00577   Flu_Button *fileListBtn, *fileListWideBtn, *fileDetailsBtn, *backBtn, *forwardBtn, *upDirBtn, *trashBtn,
00578     *newDirBtn, *addFavoriteBtn, *reloadBtn, *previewBtn;
00579   Fl_Browser *favoritesList;
00580   Flu_Combo_List *filePattern;
00581   int selectionType;
00582   bool filenameEnterCallback, filenameTabCallback, walkingHistory, caseSort, fileEditing;
00583   int sortMethod;
00584 
00585   FluStringVector patterns;
00586 
00587   static FileTypeInfo *types;
00588   static int numTypes;
00589   static int typeArraySize;
00590 
00591   static FluSimpleString dArrow[4];
00592   static FluSimpleString uArrow[4];
00593 
00594 #ifdef WIN32
00595   unsigned int driveMask;
00596   unsigned int driveTypes[26];
00597   FluSimpleString volumeNames[26];
00598   bool refreshDrives;
00599 #endif
00600 
00601   class History
00602   {
00603   public:
00604     History() { last = next = NULL; }
00605     FluSimpleString path;
00606     History *last, *next;
00607   };
00608 
00609   History *history, *currentHist;
00610 
00611   Fl_Callback *_callback;
00612   void *_userdata;
00613 
00614 };
00615 
00616 #endif

Generated on Fri Nov 5 12:41:32 2004 for FLTK Utility Library and Widget Collection (FLU) by doxygen 1.3.5