add ability to enable wrap around in listbox
[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         void setListbox(eListbox *lb);
42         
43         // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though
44         virtual void setSize(const eSize &size)=0;
45         
46                 /* the following functions always refer to the selected item */
47         virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)=0;
48         
49         eListbox *m_listbox;
50 #endif
51 };
52
53 class eListbox: public eWidget
54 {
55         void updateScrollBar();
56 public:
57         eListbox(eWidget *parent);
58         ~eListbox();
59
60         PSignal0<void> selectionChanged;
61
62         enum {
63                 showOnDemand,
64                 showAlways,
65                 showNever
66         };
67         void setScrollbarMode(int mode);
68         void setWrapAround(bool);
69
70         void setContent(iListboxContent *content);
71         
72 /*      enum Movement {
73                 moveUp,
74                 moveDown,
75                 moveTop,
76                 moveEnd,
77                 justCheck
78         }; */
79
80         int getCurrentIndex();
81         void moveSelection(int how);
82         void moveSelectionTo(int index);
83         void moveToEnd();
84         bool atBegin();
85         bool atEnd();
86
87         enum ListboxActions {
88                 moveUp,
89                 moveDown,
90                 moveTop,
91                 moveEnd,
92                 pageUp,
93                 pageDown,
94                 justCheck
95         };
96         
97         void setItemHeight(int h);
98         void setSelectionEnable(int en);
99 #ifndef SWIG
100                 /* entryAdded: an entry was added *before* the given index. it's index is the given number. */
101         void entryAdded(int index);
102                 /* entryRemoved: an entry with the given index was removed. */
103         void entryRemoved(int index);
104                 /* entryChanged: the entry with the given index was changed and should be redrawn. */
105         void entryChanged(int index);
106                 /* the complete list changed. you should not attemp to keep the current index. */
107         void entryReset(bool cursorHome=true);
108
109 protected:
110         int event(int event, void *data=0, void *data2=0);
111         void recalcSize();
112
113 private:
114         int m_scrollbar_mode, m_prev_scrollbar_page;
115         bool m_content_changed;
116         bool m_enabled_wrap_around;
117
118         int m_top, m_selected;
119         int m_itemheight;
120         int m_items_per_page;
121         int m_selection_enabled;
122         ePtr<iListboxContent> m_content;
123         eSlider *m_scrollbar;
124 #endif
125 };
126
127 #endif