add 'local style' for listboxes (still needs support in listbox content)
[vuplus_dvbapp] / lib / gui / elistbox.h
1 #ifndef __lib_listbox_h
2 #define __lib_listbox_h
3
4 #include <lib/gui/ewidget.h>
5 #include <connection.h>
6
7 class eListbox;
8 class eSlider;
9
10 class iListboxContent: public iObject
11 {
12 public:
13         virtual ~iListboxContent()=0;
14         
15                 /* indices go from 0 to size().
16                    the end is reached when the cursor is on size(), 
17                    i.e. one after the last entry (this mimics 
18                    stl behaviour)
19                    
20                    cursors never invalidate - they can become invalid
21                    when stuff is removed. Cursors will always try
22                    to stay on the same data, however when the current
23                    item is removed, this won't work. you'll be notified
24                    anyway. */
25 #ifndef SWIG    
26 protected:
27         iListboxContent();
28         friend class eListbox;
29         virtual void cursorHome()=0;
30         virtual void cursorEnd()=0;
31         virtual int cursorMove(int count=1)=0;
32         virtual int cursorValid()=0;
33         virtual int cursorSet(int n)=0;
34         virtual int cursorGet()=0;
35         
36         virtual void cursorSave()=0;
37         virtual void cursorRestore()=0;
38         
39         virtual int size()=0;
40         
41         virtual int currentCursorSelectable();
42         
43         void setListbox(eListbox *lb);
44         
45         // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though
46         virtual void setSize(const eSize &size)=0;
47         
48                 /* the following functions always refer to the selected item */
49         virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)=0;
50         
51         virtual int getItemHeight()=0;
52         
53         eListbox *m_listbox;
54 #endif
55 };
56
57 struct eListboxStyle
58 {
59         ePtr<gPixmap> m_background, m_selection;
60         int m_transparent_background;
61         gRGB m_background_color, m_foreground_color;
62         int m_background_color_set, m_foreground_color_set;
63
64                 /*
65                         {m_transparent_background m_background_color_set m_background}
66                         {0 0 0} use global background color
67                         {0 1 x} use background color
68                         {0 0 p} use background picture
69                         {1 x 0} use transparent background
70                         {1 x p} use transparent background picture
71                 */
72 };
73
74 class eListbox: public eWidget
75 {
76         void updateScrollBar();
77 public:
78         eListbox(eWidget *parent);
79         ~eListbox();
80
81         PSignal0<void> selectionChanged;
82
83         enum {
84                 showOnDemand,
85                 showAlways,
86                 showNever
87         };
88         void setScrollbarMode(int mode);
89         void setWrapAround(bool);
90
91         void setContent(iListboxContent *content);
92
93 /*      enum Movement {
94                 moveUp,
95                 moveDown,
96                 moveTop,
97                 moveEnd,
98                 justCheck
99         }; */
100
101         int getCurrentIndex();
102         void moveSelection(int how);
103         void moveSelectionTo(int index);
104         void moveToEnd();
105         bool atBegin();
106         bool atEnd();
107
108         enum ListboxActions {
109                 moveUp,
110                 moveDown,
111                 moveTop,
112                 moveEnd,
113                 pageUp,
114                 pageDown,
115                 justCheck
116         };
117
118         void setItemHeight(int h);
119         void setSelectionEnable(int en);
120
121         void setBackgroundColor(gRGB &col);
122         void setForegroundColor(gRGB &col);
123         void setTransparent(int t);
124         void setBackgroundPicture(gPixmap *pm);
125         void setSelectionPicture(gPixmap *pm);
126
127         struct eListboxStyle *getLocalStyle(void);
128 #ifndef SWIG
129                 /* entryAdded: an entry was added *before* the given index. it's index is the given number. */
130         void entryAdded(int index);
131                 /* entryRemoved: an entry with the given index was removed. */
132         void entryRemoved(int index);
133                 /* entryChanged: the entry with the given index was changed and should be redrawn. */
134         void entryChanged(int index);
135                 /* the complete list changed. you should not attemp to keep the current index. */
136         void entryReset(bool cursorHome=true);
137
138 protected:
139         int event(int event, void *data=0, void *data2=0);
140         void recalcSize();
141
142 private:
143         int m_scrollbar_mode, m_prev_scrollbar_page;
144         bool m_content_changed;
145         bool m_enabled_wrap_around;
146
147         int m_top, m_selected;
148         int m_itemheight;
149         int m_items_per_page;
150         int m_selection_enabled;
151         ePtr<iListboxContent> m_content;
152         eSlider *m_scrollbar;
153         eListboxStyle m_style;
154 #endif
155 };
156
157 #endif