OpenWalnut  1.5.0dev
WUIWidgetBase.cpp
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 #include <memory>
26 #include <string>
27 
28 #include "WUIWidgetBase.h"
29 #include "core/common/WConditionOneShot.h"
30 #include "core/common/WLogger.h"
31 
32 WUIWidgetBase::WUIWidgetBase( std::string title ):
33  m_title( title ),
34  m_closeCondition( new WConditionOneShot() ),
35  m_closed( false )
36 {
37  // initialize members
38 }
39 
41 {
42  // cleanup
43 }
44 
45 std::string WUIWidgetBase::getTitle() const
46 {
47  return m_title;
48 }
49 
51 {
52  // already closed?
53  if( isClosed() )
54  {
55  return;
56  }
57 
58  m_closed = true;
59 
60  // close all children
61  closeChildren();
62 
63  // clear the list of children. Their shared_ptr now get de-references.
64  m_childs.clear();
65 
66  // notify about close
67  m_closeCondition->notify();
68 
69  // let the implementor do the rest
70  closeImpl();
71 }
72 
74 {
75  return m_closeCondition;
76 }
77 
79 {
80  m_parent = parent;
81 }
82 
84 {
85  return m_parent;
86 }
87 
89 {
90  // it is a WSharedSequenceContainer which handles all the nasty locking stuff
91  m_childs.unique_push_back( child );
92 }
93 
95 {
96  // not allowed by default.
97  return false;
98 }
99 
101 {
102  return m_childs;
103 }
104 
106 {
107  return m_childs;
108 }
109 
110 /**
111  * Close the specified widget.
112  *
113  * \param widget the widget
114  */
115 void closeFunctor( WUIWidgetBase::SPtr widget )
116 {
117  widget->close();
118 }
119 
121 {
123  std::for_each( w->get().begin(), w->get().end(), closeFunctor );
124 }
125 
127 {
128  return m_closed;
129 }
130 
Implements a WCondition, but can be fired only ONCE.
std::shared_ptr< WCondition > SPtr
Shared pointer type for WCondition.
Definition: WCondition.h:48
std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
Definition: WSharedObject.h:70
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
void unique_push_back(const typename S::value_type &x)
Add the element only if it is not inside the container until now.
void clear()
Clears the container.
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.
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.
bool m_closed
Flag denotes whether the widget was closed already.
WUIWidgetBase(std::string title)
Default constructor.
std::string m_title
The widget's title string.
WUIWidgetBase::SPtr m_parent
The parent.
ChildContainer m_childs
Child widgets.
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.