list->append(item);
}
+void Dropdown::insert(unsigned i, const string &v)
+{
+ list->insert(i, v);
+}
+
+void Dropdown::remove(unsigned i)
+{
+ list->remove(i);
+}
+
+void Dropdown::clear()
+{
+ list->clear();
+}
+
+void Dropdown::set_selected_index(int i)
+{
+ list->set_selected_index(i);
+}
+
+const string &Dropdown::get_selected() const
+{
+ return list->get_selected();
+}
+
+int Dropdown::get_selected_index() const
+{
+ return list->get_selected_index();
+}
+
void Dropdown::button_press(int x, int y, unsigned btn)
{
if(list->get_geometry().is_inside(x, y))
{
text=item;
- list_active=false;
- dropped=false;
- state&=~ACTIVE;
- if(parent)
- parent->ungrab_pointer(*this);
+ if(dropped)
+ {
+ list_active=false;
+ dropped=false;
+ state&=~ACTIVE;
+ if(parent)
+ parent->ungrab_pointer(*this);
+ }
signal_item_selected.emit(index, item);
}
~Dropdown();
void append(const std::string &);
+ void insert(unsigned, const std::string &);
+ void remove(unsigned);
+ void clear();
+
+ void set_selected_index(int);
+ const std::string &get_selected() const;
+ int get_selected_index() const;
virtual void button_press(int, int, unsigned);
virtual void button_release(int, int, unsigned);
virtual void pointer_motion(int, int);
+
private:
virtual const char *get_class() const { return "dropdown"; }
virtual void render_special(const Part &) const;
sel_index=-1;
}
+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
{
if(sel_index<0)
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)
{
void remove(unsigned);
void clear();
+ void set_selected_index(int);
const std::string &get_selected() const;
int get_selected_index() const { return sel_index; }