KWWidgets
vtkKWTopLevel.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWTopLevel.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 vtkKWTopLevel - toplevel superclass
15 // .SECTION Description
16 // A generic superclass for toplevel.
17 
18 #ifndef __vtkKWTopLevel_h
19 #define __vtkKWTopLevel_h
20 
21 #include "vtkKWCoreWidget.h"
22 
23 class vtkKWMenu;
24 class vtkKWTclInteractor;
25 
27 {
28 public:
29  static vtkKWTopLevel* New();
30  vtkTypeRevisionMacro(vtkKWTopLevel,vtkKWCoreWidget);
31  void PrintSelf(ostream& os, vtkIndent indent);
32 
33  // Description:
34  // Class of the window. Used to group several windows under the same class
35  // (they will, for example, de-iconify together).
36  // Make sure you set it before a call to Create().
37  vtkSetStringMacro(WindowClass);
38  vtkGetStringMacro(WindowClass);
39 
40  // Description:
41  // Set the widget/window to which this toplevel will be slave.
42  // If set, this toplevel will always be on top of the master
43  // window and will minimize with it (assuming that the windowing
44  // system supports this).
45  // For convenience purposes, the MasterWindow does not have to be a
46  // toplevel, it can be a plain widget (its toplevel will be found
47  // at runtime).
48  // Has to be called before Create().
49  virtual void SetMasterWindow(vtkKWWidget* win);
50  vtkGetObjectMacro(MasterWindow, vtkKWWidget);
51 
52  // Description:
53  // Get the application instance for this object.
54  // Override the superclass to try to retrieve the masterwindow's application
55  // if it was not set already.
57 
58  // Description:
59  // Display the toplevel. Hide it with the Withdraw() method.
60  // This also call DeIconify(), Focus() and Raise()
61  virtual void Display();
62 
63  // Description:
64  // Arranges for window to be withdrawn from the screen. This causes the
65  // window to be unmapped and forgotten about by the window manager.
66  virtual void Withdraw();
67 
68  // Description:
69  // Inform the window manager that this toplevel should be modal.
70  // If it is set, Display() will bring up the toplevel and grab it.
71  // Withdraw() will bring down the toplevel, and release the grab.
72  vtkSetClampMacro(Modal, int, 0, 1);
73  vtkBooleanMacro(Modal, int);
74  vtkGetMacro(Modal, int);
75 
76  // Description:
77  // Set/Get the background color of the widget.
78  virtual void GetBackgroundColor(double *r, double *g, double *b);
79  virtual double* GetBackgroundColor();
80  virtual void SetBackgroundColor(double r, double g, double b);
81  virtual void SetBackgroundColor(double rgb[3])
82  { this->SetBackgroundColor(rgb[0], rgb[1], rgb[2]); };
83 
84  // Description:
85  // Set/Get the border width, a non-negative value indicating the width of
86  // the 3-D border to draw around the outside of the widget (if such a border
87  // is being drawn; the Relief option typically determines this).
88  virtual void SetBorderWidth(int);
89  virtual int GetBorderWidth();
90 
91  // Description:
92  // Set/Get the highlight thickness, a non-negative value indicating the
93  // width of the highlight rectangle to draw around the outside of the
94  // widget when it has the input focus.
95  virtual void SetHighlightThickness(int);
96  virtual int GetHighlightThickness();
97 
98  // Description:
99  // Set/Get the 3-D effect desired for the widget.
100  // The value indicates how the interior of the widget should appear
101  // relative to its exterior.
102  // Valid constants can be found in vtkKWOptions::ReliefType.
103  virtual void SetRelief(int);
104  virtual int GetRelief();
105  virtual void SetReliefToRaised();
106  virtual void SetReliefToSunken();
107  virtual void SetReliefToFlat();
108  virtual void SetReliefToRidge();
109  virtual void SetReliefToSolid();
110  virtual void SetReliefToGroove();
111 
112  // Description:
113  // Set/Get the padding that will be applied around each widget (in pixels).
114  // Specifies a non-negative value indicating how much extra space to request
115  // for the widget in the X and Y-direction. When computing how large a
116  // window it needs, the widget will add this amount to the width it would
117  // normally need (as determined by the width of the things displayed
118  // in the widget); if the geometry manager can satisfy this request, the
119  // widget will end up with extra internal space around what it displays
120  // inside.
121  virtual void SetPadX(int);
122  virtual int GetPadX();
123  virtual void SetPadY(int);
124  virtual int GetPadY();
125 
126  // Description:
127  // Set/Get the position this toplevel should be centered at when Display()
128  // is called. The default setting, Default, is to not set/change the
129  // position at all and let the user or the window manager place the toplevel.
130  // If set to MasterWindowCenter, the toplevel is centered inside its master
131  // window ; if the MasterWindow ivar is not set, it is centered on the
132  // screen, which is similar to the ScreenCenter setting. If set to
133  // Pointer, the toplevel is centered at the current mouse position.
134  // On some sytem, the default setting can lead the window manager to
135  // place the window at the upper left corner (0, 0) the first time it
136  // is displayed. Since this can be fairly annoying, the
137  // MasterWindowCenterFirst and ScreenCenterFirst can be used to center
138  // the toplevel relative to the master window or the screen only the
139  // first time it is displayed (after that, the toplevel will be displayed
140  // wherever it was left).
141  //BTX
142  enum
143  {
144  DisplayPositionDefault = 0,
145  DisplayPositionMasterWindowCenter = 1,
146  DisplayPositionMasterWindowCenterFirst = 2,
147  DisplayPositionScreenCenter = 3,
148  DisplayPositionScreenCenterFirst = 4,
149  DisplayPositionPointer = 5
150  };
151  //ETX
152  vtkSetClampMacro(DisplayPosition, int,
155  vtkGetMacro(DisplayPosition, int);
156  virtual void SetDisplayPositionToDefault()
157  { this->SetDisplayPosition(
159  virtual void SetDisplayPositionToMasterWindowCenter()
160  { this->SetDisplayPosition(
162  virtual void SetDisplayPositionToMasterWindowCenterFirst()
163  { this->SetDisplayPosition(
165  virtual void SetDisplayPositionToScreenCenter()
166  { this->SetDisplayPosition(
168  virtual void SetDisplayPositionToScreenCenterFirst()
169  { this->SetDisplayPosition(
171  virtual void SetDisplayPositionToPointer()
172  { this->SetDisplayPosition(
174 
175  // Description:
176  // Arrange for the toplevel to be displayed in normal (non-iconified) form.
177  // This is done by mapping the window.
178  virtual void DeIconify();
179 
180  // Description:
181  // Set the title of the toplevel.
182  virtual void SetTitle(const char *);
183  vtkGetStringMacro(Title);
184 
185  // Description:
186  // Set the title to the same title as another widget's toplevel.
187  virtual void SetTitleToTopLevelTitle(vtkKWWidget*);
188 
189  // Description:
190  // Set/Get the window position in screen pixel coordinates. No effect if
191  // called before Create()
192  // Return 1 on success, 0 otherwise.
193  virtual int SetPosition(int x, int y);
194  virtual int GetPosition(int *x, int *y);
195 
196  // Description:
197  // Set/Get the window size in pixels. No effect if called before Create()
198  // This will in turn call GetWidget() and GetHeight()
199  // Return 1 on success, 0 otherwise.
200  virtual int SetSize(int w, int h);
201  virtual int GetSize(int *w, int *h);
202 
203  // Description:
204  // Get the width/height of the toplevel.
205  virtual int GetWidth();
206  virtual int GetHeight();
207 
208  // Description:
209  // Set/Get the minimum window size.
210  // For gridded windows the dimensions are specified in grid units;
211  // otherwise they are specified in pixel units. The window manager will
212  // restrict the window's dimensions to be greater than or equal to width
213  // and height.
214  // No effect if called before Create()
215  // Return 1 on success, 0 otherwise.
216  virtual int SetMinimumSize(int w, int h);
217  virtual int GetMinimumSize(int *w, int *h);
218 
219  // Description:
220  // Set/Get the window size and position in screen pixel
221  // coordinates as a geometry format wxh+x+y (ex: 800x700+20+50).
222  // No effect if called before Create()
223  // SetGeometry will return 1 on success, 0 otherwise.
224  // GetGeometry will return the geometry in a temporary buffer on success
225  // (copy the value to another string buffer as soon as possible), or NULL
226  // otherwise
227  virtual int SetGeometry(const char *);
228  virtual const char* GetGeometry();
229 
230  // Description:
231  // Arranges for window to be maximized.
232  // Windows only.
233  virtual void Maximize();
234 
235  // Description:
236  // Set/Get if the toplevel should be displayed without decorations (i.e.
237  // ignored by the window manager). Default to 0. If not decorated, the
238  // toplevel will usually be displayed without a title bar, resizing handles,
239  // etc.
240  virtual void SetHideDecoration(int);
241  vtkGetMacro(HideDecoration, int);
242  vtkBooleanMacro(HideDecoration, int);
243 
244  // Description:
245  // Get the menu associated to this toplevel.
246  // Note that this menu is created on the fly to lower the footprint
247  // of this object.
248  vtkKWMenu *GetMenu();
249 
250  // Description:
251  // Specifies a command to associate with the widget. This command is
252  // typically invoked when the user closes the window using the
253  // window manager.
254  // The 'object' argument is the object that will have the method called on
255  // it. The 'method' argument is the name of the method to be called and any
256  // arguments in string form. If the object is NULL, the method is still
257  // evaluated as a simple command.
258  virtual void SetDeleteWindowProtocolCommand(
259  vtkObject *object, const char *method);
260 
261  // Description:
262  // Set the name inside the icon associated to this window/toplevel.
263  virtual void SetIconName(const char *name);
264 
265  // Description:
266  // Set whether or not the user may interactively resize the toplevel window.
267  // The parameters are boolean values that determine whether the width and
268  // height of the window may be modified by the user.
269  // No effect if called before Create()
270  virtual void SetResizable(int w, int h);
271 
272  // Description:
273  // Get/display the tcl interactor.
274  // Kept for compatibility purposes, use vtkKWApplication instead.
275  virtual vtkKWTclInteractor* GetTclInteractor();
276  virtual void DisplayTclInteractor();
277 
278  // Description:
279  // Update the "enable" state of the object and its internal parts.
280  // Depending on different Ivars (this->Enabled, the application's
281  // Limited Edition Mode, etc.), the "enable" state of the object is updated
282  // and propagated to its internal parts/subwidgets. This will, for example,
283  // enable/disable parts of the widget UI, enable/disable the visibility
284  // of 3D widgets, etc.
285  virtual void UpdateEnableState();
286 
287  // Description:
288  // Events.
289  // WithdrawEvent is called when the toplevel has been withdrawn, as a result
290  // of calling the Withdraw() method. DisplayEvent is called when the
291  // toplevel has been displayed by calling the Display() method.
292  // SlaveDisplayEvent is invoked when a slave toplevel of that instance is
293  // displayed (i.e. a toplevel whose MasterWindow was set to this instance).
294  // SlaveWithdrawEvent is invoked when a slave toplevel of that instance is
295  // withdrawn. Both events pass a pointer to the slave as call data.
296  //BTX
297  enum
298  {
299  DisplayEvent = 5500,
300  WithdrawEvent,
301  SlaveDisplayEvent,
302  SlaveWithdrawEvent
303  };
304  //ETX
305 
306 protected:
307  vtkKWTopLevel();
308  ~vtkKWTopLevel();
309 
310  // Description:
311  // Create the widget.
312  // Make sure WindowClass is set before calling this method (if needed).
313  // If MasterWindow is set and is a vtkKWTopLevel, its class will be used
314  // to set our own WindowClass.
315  // Withdraw() is called at the end of the creation.
316  virtual void CreateWidget();
317 
318  vtkKWWidget *MasterWindow;
319  vtkKWMenu *Menu;
320 
321  char *Title;
322  char *WindowClass;
323 
324  int HideDecoration;
325  int Modal;
326  int DisplayPosition;
327 
328  // Description:
329  // Get the width/height of the toplevel as requested
330  // by the window manager. Not exposed in public since it is so Tk
331  // related. Is is usually used to get the geometry of a window before
332  // it is mapped to screen, as requested by the geometry manager.
333  virtual int GetRequestedWidth();
334  virtual int GetRequestedHeight();
335 
336  // Description:
337  // Compute the display position (centered or at pointer)
338  // Return 1 on success, 0 otherwise
339  virtual int ComputeDisplayPosition(int *x, int *y);
340 
341  // Description:
342  // Setup transient, protocol, title and other settings right after
343  // the widget has been created. This can be used by subclass that
344  // really need to create the toplevel manually, but want to have
345  // the ivar setup properly
346  virtual void PostCreate();
347 
348 private:
349  vtkKWTopLevel(const vtkKWTopLevel&); // Not implemented
350  void operator=(const vtkKWTopLevel&); // Not Implemented
351 };
352 
353 #endif