KWWidgets
|
00001 /*========================================================================= 00002 00003 Copyright (c) 1998-2003 Kitware Inc. 469 Clifton Corporate Parkway, 00004 Clifton Park, NY, 12065, USA. 00005 00006 All rights reserved. No part of this software may be reproduced, distributed, 00007 or modified, in any form or by any means, without permission in writing from 00008 Kitware Inc. 00009 00010 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR 00011 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00012 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, 00013 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00014 00015 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, 00016 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 00017 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN 00018 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE 00019 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 00020 00021 =========================================================================*/ 00022 // .NAME vtkKWDirectoryPresetSelector - a directory preset selector. 00023 // .SECTION Description 00024 // This class is a widget that can be used to pick and list of set of directories. 00025 // presets. 00026 // .SECTION Thanks 00027 // This work is part of the National Alliance for Medical Image 00028 // Computing (NAMIC), funded by the National Institutes of Health 00029 // through the NIH Roadmap for Medical Research, Grant U54 EB005149. 00030 // Information on the National Centers for Biomedical Computing 00031 // can be obtained from http://nihroadmap.nih.gov/bioinformatics. 00032 // .SECTION See Also 00033 // vtkKWPresetSelector 00034 00035 #ifndef __vtkKWDirectoryPresetSelector_h 00036 #define __vtkKWDirectoryPresetSelector_h 00037 00038 #include "vtkKWPresetSelector.h" 00039 00040 class vtkKWFileBrowserDialog; 00041 00042 class KWWidgets_EXPORT vtkKWDirectoryPresetSelector : public vtkKWPresetSelector 00043 { 00044 public: 00045 static vtkKWDirectoryPresetSelector* New(); 00046 vtkTypeRevisionMacro(vtkKWDirectoryPresetSelector, vtkKWPresetSelector); 00047 void PrintSelf(ostream& os, vtkIndent indent); 00048 00049 // Description: 00050 // Set/Get the directory for a given preset. 00051 // Return 1 on success, 0 otherwise 00052 virtual int SetPresetDirectory(int id, const char *directory); 00053 virtual const char* GetPresetDirectory(int id); 00054 00055 // Description: 00056 // Query if the pool has a given directory preset 00057 virtual int HasPresetWithDirectory(const char *directory); 00058 00059 // Description: 00060 // Set/Get the directory enabled flag for a given preset. 00061 // Return 1 on success, 0 otherwise 00062 virtual int GetPresetDirectoryEnabled(int id); 00063 virtual int SetPresetDirectoryEnabled(int id, int flag); 00064 00065 // Description: 00066 // Set/Get the visibility of the directory enabled flag column. 00067 // Hidden by default. 00068 // No effect if called before Create(). 00069 virtual void SetDirectoryEnabledColumnVisibility(int); 00070 virtual int GetDirectoryEnabledColumnVisibility(); 00071 vtkBooleanMacro(DirectoryEnabledColumnVisibility, int); 00072 00073 // Description: 00074 // Set/Get the maximum length of the directory paths, in characters. 00075 // If set to 0 (default), do not shorten the paths automatically. 00076 virtual void SetMaximumDirectoryLength(int); 00077 vtkGetMacro(MaximumDirectoryLength, int); 00078 00079 // Description: 00080 // Set/Get if unique directories are enforced.. 00081 virtual void SetUniqueDirectories(int); 00082 vtkGetMacro(UniqueDirectories,int); 00083 vtkBooleanMacro(UniqueDirectories,int); 00084 00085 00086 // Description: 00087 // Add/retrieve the whole list of enabled directories from/to a string. Each 00088 // directory in this list is separated by a given delimiter (ex: ':' or ';'). 00089 // Presets are added in an "enabled" state (see GetPresetDirectoryEnabled) 00090 // to the end of the preset list. 00091 // Only presets that were enabled are retrieved and stored into a string 00092 // (note that said string will be allocated to the proper size with 'new' and 00093 // should therefore be de-allocated by the called with 'delete []'). 00094 // Return the number of enabled directories added, or retrieved. 00095 virtual int AddEnabledPresetDirectoriesFromDelimitedString( 00096 const char *from_str, const char from_delim); 00097 virtual int GetEnabledPresetDirectoriesToDelimitedString( 00098 char **to_str, const char to_delim); 00099 00100 // Description: 00101 // Add/retrieve the whole list of directories *and* their enabled flag 00102 // from/to a string representation. 00103 // Each item in this list is a directory and a boolean flag (0 or 1) 00104 // specifying if that directory is actually enabled or not in the UI. 00105 // Each element is separated by a given delimiter (ex: with '|' as delim, 00106 // "c:/temp|0|d:/foo/bar|1|c:/windows|1" refers to "c:/temp" as disabled and 00107 // both "d:/foo/bar" and "c:/windows" enabled; at this point, the string 00108 // returned by AddEnabledPresetDirectoriesFromDelimitedString would be 00109 // "d:/foo/bar;c:/windows" with a ';' delimiter). 00110 // Presets are added to the end of the preset list. 00111 // (note that said string will be allocated to the proper size with 'new' and 00112 // should therefore be de-allocated by the caller with 'delete []'). 00113 // Return the number of directories added, or retrieved. 00114 virtual int AddPresetDirectoriesFromDelimitedString( 00115 const char *from_str, const char from_delim); 00116 virtual int GetPresetDirectoriesToDelimitedString( 00117 char **to_str, const char to_delim); 00118 00119 // Description: 00120 // Static helper method. 00121 // This method extracts the list of enabled directories (to a string) from 00122 // the list of directories + flag (as a string, as it was returned by 00123 // GetPresetDirectoriesToDelimitedString for example). 00124 // Each list can be separated by different delimiters (ex: with '|' as 00125 // from_delim, "c:/temp|0|d:/foo/bar|1|c:/windows|1" as from_str will be 00126 // output to to_str as "d:/foo/bar;c:/windows" if to_delim is ';'). 00127 // (note that said string will be allocated to the proper size with 'new' and 00128 // should therefore be de-allocated by the caller with 'delete []'). 00129 // Return the number of enabled directories retrieved. 00130 static int GetEnabledPresetDirectoriesFromPresetDirectories( 00131 char **to_str, const char to_delim, 00132 const char *from_str, const char from_delim); 00133 00134 // Description: 00135 // Static helper method. 00136 // This method *updates* the list of directories + flag (to a string) from 00137 // a list of enabled directories (as a string, as it was returned by 00138 // Duplicated directories are not supported here. 00139 // Each list can be separated by different delimiters (ex: with ';' as 00140 // from_delim, "c:/temp;d:/bill" as from_str, '|' as to_delim and 00141 // "c:/temp|0|d:/foo/bar|0|c:/windows|1" as to_str, to_str will be updated 00142 // (i.e. potentially re-allocated) to a new string 00143 // "c:/temp|1|d:/foo/bar|0|d:/bill|1", where the already 00144 // existing "c:/temp" was updated/enabled, ""d:/foo/bar" was ignored, 00145 // "c:/windows" was removed (since considered not enabled) and "d:/bill" was 00146 // added. 00147 // (note that said string will be allocated to the proper size with 'new' and 00148 // should therefore be de-allocated by the caller with 'delete []'). 00149 // Return the number of directories updated (i.e. removed, updated or added). 00150 static int UpdatePresetDirectoriesFromEnabledPresetDirectories( 00151 char **update_str, const char update_delim, 00152 const char *from_str, const char from_delim); 00153 00154 // Description: 00155 // Some constants 00156 //BTX 00157 static const char *DirectoryColumnName; 00158 static const char *DirectoryEnabledColumnName; 00159 //ETX 00160 00161 // Description: 00162 // Callback invoked when the user starts editing a specific preset field 00163 // located at cell ('row', 'col'), which current contents is 'text'. 00164 // This method returns the value that is to become the initial 00165 // contents of the temporary embedded widget used for editing: most of the 00166 // time, this is the same value as 'text'. 00167 // The next step (validation) is handled by PresetCellEditEndCallback 00168 virtual const char* PresetCellEditStartCallback( 00169 int row, int col, const char *text); 00170 00171 // Description: 00172 // Callback invoked when the user ends editing a specific preset field 00173 // located at cell ('row', 'col'). 00174 // The main purpose of this method is to perform a final validation of 00175 // the edit window's contents 'text'. 00176 // This method returns the value that is to become the new contents 00177 // for that cell. 00178 // The next step (updating) is handled by PresetCellUpdateCallback 00179 virtual const char* PresetCellEditEndCallback( 00180 int row, int col, const char *text); 00181 00182 // Description: 00183 // Callback invoked when the user successfully updated the preset field 00184 // located at ('row', 'col') with the new contents 'text', as a result 00185 // of editing the corresponding cell interactively. 00186 virtual void PresetCellUpdatedCallback(int row, int col, const char *text); 00187 00188 // Description: 00189 // Callback invoked when the user press the "Add" button 00190 virtual int AddDirectoryCallback(); 00191 00192 // Description: 00193 // Access to sub-widgets. 00194 vtkGetObjectMacro(FileBrowserDialog, vtkKWFileBrowserDialog); 00195 00196 protected: 00197 vtkKWDirectoryPresetSelector(); 00198 ~vtkKWDirectoryPresetSelector(); 00199 00200 int MaximumDirectoryLength; 00201 int UniqueDirectories; 00202 00203 // Description: 00204 // Create the widget. 00205 virtual void CreateWidget(); 00206 00207 // Description: 00208 // Create the columns. 00209 // Subclasses should override this method to add their own columns and 00210 // display their own preset fields (do not forget to call the superclass 00211 // first). 00212 virtual void CreateColumns(); 00213 00214 // Description: 00215 // Update the preset row, i.e. add a row for that preset if it is not 00216 // displayed already, hide it if it does not match GroupFilter, and 00217 // update the table columns with the corresponding preset fields. 00218 // Subclass should override this method to display their own fields. 00219 // Return 1 on success, 0 if the row was not (or can not be) updated. 00220 // Subclasses should call the parent's UpdatePresetRow, and abort 00221 // if the result is not 1. 00222 virtual int UpdatePresetRow(int id); 00223 00224 // Description: 00225 // Get the index of a given column 00226 virtual int GetDirectoryColumnIndex(); 00227 virtual int GetDirectoryEnabledColumnIndex(); 00228 00229 vtkKWFileBrowserDialog *FileBrowserDialog; 00230 00231 private: 00232 00233 vtkKWDirectoryPresetSelector(const vtkKWDirectoryPresetSelector&); // Not implemented 00234 void operator=(const vtkKWDirectoryPresetSelector&); // Not implemented 00235 }; 00236 00237 #endif