]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/panel.cpp
Make widgets aware of their parents
[libs/gltk.git] / source / panel.cpp
index efe857ec6860be568acc50b4e37134cd2f85ec44..36585c97716778431c96cdcf4285c2cbaedc1b5b 100644 (file)
@@ -1,4 +1,12 @@
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <msp/core/refptr.h>
+#include "button.h"
 #include "label.h"
 #include "panel.h"
 #include "part.h"
@@ -19,8 +27,24 @@ Panel::Panel(const Resources &r):
 
 Panel::~Panel()
 {
-       for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i)
-               delete *i;
+       while(!children.empty())
+               delete children.front();
+}
+
+void Panel::add(Widget &wdg)
+{
+       set_parent(wdg, this);
+       children.push_back(&wdg);
+}
+
+void Panel::remove(Widget &wdg)
+{
+       ChildSeq::iterator i=find(children.begin(), children.end(), &wdg);
+       if(i!=children.end())
+       {
+               set_parent(wdg, 0);
+               children.erase(i);
+       }
 }
 
 void Panel::button_press(int x, int y, unsigned btn)
@@ -88,11 +112,6 @@ void Panel::focus_out()
        set_input_focus(0);
 }
 
-void Panel::add(Widget &wdg)
-{
-       children.push_back(&wdg);
-}
-
 void Panel::render_part(const Part &part) const
 {
        if(part.get_name()=="children")
@@ -148,8 +167,9 @@ Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
        pnl(p),
        wdg_map(m)
 {
-       add("label", &Loader::child<Label>);
-       add("panel", &Loader::panel);
+       add("button", &Loader::child<Button>);
+       add("label",  &Loader::child<Label>);
+       add("panel",  &Loader::panel);
 }
 
 template<typename T>