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)
{
if(pointer_grab>0)
~Panel();
void add(Widget &);
+ void remove(Widget &);
virtual void button_press(int, int, unsigned);
virtual void button_release(int, int, unsigned);
#include <msp/gl/matrix.h>
#include <msp/gl/transform.h>
+#include "panel.h"
#include "resources.h"
#include "widget.h"
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;
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)
namespace Msp {
namespace GLtk {
+class Panel;
class Part;
class Resources;
class Style;
const Style *style;
State state;
bool visible;
+ Panel *parent;
Widget(const Resources &);
public:
- virtual ~Widget() { }
+ virtual ~Widget();
void set_position(int, int);
void set_size(unsigned, unsigned);
void set_geometry(const Geometry &);
*/
virtual const char *get_class() const { return "widget"; }
+ /**
+ Gets a style object from the resource collection based on the class and
+ style names of the widget.
+ */
void update_style();
+
+ /**
+ Sets the widget's parent Panel. The widget must be unparented when calling
+ this function.
+ */
+ void set_parent(Panel *);
+
+ /**
+ A helper function to set the parent of another widget.
+ */
+ void set_parent(Widget &, Panel *);
};
} // namespace GLtk