KWWidgets
vtkKWListBox.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWListBox.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 vtkKWListBox - List Box
15 // .SECTION Description
16 // A widget that can have a list of items.
17 // Use vtkKWListBoxWithScrollbars if you need scrollbars.
18 // .SECTION See Also
19 // vtkKWListBoxWithScrollbars
20 
21 #ifndef __vtkKWListBox_h
22 #define __vtkKWListBox_h
23 
24 #include "vtkKWCoreWidget.h"
25 
27 {
28 public:
29  static vtkKWListBox* New();
30  vtkTypeRevisionMacro(vtkKWListBox,vtkKWCoreWidget);
31  void PrintSelf(ostream& os, vtkIndent indent);
32 
33  // Description:
34  // Set/Get the background color of the widget.
35  virtual void GetBackgroundColor(double *r, double *g, double *b);
36  virtual double* GetBackgroundColor();
37  virtual void SetBackgroundColor(double r, double g, double b);
38  virtual void SetBackgroundColor(double rgb[3])
39  { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); };
40 
41  // Description:
42  // Set/Get the foreground color of the widget.
43  virtual void GetForegroundColor(double *r, double *g, double *b);
44  virtual double* GetForegroundColor();
45  virtual void SetForegroundColor(double r, double g, double b);
46  virtual void SetForegroundColor(double rgb[3])
47  { this->SetForegroundColor(rgb[0], rgb[1], rgb[2]); };
48 
49  // Description:
50  // Set/Get the foreground color of the widget when it is disabled.
51  virtual void GetDisabledForegroundColor(double *r, double *g, double *b);
52  virtual double* GetDisabledForegroundColor();
53  virtual void SetDisabledForegroundColor(double r, double g, double b);
54  virtual void SetDisabledForegroundColor(double rgb[3])
55  { this->SetDisabledForegroundColor(rgb[0], rgb[1], rgb[2]); };
56 
57  // Description:
58  // Set/Get the highlight thickness, a non-negative value indicating the
59  // width of the highlight rectangle to draw around the outside of the
60  // widget when it has the input focus.
61  virtual void SetHighlightThickness(int);
62  virtual int GetHighlightThickness();
63 
64  // Description:
65  // Set/Get the border width, a non-negative value indicating the width of
66  // the 3-D border to draw around the outside of the widget (if such a border
67  // is being drawn; the Relief option typically determines this).
68  virtual void SetBorderWidth(int);
69  virtual int GetBorderWidth();
70 
71  // Description:
72  // Set/Get the 3-D effect desired for the widget.
73  // The value indicates how the interior of the widget should appear
74  // relative to its exterior.
75  // Valid constants can be found in vtkKWOptions::ReliefType.
76  virtual void SetRelief(int);
77  virtual int GetRelief();
78  virtual void SetReliefToRaised();
79  virtual void SetReliefToSunken();
80  virtual void SetReliefToFlat();
81  virtual void SetReliefToRidge();
82  virtual void SetReliefToSolid();
83  virtual void SetReliefToGroove();
84 
85  // Description:
86  // Specifies the font to use when drawing text inside the widget.
87  // You can use predefined font names (e.g. 'system'), or you can specify
88  // a set of font attributes with a platform-independent name, for example,
89  // 'times 12 bold'. In this example, the font is specified with a three
90  // element list: the first element is the font family, the second is the
91  // size, the third is a list of style parameters (normal, bold, roman,
92  // italic, underline, overstrike). Example: 'times 12 {bold italic}'.
93  // The Times, Courier and Helvetica font families are guaranteed to exist
94  // and will be matched to the corresponding (closest) font on your system.
95  // If you are familiar with the X font names specification, you can also
96  // describe the font that way (say, '*times-medium-r-*-*-12*').
97  virtual void SetFont(const char *font);
98  virtual const char* GetFont();
99 
100  // Description:
101  // Set/Get the one of several styles for manipulating the selection.
102  // Valid constants can be found in vtkKWOptions::SelectionModeType.
103  virtual void SetSelectionMode(int);
104  virtual int GetSelectionMode();
105  virtual void SetSelectionModeToSingle();
106  virtual void SetSelectionModeToBrowse();
107  virtual void SetSelectionModeToMultiple();
108  virtual void SetSelectionModeToExtended();
109 
110  // Description:
111  // Specifies whether or not a selection in the widget should also be the X
112  // selection. If the selection is exported, then selecting in the widget
113  // deselects the current X selection, selecting outside the widget deselects
114  // any widget selection, and the widget will respond to selection retrieval
115  // requests when it has a selection.
116  virtual void SetExportSelection(int);
117  virtual int GetExportSelection();
118  vtkBooleanMacro(ExportSelection, int);
119 
120  // Description:
121  // Get the current selected string in the list. This is used when
122  // Select mode is single or browse.
123  virtual const char *GetSelection();
124  virtual int GetSelectionIndex();
125  virtual void SetSelectionIndex(int);
126 
127  // Description:
128  // When selectmode is multiple or extended, then these methods can
129  // be used to set and query the selection.
130  virtual void SetSelectState(int idx, int state);
131  virtual int GetSelectState(int idx);
132 
133  // Description:
134  // Add an entry.
135  virtual void InsertEntry(int index, const char *name);
136 
137  // Description:
138  // Append a unique string to the list. If the string exists,
139  // it will not be appended
140  virtual int AppendUnique(const char* name);
141 
142  // Description:
143  // Append a string to the list. This call does not check if the string
144  // is unique.
145  virtual int Append(const char* name);
146 
147  // Description:
148  // Specifies a command to be invoked when an element is selected/deselected
149  // in the widget. Re-selecting an element will trigger this command too.
150  // The 'object' argument is the object that will have the method called on
151  // it. The 'method' argument is the name of the method to be called and any
152  // arguments in string form. If the object is NULL, the method is still
153  // evaluated as a simple command.
154  virtual void SetSelectionCommand(vtkObject *object, const char *method);
155 
156  // Description:
157  // Specifies a command to be invoked when the user single-click or
158  // double-click in the listbox. This does *not* imply the selection changed
159  // though (use SetSelectionCommand instead).
160  // The 'object' argument is the object that will have the method called on
161  // it. The 'method' argument is the name of the method to be called and any
162  // arguments in string form. If the object is NULL, the method is still
163  // evaluated as a simple command.
164  // Set callback for single and double click on a list item.
165  virtual void SetDoubleClickCommand(vtkObject *obj, const char *method);
166  virtual void SetSingleClickCommand(vtkObject *obj, const char *method);
167 
168  // Description:
169  // Events. The ListBoxSelectionChangedEvent is triggered when an element
170  // is selected/deselected in the widget. Re-selecting an element will
171  // trigger this event too. It is similar in concept as the 'SelectionCommand'
173  //BTX
174  enum
175  {
176  ListBoxSelectionChangedEvent = 10000
177  };
178  //ETX
179 
180  // Description:
181  // Get number of items in the list.
182  virtual int GetNumberOfItems();
183 
184  // Description:
185  // Get the item at the given index.
186  virtual const char* GetItem(int index);
187 
188  // Description:
189  // Returns the index of the first given item.
190  virtual int GetItemIndex(const char* item);
191 
192  // Description:
193  // Delete a range of items in the list.
194  virtual void DeleteRange(int start, int end);
195 
196  // Description:
197  // Delete all items from the list.
198  virtual void DeleteAll();
199 
200  // Description:
201  // Set the width of the list box. If the width is less than or equal to 0,
202  // then the width is set to the size of the largest string.
203  virtual void SetWidth(int);
204  virtual int GetWidth();
205 
206  // Description:
207  // Set the height of the list box. If the height is less than or equal to 0,
208  // then the height is set to the size of the number of items in the listbox.
209  virtual void SetHeight(int);
210  virtual int GetHeight();
211 
212  // Description:
213  // Update the "enable" state of the object and its internal parts.
214  // Depending on different Ivars (this->Enabled, the application's
215  // Limited Edition Mode, etc.), the "enable" state of the object is updated
216  // and propagated to its internal parts/subwidgets. This will, for example,
217  // enable/disable parts of the widget UI, enable/disable the visibility
218  // of 3D widgets, etc.
219  virtual void UpdateEnableState();
220 
221  // Description:
222  // Callbacks. Internal, do not use.
223  virtual void SelectionCallback();
224 
225 protected:
226  vtkKWListBox();
227  ~vtkKWListBox();
228 
229  // Description:
230  // Create the widget.
231  virtual void CreateWidget();
232 
233  char* CurrentSelection; // store last call of CurrentSelection
234  char* Item; // store last call of GetItem
235 
236  char *SelectionCommand;
237  virtual void InvokeSelectionCommand();
238 
239 private:
240  vtkKWListBox(const vtkKWListBox&); // Not implemented
241  void operator=(const vtkKWListBox&); // Not implemented
242 };
243 
244 
245 #endif
246 
247 
248