X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=blobdiff_plain;f=source%2Fdropdown.cpp;h=cbd7ee437111bc3726b1c0ba988471638142140b;hp=a4816d48d593bb430e8b1aa764c35aac131b5744;hb=8a0058b5b90bb7e9eacf1646142f4d73b426fd66;hpb=1a5f227ac945bc9e6449d1552e5d9eb4c1c196fb diff --git a/source/dropdown.cpp b/source/dropdown.cpp index a4816d4..cbd7ee4 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgltk -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -19,19 +19,16 @@ namespace GLtk { Dropdown::Dropdown(const Resources &r): Widget(r), + Container(r), list(r), - dropped(false), - list_active(false) + dropped(false) { + add(list); list.signal_item_selected.connect(sigc::mem_fun(this, &Dropdown::list_item_selected)); update_style(); } -Dropdown::~Dropdown() -{ -} - void Dropdown::append(const string &item) { list.append(item); @@ -78,47 +75,21 @@ int Dropdown::get_selected_index() const void Dropdown::button_press(int x, int y, unsigned btn) { - if(list.get_geometry().is_inside(x, y)) - { - const Geometry &lgeom=list.get_geometry(); - list.button_press(x-lgeom.x, y-lgeom.y, btn); - list_active=true; - } - else if(dropped) + if(dropped) { - dropped=false; - state&=~ACTIVE; - parent->ungrab_pointer(*this); + Container::button_press(x, y, btn); + if(!click_focus) + { + dropped=false; + state&=~ACTIVE; + signal_ungrab_pointer.emit(); + } } else if(btn==1) { dropped=true; state|=ACTIVE; - - if(parent) - { - parent->raise(*this); - parent->grab_pointer(*this); - } - } -} - -void Dropdown::button_release(int x, int y, unsigned btn) -{ - if(list_active) - { - const Geometry &lgeom=list.get_geometry(); - list.button_release(x-lgeom.x, y-lgeom.y, btn); - list_active=false; - } -} - -void Dropdown::pointer_motion(int x, int y) -{ - if(list_active) - { - const Geometry &lgeom=list.get_geometry(); - list.pointer_motion(x-lgeom.x, y-lgeom.y); + signal_grab_pointer.emit(); } } @@ -144,7 +115,7 @@ void Dropdown::resize_list() unsigned n_items=list.get_n_items(); const Style &stl=list.get_style(); const GL::Font &font=*stl.get_font(); - unsigned h=min(max(n_items, 1U), 20U)*static_cast((font.get_ascent()-font.get_descent())*font.get_default_size()); + unsigned h=min(max(n_items, 1U), 10U)*static_cast((font.get_ascent()-font.get_descent())*font.get_default_size()); for(std::list::const_iterator i=stl.get_parts().begin(); i!=stl.get_parts().end(); ++i) if(i->get_name()=="items") { @@ -158,11 +129,9 @@ void Dropdown::list_item_selected(unsigned index, const std::string &item) { if(dropped) { - list_active=false; dropped=false; state&=~ACTIVE; - if(parent) - parent->ungrab_pointer(*this); + signal_ungrab_pointer.emit(); } signal_item_selected.emit(index, item); @@ -177,7 +146,7 @@ Dropdown::Loader::Loader(Dropdown &d): void Dropdown::Loader::item(const string &str) { - static_cast(wdg).append(str); + dynamic_cast(wdg).append(str); } } // namespace GLtk