src/gui/kernel/qwidget_s60.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 19 fcece45ef507
--- a/src/gui/kernel/qwidget_s60.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/gui/kernel/qwidget_s60.cpp	Fri Apr 16 15:50:13 2010 +0300
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -389,9 +389,13 @@
 
             if (!isOpaque) {
                 RWindow *const window = static_cast<RWindow *>(drawableWindow);
+#ifdef Q_SYMBIAN_SEMITRANSPARENT_BG_SURFACE
+                window->SetSurfaceTransparency(true);
+#else
                 const TDisplayMode displayMode = static_cast<TDisplayMode>(window->SetRequiredDisplayMode(EColor16MA));
                 if (window->SetTransparencyAlphaChannel() == KErrNone)
                     window->SetBackgroundColor(TRgb(255, 255, 255, 0));
+#endif
             }
         }
 
@@ -707,12 +711,16 @@
 
     RWindow *const window = static_cast<RWindow *>(q->effectiveWinId()->DrawableWindow());
 
+#ifdef Q_SYMBIAN_SEMITRANSPARENT_BG_SURFACE
+    window->SetSurfaceTransparency(!isOpaque);
+#else
     if (!isOpaque) {
         const TDisplayMode displayMode = static_cast<TDisplayMode>(window->SetRequiredDisplayMode(EColor16MA));
         if (window->SetTransparencyAlphaChannel() == KErrNone)
             window->SetBackgroundColor(TRgb(255, 255, 255, 0));
     } else
         window->SetTransparentRegion(TRegionFix<1>());
+#endif
 }
 
 void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
@@ -870,10 +878,13 @@
 void QWidgetPrivate::createTLSysExtra()
 {
     extra->topextra->backingStore = 0;
+    extra->topextra->inExpose = 0;
 }
 
 void QWidgetPrivate::deleteTLSysExtra()
 {
+    delete extra->topextra->backingStore;
+    extra->topextra->backingStore = 0;
 }
 
 void QWidgetPrivate::createSysExtra()
@@ -888,14 +899,6 @@
     // this should only be non-zero if destroy() has not run due to constructor fail
     if (data.winid) {
         data.winid->ControlEnv()->AppUi()->RemoveFromStack(data.winid);
-        // We need to delete the backing store here before the CCoeControl and RWindow is deleted.
-        // The reason is that the backing store may be an EGL surface and if we delete the window
-        // before we delete the surface, the implementation may try to access to the window and raise
-        // a WSERV 3 panic.
-        if (extra && extra->topextra) {
-            delete extra->topextra->backingStore;
-            extra->topextra->backingStore = 0;
-        }
         delete data.winid;
         data.winid = 0;
     }
@@ -1043,96 +1046,48 @@
         return;
 
     if (isWindow()) {
+
+        QSymbianControl *window = static_cast<QSymbianControl *>(effectiveWinId());
+        if (window && newstate & Qt::WindowMinimized) {
+            window->setFocusSafely(false);
+            window->MakeVisible(false);
+        } else if (window && oldstate & Qt::WindowMinimized) {
+            window->setFocusSafely(true);
+            window->MakeVisible(true);
+        }
+
 #ifdef Q_WS_S60
-        // Change window decoration visibility if switching to or from fullsccreen
-        // In addition decoration visibility is changed when the initial has been
-        // WindowNoState.
-        // The window decoration visibility has to be changed before doing actual
-        // window state change since in that order the availableGeometry will return
-        // directly the right size and we will avoid unnecessarty redraws
-        if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen) ||
-            oldstate == Qt::WindowNoState) {
-            CEikStatusPane* statusPane = S60->statusPane();
-            CEikButtonGroupContainer* buttonGroup = S60->buttonGroupContainer();
-            if (newstate & Qt::WindowFullScreen) {
-                if (statusPane)
-                    statusPane->MakeVisible(false);
-                if (buttonGroup)
-                    buttonGroup->MakeVisible(false);
-            } else {
-                if (statusPane)
-                    statusPane->MakeVisible(true);
-                if (buttonGroup)
-                    buttonGroup->MakeVisible(true);
-            }
-
-        }
+        // Hide window decoration when switching to fullsccreen / minimized otherwise show decoration.
+        // The window decoration visibility has to be changed before doing actual window state 
+        // change since in that order the availableGeometry will return directly the right size and 
+        // we will avoid unnecessarty redraws
+        CEikStatusPane* statusPane = S60->statusPane();
+        CEikButtonGroupContainer* buttonGroup = S60->buttonGroupContainer();
+        TBool visible = !(newstate & (Qt::WindowFullScreen | Qt::WindowMinimized)); 
+        if (statusPane)
+            statusPane->MakeVisible(visible);
+        if (buttonGroup)
+            buttonGroup->MakeVisible(visible);
 #endif // Q_WS_S60
 
         createWinId();
         Q_ASSERT(testAttribute(Qt::WA_WState_Created));
