]> git.tdb.fi Git - libs/gltk.git/blob - source/list.h
770cc2f4517366a0b777d3e33df26f7f86b1a31f
[libs/gltk.git] / source / list.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GLTK_LIST_H_
9 #define MSP_GLTK_LIST_H_
10
11 #include <sigc++/signal.h>
12 #include "widget.h"
13
14 namespace Msp {
15 namespace GLtk {
16
17 class VSlider;
18
19 /**
20 Shows a list of items, allowing the user to select one.  A slider is included
21 to allow scrolling through a long list.
22 */
23 class List: public Widget
24 {
25 public:
26         class Loader: public Widget::Loader
27         {
28         public:
29                 Loader(List &);
30         private:
31                 void item(const std::string &);
32         };
33
34 private:
35         std::vector<std::string> items;
36         int sel_index;
37         unsigned first;
38         unsigned n_visible;
39         unsigned row_height;
40
41         const Part *items_part;
42
43         VSlider *slider;
44         bool slider_active;
45
46 public:
47         sigc::signal<void, unsigned, const std::string &> signal_item_selected;
48
49         List(const Resources &);
50         ~List();
51
52         void append(const std::string &);
53         void insert(unsigned, const std::string &);
54         void remove(unsigned);
55         void clear();
56         unsigned get_n_items() const { return items.size(); }
57
58         void set_selected_index(int);
59         const std::string &get_selected() const;
60         int get_selected_index() const { return sel_index; }
61
62         virtual void button_press(int, int, unsigned);
63         virtual void button_release(int, int, unsigned);
64         virtual void pointer_motion(int, int);
65
66 private:
67         virtual const char *get_class() const { return "list"; }
68         virtual void render_special(const Part &) const;
69
70         virtual void on_geometry_change();
71         virtual void on_style_change();
72         void reposition_slider();
73         void recalculate_parameters();
74         void slider_value_changed(double);
75 };
76
77 } // namespace GLtk
78 } // namespace Msp
79
80 #endif