KWWidgets
debian/tmp/usr/include/KWWidgets/vtkKWFileListTable.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWFileListTable.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 vtkKWFileListTable - a file list table widget
15 // .SECTION Description
16 // A widget for displaying and selecting files/directories within
17 // a directory. It contains information about file name, size and
18 // modified time. The files can be sorted by these info individually.
19 // The right click context menu offers explore, rename, delete functions.
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 // vtkKWFileBrowserDialog vtkKWFileBrowserWidget
28 
29 #ifndef __vtkKWFileListTable_h
30 #define __vtkKWFileListTable_h
31 
32 #include "vtkKWCompositeWidget.h"
33 
35 class vtkKWMenu;
36 class vtkGlobFileNames;
37 class vtkKWFileListTableInternals;
38 
40 {
41 public:
42  static vtkKWFileListTable* New();
44  void PrintSelf(ostream& os, vtkIndent indent);
45 
46  // Description:
47  // Show folders and files of the given directory (path) in the table,
48  // based on file patterns and/or extensions if they exist.
49  // If both patterns and extensions exist, only the patterns are used.
50  // Return 1 on success, 0 otherwise
51  virtual int ShowFileList(
52  const char *path,
53  const char *filepattern,
54  const char *fileextensions);
55 
56  // Description:
57  // Set/Get the parent directory, of which this widget is
58  // displaying the files and directories
59  virtual void SetParentDirectory(const char *arg);
60  vtkGetStringMacro(ParentDirectory);
61 
62  // Description:
63  // Set/Get the file pattern that should contains "*" or "?",
64  // with which the files will be filtered. When the widget uses
65  // file pattern to filter files, the file extensions will be ignored.
66  // Example: "foo*" or "?bar"
67  virtual void SetFilePattern(const char *arg);
68  vtkGetStringMacro(FilePattern);
69 
70  // Description:
71  // Set/Get the file extenstions that the file table will use
72  // to filter its files. When the widget uses
73  // file pattern to filter files, the file extensions will be ignored.
74  // The argument is NOT a Tk format, just a simple string of extensions
75  // with space between them.
76  // Example: ".txt .text .jpg .jpeg"
77  virtual void SetFileExtensions(const char *arg);
78  vtkGetStringMacro(FileExtensions);
79 
80  // Description:
81  // Set the one of several styles for manipulating the selection.
82  // Valid constants can be found in vtkKWOptions::SelectionModeType.
83  virtual void SetSelectionMode(int);
84  virtual void SetSelectionModeToSingle();
85  virtual void SetSelectionModeToBrowse();
86  virtual void SetSelectionModeToMultiple();
87  virtual void SetSelectionModeToExtended();
88 
89  // Description:
90  // Get the files that are selected. This is meant
91  // for use with MultipleSelection mode.
92  virtual const char *GetSelectedFileName()
93  {return GetNthSelectedFileName(0);}
94  virtual int GetNumberOfSelectedFileNames();
95  virtual const char *GetNthSelectedFileName(int i);
96  virtual void SelectFileName(const char* filename);
97  virtual void DeselectFileName(const char*);
98  virtual void ClearSelection();
99 
100  // Description:
101  // Set/Get the selection background and foreground colors.
102  virtual void GetSelectionBackgroundColor(double *r, double *g, double *b);
103  virtual double* GetSelectionBackgroundColor();
104  virtual void SetSelectionBackgroundColor(double r, double g, double b);
105  virtual void SetSelectionBackgroundColor(double rgb[3])
106  { this->SetSelectionBackgroundColor(rgb[0], rgb[1], rgb[2]); };
107  virtual void GetSelectionForegroundColor(double *r, double *g, double *b);
108  virtual double* GetSelectionForegroundColor();
109  virtual void SetSelectionForegroundColor(double r, double g, double b);
110  virtual void SetSelectionForegroundColor(double rgb[3])
111  { this->SetSelectionForegroundColor(rgb[0], rgb[1], rgb[2]); };
112 
113  // Description:
114  // Set/Get the width (in chars) and height (in lines) of the table.
115  // If width is set to 0, the widget will be large enough to show
116  // all columns. In all cases, the widget will still obey to its packing
117  // layout, i.e. it will stretch all the way if: -fill x
118  virtual void SetTableWidth(int width);
119  virtual int GetTableWidth();
120  virtual void SetTableHeight(int height);
121  virtual int GetTableHeight();
122 
123  // Description:
124  // Convenience method to Set/Get the table background color.
125  virtual void GetTableBackgroundColor(double *r, double *g, double *b);
126  virtual double* GetTableBackgroundColor();
127  virtual void SetTableBackgroundColor(double r, double g, double b);
128  virtual void SetTableBackgroundColor(double rgb[3])
129  { this->SetTableBackgroundColor(rgb[0], rgb[1], rgb[2]); };
130 
131  // Description:
132  // Specifies commands to associate with the widget.
133  // 'FileSelected' is called whenever the selection is changed.
134  // 'FileDoubleClicked' is called when a file/folder is double-clicked on.
135  // 'FileDeleted' is called when a file/folder is removed
136  // 'FileRenamed' is called when a file/folder is renamed by right click
137  // 'FileUpdated' is called when a new folder is created from right click
138  // on empty rows.
139  // The 'object' argument is the object that will have the method called on
140  // it. The 'method' argument is the name of the method to be called and any
141  // arguments in string form. If the object is NULL, the method is still
142  // evaluated as a simple command.
143  virtual void SetFileSelectedCommand(vtkObject *obj, const char *method);
144  virtual void SetFileDoubleClickedCommand(vtkObject *obj, const char *method);
145  virtual void SetFileDeletedCommand(vtkObject *obj, const char *method);
146  virtual void SetFileRenamedCommand(vtkObject *obj, const char *method);
147  virtual void SetFolderCreatedCommand(vtkObject *obj, const char *method);
148 
149  // Description:
150  // Define the event types with enumeration
151  // Even though it is highly recommended to use the commands
152  // framework defined above to specify the callback methods you want to be
153  // invoked when specific event occur, you can also use the observer
154  // framework and listen to the corresponding events/
155  // Note that they are passed the same parameters as the commands, if any.
156  // If more than one numerical parameter is passed, they are all stored
157  // in the calldata as an array of double.
158  //BTX
159  enum
160  {
161  FileSelectionChangedEvent = 10000,
165  FileDeletedEvent
166  };
167  //ETX
168 
169  // Description:
170  // Set focus to the file list component of this widget.
171  // Based on the visibility
172  virtual void Focus();
173  virtual int HasFocus();
174 
175  // Description:
176  // Add/Remove event binding to the internal file list
177  // component of this widget, so that these events will be
178  // invoked directly from the file list component of this widget.
179  virtual void AddBindingToInternalWidget(const char* event,
180  vtkObject *obj, const char* method);
181  virtual void RemoveBindingFromInternalWidget(const char* event,
182  vtkObject *obj, const char* method);
183 
184  // Description:
185  // Callback, do NOT use.
186  // Right-click context menu callbacks
187  virtual void ContextMenuCallback(int row, int col, int x, int y);
188 
189  // Description:
190  // Callback, do NOT use.
191  // Callbacks for Prior/Next key navigations in the table
192  virtual void KeyPriorNextNavigationCallback(
193  const char *w, int x, int y,
194  int root_x, int root_y, const char* key);
195 
196  // Description:
197  // Callback, do NOT use.
198  // Rename callback.
199  virtual int RenameFileCallback();
200 
201  // Description:
202  // Callback, do NOT use.
203  // Callback triggered when the file list table is getting focus.
204  virtual void FocusInCallback();
205 
206  // Description:
207  // Callback, do NOT use.
208  // Launch native explorer callback.
209  virtual void ExploreFileCallback();
210 
211  // Description:
212  // Callback, do NOT use.
213  // Create new folder callback.
214  virtual void CreateNewFolderCallback(const char* parentdir);
215 
216  // Description:
217  // Callback, do NOT use.
218  // Callback triggered when the file selection is changed in the file list.
219  virtual void SelectedFileChangedCallback();
220 
221  // Description:
222  // Callback, do NOT use.
223  // Callback triggered for the Navigation keys: Home/End.
224  // This is used to change the default behavior of the
225  // vtkKWMultiColumnList, so that the list behaves more like Win32 explorer
226  virtual void KeyHomeEndNavigationCallback(const char *key);
227 
228  // Description:
229  // Callback, do NOT use.
230  // Callback triggered when an item is double clicked in the file list.
231  virtual void FileDoubleClickCallback();
232 
233  // Description:
234  // Callback, do NOT use.
235  // Callback triggered when the 'Delete' key is pressed.
236  // Remove the selected item from the file list.
237  virtual int RemoveSelectedFileCallback();
238 
239  // Description:
240  // Callback, do NOT use.
241  // When the time column in the file list is displayed, convert
242  // the celltext ('+' as file or '-' as folder plus time value in seconds
243  // for sorting while keeps folders and files separate)) to ctime format.
244  // Funtion returns the formatted string that will be displayed: char*
245  virtual char *GetFormatTimeStringCallback(const char* celltext);
246 
247  // Description:
248  // Callback, do NOT use.
249  // Sort items by time.
250  virtual int SortTimeCallback(const char* cell1, const char* cell2);
251 
252  // Description:
253  // Callback, do NOT use.
254  // When the size column in the file list is displayed, convert
255  // the celltext (size value in bytes) to 'KB' format.
256  // Funtion returns the formatted string that will be displayed: const char*
257  virtual char *GetFormatSizeStringCallback(const char* celltext);
258 
259  // Description:
260  // Callback, do NOT use.
261  // When the Name column in the file list is displayed, convert
262  // the celltext (1 as file or 0 as folder plus real name for sorting
263  // while keeping folders and files seperate) to real name.
264  // Funtion returns the real name that will be displayed: const char*
265  virtual char *GetRealNameStringCallback(const char* celltext);
266 
267  // Description:
268  // Update the "enable" state of the object and its internal parts.
269  // Depending on different Ivars (this->Enabled, the application's
270  // Limited Edition Mode, etc.), the "enable" state of the object
271  // is updated and propagated to its internal parts/subwidgets.
272  // This will, for example, enable/disable parts of the widget UI,
273  // enable/disable the visibility of 3D widgets, etc.
274  virtual void UpdateEnableState();
275 
276  // Description:
277  // Given the prefix of a file or folder name, this function will make
278  // the corresponding row with this name visible in the window
279  virtual void ScrollToFile(const char* prefix);
280 
281 protected:
284 
285  // Description:
286  // Create the widget.
287  virtual void CreateWidget();
288 
289  // Description:
290  // Populate the right-click context menu.
291  virtual void PopulateContextMenu(int rowselected);
292 
293  // Description:
294  // Commands
300 
301  // Description:
302  // Invoke Commands
303  virtual void InvokeFileSelectedCommand(const char* path);
304  virtual void InvokeFileDoubleClickedCommand(const char* path);
305  virtual void InvokeFileDeletedCommand(const char* path, int isDir);
306  virtual void InvokeFileRenamedCommand(
307  const char* oldname, const char* newname);
308  virtual void InvokeFolderCreatedCommand(const char* filename);
309 
310  // Description:
311  // Set the parent directory, file pattern, file extensions
312  virtual void SetParentDirectoryInternal(const char *arg);
313  virtual void SetFilePatternInternal(const char *arg);
314  virtual void SetFileExtensionsInternal(const char *arg);
315 
316  // Description:
317  // Member variables
318  vtkKWFileListTableInternals *Internals;
322  char* FilePattern;
324 
325 private:
326  vtkKWFileListTable(const vtkKWFileListTable&); // Not implemented
327  void operator=(const vtkKWFileListTable&); // Not implemented
328 
329  // Description:
330  // Get a temporary full filename given the row index,
331  // should be stored right away
332  virtual char* GetRowFileName(int row);
333 
334  // Description:
335  // Get the cell text
336  virtual const char* GetCellText(int row, int col);
337 
338 };
339 #endif