OpenWalnut  1.5.0dev
WUIWidgetBase.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WUIWIDGETBASE_H
26 #define WUIWIDGETBASE_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 
33 #include "core/common/WCondition.h"
34 #include "core/common/WProperties.h"
35 #include "core/common/WSharedSequenceContainer.h"
36 #include "core/graphicsEngine/WGEImage.h"
37 
38 /**
39  * Base class for all the widget abstraction the core UI provides. All the abstract widgets use the bridge pattern to let the UI/GUI implementor
40  * actually handle everything.
41  *
42  * \note Please read documentation of \ref WUIWidgetFactory for limitations, requirements and creation of these widgets.
43  */
45 {
46  friend class WUIWidgetFactory; //!< The factory needs to be able to call the constructor
47 public:
48  /**
49  * Convenience typedef for a std::shared_ptr< WUIWidgetBase >.
50  */
51  typedef std::shared_ptr< WUIWidgetBase > SPtr;
52 
53  /**
54  * Convenience typedef for a std::shared_ptr< const WUIWidgetBase >.
55  */
56  typedef std::shared_ptr< const WUIWidgetBase > ConstSPtr;
57 
58  /**
59  * Destructor.
60  */
61  virtual ~WUIWidgetBase();
62 
63  /**
64  * Get the title of the widget.
65  *
66  * \return title as string
67  */
68  virtual std::string getTitle() const;
69 
70  /**
71  * Show this widget if not yet visible.
72  */
73  virtual void show() = 0;
74 
75  /**
76  * Hide/show this widget. Unlike close(), you can show the widget again using show().
77  *
78  * \param visible false to hide widget
79  */
80  virtual void setVisible( bool visible = true ) = 0;
81 
82  /**
83  * Check if the widget is hidden or not.
84  *
85  * \return true if visible.
86  */
87  virtual bool isVisible() const = 0;
88 
89  /**
90  * Close the widget. When done, the widget can be safely deleted. You cannot re-open the widget with \ref show(). If you want to hide widget,
91  * use setVisible( false ) instead. This function cascades to all child widgets if any. So it is enough to use this for the top-level
92  * (parent-less) widget only. This ensures proper close for all nested widgets.
93  */
94  void close();
95 
96  /**
97  * Checks whether the widget was closed already.
98  *
99  * \return true if already closed
100  */
101  bool isClosed() const;
102 
103  /**
104  * Return the condition that fires when the widgets closes.
105  *
106  * \return the condition fired whenever the widget closes
107  */
109 
110  /**
111  * Get the parent widget of this widget if any. Can be NULL.
112  *
113  * \return the parent
114  */
115  virtual WUIWidgetBase::SPtr getParent() const;
116 
117  /**
118  * Tell the user whether this kind of widget can be used as parent. In other word, whether it is allowed to nest other widgets into this one.
119  *
120  * \return true if nesting other widgets INTO this one is allowed
121  */
122  virtual bool allowNesting() const;
123 
124  /**
125  * Define a property as action. Depending on the UI implementing this, adding actions to a nested widget can be useless. View the
126  * corresponding WUI*Widget doc for details. Order of adding is order of appearance in the UI/GUI.
127  *
128  * \note They might not be visible. Only top-level widgets guarantee to show these properly.
129  *
130  * \param group the property to use.
131  * \param icon the icon to use. Consider a minimum size of 32x32.
132  */
133  virtual void addAction( WPropGroup group, WGEImage::SPtr icon = WGEImage::SPtr() ) = 0;
134 
135  /**
136  * Define a property as action. Depending on the UI implementing this, adding actions to a nested widget can be useless. View the
137  * corresponding WUI*Widget doc for details. Order of adding is order of appearance in the UI/GUI.
138  *
139  * \note They might not be visible. Only top-level widgets guarantee to show these properly.
140  *
141  * \param trigger the property to use
142  * \param icon the icon to use. Consider a minimum size of 32x32.
143  */
144  virtual void addAction( WPropTrigger trigger, WGEImage::SPtr icon = WGEImage::SPtr() ) = 0;
145 
146  /**
147  * Define a property as action. Depending on the UI implementing this, adding actions to a nested widget can be useless. View the
148  * corresponding WUI*Widget doc for details. Order of adding is order of appearance in the UI/GUI.
149  *
150  * \note They might not be visible. Only top-level widgets guarantee to show these properly.
151  *
152  * \param toggle the property to use
153  * \param icon the icon to use. Consider a minimum size of 32x32.
154  */
155  virtual void addAction( WPropBool toggle, WGEImage::SPtr icon = WGEImage::SPtr() ) = 0;
156 
157 protected:
158  /**
159  * Default constructor.
160  *
161  * \param title the title of the widget
162  */
163  explicit WUIWidgetBase( std::string title );
164 
165  /**
166  * Close the widget. When done, the widget can be safely deleted. You cannot re-open the widget with \ref show(). If you want to hide widget,
167  * use setVisible( false ) instead.
168  */
169  virtual void closeImpl() = 0;
170 
171  /**
172  * Set the parent of this WUI widget. Do never call this after the widget was realized by the factory. This method is used by the factory. Do
173  * not manually call it.
174  *
175  * \param parent the parent. Can be NULL if none.
176  */
177  virtual void setParent( WUIWidgetBase::SPtr parent );
178 
179  /**
180  * Register widget as child. Called by the widget factory.
181  *
182  * \param child the child.
183  */
184  virtual void registerChild( WUIWidgetBase::SPtr child );
185 
186  /**
187  * Keep track of our child widgets. Please note that we store shared_ptr here. This means, no widget ever gets deleted by the shared_ptr
188  * accidentally in a module. All widgets keeps reference of their parent, and each widget keeps reference to its childs. Only a call to close
189  * will recursively free the widgets.
190  */
192 
193  /**
194  * Return the list of children.
195  *
196  * \return the children
197  */
199 
200  /**
201  * Return the list of children.
202  *
203  * \return the children
204  */
205  const ChildContainer& getChildren() const;
206 
207  /**
208  * Comfortable function to recurse a close call. This iterates the children and closes them.
209  */
210  void closeChildren();
211 
212 private:
213  /**
214  * The widget's title string.
215  */
216  std::string m_title;
217 
218  /**
219  * Close condition. Notified when widget closes.
220  */
222 
223  /**
224  * The parent. Can be NULL.
225  */
227 
228  /**
229  * Child widgets.
230  */
232 
233  /**
234  * Flag denotes whether the widget was closed already.
235  */
236  bool m_closed;
237 };
238 
239 #endif // WUIWIDGETBASE_H
std::shared_ptr< WCondition > SPtr
Shared pointer type for WCondition.
Definition: WCondition.h:48
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
Definition: WGEImage.h:48
This class provides a common interface for thread-safe access to sequence containers (list,...
Base class for all the widget abstraction the core UI provides.
Definition: WUIWidgetBase.h:45
void closeChildren()
Comfortable function to recurse a close call.
std::shared_ptr< WUIWidgetBase > SPtr
Convenience typedef for a std::shared_ptr< WUIWidgetBase >.
Definition: WUIWidgetBase.h:51
void close()
Close the widget.
virtual void registerChild(WUIWidgetBase::SPtr child)
Register widget as child.
virtual void closeImpl()=0
Close the widget.
virtual ~WUIWidgetBase()
Destructor.
ChildContainer & getChildren()
Return the list of children.
WCondition::SPtr getCloseCondition() const
Return the condition that fires when the widgets closes.
virtual void addAction(WPropGroup group, WGEImage::SPtr icon=WGEImage::SPtr())=0
Define a property as action.
bool isClosed() const
Checks whether the widget was closed already.
virtual bool allowNesting() const
Tell the user whether this kind of widget can be used as parent.
WCondition::SPtr m_closeCondition
Close condition.
virtual bool isVisible() const =0
Check if the widget is hidden or not.
bool m_closed
Flag denotes whether the widget was closed already.
WUIWidgetBase(std::string title)
Default constructor.
virtual void show()=0
Show this widget if not yet visible.
virtual void addAction(WPropBool toggle, WGEImage::SPtr icon=WGEImage::SPtr())=0
Define a property as action.
virtual void setVisible(bool visible=true)=0
Hide/show this widget.
virtual void addAction(WPropTrigger trigger, WGEImage::SPtr icon=WGEImage::SPtr())=0
Define a property as action.
WSharedSequenceContainer< std::vector< WUIWidgetBase::SPtr > > ChildContainer
Keep track of our child widgets.
std::string m_title
The widget's title string.
WUIWidgetBase::SPtr m_parent
The parent.
ChildContainer m_childs
Child widgets.
std::shared_ptr< const WUIWidgetBase > ConstSPtr
Convenience typedef for a std::shared_ptr< const WUIWidgetBase >.
Definition: WUIWidgetBase.h:56
virtual void setParent(WUIWidgetBase::SPtr parent)
Set the parent of this WUI widget.
virtual WUIWidgetBase::SPtr getParent() const
Get the parent widget of this widget if any.
virtual std::string getTitle() const
Get the title of the widget.
Create instances of WUI widgets.