D:/Papagan/490.2006/490.2006/korsan/Papagan/490.2006/korsan/Papagan/CEGUICommonFileDialog.h

Go to the documentation of this file.
00001 #ifndef _CEGUI_COMMON_FILE_DIALOG_H_
00002 #define _CEGUI_COMMON_FILE_DIALOG_H_
00003 
00004 #include "CEGUISingletonX.h"
00005 #include <CEGUI/CEGUIBase.h>
00006 #include <CEGUI/CEGUIWindow.h>
00007 #include <CEGUI/CEGUIWindowManager.h>
00008 #include <CEGUI/elements/CEGUIPushButton.h>
00009 #include <CEGUI/elements/CEGUIListboxTextItem.h>
00010 #include <CEGUI/elements/CEGUIListbox.h>
00011 
00012 #if defined(_MSC_VER)
00013 #       pragma warning(push)
00014 #       pragma warning(disable : 4251)
00015 #endif
00016 
00017 using namespace std;
00018 using namespace stdext;
00019 
00020 namespace CEGUI
00021 {
00022         const String NAME_LAYOUT_COMMON_FILE_DIALOG                             = "CommonFileDialog_WindowsLook.layout";
00023         const String NAME_FRAMEWINDOW_COMMON_FILE_DIALOG                = "CommonFileDialog";
00024         const String NAME_PUSHBUTTON_BACK                                               = "CommonFileDialog/BackButton";
00025         const String NAME_PUSHBUTTON_OK                                                 = "CommonFileDialog/OkButton";
00026         const String NAME_PUSHBUTTON_CANCEL                                             = "CommonFileDialog/CancelButton";
00027         const String NAME_COMBOBOX_FILE                                                 = "CommonFileDialog/FileCombobox";
00028         const String NAME_COMBOBOX_EXTENSION                                    = "CommonFileDialog/ExtensionCombobox";
00029         const String NAME_COMBOBOX_DRIVE                                                = "CommonFileDialog/DriveCombobox";
00030         const String NAME_LISTBOX_FILES                                                 = "CommonFileDialog/Listbox";
00031         const String NAME_FRAMEWINDOW_PROMPT_LOAD                               = "CommonFileDialog/PromptLoad";
00032         const String NAME_STATICTEXT_PROMPT_LOAD                                = "CommonFileDialog/PromptLoad/Text";
00033         const String NAME_PUSHBUTTON_OK_PROMPT_LOAD                             = "CommonFileDialog/PromptLoad/OkButton";
00034         const String NAME_FRAMEWINDOW_PROMPT_SAVE                               = "CommonFileDialog/PromptSave";
00035         const String NAME_STATICTEXT_PROMPT_SAVE                                = "CommonFileDialog/PromptSave/Text";
00036         const String NAME_PUSHBUTTON_OK_PROMPT_SAVE                             = "CommonFileDialog/PromptSave/OkButton";
00037         const String NAME_PUSHBUTTON_CANCEL_PROMPT_SAVE                 = "CommonFileDialog/PromptSave/CancelButton";
00038 
00039         const String DEFAULT_TEXT_DIALOG_LOAD                                   = "Load";
00040         const String DEFAULT_TEXT_DIALOG_SAVE                                   = "Save As";
00041         const String DEFAULT_TEXT_PROMPT_LOAD                                   = "Cannot find the requested file.";
00042         const String DEFAULT_TEXT_PROMPT_SAVE                                   = "The file already exist. Replace it?";
00043 
00044         const String EXTENSION_ALL                                                              = "*.*";
00045         const String EXTENSION_PRESENTATION_DEFAULT                             = "All files (*.*)|*.*|";
00046         const String BRACKET_OPEN                                                               = "<";
00047         const String BRACKET_CLOSED                                                             = ">";
00048         const ulong BRACKET_OPEN_ASCII                                                  = 0x03C;
00049         const String SEPARATOR                                                                  = "\\";
00050         const uint MAX_NUMBER_OF_HISTORY_ITEMS                                  = 12;
00051 
00052         const enum CommonFileDialogAction
00053         {
00054                 ACTION_OK,
00055                 ACTION_CANCEL,
00056                 ACTION_WINDOW_CLOSED
00057         };
00058 
00059         /*************************************************************************
00060                 Class: CommonFileDialogInput
00061         *************************************************************************/
00062         class CommonFileDialogInput
00063         {
00064                 private:
00065                         uint _uHandle;                                                                          
00074                         String _szFilter;                                                                       
00089                         String _szDefaultExtension;                                                     
00092                         String _szFileName;                                                                     
00095                         String _szTitle;                                                                        
00099                         bool _bOpenFileDialog;                                                          
00102                         bool _bDoPrompt;                                                                        
00107                         String _szPromptText;
00108 
00109                 protected:
00110                 public:
00111                         CommonFileDialogInput ( const uint uHandle = 0,
00112                                                                         const String szFileName = "",
00113                                                                         const String szFilter = EXTENSION_PRESENTATION_DEFAULT,
00114                                                                         const String szDefaultExtension = EXTENSION_ALL,
00115                                                                         const String szTitle = "",
00116                                                                         bool bOpenFileDialog = true,
00117                                                                         bool bDoPrompt = true,
00118                                                                         const String szPromptText = "") : 
00119                                                                         _uHandle (uHandle),
00120                                                                         _szFileName (szFileName),
00121                                                                         _szFilter (szFilter),
00122                                                                         _szDefaultExtension (szDefaultExtension),
00123                                                                         _szTitle (szTitle),
00124                                                                         _bOpenFileDialog (bOpenFileDialog),
00125                                                                         _bDoPrompt (bDoPrompt),
00126                                                                         _szPromptText (szPromptText){};
00127 
00128                         virtual ~CommonFileDialogInput(void){};
00129                         uint getHandle (void);
00130                         String getFileName (void);
00131                         String getFilter (void);
00132                         String getDefaultExtension (void);
00133                         String getTitle (void);
00134                         bool getOpenFileDialog (void);
00135                         bool getDoPrompt (void);
00136                         String getPromptText (void);
00137 
00138                         void setHandle (const uint);
00139                         void setFileName (const String);
00140                         void setFilter (const String);
00141                         void setDefaultExtension (const String);
00142                         void setTitle (const String);
00143                         void setOpenFileDialog (const bool);
00144                         void setDoPrompt (const bool);
00145                         void setPromptText (const String);
00146                         
00147         };
00148 
00149         /*************************************************************************
00150                 Class: CommonFileDialogOutput
00151         *************************************************************************/
00152         class CommonFileDialogOutput
00153         {
00154                 private:
00155                         uint _uHandle;
00160                         String _szFullQualifiedFileName;                                                
00161                         String _szDrive;                                                                                 
00162                         String _szAbsolutePath;                                                                  
00163                         String _szRelativePath;                                                                  
00164                                                                                                                                          
00165                         String _szFileName;                                                                              
00166                         CommonFileDialogAction _action;                                                  
00167                         bool _bFileExisting;                                                                     
00168                                                                                                                                          
00169 
00170                 protected:
00171                 public:
00172                         CommonFileDialogOutput (const uint uHandle = 0,
00173                                                                         const String szFullQualifiedFileName = "",
00174                                                                         const String szDrive = "",
00175                                                                         const String szAbsolutePath = "",
00176                                                                         const String szRelativePath = "",
00177                                                                         const String szFileName = "",
00178                                                                         const bool bFileExisting = false) : 
00179                                                                         _uHandle (uHandle),
00180                                                                         _szFullQualifiedFileName (szFullQualifiedFileName),
00181                                                                         _szDrive (szDrive),
00182                                                                         _szAbsolutePath (szAbsolutePath),
00183                                                                         _szRelativePath (szRelativePath),
00184                                                                         _szFileName (szFileName),
00185                                                                         _bFileExisting(bFileExisting){};
00186 
00187                         virtual ~CommonFileDialogOutput(void){};
00188                         uint getHandle (void);
00189                         String getFullQualifiedFileName (void);
00190                         String getDrive (void);
00191                         String getAbsolutePath (void);
00192                         String getRelativePath (void);
00193                         String getFileName (void);
00194                         CommonFileDialogAction getAction (void);
00195                         bool isFileExisting (void);
00196                         void setHandle (const uint);
00197                         void setFullQualifiedFileName (const String);
00198                         void setDrive (const String);
00199                         void setAbsolutePath (const String);
00200                         void setRelativePath (const String);
00201                         void setFileName (const String);
00202                         void setAction (CommonFileDialogAction);
00203                         void setFileExisting (const bool);
00204         };
00205 
00206         /*************************************************************************
00207                 Class: CCommonFileDialog
00208         *************************************************************************/
00209         class CCommonFileDialog
00210         {
00211                 private:
00213                         class _FilterElement : public ListboxTextItem
00214                         {
00215                                 private:
00216                                 public:
00217                                         _FilterElement( const String& szDescription,
00218                                                                         const String& szExtension) :    szDescription(szDescription),
00219                                                                                                                                         szExtension(szExtension),
00220                                                                                                                                         ListboxTextItem(szDescription) {};
00221                                         String szDescription;                                                   // Description presented in the combobox
00222                                         String szExtension;                                                             // File extension
00223                         };
00224 
00226                         class _Path : public ListboxTextItem
00227                         {
00228                                 private:
00229                                 protected:
00230                                 public:
00231                                         _Path(const String& szRelativePath) :
00232                                                 szAbsolutePath(szAbsolutePath),
00233                                                 szRelativePath(""),
00234                                                 ListboxTextItem(szAbsolutePath) {};
00235                                         virtual ~_Path(void){};
00236                                         String szAbsolutePath;
00237                                         String szRelativePath;
00238                         };
00239 
00241                         class _Filter
00242                         {
00243                                 private:
00244                                 protected:
00245                                 public:
00246                                         _Filter(void) {};
00247                                         virtual ~_Filter(void){};
00248                                         String szDescription;                                                   // Description presented in the combobox
00249                                         String szExtension;                                                             // File extension
00250                         };
00251 
00253                         class _FilterParser
00254                         {
00255                                 private:
00256                                         vector<_Filter*>__filter;                                               // Parsed filter
00257                                         void __deleteFilter();
00258                                 protected:
00259                                 public:
00260                                         _FilterParser(void) {};
00261                                         virtual ~_FilterParser(void){__deleteFilter();};
00262                                         void parseFilter(const String);
00263                                         vector<_Filter*> getParsedFilter(void);
00264                         };
00265                         _FilterParser _filterParser;                                                    // Object that contains the parsed filter
00266 
00267                         // Open/close/enable/disable windows and widgets
00268                         void _disableDialog (void);
00269                         void _enableDialog (void);
00270                         void _closeWindow (void);
00271                         void _closePromptWindowLoad (void);
00272                         void _closePromptWindowSave (void);
00273                         void _openPromptWindowLoad (void);
00274                         void _openPromptWindowSave (void);
00275 
00276                         // Handlers
00277                         bool _handleClose (const CEGUI::EventArgs&);
00278                         bool _handleCancel (const CEGUI::EventArgs&);
00279                         void _okExecute (void);
00280                         bool _handleOk (const CEGUI::EventArgs&);
00281                         bool _handleBack (const CEGUI::EventArgs&);
00282                         bool _handleDriveSelect (const CEGUI::EventArgs&);
00283                         bool _handleFilterSelect (const CEGUI::EventArgs&);
00284                         bool _handleFileSelect (const CEGUI::EventArgs&);
00285                         bool _handleDirectorySelect (const CEGUI::EventArgs&);
00286                         bool _handlePromptLoadOk (const CEGUI::EventArgs&);
00287                         bool _handlePromptSaveOk (const CEGUI::EventArgs&);
00288                         bool _handlePromptSaveCancel (const CEGUI::EventArgs&);
00289 
00290                         // Other private functions
00291                         bool _isFileExisting (const String);
00292                         void _prefillOutputAndClearInput (void);
00293                         void _determineDrives (void);
00294                         String _getWorkingPath (void);
00295                         String _getCurrentDrive (void);
00296                         _FilterElement* _getCurrentFilterElement (void);
00297                         void _setCurrentFile (const String);
00298                         String _getCurrentFile (void);
00299                         void _addFileNameToHistory (const String);
00300                         void _adjustPathOfSelectedDrive (const String);
00301                         _Path* _getPathOfSelectedDrive (void);
00302                         String _stripBrackets(const String);
00303                         String _stripDrive(const String);
00304                         String _stripFileExtension(     const String, bool returnRightPart = true);
00305                         bool _matchItem (const String);
00306                         void _fillListbox (void);
00307 
00308                         // Widgets
00309                         Window* _mWindow;                                                                               
00310                         PushButton* _mBtnBack;                                                                  
00311                         PushButton* _mBtnOk;                                                                    
00312                         PushButton* _mBtnCancel;                                                                
00313                         Combobox* _mCmbFile;                                                                    
00314 
00315 
00316                         Combobox* _mCmbDrives;                                                                  
00317                         Combobox* _mCmbExtensions;                                                              
00318                         Listbox* _mLbxFiles;                                                                    
00319 
00320                         FrameWindow* _mWindowPromptLoad;                                                
00321                         StaticText* _mStPromptLoad;                                                             
00322                         PushButton* _mBtnPromptLoadOk;                                                  
00323                         FrameWindow* _mWindowPromptSave;                                                
00324                         StaticText* _mStPromptSave;                                                             
00325                         PushButton* _mBtnPromptSaveOk;                                                  
00326                         PushButton* _mBtnPromptSaveCancel;                                              
00327 
00328                         // Other private attributes
00329                         vector<String> _drives;                                                                 
00330                         CommonFileDialogInput _currentInput;                                    
00331                         CommonFileDialogOutput _currentOutput;                                  
00332                         hash_map<string, _Path*> _currentPaths;                                 
00333 
00334                 protected:
00335                 public:
00336                         CCommonFileDialog(void);
00337                         virtual ~CCommonFileDialog(void);
00338                         Window* getWindow() {return _mWindow;};
00339                         void openDialog (CommonFileDialogInput&);
00340                         CommonFileDialogOutput getResult (void);
00341         };
00342         typedef CEGUISingletonX<CCommonFileDialog> CommonFileDialog;
00343 };
00344 #endif

Generated on Mon May 29 01:10:33 2006 for Papagan by  doxygen 1.4.6-NO