src/gui/kernel/qwidget_s60.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 19 fcece45ef507
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   387                 | EPointerFilterMove | EPointerFilterDrag, 0);
   387                 | EPointerFilterMove | EPointerFilterDrag, 0);
   388             drawableWindow->EnableVisibilityChangeEvents();
   388             drawableWindow->EnableVisibilityChangeEvents();
   389 
   389 
   390             if (!isOpaque) {
   390             if (!isOpaque) {
   391                 RWindow *const window = static_cast<RWindow *>(drawableWindow);
   391                 RWindow *const window = static_cast<RWindow *>(drawableWindow);
       
   392 #ifdef Q_SYMBIAN_SEMITRANSPARENT_BG_SURFACE
       
   393                 window->SetSurfaceTransparency(true);
       
   394 #else
   392                 const TDisplayMode displayMode = static_cast<TDisplayMode>(window->SetRequiredDisplayMode(EColor16MA));
   395                 const TDisplayMode displayMode = static_cast<TDisplayMode>(window->SetRequiredDisplayMode(EColor16MA));
   393                 if (window->SetTransparencyAlphaChannel() == KErrNone)
   396                 if (window->SetTransparencyAlphaChannel() == KErrNone)
   394                     window->SetBackgroundColor(TRgb(255, 255, 255, 0));
   397                     window->SetBackgroundColor(TRgb(255, 255, 255, 0));
       
   398 #endif
   395             }
   399             }
   396         }
   400         }
   397 
   401 
   398         q->setAttribute(Qt::WA_WState_Created);
   402         q->setAttribute(Qt::WA_WState_Created);
   399 
   403 
   705     if ((data.window_flags & Qt::FramelessWindowHint) == 0)
   709     if ((data.window_flags & Qt::FramelessWindowHint) == 0)
   706         return;
   710         return;
   707 
   711 
   708     RWindow *const window = static_cast<RWindow *>(q->effectiveWinId()->DrawableWindow());
   712     RWindow *const window = static_cast<RWindow *>(q->effectiveWinId()->DrawableWindow());
   709 
   713 
       
   714 #ifdef Q_SYMBIAN_SEMITRANSPARENT_BG_SURFACE
       
   715     window->SetSurfaceTransparency(!isOpaque);
       
   716 #else
   710     if (!isOpaque) {
   717     if (!isOpaque) {
   711         const TDisplayMode displayMode = static_cast<TDisplayMode>(window->SetRequiredDisplayMode(EColor16MA));
   718         const TDisplayMode displayMode = static_cast<TDisplayMode>(window->SetRequiredDisplayMode(EColor16MA));
   712         if (window->SetTransparencyAlphaChannel() == KErrNone)
   719         if (window->SetTransparencyAlphaChannel() == KErrNone)
   713             window->SetBackgroundColor(TRgb(255, 255, 255, 0));
   720             window->SetBackgroundColor(TRgb(255, 255, 255, 0));
   714     } else
   721     } else
   715         window->SetTransparentRegion(TRegionFix<1>());
   722         window->SetTransparentRegion(TRegionFix<1>());
       
   723 #endif
   716 }
   724 }
   717 
   725 
   718 void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
   726 void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
   719 {
   727 {
   720 #ifdef Q_WS_S60
   728 #ifdef Q_WS_S60
   868 }
   876 }
   869 
   877 
   870 void QWidgetPrivate::createTLSysExtra()
   878 void QWidgetPrivate::createTLSysExtra()
   871 {
   879 {
   872     extra->topextra->backingStore = 0;
   880     extra->topextra->backingStore = 0;
       
   881     extra->topextra->inExpose = 0;
   873 }
   882 }
   874 
   883 
   875 void QWidgetPrivate::deleteTLSysExtra()
   884 void QWidgetPrivate::deleteTLSysExtra()
   876 {
   885 {
       
   886     delete extra->topextra->backingStore;
       
   887     extra->topextra->backingStore = 0;
   877 }
   888 }
   878 
   889 
   879 void QWidgetPrivate::createSysExtra()
   890 void QWidgetPrivate::createSysExtra()
   880 {
   891 {
   881     extra->activated = 0;
   892     extra->activated = 0;
   886 void QWidgetPrivate::deleteSysExtra()
   897 void QWidgetPrivate::deleteSysExtra()
   887 {
   898 {
   888     // this should only be non-zero if destroy() has not run due to constructor fail
   899     // this should only be non-zero if destroy() has not run due to constructor fail
   889     if (data.winid) {
   900     if (data.winid) {
   890         data.winid->ControlEnv()->AppUi()->RemoveFromStack(data.winid);
   901         data.winid->ControlEnv()->AppUi()->RemoveFromStack(data.winid);
   891         // We need to delete the backing store here before the CCoeControl and RWindow is deleted.
       
   892         // The reason is that the backing store may be an EGL surface and if we delete the window
       
   893         // before we delete the surface, the implementation may try to access to the window and raise
       
   894         // a WSERV 3 panic.
       
   895         if (extra && extra->topextra) {
       
   896             delete extra->topextra->backingStore;
       
   897             extra->topextra->backingStore = 0;
       
   898         }
       
   899         delete data.winid;
   902         delete data.winid;
   900         data.winid = 0;
   903         data.winid = 0;
   901     }
   904     }
   902 }
   905 }
   903 
   906 
  1041     Qt::WindowStates oldstate = windowState();
  1044     Qt::WindowStates oldstate = windowState();
  1042     if (oldstate == newstate)
  1045     if (oldstate == newstate)
  1043         return;
  1046         return;
  1044 
  1047 
  1045     if (isWindow()) {
  1048     if (isWindow()) {
       
  1049 
       
  1050         QSymbianControl *window = static_cast<QSymbianControl *>(effectiveWinId());
       
  1051         if (window && newstate & Qt::WindowMinimized) {
       
  1052             window->setFocusSafely(false);
       
  1053             window->MakeVisible(false);
       
  1054         } else if (window && oldstate & Qt::WindowMinimized) {
       
  1055             window->setFocusSafely(true);
       
  1056             window->MakeVisible(true);
       
  1057         }
       
  1058 
  1046 #ifdef Q_WS_S60
  1059 #ifdef Q_WS_S60
  1047         // Change window decoration visibility if switching to or from fullsccreen
  1060         // Hide window decoration when switching to fullsccreen / minimized otherwise show decoration.
  1048         // In addition decoration visibility is changed when the initial has been
  1061         // The window decoration visibility has to be changed before doing actual window state 
  1049         // WindowNoState.
  1062         // change since in that order the availableGeometry will return directly the right size and 
  1050         // The window decoration visibility has to be changed before doing actual
  1063         // we will avoid unnecessarty redraws
  1051         // window state change since in that order the availableGeometry will return
  1064         CEikStatusPane* statusPane = S60->statusPane();
  1052         // directly the right size and we will avoid unnecessarty redraws
  1065         CEikButtonGroupContainer* buttonGroup = S60->buttonGroupContainer();
  1053         if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen) ||
  1066         TBool visible = !(newstate & (Qt::WindowFullScreen | Qt::WindowMinimized)); 
  1054             oldstate == Qt::WindowNoState) {
  1067         if (statusPane)
  1055             CEikStatusPane* statusPane = S60->statusPane();
  1068             statusPane->MakeVisible(visible);
  1056             CEikButtonGroupContainer* buttonGroup = S60->buttonGroupContainer();
  1069         if (buttonGroup)
  1057             if (newstate & Qt::WindowFullScreen) {
  1070             buttonGroup->MakeVisible(visible);
  1058                 if (statusPane)
       
  1059                     statusPane->MakeVisible(false);
       
  1060                 if (buttonGroup)
       
  1061                     buttonGroup->MakeVisible(false);
       
  1062             } else {
       
  1063                 if (statusPane)
       
  1064                     statusPane->MakeVisible(true);
       
  1065                 if (buttonGroup)
       
  1066                     buttonGroup->MakeVisible(true);
       
  1067             }
       
  1068 
       
  1069         }
       
  1070 #endif // Q_WS_S60
  1071 #endif // Q_WS_S60
  1071 
  1072 
  1072         createWinId();
  1073         createWinId();
  1073         Q_ASSERT(testAttribute(Qt::WA_WState_Created));
  1074         Q_ASSERT(testAttribute(Qt::WA_WState_Created));
  1074         QTLWExtra *top = d->topData();
       
  1075 
       
  1076         // Ensure the initial size is valid, since we store it as normalGeometry below.
  1075         // Ensure the initial size is valid, since we store it as normalGeometry below.
  1077         if (!testAttribute(Qt::WA_Resized) && !isVisible())
  1076         if (!testAttribute(Qt::WA_Resized) && !isVisible())
  1078             adjustSize();
  1077             adjustSize();
  1079 
  1078 
  1080         if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) {
  1079         QTLWExtra *top = d->topData();
  1081             if ((newstate & Qt::WindowMaximized)) {
  1080         const QRect normalGeometry = (top->normalGeometry.width() < 0) ? geometry() : top->normalGeometry;
  1082                 const QRect normalGeometry = geometry();
  1081 
  1083 
  1082         if (newstate & Qt::WindowFullScreen)
  1084                 const QRect r = top->normalGeometry;
  1083             setGeometry(qApp->desktop()->screenGeometry(this));
  1085                 setGeometry(qApp->desktop()->availableGeometry(this));
  1084         else if (newstate & Qt::WindowMaximized)
  1086                 top->normalGeometry = r;
  1085             setGeometry(qApp->desktop()->availableGeometry(this));
  1087 
  1086         else
  1088                 if (top->normalGeometry.width() < 0)
  1087             setGeometry(normalGeometry);
  1089                     top->normalGeometry = normalGeometry;
  1088 
  1090             } else {
  1089         //restore normal geometry
  1091                 // restore original geometry
  1090         top->normalGeometry = normalGeometry;
  1092                 setGeometry(top->normalGeometry);
       
  1093             }
       
  1094         }
       
  1095         if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) {
       
  1096             if (newstate & Qt::WindowFullScreen) {
       
  1097                 const QRect normalGeometry = geometry();
       
  1098                 const QRect r = top->normalGeometry;
       
  1099                 setGeometry(qApp->desktop()->screenGeometry(this));
       
  1100 
       
  1101                 top->normalGeometry = r;
       
  1102                 if (top->normalGeometry.width() < 0)
       
  1103                     top->normalGeometry = normalGeometry;
       
  1104             } else {
       
  1105                 if (newstate & Qt::WindowMaximized) {
       
  1106                     const QRect r = top->normalGeometry;
       
  1107                     setGeometry(qApp->desktop()->availableGeometry(this));
       
  1108                     top->normalGeometry = r;
       
  1109                 } else {
       
  1110                     setGeometry(top->normalGeometry);
       
  1111                 }
       
  1112             }
       
  1113         }
       
  1114         if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) {
       
  1115             if (newstate & Qt::WindowMinimized) {
       
  1116                 if (isVisible()) {
       
  1117                     QSymbianControl *id = static_cast<QSymbianControl *>(effectiveWinId());
       
  1118                     if (id->IsFocused()) // Avoid unnecessary calls to FocusChanged()
       
  1119                         id->setFocusSafely(false);
       
  1120                     id->MakeVisible(false);
       
  1121                 }
       
  1122             } else {
       
  1123                 if (isVisible()) {
       
  1124                     QSymbianControl *id = static_cast<QSymbianControl *>(effectiveWinId());
       
  1125                     id->MakeVisible(true);
       
  1126                     if (!id->IsFocused()) // Avoid unnecessary calls to FocusChanged()
       
  1127                         id->setFocusSafely(true);
       
  1128                 }
       
  1129                 const QRect normalGeometry = geometry();
       
  1130                 const QRect r = top->normalGeometry;
       
  1131                 top->normalGeometry = r;
       
  1132                 if (top->normalGeometry.width() < 0)
       
  1133                     top->normalGeometry = normalGeometry;
       
  1134             }
       
  1135         }
       
  1136     }
  1091     }
  1137 
  1092 
  1138     data->window_state = newstate;
  1093     data->window_state = newstate;
  1139 
  1094 
  1140     if (newstate & Qt::WindowActive)
  1095     if (newstate & Qt::WindowActive)
  1156 
  1111 
  1157 #ifndef QT_NO_IM
  1112 #ifndef QT_NO_IM
  1158         if (d->ic) {
  1113         if (d->ic) {
  1159             delete d->ic;
  1114             delete d->ic;
  1160         } else {
  1115         } else {
  1161             QInputContext *ic = inputContext();
  1116             QInputContext *ic = QApplicationPrivate::inputContext;
  1162             if (ic) {
  1117             if (ic) {
  1163                 ic->widgetDestroyed(this);
  1118                 ic->widgetDestroyed(this);
  1164             }
  1119             }
  1165         }
  1120         }
  1166 #endif
  1121 #endif
  1189     } QT_CATCH (const std::bad_alloc &) {
  1144     } QT_CATCH (const std::bad_alloc &) {
  1190         // swallow - destructors must not throw
  1145         // swallow - destructors must not throw
  1191     }
  1146     }
  1192 
  1147 
  1193     if (destroyWindow) {
  1148     if (destroyWindow) {
  1194         d->deleteSysExtra(); // deletes backingstore + window
  1149         delete id;
       
  1150         // At this point the backing store should already be destroyed
       
  1151         // so we flush the command buffer to ensure that the freeing of
       
  1152         // those resources and deleting the window can happen "atomically"
       
  1153         S60->wsSession().Flush();
  1195     }
  1154     }
  1196 }
  1155 }
  1197 
  1156 
  1198 QWidget *QWidget::mouseGrabber()
  1157 QWidget *QWidget::mouseGrabber()
  1199 {
  1158 {