+static void clearRegionSelectedHelper(gPainter &painter, eListboxStyle *local_style, const ePoint &offset, ePyObject &pbackColorSelected, bool cursorValid)
+{
+ if (pbackColorSelected)
+ {
+ unsigned int color = PyInt_AsUnsignedLongMask(pbackColorSelected);
+ painter.setBackgroundColor(gRGB(color));
+ }
+ else if (local_style)
+ {
+ if (local_style && local_style->m_background_color_selected_set)
+ painter.setBackgroundColor(local_style->m_background_color_selected);
+ if (local_style->m_background && cursorValid)
+ {
+ if (local_style->m_transparent_background)
+ painter.blit(local_style->m_background, offset, eRect(), gPainter::BT_ALPHATEST);
+ else
+ painter.blit(local_style->m_background, offset, eRect(), 0);
+ return;
+ }
+ }
+ painter.clear();
+}
+
+static void clearRegion(gPainter &painter, eWindowStyle &style, eListboxStyle *local_style, ePyObject pforeColor, ePyObject pforeColorSelected, ePyObject pbackColor, ePyObject pbackColorSelected, int selected, gRegion &rc, eRect &sel_clip, const ePoint &offset, bool cursorValid)
+{
+ if (selected && sel_clip.valid())
+ {
+ gRegion part = rc - sel_clip;
+ if (!part.empty())
+ {
+ painter.clip(part);
+ style.setStyle(painter, eWindowStyle::styleListboxNormal);
+ clearRegionHelper(painter, local_style, offset, pbackColor, cursorValid);
+ painter.clippop();
+ selected = 0;
+ }
+ part = rc & sel_clip;
+ if (!part.empty())
+ {
+ painter.clip(part);
+ style.setStyle(painter, eWindowStyle::styleListboxSelected);
+ clearRegionSelectedHelper(painter, local_style, offset, pbackColorSelected, cursorValid);
+ painter.clippop();
+ selected = 1;
+ }
+ }
+ else if (selected)
+ {
+ style.setStyle(painter, eWindowStyle::styleListboxSelected);
+ clearRegionSelectedHelper(painter, local_style, offset, pbackColorSelected, cursorValid);
+ if (local_style && local_style->m_selection)
+ painter.blit(local_style->m_selection, offset, eRect(), gPainter::BT_ALPHATEST);
+ }
+ else
+ {
+ style.setStyle(painter, eWindowStyle::styleListboxNormal);
+ clearRegionHelper(painter, local_style, offset, pbackColor, cursorValid);
+ }
+
+ if (selected)
+ {
+ if (pforeColorSelected)
+ {
+ unsigned int color = PyInt_AsUnsignedLongMask(pforeColorSelected);
+ painter.setForegroundColor(gRGB(color));
+ }
+ /* if we have a local foreground color set, use that. */
+ else if (local_style && local_style->m_foreground_color_selected_set)
+ painter.setForegroundColor(local_style->m_foreground_color_selected);
+ }
+ else
+ {
+ if (pforeColor)
+ {
+ unsigned int color = PyInt_AsUnsignedLongMask(pforeColor);
+ painter.setForegroundColor(gRGB(color));
+ }
+ /* if we have a local foreground color set, use that. */
+ else if (local_style && local_style->m_foreground_color_set)
+ painter.setForegroundColor(local_style->m_foreground_color);
+ }
+}
+
+static ePyObject lookupColor(ePyObject color, ePyObject data)
+{
+ if (color == Py_None)
+ return ePyObject();
+
+ if ((!color) && (!data))
+ return color;
+
+ unsigned int icolor = PyInt_AsUnsignedLongMask(color);
+
+ /* check if we have the "magic" template color */
+ if ((icolor & 0xFF000000) == 0xFF000000)
+ {
+ int index = icolor & 0xFFFFFF;
+ eDebug("[eListboxPythonMultiContent] template color index: %d", index);
+ return PyTuple_GetItem(data, index);
+ }
+
+ if (color == Py_None)
+ return ePyObject();
+
+ return color;
+}
+
+void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
+{
+ gRegion itemregion(eRect(offset, m_itemsize));
+ eListboxStyle *local_style = 0;
+ eRect sel_clip(m_selection_clip);
+ bool cursorValid = this->cursorValid();
+ if (sel_clip.valid())
+ sel_clip.moveBy(offset);
+
+ /* get local listbox style, if present */
+ if (m_listbox)
+ local_style = m_listbox->getLocalStyle();
+
+ painter.clip(itemregion);
+ clearRegion(painter, style, local_style, ePyObject(), ePyObject(), ePyObject(), ePyObject(), selected, itemregion, sel_clip, offset, cursorValid);
+
+ ePyObject items, buildfunc_ret;
+
+ if (m_list && cursorValid)