X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcontainer.cpp;h=bec206602a95248c72f53ad4de28f41444b71659;hb=c8f5fd14a1fbdaaa9e1216dd5163d1f5c1b5ff27;hp=b2b8c56adaec281394847f0d954d9f516e5859a6;hpb=91997dd3189b93a67179822ec2fed5f2a7bddb74;p=libs%2Fgltk.git diff --git a/source/container.cpp b/source/container.cpp index b2b8c56..bec2066 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include "container.h" using namespace std; @@ -12,6 +5,11 @@ using namespace std; namespace Msp { namespace GLtk { +hierarchy_error::hierarchy_error(const string &w): + logic_error(w) +{ } + + Container::Container(): click_focus(0), click_button(0) @@ -25,8 +23,9 @@ Container::~Container() void Container::add(Widget &wdg) { - set_parent(wdg, this); + wdg.set_parent(this); children.push_back(create_child(&wdg)); + on_child_added(wdg); } void Container::remove(Widget &wdg) @@ -34,13 +33,19 @@ void Container::remove(Widget &wdg) for(list::iterator i=children.begin(); i!=children.end(); ++i) if((*i)->widget==&wdg) { - set_parent(wdg, 0); + wdg.set_parent(0); delete *i; children.erase(i); + on_child_removed(wdg); return; } - throw InvalidState("That Widget is not in this Container"); + throw hierarchy_error("widget not in container"); +} + +Container::Child *Container::create_child(Widget *wdg) +{ + return new Child(*this, wdg); } list Container::get_children() const @@ -139,18 +144,13 @@ void Container::pointer_leave() click_focus = 0; } -Container::Child *Container::create_child(Widget *wdg) -{ - return new Child(*this, wdg); -} - void Container::on_reparent() { for(list::iterator i=children.begin(); i!=children.end(); ++i) { if(Container *c = dynamic_cast((*i)->widget)) c->on_reparent(); - update_style(*(*i)->widget); + (*i)->widget->update_style(); } }