00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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/VectorClass.h"
00035
00036 FLU_EXPORT const char* flu_file_chooser( const char *message, const char *pattern, const char *filename );
00037 FLU_EXPORT const char* flu_save_chooser( const char *message, const char *pattern, const char *filename );
00038 FLU_EXPORT const char* flu_dir_chooser( const char *message, const char *filename );
00039 FLU_EXPORT const char* flu_dir_chooser( const char *message, const char *filename, bool showFiles );
00040 FLU_EXPORT const char* flu_file_and_dir_chooser( const char *message, const char *filename );
00041
00042 MakeVectorClass( FluSimpleString, StringVector );
00043
00045 class FLU_EXPORT Flu_File_Chooser : public Fl_Double_Window
00046 {
00047
00048 friend class FileInput;
00049 class FileInput : public Fl_Input
00050 {
00051 public:
00052 FileInput( int x, int y, int w, int h, const char *l, Flu_File_Chooser *c );
00053 ~FileInput();
00054
00055 int handle( int event );
00056 protected:
00057 Flu_File_Chooser *chooser;
00058 };
00059
00060 public:
00061
00063
00064 static FluSimpleString favoritesTxt;
00065 static FluSimpleString desktopTxt;
00066 static FluSimpleString myComputerTxt;
00067 static FluSimpleString myDocumentsTxt;
00068
00069 static FluSimpleString filenameTxt;
00070 static FluSimpleString okTxt;
00071 static FluSimpleString cancelTxt;
00072 static FluSimpleString locationTxt;
00073 static FluSimpleString showHiddenTxt;
00074 static FluSimpleString fileTypesTxt;
00075 static FluSimpleString directoryTxt;
00076 static FluSimpleString allFilesTxt;
00077 static FluSimpleString defaultFolderNameTxt;
00078
00079 static FluSimpleString backTTxt;
00080 static FluSimpleString forwardTTxt;
00081 static FluSimpleString upTTxt;
00082 static FluSimpleString reloadTTxt;
00083 static FluSimpleString trashTTxt;
00084 static FluSimpleString newDirTTxt;
00085 static FluSimpleString addFavoriteTTxt;
00086 static FluSimpleString previewTTxt;
00087 static FluSimpleString listTTxt;
00088 static FluSimpleString wideListTTxt;
00089 static FluSimpleString detailTTxt;
00090
00091 static FluSimpleString detailTxt[4];
00092 static FluSimpleString contextMenuTxt[3];
00093 static FluSimpleString diskTypesTxt[6];
00094
00095 static FluSimpleString createFolderErrTxt;
00096 static FluSimpleString deleteFileErrTxt;
00097 static FluSimpleString fileExistsErrTxt;
00098 static FluSimpleString renameErrTxt;
00099
00101
00108 class FLU_EXPORT PreviewWidgetBase : public Fl_Group
00109 {
00110 public:
00111 PreviewWidgetBase();
00112 virtual ~PreviewWidgetBase();
00113 virtual int preview( const char *filename ) = 0;
00114 };
00115
00117 enum {
00118 ENTRY_NONE = 1,
00119 ENTRY_DIR = 2,
00120 ENTRY_FILE = 4,
00121 ENTRY_FAVORITE = 8,
00122 ENTRY_DRIVE = 16,
00123 ENTRY_MYDOCUMENTS = 32,
00124 ENTRY_MYCOMPUTER = 64
00125 };
00126
00128 enum {
00129 SINGLE = 0,
00130 MULTI = 1,
00131 DIRECTORY = 4,
00132 DEACTIVATE_FILES = 8,
00133 SAVING = 16,
00134 STDFILE = 32
00135 };
00136
00138 struct FileTypeInfo
00139 {
00140 Fl_Image *icon;
00141 FluSimpleString extensions;
00142 FluSimpleString type, shortType;
00143 };
00144
00146 Flu_File_Chooser( const char *path, const char *pattern, int type, const char *title );
00147
00149 ~Flu_File_Chooser();
00150
00152
00156 static void add_context_handler( int type, const char *ext, const char *name,
00157 void (*cb)(const char*,int,void*), void *cbd );
00158
00160 static void add_preview_handler( PreviewWidgetBase *w );
00161
00163
00167 static void add_type( const char *extensions, const char *short_description, Fl_Image *icon = NULL );
00168
00170 inline void allow_file_editing( bool b )
00171 { fileEditing = b; }
00172
00174 inline bool allow_file_editing() const
00175 { return fileEditing; }
00176
00178 inline void case_insensitive_sort( bool b )
00179 { caseSort = !b; }
00180
00182 inline bool case_insensitive_sort() const
00183 { return !caseSort; }
00184
00186 void cd( const char *path );
00187
00189 void clear_history();
00190
00192 int count();
00193
00195 inline void default_file_icon( Fl_Image* i )
00196 { defaultFileIcon = i; }
00197
00199 inline void directory( const char *d )
00200 { cd( d ); }
00201
00203 inline void filter( const char *p )
00204 { pattern( p ); }
00205
00207 inline const char* filter() const
00208 { return pattern(); }
00209
00211 static FileTypeInfo *find_type( const char *extension );
00212
00214 inline const char* get_current_directory() const
00215 { return currentDir.c_str(); }
00216
00218 int handle( int event );
00219
00221 void pattern( const char *p );
00222
00224 inline const char* pattern() const
00225 { return rawPattern.c_str(); }
00226
00228 inline void preview( bool b )
00229 { previewBtn->value(b); previewBtn->do_callback(); }
00230
00232 inline int preview() const
00233 { return previewBtn->value(); }
00234
00236 inline void rescan() { reloadCB(); }
00237
00239 void resize( int x, int y, int w, int h );
00240
00242 void select_all();
00243
00245 inline void set_sort_function( int (*cb)(const char*,const char*) )
00246 { customSort = cb; rescan(); }
00247
00249 inline void type( int t )
00250 { selectionType = t; rescan(); }
00251
00253 inline int type( int t ) const
00254 { return selectionType; }
00255
00257 void unselect_all();
00258
00260 void value( const char *v );
00261
00263 const char *value();
00264
00266 const char *value( int n );
00267
00268 FileInput filename;
00269
00270 #if FL_MAJOR_VERSION >= 1 && FL_MINOR_VERSION >= 1 && FL_PATCH_VERSION >= 4
00271 Flu_Return_Button ok;
00272 #else
00273 Flu_Button ok;
00274 #endif
00275 Flu_Button cancel;
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 class ContextHandler
00287 {
00288 public:
00289 FluSimpleString ext, name;
00290 int type;
00291 void (*callback)(const char*,int,void*);
00292 void *callbackData;
00293 inline ContextHandler& operator =( const ContextHandler &c )
00294 { ext = c.ext; name = c.name; type = c.type; callback = c.callback; callbackData = c.callbackData; return *this; }
00295 };
00296 MakeVectorClass( ContextHandler, ContextHandlerVector );
00297 static ContextHandlerVector contextHandlers;
00298
00299 typedef PreviewWidgetBase* pPreviewWidgetBase;
00300 MakeVectorClass( pPreviewWidgetBase, PreviewHandlerVector );
00301 static PreviewHandlerVector previewHandlers;
00302
00303 Fl_Check_Button *hiddenFiles;
00304 Flu_Combo_Tree *location;
00305
00306 inline static void _backCB( Fl_Widget *w, void *arg )
00307 { ((Flu_File_Chooser*)arg)->backCB(); }
00308 void backCB();
00309
00310 inline static void _forwardCB( Fl_Widget *w, void *arg )
00311 { ((Flu_File_Chooser*)arg)->forwardCB(); }
00312 void forwardCB();
00313
00314 inline static void _sortCB( Fl_Widget *w, void *arg )
00315 { ((Flu_File_Chooser*)arg)->sortCB( w ); }
00316 void sortCB( Fl_Widget *w );
00317
00318 inline static void _previewCB( Fl_Widget*, void *arg )
00319 { ((Flu_File_Chooser*)arg)->previewCB(); }
00320 void previewCB();
00321
00322 inline static void _listModeCB( Fl_Widget *w, void *arg )
00323 { ((Flu_File_Chooser*)arg)->listModeCB(); }
00324 void listModeCB();
00325
00326 inline static void _filenameCB( Fl_Widget *w, void *arg )
00327 { ((Flu_File_Chooser*)arg)->filenameCB(); }
00328 void filenameCB();
00329
00330 inline static void _locationCB( Fl_Widget *w, void *arg )
00331 { ((Flu_File_Chooser*)arg)->locationCB( ((Flu_Combo_Tree*)w)->value() ); }
00332 void locationCB( const char *path );
00333
00334 inline static void _locationQJCB( Fl_Widget *w, void *arg )
00335 { ((Flu_File_Chooser*)arg)->cd( ((Fl_Button*)w)->label() ); }
00336
00337 inline static void delayedCdCB( void *arg )
00338 { ((Flu_File_Chooser*)arg)->cd( ((Flu_File_Chooser*)arg)->delayedCd.c_str() ); }
00339
00340 inline static void selectCB( void *arg )
00341 { ((Flu_File_Chooser*)arg)->hide(); }
00342
00343 inline static void _cancelCB( Fl_Widget*, void *arg )
00344 { ((Flu_File_Chooser*)arg)->cancelCB(); }
00345 void cancelCB();
00346
00347 inline static void _okCB( Fl_Widget*, void *arg )
00348 { ((Flu_File_Chooser*)arg)->okCB(); }
00349 void okCB();
00350
00351 inline static void _trashCB( Fl_Widget*, void *arg )
00352 { ((Flu_File_Chooser*)arg)->trashCB(); }
00353 void trashCB( bool recycle = true );
00354
00355 inline static void _newFolderCB( Fl_Widget*, void *arg )
00356 { ((Flu_File_Chooser*)arg)->newFolderCB(); }
00357 void newFolderCB();
00358
00359 inline static void upDirCB( Fl_Widget*, void *arg )
00360 { ((Flu_File_Chooser*)arg)->cd( "../" ); }
00361
00362 inline static void reloadCB( Fl_Widget*, void *arg )
00363 { ((Flu_File_Chooser*)arg)->reloadCB(); }
00364 void reloadCB();
00365
00366 inline static void _homeCB( Fl_Widget*, void *arg )
00367 { ((Flu_File_Chooser*)arg)->homeCB(); }
00368 void homeCB();
00369
00370 inline static void _desktopCB( Fl_Widget*, void *arg )
00371 { ((Flu_File_Chooser*)arg)->desktopCB(); }
00372 void desktopCB();
00373
00374 inline static void _favoritesCB( Fl_Widget*, void *arg )
00375 { ((Flu_File_Chooser*)arg)->favoritesCB(); }
00376 void favoritesCB();
00377
00378 inline static void _myComputerCB( Fl_Widget*, void *arg )
00379 { ((Flu_File_Chooser*)arg)->myComputerCB(); }
00380 void myComputerCB();
00381
00382 inline static void _addToFavoritesCB( Fl_Widget*, void *arg )
00383 { ((Flu_File_Chooser*)arg)->addToFavoritesCB(); }
00384 void addToFavoritesCB();
00385
00386 inline static void _documentsCB( Fl_Widget*, void *arg )
00387 { ((Flu_File_Chooser*)arg)->documentsCB(); }
00388 void documentsCB();
00389
00390 inline static void _hideCB( Fl_Widget*, void *arg )
00391 { ((Flu_File_Chooser*)arg)->hideCB(); }
00392 void hideCB();
00393 void do_callback();
00394
00395 enum {
00396 SORT_NAME = 1,
00397 SORT_SIZE = 2,
00398 SORT_TYPE = 4,
00399 SORT_DATE = 8,
00400 SORT_REVERSE = 16
00401 };
00402 static void _qSort( int how, bool caseSort, Fl_Widget **array, int low, int high );
00403
00404 friend class Entry;
00405 class Entry : public Fl_Input
00406 {
00407 public:
00408 Entry( const char* name, int t, bool d, Flu_File_Chooser *c );
00409 ~Entry();
00410
00411 int handle( int event );
00412 void draw();
00413
00414 void updateSize();
00415 void updateIcon();
00416
00417 FluSimpleString filename, date, filesize, shortname,
00418 description, shortDescription, toolTip, altname;
00419
00420
00421 unsigned int type, idate;
00422 unsigned long isize;
00423 bool selected;
00424 int editMode;
00425 Flu_File_Chooser *chooser;
00426 Fl_Image *icon;
00427
00428 int nameW, typeW, sizeW, dateW;
00429 bool details;
00430
00431 inline static void _inputCB( Fl_Widget *w, void *arg )
00432 { ((Entry*)arg)->inputCB(); }
00433 void inputCB();
00434
00435 inline static void _editCB( void *arg )
00436 { ((Entry*)arg)->editCB(); }
00437 void editCB();
00438 };
00439
00440 friend class FileList;
00441 class FileList : public Flu_Wrap_Group
00442 {
00443 public:
00444 FileList( int x, int y, int w, int h, Flu_File_Chooser *c );
00445 ~FileList();
00446
00447 int handle( int event );
00448 void sort( int numDirs = -1 );
00449
00450 inline Fl_Widget *child(int n) const
00451 { return Flu_Wrap_Group::child(n); }
00452
00453 inline int children() const
00454 { return Flu_Wrap_Group::children(); }
00455
00456 int numDirs;
00457 Flu_File_Chooser *chooser;
00458 };
00459
00460 friend class FileDetails;
00461 class FileDetails : public Fl_Pack
00462 {
00463 public:
00464 FileDetails( int x, int y, int w, int h, Flu_File_Chooser *c );
00465 ~FileDetails();
00466
00467 int handle( int event );
00468 void sort( int numDirs = -1 );
00469
00470 void scroll_to( Fl_Widget *w );
00471 Fl_Widget* next( Fl_Widget* w );
00472 Fl_Widget* previous( Fl_Widget* w );
00473
00474 int numDirs;
00475 Flu_File_Chooser *chooser;
00476 };
00477
00478 friend class CBTile;
00479 class CBTile : public Fl_Tile
00480 {
00481 public:
00482 CBTile( int x, int y, int w, int h, Flu_File_Chooser *c );
00483 int handle( int event );
00484 Flu_File_Chooser *chooser;
00485 };
00486
00487 friend class FileColumns;
00488 class FileColumns : public Fl_Tile
00489 {
00490 public:
00491 FileColumns( int x, int y, int w, int h, Flu_File_Chooser *c );
00492 ~FileColumns();
00493
00494 int handle( int event );
00495 void resize( int x, int y, int w, int h );
00496 Flu_File_Chooser *chooser;
00497 int W1, W2, W3, W4;
00498 };
00499
00500 friend class PreviewTile;
00501 class PreviewTile : public Fl_Tile
00502 {
00503 public:
00504 PreviewTile( int x, int y, int w, int h, Flu_File_Chooser *c );
00505 int handle( int event );
00506 Flu_File_Chooser *chooser;
00507 int last;
00508 };
00509
00510 class ImgTxtPreview : public PreviewWidgetBase
00511 {
00512 public:
00513 int preview( const char *filename );
00514 unsigned char previewTxt[1024];
00515 };
00516
00517 friend class PreviewGroup;
00518 class PreviewGroup : public Fl_Group
00519 {
00520 public:
00521 PreviewGroup( int x, int y, int w, int h, Flu_File_Chooser *c );
00522 void draw();
00523 Flu_File_Chooser *chooser;
00524 FluSimpleString lastFile, file;
00525 PreviewWidgetBase* handled;
00526 };
00527
00528 Fl_Group *getEntryGroup();
00529 Fl_Group *getEntryContainer();
00530
00531 void win2unix( FluSimpleString &s );
00532
00533 void cleanupPath( FluSimpleString &s );
00534
00535 bool correctPath( FluSimpleString &path );
00536
00537 void updateEntrySizes();
00538
00539 void buildLocationCombo();
00540
00541 void updateLocationQJ();
00542
00543 void addToHistory();
00544
00545 FluSimpleString formatDate( const char *d );
00546
00547 void recursiveScan( const char *dir, StringVector *files );
00548
00549 bool stripPatterns( FluSimpleString s, StringVector* patterns );
00550
00551 int popupContextMenu( Entry *entry );
00552
00553 FluSimpleString commonStr();
00554
00555 static ImgTxtPreview *imgTxtPreview;
00556
00557 static int (*customSort)(const char*,const char*);
00558
00559 PreviewGroup *previewGroup;
00560 PreviewTile *previewTile;
00561 Fl_Group *fileGroup, *locationQuickJump;
00562 Fl_Menu_Button entryPopup;
00563 Fl_Image *defaultFileIcon;
00564 Entry *lastSelected;
00565 FileList *filelist;
00566 FileColumns *filecolumns;
00567 Fl_Group *fileDetailsGroup;
00568 Fl_Scroll *filescroll;
00569 FileDetails *filedetails;
00570 Flu_Button *detailNameBtn, *detailTypeBtn, *detailSizeBtn, *detailDateBtn;
00571 FluSimpleString currentDir, delayedCd, rawPattern;
00572 FluSimpleString configFilename;
00573 FluSimpleString userHome, userDesktop, userDocs;
00574 FluSimpleString drives[26];
00575 Fl_Pixmap* driveIcons[26];
00576 Flu_Button *fileListBtn, *fileListWideBtn, *fileDetailsBtn, *backBtn, *forwardBtn, *upDirBtn, *trashBtn,
00577 *newDirBtn, *addFavoriteBtn, *reloadBtn, *previewBtn;
00578 Fl_Browser *favoritesList;
00579 Flu_Combo_List *filePattern;
00580 int selectionType;
00581 bool filenameEnterCallback, filenameTabCallback, walkingHistory, caseSort, fileEditing;
00582 int sortMethod;
00583
00584 StringVector patterns;
00585
00586 static FileTypeInfo *types;
00587 static int numTypes;
00588 static int typeArraySize;
00589
00590 static FluSimpleString dArrow[4];
00591 static FluSimpleString uArrow[4];
00592
00593 #ifdef WIN32
00594 unsigned int driveMask;
00595 unsigned int driveTypes[26];
00596 FluSimpleString volumeNames[26];
00597 bool refreshDrives;
00598 #endif
00599
00600 class History
00601 {
00602 public:
00603 History() { last = next = NULL; }
00604 FluSimpleString path;
00605 History *last, *next;
00606 };
00607
00608 History *history, *currentHist;
00609
00610 Fl_Callback *_callback;
00611 void *_userdata;
00612
00613 };
00614
00615 #endif