KWWidgets
vtkKWToolbarSet.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWToolbarSet.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 vtkKWToolbarSet - a "set of toolbars" widget
15 // .SECTION Description
16 // A simple widget representing a set of toolbars..
17 
18 #ifndef __vtkKWToolbarSet_h
19 #define __vtkKWToolbarSet_h
20 
21 #include "vtkKWCompositeWidget.h"
22 
23 class vtkKWFrame;
24 class vtkKWMenu;
25 class vtkKWSeparator;
26 class vtkKWToolbar;
27 class vtkKWToolbarSetInternals;
28 
30 {
31 public:
32  static vtkKWToolbarSet* New();
33  vtkTypeRevisionMacro(vtkKWToolbarSet,vtkKWCompositeWidget);
34  void PrintSelf(ostream& os, vtkIndent indent);
35 
36  // Description:
37  // Get the frame that can be used as a parent to a toolbar
38  vtkGetObjectMacro(ToolbarsFrame, vtkKWFrame);
39 
40  // Description:
41  // Add a toolbar to the set.
42  // The default_visibility parameter sets the visibility of the toolbar
43  // in the set once it is added (so that it can be added hidden for example,
44  // before its visibility setting is retrieved from the registry).
45  // Return 1 on success, 0 otherwise.
46  virtual int AddToolbar(vtkKWToolbar *toolbar)
47  { return this->AddToolbar(toolbar, 1); };
48  virtual int AddToolbar(vtkKWToolbar *toolbar, int default_visibility);
49  virtual int HasToolbar(vtkKWToolbar *toolbar);
50 
51  // Description:
52  // Get the n-th toolbar, and the number of toolbars.
53  virtual vtkKWToolbar* GetNthToolbar(int rank);
54  virtual int GetNumberOfToolbars();
55 
56  // Description:
57  // Remove a toolbar (or all) from the set.
58  // Return 1 on success, 0 otherwise.
59  virtual int RemoveToolbar(vtkKWToolbar *toolbar);
60  virtual void RemoveAllToolbars();
61 
62  // Description:
63  // Set/Get the aspect of the toolbar (flat or 3D GUI style, or unchanged)
64  // Important: this will *not* override the toolbar aspect of a toolbar
65  // which aspect was already set to 'UnChanged'.
66  virtual void SetToolbarsAspect(int);
67 
68  // Description:
69  // Set/Get the aspect of the widgets (flat, 3D GUI style, or unchanged)
70  // Important: this will *not* override the widgets aspect of a toolbar
71  // which widgets aspect was already set to 'UnChanged'.
72  virtual void SetToolbarsWidgetsAspect(int);
73 
74  // Description:
75  // Set the visibility of a toolbar.
76  virtual void HideToolbar(vtkKWToolbar *toolbar);
77  virtual void ShowToolbar(vtkKWToolbar *toolbar);
78  virtual void SetToolbarVisibility(vtkKWToolbar *toolbar, int flag);
79  virtual int GetToolbarVisibility(vtkKWToolbar *toolbar);
80  virtual void ToggleToolbarVisibility(vtkKWToolbar *toolbar);
81 
82  // Description:
83  // Return the number of visible toolbars
84  virtual int GetNumberOfVisibleToolbars();
85 
86  // Description:
87  // Set a toolbar's anchor. By default, toolbars are packed from left
88  // to right in the order they were added to the toolbar set, i.e. each
89  // toolbar is "anchored" to the west side of the set. One can change
90  // this anchor on a per-toolbar basis. This means that all toolbars anchored
91  // to the west side will be grouped together on that side, and all toolbars
92  // anchored to the east side will be grouped on the opposite side. Note
93  // though that anchoring acts like a "mirror": packing starts from the
94  // anchor side, progressing towards the middle of the toolbar set (i.e.,
95  // toolbars anchored west are packed left to right, toolbars anchored east
96  // are packed right to left, following the order they were inserted in
97  // the set).
98  //BTX
99  enum
100  {
101  ToolbarAnchorWest = 0,
102  ToolbarAnchorEast
103  };
104  //ETX
105  virtual void SetToolbarAnchor(vtkKWToolbar *toolbar, int anchor);
106  virtual int GetToolbarAnchor(vtkKWToolbar *toolbar);
107  virtual void SetToolbarAnchorToWest(vtkKWToolbar *toolbar)
108  { this->SetToolbarAnchor(toolbar, vtkKWToolbarSet::ToolbarAnchorWest); };
109  virtual void SetToolbarAnchorToEast(vtkKWToolbar *toolbar)
110  { this->SetToolbarAnchor(toolbar, vtkKWToolbarSet::ToolbarAnchorEast); };
111 
112  // Description:
113  // Save/Restore the visibility flag of one/all toolbars to/from the registry
114  // Note that the name of each toolbar to save/restore should have been set
115  // for this method to work (see vtkKWToolbar).
116  virtual void SaveToolbarVisibilityToRegistry(vtkKWToolbar *toolbar);
117  virtual void RestoreToolbarVisibilityFromRegistry(vtkKWToolbar *toolbar);
118  virtual void SaveToolbarsVisibilityToRegistry();
119  virtual void RestoreToolbarsVisibilityFromRegistry();
120 
121  // Description:
122  // Set/Get if the visibility flag of the toolbars should be saved
123  // or restored to the registry automatically.
124  // It is restored when the toolbar is added, and saved when the visibility
125  // flag is changed.
126  vtkBooleanMacro(SynchronizeToolbarsVisibilityWithRegistry, int);
127  vtkGetMacro(SynchronizeToolbarsVisibilityWithRegistry, int);
128  vtkSetMacro(SynchronizeToolbarsVisibilityWithRegistry, int);
129 
130  // Description:
131  // Create and update a menu that can be used to control the visibility of
132  // all toolbars.
133  // The Populate...() method will repopulate the menu (note that it does
134  // *not* remove all entries, so that this menu can be used for several
135  // toolbar sets).
136  // The Update...() method will update the state of the entries according
137  // to the toolbarsvisibility (the first one will call the second one
138  // automatically).
139  virtual void PopulateToolbarsVisibilityMenu(vtkKWMenu *menu);
140  virtual void UpdateToolbarsVisibilityMenu(vtkKWMenu *menu);
141 
142  // Description:
143  // Specifies a command to associate with the widget. This command is
144  // typically invoked when the visibility of a toolbar is changed.
145  // The 'object' argument is the object that will have the method called on
146  // it. The 'method' argument is the name of the method to be called and any
147  // arguments in string form. If the object is NULL, the method is still
148  // evaluated as a simple command.
149  // The following parameters are also passed to the command:
150  // - pointer to the toolbar which visibility changed: vtkKWToolbar*
151  virtual void SetToolbarVisibilityChangedCommand(
152  vtkObject *object, const char *method);
153 
154  // Description:
155  // Specifies a command to associate with the widget. This command is
156  // typically invoked when the number of toolbars has changed
157  // (i.e. a toolbar is added or removed).
158  // The 'object' argument is the object that will have the method called on
159  // it. The 'method' argument is the name of the method to be called and any
160  // arguments in string form. If the object is NULL, the method is still
161  // evaluated as a simple command.
162  virtual void SetNumberOfToolbarsChangedCommand(
163  vtkObject *object, const char *method);
164 
165  // Description:
166  // Set/Get the visibility of the separator at the bottom of the set
167  virtual void SetBottomSeparatorVisibility(int);
168  vtkBooleanMacro(BottomSeparatorVisibility, int);
169  vtkGetMacro(BottomSeparatorVisibility, int);
170 
171  // Description:
172  // Set/Get the visibility of the separator at the top of the set
173  virtual void SetTopSeparatorVisibility(int);
174  vtkBooleanMacro(TopSeparatorVisibility, int);
175  vtkGetMacro(TopSeparatorVisibility, int);
176 
177  // Description:
178  // Update the toolbar set
179  // (update the enabled state of all toolbars, call PackToolbars(), etc.).
180  virtual void Update();
181 
182  // Description:
183  // (Re)Pack the toolbars, if needed (if the widget is created, and the
184  // toolbar is created, AddToolbar will pack the toolbar automatically).
185  virtual void Pack();
186 
187  // Description:
188  // Update the "enable" state of the object and its internal parts.
189  // Depending on different Ivars (this->Enabled, the application's
190  // Limited Edition Mode, etc.), the "enable" state of the object is updated
191  // and propagated to its internal parts/subwidgets. This will, for example,
192  // enable/disable parts of the widget UI, enable/disable the visibility
193  // of 3D widgets, etc.
194  virtual void UpdateEnableState();
195 
196 protected:
197  vtkKWToolbarSet();
198  ~vtkKWToolbarSet();
199 
200  // Description:
201  // Create the widget.
202  virtual void CreateWidget();
203 
204  vtkKWSeparator *TopSeparator;
205  vtkKWFrame *ToolbarsFrame;
206  vtkKWSeparator *BottomSeparator;
207 
208  int BottomSeparatorVisibility;
209  int TopSeparatorVisibility;
210  int SynchronizeToolbarsVisibilityWithRegistry;
211 
212  char *ToolbarVisibilityChangedCommand;
213  char *NumberOfToolbarsChangedCommand;
214 
215  virtual void InvokeToolbarVisibilityChangedCommand(
216  vtkKWToolbar *toolbar);
217  virtual void InvokeNumberOfToolbarsChangedCommand();
218 
219  //BTX
220 
221  // A toolbar slot stores a toolbar + some infos
222 
223  class ToolbarSlot
224  {
225  public:
226  int Visibility;
227  int Anchor;
228  vtkKWSeparator *Separator;
229  vtkKWToolbar *Toolbar;
230  };
231 
232  // PIMPL Encapsulation for STL containers
233 
234  vtkKWToolbarSetInternals *Internals;
235  friend class vtkKWToolbarSetInternals;
236 
237  // Helper methods
238 
239  ToolbarSlot* GetToolbarSlot(vtkKWToolbar *toolbar);
240 
241  //ETX
242 
243  virtual void PackToolbars();
244  virtual void PackBottomSeparator();
245  virtual void PackTopSeparator();
246 
247 private:
248  vtkKWToolbarSet(const vtkKWToolbarSet&); // Not implemented
249  void operator=(const vtkKWToolbarSet&); // Not implemented
250 };
251 
252 #endif
253