allow using a pixmap as background for slider
[enigma2.git] / lib / gui / ewidget.cpp
index f71d7e1d503e5e85e5070277c88baeb27f57f075..7c50f4af47344d2f0153c36d3de0062a0f19e12d 100644 (file)
@@ -32,6 +32,9 @@ void eWidget::move(ePoint pos)
        if (m_position == pos)
                return;
 
+                       /* ?? what about native move support? */
+       invalidate();
+
        m_position = pos;
        
        event(evtChangedPosition);
@@ -97,16 +100,25 @@ void eWidget::show()
 {
        if (m_vis & wVisShow)
                return;
-       
-       m_vis |=  wVisShow;
 
+       m_vis |= wVisShow;
+       
                /* TODO: optimize here to only recalc what's required. possibly merge with hide. */
        eWidget *root = this;
        ePoint abspos = position();
        while (root && !root->m_desktop)
        {
                root = root->m_parent;
-               assert(root);
+               if (!root)
+               {
+                               /* oops: our root widget does not have a desktop associated. 
+                                       probably somebody already erased the root, but tries some
+                                       operations on a child window. 
+                                       
+                                       ignore them for now. */
+                       /* assert(root); */
+                       return;
+               }
                abspos += root->position();
        }
 
@@ -137,6 +149,8 @@ void eWidget::hide()
        while (root && !root->m_desktop)
        {
                root = root->m_parent;
+               if (!root)
+                       return;
                abspos += root->position();
        }
        assert(root->m_desktop);
@@ -177,6 +191,29 @@ void eWidget::setZPosition(int z)
        insertIntoParent(); /* now at the new Z position */
 }
 
+void eWidget::setTransparent(int transp)
+{
+       if (transp)
+               m_vis |= wVisTransparent;
+       else
+               m_vis &=~wVisTransparent;
+}
+
+ePoint eWidget::getAbsolutePosition()
+{
+       eWidget *root = this;
+       ePoint abspos = position();
+
+       while (root && !root->m_desktop)
+       {
+               root = root->m_parent;
+               assert(root);
+               abspos += root->position();
+       }
+
+       return abspos;
+}
+
 void eWidget::mayKillFocus()
 {
        setFocus(0);
@@ -194,12 +231,11 @@ eWidget::~eWidget()
 
        m_parent = 0;
 
-               /* destroy all childs */
+               /* tell all childs that the parent is not anymore existing */
        ePtrList<eWidget>::iterator i(m_childs.begin());
        while (i != m_childs.end())
        {
-               (*i)->m_parent = 0;
-               delete *i;
+               (*i)->parentRemoved();
                i = m_childs.erase(i);
        }
 }
@@ -215,6 +251,7 @@ void eWidget::insertIntoParent()
                        m_parent->m_childs.insert(i, this);
                        return;
                }
+               ++i;
        }
 }
 
@@ -223,14 +260,11 @@ void eWidget::doPaint(gPainter &painter, const gRegion &r)
        if (m_visible_with_childs.empty())
                return;
        
-       gRegion region = r;
+       gRegion region = r, childs = r;
                        /* we were in parent's space, now we are in local space */
        region.moveBy(-position());
        
        painter.moveOffset(position());
-               /* walk all childs */
-       for (ePtrList<eWidget>::iterator i(m_childs.begin()); i != m_childs.end(); ++i)
-               i->doPaint(painter, region);
        
                /* check if there's anything for us to paint */
        region &= m_visible_region;
@@ -240,6 +274,11 @@ void eWidget::doPaint(gPainter &painter, const gRegion &r)
                painter.resetClip(region);
                event(evtPaint, &region, &painter);
        }
+
+       childs.moveBy(-position());
+               /* walk all childs */
+       for (ePtrList<eWidget>::iterator i(m_childs.begin()); i != m_childs.end(); ++i)
+               i->doPaint(painter, childs);
        
        painter.moveOffset(-position());
 }
@@ -261,6 +300,11 @@ void eWidget::recalcClipRegionsWhenVisible()
        } while(1);
 }
 
+void eWidget::parentRemoved()
+{
+       m_parent = 0;
+}
+
 int eWidget::event(int event, void *data, void *data2)
 {
        switch (event)
@@ -271,15 +315,22 @@ int eWidget::event(int event, void *data, void *data2)
                
 //             eDebug("eWidget::evtPaint");
 //             dumpRegion(*(gRegion*)data);
-               if (!m_have_background_color)
+               if (!isTransparent())
                {
-                       ePtr<eWindowStyle> style;
-                       if (!getStyle(style))
-                               style->paintBackground(painter, ePoint(0, 0), size());
+                       if (!m_have_background_color)
+                       {
+                               ePtr<eWindowStyle> style;
+                               if (!getStyle(style))
+                                       style->paintBackground(painter, ePoint(0, 0), size());
+                       } else
+                       {
+                               painter.setBackgroundColor(m_background_color);
+                               painter.clear();
+                       }
                } else
                {
-                       painter.setBackgroundColor(m_background_color);
-                       painter.clear();
+                       if (m_have_background_color)
+                               painter.setBackgroundColor(m_background_color);
                }
                break;
        }