debian/tmp/usr/include/KWWidgets/vtkKWFileBrowserDialog.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Module:    $RCSfile: vtkKWFileBrowserDialog.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 vtkKWFileBrowserDialog - dialog for browsing and selecting 
00015 // files or directories.
00016 // .SECTION Description
00017 // It includes a Favorite Directories Places Bar, a Directory Explorer, 
00018 // a Multi-colomn list to list files, and some toolbar buttons to 
00019 // perform some related tasks on these components.
00020 // .SECTION Thanks
00021 // This work is part of the National Alliance for Medical Image
00022 // Computing (NAMIC), funded by the National Institutes of Health
00023 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
00024 // Information on the National Centers for Biomedical Computing
00025 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
00026 // .SECTION See Also
00027 // vtkKWFileBrowserWidget vtkKWDiretoryExplorer vtkKWFileListTable 
00028 // vtkKWFavoriteDirectoriesFrame
00029 
00030 #ifndef __vtkKWFileBrowserDialog_h
00031 #define __vtkKWFileBrowserDialog_h
00032 
00033 #include "vtkKWDialog.h"
00034 
00035 class vtkKWFileBrowserWidget;
00036 class vtkKWPushButton;
00037 class vtkKWFrame;
00038 class vtkKWLabel;
00039 class vtkKWEntry;
00040 class vtkKWComboBox;
00041 class vtkKWFileBrowserDialogInternals;
00042 class vtkStringArray;
00043 
00044 class KWWidgets_EXPORT vtkKWFileBrowserDialog : public vtkKWDialog
00045 {
00046 public:
00047   static vtkKWFileBrowserDialog* New();
00048   vtkTypeRevisionMacro(vtkKWFileBrowserDialog,vtkKWDialog);
00049   void PrintSelf(ostream& os, vtkIndent indent);
00050   
00051   // Description:
00052   // Get the file path(s) the user selected. Note that if the dialog
00053   // was cancelled, the FileName is set to NULL, reflecting that the user
00054   // did not select anything (i.e., the previous selection is *not* kept).
00055   // If MultipleSelection is On, the above methods can also be used retrieve
00056   // all the file (or directory) names that were selected.
00057   vtkGetStringMacro(FileName);
00058   int GetNumberOfFileNames();
00059   const char *GetNthFileName(int i);
00060   vtkGetObjectMacro(FileNames, vtkStringArray); 
00061 
00062   // Description:
00063   // Set the file path that will be returned when calling GetFileName().
00064   // This method will reset FileNames array if FileNames[0] is different
00065   // from the FileName. It will also reset the InitialFileName and LastPath
00066   // if they are not set already. The idea is that user can just use this 
00067   // ONE method to initialize the dialog before invoke.
00068   virtual void SetFileName(const char*);
00069 
00070   // Description:
00071   // This function will take an array of file names (full names with path),
00072   // and has to be called before calling Invoke(). Also, MultipleSelection 
00073   // has to be set to ON to select multiples before calling this function.
00074   // In case of file browser, open the directory of the first file, then
00075   // if the SelectionMode is MultipleSelection, select the files
00076   // in the array if they are in the opened directory, otherwise ignored;
00077   // if it is in the SingleSelectionMode, only the first file will be selected.
00078   // In case of ChooseDirectoryOn, select all directories in the array for 
00079   // Multiple selection mode; select the first in Single selection mode.
00080   // Note: in file browser case, this function will ignore 
00081   // FileTypes and LastPath.
00082   void SetInitialSelectedFileNames(vtkStringArray* filenames);
00083 
00084   // Description:
00085   // Set/Get a filename to be displayed in the dialog when it pops up.
00086   vtkSetStringMacro(InitialFileName);
00087   vtkGetStringMacro(InitialFileName);
00088 
00089   // Description:
00090   // Set/Get the file types the dialog will open or save.
00091   // Should be in TK format. 
00092   // Example: "{{Text Document} {.txt}} {{JPEG image} {.jpg .jpeg}}"
00093   virtual void SetFileTypes(const char *);
00094   vtkGetStringMacro(FileTypes);
00095   
00096   // Description:
00097   // Get current file extensions that is selected from the FileType dropdown box.
00098   // If multiple extensions are available (for example: {{JPEG image} {.jpg .jpeg}}),
00099   // the extensions will be returned as a space-separated string (e.g. ".jpg .jpeg").
00100   // NOTE: By default, the current file extension is set to ".*", and NULL will returned.
00101   virtual const char* GetCurrentFileExtensions();
00102 
00103   // Description:
00104   // Set/Get the default file extension.
00105   virtual void SetDefaultExtension(const char *);
00106   vtkGetStringMacro(DefaultExtension);
00107   
00108   // Description:
00109   // Set/Get if the dialog should be a "save file" dialog, or a "load file"
00110   // dialog.
00111   virtual void SetSaveDialog(int);
00112   vtkBooleanMacro(SaveDialog, int);
00113   vtkGetMacro(SaveDialog, int);
00114 
00115   // Description:
00116   // Set/Get if the dialog should ask the user to pick a directory, or a file.
00117   virtual void SetChooseDirectory(int);
00118   vtkBooleanMacro(ChooseDirectory, int);
00119   vtkGetMacro(ChooseDirectory, int);
00120 
00121   // Description:
00122   // Set/Get if multiple selection are allowed.
00123   virtual int GetMultipleSelection();
00124   virtual void SetMultipleSelection(int);
00125   vtkBooleanMacro(MultipleSelection, int);
00126 
00127   // Description:
00128   // Set/Get the last path.
00129   virtual char* GetLastPath();
00130   vtkSetStringMacro(LastPath);
00131   
00132   // Description:
00133   // Update the LastPath from a full path to a file.
00134   const char* GenerateLastPath(const char* path);
00135 
00136   // Description:
00137   // Accessor for the file browser widget object.
00138   vtkGetObjectMacro(FileBrowserWidget, vtkKWFileBrowserWidget);
00139   
00140   // Description:
00141   // Accessor for the preview frame, i.e. the frame where people can
00142   // pack their own widgets (say preview images or files, etc.).
00143   vtkGetObjectMacro(PreviewFrame, vtkKWFrame);
00144 
00145   // Description:
00146   // Set/Get the visibility of the preview frame
00147   virtual void SetPreviewFrameVisibility(int);
00148   vtkBooleanMacro(PreviewFrameVisibility, int); 
00149   vtkGetMacro(PreviewFrameVisibility, int); 
00150 
00151   // Description:
00152   // Save/retrieve the last geometry to/from the registry.
00153   virtual void SaveGeometryToRegistry();
00154   virtual void RestoreGeometryFromRegistry();
00155 
00156   // Description:
00157   // Save/retrieve the last path to/from the registry.
00158   // Note that the subkey used here is "RunTime".
00159   virtual void SaveLastPathToRegistry(const char *key);
00160   virtual void RetrieveLastPathFromRegistry(const char *key);
00161 
00162   // Description:
00163   // Specifies a command to associate with the widget. This command is 
00164   // typically invoked when the a file has been selected.
00165   // The 'object' argument is the object that will have the method called on
00166   // it. The 'method' argument is the name of the method to be called and any
00167   // arguments in string form. If the object is NULL, the method is still
00168   // evaluated as a simple command. 
00169   // The following parameters are also passed to the command:
00170   // - filename (first selected): const char* (warning: NULL is passed as
00171   // empty string)
00172   virtual void SetFileNameChangedCommand(
00173     vtkObject *object, const char *method);
00174 
00175   // Description:
00176   // Events. The FileNameChangedEvent is triggered when the FileName variable
00177   // is changed.
00178   // The following parameters are also passed as client data:
00179   // - current filename: const char*
00180   //BTX
00181   enum
00182   {
00183     FileNameChangedEvent = 15000
00184   };
00185   //ETX
00186 
00187   // Description:
00188   // Callback. Confirm the action and close this dialog
00189   virtual void OK();
00190   
00191   // Description:
00192   // Callback. Cancel the action and close this dialog
00193   virtual void Cancel();
00194 
00195   // Description:
00196   // Callback. A file type is selected in the File dropdown box.
00197   virtual void FileTypeChangedCallback(const char* filetype);
00198 
00199   // Description:
00200   // Callback when user starts editing this entry box.
00201   virtual void FileNameEditingCallback(const char* filename);
00202 
00203   // Description:
00204   // Add all the default observers needed by that object, or remove
00205   // all the observers that were added through AddCallbackCommandObserver.
00206   // Subclasses can override these methods to add/remove their own default
00207   // observers, but should call the superclass too.
00208   virtual void AddCallbackCommandObservers();
00209   virtual void RemoveCallbackCommandObservers();
00210   
00211 protected:
00212   vtkKWFileBrowserDialog();
00213   ~vtkKWFileBrowserDialog();
00214 
00215   // Description:
00216   // Create the widget.
00217   virtual void CreateWidget();
00218   
00219   // Description:
00220   // Create (and pack) preview frame.  
00221   virtual void CreatePreviewFrame();
00222 
00223   // Description:
00224   // Fill in file types in TK format. 
00225   // Default is: "{{Text Document} {.txt}}"   
00226   virtual void PopulateFileTypes();
00227 
00228   // Description:
00229   // Update the components of the dialog.
00230   virtual void Update();
00231 
00232   // Description:
00233   // Update the "enable" state of the object and its internal parts.
00234   // Depending on different Ivars (this->Enabled, the application's 
00235   // Limited Edition Mode, etc.), the "enable" state of the object is updated
00236   // and propagated to its internal parts/subwidgets. This will, for example,
00237   // enable/disable parts of the widget UI, enable/disable the visibility
00238   // of 3D widgets, etc.
00239   virtual void UpdateEnableState();
00240 
00241   // Description:
00242   // Display the dialog.
00243   virtual void Display();
00244   
00245   // Description:
00246   // Prompt user for confirmation of overwriting file
00247   // Return 1, confirmed; 0 otherwise
00248   virtual int ConfirmOverwrite(const char* filename);
00249 
00250   // Description:
00251   // Final step on the selected files or directories
00252   virtual int FileOK();
00253   virtual int DirectoryOK();
00254 
00255   // Description:
00256   // Internal PIMPL class for STL purposes.
00257   vtkKWFileBrowserDialogInternals *Internals;
00258   
00259   // Description:
00260   // GUI
00261   vtkKWFileBrowserWidget *FileBrowserWidget;
00262   vtkKWFrame             *BottomFrame;
00263   vtkKWLabel             *FileNameLabel;
00264   vtkKWLabel             *FileTypesLabel;
00265   vtkKWEntry             *FileNameText;
00266   vtkKWComboBox          *FileTypesBox;
00267   vtkKWPushButton        *OKButton;
00268   vtkKWPushButton        *CancelButton;  
00269   vtkKWFrame             *PreviewFrame;
00270 
00271   // Description:
00272   // Member variables.
00273   char *FileTypes;
00274   char *DefaultExtension;
00275 
00276   int  PreviewFrameVisibility;
00277   int  SaveDialog;
00278   int  ChooseDirectory;
00279 
00280   vtkStringArray *FileNames;
00281   vtkStringArray *InitialSelecttedFileNames;
00282 
00283   char *FileNameChangedCommand;
00284   virtual void InvokeFileNameChangedCommand(const char*);
00285   
00286   // Description:
00287   // Set up initial selected files if they are set.
00288   // Return 1 on success, 0 on failure.
00289   virtual int SetupInitialSelectedFiles();
00290 
00291   // Description:
00292   // Processes the events that are passed through CallbackCommand (or others).
00293   // Subclasses can override this method to process their own events, but
00294   // should call the superclass too.
00295   virtual void ProcessCallbackCommandEvents(
00296     vtkObject *caller, unsigned long event, void *calldata);
00297   virtual void ProcessDirectorySelectedEvent(const char* fullname);
00298   virtual void ProcessFileSelectionChangedEvent(const char* fullname);
00299   virtual void ProcessFileDoubleClickedEvent(const char* fullname);
00300 
00301   // Description:
00302   // Check to see if the filename box input has multiple filenames.
00303   // Return 1 on success, 0 on failure.
00304   virtual int OpenMultipleFileNames(const char* inputnames);
00305 
00306 private:
00307 
00308   char *InitialFileName;
00309   char *LastPath;
00310   char *FileName;
00311 
00312   vtkKWFileBrowserDialog(const vtkKWFileBrowserDialog&); // Not implemented
00313   void operator=(const vtkKWFileBrowserDialog&); // Not implemented
00314 };
00315 #endif