1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "QtWidgets/qwidget.h"
43 #include "QtGui/qevent.h"
44 #include "QtWidgets/qapplication.h"
45 #include "private/qwidgetbackingstore_p.h"
46 #include "private/qwidget_p.h"
47 #include "private/qwidgetwindow_qpa_p.h"
48 #include "private/qapplication_p.h"
49 #include "QtWidgets/qdesktopwidget.h"
50 #include <qpa/qplatformwindow.h>
51 #include "QtGui/qsurfaceformat.h"
52 #include <qpa/qplatformopenglcontext.h>
53 #include "QtGui/private/qwindow_p.h"
55 #include <qpa/qplatformcursor.h>
56 #include <QtGui/QGuiApplication>
57 #include <QtGui/QScreen>
58 #include <QtCore/QMargins>
62 void q_createNativeChildrenAndSetParent(const QWidget *parentWidget)
64 QObjectList children = parentWidget->children();
65 for (int i = 0; i < children.size(); i++) {
66 if (children.at(i)->isWidgetType()) {
67 const QWidget *childWidget = qobject_cast<const QWidget *>(children.at(i));
68 if (childWidget) { // should not be necessary
69 if (childWidget->testAttribute(Qt::WA_NativeWindow)) {
70 if (!childWidget->windowHandle())
72 if (childWidget->windowHandle()) {
73 QWindow *parentWindow = childWidget->nativeParentWidget()->windowHandle();
74 if (childWidget->isWindow())
75 childWidget->windowHandle()->setTransientParent(parentWindow);
77 childWidget->windowHandle()->setParent(parentWindow);
80 q_createNativeChildrenAndSetParent(childWidget);
88 void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
93 Q_UNUSED(initializeWindow);
94 Q_UNUSED(destroyOldWindow);
96 Qt::WindowFlags flags = data.window_flags;
98 if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow())
99 return; // we only care about real toplevels
101 QWindow *win = topData()->window;
102 // topData() ensures the extra is created but does not ensure 'window' is non-null
103 // in case the extra was already valid.
106 win = topData()->window;
109 win->setWindowFlags(data.window_flags);
110 fixPosIncludesFrame();
111 win->setGeometry(q->geometry());
112 win->setScreen(QGuiApplication::screens().value(topData()->screenIndex, 0));
114 if (q->testAttribute(Qt::WA_TranslucentBackground)) {
115 QSurfaceFormat format;
116 format.setAlphaBufferSize(8);
117 win->setFormat(format);
120 if (QWidget *nativeParent = q->nativeParentWidget()) {
121 if (nativeParent->windowHandle()) {
122 if (flags & Qt::Window) {
123 win->setTransientParent(nativeParent->windowHandle());
126 win->setTransientParent(0);
127 win->setParent(nativeParent->windowHandle());
132 qt_window_private(win)->positionPolicy = topData()->posIncludesFrame ?
133 QWindowPrivate::WindowFrameInclusive : QWindowPrivate::WindowFrameExclusive;
136 data.window_flags = win->windowFlags();
138 QBackingStore *store = q->backingStore();
141 if (win && q->windowType() != Qt::Desktop)
142 q->setBackingStore(new QBackingStore(win));
144 q->setAttribute(Qt::WA_PaintOnScreen, true);
147 setWindowModified_helper();
148 setWinId(win->winId());
150 // Check children and create windows for them if necessary
151 q_createNativeChildrenAndSetParent(q);
153 // If widget is already shown, set window visible, too
155 win->setVisible(true);
158 void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
163 if (!isWindow() && parentWidget())
164 parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
165 d->deactivateWidgetCleanup();
167 if ((windowType() == Qt::Popup))
168 qApp->d_func()->closePopup(this);
170 if (this == QApplicationPrivate::active_window)
171 QApplication::setActiveWindow(0);
172 if (QWidget::mouseGrabber() == this)
174 if (QWidget::keyboardGrabber() == this)
177 setAttribute(Qt::WA_WState_Created, false);
179 if (windowType() != Qt::Desktop) {
180 if (destroySubWindows) {
181 QObjectList childList(children());
182 for (int i = 0; i < childList.size(); i++) {
183 QWidget *widget = qobject_cast<QWidget *>(childList.at(i));
184 if (widget && widget->testAttribute(Qt::WA_NativeWindow)) {
185 if (widget->windowHandle()) {
192 d->deleteTLSysExtra();
194 if (parentWidget() && parentWidget()->testAttribute(Qt::WA_WState_Created)) {
203 void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
207 Qt::WindowFlags oldFlags = data.window_flags;
208 bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
210 int targetScreen = -1;
211 // Handle a request to move the widget to a particular screen
212 if (newparent && newparent->windowType() == Qt::Desktop) {
213 // make sure the widget is created on the same screen as the
214 // programmer specified desktop widget
216 // get the desktop's screen number
217 targetScreen = newparent->window()->d_func()->topData()->screenIndex;
223 if (parent != newparent) {
224 QObjectPrivate::setParent_helper(newparent); //### why does this have to be done in the _sys function???
225 if (q->windowHandle()) {
226 q->windowHandle()->setWindowFlags(f);
227 QWidget *parentWithWindow =
228 newparent ? (newparent->windowHandle() ? newparent : newparent->nativeParentWidget()) : 0;
229 if (parentWithWindow) {
230 if (f & Qt::Window) {
231 q->windowHandle()->setTransientParent(parentWithWindow->windowHandle());
232 q->windowHandle()->setParent(0);
234 q->windowHandle()->setTransientParent(0);
235 q->windowHandle()->setParent(parentWithWindow->windowHandle());
238 q->windowHandle()->setTransientParent(0);
239 q->windowHandle()->setParent(0);
246 if (targetScreen == -1) {
248 targetScreen = q->parentWidget()->window()->d_func()->topData()->screenIndex;
252 bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
254 // Reparenting toplevel to child
255 if (!(f&Qt::Window) && (oldFlags&Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) {
256 //qDebug() << "setParent_sys() change from toplevel";
258 } else if (newparent && wasCreated) {
263 data.window_flags = f;
264 q->setAttribute(Qt::WA_WState_Created, false);
265 q->setAttribute(Qt::WA_WState_Visible, false);
266 q->setAttribute(Qt::WA_WState_Hidden, false);
268 if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden)
269 q->setAttribute(Qt::WA_WState_Hidden);
270 q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
272 // move the window to the selected screen
273 if (!newparent && targetScreen != -1) {
275 maybeTopData()->screenIndex = targetScreen;
276 // only if it is already created
277 if (q->testAttribute(Qt::WA_WState_Created)) {
278 q->windowHandle()->setScreen(QGuiApplication::screens().value(targetScreen, 0));
283 QPoint QWidget::mapToGlobal(const QPoint &pos) const
285 int x = pos.x(), y = pos.y();
286 const QWidget *w = this;
288 x += w->data->crect.x();
289 y += w->data->crect.y();
290 w = w->isWindow() ? 0 : w->parentWidget();
295 QPoint QWidget::mapFromGlobal(const QPoint &pos) const
297 int x = pos.x(), y = pos.y();
298 const QWidget *w = this;
300 x -= w->data->crect.x();
301 y -= w->data->crect.y();
302 w = w->isWindow() ? 0 : w->parentWidget();
307 void QWidgetPrivate::updateSystemBackground() {}
310 void QWidgetPrivate::setCursor_sys(const QCursor &cursor)
314 qt_qpa_set_cursor(q, false);
317 void QWidgetPrivate::unsetCursor_sys()
320 qt_qpa_set_cursor(q, false);
323 #endif //QT_NO_CURSOR
325 void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
331 if (QWindow *window = q->windowHandle())
332 window->setWindowTitle(caption);
336 void QWidgetPrivate::setWindowIcon_sys()
339 if (QWindow *window = q->windowHandle())
340 window->setWindowIcon(q->windowIcon());
343 void QWidgetPrivate::setWindowIconText_sys(const QString &iconText)
348 QWidget *qt_pressGrab = 0;
349 QWidget *qt_mouseGrb = 0;
350 static QWidget *keyboardGrb = 0;
352 void QWidget::grabMouse()
355 qt_mouseGrb->releaseMouse();
358 windowHandle()->setMouseGrabEnabled(true);
365 void QWidget::grabMouse(const QCursor &cursor)
370 qt_mouseGrb->releaseMouse();
373 windowHandle()->setMouseGrabEnabled(true);
380 bool QWidgetPrivate::stealMouseGrab(bool grab)
382 // This is like a combination of grab/releaseMouse() but with error checking
383 // and it has no effect on the result of mouseGrabber().
385 return q->windowHandle() ? q->windowHandle()->setMouseGrabEnabled(grab) : false;
388 void QWidget::releaseMouse()
390 if (qt_mouseGrb == this) {
392 windowHandle()->setMouseGrabEnabled(false);
397 void QWidget::grabKeyboard()
400 keyboardGrb->releaseKeyboard();
402 windowHandle()->setKeyboardGrabEnabled(true);
406 bool QWidgetPrivate::stealKeyboardGrab(bool grab)
408 // This is like a combination of grab/releaseKeyboard() but with error
409 // checking and it has no effect on the result of keyboardGrabber().
411 return q->windowHandle() ? q->windowHandle()->setKeyboardGrabEnabled(grab) : false;
414 void QWidget::releaseKeyboard()
416 if (keyboardGrb == this) {
418 windowHandle()->setKeyboardGrabEnabled(false);
423 QWidget *QWidget::mouseGrabber()
430 QWidget *QWidget::keyboardGrabber()
435 void QWidget::activateWindow()
438 windowHandle()->requestActivateWindow();
441 // Position top level windows at the center, avoid showing
442 // Windows at the default 0,0 position excluding the frame.
443 static inline QRect positionTopLevelWindow(QRect geometry, const QScreen *screen)
445 if (screen && geometry.x() == 0 && geometry.y() == 0) {
446 const QRect availableGeometry = screen->availableGeometry();
447 if (availableGeometry.width() > geometry.width()
448 && availableGeometry.height() > geometry.height())
449 geometry.moveCenter(availableGeometry.center());
454 // move() was invoked with Qt::WA_WState_Created not set (frame geometry
455 // unknown), that is, crect has a position including the frame.
456 // If we can determine the frame strut, fix that and clear the flag.
457 void QWidgetPrivate::fixPosIncludesFrame()
460 if (QTLWExtra *te = maybeTopData()) {
461 if (te->posIncludesFrame) {
462 // For Qt::WA_DontShowOnScreen, assume a frame of 0 (for
463 // example, in QGraphicsProxyWidget).
464 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
465 te->posIncludesFrame = 0;
467 if (q->windowHandle()) {
469 if (!q->data->fstrut_dirty) {
470 data.crect.translate(te->frameStrut.x(), te->frameStrut.y());
471 te->posIncludesFrame = 0;
474 } // !WA_DontShowOnScreen
475 } // posIncludesFrame
479 void QWidgetPrivate::show_sys()
483 QWindow *window = q->windowHandle();
485 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
486 invalidateBuffer(q->rect());
487 q->setAttribute(Qt::WA_Mapped);
488 if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
489 // add our window to the modal window list
490 QGuiApplicationPrivate::showModalWindow(window);
495 QApplication::postEvent(q, new QUpdateLaterEvent(q->rect()));
497 if (!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow))
502 fixPosIncludesFrame();
503 QRect geomRect = q->geometry();
505 if (!q->testAttribute(Qt::WA_Moved))
506 geomRect = positionTopLevelWindow(geomRect, window->screen());
508 QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint());
509 geomRect.moveTopLeft(topLeftOfWindow);
511 const QRect windowRect = window->geometry();
512 if (windowRect != geomRect) {
513 window->setGeometry(geomRect);
516 if (QBackingStore *store = q->backingStore()) {
517 if (store->size() != geomRect.size()) {
518 store->resize(geomRect.size());
522 invalidateBuffer(q->rect());
523 window->setVisible(true);
528 void QWidgetPrivate::hide_sys()
532 QWindow *window = q->windowHandle();
534 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
535 q->setAttribute(Qt::WA_Mapped, false);
536 if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
537 // remove our window from the modal window list
538 QGuiApplicationPrivate::hideModalWindow(window);
540 // do not return here, if window non-zero, we must hide it
543 deactivateWidgetCleanup();
545 if (!q->isWindow()) {
546 QWidget *p = q->parentWidget();
547 if (p &&p->isVisible()) {
548 invalidateBuffer(q->rect());
551 invalidateBuffer(q->rect());
555 window->setVisible(false);
558 void QWidgetPrivate::setMaxWindowState_helper()
562 const uint old_state = data.in_set_window_state;
563 data.in_set_window_state = 1;
565 const QRect desktop = qApp->desktop()->availableGeometry(qApp->desktop()->screenNumber(q));
566 q->setGeometry(desktop);
568 data.in_set_window_state = old_state;
571 void QWidgetPrivate::setFullScreenSize_helper()
575 const uint old_state = data.in_set_window_state;
576 data.in_set_window_state = 1;
578 const QRect screen = qApp->desktop()->screenGeometry(qApp->desktop()->screenNumber(q));
579 q->move(screen.topLeft());
580 q->resize(screen.size());
582 data.in_set_window_state = old_state;
585 Qt::WindowState effectiveState(Qt::WindowStates state)
587 if (state & Qt::WindowMinimized)
588 return Qt::WindowMinimized;
589 else if (state & Qt::WindowFullScreen)
590 return Qt::WindowFullScreen;
591 else if (state & Qt::WindowMaximized)
592 return Qt::WindowMaximized;
593 return Qt::WindowNoState;
596 void QWidget::setWindowState(Qt::WindowStates newstate)
599 Qt::WindowStates oldstate = windowState();
600 if (oldstate == newstate)
602 if (isWindow() && !testAttribute(Qt::WA_WState_Created))
605 data->window_state = newstate;
606 data->in_set_window_state = 1;
607 bool needShow = false;
608 Qt::WindowState newEffectiveState = effectiveState(newstate);
609 Qt::WindowState oldEffectiveState = effectiveState(oldstate);
610 if (isWindow() && newEffectiveState != oldEffectiveState) {
612 if (oldEffectiveState == Qt::WindowNoState)
613 d->topData()->normalGeometry = geometry();
615 Q_ASSERT(windowHandle());
616 windowHandle()->setWindowState(newEffectiveState);
617 bool supported = windowHandle()->windowState() == newEffectiveState;
620 // undo the effects of the old emulated state
621 if (oldEffectiveState == Qt::WindowFullScreen) {
622 setParent(0, d->topData()->savedFlags);
624 } else if (oldEffectiveState == Qt::WindowMinimized) {
628 // emulate the new window state
629 if (newEffectiveState == Qt::WindowMinimized) {
633 } else if (newEffectiveState == Qt::WindowFullScreen) {
634 d->topData()->savedFlags = windowFlags();
635 setParent(0, Qt::FramelessWindowHint | (windowFlags() & Qt::WindowStaysOnTopHint));
636 d->setFullScreenSize_helper();
639 } else if (newEffectiveState == Qt::WindowMaximized) {
641 d->setMaxWindowState_helper();
642 } else if (newEffectiveState == Qt::WindowNoState) {
643 // reset old geometry
644 QRect r = d->topData()->normalGeometry;
645 if (r.width() >= 0) {
646 d->topData()->normalGeometry = QRect(0,0,-1,-1);
652 data->in_set_window_state = 0;
657 if (newstate & Qt::WindowActive)
660 QWindowStateChangeEvent e(oldstate);
661 QApplication::sendEvent(this, &e);
664 void QWidgetPrivate::setFocus_sys()
669 void QWidgetPrivate::raise_sys()
673 q->windowHandle()->raise();
677 void QWidgetPrivate::lower_sys()
681 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
682 q->windowHandle()->lower();
683 } else if (QWidget *p = q->parentWidget()) {
684 setDirtyOpaqueRegion();
685 p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
689 void QWidgetPrivate::stackUnder_sys(QWidget*)
692 if (QWidget *p = q->parentWidget()) {
693 setDirtyOpaqueRegion();
694 p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
698 void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
701 if (extra) { // any size restrictions?
702 w = qMin(w,extra->maxw);
703 h = qMin(h,extra->maxh);
704 w = qMax(w,extra->minw);
705 h = qMax(h,extra->minh);
708 QPoint oldp = q->geometry().topLeft();
709 QSize olds = q->size();
712 bool isResize = olds != r.size();
713 isMove = oldp != r.topLeft(); //### why do we have isMove as a parameter?
716 // We only care about stuff that changes the geometry, or may
717 // cause the window manager to change its state
718 if (r.size() == olds && oldp == r.topLeft())
721 if (!data.in_set_window_state) {
722 q->data->window_state &= ~Qt::WindowMaximized;
723 q->data->window_state &= ~Qt::WindowFullScreen;
725 topData()->normalGeometry = QRect(0, 0, -1, -1);
728 QPoint oldPos = q->pos();
731 bool needsShow = false;
733 if (w == 0 || h == 0) {
734 q->setAttribute(Qt::WA_OutsideWSRange, true);
735 if (q->isVisible() && q->testAttribute(Qt::WA_Mapped))
737 data.crect = QRect(x, y, w, h);
738 } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) {
739 q->setAttribute(Qt::WA_OutsideWSRange, false);
743 if (q->isVisible()) {
744 if (!q->testAttribute(Qt::WA_DontShowOnScreen) && !q->testAttribute(Qt::WA_OutsideWSRange)) {
745 if (q->windowHandle()) {
747 q->windowHandle()->setGeometry(q->geometry());
749 QPoint posInNativeParent = q->mapTo(q->nativeParentWidget(),QPoint());
750 q->windowHandle()->setGeometry(QRect(posInNativeParent,r.size()));
752 const QWidgetBackingStore *bs = maybeBackingStore();
755 bs->store->resize(r.size());
761 if (isMove && !isResize)
762 moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y());
764 invalidateBuffer_resizeHelper(oldPos, olds);
769 QMoveEvent e(q->pos(), oldPos);
770 QApplication::sendEvent(q, &e);
773 QResizeEvent e(r.size(), olds);
774 QApplication::sendEvent(q, &e);
775 if (q->windowHandle())
778 } else { // not visible
779 if (isMove && q->pos() != oldPos)
780 q->setAttribute(Qt::WA_PendingMoveEvent, true);
782 q->setAttribute(Qt::WA_PendingResizeEvent, true);
787 void QWidgetPrivate::setConstraints_sys()
790 if (extra && q->windowHandle()) {
791 QWindow *win = q->windowHandle();
792 QWindowPrivate *winp = qt_window_private(win);
794 winp->minimumSize = QSize(extra->minw, extra->minh);
795 winp->maximumSize = QSize(extra->maxw, extra->maxh);
797 if (extra->topextra) {
798 winp->baseSize = QSize(extra->topextra->basew, extra->topextra->baseh);
799 winp->sizeIncrement = QSize(extra->topextra->incw, extra->topextra->inch);
802 if (winp->platformWindow) {
803 fixPosIncludesFrame();
804 winp->platformWindow->propagateSizeHints();
809 void QWidgetPrivate::scroll_sys(int dx, int dy)
812 scrollChildren(dx, dy);
813 scrollRect(q->rect(), dx, dy);
816 void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
818 scrollRect(r, dx, dy);
821 int QWidget::metric(PaintDeviceMetric m) const
826 if (QWidget *topLevel = window())
827 if (QWindow *topLevelWindow = topLevel->windowHandle()) {
828 QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow);
830 screen = platformScreen->screen();
832 if (!screen && QGuiApplication::primaryScreen())
833 screen = QGuiApplication::primaryScreen();
836 if (m == PdmDpiX || m == PdmDpiY)
838 return QPaintDevice::metric(m);
842 val = data->crect.width();
843 } else if (m == PdmWidthMM) {
844 val = data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
845 } else if (m == PdmHeight) {
846 val = data->crect.height();
847 } else if (m == PdmHeightMM) {
848 val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
849 } else if (m == PdmDepth) {
850 return screen->depth();
851 } else if (m == PdmDpiX) {
852 if (d->extra && d->extra->customDpiX)
853 return d->extra->customDpiX;
855 return static_cast<QWidget *>(d->parent)->metric(m);
856 return qRound(screen->logicalDotsPerInchX());
857 } else if (m == PdmDpiY) {
858 if (d->extra && d->extra->customDpiY)
859 return d->extra->customDpiY;
861 return static_cast<QWidget *>(d->parent)->metric(m);
862 return qRound(screen->logicalDotsPerInchY());
863 } else if (m == PdmPhysicalDpiX) {
864 return qRound(screen->physicalDotsPerInchX());
865 } else if (m == PdmPhysicalDpiY) {
866 return qRound(screen->physicalDotsPerInchY());
868 val = QPaintDevice::metric(m);// XXX
876 Returns the QPlatformWindow this widget will be drawn into.
878 QWindow *QWidget::windowHandle() const
881 QTLWExtra *extra = d->maybeTopData();
883 return extra->window;
888 void QWidgetPrivate::createSysExtra()
892 void QWidgetPrivate::deleteSysExtra()
897 void QWidgetPrivate::createTLSysExtra()
900 extra->topextra->screenIndex = 0;
901 extra->topextra->window = 0;
902 if (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow())
903 extra->topextra->window = new QWidgetWindow(q);
906 void QWidgetPrivate::deleteTLSysExtra()
908 if (extra && extra->topextra) {
909 //the toplevel might have a context with a "qglcontext associated with it. We need to
910 //delete the qglcontext before we delete the qplatformopenglcontext.
911 //One unfortunate thing about this is that we potentially create a glContext just to
912 //delete it straight afterwards.
913 if (extra->topextra->window) {
914 extra->topextra->window->destroy();
917 delete extra->topextra->window;
918 extra->topextra->window = 0;
920 extra->topextra->backingStoreTracker.destroy();
921 delete extra->topextra->backingStore;
922 extra->topextra->backingStore = 0;
927 void QWidgetPrivate::registerDropSite(bool on)
932 void QWidgetPrivate::setMask_sys(const QRegion ®ion)
938 void QWidgetPrivate::updateFrameStrut()
941 if (q->data->fstrut_dirty) {
942 if (QTLWExtra *te = maybeTopData()) {
944 if (const QPlatformWindow *pw = te->window->handle()) {
945 const QMargins margins = pw->frameMargins();
946 if (!margins.isNull()) {
947 te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
948 q->data->fstrut_dirty = false;
956 void QWidgetPrivate::setWindowOpacity_sys(qreal level)
959 if (q->windowHandle())
960 q->windowHandle()->setOpacity(level);
963 void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
970 QPaintEngine *QWidget::paintEngine() const
972 qWarning("QWidget::paintEngine: Should no longer be called");
973 return 0; //##### @@@
976 void QWidgetPrivate::setModal_sys()
979 if (q->windowHandle())
980 q->windowHandle()->setWindowModality(q->windowModality());
984 static inline void applyCursor(QWidget *w, QCursor c)
986 if (QWindow *window = w->windowHandle())
987 if (const QScreen *screen = window->screen())
988 if (QPlatformCursor *cursor = screen->handle()->cursor())
989 cursor->changeCursor(&c, window);
992 void qt_qpa_set_cursor(QWidget *w, bool force)
994 if (!w->testAttribute(Qt::WA_WState_Created))
997 static QPointer<QWidget> lastUnderMouse = 0;
1000 } else if (lastUnderMouse) {
1001 const WId lastWinId = lastUnderMouse->effectiveWinId();
1002 const WId winId = w->effectiveWinId();
1003 if (lastWinId && lastWinId == winId)
1005 } else if (!w->internalWinId()) {
1006 return; // The mouse is not under this widget, and it's not native, so don't change it.
1009 while (!w->internalWinId() && w->parentWidget() && !w->isWindow()
1010 && !w->testAttribute(Qt::WA_SetCursor))
1011 w = w->parentWidget();
1013 QWidget *nativeParent = w;
1014 if (!w->internalWinId())
1015 nativeParent = w->nativeParentWidget();
1016 if (!nativeParent || !nativeParent->internalWinId())
1019 if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {
1020 QCursor *oc = QApplication::overrideCursor();
1022 applyCursor(nativeParent, *oc);
1023 else if (w->isEnabled())
1024 applyCursor(nativeParent, w->cursor());
1026 // Enforce the windows behavior of clearing the cursor on
1027 // disabled widgets.
1028 applyCursor(nativeParent, Qt::ArrowCursor);
1030 applyCursor(nativeParent, Qt::ArrowCursor);
1033 #endif //QT_NO_CURSOR