X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcontainer.cpp;h=4c0ce93fa6fda1a5fca02860cc793e13e9bb2a03;hb=9bfda3958f5b610c4513a912f4cd07d703d3d184;hp=a755644bab6283bf3b6f7eb575befba32a3003d6;hpb=8a0058b5b90bb7e9eacf1646142f4d73b426fd66;p=libs%2Fgltk.git diff --git a/source/container.cpp b/source/container.cpp index a755644..4c0ce93 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgltk -Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2011 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -12,8 +12,7 @@ using namespace std; namespace Msp { namespace GLtk { -Container::Container(const Resources &r): - Widget(r), +Container::Container(): click_focus(0), click_button(0) { } @@ -26,8 +25,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) @@ -35,15 +35,21 @@ 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"); } +Container::Child *Container::create_child(Widget *wdg) +{ + return new Child(*this, wdg); +} + list Container::get_children() const { list result; @@ -63,11 +69,13 @@ Widget *Container::get_child_at(int x, int y) Widget *Container::get_descendant_at(int x, int y) { - Widget *wdg=get_child_at(x, y); - if(Container *cont=dynamic_cast(wdg)) + Widget *wdg = get_child_at(x, y); + if(Container *cont = dynamic_cast(wdg)) { - const Geometry &cgeom=wdg->get_geometry(); - return cont->get_descendant_at(x-cgeom.x, y-cgeom.y); + const Geometry &cgeom = wdg->get_geometry(); + Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y); + if(wdg2) + return wdg2; } return wdg; } @@ -76,17 +84,17 @@ void Container::button_press(int x, int y, unsigned btn) { if(click_focus) { - const Geometry &cgeom=click_focus->get_geometry(); + const Geometry &cgeom = click_focus->get_geometry(); click_focus->button_press(x-cgeom.x, y-cgeom.y, btn); } else { - if(Widget *wdg=get_child_at(x, y)) + if(Widget *wdg = get_child_at(x, y)) { - click_focus=wdg; - click_button=btn; + click_focus = wdg; + click_button = btn; - const Geometry &cgeom=wdg->get_geometry(); + const Geometry &cgeom = wdg->get_geometry(); wdg->button_press(x-cgeom.x, y-cgeom.y, btn); } } @@ -96,19 +104,19 @@ void Container::button_release(int x, int y, unsigned btn) { if(click_focus) { - Widget *wdg=click_focus; + Widget *wdg = click_focus; if(btn==click_button) - click_focus=0; + click_focus = 0; - const Geometry &cgeom=wdg->get_geometry(); + const Geometry &cgeom = wdg->get_geometry(); wdg->button_release(x-cgeom.x, y-cgeom.y, btn); } else { - if(Widget *wdg=get_child_at(x, y)) + if(Widget *wdg = get_child_at(x, y)) { - const Geometry &cgeom=wdg->get_geometry(); + const Geometry &cgeom = wdg->get_geometry(); wdg->button_release(x-cgeom.x, y-cgeom.y, btn); } } @@ -118,15 +126,15 @@ void Container::pointer_motion(int x, int y) { if(click_focus) { - const Geometry &cgeom=click_focus->get_geometry(); + const Geometry &cgeom = click_focus->get_geometry(); click_focus->pointer_motion(x-cgeom.x, y-cgeom.y); } else { - Widget *wdg=get_child_at(x, y); + Widget *wdg = get_child_at(x, y); if(wdg) { - const Geometry &cgeom=wdg->get_geometry(); + const Geometry &cgeom = wdg->get_geometry(); wdg->pointer_motion(x-cgeom.x, y-cgeom.y); } } @@ -135,12 +143,17 @@ void Container::pointer_motion(int x, int y) void Container::pointer_leave() { Widget::pointer_leave(); - click_focus=0; + click_focus = 0; } -Container::Child *Container::create_child(Widget *wdg) +void Container::on_reparent() { - return new Child(*this, wdg); + for(list::iterator i=children.begin(); i!=children.end(); ++i) + { + if(Container *c = dynamic_cast((*i)->widget)) + c->on_reparent(); + (*i)->widget->update_style(); + } } @@ -154,13 +167,13 @@ Container::Child::Child(Container &c, Widget *w): Container::Child::~Child() { if(widget==container.click_focus) - container.click_focus=0; + container.click_focus = 0; } void Container::Child::visibility_changed(bool v) { if(!v && widget==container.click_focus) - container.click_focus=0; + container.click_focus = 0; } } // namespace GLtk