diff options
Diffstat (limited to 'lib/gui')
| -rw-r--r-- | lib/gui/elistbox.cpp | 69 | ||||
| -rw-r--r-- | lib/gui/elistbox.h | 18 | ||||
| -rw-r--r-- | lib/gui/elistboxcontent.cpp | 14 | ||||
| -rw-r--r-- | lib/gui/elistboxcontent.h | 2 |
4 files changed, 82 insertions, 21 deletions
diff --git a/lib/gui/elistbox.cpp b/lib/gui/elistbox.cpp index 5a9ee4d6..f530019d 100644 --- a/lib/gui/elistbox.cpp +++ b/lib/gui/elistbox.cpp @@ -1,3 +1,4 @@ + /* written by: Felix Domke <tmbinc@elitedvb.net> */ #include <lib/gui/elistbox.h> #include <lib/gui/elistboxcontent.h> @@ -9,11 +10,7 @@ eListbox::eListbox(eWidget *parent): eWidget(parent) void eListbox::setContent(iListboxContent *content) { m_content = content; - invalidate(); - if (m_content) - m_content->cursorHome(); - m_top = 0; - m_selected = 0; + entryReset(); } void eListbox::moveSelection(int dir) @@ -46,6 +43,8 @@ void eListbox::moveSelection(int dir) if (m_top < 0) m_top = 0; break; + case justCheck: + break; } /* note that we could be on an invalid cursor position, but we don't @@ -54,6 +53,7 @@ void eListbox::moveSelection(int dir) /* now, look wether the current selection is out of screen */ m_selected = m_content->cursorGet(); + if (m_selected < m_top) { m_top -= m_items_per_page; @@ -64,11 +64,12 @@ void eListbox::moveSelection(int dir) /* m_top should be always valid here as it's selected */ m_top += m_items_per_page; } - + if (m_top != oldtop) invalidate(); - else + else if (m_selected != oldsel) { + /* redraw the old and newly selected */ gRegion inv = eRect(0, m_itemheight * (m_selected-m_top), size().width(), m_itemheight); inv |= eRect(0, m_itemheight * (oldsel-m_top), size().width(), m_itemheight); @@ -119,3 +120,57 @@ void eListbox::recalcSize() m_content->setSize(eSize(size().width(), m_itemheight)); m_items_per_page = size().height() / m_itemheight; } + +void eListbox::entryAdded(int index) +{ + /* manage our local pointers. when the entry was added before the current position, we have to advance. */ + + /* we need to check <= - when the new entry has the (old) index of the cursor, the cursor was just moved down. */ + if (index <= m_selected) + ++m_selected; + if (index <= m_top) + ++m_top; + + /* we have to check wether our current cursor is gone out of the screen. */ + /* moveSelection will check for this case */ + moveSelection(justCheck); + + /* now, check if the new index is visible. */ + if ((m_top <= index) && (index < (m_top + m_items_per_page))) + { + /* todo, calc exact invalidation... */ + invalidate(); + } +} + +void eListbox::entryRemoved(int index) +{ + if (index == m_selected) + m_selected = m_content->cursorGet(); + + moveSelection(justCheck); + + if ((m_top <= index) && (index < (m_top + m_items_per_page))) + { + /* todo, calc exact invalidation... */ + invalidate(); + } +} + +void eListbox::entryChanged(int index) +{ + if ((m_top <= index) && (index < (m_top + m_items_per_page))) + { + gRegion inv = eRect(0, m_itemheight * (index-m_top), size().width(), m_itemheight); + invalidate(inv); + } +} + +void eListbox::entryReset() +{ + invalidate(); + if (m_content) + m_content->cursorHome(); + m_top = 0; + m_selected = 0; +} diff --git a/lib/gui/elistbox.h b/lib/gui/elistbox.h index d5464868..9ec94665 100644 --- a/lib/gui/elistbox.h +++ b/lib/gui/elistbox.h @@ -34,13 +34,15 @@ protected: virtual int size()=0; - virtual RESULT connectItemChanged(const Slot0<void> &itemChanged, ePtr<eConnection> &connection)=0; + void setListbox(eListbox *lb); // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though virtual void setSize(const eSize &size)=0; /* the following functions always refer to the selected item */ virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)=0; + + eListbox *m_listbox; #endif }; @@ -55,12 +57,24 @@ public: moveUp, moveDown, moveTop, - moveEnd + moveEnd, + justCheck }; protected: int event(int event, void *data=0, void *data2=0); void recalcSize(); private: + friend class iListboxContent; + + /* entryAdded: an entry was added *before* the given index. it's index is the given number. */ + void entryAdded(int index); + /* entryRemoved: an entry with the given index was removed. */ + void entryRemoved(int index); + /* entryChanged: the entry with the given index was changed and should be redrawn. */ + void entryChanged(int index); + /* the complete list changed. you should not attemp to keep the current index. */ + void entryReset(); + int m_top, m_selected; int m_itemheight; int m_items_per_page; diff --git a/lib/gui/elistboxcontent.cpp b/lib/gui/elistboxcontent.cpp index d3a2e77a..0a10b27a 100644 --- a/lib/gui/elistboxcontent.cpp +++ b/lib/gui/elistboxcontent.cpp @@ -29,6 +29,10 @@ iListboxContent::~iListboxContent() { } +void iListboxContent::setListbox(eListbox *lb) +{ + m_listbox = lb; +} DEFINE_REF(eListboxTestContent); @@ -203,11 +207,6 @@ int eListboxStringContent::size() return m_size; } -RESULT eListboxStringContent::connectItemChanged(const Slot0<void> &itemChanged, ePtr<eConnection> &connection) -{ - return 0; -} - void eListboxStringContent::setSize(const eSize &size) { m_itemsize = size; @@ -316,11 +315,6 @@ int eListboxPythonStringContent::size() return PyList_Size(m_list); } -RESULT eListboxPythonStringContent::connectItemChanged(const Slot0<void> &itemChanged, ePtr<eConnection> &connection) -{ - return 0; -} - void eListboxPythonStringContent::setSize(const eSize &size) { m_itemsize = size; diff --git a/lib/gui/elistboxcontent.h b/lib/gui/elistboxcontent.h index 7ef60116..deea3000 100644 --- a/lib/gui/elistboxcontent.h +++ b/lib/gui/elistboxcontent.h @@ -55,8 +55,6 @@ protected: void cursorRestore(); int size(); - RESULT connectItemChanged(const Slot0<void> &itemChanged, ePtr<eConnection> &connection); - // void setOutputDevice ? (for allocating colors, ...) .. requires some work, though void setSize(const eSize &size); |
