2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2009 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 of the Qt Toolkit. |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
8 ** |
8 ** |
9 ** $QT_BEGIN_LICENSE:LGPL$ |
9 ** $QT_BEGIN_LICENSE:LGPL$ |
10 ** No Commercial Usage |
10 ** No Commercial Usage |
11 ** This file contains pre-release code and may not be distributed. |
11 ** This file contains pre-release code and may not be distributed. |
12 ** You may use this file in accordance with the terms and conditions |
12 ** You may use this file in accordance with the terms and conditions |
211 |
211 |
212 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
212 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
213 |
213 |
214 if ((q->windowType() == Qt::Desktop)) |
214 if ((q->windowType() == Qt::Desktop)) |
215 return; |
215 return; |
|
216 |
|
217 QPoint oldPos(q->pos()); |
|
218 QSize oldSize(q->size()); |
|
219 QRect oldGeom(data.crect); |
|
220 |
|
221 // Lose maximized status if deliberate resize |
|
222 if (w != oldSize.width() || h != oldSize.height()) |
|
223 data.window_state &= ~Qt::WindowMaximized; |
|
224 |
216 if (extra) { // any size restrictions? |
225 if (extra) { // any size restrictions? |
217 w = qMin(w,extra->maxw); |
226 w = qMin(w,extra->maxw); |
218 h = qMin(h,extra->maxh); |
227 h = qMin(h,extra->maxh); |
219 w = qMax(w,extra->minw); |
228 w = qMax(w,extra->minw); |
220 h = qMax(h,extra->minh); |
229 h = qMax(h,extra->minh); |
226 uint s = data.window_state; |
235 uint s = data.window_state; |
227 s &= ~(Qt::WindowMaximized | Qt::WindowFullScreen); |
236 s &= ~(Qt::WindowMaximized | Qt::WindowFullScreen); |
228 data.window_state = s; |
237 data.window_state = s; |
229 } |
238 } |
230 |
239 |
231 QPoint oldPos(q->pos()); |
|
232 QSize oldSize(q->size()); |
|
233 QRect oldGeom(data.crect); |
|
234 |
|
235 bool isResize = w != oldSize.width() || h != oldSize.height(); |
240 bool isResize = w != oldSize.width() || h != oldSize.height(); |
236 if (!isMove && !isResize) |
241 if (!isMove && !isResize) |
237 return; |
242 return; |
238 |
|
239 if (isResize) |
|
240 data.window_state &= ~Qt::WindowMaximized; |
|
241 |
243 |
242 if (q->isWindow()) { |
244 if (q->isWindow()) { |
243 if (w == 0 || h == 0) { |
245 if (w == 0 || h == 0) { |
244 q->setAttribute(Qt::WA_OutsideWSRange, true); |
246 q->setAttribute(Qt::WA_OutsideWSRange, true); |
245 if (q->isVisible() && q->testAttribute(Qt::WA_Mapped)) |
247 if (q->isVisible() && q->testAttribute(Qt::WA_Mapped)) |
357 if (!q->testAttribute(Qt::WA_Moved) && !q->testAttribute(Qt::WA_DontShowOnScreen)) |
359 if (!q->testAttribute(Qt::WA_Moved) && !q->testAttribute(Qt::WA_DontShowOnScreen)) |
358 data.crect.moveTopLeft(QPoint(clientRect.iTl.iX, clientRect.iTl.iY)); |
360 data.crect.moveTopLeft(QPoint(clientRect.iTl.iX, clientRect.iTl.iY)); |
359 |
361 |
360 QScopedPointer<QSymbianControl> control( q_check_ptr(new QSymbianControl(q)) ); |
362 QScopedPointer<QSymbianControl> control( q_check_ptr(new QSymbianControl(q)) ); |
361 QT_TRAP_THROWING(control->ConstructL(true, desktop)); |
363 QT_TRAP_THROWING(control->ConstructL(true, desktop)); |
|
364 control->SetMopParent(static_cast<CEikAppUi*>(S60->appUi())); |
362 |
365 |
363 // Symbian windows are always created in an inactive state |
366 // Symbian windows are always created in an inactive state |
364 // We perform this assignment for the case where the window is being re-created |
367 // We perform this assignment for the case where the window is being re-created |
365 // as aa result of a call to setParent_sys, on either this widget or one of its |
368 // as aa result of a call to setParent_sys, on either this widget or one of its |
366 // ancestors. |
369 // ancestors. |
432 RDrawableWindow *const drawableWindow = control->DrawableWindow(); |
435 RDrawableWindow *const drawableWindow = control->DrawableWindow(); |
433 // Request mouse move events. |
436 // Request mouse move events. |
434 drawableWindow->PointerFilter(EPointerFilterEnterExit |
437 drawableWindow->PointerFilter(EPointerFilterEnterExit |
435 | EPointerFilterMove | EPointerFilterDrag, 0); |
438 | EPointerFilterMove | EPointerFilterDrag, 0); |
436 |
439 |
437 if (q->isVisible() && q->testAttribute(Qt::WA_Mapped)) |
440 if (q->isVisible() && q->testAttribute(Qt::WA_Mapped)) { |
438 activateSymbianWindow(control.data()); |
441 activateSymbianWindow(control.data()); |
|
442 control->MakeVisible(true); |
|
443 } |
439 |
444 |
440 // We wait until the control is fully constructed before calling setWinId, because |
445 // We wait until the control is fully constructed before calling setWinId, because |
441 // this generates a WinIdChanged event. |
446 // this generates a WinIdChanged event. |
442 setWinId(control.take()); |
447 setWinId(control.take()); |
443 } |
448 } |
481 |
486 |
482 id->MakeVisible(true); |
487 id->MakeVisible(true); |
483 |
488 |
484 if(q->isWindow()) |
489 if(q->isWindow()) |
485 id->setFocusSafely(true); |
490 id->setFocusSafely(true); |
486 |
|
487 // Force setting of the icon after window is made visible, |
|
488 // this is needed even WA_SetWindowIcon is not set, as in that case we need |
|
489 // to reset to the application level window icon |
|
490 if(q->isWindow()) |
|
491 setWindowIcon_sys(true); |
|
492 } |
491 } |
493 |
492 |
494 invalidateBuffer(q->rect()); |
493 invalidateBuffer(q->rect()); |
495 } |
494 } |
496 |
495 |
562 void QWidgetPrivate::lower_sys() |
561 void QWidgetPrivate::lower_sys() |
563 { |
562 { |
564 Q_Q(QWidget); |
563 Q_Q(QWidget); |
565 |
564 |
566 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
565 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
567 if (q->internalWinId()) |
566 if (q->internalWinId()) { |
568 q->internalWinId()->DrawableWindow()->SetOrdinalPosition(-1); |
567 // If toplevel widget, lower app to background |
|
568 if (q->isWindow()) |
|
569 S60->wsSession().SetWindowGroupOrdinalPosition(S60->windowGroup().Identifier(), -1); |
|
570 else |
|
571 q->internalWinId()->DrawableWindow()->SetOrdinalPosition(-1); |
|
572 } |
569 |
573 |
570 if (!q->isWindow()) |
574 if (!q->isWindow()) |
571 invalidateBuffer(q->rect()); |
575 invalidateBuffer(q->rect()); |
572 } |
576 } |
573 |
577 |
709 window->SetBackgroundColor(TRgb(255, 255, 255, 0)); |
713 window->SetBackgroundColor(TRgb(255, 255, 255, 0)); |
710 } else |
714 } else |
711 window->SetTransparentRegion(TRegionFix<1>()); |
715 window->SetTransparentRegion(TRegionFix<1>()); |
712 } |
716 } |
713 |
717 |
714 CFbsBitmap* qt_pixmapToNativeBitmap(QPixmap pixmap, bool invert) |
|
715 { |
|
716 CFbsBitmap* fbsBitmap = q_check_ptr(new CFbsBitmap); // CBase derived object needs check on new |
|
717 TSize size(pixmap.size().width(), pixmap.size().height()); |
|
718 TDisplayMode mode(EColor16MU); |
|
719 |
|
720 bool isNull = pixmap.isNull(); |
|
721 int depth = pixmap.depth(); |
|
722 |
|
723 // TODO: dummy assumptions from bit amounts for each color |
|
724 // Will fix later on when native pixmap is implemented |
|
725 switch(pixmap.depth()) { |
|
726 case 1: |
|
727 mode = EGray2; |
|
728 break; |
|
729 case 4: |
|
730 mode = EColor16; |
|
731 break; |
|
732 case 8: |
|
733 mode = EColor256; |
|
734 break; |
|
735 case 12: |
|
736 mode = EColor4K; |
|
737 break; |
|
738 case 16: |
|
739 mode = EColor64K; |
|
740 break; |
|
741 case 24: |
|
742 mode = EColor16M; |
|
743 break; |
|
744 case 32: |
|
745 case EColor16MU: |
|
746 break; |
|
747 default: |
|
748 qFatal("Unsupported pixmap depth"); |
|
749 break; |
|
750 } |
|
751 |
|
752 qt_symbian_throwIfError(fbsBitmap->Create(size, mode)); |
|
753 fbsBitmap->LockHeap(); |
|
754 QImage image = pixmap.toImage(); |
|
755 |
|
756 if (invert) |
|
757 image.invertPixels(); |
|
758 |
|
759 int height = pixmap.size().height(); |
|
760 for(int i=0;i<height;i++ ) |
|
761 { |
|
762 TPtr8 scanline(image.scanLine(i), image.bytesPerLine(), image.bytesPerLine()); |
|
763 fbsBitmap->SetScanLine( scanline, i ); |
|
764 } |
|
765 |
|
766 fbsBitmap->UnlockHeap(); |
|
767 return fbsBitmap; |
|
768 } |
|
769 |
|
770 void QWidgetPrivate::setWindowIcon_sys(bool forceReset) |
718 void QWidgetPrivate::setWindowIcon_sys(bool forceReset) |
771 { |
719 { |
772 #ifdef Q_WS_S60 |
720 #ifdef Q_WS_S60 |
773 Q_Q(QWidget); |
721 Q_Q(QWidget); |
774 |
722 |
793 if (mask.isNull()) { |
741 if (mask.isNull()) { |
794 mask = QBitmap(pm.size()); |
742 mask = QBitmap(pm.size()); |
795 mask.fill(Qt::color1); |
743 mask.fill(Qt::color1); |
796 } |
744 } |
797 |
745 |
798 // Convert to CFbsBitmp |
746 CFbsBitmap* nBitmap = pm.toSymbianCFbsBitmap(); |
799 // TODO: When QPixmap is adapted to use native CFbsBitmap, |
747 CFbsBitmap* nMask = mask.toSymbianCFbsBitmap(); |
800 // it could be set directly to context pane |
|
801 CFbsBitmap* nBitmap = qt_pixmapToNativeBitmap(pm, false); |
|
802 CFbsBitmap* nMask = qt_pixmapToNativeBitmap(mask, true); |
|
803 |
|
804 contextPane->SetPicture(nBitmap,nMask); |
748 contextPane->SetPicture(nBitmap,nMask); |
805 } else { |
749 } else { |
806 // Icon set to null -> set context pane picture to default |
750 // Icon set to null -> set context pane picture to default |
807 QT_TRAP_THROWING(contextPane->SetPictureToDefaultL()); |
751 QT_TRAP_THROWING(contextPane->SetPictureToDefaultL()); |
808 } |
752 } |
829 if (mask.isNull()) { |
773 if (mask.isNull()) { |
830 mask = QBitmap(pm.size()); |
774 mask = QBitmap(pm.size()); |
831 mask.fill(Qt::color1); |
775 mask.fill(Qt::color1); |
832 } |
776 } |
833 |
777 |
834 // Convert to CFbsBitmp |
778 CFbsBitmap* nBitmap = pm.toSymbianCFbsBitmap(); |
835 // TODO: When QPixmap is adapted to use native CFbsBitmap, |
779 CFbsBitmap* nMask = mask.toSymbianCFbsBitmap(); |
836 // it could be set directly to context pane |
|
837 CFbsBitmap* nBitmap = qt_pixmapToNativeBitmap(pm, false); |
|
838 CFbsBitmap* nMask = qt_pixmapToNativeBitmap(mask, true); |
|
839 |
|
840 titlePane->SetSmallPicture( nBitmap, nMask, ETrue ); |
780 titlePane->SetSmallPicture( nBitmap, nMask, ETrue ); |
841 } else { |
781 } else { |
842 // Icon set to null -> set context pane picture to default |
782 // Icon set to null -> set context pane picture to default |
843 titlePane->SetSmallPicture( NULL, NULL, EFalse ); |
783 titlePane->SetSmallPicture( NULL, NULL, EFalse ); |
844 } |
784 } |
937 } |
877 } |
938 |
878 |
939 void QWidgetPrivate::createSysExtra() |
879 void QWidgetPrivate::createSysExtra() |
940 { |
880 { |
941 extra->activated = 0; |
881 extra->activated = 0; |
942 extra->disableBlit = 0; |
882 extra->nativePaintMode = QWExtra::Default; |
|
883 extra->receiveNativePaintEvents = 0; |
943 } |
884 } |
944 |
885 |
945 void QWidgetPrivate::deleteSysExtra() |
886 void QWidgetPrivate::deleteSysExtra() |
946 { |
887 { |
947 // this should only be non-zero if destroy() has not run due to constructor fail |
888 // this should only be non-zero if destroy() has not run due to constructor fail |
1238 } |
1179 } |
1239 if (destroyWindow && !(windowType() == Qt::Desktop) && id) { |
1180 if (destroyWindow && !(windowType() == Qt::Desktop) && id) { |
1240 if (id->IsFocused()) // Avoid unnecessry calls to FocusChanged() |
1181 if (id->IsFocused()) // Avoid unnecessry calls to FocusChanged() |
1241 id->setFocusSafely(false); |
1182 id->setFocusSafely(false); |
1242 id->ControlEnv()->AppUi()->RemoveFromStack(id); |
1183 id->ControlEnv()->AppUi()->RemoveFromStack(id); |
1243 |
|
1244 // Hack to activate window under destroyed one. With this activation |
|
1245 // the next visible window will get keyboard focus |
|
1246 WId wid = CEikonEnv::Static()->AppUi()->TopFocusedControl(); |
|
1247 if (wid) { |
|
1248 QWidget *widget = QWidget::find(wid); |
|
1249 QApplication::setActiveWindow(widget); |
|
1250 if (widget) { |
|
1251 // Reset global window title for focusing window |
|
1252 widget->d_func()->setWindowTitle_sys(widget->windowTitle()); |
|
1253 } |
|
1254 } |
|
1255 } |
1184 } |
1256 } |
1185 } |
1257 |
1186 |
1258 QT_TRY { |
1187 QT_TRY { |
1259 d->setWinId(0); |
1188 d->setWinId(0); |
1296 } |
1225 } |
1297 } |
1226 } |
1298 |
1227 |
1299 void QWidget::grabMouse() |
1228 void QWidget::grabMouse() |
1300 { |
1229 { |
1301 if (!qt_nograb()) { |
1230 if (isVisible() && !qt_nograb()) { |
1302 if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this) |
1231 if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this) |
1303 QWidgetPrivate::mouseGrabber->releaseMouse(); |
1232 QWidgetPrivate::mouseGrabber->releaseMouse(); |
1304 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
1233 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
1305 WId id = effectiveWinId(); |
1234 WId id = effectiveWinId(); |
1306 id->SetPointerCapture(true); |
1235 id->SetPointerCapture(true); |
1313 } |
1242 } |
1314 |
1243 |
1315 #ifndef QT_NO_CURSOR |
1244 #ifndef QT_NO_CURSOR |
1316 void QWidget::grabMouse(const QCursor &cursor) |
1245 void QWidget::grabMouse(const QCursor &cursor) |
1317 { |
1246 { |
1318 if (!qt_nograb()) { |
1247 if (isVisible() && !qt_nograb()) { |
1319 if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this) |
1248 if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this) |
1320 QWidgetPrivate::mouseGrabber->releaseMouse(); |
1249 QWidgetPrivate::mouseGrabber->releaseMouse(); |
1321 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
1250 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
1322 WId id = effectiveWinId(); |
1251 WId id = effectiveWinId(); |
1323 id->SetPointerCapture(true); |
1252 id->SetPointerCapture(true); |