fix bluescreen in ci menu when no entries in a menulist an ok is pressed
[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 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         eListbox *m_listbox;
52 #endif
53 };
54
55 class eListbox: public eWidget
56 {
57         void updateScrollBar();
58 public:
59         eListbox(eWidget *parent);
60         ~eListbox();
61
62         PSignal0<void> selectionChanged;
63
64         enum {
65                 showOnDemand,
66                 showAlways,
67                 showNever
68         };
69         void setScrollbarMode(int mode);
70         void setWrapAround(bool);
71
72         void setContent(iListboxContent *content);
73         
74 /*      enum Movement {
75                 moveUp,
76                 moveDown,
77                 moveTop,
78                 moveEnd,
79                 justCheck
80         }; */
81
82         int getCurrentIndex();
83         void moveSelection(int how);
84         void moveSelectionTo(int index);
85         void moveToEnd();
86         bool atBegin();
87         bool atEnd();
88
89         enum ListboxActions {
90                 moveUp,
91                 moveDown,
92                 moveTop,
93                 moveEnd,
94                 pageUp,
95                 pageDown,
96                 justCheck
97         };
98         
99         void setItemHeight(int h);
100         void setSelectionEnable(int en);
101 #ifndef SWIG
102                 /* entryAdded: an entry was added *before* the given index. it's index is the given number. */
103         void entryAdded(int index);
104                 /* entryRemoved: an entry with the given index was removed. */
105         void entryRemoved(int index);
106                 /* entryChanged: the entry with the given index was changed and should be redrawn. */
107         void entryChanged(int index);
108                 /* the complete list changed. you should not attemp to keep the current index. */
109         void entryReset(bool cursorHome=true);
110
111 protected:
112         int event(int event, void *data=0, void *data2=0);
113         void recalcSize();
114
115 private:
116         int m_scrollbar_mode, m_prev_scrollbar_page;
117         bool m_content_changed;
118         bool m_enabled_wrap_around;
119
120         int m_top, m_selected;
121         int m_itemheight;
122         int m_items_per_page;
123         int m_selection_enabled;
124         ePtr<iListboxContent> m_content;
125         eSlider *m_scrollbar;
126 #endif
127 };
128
129 #endif