KWWidgets
vtkKWCheckButton.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWCheckButton.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 vtkKWCheckButton - check button widget
15 // .SECTION Description
16 // A simple widget that represents a check button. It can be modified
17 // and queried using the GetSelectedState and SetSelectedState methods.
18 
19 #ifndef __vtkKWCheckButton_h
20 #define __vtkKWCheckButton_h
21 
22 #include "vtkKWCoreWidget.h"
23 
24 class vtkKWIcon;
25 
27 {
28 public:
29  static vtkKWCheckButton* New();
30  vtkTypeRevisionMacro(vtkKWCheckButton,vtkKWCoreWidget);
31  void PrintSelf(ostream& os, vtkIndent indent);
32 
33  // Description:
34  // Set/Get/Toggle the selected state of the check button 0 = off 1 = on
35  virtual void SetSelectedState(int );
36  virtual int GetSelectedState();
37  vtkBooleanMacro(SelectedState, int);
38  virtual void ToggleSelectedState();
39  virtual void Select() { this->SetSelectedState(1); };
40  virtual void Deselect() { this->SetSelectedState(0); };
41 
42  // Description:
43  // Tell the widget whether it should use an indicator (check box)
44  virtual void SetIndicatorVisibility(int ind);
45  vtkGetMacro(IndicatorVisibility, int);
46  vtkBooleanMacro(IndicatorVisibility, int);
47 
48  // Description:
49  // Set the text.
50  virtual void SetText(const char* txt);
51  virtual const char* GetText();
52 
53  // Description:
54  // Set the variable name.
55  // Important: note that this will *not* copy over the previous variable
56  // value to the new one.
57  vtkGetStringMacro(VariableName);
58  virtual void SetVariableName(const char *);
59 
60  // Description:
61  // Specifies a command to associate with the widget. This command is
62  // typically invoked when the button is selected or deselected.
63  // The 'object' argument is the object that will have the method called on
64  // it. The 'method' argument is the name of the method to be called and any
65  // arguments in string form. If the object is NULL, the method is still
66  // evaluated as a simple command.
67  // The following parameters are also passed to the command:
68  // - current selected state: int
69  virtual void SetCommand(vtkObject *object, const char *method);
70 
71  // Description:
72  // Events. The SelectedStateChangedEvent is triggered when the button
73  // is selected or deselected.
74  // The following parameters are also passed as client data:
75  // - the current selected state: int
76  //BTX
77  enum
78  {
79  SelectedStateChangedEvent = 10000
80  };
81  //ETX
82 
83  // Description:
84  // Set/Get the background color of the widget.
85  virtual void GetBackgroundColor(double *r, double *g, double *b);
86  virtual double* GetBackgroundColor();
87  virtual void SetBackgroundColor(double r, double g, double b);
88  virtual void SetBackgroundColor(double rgb[3])
89  { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); };
90 
91  // Description:
92  // Set/Get the foreground color of the widget.
93  virtual void GetForegroundColor(double *r, double *g, double *b);
94  virtual double* GetForegroundColor();
95  virtual void SetForegroundColor(double r, double g, double b);
96  virtual void SetForegroundColor(double rgb[3])
97  { this->SetForegroundColor(rgb[0], rgb[1], rgb[2]); };
98 
99  // Description:
100  // Set/Get the highlight thickness, a non-negative value indicating the
101  // width of the highlight rectangle to draw around the outside of the
102  // widget when it has the input focus.
103  virtual void SetHighlightThickness(int);
104  virtual int GetHighlightThickness();
105 
106  // Description:
107  // Set/Get the active background color of the widget. An element
108  // (a widget or portion of a widget) is active if the mouse cursor is
109  // positioned over the element and pressing a mouse button will cause some
110  // action to occur.
111  virtual void GetActiveBackgroundColor(double *r, double *g, double *b);
112  virtual double* GetActiveBackgroundColor();
113  virtual void SetActiveBackgroundColor(double r, double g, double b);
114  virtual void SetActiveBackgroundColor(double rgb[3])
115  { this->SetActiveBackgroundColor(rgb[0], rgb[1], rgb[2]); };
116 
117  // Description:
118  // Set/Get the active foreground color of the widget. An element
119  // (a widget or portion of a widget) is active if the mouse cursor is
120  // positioned over the element and pressing a mouse button will cause some
121  // action to occur.
122  virtual void GetActiveForegroundColor(double *r, double *g, double *b);
123  virtual double* GetActiveForegroundColor();
124  virtual void SetActiveForegroundColor(double r, double g, double b);
125  virtual void SetActiveForegroundColor(double rgb[3])
126  { this->SetActiveForegroundColor(rgb[0], rgb[1], rgb[2]); };
127 
128  // Description:
129  // Set/Get the foreground color of the widget when it is disabled.
130  virtual void GetDisabledForegroundColor(double *r, double *g, double *b);
131  virtual double* GetDisabledForegroundColor();
132  virtual void SetDisabledForegroundColor(double r, double g, double b);
133  virtual void SetDisabledForegroundColor(double rgb[3])
134  { this->SetDisabledForegroundColor(rgb[0], rgb[1], rgb[2]); };
135 
136  // Description:
137  // Set/Get the border width, a non-negative value indicating the width of
138  // the 3-D border to draw around the outside of the widget (if such a border
139  // is being drawn; the Relief option typically determines this).
140  virtual void SetBorderWidth(int);
141  virtual int GetBorderWidth();
142 
143  // Description:
144  // Set/Get the 3-D effect desired for the widget.
145  // The value indicates how the interior of the widget should appear
146  // relative to its exterior.
147  // Valid constants can be found in vtkKWOptions::ReliefType.
148  virtual void SetRelief(int);
149  virtual int GetRelief();
150  virtual void SetReliefToRaised();
151  virtual void SetReliefToSunken();
152  virtual void SetReliefToFlat();
153  virtual void SetReliefToRidge();
154  virtual void SetReliefToSolid();
155  virtual void SetReliefToGroove();
156 
157  // Description:
158  // Set/Get the padding that will be applied around each widget (in pixels).
159  // Specifies a non-negative value indicating how much extra space to request
160  // for the widget in the X and Y-direction. When computing how large a
161  // window it needs, the widget will add this amount to the width it would
162  // normally need (as determined by the width of the things displayed
163  // in the widget); if the geometry manager can satisfy this request, the
164  // widget will end up with extra internal space around what it displays
165  // inside.
166  virtual void SetPadX(int);
167  virtual int GetPadX();
168  virtual void SetPadY(int);
169  virtual int GetPadY();
170 
171  // Description:
172  // Set/Get the anchoring.
173  // Specifies how the information in a widget (e.g. text or a bitmap) is to
174  // be displayed in the widget.
175  // Valid constants can be found in vtkKWOptions::AnchorType.
176  virtual void SetAnchor(int);
177  virtual int GetAnchor();
178  virtual void SetAnchorToNorth();
179  virtual void SetAnchorToNorthEast();
180  virtual void SetAnchorToEast();
181  virtual void SetAnchorToSouthEast();
182  virtual void SetAnchorToSouth();
183  virtual void SetAnchorToSouthWest();
184  virtual void SetAnchorToWest();
185  virtual void SetAnchorToNorthWest();
186  virtual void SetAnchorToCenter();
187 
188  // Description:
189  // Set/Get the 3-D effect desired for the widget.
190  // Specifies the relief for the button when the indicator is not drawn
191  // (i.e. IndicatorVisibility is Off) and the button is not selected.
192  // The default value is Raised. By setting this option to Flat and setting
193  // IndicatorVisibility to Off and OverRelief to Raised or Flat, the effect
194  // is achieved of having a flat button that raises on mouse-over and which
195  // is depressed when activated. This is the behavior typically exhibited by
196  // the Bold, Italic, and Underline checkbuttons on the toolbar of a
197  // word-processor, for example.
198  // Valid constants can be found in vtkKWOptions::ReliefType.
199  virtual void SetOffRelief(int);
200  virtual int GetOffRelief();
201  virtual void SetOffReliefToRaised();
202  virtual void SetOffReliefToSunken();
203  virtual void SetOffReliefToFlat();
204  virtual void SetOffReliefToRidge();
205  virtual void SetOffReliefToSolid();
206  virtual void SetOffReliefToGroove();
207 
208  // Description:
209  // Set/Get the 3-D effect desired for the widget.
210  // Specifies an alternative relief for the button, to be used when the mouse
211  // cursor is over the widget. This option can be used to make toolbar
212  // buttons, by configuring SetRelief to Flat and OverRelief to Raised.
213  // Valid constants can be found in vtkKWOptions::ReliefType.
214  // If the value of this option is None, then no alternative relief is used
215  // when the mouse cursor is over the checkbutton.
216  virtual void SetOverRelief(int);
217  virtual int GetOverRelief();
218  virtual void SetOverReliefToRaised();
219  virtual void SetOverReliefToSunken();
220  virtual void SetOverReliefToFlat();
221  virtual void SetOverReliefToRidge();
222  virtual void SetOverReliefToSolid();
223  virtual void SetOverReliefToGroove();
224  virtual void SetOverReliefToNone();
225 
226  // Description:
227  // Specifies the font to use when drawing text inside the widget.
228  // You can use predefined font names (e.g. 'system'), or you can specify
229  // a set of font attributes with a platform-independent name, for example,
230  // 'times 12 bold'. In this example, the font is specified with a three
231  // element list: the first element is the font family, the second is the
232  // size, the third is a list of style parameters (normal, bold, roman,
233  // italic, underline, overstrike). Example: 'times 12 {bold italic}'.
234  // The Times, Courier and Helvetica font families are guaranteed to exist
235  // and will be matched to the corresponding (closest) font on your system.
236  // If you are familiar with the X font names specification, you can also
237  // describe the font that way (say, '*times-medium-r-*-*-12*').
238  virtual void SetFont(const char *font);
239  virtual const char* GetFont();
240 
241  // Description:
242  // Specifies an image to display in the widget. Typically, if the image
243  // is specified then it overrides other options that specify a bitmap or
244  // textual value to display in the widget. Invoke vtkKWWidget's
245  // SetConfigurationOption("-image", imagename) to use a specific
246  // pre-existing Tk image, or call one of the following functions:
247  // The SetImageToPredefinedIcon method accepts an index to one of the
248  // predefined icon listed in vtkKWIcon.
249  // The SetImageToPixels method sets the image using pixel data. It expects
250  // a pointer to the pixels and the structure of the image, i.e. its width,
251  // height and the pixel_size (how many bytes per pixel, say 3 for RGB, or
252  // 1 for grayscale). If buffer_length = 0, it is computed automatically
253  // from the previous parameters. If it is not, it will most likely indicate
254  // that the buffer has been encoded using base64 and/or zlib.
255  // If pixel_size > 3 (i.e. RGBA), the image is blend the with background
256  // color of the widget.
257  // Check the SetCompoundMode method if you want to display both the
258  // image and the label at the same time.
259  virtual void SetImageToIcon(vtkKWIcon *icon);
260  virtual void SetImageToPredefinedIcon(int icon_index);
261  virtual void SetImageToPixels(
262  const unsigned char *pixels, int width, int height, int pixel_size,
263  unsigned long buffer_length = 0);
264 
265  // Description:
266  // Specifies an image to display in the widget when the button is selected.
267  // This option is ignored unless an image has been set for the unselected
268  // state of the button already (see SetImageToIcon).
269  // Typically, if the image is specified then it overrides other options that
270  // specify a bitmap or textual value to display in the widget.
271  // Invoke vtkKWWidget's SetConfigurationOption("-selectimage", imagename)
272  // to use a specific pre-existing Tk image, or call one of the following
273  // functions:
274  // The SetSelectImageToPredefinedIcon method accepts an index to one of the
275  // predefined icon listed in vtkKWIcon.
276  // The SetSelectImageToPixels method sets the image using pixel data. It
277  // expects a pointer to the pixels and the structure of the image, i.e. its
278  // width, height and the pixel_size (how many bytes per pixel, say 3 for RGB,
279  // or 1 for grayscale). If buffer_length = 0, it is computed automatically
280  // from the previous parameters. If it is not, it will most likely indicate
281  // that the buffer has been encoded using base64 and/or zlib.
282  // If pixel_size > 3 (i.e. RGBA), the image is blend the with background
283  // color of the widget.
284  // Check the SetCompoundMode method if you want to display both the
285  // image and the label at the same time.
286  virtual void SetSelectImageToIcon(vtkKWIcon *icon);
287  virtual void SetSelectImageToPredefinedIcon(int icon_index);
288  virtual void SetSelectImageToPixels(
289  const unsigned char *pixels, int width, int height, int pixel_size,
290  unsigned long buffer_length = 0);
291 
292  // Description:
293  // Specifies if the widget should display text and bitmaps/images at the
294  // same time, and if so, where the bitmap/image should be placed relative
295  // to the text.
296  // Valid constants can be found in vtkKWOptions::CompoundModeType.
297  // The (default) value CompoundModeNone specifies that the bitmap or image
298  // should (if defined) be displayed instead of the text.
299  virtual void SetCompoundMode(int);
300  virtual int GetCompoundMode();
301  virtual void SetCompoundModeToNone();
302  virtual void SetCompoundModeToLeft();
303  virtual void SetCompoundModeToCenter();
304  virtual void SetCompoundModeToRight();
305  virtual void SetCompoundModeToTop();
306  virtual void SetCompoundModeToBottom();
307 
308  // Description:
309  // Set/Get the background color to use when the widget is selected.
310  virtual void GetSelectColor(double *r, double *g, double *b);
311  virtual double* GetSelectColor();
312  virtual void SetSelectColor(double r, double g, double b);
313  virtual void SetSelectColor(double rgb[3])
314  { this->SetSelectColor(rgb[0], rgb[1], rgb[2]); };
315 
316  // Description:
317  // Update the "enable" state of the object and its internal parts.
318  // Depending on different Ivars (this->Enabled, the application's
319  // Limited Edition Mode, etc.), the "enable" state of the object is updated
320  // and propagated to its internal parts/subwidgets. This will, for example,
321  // enable/disable parts of the widget UI, enable/disable the visibility
322  // of 3D widgets, etc.
323  virtual void UpdateEnableState();
324 
325  // Description:
326  // Callbacks. Internal, do not use.
327  virtual void CommandCallback();
328 
329 protected:
330 
331  // Description:
332  // Create the widget.
333  virtual void CreateWidget();
334 
335  vtkSetStringMacro(InternalText);
336 
338  ~vtkKWCheckButton();
339 
340  int IndicatorVisibility;
341 
342  char *InternalText;
343  char *VariableName;
344 
345  virtual void Configure();
346 
347  char *Command;
348  virtual void InvokeCommand(int state);
349 
350 private:
351  vtkKWCheckButton(const vtkKWCheckButton&); // Not implemented
352  void operator=(const vtkKWCheckButton&); // Not Implemented
353 };
354 
355 #endif