- added ListBoxContents: based on std::list<std::string> and PyList with Strings
[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                   
23         virtual void cursorHome()=0;
24         virtual void cursorEnd()=0;
25         virtual int cursorMove(int count=1)=0;
26         virtual int cursorValid()=0;
27         virtual int cursorSet(int n)=0;
28         virtual int cursorGet()=0;
29         
30         virtual void cursorSave()=0;
31         virtual void cursorRestore()=0;
32         
33         virtual int size()=0;
34         
35         virtual RESULT connectItemChanged(const Slot0<void> &itemChanged, ePtr<eConnection> &connection)=0;
36         
37         // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though
38         virtual void setSize(const eSize &size)=0;
39         
40                 /* the following functions always refer to the selected item */
41         virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)=0;
42 };
43
44 class eListbox: public eWidget
45 {
46 public:
47         eListbox(eWidget *parent);
48         void setContent(iListboxContent *content);
49         
50         void moveSelection(int how);
51         enum {
52                 moveUp,
53                 moveDown,
54                 moveTop,
55                 moveEnd
56         };
57 protected:
58         int event(int event, void *data=0, void *data2=0);
59         void recalcSize();
60 private:
61         int m_top, m_selected;
62         int m_itemheight;
63         int m_items_per_page;
64         ePtr<iListboxContent> m_content;
65 };
66
67 #endif