X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/1f5b1a20e4de369c197de1dae8fcb368e3e10b26..d36dec58e0a0cec9fa302fbead465688c26461ca:/lib/service/listboxservice.cpp diff --git a/lib/service/listboxservice.cpp b/lib/service/listboxservice.cpp index 07838722..19ff6933 100644 --- a/lib/service/listboxservice.cpp +++ b/lib/service/listboxservice.cpp @@ -87,7 +87,7 @@ void eListboxServiceContent::setVisualMode(int mode) if (m_visual_mode == visModeSimple) { m_element_position[celServiceName] = eRect(ePoint(0, 0), m_itemsize); - m_element_font[celServiceName] = new gFont("Arial", 14); + m_element_font[celServiceName] = new gFont("Arial", 23); m_element_position[celServiceNumber] = eRect(); m_element_font[celServiceNumber] = 0; m_element_position[celIcon] = eRect(); @@ -108,33 +108,95 @@ void eListboxServiceContent::setElementFont(int element, gFont *font) m_element_font[element] = font; } +void eListboxServiceContent::sort() +{ + ePtr lst; + if (!m_service_center->list(m_root, lst)) + { + m_list.sort(iListableServiceCompare(lst)); + /* FIXME: is this really required or can we somehow keep the current entry? */ + cursorHome(); + if (m_listbox) + m_listbox->entryReset(); + } +} + 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; cursorHome(); eServiceCenter::getInstance(m_service_center); } 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 ); } 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; } +int eListboxServiceContent::setCurrentMarked(bool state) +{ + bool prev = m_current_marked; + m_current_marked = state; + + if (state != prev && m_listbox) + { + m_listbox->entryChanged(m_cursor_number); + if (!state) + { + ePtr lst; + if (m_service_center->list(m_root, lst)) + eDebug("no list available!"); + else + { + ePtr list; + if (lst->startEdit(list)) + eDebug("no editable list"); + else + { + eServiceReference ref; + getCurrent(ref); + if(!ref) + eDebug("no valid service selected"); + else + { + int pos = cursorGet(); + eDebugNoNewLine("move %s to %d ", ref.toString().c_str(), pos); + if (list->moveService(ref, cursorGet())) + eDebug("failed"); + else + eDebug("ok"); + } + } + } + } + } + + return 0; +} + int eListboxServiceContent::cursorMove(int count) { + list::iterator old = m_cursor; + if (count > 0) { - while (count && (m_cursor != m_list.end())) + while(count && (m_cursor != m_list.end())) { ++m_cursor; ++m_cursor_number; @@ -149,7 +211,20 @@ int eListboxServiceContent::cursorMove(int count) ++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; } @@ -181,6 +256,7 @@ void eListboxServiceContent::cursorRestore() { m_cursor = m_saved_cursor; m_cursor_number = m_saved_cursor_number; + m_saved_cursor = m_list.end(); } int eListboxServiceContent::size() @@ -197,7 +273,10 @@ void eListboxServiceContent::setSize(const eSize &size) void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected) { painter.clip(eRect(offset, m_itemsize)); - if (cursorValid() && isMarked(*m_cursor)) + + if (m_current_marked && selected) + style.setStyle(painter, eWindowStyle::styleListboxMarked); + else if (cursorValid() && isMarked(*m_cursor)) style.setStyle(painter, eWindowStyle::styleListboxMarked); else style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);