]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/list.cpp
Clear focus in Panel if focused child is removed
[libs/gltk.git] / source / list.cpp
index 73f427bff7fdf2dbadb84eaa4e67b55152e27d0d..8c0d789188ab917221336d98f09efbc66bb561fe 100644 (file)
@@ -33,6 +33,11 @@ List::List(const Resources &r):
        update_style();
 }
 
+List::~List()
+{
+       delete slider;
+}
+
 void List::append(const string &v)
 {
        items.push_back(v);
@@ -66,6 +71,21 @@ void List::clear()
 {
        items.clear();
        sel_index=-1;
+
+       recalculate_parameters();
+}
+
+void List::set_selected_index(int i)
+{
+       if(i<0)
+               sel_index=-1;
+       else if(i<static_cast<int>(items.size()))
+       {
+               sel_index=i;
+               signal_item_selected.emit(sel_index, items[sel_index]);
+       }
+       else
+               throw InvalidParameterValue("Index out of range");
 }
 
 const string &List::get_selected() const
@@ -93,7 +113,7 @@ void List::button_press(int x, int y, unsigned btn)
                        y+=items_part->get_margin().top;
 
                unsigned i=(geom.h-1-y)/row_height;
-               if(i<n_visible)
+               if(i<n_visible && first+i<items.size())
                {
                        sel_index=first+i;
 
@@ -132,6 +152,7 @@ void List::render_special(const Part &part) const
 
                Geometry pgeom=geom;
                pgeom.h=row_height;
+               pgeom.w-=margin.left+margin.right;
 
                for(unsigned i=0; (i<n_visible && first+i<items.size()); ++i)
                {
@@ -242,7 +263,8 @@ void List::recalculate_parameters()
 
 void List::slider_value_changed(double value)
 {
-       first=items.size()-n_visible-static_cast<unsigned>(value);
+       if(items.size()>n_visible)
+               first=items.size()-n_visible-static_cast<unsigned>(value);
 }