X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpanel.cpp;h=529ec199183d20e1b31cdb3675b3025450fb4ca5;hb=c2635c5a3dca6a6cea5562fd387beb0662b18cf0;hp=c93d430be07f16a988fa1a120af013104cd8889e;hpb=e7bc29984e91ee36555d6a4e4eece22170d10ba4;p=libs%2Fgltk.git diff --git a/source/panel.cpp b/source/panel.cpp index c93d430..529ec19 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -1,4 +1,12 @@ +/* $Id$ + +This file is part of libmspgltk +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + #include +#include "button.h" #include "label.h" #include "panel.h" #include "part.h" @@ -23,19 +31,23 @@ Panel::~Panel() delete *i; } +void Panel::add(Widget &wdg) +{ + children.push_back(&wdg); +} + void Panel::button_press(int x, int y, unsigned btn) { if(pointer_grab>0) pointer_focus->button_press(x-geom.x, y-geom.y, btn); else if(geom.is_inside(x, y)) { - for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) - { - (*i)->button_press(x-geom.x, y-geom.y, btn); - pointer_grab=btn; - set_input_focus(*i); - } + if(Widget *wdg=get_child_at(x, y)) + { + wdg->button_press(x-geom.x, y-geom.y, btn); + pointer_grab=btn; + set_input_focus(wdg); + } } } @@ -49,19 +61,13 @@ void Panel::button_release(int x, int y, unsigned btn) { pointer_grab=0; - for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) - { - set_pointer_focus(*i); - break; - } + set_pointer_focus(get_child_at(x, y)); } } else if(geom.is_inside(x, y)) { - for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) - (*i)->button_release(x-geom.x, y-geom.y, btn); + if(Widget *wdg=get_child_at(x, y)) + wdg->button_release(x-geom.x, y-geom.y, btn); } } @@ -71,17 +77,10 @@ void Panel::pointer_motion(int x, int y) pointer_focus->pointer_motion(x-geom.x, y-geom.y); else if(geom.is_inside(x, y)) { - bool found=false; - for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) - { - set_pointer_focus(*i); - (*i)->pointer_motion(x-geom.x, y-geom.y); - found=true; - } - - if(!found) - set_pointer_focus(0); + Widget *wdg=get_child_at(x, y); + set_pointer_focus(wdg); + if(wdg) + wdg->pointer_motion(x-geom.x, y-geom.y); } } @@ -102,17 +101,13 @@ void Panel::focus_out() set_input_focus(0); } -void Panel::add(Widget &wdg) -{ - children.push_back(&wdg); -} - void Panel::render_part(const Part &part) const { if(part.get_name()=="children") { for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i) - (*i)->render(); + if((*i)->is_visible()) + (*i)->render(); } else Widget::render_part(part); @@ -146,23 +141,42 @@ void Panel::set_input_focus(Widget *wdg) } } +Widget *Panel::get_child_at(int x, int y) +{ + for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i) + if((*i)->is_visible() && (*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) + return *i; + + return 0; +} + Panel::Loader::Loader(Panel &p, map &m): Widget::Loader(p), - panel(p), + pnl(p), wdg_map(m) { - add("label", &Loader::child