-        QTLWExtra *top = d->topData();
-
         // Ensure the initial size is valid, since we store it as normalGeometry below.
         if (!testAttribute(Qt::WA_Resized) && !isVisible())
             adjustSize();
 
-        if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) {
-            if ((newstate & Qt::WindowMaximized)) {
-                const QRect normalGeometry = geometry();
-
-                const QRect r = top->normalGeometry;
-                setGeometry(qApp->desktop()->availableGeometry(this));
-                top->normalGeometry = r;
-
-                if (top->normalGeometry.width() < 0)
-                    top->normalGeometry = normalGeometry;
-            } else {
-                // restore original geometry
-                setGeometry(top->normalGeometry);
-            }
-        }
-        if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) {
-            if (newstate & Qt::WindowFullScreen) {
-                const QRect normalGeometry = geometry();
-                const QRect r = top->normalGeometry;
-                setGeometry(qApp->desktop()->screenGeometry(this));
+        QTLWExtra *top = d->topData();
+        const QRect normalGeometry = (top->normalGeometry.width() < 0) ? geometry() : top->normalGeometry;
 
-                top->normalGeometry = r;
-                if (top->normalGeometry.width() < 0)
-                    top->normalGeometry = normalGeometry;
-            } else {
-                if (newstate & Qt::WindowMaximized) {
-                    const QRect r = top->normalGeometry;
-                    setGeometry(qApp->desktop()->availableGeometry(this));
-                    top->normalGeometry = r;
-                } else {
-                    setGeometry(top->normalGeometry);
-                }
-            }
-        }
-        if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) {
-            if (newstate & Qt::WindowMinimized) {
-                if (isVisible()) {
-                    QSymbianControl *id = static_cast<QSymbianControl *>(effectiveWinId());
-                    if (id->IsFocused()) // Avoid unnecessary calls to FocusChanged()
-                        id->setFocusSafely(false);
-                    id->MakeVisible(false);
-                }
-            } else {
-                if (isVisible()) {
-                    QSymbianControl *id = static_cast<QSymbianControl *>(effectiveWinId());
-                    id->MakeVisible(true);
-                    if (!id->IsFocused()) // Avoid unnecessary calls to FocusChanged()
-                        id->setFocusSafely(true);
-                }
-                const QRect normalGeometry = geometry();
-                const QRect r = top->normalGeometry;
-                top->normalGeometry = r;
-                if (top->normalGeometry.width() < 0)
-                    top->normalGeometry = normalGeometry;
-            }
-        }
+        if (newstate & Qt::WindowFullScreen)
+            setGeometry(qApp->desktop()->screenGeometry(this));
+        else if (newstate & Qt::WindowMaximized)
+            setGeometry(qApp->desktop()->availableGeometry(this));
+        else
+            setGeometry(normalGeometry);
+
+        //restore normal geometry
+        top->normalGeometry = normalGeometry;
     }
 
     data->window_state = newstate;
@@ -1158,7 +1113,7 @@
         if (d->ic) {
             delete d->ic;
         } else {
-            QInputContext *ic = inputContext();
+            QInputContext *ic = QApplicationPrivate::inputContext;
             if (ic) {
                 ic->widgetDestroyed(this);
             }
@@ -1191,7 +1146,11 @@
     }
 
     if (destroyWindow) {
-        d->deleteSysExtra(); // deletes backingstore + window
+        delete id;
+        // At this point the backing store should already be destroyed
+        // so we flush the command buffer to ensure that the freeing of
+        // those resources and deleting the window can happen "atomically"
+        S60->wsSession().Flush();
     }
 }