X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/a6d3a3d2a552e2846e8da5a03f7651c5c2e7d6b2..d2ceae9583bc62daa872c316f8952b9a6a416a69:/lib/service/listboxservice.cpp diff --git a/lib/service/listboxservice.cpp b/lib/service/listboxservice.cpp index 19ff6933..fe690608 100644 --- a/lib/service/listboxservice.cpp +++ b/lib/service/listboxservice.cpp @@ -22,6 +22,18 @@ void eListboxServiceContent::setRoot(const eServiceReference &root) m_listbox->entryReset(); } +void eListboxServiceContent::setCurrent(const eServiceReference &ref) +{ + int index=0; + for (list::iterator i(m_list.begin()); i != m_list.end(); ++i, ++index) + if ( *i == ref ) + { + m_cursor = i; + m_cursor_number = index; + break; + } +} + void eListboxServiceContent::getCurrent(eServiceReference &ref) { if (cursorValid()) @@ -124,7 +136,7 @@ void eListboxServiceContent::sort() DEFINE_REF(eListboxServiceContent); eListboxServiceContent::eListboxServiceContent() - :m_visual_mode(visModeSimple), m_size(0), m_current_marked(false), m_swap(m_list.end()) + :m_visual_mode(visModeSimple), m_size(0), m_current_marked(false), m_numberoffset(0) { cursorHome(); eServiceCenter::getInstance(m_service_center); @@ -132,21 +144,44 @@ eListboxServiceContent::eListboxServiceContent() void eListboxServiceContent::cursorHome() { - list::iterator old = m_cursor; - - m_cursor = m_list.begin(); - m_cursor_number = 0; - - if ( m_current_marked && m_saved_cursor == m_list.end() ) - std::iter_swap( old, m_cursor ); + if (m_current_marked && m_saved_cursor == m_list.end()) + { + while (m_cursor_number) + { + std::iter_swap(m_cursor--, m_cursor); + --m_cursor_number; + if (m_listbox && m_cursor_number) + m_listbox->entryChanged(m_cursor_number); + } + } + else + { + m_cursor = m_list.begin(); + m_cursor_number = 0; + } } void eListboxServiceContent::cursorEnd() { - if ( m_current_marked && m_saved_cursor == m_list.end() && m_cursor != m_list.end() ) - m_swap = m_cursor; - m_cursor = m_list.end(); - m_cursor_number = m_size; + if (m_current_marked && m_saved_cursor == m_list.end()) + { + while (m_cursor != m_list.end()) + { + list::iterator prev = m_cursor++; + ++m_cursor_number; + if ( prev != m_list.end() && m_cursor != m_list.end() ) + { + std::iter_swap(m_cursor, prev); + if ( m_listbox ) + m_listbox->entryChanged(m_cursor_number); + } + } + } + else + { + m_cursor = m_list.end(); + m_cursor_number = m_size; + } } int eListboxServiceContent::setCurrentMarked(bool state) @@ -192,39 +227,36 @@ int eListboxServiceContent::setCurrentMarked(bool state) int eListboxServiceContent::cursorMove(int count) { - list::iterator old = m_cursor; - + int prev = m_cursor_number, last = m_cursor_number + count; if (count > 0) { - while(count && (m_cursor != m_list.end())) + while(count && m_cursor != m_list.end()) { - ++m_cursor; + list::iterator prev_it = m_cursor++; + if ( m_current_marked && m_cursor != m_list.end() && m_saved_cursor == m_list.end() ) + { + std::iter_swap(prev_it, m_cursor); + if ( m_listbox && prev != m_cursor_number && last != m_cursor_number ) + m_listbox->entryChanged(m_cursor_number); + } ++m_cursor_number; --count; - } + } } else if (count < 0) { - while (count && (m_cursor != m_list.begin())) + while (count && m_cursor != m_list.begin()) { - --m_cursor; + list::iterator prev_it = m_cursor--; + if ( m_current_marked && m_cursor != m_list.end() && prev_it != m_list.end() && m_saved_cursor == m_list.end() ) + { + std::iter_swap(prev_it, m_cursor); + if ( m_listbox && prev != m_cursor_number && last != m_cursor_number ) + m_listbox->entryChanged(m_cursor_number); + } --m_cursor_number; ++count; } } - - if ( m_current_marked && m_saved_cursor == m_list.end() ) - { - if ( m_cursor == m_list.end() ) - m_swap = old; - else if ( old == m_list.end() ) - { - std::iter_swap( m_swap, m_cursor ); - m_swap = m_list.end(); - } - else - std::iter_swap( old, m_cursor ); - } - return 0; } @@ -307,7 +339,7 @@ void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const case celServiceNumber: { char bla[10]; - sprintf(bla, "%d", m_cursor_number + 1); + sprintf(bla, "%d", m_numberoffset + m_cursor_number + 1); text = bla; break; }