X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpanel.cpp;h=836d991eb73e3b226d859b5c2c4a2da7acf5037a;hb=31e9ee682f8a9cd77c97ed9dc142283559ddaacc;hp=f17439a5eca810b8510d3537fc750a53c2b5868a;hpb=95210598ff214bbc8d05657aeffc4ce7801f211a;p=libs%2Fgltk.git diff --git a/source/panel.cpp b/source/panel.cpp index f17439a..836d991 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -1,20 +1,20 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include +#include #include #include "button.h" +#include "column.h" +#include "draghandle.h" #include "dropdown.h" #include "entry.h" +#include "grid.h" #include "hslider.h" #include "indicator.h" #include "label.h" #include "list.h" #include "panel.h" #include "part.h" +#include "row.h" +#include "stack.h" #include "toggle.h" #include "vslider.h" @@ -23,235 +23,174 @@ using namespace std; namespace Msp { namespace GLtk { -Panel::Panel(const Resources &r): - Widget(r), - pointer_focus(0), - pointer_grab(0), - input_focus(0) -{ - update_style(); -} +Panel::Panel(): + layout(0) +{ } Panel::~Panel() { - while(!children.empty()) - delete children.front(); + delete layout; + layout = 0; } -void Panel::add(Widget &wdg) +void Panel::set_layout(Layout *l) { - set_parent(wdg, this); - children.push_back(&wdg); + l->set_container(*this); + delete layout; + layout = l; } -void Panel::remove(Widget &wdg) +void Panel::autosize_special(const Part &part, Geometry &ageom) { - ChildSeq::iterator i=find(children.begin(), children.end(), &wdg); - if(i!=children.end()) - { - set_parent(wdg, 0); - children.erase(i); - } + if(part.get_name()=="children" && layout) + layout->autosize(ageom); } -void Panel::raise(Widget &wdg) +void Panel::render_special(const Part &part, GL::Renderer &renderer) const { - ChildSeq::iterator i=find(children.begin(), children.end(), &wdg); - if(i!=children.end()) + if(part.get_name()=="children") { - children.erase(i); - children.push_back(&wdg); + for(list::const_iterator i=children.begin(); i!=children.end(); ++i) + if((*i)->widget->is_visible()) + (*i)->widget->render(renderer); } } -void Panel::button_press(int x, int y, unsigned btn) +void Panel::on_geometry_change() { - if(pointer_grab>0) - { - const Geometry &cgeom=pointer_focus->get_geometry(); - pointer_focus->button_press(x-cgeom.x, y-cgeom.y, btn); - } - else if(geom.is_inside_relative(x, y)) - { - if(Widget *wdg=get_child_at(x, y)) - { - set_pointer_focus(wdg, btn); - set_input_focus(wdg); - - const Geometry &cgeom=wdg->get_geometry(); - wdg->button_press(x-cgeom.x, y-cgeom.y, btn); - } - } + if(layout) + layout->update(); } -void Panel::button_release(int x, int y, unsigned btn) +void Panel::on_child_added(Widget &wdg) { - if(pointer_grab>0) + if(layout) { - const Geometry &cgeom=pointer_focus->get_geometry(); - pointer_focus->button_release(x-cgeom.x, y-cgeom.y, btn); - - if(btn==pointer_grab) - set_pointer_focus(get_child_at(x, y), 0); - } - else if(geom.is_inside_relative(x, y)) - { - if(Widget *wdg=get_child_at(x, y)) - { - const Geometry &cgeom=wdg->get_geometry(); - wdg->button_release(x-cgeom.x, y-cgeom.y, btn); - } + layout->add_widget(wdg); + signal_autosize_changed.emit(); } } -void Panel::pointer_motion(int x, int y) +void Panel::on_child_removed(Widget &wdg) { - if(pointer_grab>0) - { - const Geometry &cgeom=pointer_focus->get_geometry(); - pointer_focus->pointer_motion(x-cgeom.x, y-cgeom.y); - } - else if(geom.is_inside_relative(x, y)) + if(layout) { - Widget *wdg=get_child_at(x, y); - set_pointer_focus(wdg, 0); - if(wdg) - { - const Geometry &cgeom=wdg->get_geometry(); - wdg->pointer_motion(x-cgeom.x, y-cgeom.y); - } + layout->remove_widget(wdg); + signal_autosize_changed.emit(); } } -void Panel::pointer_leave() -{ - set_pointer_focus(0, 0); -} -void Panel::key_press(unsigned key, unsigned mod, wchar_t ch) +Panel::Loader::Loader(Panel &p, map &m): + DataFile::DerivedObjectLoader(p), + wdg_map(m), + last_widget(0) { - if(input_focus) - input_focus->key_press(key, mod, ch); + add("button", &Loader::child