1 #include <lib/service/listboxservice.h>
2 #include <lib/service/service.h>
4 void eListboxServiceContent::setRoot(const eServiceReference &root)
9 assert(m_service_center);
11 ePtr<iListableService> lst;
12 if (m_service_center->list(m_root, lst))
13 eDebug("no list available!");
15 if (lst->getContent(m_list))
16 eDebug("getContent failed");
18 m_size = m_list.size();
22 m_listbox->entryReset();
25 void eListboxServiceContent::getCurrent(eServiceReference &ref)
30 ref = eServiceReference();
33 void eListboxServiceContent::initMarked()
38 void eListboxServiceContent::addMarked(const eServiceReference &ref)
42 m_listbox->entryChanged(lookupService(ref));
45 void eListboxServiceContent::removeMarked(const eServiceReference &ref)
49 m_listbox->entryChanged(lookupService(ref));
52 int eListboxServiceContent::isMarked(const eServiceReference &ref)
54 return m_marked.find(ref) != m_marked.end();
57 int eListboxServiceContent::lookupService(const eServiceReference &ref)
59 /* shortcut for cursor */
61 return m_cursor_number;
62 /* otherwise, search in the list.. */
64 for (list::const_iterator i(m_list.begin()); i != m_list.end(); ++i, ++index);
66 /* this is ok even when the index was not found. */
70 DEFINE_REF(eListboxServiceContent);
72 eListboxServiceContent::eListboxServiceContent()
76 eServiceCenter::getInstance(m_service_center);
79 void eListboxServiceContent::cursorHome()
81 m_cursor = m_list.begin();
85 void eListboxServiceContent::cursorEnd()
87 m_cursor = m_list.end();
88 m_cursor_number = m_size;
91 int eListboxServiceContent::cursorMove(int count)
95 while (count && (m_cursor != m_list.end()))
101 } else if (count < 0)
103 while (count && (m_cursor != m_list.begin()))
114 int eListboxServiceContent::cursorValid()
116 return m_cursor != m_list.end();
119 int eListboxServiceContent::cursorSet(int n)
127 int eListboxServiceContent::cursorGet()
129 return m_cursor_number;
132 void eListboxServiceContent::cursorSave()
134 m_saved_cursor = m_cursor;
135 m_saved_cursor_number = m_cursor_number;
138 void eListboxServiceContent::cursorRestore()
140 m_cursor = m_saved_cursor;
141 m_cursor_number = m_saved_cursor_number;
144 int eListboxServiceContent::size()
149 void eListboxServiceContent::setSize(const eSize &size)
154 void eListboxServiceContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
156 ePtr<gFont> fnt = new gFont("Arial", 14);
157 painter.clip(eRect(offset, m_itemsize));
158 if (cursorValid() && isMarked(*m_cursor))
159 style.setStyle(painter, eWindowStyle::styleListboxMarked);
161 style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal);
166 painter.setFont(fnt);
168 ePoint text_offset = offset + (selected ? ePoint(2, 2) : ePoint(1, 1));
170 /* get name of service */
171 ePtr<iStaticServiceInformation> service_info;
172 m_service_center->info(*m_cursor, service_info);
173 std::string name = "<n/a>";
176 service_info->getName(*m_cursor, name);
178 painter.renderText(eRect(text_offset, m_itemsize), name);
181 style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);