X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fwidget.cpp;h=1113c971974f84779a3ca863df1b57f4ddf973ea;hb=b30edd979e6e9c7acfaaf3a90903814a7e62a71e;hp=9dbd9da5ba2df7f60f44d824a8a7989d11d917dd;hpb=fdc7fecc65f5f517d66abe3546a949a46836c4a6;p=libs%2Fgltk.git diff --git a/source/widget.cpp b/source/widget.cpp index 9dbd9da..1113c97 100644 --- a/source/widget.cpp +++ b/source/widget.cpp @@ -30,18 +30,12 @@ Widget::~Widget() void Widget::set_position(int x, int y) { - geom.x = x; - geom.y = y; - on_geometry_change(); - rebuild(); + set_geometry(Geometry(x, y, geom.w, geom.h)); } void Widget::set_size(unsigned w, unsigned h) { - geom.w = w; - geom.h = h; - on_geometry_change(); - rebuild(); + set_geometry(Geometry(geom.x, geom.y, w, h)); } void Widget::autosize() @@ -52,8 +46,10 @@ void Widget::autosize() for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i) if(i->get_name().empty()) { - geom.w = max(geom.w, i->get_geometry().w); - geom.h = max(geom.h, i->get_geometry().h); + const Geometry &pgeom = i->get_geometry(); + const Sides &pmargin = i->get_margin(); + geom.w = max(geom.w, pgeom.w+pmargin.left+pmargin.right); + geom.h = max(geom.h, pgeom.h+pmargin.top+pmargin.bottom); } } @@ -70,10 +66,20 @@ void Widget::set_parent(Container *p) throw hierarchy_error("widget already parented"); else if(p==parent) return; - parent = p; - on_reparent(); - update_style(); + try + { + parent = p; + + on_reparent(); + update_style(); + } + catch(...) + { + // The container has not yet added the widget as its child + parent = 0; + throw; + } } void Widget::set_style(const string &s)