bouquets and lamedb now stored in /etc/enigma2 (CONFIGDIR/enigma2)
[enigma2.git] / 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 eSlider;
8
9 class iListboxContent: public iObject
10 {
11 public:
12         virtual ~iListboxContent()=0;
13         
14                 /* indices go from 0 to size().
15                    the end is reached when the cursor is on size(), 
16                    i.e. one after the last entry (this mimics 
17                    stl behaviour)
18                    
19                    cursors never invalidate - they can become invalid
20                    when stuff is removed. Cursors will always try
21                    to stay on the same data, however when the current
22                    item is removed, this won't work. you'll be notified
23                    anyway. */
24 #ifndef SWIG    
25 protected:
26         iListboxContent();
27         friend class eListbox;
28         virtual void cursorHome()=0;
29         virtual void cursorEnd()=0;
30         virtual int cursorMove(int count=1)=0;
31         virtual int cursorValid()=0;
32         virtual int cursorSet(int n)=0;
33         virtual int cursorGet()=0;
34         
35         virtual void cursorSave()=0;
36         virtual void cursorRestore()=0;
37         
38         virtual int size()=0;
39         
40         void setListbox(eListbox *lb);
41         
42         // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though
43         virtual void setSize(const eSize &size)=0;
44         
45                 /* the following functions always refer to the selected item */
46         virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)=0;
47         
48         eListbox *m_listbox;
49 #endif
50 };
51
52 class eListbox: public eWidget
53 {
54         void updateScrollBar();
55 public:
56         eListbox(eWidget *parent);
57         ~eListbox();
58
59         enum {
60                 showOnDemand,
61                 showAlways,
62                 showNever
63         };
64         void setScrollbarMode(int mode);
65
66         void setContent(iListboxContent *content);
67         
68 /*      enum Movement {
69                 moveUp,
70                 moveDown,
71                 moveTop,
72                 moveEnd,
73                 justCheck
74         }; */
75
76         int getCurrentIndex();
77         void moveSelection(int how);
78         void moveSelectionTo(int index);
79
80         enum ListboxActions {
81                 moveUp,
82                 moveDown,
83                 moveTop,
84                 moveEnd,
85                 pageUp,
86                 pageDown,
87                 justCheck
88         };
89         
90         void setItemHeight(int h);
91         void setSelectionEnable(int en);
92
93 #ifndef SWIG
94                 /* entryAdded: an entry was added *before* the given index. it's index is the given number. */
95         void entryAdded(int index);
96                 /* entryRemoved: an entry with the given index was removed. */
97         void entryRemoved(int index);
98                 /* entryChanged: the entry with the given index was changed and should be redrawn. */
99         void entryChanged(int index);
100                 /* the complete list changed. you should not attemp to keep the current index. */
101         void entryReset(bool cursorHome=true);
102
103 protected:
104         int event(int event, void *data=0, void *data2=0);
105         void recalcSize();
106
107 private:
108         int m_scrollbar_mode, m_prev_scrollbar_page;
109         bool m_content_changed;
110
111         int m_top, m_selected;
112         int m_itemheight;
113         int m_items_per_page;
114         int m_selection_enabled;
115         ePtr<iListboxContent> m_content;
116         eSlider *m_scrollbar;
117 #endif
118 };
119
120 #endif