X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flist.cpp;h=2c13ccca8e2d403a8911c8061e0f502a60a60901;hb=ec63df81f6c3f77454b0fe3bdae24876c84616b1;hp=378bf707c1a7d702f2192d50b0da8cd2ea70d9bc;hpb=d75275638b2dfeb5e346c42ec2c4498da3671042;p=libs%2Fgltk.git diff --git a/source/list.cpp b/source/list.cpp index 378bf70..2c13ccc 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -31,6 +31,7 @@ void List::init() sel_index = -1; first = 0; max_scroll = 0; + view_size = 5; observer = new DataObserver(*this); @@ -46,46 +47,29 @@ List::~List() delete data; } -void List::autosize() +void List::autosize_special(const Part &part, Geometry &ageom) { - autosize_rows(5); -} - -void List::autosize_rows(unsigned n) -{ - if(!style) - return; - - Widget::autosize(); - - if(const Part *items_part = style->get_part("items")) + if(part.get_name()=="items") { - const Sides &margin = items_part->get_margin(); + const Sides &margin = part.get_margin(); unsigned max_w = 0; unsigned total_h = 0; - for(unsigned i=0; (iautosize(); const Geometry &igeom = items[i]->get_geometry(); max_w = max(max_w, igeom.w); - total_h += igeom.h; + if(view_size==0 || isize()); } void List::set_data(ListData &d) @@ -113,6 +97,17 @@ List::Item *List::create_item(unsigned index) return new BasicItem(data->get_string(index)); } +void List::set_view_size(unsigned s) +{ + view_size = s; + signal_autosize_changed.emit(); +} + +void List::set_view_all() +{ + set_view_size(0); +} + void List::set_selected_index(int i) { if(i>static_cast(data->size())) @@ -122,7 +117,7 @@ void List::set_selected_index(int i) items[sel_index]->set_active(false); if(i<0) sel_index = -1; - else + else if(i!=sel_index) { sel_index = i; items[sel_index]->set_active(true); @@ -310,25 +305,16 @@ void List::DataObserver::refresh_strings() } -List::Loader::Loader(List &l): - Widget::Loader(l) -{ - add("item", &Loader::item); -} - - -void List::Item::autosize() +void List::Item::autosize_special(const Part &part, Geometry &ageom) { - Widget::autosize(); - - if(const Part *part = style->get_part("children")) + if(part.get_name()=="children") { - const Sides &margin = part->get_margin(); + const Sides &margin = part.get_margin(); for(list::const_iterator i=children.begin(); i!=children.end(); ++i) { const Geometry &cgeom = (*i)->widget->get_geometry(); - geom.w = max(geom.w, cgeom.x+cgeom.w+margin.right); - geom.h = max(geom.h, cgeom.y+cgeom.h+margin.top); + ageom.w = max(ageom.w, cgeom.x+cgeom.w+margin.right); + ageom.h = max(ageom.h, cgeom.y+cgeom.h+margin.top); } } } @@ -368,9 +354,16 @@ void List::BasicItem::on_style_change() } +List::Loader::Loader(List &l): + DataFile::DerivedObjectLoader(l) +{ + add("item", &Loader::item); + add("view_size", &List::view_size); +} + void List::Loader::item(const string &v) { - dynamic_cast &>(*dynamic_cast(obj).data).append(v); + dynamic_cast &>(*obj.data).append(v); } } // namespace GLtk