KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWFavoriteDirectoriesFrame.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkKWFavoriteDirectoriesFrame - A favorite directories frame 00015 // .SECTION Description 00016 // Used as part of a file browser widget, this class includes a toolbar to 00017 // add a favorite directory, and a frame to store all the favorite 00018 // directories as pushbuttons. 00019 // .SECTION Thanks 00020 // This work is part of the National Alliance for Medical Image 00021 // Computing (NAMIC), funded by the National Institutes of Health 00022 // through the NIH Roadmap for Medical Research, Grant U54 EB005149. 00023 // Information on the National Centers for Biomedical Computing 00024 // can be obtained from http://nihroadmap.nih.gov/bioinformatics. 00025 // .SECTION See Also 00026 // vtkKWFileBrowserDialog vtkKWFileBrowserWidget 00027 00028 #ifndef __vtkKWFavoriteDirectoriesFrame_h 00029 #define __vtkKWFavoriteDirectoriesFrame_h 00030 00031 #include "vtkKWCompositeWidget.h" 00032 00033 class vtkKWPushButton; 00034 class vtkKWToolbar; 00035 class vtkKWFrameWithScrollbar; 00036 class vtkKWFavoriteDirectoriesFrameInternals; 00037 class vtkKWMenu; 00038 00039 class KWWidgets_EXPORT vtkKWFavoriteDirectoriesFrame : public vtkKWCompositeWidget 00040 { 00041 public: 00042 static vtkKWFavoriteDirectoriesFrame* New(); 00043 vtkTypeRevisionMacro(vtkKWFavoriteDirectoriesFrame,vtkKWCompositeWidget); 00044 void PrintSelf(ostream& os, vtkIndent indent); 00045 00046 // Description: 00047 // Add a directory to the favorite directories, 00048 // given the path of the directory and the name to display. 00049 virtual void AddFavoriteDirectory(const char *path, const char *name); 00050 00051 // Description: 00052 // Set/Get the path or name of a favorite directory 00053 virtual void SetFavoriteDirectoryPath( 00054 const char* oldpath, const char* newpath); 00055 virtual void SetFavoriteDirectoryName( 00056 const char* oldname, const char* newname); 00057 00058 // Description: 00059 // Remove/relocate a favorite directory. 00060 virtual void RemoveFavoriteDirectory(const char *path); 00061 00062 // Description: 00063 // Select a favorite directory, if it is in the favorite directories list; 00064 // otherwise, de-select all the favorite directories. 00065 virtual void SelectFavoriteDirectory(const char *path); 00066 virtual int IsFavoriteDirectorySelected(const char *path); 00067 00068 // Description: 00069 // Get the selected favorite directory within the frame 00070 virtual const char* GetSelectedFavoriteDirectory(); 00071 00072 // Description 00073 // Check if the given directory has already been added 00074 virtual int HasFavoriteDirectory(const char* path); 00075 00076 // Description 00077 // Check if the given favorite name is already used 00078 virtual int HasFavoriteDirectoryWithName(const char *name); 00079 00080 // Description: 00081 // Set/Get the maximum number of favorite directories to store in the 00082 // registry. 00083 virtual void SetMaximumNumberOfFavoriteDirectoriesInRegistry(int); 00084 vtkGetMacro(MaximumNumberOfFavoriteDirectoriesInRegistry, int); 00085 00086 // Description: 00087 // Restore the favorite directories from the registry 00088 virtual void RestoreFavoriteDirectoriesFromRegistry(); 00089 00090 // Description: 00091 // Convenience method to Set/Get the background color of the container 00092 // frame, i.e. the frame that old all the favorite directories button. 00093 virtual void GetContainerFrameBackgroundColor( 00094 double *r, double *g, double *b); 00095 virtual double* GetContainerFrameBackgroundColor(); 00096 virtual void SetContainerFrameBackgroundColor( 00097 double r, double g, double b); 00098 virtual void SetContainerFrameBackgroundColor(double rgb[3]) 00099 { this->SetContainerFrameBackgroundColor(rgb[0], rgb[1], rgb[2]); }; 00100 00101 // Description: 00102 // Specifies commands to associate with the widget. 00103 // This command will be called from when the "AddFavorites" button is 00104 // clicked. Since this widget does not know by itself what directory to add, 00105 // this callback gives you the opportunity to call 'AddFavoriteDirectory' to 00106 // add a new favorite directory given your application context. 00107 // The 'object' argument is the object that will have the method called on 00108 // it. The 'method' argument is the name of the method to be called and any 00109 // arguments in string form. If the object is NULL, the method is still 00110 // evaluated as a simple command. 00111 virtual void SetAddFavoriteDirectoryCommand( 00112 vtkObject *obj, const char *method); 00113 00114 // Description: 00115 // Specifies commands to associate with the widget. 00116 // This command is called when a favorite directory is selected. 00117 // The 'object' argument is the object that will have the method called on 00118 // it. The 'method' argument is the name of the method to be called and any 00119 // arguments in string form. If the object is NULL, the method is still 00120 // evaluated as a simple command. 00121 // The following parameters are also passed to the command: 00122 // - the path to the favorite: const char* 00123 // - the name of the favorite: const char* 00124 virtual void SetFavoriteDirectorySelectedCommand( 00125 vtkObject *obj, const char *method); 00126 00127 // Description: 00128 // Get the toolbar object. 00129 vtkGetObjectMacro(Toolbar, vtkKWToolbar); 00130 00131 // Description: 00132 // Set/Get if the system default favorites should be ignored. 00133 // On Windows OS, there are system defined Places bar on common 00134 // dialogs to show favorite places. If this ivar is OFF, those 00135 // system defined Places will NOT be read or modified by this class; 00136 // otherwise, those system defined Places will be replaced by 00137 // favorites defined by this class. Default is ON. 00138 //BTX 00139 vtkSetMacro(UseSystemDefaultPlaces, int); 00140 vtkGetMacro(UseSystemDefaultPlaces, int); 00141 vtkBooleanMacro(UseSystemDefaultPlaces, int); 00142 //ETX 00143 00144 // Description: 00145 // Get the add favorite directory button objects. 00146 // DO NOT modify the callbacks, this accessor is provided to change 00147 // the button icon, for example. 00148 vtkGetObjectMacro(AddFavoriteDirectoryButton, vtkKWPushButton); 00149 00150 // Description: 00151 // Update the "enable" state of the object and its internal parts. 00152 // Depending on different Ivars (this->Enabled, the application's 00153 // Limited Edition Mode, etc.), the "enable" state of the object 00154 // is updated and propagated to its internal parts/subwidgets. 00155 // This will, for example, enable/disable parts of the widget UI, 00156 // enable/disable the visibility of 3D widgets, etc. 00157 virtual void UpdateEnableState(); 00158 virtual void Update(); 00159 00160 // Description: 00161 // Callbacks, do NOT use 00162 // When the "Add Favorites" button is clicked, the function will 00163 // be called and a dialog will popup prompt user for a name of the directory 00164 // that will be added to the frame. The default name is the displayed text 00165 // of the directory. 00166 virtual void AddFavoriteDirectoryCallback(); 00167 00168 // Description: 00169 // Callback, do NOT use. 00170 virtual void SelectFavoriteDirectoryCallback( 00171 const char* path, const char*name); 00172 virtual void PopupFavoriteDirectoryCallback( 00173 const char* path, int x, int y); 00174 00175 // Description: 00176 // Callback, do NOT use. 00177 // Rename directory callback from right-click context menu. 00178 virtual void RenameFavoriteDirectoryCallback(const char* path); 00179 00180 // Description: 00181 // Callback, do NOT use. 00182 // Launch native explorer callback from right-click context menu. 00183 virtual void ExploreFavoriteDirectoryCallback(const char* path); 00184 00185 // Description: 00186 // Callbacks, do NOT use 00187 // A dialog will popup for user confirmation of the deleting action. 00188 // If user confirms the action, the favorite folder will be removed from 00189 // the places bar of the dialog. 00190 virtual void RemoveFavoriteDirectoryCallback(const char* path); 00191 00192 protected: 00193 vtkKWFavoriteDirectoriesFrame(); 00194 ~vtkKWFavoriteDirectoriesFrame(); 00195 00196 // Description: 00197 // Create the widget. 00198 virtual void CreateWidget(); 00199 00200 // Description: 00201 // Get the name of a favorite directory given its path (NULL if not found) 00202 virtual const char* GetNameOfFavoriteDirectory(const char *path); 00203 virtual vtkKWPushButton* GetButtonOfFavoriteDirectoryWithName( 00204 const char *name); 00205 00206 // Description: 00207 // Load/Save up to 'maximum_number' favorite dirs 00208 // from/to the registry under the application's 'reg_key'. 00209 // Subkeys are "Place[n][type]" 00210 // The parameter-less methods use RegistryKey as 'reg_key' and 00211 // MaximumNumberOfFavoriteDirectoriesInRegistry as 'maximum_number'. 00212 virtual void RestoreFavoriteDirectoriesFromSystemRegistry(); 00213 virtual void RestoreFavoriteDirectoriesFromUserRegistry( 00214 const char *reg_key, int max_nb); 00215 virtual void WriteFavoriteDirectoriesToRegistry(); 00216 virtual void WriteFavoriteDirectoriesToRegistry( 00217 const char *reg_key, int max_nb); 00218 virtual void WriteFavoriteDirectoriesToSystemRegistry(); 00219 00220 // Description: 00221 // Update favorite directory entries in Registry according to the 00222 // MaximumNumberOfFavoriteDirectoriesInRegistry 00223 virtual void PruneFavoriteDirectoriesInRegistry(); 00224 00225 // Description: 00226 // Add the special folders from Win32 registry to the favorite dirs list, 00227 // such as "My Documents", "Desktop" 00228 virtual int AddSpecialFavoriteFolder(int csidl); 00229 00230 // Description: 00231 // Add a favorite button to the favorite frame 00232 virtual void AddFavoriteDirectoryToFrame( 00233 const char *path, 00234 const char *name); 00235 virtual void UpdateFavoriteDirectoryButton( 00236 vtkKWPushButton *button, const char *path, const char *name); 00237 00238 // Description: 00239 // Select a favorite directory given its name 00240 virtual void SelectFavoriteDirectoryWithName(const char* path); 00241 00242 // Description: 00243 // Get the selected favorite directory given its name 00244 const char* GetSelectedFavoriteDirectoryWithName(const char* name); 00245 00246 // Description: 00247 // Remove a directory node from the most recent history list 00248 virtual void PopulateContextMenu(vtkKWMenu *menu, const char* path); 00249 00250 // Description: 00251 // Clear pointers from internal list 00252 virtual void ClearInternalList(); 00253 00254 // Description: 00255 // Reset favorite frame/buttons state to unselected 00256 virtual void ClearFavoriteDirectorySelection(); 00257 00258 // Description: 00259 // Set/Get the default registry key the favorite dirs are saved to or 00260 // loaded from. 00261 vtkGetStringMacro(RegistryKey); 00262 vtkSetStringMacro(RegistryKey); 00263 00264 // Description: 00265 // Commands 00266 char *AddFavoriteDirectoryCommand; 00267 char *FavoriteDirectorySelectedCommand; 00268 virtual void InvokeAddFavoriteDirectoryCommand(); 00269 virtual void InvokeFavoriteDirectorySelectedCommand( 00270 const char* path, const char *name); 00271 00272 // Description: 00273 // Internal PIMPL class for STL purposes. 00274 vtkKWFavoriteDirectoriesFrameInternals *Internals; 00275 00276 // Description: 00277 // GUI 00278 vtkKWToolbar *Toolbar; 00279 vtkKWFrameWithScrollbar *ContainerFrame; 00280 vtkKWPushButton *AddFavoriteDirectoryButton; 00281 vtkKWMenu *ContextMenu; 00282 00283 // Description: 00284 // Member variables 00285 char *RegistryKey; 00286 int MaximumNumberOfFavoriteDirectoriesInRegistry; 00287 int UseSystemDefaultPlaces; 00288 00289 private: 00290 00291 vtkKWFavoriteDirectoriesFrame(const vtkKWFavoriteDirectoriesFrame&); // Not implemented 00292 void operator=(const vtkKWFavoriteDirectoriesFrame&); // Not implemented 00293 }; 00294 #endif