]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/widget.cpp
Make widgets aware of their parents
[libs/gltk.git] / source / widget.cpp
index e20ea82b56fcf085a2cab9a8eb7a1e0e96aaad19..e41310a50c5fd5cba82298dd3149983b16a0f8a1 100644 (file)
@@ -7,6 +7,7 @@ Distributed under the LGPL
 
 #include <msp/gl/matrix.h>
 #include <msp/gl/transform.h>
+#include "panel.h"
 #include "resources.h"
 #include "widget.h"
 
@@ -19,9 +20,16 @@ Widget::Widget(const Resources &r):
        res(r),
        style(0),
        state(NORMAL),
-       visible(true)
+       visible(true),
+       parent(0)
 { }
 
+Widget::~Widget()
+{
+       if(parent)
+               parent->remove(*this);
+}
+
 void Widget::set_position(int x, int y)
 {
        geom.x=x;
@@ -100,6 +108,18 @@ void Widget::update_style()
        style=res.get<Style>(sname);
 }
 
+void Widget::set_parent(Panel *p)
+{
+       if(parent && p)
+               throw InvalidState("Widget is already in a Panel");
+       parent=p;
+}
+
+void Widget::set_parent(Widget &w, Panel *p)
+{
+       w.set_parent(p);
+}
+
 
 Widget::Loader::Loader(Widget &w):
        wdg(w)