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