00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWMenuButton.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 vtkKWMenuButton - an option menu widget 00015 // .SECTION Description 00016 // A widget that looks like a button but when pressed provides a list 00017 // of options that the user can select. 00018 00019 #ifndef __vtkKWMenuButton_h 00020 #define __vtkKWMenuButton_h 00021 00022 #include "vtkKWCoreWidget.h" 00023 00024 class vtkKWMenu; 00025 class vtkKWIcon; 00026 class vtkKWMenuButtonInternals; 00027 00028 class KWWidgets_EXPORT vtkKWMenuButton : public vtkKWCoreWidget 00029 { 00030 public: 00031 static vtkKWMenuButton* New(); 00032 vtkTypeRevisionMacro(vtkKWMenuButton,vtkKWCoreWidget); 00033 void PrintSelf(ostream& os, vtkIndent indent); 00034 00035 // Description: 00036 // Set/Get the current entry of this option menu. 00037 // This can be an image name if any entry in the menu uses an image 00038 // instead of a label. 00039 virtual const char *GetValue(); 00040 virtual void SetValue(const char *name); 00041 00042 // Description: 00043 // Set/Get the current entry to the previous or next entry. 00044 // and call the corresponding callback if any. 00045 // WARNING: this does not support multiple menu levels (i.e. cascade) 00046 virtual void NextValue(); 00047 virtual void PreviousValue(); 00048 00049 // Description: 00050 // Get the menu object 00051 vtkGetObjectMacro(Menu, vtkKWMenu); 00052 00053 // Description 00054 // Set the indicator On/Off. To be called after creation. 00055 virtual void SetIndicatorVisibility(int ind); 00056 virtual int GetIndicatorVisibility(); 00057 vtkBooleanMacro(IndicatorVisibility, int); 00058 00059 // Description: 00060 // Set the button width (in chars if text, in pixels if image). 00061 virtual void SetWidth(int width); 00062 virtual int GetWidth(); 00063 00064 // Description: 00065 // Set/Get the maximum width *in characters* of the option menu label. 00066 // This does not modify the internal value, this is only meant for display 00067 // purposes: the option menu button can therefore be automatically 00068 // shrinked, while the menu associated to it will display all entries 00069 // correctly. 00070 // Set width to 0 (default) to prevent auto-cropping. 00071 virtual void SetMaximumLabelWidth(int); 00072 vtkGetMacro(MaximumLabelWidth, int); 00073 00074 // Description: 00075 // Adjust the label width automatically to fit in the menu button. 00076 // This does not modify the internal value, this is only meant for display 00077 // purposes: the option menu button can therefore be automatically 00078 // shrinked, while the menu associated to it will display all entries 00079 // correctly. Overrides MaximumLabelWidth. 00080 virtual void SetAdjustLabelWidthToWidgetSize(int); 00081 vtkGetMacro(AdjustLabelWidthToWidgetSize, int); 00082 vtkBooleanMacro(AdjustLabelWidthToWidgetSize, int); 00083 00084 // Description: 00085 // Set/Get the background color of the widget. 00086 virtual void GetBackgroundColor(double *r, double *g, double *b); 00087 virtual double* GetBackgroundColor(); 00088 virtual void SetBackgroundColor(double r, double g, double b); 00089 virtual void SetBackgroundColor(double rgb[3]) 00090 { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); }; 00091 00092 // Description: 00093 // Set/Get the foreground color of the widget. 00094 virtual void GetForegroundColor(double *r, double *g, double *b); 00095 virtual double* GetForegroundColor(); 00096 virtual void SetForegroundColor(double r, double g, double b); 00097 virtual void SetForegroundColor(double rgb[3]) 00098 { this->SetForegroundColor(rgb[0], rgb[1], rgb[2]); }; 00099 00100 // Description: 00101 // Set/Get the highlight thickness, a non-negative value indicating the 00102 // width of the highlight rectangle to draw around the outside of the 00103 // widget when it has the input focus. 00104 virtual void SetHighlightThickness(int); 00105 virtual int GetHighlightThickness(); 00106 00107 // Description: 00108 // Set/Get the active background color of the widget. An element 00109 // (a widget or portion of a widget) is active if the mouse cursor is 00110 // positioned over the element and pressing a mouse button will cause some 00111 // action to occur. 00112 virtual void GetActiveBackgroundColor(double *r, double *g, double *b); 00113 virtual double* GetActiveBackgroundColor(); 00114 virtual void SetActiveBackgroundColor(double r, double g, double b); 00115 virtual void SetActiveBackgroundColor(double rgb[3]) 00116 { this->SetActiveBackgroundColor(rgb[0], rgb[1], rgb[2]); }; 00117 00118 // Description: 00119 // Set/Get the active foreground color of the widget. An element 00120 // (a widget or portion of a widget) is active if the mouse cursor is 00121 // positioned over the element and pressing a mouse button will cause some 00122 // action to occur. 00123 virtual void GetActiveForegroundColor(double *r, double *g, double *b); 00124 virtual double* GetActiveForegroundColor(); 00125 virtual void SetActiveForegroundColor(double r, double g, double b); 00126 virtual void SetActiveForegroundColor(double rgb[3]) 00127 { this->SetActiveForegroundColor(rgb[0], rgb[1], rgb[2]); }; 00128 00129 // Description: 00130 // Set/Get the foreground color of the widget when it is disabled. 00131 virtual void GetDisabledForegroundColor(double *r, double *g, double *b); 00132 virtual double* GetDisabledForegroundColor(); 00133 virtual void SetDisabledForegroundColor(double r, double g, double b); 00134 virtual void SetDisabledForegroundColor(double rgb[3]) 00135 { this->SetDisabledForegroundColor(rgb[0], rgb[1], rgb[2]); }; 00136 00137 // Description: 00138 // Set/Get the border width, a non-negative value indicating the width of 00139 // the 3-D border to draw around the outside of the widget (if such a border 00140 // is being drawn; the Relief option typically determines this). 00141 virtual void SetBorderWidth(int); 00142 virtual int GetBorderWidth(); 00143 00144 // Description: 00145 // Set/Get the 3-D effect desired for the widget. 00146 // The value indicates how the interior of the widget should appear 00147 // relative to its exterior. 00148 // Valid constants can be found in vtkKWOptions::ReliefType. 00149 virtual void SetRelief(int); 00150 virtual int GetRelief(); 00151 virtual void SetReliefToRaised(); 00152 virtual void SetReliefToSunken(); 00153 virtual void SetReliefToFlat(); 00154 virtual void SetReliefToRidge(); 00155 virtual void SetReliefToSolid(); 00156 virtual void SetReliefToGroove(); 00157 00158 // Description: 00159 // Specifies the font to use when drawing text inside the widget. 00160 // You can use predefined font names (e.g. 'system'), or you can specify 00161 // a set of font attributes with a platform-independent name, for example, 00162 // 'times 12 bold'. In this example, the font is specified with a three 00163 // element list: the first element is the font family, the second is the 00164 // size, the third is a list of style parameters (normal, bold, roman, 00165 // italic, underline, overstrike). Example: 'times 12 {bold italic}'. 00166 // The Times, Courier and Helvetica font families are guaranteed to exist 00167 // and will be matched to the corresponding (closest) font on your system. 00168 // If you are familiar with the X font names specification, you can also 00169 // describe the font that way (say, '*times-medium-r-*-*-12*'). 00170 virtual void SetFont(const char *font); 00171 virtual const char* GetFont(); 00172 00173 // Description: 00174 // Set/Get the padding that will be applied around each widget (in pixels). 00175 // Specifies a non-negative value indicating how much extra space to request 00176 // for the widget in the X and Y-direction. When computing how large a 00177 // window it needs, the widget will add this amount to the width it would 00178 // normally need (as determined by the width of the things displayed 00179 // in the widget); if the geometry manager can satisfy this request, the 00180 // widget will end up with extra internal space around what it displays 00181 // inside. 00182 virtual void SetPadX(int); 00183 virtual int GetPadX(); 00184 virtual void SetPadY(int); 00185 virtual int GetPadY(); 00186 00187 // Description: 00188 // Set/Get the anchoring. 00189 // Specifies how the information in a widget (e.g. text or a bitmap) is to 00190 // be displayed in the widget. 00191 // Valid constants can be found in vtkKWOptions::AnchorType. 00192 virtual void SetAnchor(int); 00193 virtual int GetAnchor(); 00194 virtual void SetAnchorToNorth(); 00195 virtual void SetAnchorToNorthEast(); 00196 virtual void SetAnchorToEast(); 00197 virtual void SetAnchorToSouthEast(); 00198 virtual void SetAnchorToSouth(); 00199 virtual void SetAnchorToSouthWest(); 00200 virtual void SetAnchorToWest(); 00201 virtual void SetAnchorToNorthWest(); 00202 virtual void SetAnchorToCenter(); 00203 00204 // Description: 00205 // Specifies an image to display in the widget. Typically, if the image 00206 // is specified then it overrides other options that specify a bitmap or 00207 // textual value to display in the widget. Invoke vtkKWWidget's 00208 // SetConfigurationOption("-image", imagename) to use a specific 00209 // pre-existing Tk image, or call one of the following functions. 00210 // The SetImageToPredefinedIcon method accepts an index to one of the 00211 // predefined icon listed in vtkKWIcon. 00212 // The SetImageToPixels method sets the image using pixel data. It expects 00213 // a pointer to the pixels and the structure of the image, i.e. its width, 00214 // height and the pixel_size (how many bytes per pixel, say 3 for RGB, or 00215 // 1 for grayscale). If buffer_length = 0, it is computed automatically 00216 // from the previous parameters. If it is not, it will most likely indicate 00217 // that the buffer has been encoded using base64 and/or zlib. 00218 // If pixel_size > 3 (i.e. RGBA), the image is blend the with background 00219 // color of the widget. 00220 // Check the SetCompoundMode method if you want to display both the 00221 // image and the label at the same time. 00222 virtual void SetImageToIcon(vtkKWIcon *icon); 00223 virtual void SetImageToPredefinedIcon(int icon_index); 00224 virtual void SetImageToPixels( 00225 const unsigned char *pixels, int width, int height, int pixel_size, 00226 unsigned long buffer_length = 0); 00227 00228 // Description: 00229 // Specifies if the widget should display text and bitmaps/images at the 00230 // same time, and if so, where the bitmap/image should be placed relative 00231 // to the text. 00232 // Valid constants can be found in vtkKWOptions::CompoundModeType. 00233 // The (default) value CompoundModeNone specifies that the bitmap or image 00234 // should (if defined) be displayed instead of the text. 00235 virtual void SetCompoundMode(int); 00236 virtual int GetCompoundMode(); 00237 virtual void SetCompoundModeToNone(); 00238 virtual void SetCompoundModeToLeft(); 00239 virtual void SetCompoundModeToCenter(); 00240 virtual void SetCompoundModeToRight(); 00241 virtual void SetCompoundModeToTop(); 00242 virtual void SetCompoundModeToBottom(); 00243 00244 // Description: 00245 // Update the "enable" state of the object and its internal parts. 00246 // Depending on different Ivars (this->Enabled, the application's 00247 // Limited Edition Mode, etc.), the "enable" state of the object is updated 00248 // and propagated to its internal parts/subwidgets. This will, for example, 00249 // enable/disable parts of the widget UI, enable/disable the visibility 00250 // of 3D widgets, etc. 00251 virtual void UpdateEnableState(); 00252 00253 // Description: 00254 // Callbacks. Internal, do not use. 00255 virtual void TracedVariableChangedCallback( 00256 const char *, const char *, const char *); 00257 virtual void ConfigureCallback(); 00258 virtual void UpdateMenuButtonLabelCallback(); 00259 00260 // Description: 00261 // Add all the default observers needed by that object, or remove 00262 // all the observers that were added through AddCallbackCommandObserver. 00263 // Subclasses can override these methods to add/remove their own default 00264 // observers, but should call the superclass too. 00265 virtual void AddCallbackCommandObservers(); 00266 virtual void RemoveCallbackCommandObservers(); 00267 00268 protected: 00269 vtkKWMenuButton(); 00270 ~vtkKWMenuButton(); 00271 00272 // Description: 00273 // Create the widget. 00274 virtual void CreateWidget(); 00275 00276 vtkGetStringMacro(CurrentValue); 00277 vtkSetStringMacro(CurrentValue); 00278 00279 char *CurrentValue; 00280 vtkKWMenu *Menu; 00281 int MaximumLabelWidth; 00282 int AdjustLabelWidthToWidgetSize; 00283 00284 virtual void UpdateMenuButtonLabel(); 00285 virtual const char* UpdateMenuButtonLabelFromMenu( 00286 const char *varname, const char *value, vtkKWMenu *menu); 00287 virtual void ScheduleUpdateMenuButtonLabel(); 00288 00289 // Description: 00290 // Processes the events that are passed through CallbackCommand (or others). 00291 // Subclasses can oberride this method to process their own events, but 00292 // should call the superclass too. 00293 virtual void ProcessCallbackCommandEvents( 00294 vtkObject *caller, unsigned long event, void *calldata); 00295 00296 // Description: 00297 // Update bindings 00298 virtual void UpdateBindings(); 00299 00300 // PIMPL Encapsulation for STL containers 00301 //BTX 00302 vtkKWMenuButtonInternals *Internals; 00303 //ETX 00304 00305 private: 00306 vtkKWMenuButton(const vtkKWMenuButton&); // Not implemented 00307 void operator=(const vtkKWMenuButton&); // Not implemented 00308 }; 00309 00310 #endif 00311 00312