add new multicontent TYPE_PROGRESS_PIXMAP
[enigma2.git] / lib / gui / elistboxcontent.cpp
index 4da1618c5762e4c535e8c8079ca9896df1c69eb3..dbf96375015fa273680739b8e8cd3c4e05cddea1 100644 (file)
@@ -49,7 +49,8 @@ int iListboxContent::currentCursorSelectable()
 
 DEFINE_REF(eListboxPythonStringContent);
 
-eListboxPythonStringContent::eListboxPythonStringContent(): m_itemheight(25)
+eListboxPythonStringContent::eListboxPythonStringContent()
+       :m_cursor(0), m_itemheight(25)
 {
 }
 
@@ -182,7 +183,7 @@ void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style,
        {
                if (local_style->m_background && cursorValid)
                        painter.blit(local_style->m_background, offset, eRect(), gPainter::BT_ALPHATEST);
-               else
+               else if (selected && !local_style->m_selection)
                        painter.clear();
        }
 
@@ -319,7 +320,7 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style,
        {
                if (local_style->m_background && cursorValid)
                        painter.blit(local_style->m_background, offset, eRect(), gPainter::BT_ALPHATEST);
-               else
+               else if (selected && !local_style->m_selection)
                        painter.clear();
        }
 
@@ -533,6 +534,8 @@ static void clearRegionHelper(gPainter &painter, eListboxStyle *local_style, con
                                painter.blit(local_style->m_background, offset, eRect(), 0);
                        return;
                }
+               else if (local_style->m_transparent_background)
+                       return;
        }
        painter.clear();
 }
@@ -850,6 +853,10 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
                                }
                                break;
                        }
