/* $Id$
This file is part of libmspgltk
-Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
namespace Msp {
namespace GLtk {
-List::List(const Resources &r):
- Widget(r),
- Container(r),
+List::List():
sel_index(-1),
first(0),
n_visible(1),
row_height(1),
- items_part(0),
- slider(res)
+ items_part(0)
{
add(slider);
slider.set_step(1);
slider.signal_value_changed.connect(sigc::mem_fun(this, &List::slider_value_changed));
-
- update_style();
}
void List::autosize()
{
+ if(!style)
+ return;
+
float font_size = style->get_font()->get_default_size();
geom.w = 0;
return items[sel_index];
}
-void List::button_press(int x, int y, unsigned btn)
-{
- Container::button_press(x, y, btn);
- if(!click_focus && btn==1)
- {
- if(items_part)
- y += items_part->get_margin().top;
-
- unsigned i = (geom.h-1-y)/row_height;
- if(i<n_visible && first+i<items.size())
- {
- sel_index = first+i;
-
- signal_item_selected.emit(sel_index, items[sel_index]);
- }
- }
-}
-
void List::render_special(const Part &part) const
{
if(part.get_name()=="items")
slider.render();
}
+void List::button_press(int x, int y, unsigned btn)
+{
+ Container::button_press(x, y, btn);
+ if(!click_focus && btn==1)
+ {
+ if(items_part)
+ y += items_part->get_margin().top;
+
+ unsigned i = (geom.h-1-y)/row_height;
+ if(i<n_visible && first+i<items.size())
+ {
+ sel_index = first+i;
+
+ signal_item_selected.emit(sel_index, items[sel_index]);
+ }
+ }
+}
+
void List::on_geometry_change()
{
reposition_slider();
void List::on_style_change()
{
+ if(!style)
+ {
+ items_part = 0;
+ return;
+ }
+
reposition_slider();
items_part = style->get_part("items");
void List::reposition_slider()
{
+ if(!style)
+ return;
+
if(const Part *slider_part = style->get_part("slider"))
{
Geometry sgeom = slider_part->get_geometry();