KWWidgets
debian/tmp/usr/include/KWWidgets/vtkKWFileBrowserDialog.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWFileBrowserDialog.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 vtkKWFileBrowserDialog - dialog for browsing and selecting
15 // files or directories.
16 // .SECTION Description
17 // It includes a Favorite Directories Places Bar, a Directory Explorer,
18 // a Multi-colomn list to list files, and some toolbar buttons to
19 // perform some related tasks on these components.
20 // .SECTION Thanks
21 // This work is part of the National Alliance for Medical Image
22 // Computing (NAMIC), funded by the National Institutes of Health
23 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
24 // Information on the National Centers for Biomedical Computing
25 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
26 // .SECTION See Also
27 // vtkKWFileBrowserWidget vtkKWDiretoryExplorer vtkKWFileListTable
28 // vtkKWFavoriteDirectoriesFrame
29 
30 #ifndef __vtkKWFileBrowserDialog_h
31 #define __vtkKWFileBrowserDialog_h
32 
33 #include "vtkKWDialog.h"
34 
36 class vtkKWPushButton;
37 class vtkKWFrame;
38 class vtkKWLabel;
39 class vtkKWEntry;
40 class vtkKWComboBox;
41 class vtkKWFileBrowserDialogInternals;
42 class vtkStringArray;
43 
45 {
46 public:
47  static vtkKWFileBrowserDialog* New();
48  vtkTypeRevisionMacro(vtkKWFileBrowserDialog,vtkKWDialog);
49  void PrintSelf(ostream& os, vtkIndent indent);
50 
51  // Description:
52  // Get the file path(s) the user selected. Note that if the dialog
53  // was cancelled, the FileName is set to NULL, reflecting that the user
54  // did not select anything (i.e., the previous selection is *not* kept).
55  // If MultipleSelection is On, the above methods can also be used retrieve
56  // all the file (or directory) names that were selected.
57  vtkGetStringMacro(FileName);
58  int GetNumberOfFileNames();
59  const char *GetNthFileName(int i);
60  vtkGetObjectMacro(FileNames, vtkStringArray);
61 
62  // Description:
63  // Set the file path that will be returned when calling GetFileName().
64  // This method will reset FileNames array if FileNames[0] is different
65  // from the FileName. It will also reset the InitialFileName and LastPath
66  // if they are not set already. The idea is that user can just use this
67  // ONE method to initialize the dialog before invoke.
68  virtual void SetFileName(const char*);
69 
70  // Description:
71  // This function will take an array of file names (full names with path),
72  // and has to be called before calling Invoke(). Also, MultipleSelection
73  // has to be set to ON to select multiples before calling this function.
74  // In case of file browser, open the directory of the first file, then
75  // if the SelectionMode is MultipleSelection, select the files
76  // in the array if they are in the opened directory, otherwise ignored;
77  // if it is in the SingleSelectionMode, only the first file will be selected.
78  // In case of ChooseDirectoryOn, select all directories in the array for
79  // Multiple selection mode; select the first in Single selection mode.
80  // Note: in file browser case, this function will ignore
81  // FileTypes and LastPath.
82  void SetInitialSelectedFileNames(vtkStringArray* filenames);
83 
84  // Description:
85  // Set/Get a filename to be displayed in the dialog when it pops up.
86  vtkSetStringMacro(InitialFileName);
87  vtkGetStringMacro(InitialFileName);
88 
89  // Description:
90  // Set/Get the file types the dialog will open or save.
91  // Should be in TK format.
92  // Example: "{{Text Document} {.txt}} {{JPEG image} {.jpg .jpeg}}"
93  virtual void SetFileTypes(const char *);
94  vtkGetStringMacro(FileTypes);
95 
96  // Description:
97  // Get current file extensions that is selected from the FileType dropdown box.
98  // If multiple extensions are available (for example: {{JPEG image} {.jpg .jpeg}}),
99  // the extensions will be returned as a space-separated string (e.g. ".jpg .jpeg").
100  // NOTE: By default, the current file extension is set to ".*", and NULL will returned.
101  virtual const char* GetCurrentFileExtensions();
102 
103  // Description:
104  // Set/Get the default file extension.
105  virtual void SetDefaultExtension(const char *);
106  vtkGetStringMacro(DefaultExtension);
107 
108  // Description:
109  // Set/Get if the dialog should be a "save file" dialog, or a "load file"
110  // dialog.
111  virtual void SetSaveDialog(int);
112  vtkBooleanMacro(SaveDialog, int);
113  vtkGetMacro(SaveDialog, int);
114 
115  // Description:
116  // Set/Get if the dialog should ask the user to pick a directory, or a file.
117  virtual void SetChooseDirectory(int);
118  vtkBooleanMacro(ChooseDirectory, int);
119  vtkGetMacro(ChooseDirectory, int);
120 
121  // Description:
122  // Set/Get if multiple selection are allowed.
123  virtual int GetMultipleSelection();
124  virtual void SetMultipleSelection(int);
125  vtkBooleanMacro(MultipleSelection, int);
126 
127  // Description:
128  // Set/Get the last path.
129  virtual char* GetLastPath();
130  vtkSetStringMacro(LastPath);
131 
132  // Description:
133  // Update the LastPath from a full path to a file.
134  const char* GenerateLastPath(const char* path);
135 
136  // Description:
137  // Accessor for the file browser widget object.
138  vtkGetObjectMacro(FileBrowserWidget, vtkKWFileBrowserWidget);
139 
140  // Description:
141  // Accessor for the preview frame, i.e. the frame where people can
142  // pack their own widgets (say preview images or files, etc.).
143  vtkGetObjectMacro(PreviewFrame, vtkKWFrame);
144 
145  // Description:
146  // Set/Get the visibility of the preview frame
147  virtual void SetPreviewFrameVisibility(int);
148  vtkBooleanMacro(PreviewFrameVisibility, int);
149  vtkGetMacro(PreviewFrameVisibility, int);
150 
151  // Description:
152  // Save/retrieve the last geometry to/from the registry.
153  virtual void SaveGeometryToRegistry();
154  virtual void RestoreGeometryFromRegistry();
155 
156  // Description:
157  // Save/retrieve the last path to/from the registry.
158  // Note that the subkey used here is "RunTime".
159  virtual void SaveLastPathToRegistry(const char *key);
160  virtual void RetrieveLastPathFromRegistry(const char *key);
161 
162  // Description:
163  // Specifies a command to associate with the widget. This command is
164  // typically invoked when the a file has been selected.
165  // The 'object' argument is the object that will have the method called on
166  // it. The 'method' argument is the name of the method to be called and any
167  // arguments in string form. If the object is NULL, the method is still
168  // evaluated as a simple command.
169  // The following parameters are also passed to the command:
170  // - filename (first selected): const char* (warning: NULL is passed as
171  // empty string)
172  virtual void SetFileNameChangedCommand(
173  vtkObject *object, const char *method);
174 
175  // Description:
176  // Events. The FileNameChangedEvent is triggered when the FileName variable
177  // is changed.
178  // The following parameters are also passed as client data:
179  // - current filename: const char*
180  //BTX
181  enum
182  {
183  FileNameChangedEvent = 15000
184  };
185  //ETX
186 
187  // Description:
188  // Callback. Confirm the action and close this dialog
189  virtual void OK();
190 
191  // Description:
192  // Callback. Cancel the action and close this dialog
193  virtual void Cancel();
194 
195  // Description:
196  // Callback. A file type is selected in the File dropdown box.
197  virtual void FileTypeChangedCallback(const char* filetype);
198 
199  // Description:
200  // Callback when user starts editing this entry box.
201  virtual void FileNameEditingCallback(const char* filename);
202 
203  // Description:
204  // Add all the default observers needed by that object, or remove
205  // all the observers that were added through AddCallbackCommandObserver.
206  // Subclasses can override these methods to add/remove their own default
207  // observers, but should call the superclass too.
208  virtual void AddCallbackCommandObservers();
209  virtual void RemoveCallbackCommandObservers();
210 
211 protected:
214 
215  // Description:
216  // Create the widget.
217  virtual void CreateWidget();
218 
219  // Description:
220  // Create (and pack) preview frame.
221  virtual void CreatePreviewFrame();
222 
223  // Description:
224  // Fill in file types in TK format.
225  // Default is: "{{Text Document} {.txt}}"
226  virtual void PopulateFileTypes();
227 
228  // Description:
229  // Update the components of the dialog.
230  virtual void Update();
231 
232  // Description:
233  // Update the "enable" state of the object and its internal parts.
234  // Depending on different Ivars (this->Enabled, the application's
235  // Limited Edition Mode, etc.), the "enable" state of the object is updated
236  // and propagated to its internal parts/subwidgets. This will, for example,
237  // enable/disable parts of the widget UI, enable/disable the visibility
238  // of 3D widgets, etc.
239  virtual void UpdateEnableState();
240 
241  // Description:
242  // Display the dialog.
243  virtual void Display();
244 
245  // Description:
246  // Prompt user for confirmation of overwriting file
247  // Return 1, confirmed; 0 otherwise
248  virtual int ConfirmOverwrite(const char* filename);
249 
250  // Description:
251  // Final step on the selected files or directories
252  virtual int FileOK();
253  virtual int DirectoryOK();
254 
255  // Description:
256  // Internal PIMPL class for STL purposes.
257  vtkKWFileBrowserDialogInternals *Internals;
258 
259  // Description:
260  // GUI
270 
271  // Description:
272  // Member variables.
273  char *FileTypes;
275 
279 
280  vtkStringArray *FileNames;
281  vtkStringArray *InitialSelecttedFileNames;
282 
284  virtual void InvokeFileNameChangedCommand(const char*);
285 
286  // Description:
287  // Set up initial selected files if they are set.
288  // Return 1 on success, 0 on failure.
289  virtual int SetupInitialSelectedFiles();
290 
291  // Description:
292  // Processes the events that are passed through CallbackCommand (or others).
293  // Subclasses can override this method to process their own events, but
294  // should call the superclass too.
295  virtual void ProcessCallbackCommandEvents(
296  vtkObject *caller, unsigned long event, void *calldata);
297  virtual void ProcessDirectorySelectedEvent(const char* fullname);
298  virtual void ProcessFileSelectionChangedEvent(const char* fullname);
299  virtual void ProcessFileDoubleClickedEvent(const char* fullname);
300 
301  // Description:
302  // Check to see if the filename box input has multiple filenames.
303  // Return 1 on success, 0 on failure.
304  virtual int OpenMultipleFileNames(const char* inputnames);
305 
306 private:
307 
308  char *InitialFileName;
309  char *LastPath;
310  char *FileName;
311 
312  vtkKWFileBrowserDialog(const vtkKWFileBrowserDialog&); // Not implemented
313  void operator=(const vtkKWFileBrowserDialog&); // Not implemented
314 };
315 #endif