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(QWindow *parentWindow, 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 if (childWidget->isTopLevel())
74 childWidget->windowHandle()->setTransientParent(parentWindow);
76 childWidget->windowHandle()->setParent(parentWindow);
79 q_createNativeChildrenAndSetParent(parentWindow,childWidget);
87 void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
92 Q_UNUSED(initializeWindow);
93 Q_UNUSED(destroyOldWindow);
95 Qt::WindowFlags flags = data.window_flags;
97 if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow())
98 return; // we only care about real toplevels
100 QWindow *win = topData()->window;
101 // topData() ensures the extra is created but does not ensure 'window' is non-null
102 // in case the extra was already valid.
105 win = topData()->window;
108 win->setWindowFlags(data.window_flags);
109 fixPosIncludesFrame();
110 win->setGeometry(q->geometry());
111 win->setScreen(QGuiApplication::screens().value(topData()->screenIndex, 0));
113 if (q->testAttribute(Qt::WA_TranslucentBackground)) {
114 QSurfaceFormat format;
115 format.setAlphaBufferSize(8);
116 win->setFormat(format);
119 if (QWidget *nativeParent = q->nativeParentWidget()) {
120 if (nativeParent->windowHandle()) {
121 if (flags & Qt::Window) {
122 win->setTransientParent(nativeParent->windowHandle());
125 win->setTransientParent(0);
126 win->setParent(nativeParent->windowHandle());
131 qt_window_private(win)->positionPolicy = topData()->posIncludesFrame ?
132 QWindowPrivate::WindowFrameInclusive : QWindowPrivate::WindowFrameExclusive;
135 data.window_flags = win->windowFlags();
137 QBackingStore *store = q->backingStore();
140 if (win && q->windowType() != Qt::Desktop)
141 q->setBackingStore(new QBackingStore(win));
143 q->setAttribute(Qt::WA_PaintOnScreen, true);
146 setWindowModified_helper();
147 setWinId(win->winId());
149 // Check children and create windows for them if necessary
150 q_createNativeChildrenAndSetParent(q->windowHandle(), q);
152 // If widget is already shown, set window visible, too
154 win->setVisible(true);
157 void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
162 if (!isWindow() && parentWidget())
163 parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
164 d->deactivateWidgetCleanup();
166 if ((windowType() == Qt::Popup))
167 qApp->d_func()->closePopup(this);
169 if (this == QApplicationPrivate::active_window)
170 QApplication::setActiveWindow(0);
172 setAttribute(Qt::WA_WState_Created, false);
174 if (windowType() != Qt::Desktop) {
175 if (destroySubWindows) {
176 QObjectList childList(children());
177 for (int i = 0; i < childList.size(); i++) {
178 QWidget *widget = qobject_cast<QWidget *>(childList.at(i));
179 if (widget && widget->testAttribute(Qt::WA_NativeWindow)) {
180 if (widget->windowHandle()) {
187 d->deleteTLSysExtra();
189 if (parentWidget() && parentWidget()->testAttribute(Qt::WA_WState_Created)) {
198 void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
202 Qt::WindowFlags oldFlags = data.window_flags;
203 bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
205 int targetScreen = -1;
206 // Handle a request to move the widget to a particular screen
207 if (newparent && newparent->windowType() == Qt::Desktop) {
208 // make sure the widget is created on the same screen as the
209 // programmer specified desktop widget
211 // get the desktop's screen number
212 targetScreen = newparent->window()->d_func()->topData()->screenIndex;
218 if (parent != newparent) {
219 QObjectPrivate::setParent_helper(newparent); //### why does this have to be done in the _sys function???
220 if (q->windowHandle()) {
221 q->windowHandle()->setWindowFlags(f);
222 QWidget *parentWithWindow =
223 newparent ? (newparent->windowHandle() ? newparent : newparent->nativeParentWidget()) : 0;
224 if (parentWithWindow) {
225 if (f & Qt::Window) {
226 q->windowHandle()->setTransientParent(parentWithWindow->windowHandle());
227 q->windowHandle()->setParent(0);
229 q->windowHandle()->setTransientParent(0);
230 q->windowHandle()->setParent(parentWithWindow->windowHandle());
233 q->windowHandle()->setTransientParent(0);
234 q->windowHandle()->setParent(0);
241 if (targetScreen == -1) {
243 targetScreen = q->parentWidget()->window()->d_func()->topData()->screenIndex;
247 bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
249 // Reparenting toplevel to child
250 if (!(f&Qt::Window) && (oldFlags&Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) {
251 //qDebug() << "setParent_sys() change from toplevel";
253 } else if (newparent && wasCreated) {
258 data.window_flags = f;
259 q->setAttribute(Qt::WA_WState_Created, false);
260 q->setAttribute(Qt::WA_WState_Visible, false);
261 q->setAttribute(Qt::WA_WState_Hidden, false);
263 if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden)
264 q->setAttribute(Qt::WA_WState_Hidden);
265 q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
267 // move the window to the selected screen
268 if (!newparent && targetScreen != -1) {
270 maybeTopData()->screenIndex = targetScreen;
271 // only if it is already created
272 if (q->testAttribute(Qt::WA_WState_Created)) {
273 q->windowHandle()->setScreen(QGuiApplication::screens().value(targetScreen, 0));
278 QPoint QWidget::mapToGlobal(const QPoint &pos) const
280 int x = pos.x(), y = pos.y();
281 const QWidget *w = this;
283 x += w->data->crect.x();
284 y += w->data->crect.y();
285 w = w->isWindow() ? 0 : w->parentWidget();
290 QPoint QWidget::mapFromGlobal(const QPoint &pos) const
292 int x = pos.x(), y = pos.y();
293 const QWidget *w = this;
295 x -= w->data->crect.x();
296 y -= w->data->crect.y();
297 w = w->isWindow() ? 0 : w->parentWidget();
302 void QWidgetPrivate::updateSystemBackground() {}
305 void QWidgetPrivate::setCursor_sys(const QCursor &cursor)
309 qt_qpa_set_cursor(q, false);
312 void QWidgetPrivate::unsetCursor_sys()
315 qt_qpa_set_cursor(q, false);
318 #endif //QT_NO_CURSOR
320 void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
326 if (QWindow *window = q->windowHandle())
327 window->setWindowTitle(caption);
331 void QWidgetPrivate::setWindowIcon_sys()
334 if (QWindow *window = q->windowHandle())
335 window->setWindowIcon(q->windowIcon());
338 void QWidgetPrivate::setWindowIconText_sys(const QString &iconText)
343 QWidget *qt_pressGrab = 0;
344 QWidget *qt_mouseGrb = 0;
345 static QWidget *keyboardGrb = 0;
347 void QWidget::grabMouse()
350 qt_mouseGrb->releaseMouse();
353 windowHandle()->setMouseGrabEnabled(true);
360 void QWidget::grabMouse(const QCursor &cursor)
365 qt_mouseGrb->releaseMouse();
368 windowHandle()->setMouseGrabEnabled(true);
375 bool QWidgetPrivate::stealMouseGrab(bool grab)
377 // This is like a combination of grab/releaseMouse() but with error checking
378 // and it has no effect on the result of mouseGrabber().
380 return q->windowHandle() ? q->windowHandle()->setMouseGrabEnabled(grab) : false;
383 void QWidget::releaseMouse()
385 if (qt_mouseGrb == this) {
387 windowHandle()->setMouseGrabEnabled(false);
392 void QWidget::grabKeyboard()
395 keyboardGrb->releaseKeyboard();
397 windowHandle()->setKeyboardGrabEnabled(true);
401 bool QWidgetPrivate::stealKeyboardGrab(bool grab)
403 // This is like a combination of grab/releaseKeyboard() but with error
404 // checking and it has no effect on the result of keyboardGrabber().
406 return q->windowHandle() ? q->windowHandle()->setKeyboardGrabEnabled(grab) : false;
409 void QWidget::releaseKeyboard()
411 if (keyboardGrb == this) {
413 windowHandle()->setKeyboardGrabEnabled(false);
418 QWidget *QWidget::mouseGrabber()
425 QWidget *QWidget::keyboardGrabber()
430 void QWidget::activateWindow()
433 windowHandle()->requestActivateWindow();
436 // Position top level windows at the center, avoid showing
437 // Windows at the default 0,0 position excluding the frame.
438 static inline QRect positionTopLevelWindow(QRect geometry, const QScreen *screen)
440 if (screen && geometry.x() == 0 && geometry.y() == 0) {
441 const QRect availableGeometry = screen->availableGeometry();
442 if (availableGeometry.width() > geometry.width()
443 && availableGeometry.height() > geometry.height())
444 geometry.moveCenter(availableGeometry.center());
449 // move() was invoked with Qt::WA_WState_Created not set (frame geometry
450 // unknown), that is, crect has a position including the frame.
451 // If we can determine the frame strut, fix that and clear the flag.
452 void QWidgetPrivate::fixPosIncludesFrame()
455 if (QTLWExtra *te = maybeTopData()) {
456 if (te->posIncludesFrame) {
457 // For Qt::WA_DontShowOnScreen, assume a frame of 0 (for
458 // example, in QGraphicsProxyWidget).
459 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
460 te->posIncludesFrame = 0;
462 if (q->windowHandle()) {
464 if (!q->data->fstrut_dirty) {
465 data.crect.translate(te->frameStrut.x(), te->frameStrut.y());
466 te->posIncludesFrame = 0;
469 } // !WA_DontShowOnScreen
470 } // posIncludesFrame
474 void QWidgetPrivate::show_sys()
478 QWindow *window = q->windowHandle();
480 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
481 invalidateBuffer(q->rect());
482 q->setAttribute(Qt::WA_Mapped);
483 if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
484 // add our window to the modal window list
485 QGuiApplicationPrivate::showModalWindow(window);
490 QApplication::postEvent(q, new QUpdateLaterEvent(q->rect()));
492 if (!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow))
497 fixPosIncludesFrame();
498 QRect geomRect = q->geometry();
500 if (!q->testAttribute(Qt::WA_Moved))
501 geomRect = positionTopLevelWindow(geomRect, window->screen());
503 QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint());
504 geomRect.moveTopLeft(topLeftOfWindow);
506 const QRect windowRect = window->geometry();
507 if (windowRect != geomRect) {
508 window->setGeometry(geomRect);
511 if (QBackingStore *store = q->backingStore()) {
512 if (store->size() != geomRect.size()) {
513 store->resize(geomRect.size());
517 invalidateBuffer(q->rect());
518 window->setVisible(true);
523 void QWidgetPrivate::hide_sys()
527 QWindow *window = q->windowHandle();
529 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
530 q->setAttribute(Qt::WA_Mapped, false);
531 if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
532 // remove our window from the modal window list
533 QGuiApplicationPrivate::hideModalWindow(window);
535 // do not return here, if window non-zero, we must hide it
538 deactivateWidgetCleanup();
540 if (!q->isWindow()) {
541 QWidget *p = q->parentWidget();
542 if (p &&p->isVisible()) {
543 invalidateBuffer(q->rect());
548 invalidateBuffer(q->rect());
551 window->setVisible(false);
554 void QWidgetPrivate::setMaxWindowState_helper()
558 const uint old_state = data.in_set_window_state;
559 data.in_set_window_state = 1;
561 const QRect desktop = qApp->desktop()->availableGeometry(qApp->desktop()->screenNumber(q));
562 q->setGeometry(desktop);
564 data.in_set_window_state = old_state;
567 void QWidgetPrivate::setFullScreenSize_helper()
571 const uint old_state = data.in_set_window_state;
572 data.in_set_window_state = 1;
574 const QRect screen = qApp->desktop()->screenGeometry(qApp->desktop()->screenNumber(q));
575 q->move(screen.topLeft());
576 q->resize(screen.size());
578 data.in_set_window_state = old_state;
581 Qt::WindowState effectiveState(Qt::WindowStates state)
583 if (state & Qt::WindowMinimized)
584 return Qt::WindowMinimized;
585 else if (state & Qt::WindowFullScreen)
586 return Qt::WindowFullScreen;
587 else if (state & Qt::WindowMaximized)
588 return Qt::WindowMaximized;
589 return Qt::WindowNoState;
592 void QWidget::setWindowState(Qt::WindowStates newstate)
595 Qt::WindowStates oldstate = windowState();
596 if (oldstate == newstate)
598 if (isWindow() && !testAttribute(Qt::WA_WState_Created))
601 data->window_state = newstate;
602 data->in_set_window_state = 1;
603 bool needShow = false;
604 Qt::WindowState newEffectiveState = effectiveState(newstate);
605 Qt::WindowState oldEffectiveState = effectiveState(oldstate);
606 if (isWindow() && newEffectiveState != oldEffectiveState) {
608 if (oldEffectiveState == Qt::WindowNoState)
609 d->topData()->normalGeometry = geometry();
611 Q_ASSERT(windowHandle());
612 windowHandle()->setWindowState(newEffectiveState);
613 bool supported = windowHandle()->windowState() == newEffectiveState;
616 // undo the effects of the old emulated state
617 if (oldEffectiveState == Qt::WindowFullScreen) {
618 setParent(0, d->topData()->savedFlags);
620 } else if (oldEffectiveState == Qt::WindowMinimized) {
624 // emulate the new window state
625 if (newEffectiveState == Qt::WindowMinimized) {
629 } else if (newEffectiveState == Qt::WindowFullScreen) {
630 d->topData()->savedFlags = windowFlags();
631 setParent(0, Qt::FramelessWindowHint | (windowFlags() & Qt::WindowStaysOnTopHint));
632 d->setFullScreenSize_helper();
635 } else if (newEffectiveState == Qt::WindowMaximized) {
637 d->setMaxWindowState_helper();
638 } else if (newEffectiveState == Qt::WindowNoState) {
639 // reset old geometry
640 QRect r = d->topData()->normalGeometry;
641 if (r.width() >= 0) {
642 d->topData()->normalGeometry = QRect(0,0,-1,-1);
648 data->in_set_window_state = 0;
653 if (newstate & Qt::WindowActive)
656 QWindowStateChangeEvent e(oldstate);
657 QApplication::sendEvent(this, &e);
660 void QWidgetPrivate::setFocus_sys()
665 void QWidgetPrivate::raise_sys()
669 q->windowHandle()->raise();
673 void QWidgetPrivate::lower_sys()
677 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
678 q->windowHandle()->lower();
679 } else if (QWidget *p = q->parentWidget()) {
680 setDirtyOpaqueRegion();
681 p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
685 void QWidgetPrivate::stackUnder_sys(QWidget*)
688 if (QWidget *p = q->parentWidget()) {
689 setDirtyOpaqueRegion();
690 p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
694 void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
697 if (extra) { // any size restrictions?
698 w = qMin(w,extra->maxw);
699 h = qMin(h,extra->maxh);
700 w = qMax(w,extra->minw);
701 h = qMax(h,extra->minh);
704 QPoint oldp = q->geometry().topLeft();
705 QSize olds = q->size();
708 bool isResize = olds != r.size();
709 isMove = oldp != r.topLeft(); //### why do we have isMove as a parameter?
712 // We only care about stuff that changes the geometry, or may
713 // cause the window manager to change its state
714 if (r.size() == olds && oldp == r.topLeft())
717 if (!data.in_set_window_state) {
718 q->data->window_state &= ~Qt::WindowMaximized;
719 q->data->window_state &= ~Qt::WindowFullScreen;
721 topData()->normalGeometry = QRect(0, 0, -1, -1);
724 QPoint oldPos = q->pos();
727 bool needsShow = false;
729 if (w == 0 || h == 0) {
730 q->setAttribute(Qt::WA_OutsideWSRange, true);
731 if (q->isVisible() && q->testAttribute(Qt::WA_Mapped))
733 data.crect = QRect(x, y, w, h);
734 } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) {
735 q->setAttribute(Qt::WA_OutsideWSRange, false);
739 if (q->isVisible()) {
740 if (!q->testAttribute(Qt::WA_DontShowOnScreen) && !q->testAttribute(Qt::WA_OutsideWSRange)) {
741 if (q->windowHandle()) {
743 q->windowHandle()->setGeometry(q->geometry());
745 QPoint posInNativeParent = q->mapTo(q->nativeParentWidget(),QPoint());
746 q->windowHandle()->setGeometry(QRect(posInNativeParent,r.size()));
748 const QWidgetBackingStore *bs = maybeBackingStore();
751 bs->store->resize(r.size());
757 if (isMove && !isResize)
758 moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y());
760 invalidateBuffer_resizeHelper(oldPos, olds);
765 QMoveEvent e(q->pos(), oldPos);
766 QApplication::sendEvent(q, &e);
769 QResizeEvent e(r.size(), olds);
770 QApplication::sendEvent(q, &e);
771 if (q->windowHandle())
774 } else { // not visible
775 if (isMove && q->pos() != oldPos)
776 q->setAttribute(Qt::WA_PendingMoveEvent, true);
778 q->setAttribute(Qt::WA_PendingResizeEvent, true);
783 void QWidgetPrivate::setConstraints_sys()
786 if (extra && q->windowHandle()) {
787 QWindow *win = q->windowHandle();
788 QWindowPrivate *winp = qt_window_private(win);
790 winp->minimumSize = QSize(extra->minw, extra->minh);
791 winp->maximumSize = QSize(extra->maxw, extra->maxh);
793 if (extra->topextra) {
794 winp->baseSize = QSize(extra->topextra->basew, extra->topextra->baseh);
795 winp->sizeIncrement = QSize(extra->topextra->incw, extra->topextra->inch);
798 if (winp->platformWindow) {
799 fixPosIncludesFrame();
800 winp->platformWindow->propagateSizeHints();
805 void QWidgetPrivate::scroll_sys(int dx, int dy)
808 scrollChildren(dx, dy);
809 scrollRect(q->rect(), dx, dy);
812 void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
814 scrollRect(r, dx, dy);
817 int QWidget::metric(PaintDeviceMetric m) const
822 if (QWidget *topLevel = window())
823 if (QWindow *topLevelWindow = topLevel->windowHandle()) {
824 QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow);
826 screen = platformScreen->screen();
828 if (!screen && QGuiApplication::primaryScreen())
829 screen = QGuiApplication::primaryScreen();
832 if (m == PdmDpiX || m == PdmDpiY)
834 return QPaintDevice::metric(m);
838 val = data->crect.width();
839 } else if (m == PdmWidthMM) {
840 val = data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
841 } else if (m == PdmHeight) {
842 val = data->crect.height();
843 } else if (m == PdmHeightMM) {
844 val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
845 } else if (m == PdmDepth) {
846 return screen->depth();
847 } else if (m == PdmDpiX) {
848 if (d->extra && d->extra->customDpiX)
849 return d->extra->customDpiX;
851 return static_cast<QWidget *>(d->parent)->metric(m);
852 return qRound(screen->logicalDotsPerInchX());
853 } else if (m == PdmDpiY) {
854 if (d->extra && d->extra->customDpiY)
855 return d->extra->customDpiY;
857 return static_cast<QWidget *>(d->parent)->metric(m);
858 return qRound(screen->logicalDotsPerInchY());
859 } else if (m == PdmPhysicalDpiX) {
860 return qRound(screen->physicalDotsPerInchX());
861 } else if (m == PdmPhysicalDpiY) {
862 return qRound(screen->physicalDotsPerInchY());
864 val = QPaintDevice::metric(m);// XXX
872 Returns the QPlatformWindow this widget will be drawn into.
874 QWindow *QWidget::windowHandle() const
877 QTLWExtra *extra = d->maybeTopData();
879 return extra->window;
884 void QWidgetPrivate::createSysExtra()
888 void QWidgetPrivate::deleteSysExtra()
893 void QWidgetPrivate::createTLSysExtra()
896 extra->topextra->screenIndex = 0;
897 extra->topextra->window = 0;
898 if (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow())
899 extra->topextra->window = new QWidgetWindow(q);
902 void QWidgetPrivate::deleteTLSysExtra()
904 if (extra && extra->topextra) {
905 //the toplevel might have a context with a "qglcontext associated with it. We need to
906 //delete the qglcontext before we delete the qplatformopenglcontext.
907 //One unfortunate thing about this is that we potentially create a glContext just to
908 //delete it straight afterwards.
909 if (extra->topextra->window) {
910 extra->topextra->window->destroy();
913 //hmmm. should we delete window..
914 delete extra->topextra->window;
915 extra->topextra->window = 0;
919 void QWidgetPrivate::registerDropSite(bool on)
924 void QWidgetPrivate::setMask_sys(const QRegion ®ion)
930 void QWidgetPrivate::updateFrameStrut()
933 if (q->data->fstrut_dirty) {
934 if (QTLWExtra *te = maybeTopData()) {
936 if (const QPlatformWindow *pw = te->window->handle()) {
937 const QMargins margins = pw->frameMargins();
938 if (!margins.isNull()) {
939 te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
940 q->data->fstrut_dirty = false;
948 void QWidgetPrivate::setWindowOpacity_sys(qreal level)
951 if (q->windowHandle())
952 q->windowHandle()->setOpacity(level);
955 void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
962 QPaintEngine *QWidget::paintEngine() const
964 qWarning("QWidget::paintEngine: Should no longer be called");
965 return 0; //##### @@@
968 void QWidgetPrivate::setModal_sys()
971 if (q->windowHandle())
972 q->windowHandle()->setWindowModality(q->windowModality());
976 static inline void applyCursor(QWidget *w, QCursor c)
978 if (QWindow *window = w->windowHandle())
979 if (const QScreen *screen = window->screen())
980 if (QPlatformCursor *cursor = screen->handle()->cursor())
981 cursor->changeCursor(&c, window);
984 void qt_qpa_set_cursor(QWidget *w, bool force)
986 if (!w->testAttribute(Qt::WA_WState_Created))
989 static QPointer<QWidget> lastUnderMouse = 0;
992 } else if (lastUnderMouse && lastUnderMouse->effectiveWinId() == w->effectiveWinId()) {
994 } else if (!w->internalWinId()) {
995 return; // The mouse is not under this widget, and it's not native, so don't change it.
998 while (!w->internalWinId() && w->parentWidget() && !w->isWindow()
999 && !w->testAttribute(Qt::WA_SetCursor))
1000 w = w->parentWidget();
1002 QWidget *nativeParent = w;
1003 if (!w->internalWinId())
1004 nativeParent = w->nativeParentWidget();
1005 if (!nativeParent || !nativeParent->internalWinId())
1008 if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {
1009 QCursor *oc = QApplication::overrideCursor();
1011 applyCursor(nativeParent, *oc);
1012 else if (w->isEnabled())
1013 applyCursor(nativeParent, w->cursor());
1015 // Enforce the windows behavior of clearing the cursor on
1016 // disabled widgets.
1017 applyCursor(nativeParent, Qt::ArrowCursor);
1019 applyCursor(nativeParent, Qt::ArrowCursor);
1022 #endif //QT_NO_CURSOR