fix warnings,
[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         void moveSelection(int how);
77         void moveSelectionTo(int index);
78
79         enum ListboxActions {
80                 moveUp,
81                 moveDown,
82                 moveTop,
83                 moveEnd,
84                 pageUp,
85                 pageDown,
86                 justCheck
87         };
88         
89         void setItemHeight(int h);
90         void setSelectionEnable(int en);
91
92 #ifndef SWIG
93                 /* entryAdded: an entry was added *before* the given index. it's index is the given number. */
94         void entryAdded(int index);
95                 /* entryRemoved: an entry with the given index was removed. */
96         void entryRemoved(int index);
97                 /* entryChanged: the entry with the given index was changed and should be redrawn. */
98         void entryChanged(int index);
99                 /* the complete list changed. you should not attemp to keep the current index. */
100         void entryReset();
101
102 protected:
103         int event(int event, void *data=0, void *data2=0);
104         void recalcSize();
105
106 private:
107         int m_scrollbar_mode, m_prev_scrollbar_page;
108         bool m_content_changed;
109
110         int m_top, m_selected;
111         int m_itemheight;
112         int m_items_per_page;
113         int m_selection_enabled;
114         ePtr<iListboxContent> m_content;
115         eSlider *m_scrollbar;
116 #endif
117 };
118
119 #endif