KWWidgets
vtkKWMenuButton.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWMenuButton.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 vtkKWMenuButton - an option menu widget
15 // .SECTION Description
16 // A widget that looks like a button but when pressed provides a list
17 // of options that the user can select.
18 
19 #ifndef __vtkKWMenuButton_h
20 #define __vtkKWMenuButton_h
21 
22 #include "vtkKWCoreWidget.h"
23 
24 class vtkKWMenu;
25 class vtkKWIcon;
26 class vtkKWMenuButtonInternals;
27 
29 {
30 public:
31  static vtkKWMenuButton* New();
32  vtkTypeRevisionMacro(vtkKWMenuButton,vtkKWCoreWidget);
33  void PrintSelf(ostream& os, vtkIndent indent);
34 
35  // Description:
36  // Set/Get the current entry of this option menu.
37  // This can be an image name if any entry in the menu uses an image
38  // instead of a label.
39  virtual const char *GetValue();
40  virtual void SetValue(const char *name);
41 
42  // Description:
43  // Set/Get the current entry to the previous or next entry.
44  // and call the corresponding callback if any.
45  // WARNING: this does not support multiple menu levels (i.e. cascade)
46  virtual void NextValue();
47  virtual void PreviousValue();
48 
49  // Description:
50  // Get the menu object
51  vtkGetObjectMacro(Menu, vtkKWMenu);
52 
53  // Description
54  // Set the indicator On/Off. To be called after creation.
55  virtual void SetIndicatorVisibility(int ind);
56  virtual int GetIndicatorVisibility();
57  vtkBooleanMacro(IndicatorVisibility, int);
58 
59  // Description:
60  // Set the button width (in chars if text, in pixels if image).
61  virtual void SetWidth(int width);
62  virtual int GetWidth();
63 
64  // Description:
65  // Set/Get the maximum width *in characters* of the option menu label.
66  // This does not modify the internal value, this is only meant for display
67  // purposes: the option menu button can therefore be automatically
68  // shrinked, while the menu associated to it will display all entries
69  // correctly.
70  // Set width to 0 (default) to prevent auto-cropping.
71  virtual void SetMaximumLabelWidth(int);
72  vtkGetMacro(MaximumLabelWidth, int);
73 
74  // Description:
75  // Adjust the label width automatically to fit in the menu button.
76  // This does not modify the internal value, this is only meant for display
77  // purposes: the option menu button can therefore be automatically
78  // shrinked, while the menu associated to it will display all entries
79  // correctly. Overrides MaximumLabelWidth.
80  virtual void SetAdjustLabelWidthToWidgetSize(int);
81  vtkGetMacro(AdjustLabelWidthToWidgetSize, int);
82  vtkBooleanMacro(AdjustLabelWidthToWidgetSize, int);
83 
84  // Description:
85  // Set/Get the background color of the widget.
86  virtual void GetBackgroundColor(double *r, double *g, double *b);
87  virtual double* GetBackgroundColor();
88  virtual void SetBackgroundColor(double r, double g, double b);
89  virtual void SetBackgroundColor(double rgb[3])
90  { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); };
91 
92  // Description:
93  // Set/Get the foreground color of the widget.
94  virtual void GetForegroundColor(double *r, double *g, double *b);
95  virtual double* GetForegroundColor();
96  virtual void SetForegroundColor(double r, double g, double b);
97  virtual void SetForegroundColor(double rgb[3])
98  { this->SetForegroundColor(rgb[0], rgb[1], rgb[2]); };
99 
100  // Description:
101  // Set/Get the highlight thickness, a non-negative value indicating the
102  // width of the highlight rectangle to draw around the outside of the
103  // widget when it has the input focus.
104  virtual void SetHighlightThickness(int);
105  virtual int GetHighlightThickness();
106 
107  // Description:
108  // Set/Get the active background color of the widget. An element
109  // (a widget or portion of a widget) is active if the mouse cursor is
110  // positioned over the element and pressing a mouse button will cause some
111  // action to occur.
112  virtual void GetActiveBackgroundColor(double *r, double *g, double *b);
113  virtual double* GetActiveBackgroundColor();
114  virtual void SetActiveBackgroundColor(double r, double g, double b);
115  virtual void SetActiveBackgroundColor(double rgb[3])
116  { this->SetActiveBackgroundColor(rgb[0], rgb[1], rgb[2]); };
117 
118  // Description:
119  // Set/Get the active foreground color of the widget. An element
120  // (a widget or portion of a widget) is active if the mouse cursor is
121  // positioned over the element and pressing a mouse button will cause some
122  // action to occur.
123  virtual void GetActiveForegroundColor(double *r, double *g, double *b);
124  virtual double* GetActiveForegroundColor();
125  virtual void SetActiveForegroundColor(double r, double g, double b);
126  virtual void SetActiveForegroundColor(double rgb[3])
127  { this->SetActiveForegroundColor(rgb[0], rgb[1], rgb[2]); };
128 
129  // Description:
130  // Set/Get the foreground color of the widget when it is disabled.
131  virtual void GetDisabledForegroundColor(double *r, double *g, double *b);
132  virtual double* GetDisabledForegroundColor();
133  virtual void SetDisabledForegroundColor(double r, double g, double b);
134  virtual void SetDisabledForegroundColor(double rgb[3])
135  { this->SetDisabledForegroundColor(rgb[0], rgb[1], rgb[2]); };
136 
137  // Description:
138  // Set/Get the border width, a non-negative value indicating the width of
139  // the 3-D border to draw around the outside of the widget (if such a border
140  // is being drawn; the Relief option typically determines this).
141  virtual void SetBorderWidth(int);
142  virtual int GetBorderWidth();
143 
144  // Description:
145  // Set/Get the 3-D effect desired for the widget.
146  // The value indicates how the interior of the widget should appear
147  // relative to its exterior.
148  // Valid constants can be found in vtkKWOptions::ReliefType.
149  virtual void SetRelief(int);
150  virtual int GetRelief();
151  virtual void SetReliefToRaised();
152  virtual void SetReliefToSunken();
153  virtual void SetReliefToFlat();
154  virtual void SetReliefToRidge();
155  virtual void SetReliefToSolid();
156  virtual void SetReliefToGroove();
157 
158  // Description:
159  // Specifies the font to use when drawing text inside the widget.
160  // You can use predefined font names (e.g. 'system'), or you can specify
161  // a set of font attributes with a platform-independent name, for example,
162  // 'times 12 bold'. In this example, the font is specified with a three
163  // element list: the first element is the font family, the second is the
164  // size, the third is a list of style parameters (normal, bold, roman,
165  // italic, underline, overstrike). Example: 'times 12 {bold italic}'.
166  // The Times, Courier and Helvetica font families are guaranteed to exist
167  // and will be matched to the corresponding (closest) font on your system.
168  // If you are familiar with the X font names specification, you can also
169  // describe the font that way (say, '*times-medium-r-*-*-12*').
170  virtual void SetFont(const char *font);
171  virtual const char* GetFont();
172 
173  // Description:
174  // Set/Get the padding that will be applied around each widget (in pixels).
175  // Specifies a non-negative value indicating how much extra space to request
176  // for the widget in the X and Y-direction. When computing how large a
177  // window it needs, the widget will add this amount to the width it would
178  // normally need (as determined by the width of the things displayed
179  // in the widget); if the geometry manager can satisfy this request, the
180  // widget will end up with extra internal space around what it displays
181  // inside.
182  virtual void SetPadX(int);
183  virtual int GetPadX();
184  virtual void SetPadY(int);
185  virtual int GetPadY();
186 
187  // Description:
188  // Set/Get the anchoring.
189  // Specifies how the information in a widget (e.g. text or a bitmap) is to
190  // be displayed in the widget.
191  // Valid constants can be found in vtkKWOptions::AnchorType.
192  virtual void SetAnchor(int);
193  virtual int GetAnchor();
194  virtual void SetAnchorToNorth();
195  virtual void SetAnchorToNorthEast();
196  virtual void SetAnchorToEast();
197  virtual void SetAnchorToSouthEast();
198  virtual void SetAnchorToSouth();
199  virtual void SetAnchorToSouthWest();
200  virtual void SetAnchorToWest();
201  virtual void SetAnchorToNorthWest();
202  virtual void SetAnchorToCenter();
203 
204  // Description:
205  // Specifies an image to display in the widget. Typically, if the image
206  // is specified then it overrides other options that specify a bitmap or
207  // textual value to display in the widget. Invoke vtkKWWidget's
208  // SetConfigurationOption("-image", imagename) to use a specific
209  // pre-existing Tk image, or call one of the following functions.
210  // The SetImageToPredefinedIcon method accepts an index to one of the
211  // predefined icon listed in vtkKWIcon.
212  // The SetImageToPixels method sets the image using pixel data. It expects
213  // a pointer to the pixels and the structure of the image, i.e. its width,
214  // height and the pixel_size (how many bytes per pixel, say 3 for RGB, or
215  // 1 for grayscale). If buffer_length = 0, it is computed automatically
216  // from the previous parameters. If it is not, it will most likely indicate
217  // that the buffer has been encoded using base64 and/or zlib.
218  // If pixel_size > 3 (i.e. RGBA), the image is blend the with background
219  // color of the widget.
220  // Check the SetCompoundMode method if you want to display both the
221  // image and the label at the same time.
222  virtual void SetImageToIcon(vtkKWIcon *icon);
223  virtual void SetImageToPredefinedIcon(int icon_index);
224  virtual void SetImageToPixels(
225  const unsigned char *pixels, int width, int height, int pixel_size,
226  unsigned long buffer_length = 0);
227 
228  // Description:
229  // Specifies if the widget should display text and bitmaps/images at the
230  // same time, and if so, where the bitmap/image should be placed relative
231  // to the text.
232  // Valid constants can be found in vtkKWOptions::CompoundModeType.
233  // The (default) value CompoundModeNone specifies that the bitmap or image
234  // should (if defined) be displayed instead of the text.
235  virtual void SetCompoundMode(int);
236  virtual int GetCompoundMode();
237  virtual void SetCompoundModeToNone();
238  virtual void SetCompoundModeToLeft();
239  virtual void SetCompoundModeToCenter();
240  virtual void SetCompoundModeToRight();
241  virtual void SetCompoundModeToTop();
242  virtual void SetCompoundModeToBottom();
243 
244  // Description:
245  // Update the "enable" state of the object and its internal parts.
246  // Depending on different Ivars (this->Enabled, the application's
247  // Limited Edition Mode, etc.), the "enable" state of the object is updated
248  // and propagated to its internal parts/subwidgets. This will, for example,
249  // enable/disable parts of the widget UI, enable/disable the visibility
250  // of 3D widgets, etc.
251  virtual void UpdateEnableState();
252 
253  // Description:
254  // Callbacks. Internal, do not use.
255  virtual void TracedVariableChangedCallback(
256  const char *, const char *, const char *);
257  virtual void ConfigureCallback();
258  virtual void UpdateMenuButtonLabelCallback();
259 
260  // Description:
261  // Add all the default observers needed by that object, or remove
262  // all the observers that were added through AddCallbackCommandObserver.
263  // Subclasses can override these methods to add/remove their own default
264  // observers, but should call the superclass too.
265  virtual void AddCallbackCommandObservers();
266  virtual void RemoveCallbackCommandObservers();
267 
268 protected:
269  vtkKWMenuButton();
270  ~vtkKWMenuButton();
271 
272  // Description:
273  // Create the widget.
274  virtual void CreateWidget();
275 
276  vtkGetStringMacro(CurrentValue);
277  vtkSetStringMacro(CurrentValue);
278 
279  char *CurrentValue;
280  vtkKWMenu *Menu;
281  int MaximumLabelWidth;
282  int AdjustLabelWidthToWidgetSize;
283 
284  virtual void UpdateMenuButtonLabel();
285  virtual const char* UpdateMenuButtonLabelFromMenu(
286  const char *varname, const char *value, vtkKWMenu *menu);
287  virtual void ScheduleUpdateMenuButtonLabel();
288 
289  // Description:
290  // Processes the events that are passed through CallbackCommand (or others).
291  // Subclasses can oberride this method to process their own events, but
292  // should call the superclass too.
293  virtual void ProcessCallbackCommandEvents(
294  vtkObject *caller, unsigned long event, void *calldata);
295 
296  // Description:
297  // Update bindings
298  virtual void UpdateBindings();
299 
300  // PIMPL Encapsulation for STL containers
301  //BTX
302  vtkKWMenuButtonInternals *Internals;
303  //ETX
304 
305 private:
306  vtkKWMenuButton(const vtkKWMenuButton&); // Not implemented
307  void operator=(const vtkKWMenuButton&); // Not implemented
308 };
309 
310 #endif
311 
312