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/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
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
00279
00280
00281
00282
00283
00284
00285
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)->delay_cd( ((Fl_Button*)w)->label() ); }
00337
00338 void delay_cd( FluSimpleString path );
00339
00340 inline static void delayedCdCB( void *arg )
00341 { ((Flu_File_Chooser*)arg)->cd( ((Flu_File_Chooser*)arg)->delayedCd.c_str() ); }
00342
00343 inline static void selectCB( void *arg )
00344 { ((Flu_File_Chooser*)arg)->okCB(); }
00345
00346 inline static void _cancelCB( Fl_Widget*, void *arg )
00347 { ((Flu_File_Chooser*)arg)->cancelCB(); }
00348 void cancelCB();
00349
00350 inline static void _okCB( Fl_Widget*, void *arg )
00351 { ((Flu_File_Chooser*)arg)->okCB(); }
00352 void okCB();
00353
00354 inline static void _trashCB( Fl_Widget*, void *arg )
00355 { ((Flu_File_Chooser*)arg)->trashCB(); }
00356 void trashCB( bool recycle = true );
00357
00358 inline static void _newFolderCB( Fl_Widget*, void *arg )
00359 { ((Flu_File_Chooser*)arg)->newFolderCB(); }
00360 void newFolderCB();
00361
00362 inline static void upDirCB( Fl_Widget*, void *arg )
00363 { ((Flu_File_Chooser*)arg)->cd( "../" ); }
00364
00365 inline static void reloadCB( Fl_Widget*, void *arg )
00366 { ((Flu_File_Chooser*)arg)->reloadCB(); }
00367 void reloadCB();
00368
00369 inline static void _homeCB( Fl_Widget*, void *arg )
00370 { ((Flu_File_Chooser*)arg)->homeCB(); }
00371 void homeCB();
00372
00373 inline static void _desktopCB( Fl_Widget*, void *arg )
00374 { ((Flu_File_Chooser*)arg)->desktopCB(); }
00375 void desktopCB();
00376
00377 inline static void _favoritesCB( Fl_Widget*, void *arg )
00378 { ((Flu_File_Chooser*)arg)->favoritesCB(); }
00379 void favoritesCB();
00380
00381 inline static void _myComputerCB( Fl_Widget*, void *arg )
00382 { ((Flu_File_Chooser*)arg)->myComputerCB(); }
00383 void myComputerCB();
00384
00385 inline static void _addToFavoritesCB( Fl_Widget*, void *arg )
00386 { ((Flu_File_Chooser*)arg)->addToFavoritesCB(); }
00387 void addToFavoritesCB();
00388
00389 inline static void _documentsCB( Fl_Widget*, void *arg )
00390 { ((Flu_File_Chooser*)arg)->documentsCB(); }
00391 void documentsCB();
00392
00393 inline static void _hideCB( Fl_Widget*, void *arg )
00394 { ((Flu_File_Chooser*)arg)->hideCB(); }
00395 void hideCB();
00396 void do_callback();
00397
00398 enum {
00399 SORT_NAME = 1,
00400 SORT_SIZE = 2,
00401 SORT_TYPE = 4,
00402 SORT_DATE = 8,
00403 SORT_REVERSE = 16
00404 };
00405 static void _qSort( int how, bool caseSort, Fl_Widget **array, int low, int high );
00406
00407 friend class Entry;
00408 class Entry : public Fl_Input
00409 {
00410 public:
00411 Entry( const char* name, int t, bool d, Flu_File_Chooser *c );
00412 ~Entry();
00413
00414 int handle( int event );
00415 void draw();
00416
00417 void updateSize();
00418 void updateIcon();
00419
00420 FluSimpleString filename, date, filesize, shortname,
00421 description, shortDescription, toolTip, altname;
00422
00423
00424 unsigned int type, idate;
00425 unsigned long isize;
00426 bool selected;
00427 int editMode;
00428 Flu_File_Chooser *chooser;
00429 Fl_Image *icon;
00430
00431 int nameW, typeW, sizeW, dateW;
00432 bool details;
00433
00434 inline static void _inputCB( Fl_Widget *w, void *arg )
00435 { ((Entry*)arg)->inputCB(); }
00436 void inputCB();
00437
00438 inline static void _editCB( void *arg )
00439 { ((Entry*)arg)->editCB(); }
00440 void editCB();
00441 };
00442
00443 friend class FileList;
00444 class FileList : public Flu_Wrap_Group
00445 {
00446 public:
00447 FileList( int x, int y, int w, int h, Flu_File_Chooser *c );
00448 ~FileList();
00449
00450 int handle( int event );
00451 void sort( int numDirs = -1 );
00452
00453 inline Fl_Widget *child(int n) const
00454 { return Flu_Wrap_Group::child(n); }
00455
00456 inline int children() const
00457 { return Flu_Wrap_Group::children(); }
00458
00459 int numDirs;
00460 Flu_File_Chooser *chooser;
00461 };
00462
00463 friend class FileDetails;
00464 class FileDetails : public Fl_Pack
00465 {
00466 public:
00467 FileDetails( int x, int y, int w, int h, Flu_File_Chooser *c );
00468 ~FileDetails();
00469
00470 int handle( int event );
00471 void sort( int numDirs = -1 );
00472
00473 void scroll_to( Fl_Widget *w );
00474 Fl_Widget* next( Fl_Widget* w );
00475 Fl_Widget* previous( Fl_Widget* w );
00476
00477 int numDirs;
00478 Flu_File_Chooser *chooser;
00479 };
00480
00481 friend class CBTile;
00482 class CBTile : public Fl_Tile
00483 {
00484 public:
00485 CBTile( int x, int y, int w, int h, Flu_File_Chooser *c );
00486 int handle( int event );
00487 Flu_File_Chooser *chooser;
00488 };
00489
00490 friend class FileColumns;
00491 class FileColumns : public Fl_Tile
00492 {
00493 public:
00494 FileColumns( int x, int y, int w, int h, Flu_File_Chooser *c );
00495 ~FileColumns();
00496
00497 int handle( int event );
00498 void resize( int x, int y, int w, int h );
00499 Flu_File_Chooser *chooser;
00500 int W1, W2, W3, W4;
00501 };
00502
00503 friend class PreviewTile;
00504 class PreviewTile : public Fl_Tile
00505 {
00506 public:
00507 PreviewTile( int x, int y, int w, int h, Flu_File_Chooser *c );
00508 int handle( int event );
00509 Flu_File_Chooser *chooser;
00510 int last;
00511 };
00512
00513 class ImgTxtPreview : public PreviewWidgetBase
00514 {
00515 public:
00516 int preview( const char *filename );
00517 unsigned char previewTxt[1024];
00518 };
00519
00520 friend class PreviewGroup;
00521 class PreviewGroup : public Fl_Group
00522 {
00523 public:
00524 PreviewGroup( int x, int y, int w, int h, Flu_File_Chooser *c );
00525 void draw();
00526 Flu_File_Chooser *chooser;
00527 FluSimpleString lastFile, file;
00528 PreviewWidgetBase* handled;
00529 };
00530
00531 Fl_Group *getEntryGroup();
00532 Fl_Group *getEntryContainer();
00533
00534 void win2unix( FluSimpleString &s );
00535
00536 void cleanupPath( FluSimpleString &s );
00537
00538 bool correctPath( FluSimpleString &path );
00539
00540 void updateEntrySizes();
00541
00542 void buildLocationCombo();
00543
00544 void updateLocationQJ();
00545
00546 void addToHistory();
00547
00548 FluSimpleString formatDate( const char *d );
00549
00550 void recursiveScan( const char *dir, FluStringVector *files );
00551
00552 bool stripPatterns( FluSimpleString s, FluStringVector* patterns );
00553
00554 int popupContextMenu( Entry *entry );
00555
00556 FluSimpleString commonStr();
00557
00558 static ImgTxtPreview *imgTxtPreview;
00559
00560 static int (*customSort)(const char*,const char*);
00561
00562 PreviewGroup *previewGroup;
00563 PreviewTile *previewTile;
00564 Fl_Group *fileGroup, *locationQuickJump;
00565 Fl_Menu_Button entryPopup;
00566 Fl_Image *defaultFileIcon;
00567 Entry *lastSelected;
00568 FileList *filelist;
00569 FileColumns *filecolumns;
00570 Fl_Group *fileDetailsGroup;
00571 Fl_Scroll *filescroll;
00572 FileDetails *filedetails;
00573 Flu_Button *detailNameBtn, *detailTypeBtn, *detailSizeBtn, *detailDateBtn;
00574 FluSimpleString currentDir, delayedCd, rawPattern;
00575 FluSimpleString configFilename;
00576 FluSimpleString userHome, userDesktop, userDocs;
00577 FluSimpleString drives[26];
00578 Fl_Pixmap* driveIcons[26];
00579 Flu_Button *fileListBtn, *fileListWideBtn, *fileDetailsBtn, *backBtn, *forwardBtn, *upDirBtn, *trashBtn,
00580 *newDirBtn, *addFavoriteBtn, *reloadBtn, *previewBtn;
00581 Fl_Browser *favoritesList;
00582 Flu_Combo_List *filePattern;
00583 int selectionType;
00584 bool filenameEnterCallback, filenameTabCallback, walkingHistory, caseSort, fileEditing;
00585 int sortMethod;
00586
00587 FluStringVector patterns;
00588
00589 static FileTypeInfo *types;
00590 static int numTypes;
00591 static int typeArraySize;
00592
00593 static FluSimpleString dArrow[4];
00594 static FluSimpleString uArrow[4];
00595
00596 #ifdef WIN32
00597 unsigned int driveMask;
00598 unsigned int driveTypes[26];
00599 FluSimpleString volumeNames[26];
00600 bool refreshDrives;
00601 #endif
00602
00603 class History
00604 {
00605 public:
00606 History() { last = next = NULL; }
00607 FluSimpleString path;
00608 History *last, *next;
00609 };
00610
00611 History *history, *currentHist;
00612
00613 Fl_Callback *_callback;
00614 void *_userdata;
00615
00616 };
00617
00618 #endif