aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/menu/control.cpp35
-rw-r--r--src/menu/control.hpp16
2 files changed, 38 insertions, 13 deletions
diff --git a/src/menu/control.cpp b/src/menu/control.cpp
index 68b5c328..f9ea2a89 100644
--- a/src/menu/control.cpp
+++ b/src/menu/control.cpp
@@ -29,26 +29,43 @@
namespace usdx
{
- Control::Control(Control *parent)
- : parent(parent)
+ Control::Control(Control *owner)
+ : owner(owner)
{
+ owner->add(this);
}
Control::~Control()
{
- if (parent) {
- delete parent;
- parent = NULL;
+ for (std::list<Control*>::iterator it =
+ slaves.begin(); it != slaves.end(); it++) {
+ delete *it;
}
+
+ slaves.clear();
+ }
+
+ void Control::set_owner(Control *owner)
+ {
+ if (this->owner != owner) {
+ this->owner->remove(this);
+ this->owner = owner;
+ this->owner->add(this);
+ }
+ }
+
+ Control* Control::get_owner(void) const
+ {
+ return owner;
}
- void Control::set_parent(Control *parent)
+ void Control::add(Control *new_slave)
{
- this->parent = parent;
+ slaves.push_back(new_slave);
}
- Control* Control::get_parent(void) const
+ void Control::remove(Control *slave)
{
- return parent;
+ slaves.remove(slave);
}
};
diff --git a/src/menu/control.hpp b/src/menu/control.hpp
index d0b70d4f..f105b69c 100644
--- a/src/menu/control.hpp
+++ b/src/menu/control.hpp
@@ -27,20 +27,28 @@
#ifndef CONTROL_HPP
#define CONTROL_HPP
+#include <list>
+
namespace usdx
{
class Control
{
private:
- Control* parent;
+ Control* owner;
+
+ protected:
+ std::list<Control*> slaves;
+
+ void add(Control *new_slave);
+ void remove(Control *slave);
public:
- Control(Control *parent);
+ Control(Control *owner);
virtual ~Control();
- void set_parent(Control *parent);
+ void set_owner(Control *owner);
- Control* get_parent(void) const;
+ Control* get_owner(void) const;
};
};