-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#ifndef MSP_GLTK_LIST_H_
#define MSP_GLTK_LIST_H_
#include <sigc++/signal.h>
-#include "widget.h"
+#include "container.h"
+#include "listdata.h"
+#include "vslider.h"
namespace Msp {
namespace GLtk {
-class VSlider;
-
/**
Shows a list of items, allowing the user to select one. A slider is included
to allow scrolling through a long list.
*/
-class List: public Widget
+class List: virtual public Widget, private Container
{
public:
class Loader: public Widget::Loader
};
private:
- std::vector<std::string> items;
+ /// This exists to make disconnecting signals easier
+ class DataObserver: public sigc::trackable
+ {
+ private:
+ List &list;
+
+ public:
+ DataObserver(List &);
+
+ void item_added(unsigned);
+ void item_removed(unsigned);
+ void cleared();
+ void refresh_strings();
+ };
+
+public:
+ sigc::signal<void, unsigned> signal_item_selected;
+
+private:
+ ListData *data;
+ bool own_data;
+ DataObserver *observer;
int sel_index;
unsigned first;
unsigned n_visible;
+ unsigned row_height;
const Part *items_part;
- VSlider *slider;
- bool slider_active;
+ VSlider slider;
public:
- sigc::signal<void, unsigned, const std::string &> signal_item_selected;
+ List();
+ List(ListData &);
+private:
+ void init();
+public:
+ virtual ~List();
- List(const Resources &);
- void append(const std::string &);
- void insert(unsigned, const std::string &);
- void remove(unsigned);
- void clear();
+ virtual const char *get_class() const { return "list"; }
- const std::string &get_selected() const;
- int get_selected_index() const { return sel_index; }
+ virtual void autosize();
+ void autosize_rows(unsigned);
+ void autosize_all();
- virtual void button_press(int, int, unsigned);
- virtual void button_release(int, int, unsigned);
- virtual void pointer_motion(int, int);
+ void set_data(ListData &);
+ ListData &get_data() { return *data; }
+ const ListData &get_data() const { return *data; }
+private:
+ void items_changed();
+public:
+
+ void set_selected_index(int);
+ int get_selected_index() const { return sel_index; }
private:
- virtual const char *get_class() const { return "list"; }
- virtual void render_special(const Part &) const;
+ virtual void rebuild_special(const Part &, CachedPart &);
+ virtual void render_special(const Part &, GL::Renderer &) const;
+public:
+ virtual void button_press(int, int, unsigned);
+private:
virtual void on_geometry_change();
virtual void on_style_change();
+
void reposition_slider();
- void recalculate_parameters();
+ void check_view_range();
void slider_value_changed(double);
};