Support turbo2.
[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 behavior)
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 updateClip(gRegion &){ };
30         virtual void cursorHome()=0;
31         virtual void cursorEnd()=0;
32         virtual int cursorMove(int count=1)=0;
33         virtual int cursorValid()=0;
34         virtual int cursorSet(int n)=0;
35         virtual int cursorGet()=0;
36         
37         virtual void cursorSave()=0;
38         virtual void cursorRestore()=0;
39         
40         virtual int size()=0;
41         
42         virtual int currentCursorSelectable();
43         
44         void setListbox(eListbox *lb);
45         
46         // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though
47         virtual void setSize(const eSize &size)=0;
48         
49                 /* the following functions always refer to the selected item */
50         virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)=0;
51         
52         virtual int getItemHeight()=0;
53         
54         eListbox *m_listbox;
55 #endif
56 };
57
58 #ifndef SWIG
59 struct eListboxStyle
60 {
61         ePtr<gPixmap> m_background, m_selection;
62         int m_transparent_background;
63         gRGB m_background_color, m_background_color_selected, m_foreground_color, m_foreground_color_selected;
64         int m_background_color_set, m_foreground_color_set, m_background_color_selected_set, m_foreground_color_selected_set;
65
66                 /*
67                         {m_transparent_background m_background_color_set m_background}
68                         {0 0 0} use global background color
69                         {0 1 x} use background color
70                         {0 0 p} use background picture
71                         {1 x 0} use transparent background
72                         {1 x p} use transparent background picture
73                 */
74         ePtr<gFont> m_font;
75 };
76 #endif
77
78 class eListbox: public eWidget
79 {
80         void updateScrollBar();
81 public:
82         eListbox(eWidget *parent);
83         ~eListbox();
84
85         PSignal0<void> selectionChanged;
86
87         enum {
88                 showOnDemand,
89                 showAlways,
90                 showNever
91         };
92         void setScrollbarMode(int mode);
93         void setWrapAround(bool);
94
95         void setContent(iListboxContent *content);
96
97 /*      enum Movement {
98                 moveUp,
99                 moveDown,
100                 moveTop,
101                 moveEnd,
102                 justCheck
103         }; */
104
105         int getCurrentIndex();
106         void moveSelection(long how);
107         void moveSelectionTo(int index);
108         void moveToEnd();
109         bool atBegin();
110         bool atEnd();
111
112         enum ListboxActions {
113                 moveUp,
114                 moveDown,
115                 moveTop,
116                 moveEnd,
117                 pageUp,
118                 pageDown,
119                 justCheck
120         };
121
122         void setItemHeight(int h);
123         void setSelectionEnable(int en);
124
125         void setBackgroundColor(gRGB &col);
126         void setBackgroundColorSelected(gRGB &col);
127         void setForegroundColor(gRGB &col);
128         void setForegroundColorSelected(gRGB &col);
129         void setBackgroundPicture(ePtr<gPixmap> &pixmap);
130         void setSelectionPicture(ePtr<gPixmap> &pixmap);
131         void setFont(gFont *font);
132
133 #ifndef SWIG
134         struct eListboxStyle *getLocalStyle(void);
135
136                 /* entryAdded: an entry was added *before* the given index. it's index is the given number. */
137         void entryAdded(int index);
138                 /* entryRemoved: an entry with the given index was removed. */
139         void entryRemoved(int index);
140                 /* entryChanged: the entry with the given index was changed and should be redrawn. */
141         void entryChanged(int index);
142                 /* the complete list changed. you should not attemp to keep the current index. */
143         void entryReset(bool cursorHome=true);
144
145         int getEntryTop();
146         void invalidate(const gRegion &region = gRegion::invalidRegion());
147 protected:
148         int event(int event, void *data=0, void *data2=0);
149         void recalcSize();
150
151 private:
152         int m_scrollbar_mode, m_prev_scrollbar_page;
153         bool m_content_changed;
154         bool m_enabled_wrap_around;
155
156         int m_top, m_selected;
157         int m_itemheight;
158         int m_items_per_page;
159         int m_selection_enabled;
160         ePtr<iListboxContent> m_content;
161         eSlider *m_scrollbar;
162         eListboxStyle m_style;
163 #ifdef USE_LIBVUGLES2
164         long m_dir;
165 #endif
166 #endif
167 };
168
169 #endif