some work on the positioner setup plugin
[enigma2.git] / lib / gui / ewidgetdesktop.cpp
index dcc2ef603b1d96dbd6555f309f56793250eddc2a..9e09220319d068b3a709ba46f5df24d729e4e84c 100644 (file)
@@ -5,18 +5,27 @@
 
 extern void dumpRegion(const gRegion &region);
 
-void eWidgetDesktop::addRootWidget(eWidget *root, int top)
+void eWidgetDesktop::addRootWidget(eWidget *root)
 {
        assert(!root->m_desktop);
        
+       int invert_sense = 0;
                /* buffered mode paints back-to-front, while immediate mode is front-to-back. */
        if (m_comp_mode == cmBuffered)
-               top = !top;
+               invert_sense = 1;
+       
+       ePtrList<eWidget>::iterator insert_position = m_root.begin();
+       
+       for (;;)
+       {
+               if ((insert_position == m_root.end()) || (invert_sense ^ (insert_position->m_z_position < root->m_z_position)))
+               {
+                       m_root.insert(insert_position, root);
+                       break;
+               }
+               ++insert_position;
+       }
        
-       if (top)
-               m_root.push_back(root);
-       else
-               m_root.push_front(root);
        root->m_desktop = this;
 
                /* the creation will be postponed. */
@@ -51,10 +60,10 @@ void eWidgetDesktop::calcWidgetClipRegion(eWidget *widget, gRegion &parent_visib
                widget->m_visible_region = widget->m_clip_region;
                widget->m_visible_region.moveBy(widget->position());
                widget->m_visible_region &= parent_visible; // in parent space!
-                       /* TODO: check transparency here! */
 
-                       /* remove everything this widget will contain from parent's visible list */
-               parent_visible -= widget->m_visible_region; // will remove child regions too!
+               if (!widget->isTransparent())
+                               /* remove everything this widget will contain from parent's visible list, unless widget is transparent. */
+                       parent_visible -= widget->m_visible_region; // will remove child regions too!
 
                        /* now prepare for recursing to childs */
                widget->m_visible_region.moveBy(-widget->position());            // now in local space
@@ -63,9 +72,22 @@ void eWidgetDesktop::calcWidgetClipRegion(eWidget *widget, gRegion &parent_visib
 
        widget->m_visible_with_childs = widget->m_visible_region;
        
-       for (ePtrList<eWidget>::iterator i(widget->m_childs.begin()); i != widget->m_childs.end(); ++i)
-               if (i->m_vis & eWidget::wVisShow)
-                       calcWidgetClipRegion(*i, widget->m_visible_region);
+                       /* add childs in reverse (Z) order - we're going from front-to-bottom here. */
+       ePtrList<eWidget>::iterator i(widget->m_childs.end());
+       
+       for (;;)
+       {
+               if (i != widget->m_childs.end())
+               {
+                       if (i->m_vis & eWidget::wVisShow)
+                               calcWidgetClipRegion(*i, widget->m_visible_region);
+                       else
+                               clearVisibility(*i);
+               }
+               if (i == widget->m_childs.begin())
+                       break;
+               --i;
+       }
 }
 
 void eWidgetDesktop::recalcClipRegions(eWidget *root)
@@ -79,7 +101,10 @@ void eWidgetDesktop::recalcClipRegions(eWidget *root)
                for (ePtrList<eWidget>::iterator i(m_root.begin()); i != m_root.end(); ++i)
                {
                        if (!(i->m_vis & eWidget::wVisShow))
+                       {
+                               clearVisibility(i);
                                continue;
+                       }
                        
                        gRegion visible_before = i->m_visible_with_childs;
 
@@ -94,10 +119,11 @@ void eWidgetDesktop::recalcClipRegions(eWidget *root)
                
                gRegion redraw = (background_before - m_screen.m_background_region) | (m_screen.m_background_region - background_before);
                invalidate(redraw);
-       } else
+       } else if (m_comp_mode == cmBuffered)
        {
                if (!root->m_vis & eWidget::wVisShow)
                {
+                       clearVisibility(root);
                        removeBufferForWidget(root);
                        return;
                }
@@ -266,7 +292,7 @@ void eWidgetDesktop::makeCompatiblePixmap(gPixmap &pm)
        if (m_comp_mode != cmImmediate)
                return;
        
-       eDebug("widgetDesktop: make compatible pixmap of %p\n", &pm);
+//     eDebug("widgetDesktop: make compatible pixmap of %p", &pm);
        if (!m_screen.m_dc)
        {
                eWarning("eWidgetDesktop: no DC to make pixmap compatible with!");
@@ -308,6 +334,12 @@ eWidgetDesktop::eWidgetDesktop(eSize size): m_mainloop(0), m_timer(0)
 
 eWidgetDesktop::~eWidgetDesktop()
 {
+               /* tell registered root windows that they no longer have a desktop. */
+       for (ePtrList<eWidget>::iterator i(m_root.begin()); i != m_root.end(); )
+       {
+               i->m_desktop = 0;
+               i = m_root.erase(i);
+       }
                /* destroy all buffers */
        setCompositionMode(-1);
 }
@@ -387,3 +419,10 @@ void eWidgetDesktop::notify()
 {
        redrawComposition(1);
 }
+
+void eWidgetDesktop::clearVisibility(eWidget *widget)
+{
+       widget->m_visible_with_childs = gRegion();
+       for (ePtrList<eWidget>::iterator i(widget->m_childs.begin()); i != widget->m_childs.end(); ++i)
+               clearVisibility(*i);
+}