From b3f87944ba62ee82684f30fc89d8bbd5cf472b48 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 23 Apr 2010 11:43:21 +0200 Subject: added parent to control parent is used to delete the objects if the parent is deleted --- src/menu/container.cpp | 3 ++- src/menu/container.hpp | 2 +- src/menu/control.cpp | 18 +++++++++++++++++- src/menu/control.hpp | 9 ++++++++- src/menu/drawable_control.cpp | 3 ++- src/menu/drawable_control.hpp | 2 +- src/menu/frame.cpp | 6 ++++-- src/menu/frame.hpp | 4 ++-- 8 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/menu/container.cpp b/src/menu/container.cpp index 57bac666..467e5aa5 100644 --- a/src/menu/container.cpp +++ b/src/menu/container.cpp @@ -28,7 +28,8 @@ namespace usdx { - Container::Container() + Container::Container(Control* parent) + : DrawableControl(parent) { } diff --git a/src/menu/container.hpp b/src/menu/container.hpp index d85320a2..271a4f67 100644 --- a/src/menu/container.hpp +++ b/src/menu/container.hpp @@ -38,7 +38,7 @@ namespace usdx std::list controls; public: - Container(); + Container(Control* parent); virtual ~Container(); /** diff --git a/src/menu/control.cpp b/src/menu/control.cpp index 373fb482..68b5c328 100644 --- a/src/menu/control.cpp +++ b/src/menu/control.cpp @@ -24,15 +24,31 @@ * $Id$ */ +#include #include "control.hpp" namespace usdx { - Control::Control() + Control::Control(Control *parent) + : parent(parent) { } Control::~Control() { + if (parent) { + delete parent; + parent = NULL; + } + } + + void Control::set_parent(Control *parent) + { + this->parent = parent; + } + + Control* Control::get_parent(void) const + { + return parent; } }; diff --git a/src/menu/control.hpp b/src/menu/control.hpp index 2d47eb55..d0b70d4f 100644 --- a/src/menu/control.hpp +++ b/src/menu/control.hpp @@ -31,9 +31,16 @@ namespace usdx { class Control { + private: + Control* parent; + public: - Control(); + Control(Control *parent); virtual ~Control(); + + void set_parent(Control *parent); + + Control* get_parent(void) const; }; }; diff --git a/src/menu/drawable_control.cpp b/src/menu/drawable_control.cpp index 404b0e4c..895193f4 100644 --- a/src/menu/drawable_control.cpp +++ b/src/menu/drawable_control.cpp @@ -28,7 +28,8 @@ namespace usdx { - DrawableControl::DrawableControl() + DrawableControl::DrawableControl(Control* parent) + : Control(parent) { } diff --git a/src/menu/drawable_control.hpp b/src/menu/drawable_control.hpp index 612e17d3..60701f4b 100644 --- a/src/menu/drawable_control.hpp +++ b/src/menu/drawable_control.hpp @@ -42,7 +42,7 @@ namespace usdx virtual void draw(void) const = 0; public: - DrawableControl(); + DrawableControl(Control* parent); virtual ~DrawableControl(); }; }; diff --git a/src/menu/frame.cpp b/src/menu/frame.cpp index 8707f0cc..665a2627 100644 --- a/src/menu/frame.cpp +++ b/src/menu/frame.cpp @@ -28,11 +28,13 @@ namespace usdx { - Frame::Frame() : background(NULL) + Frame::Frame(Control* parent) + : Container(parent), background(NULL) { } - Frame::Frame(FrameBackground* background) : background(background) + Frame::Frame(Control* parent, FrameBackground* background) + : Container(parent), background(background) { } diff --git a/src/menu/frame.hpp b/src/menu/frame.hpp index 7f9af120..e71bef9b 100644 --- a/src/menu/frame.hpp +++ b/src/menu/frame.hpp @@ -41,8 +41,8 @@ namespace usdx virtual void draw(void) const; public: - Frame(); - Frame(FrameBackground* background); + Frame(Control* parent); + Frame(Control* parent, FrameBackground* background); virtual ~Frame(); -- cgit v1.2.3