fix warnings,
[enigma2.git] / lib / gui / elistbox.cpp
index c4f9ed2c2162277e879250421a9ffe0c4320c897..d9fa30fcbeea96caa39f1146ed4e691dfaf6b645 100644 (file)
@@ -5,7 +5,7 @@
 
 eListbox::eListbox(eWidget *parent)
        :eWidget(parent), m_prev_scrollbar_page(-1), m_content_changed(false)
-       , m_scrollbar(NULL), m_scrollbar_mode(showNever)
+       , m_scrollbar_mode(showNever), m_scrollbar(NULL)
 {
        setContent(new eListboxStringContent());
 
@@ -56,6 +56,10 @@ void eListbox::moveSelection(int dir)
                /* refuse to do anything without a valid list. */
        if (!m_content)
                return;
+       
+               /* if our list does not have one entry, don't do anything. */
+       if (!m_items_per_page)
+               return;
                
                /* we need the old top/sel to see what we have to redraw */
        int oldtop = m_top;
@@ -102,7 +106,11 @@ void eListbox::moveSelection(int dir)
                        /* current selection invisible? */
                if (m_top + m_items_per_page <= m_content->cursorGet())
                {
-                       m_top = m_content->cursorGet() - m_items_per_page + 1;
+                       int rest = m_content->size() % m_items_per_page;
+                       if ( rest )
+                               m_top = m_content->cursorGet() - rest + 1;
+                       else
+                               m_top = m_content->cursorGet() - m_items_per_page + 1;
                        if (m_top < 0)
                                m_top = 0;
                }
@@ -139,6 +147,9 @@ void eListbox::moveSelection(int dir)
                
                invalidate(inv);
        }
+
+       if (m_scrollbar_mode != showNever)
+               updateScrollBar();
 }
 
 void eListbox::moveSelectionTo(int index)
@@ -213,9 +224,6 @@ int eListbox::event(int event, void *data, void *data2)
                
                gPainter &painter = *(gPainter*)data2;
                
-               if (m_scrollbar_mode != showNever)
-                       updateScrollBar();
-               
                m_content->cursorSave();
                m_content->cursorMove(m_top - m_selected);
                
@@ -329,5 +337,6 @@ void eListbox::entryReset()
                m_content->cursorHome();
        m_top = 0;
        m_selected = 0;
+       moveSelection(justCheck);
        invalidate();
 }