KWWidgets
vtkKWFavoriteDirectoriesFrame.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWFavoriteDirectoriesFrame.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWFavoriteDirectoriesFrame - A favorite directories frame
15 // .SECTION Description
16 // Used as part of a file browser widget, this class includes a toolbar to
17 // add a favorite directory, and a frame to store all the favorite
18 // directories as pushbuttons.
19 // .SECTION Thanks
20 // This work is part of the National Alliance for Medical Image
21 // Computing (NAMIC), funded by the National Institutes of Health
22 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
23 // Information on the National Centers for Biomedical Computing
24 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
25 // .SECTION See Also
26 // vtkKWFileBrowserDialog vtkKWFileBrowserWidget
27 
28 #ifndef __vtkKWFavoriteDirectoriesFrame_h
29 #define __vtkKWFavoriteDirectoriesFrame_h
30 
31 #include "vtkKWCompositeWidget.h"
32 
33 class vtkKWPushButton;
34 class vtkKWToolbar;
36 class vtkKWFavoriteDirectoriesFrameInternals;
37 class vtkKWMenu;
38 
40 {
41 public:
44  void PrintSelf(ostream& os, vtkIndent indent);
45 
46  // Description:
47  // Add a directory to the favorite directories,
48  // given the path of the directory and the name to display.
49  virtual void AddFavoriteDirectory(const char *path, const char *name);
50 
51  // Description:
52  // Set/Get the path or name of a favorite directory
53  virtual void SetFavoriteDirectoryPath(
54  const char* oldpath, const char* newpath);
55  virtual void SetFavoriteDirectoryName(
56  const char* oldname, const char* newname);
57 
58  // Description:
59  // Remove/relocate a favorite directory.
60  virtual void RemoveFavoriteDirectory(const char *path);
61 
62  // Description:
63  // Select a favorite directory, if it is in the favorite directories list;
64  // otherwise, de-select all the favorite directories.
65  virtual void SelectFavoriteDirectory(const char *path);
66  virtual int IsFavoriteDirectorySelected(const char *path);
67 
68  // Description:
69  // Get the selected favorite directory within the frame
70  virtual const char* GetSelectedFavoriteDirectory();
71 
72  // Description
73  // Check if the given directory has already been added
74  virtual int HasFavoriteDirectory(const char* path);
75 
76  // Description
77  // Check if the given favorite name is already used
78  virtual int HasFavoriteDirectoryWithName(const char *name);
79 
80  // Description:
81  // Set/Get the maximum number of favorite directories to store in the
82  // registry.
83  virtual void SetMaximumNumberOfFavoriteDirectoriesInRegistry(int);
84  vtkGetMacro(MaximumNumberOfFavoriteDirectoriesInRegistry, int);
85 
86  // Description:
87  // Restore the favorite directories from the registry
88  virtual void RestoreFavoriteDirectoriesFromRegistry();
89 
90  // Description:
91  // Convenience method to Set/Get the background color of the container
92  // frame, i.e. the frame that old all the favorite directories button.
93  virtual void GetContainerFrameBackgroundColor(
94  double *r, double *g, double *b);
95  virtual double* GetContainerFrameBackgroundColor();
96  virtual void SetContainerFrameBackgroundColor(
97  double r, double g, double b);
98  virtual void SetContainerFrameBackgroundColor(double rgb[3])
99  { this->SetContainerFrameBackgroundColor(rgb[0], rgb[1], rgb[2]); };
100 
101  // Description:
102  // Specifies commands to associate with the widget.
103  // This command will be called from when the "AddFavorites" button is
104  // clicked. Since this widget does not know by itself what directory to add,
105  // this callback gives you the opportunity to call 'AddFavoriteDirectory' to
106  // add a new favorite directory given your application context.
107  // The 'object' argument is the object that will have the method called on
108  // it. The 'method' argument is the name of the method to be called and any
109  // arguments in string form. If the object is NULL, the method is still
110  // evaluated as a simple command.
111  virtual void SetAddFavoriteDirectoryCommand(
112  vtkObject *obj, const char *method);
113 
114  // Description:
115  // Specifies commands to associate with the widget.
116  // This command is called when a favorite directory is selected.
117  // The 'object' argument is the object that will have the method called on
118  // it. The 'method' argument is the name of the method to be called and any
119  // arguments in string form. If the object is NULL, the method is still
120  // evaluated as a simple command.
121  // The following parameters are also passed to the command:
122  // - the path to the favorite: const char*
123  // - the name of the favorite: const char*
124  virtual void SetFavoriteDirectorySelectedCommand(
125  vtkObject *obj, const char *method);
126 
127  // Description:
128  // Get the toolbar object.
129  vtkGetObjectMacro(Toolbar, vtkKWToolbar);
130 
131  // Description:
132  // Set/Get if the system default favorites should be ignored.
133  // On Windows OS, there are system defined Places bar on common
134  // dialogs to show favorite places. If this ivar is OFF, those
135  // system defined Places will NOT be read or modified by this class;
136  // otherwise, those system defined Places will be replaced by
137  // favorites defined by this class. Default is ON.
138  //BTX
139  vtkSetMacro(UseSystemDefaultPlaces, int);
140  vtkGetMacro(UseSystemDefaultPlaces, int);
141  vtkBooleanMacro(UseSystemDefaultPlaces, int);
142  //ETX
143 
144  // Description:
145  // Get the add favorite directory button objects.
146  // DO NOT modify the callbacks, this accessor is provided to change
147  // the button icon, for example.
148  vtkGetObjectMacro(AddFavoriteDirectoryButton, vtkKWPushButton);
149 
150  // Description:
151  // Update the "enable" state of the object and its internal parts.
152  // Depending on different Ivars (this->Enabled, the application's
153  // Limited Edition Mode, etc.), the "enable" state of the object
154  // is updated and propagated to its internal parts/subwidgets.
155  // This will, for example, enable/disable parts of the widget UI,
156  // enable/disable the visibility of 3D widgets, etc.
157  virtual void UpdateEnableState();
158  virtual void Update();
159 
160  // Description:
161  // Callbacks, do NOT use
162  // When the "Add Favorites" button is clicked, the function will
163  // be called and a dialog will popup prompt user for a name of the directory
164  // that will be added to the frame. The default name is the displayed text
165  // of the directory.
166  virtual void AddFavoriteDirectoryCallback();
167 
168  // Description:
169  // Callback, do NOT use.
170  virtual void SelectFavoriteDirectoryCallback(
171  const char* path, const char*name);
172  virtual void PopupFavoriteDirectoryCallback(
173  const char* path, int x, int y);
174 
175  // Description:
176  // Callback, do NOT use.
177  // Rename directory callback from right-click context menu.
178  virtual void RenameFavoriteDirectoryCallback(const char* path);
179 
180  // Description:
181  // Callback, do NOT use.
182  // Launch native explorer callback from right-click context menu.
183  virtual void ExploreFavoriteDirectoryCallback(const char* path);
184 
185  // Description:
186  // Callbacks, do NOT use
187  // A dialog will popup for user confirmation of the deleting action.
188  // If user confirms the action, the favorite folder will be removed from
189  // the places bar of the dialog.
190  virtual void RemoveFavoriteDirectoryCallback(const char* path);
191 
192 protected:
195 
196  // Description:
197  // Create the widget.
198  virtual void CreateWidget();
199 
200  // Description:
201  // Get the name of a favorite directory given its path (NULL if not found)
202  virtual const char* GetNameOfFavoriteDirectory(const char *path);
203  virtual vtkKWPushButton* GetButtonOfFavoriteDirectoryWithName(
204  const char *name);
205 
206  // Description:
207  // Load/Save up to 'maximum_number' favorite dirs
208  // from/to the registry under the application's 'reg_key'.
209  // Subkeys are "Place[n][type]"
210  // The parameter-less methods use RegistryKey as 'reg_key' and
211  // MaximumNumberOfFavoriteDirectoriesInRegistry as 'maximum_number'.
212  virtual void RestoreFavoriteDirectoriesFromSystemRegistry();
213  virtual void RestoreFavoriteDirectoriesFromUserRegistry(
214  const char *reg_key, int max_nb);
215  virtual void WriteFavoriteDirectoriesToRegistry();
216  virtual void WriteFavoriteDirectoriesToRegistry(
217  const char *reg_key, int max_nb);
218  virtual void WriteFavoriteDirectoriesToSystemRegistry();
219 
220  // Description:
221  // Update favorite directory entries in Registry according to the
222  // MaximumNumberOfFavoriteDirectoriesInRegistry
223  virtual void PruneFavoriteDirectoriesInRegistry();
224 
225  // Description:
226  // Add the special folders from Win32 registry to the favorite dirs list,
227  // such as "My Documents", "Desktop"
228  virtual int AddSpecialFavoriteFolder(int csidl);
229 
230  // Description:
231  // Add a favorite button to the favorite frame
232  virtual void AddFavoriteDirectoryToFrame(
233  const char *path,
234  const char *name);
235  virtual void UpdateFavoriteDirectoryButton(
236  vtkKWPushButton *button, const char *path, const char *name);
237 
238  // Description:
239  // Select a favorite directory given its name
240  virtual void SelectFavoriteDirectoryWithName(const char* path);
241 
242  // Description:
243  // Get the selected favorite directory given its name
244  const char* GetSelectedFavoriteDirectoryWithName(const char* name);
245 
246  // Description:
247  // Remove a directory node from the most recent history list
248  virtual void PopulateContextMenu(vtkKWMenu *menu, const char* path);
249 
250  // Description:
251  // Clear pointers from internal list
252  virtual void ClearInternalList();
253 
254  // Description:
255  // Reset favorite frame/buttons state to unselected
256  virtual void ClearFavoriteDirectorySelection();
257 
258  // Description:
259  // Set/Get the default registry key the favorite dirs are saved to or
260  // loaded from.
261  vtkGetStringMacro(RegistryKey);
262  vtkSetStringMacro(RegistryKey);
263 
264  // Description:
265  // Commands
266  char *AddFavoriteDirectoryCommand;
267  char *FavoriteDirectorySelectedCommand;
268  virtual void InvokeAddFavoriteDirectoryCommand();
269  virtual void InvokeFavoriteDirectorySelectedCommand(
270  const char* path, const char *name);
271 
272  // Description:
273  // Internal PIMPL class for STL purposes.
274  vtkKWFavoriteDirectoriesFrameInternals *Internals;
275 
276  // Description:
277  // GUI
278  vtkKWToolbar *Toolbar;
279  vtkKWFrameWithScrollbar *ContainerFrame;
280  vtkKWPushButton *AddFavoriteDirectoryButton;
281  vtkKWMenu *ContextMenu;
282 
283  // Description:
284  // Member variables
285  char *RegistryKey;
286  int MaximumNumberOfFavoriteDirectoriesInRegistry;
287  int UseSystemDefaultPlaces;
288 
289 private:
290 
292  void operator=(const vtkKWFavoriteDirectoriesFrame&); // Not implemented
293 };
294 #endif