1 #ifndef __lib_listbox_h
2 #define __lib_listbox_h
4 #include <lib/gui/ewidget.h>
5 #include <connection.h>
10 class iListboxContent: public iObject
13 virtual ~iListboxContent()=0;
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
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
28 friend class eListbox;
29 virtual void updateClip(gRegion &){ };
30 virtual void cursorHome()=0;
31 virtual void cursorEnd()=0;
32 virtual int cursorMove(int count=1)=0;
33 virtual int cursorValid()=0;
34 virtual int cursorSet(int n)=0;
35 virtual int cursorGet()=0;
37 virtual void cursorSave()=0;
38 virtual void cursorRestore()=0;
42 virtual int currentCursorSelectable();
44 void setListbox(eListbox *lb);
46 // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though
47 virtual void setSize(const eSize &size)=0;
49 /* the following functions always refer to the selected item */
50 virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)=0;
52 virtual int getItemHeight()=0;
61 ePtr<gPixmap> m_background, m_selection;
62 int m_transparent_background;
63 gRGB m_background_color, m_background_color_selected, m_foreground_color, m_foreground_color_selected;
64 int m_background_color_set, m_foreground_color_set, m_background_color_selected_set, m_foreground_color_selected_set;
67 {m_transparent_background m_background_color_set m_background}
68 {0 0 0} use global background color
69 {0 1 x} use background color
70 {0 0 p} use background picture
71 {1 x 0} use transparent background
72 {1 x p} use transparent background picture
77 class eListbox: public eWidget
79 void updateScrollBar();
81 eListbox(eWidget *parent);
84 PSignal0<void> selectionChanged;
91 void setScrollbarMode(int mode);
92 void setWrapAround(bool);
94 void setContent(iListboxContent *content);
104 int getCurrentIndex();
105 void moveSelection(int how);
106 void moveSelectionTo(int index);
111 enum ListboxActions {
121 void setItemHeight(int h);
122 void setSelectionEnable(int en);
124 void setBackgroundColor(gRGB &col);
125 void setBackgroundColorSelected(gRGB &col);
126 void setForegroundColor(gRGB &col);
127 void setForegroundColorSelected(gRGB &col);
128 void setBackgroundPicture(ePtr<gPixmap> &pixmap);
129 void setSelectionPicture(ePtr<gPixmap> &pixmap);
132 struct eListboxStyle *getLocalStyle(void);
134 /* entryAdded: an entry was added *before* the given index. it's index is the given number. */
135 void entryAdded(int index);
136 /* entryRemoved: an entry with the given index was removed. */
137 void entryRemoved(int index);
138 /* entryChanged: the entry with the given index was changed and should be redrawn. */
139 void entryChanged(int index);
140 /* the complete list changed. you should not attemp to keep the current index. */
141 void entryReset(bool cursorHome=true);
144 void invalidate(const gRegion ®ion = gRegion::invalidRegion());
146 int event(int event, void *data=0, void *data2=0);
150 int m_scrollbar_mode, m_prev_scrollbar_page;
151 bool m_content_changed;
152 bool m_enabled_wrap_around;
154 int m_top, m_selected;
156 int m_items_per_page;
157 int m_selection_enabled;
158 ePtr<iListboxContent> m_content;
159 eSlider *m_scrollbar;
160 eListboxStyle m_style;