+                       case TYPE_PROGRESS_PIXMAP: // Progress
+                       /*
+                               (1, x, y, width, height, filled_percent, pixmap [, borderWidth, foreColor, backColor, backColorSelected] )
+                       */
                        case TYPE_PROGRESS: // Progress
                        {
                        /*
@@ -860,41 +867,55 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
                                                        pwidth = PyTuple_GET_ITEM(item, 3),
                                                        pheight = PyTuple_GET_ITEM(item, 4),
                                                        pfilled_perc = PyTuple_GET_ITEM(item, 5),
-                                                       pborderWidth, pforeColor, pforeColorSelected, pbackColor, pbackColorSelected;
-
-                               if (!(px && py && pwidth && pheight && pfilled_perc))
+                                                       ppixmap, pborderWidth, pforeColor, pforeColorSelected, pbackColor, pbackColorSelected;
+                               int idx = 6;
+                               if (type == TYPE_PROGRESS)
                                {
-                                       eDebug("eListboxPythonMultiContent received too small tuple (must be (TYPE_PROGRESS, x, y, width, height, filled percent [,border width, foreColor, backColor, backColorSelected]))");
-                                       goto error_out;
+                                       if (!(px && py && pwidth && pheight && pfilled_perc))
+                                       {
+                                               eDebug("eListboxPythonMultiContent received too small tuple (must be (TYPE_PROGRESS, x, y, width, height, filled percent [,border width, foreColor, backColor, backColorSelected]))");
+                                               goto error_out;
+                                       }
+                               }
+                               else
+                               {
+                                       ppixmap = PyTuple_GET_ITEM(item, idx++);
+                                       if (ppixmap == Py_None)
+                                               continue;
+                                       if (!(px && py && pwidth && pheight && pfilled_perc, ppixmap))
+                                       {
+                                               eDebug("eListboxPythonMultiContent received too small tuple (must be (TYPE_PROGRESS_PIXMAP, x, y, width, height, filled percent, pixmap, [,border width, foreColor, backColor, backColorSelected]))");
+                                               goto error_out;
+                                       }
                                }
 
-                               if (size > 6)
+                               if (size > idx)
                                {
-                                       pborderWidth = PyTuple_GET_ITEM(item, 6);
+                                       pborderWidth = PyTuple_GET_ITEM(item, idx++);
                                        if (pborderWidth == Py_None)
                                                pborderWidth = ePyObject();
                                }
-                               if (size > 7)
+                               if (size > idx)
                                {
-                                       pforeColor = PyTuple_GET_ITEM(item, 7);
+                                       pforeColor = PyTuple_GET_ITEM(item, idx++);
                                        if (pforeColor == Py_None)
                                                pforeColor = ePyObject();
                                }
-                               if (size > 8)
+                               if (size > idx)
                                {
-                                       pforeColorSelected = PyTuple_GET_ITEM(item, 8);
+                                       pforeColorSelected = PyTuple_GET_ITEM(item, idx++);
                                        if (pforeColorSelected == Py_None)
                                                pforeColorSelected=ePyObject();
                                }
-                               if (size > 9)
+                               if (size > idx)
                                {
-                                       pbackColor = PyTuple_GET_ITEM(item, 9);
+                                       pbackColor = PyTuple_GET_ITEM(item, idx++);
                                        if (pbackColor == Py_None)
                                                pbackColor=ePyObject();
                                }
-                               if (size > 10)
+                               if (size > idx)
                                {
-                                       pbackColorSelected = PyTuple_GET_ITEM(item, 10);
+                                       pbackColorSelected = PyTuple_GET_ITEM(item, idx++);
                                        if (pbackColorSelected == Py_None)
                                                pbackColorSelected=ePyObject();
                                }
@@ -907,6 +928,10 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
 
                                if ((filled < 0) && data) /* if the string is in a negative number, it refers to the 'data' list. */
                                        filled = PyInt_AsLong(PyTuple_GetItem(data, -filled));
+                                       
+                                                       /* don't do anything if percent out of range */
+                               if ((filled < 0) || (filled > 100))
+                                       continue;
 
                                int bwidth = pborderWidth ? PyInt_AsLong(pborderWidth) : 2;
 
@@ -931,14 +956,27 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
                                rect.setRect(x+width-bwidth, y+bwidth, bwidth, height-bwidth);
                                painter.fill(rect);
 
-                               // progress
                                rect.setRect(x+bwidth, y+bwidth, (width-bwidth*2) * filled / 100, height-bwidth*2);
-                               painter.fill(rect);
 
-                               painter.clippop();
+                               // progress
+                               if (ppixmap)
+                               {
+                                       ePtr<gPixmap> pixmap;
+                                       if (SwigFromPython(pixmap, ppixmap))
+                                       {
+                                               eDebug("eListboxPythonMultiContent (Pixmap) get pixmap failed");
+                                               painter.clippop();
+                                               continue;
+                                       }
+                                       painter.blit(pixmap, rect.topLeft(), rect, 0);
+                               }
+                               else
+                                       painter.fill(rect);
 
+                               painter.clippop();
                                break;
                        }
+                       case TYPE_PIXMAP_ALPHABLEND:
                        case TYPE_PIXMAP_ALPHATEST:
                        case TYPE_PIXMAP: // pixmap
                        {
@@ -991,7 +1029,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
                                        clearRegion(painter, style, local_style, ePyObject(), ePyObject(), pbackColor, pbackColorSelected, selected, rc, sel_clip, offset, cursorValid);
                                }
 
-                               painter.blit(pixmap, rect.topLeft(), rect, (type == TYPE_PIXMAP_ALPHATEST) ? gPainter::BT_ALPHATEST : 0);
+                               painter.blit(pixmap, rect.topLeft(), rect, (type == TYPE_PIXMAP_ALPHATEST) ? gPainter::BT_ALPHATEST : (type == TYPE_PIXMAP_ALPHABLEND) ? gPainter::BT_ALPHABLEND : 0);
                                painter.clippop();
                                break;
                        }
@@ -1002,7 +1040,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
                }
        }
 
-       if (selected && (!local_style || !local_style->m_selection))
+       if (selected && !sel_clip.valid() && (!local_style || !local_style->m_selection))
                style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
 
 error_out:
@@ -1041,7 +1079,7 @@ int eListboxPythonMultiContent::currentCursorSelectable()
                                {
                                        bool retval = ret == Py_True;
                                        Py_DECREF(ret);
-                                       return ret;
+                                       return retval;
                                }
                                eDebug("call m_selectableFunc failed!!! assume not callable");
                        }