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(bool /*forceReset*/)
335 void QWidgetPrivate::setWindowIconText_sys(const QString &iconText)
340 QWidget *qt_pressGrab = 0;
341 QWidget *qt_mouseGrb = 0;
342 static QWidget *keyboardGrb = 0;
344 void QWidget::grabMouse()
347 qt_mouseGrb->releaseMouse();
350 windowHandle()->setMouseGrabEnabled(true);
357 void QWidget::grabMouse(const QCursor &cursor)
362 qt_mouseGrb->releaseMouse();
365 windowHandle()->setMouseGrabEnabled(true);
372 bool QWidgetPrivate::stealMouseGrab(bool grab)
374 // This is like a combination of grab/releaseMouse() but with error checking
375 // and it has no effect on the result of mouseGrabber().
377 return q->windowHandle() ? q->windowHandle()->setMouseGrabEnabled(grab) : false;
380 void QWidget::releaseMouse()
382 if (qt_mouseGrb == this) {
384 windowHandle()->setMouseGrabEnabled(false);
389 void QWidget::grabKeyboard()
392 keyboardGrb->releaseKeyboard();
394 windowHandle()->setKeyboardGrabEnabled(true);
398 bool QWidgetPrivate::stealKeyboardGrab(bool grab)
400 // This is like a combination of grab/releaseKeyboard() but with error
401 // checking and it has no effect on the result of keyboardGrabber().
403 return q->windowHandle() ? q->windowHandle()->setKeyboardGrabEnabled(grab) : false;
406 void QWidget::releaseKeyboard()
408 if (keyboardGrb == this) {
410 windowHandle()->setKeyboardGrabEnabled(false);
415 QWidget *QWidget::mouseGrabber()
422 QWidget *QWidget::keyboardGrabber()
427 void QWidget::activateWindow()
430 windowHandle()->requestActivateWindow();
433 // Position top level windows at the center, avoid showing
434 // Windows at the default 0,0 position excluding the frame.
435 static inline QRect positionTopLevelWindow(QRect geometry, const QScreen *screen)
437 if (screen && geometry.x() == 0 && geometry.y() == 0) {
438 const QRect availableGeometry = screen->availableGeometry();
439 if (availableGeometry.width() > geometry.width()
440 && availableGeometry.height() > geometry.height())
441 geometry.moveCenter(availableGeometry.center());
446 // move() was invoked with Qt::WA_WState_Created not set (frame geometry
447 // unknown), that is, crect has a position including the frame.
448 // If we can determine the frame strut, fix that and clear the flag.
449 void QWidgetPrivate::fixPosIncludesFrame()
452 if (QTLWExtra *te = maybeTopData()) {
453 if (te->posIncludesFrame) {
454 // For Qt::WA_DontShowOnScreen, assume a frame of 0 (for
455 // example, in QGraphicsProxyWidget).
456 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
457 te->posIncludesFrame = 0;
459 if (q->windowHandle()) {
461 if (!q->data->fstrut_dirty) {
462 data.crect.translate(te->frameStrut.x(), te->frameStrut.y());
463 te->posIncludesFrame = 0;
466 } // !WA_DontShowOnScreen
467 } // posIncludesFrame
471 void QWidgetPrivate::show_sys()
475 QWindow *window = q->windowHandle();
477 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
478 invalidateBuffer(q->rect());
479 q->setAttribute(Qt::WA_Mapped);
480 if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
481 // add our window to the modal window list
482 QGuiApplicationPrivate::showModalWindow(window);
487 QApplication::postEvent(q, new QUpdateLaterEvent(q->rect()));
489 if (!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow))
494 fixPosIncludesFrame();
495 QRect geomRect = q->geometry();
497 if (!q->testAttribute(Qt::WA_Moved))
498 geomRect = positionTopLevelWindow(geomRect, window->screen());
500 QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint());
501 geomRect.moveTopLeft(topLeftOfWindow);
503 const QRect windowRect = window->geometry();
504 if (windowRect != geomRect) {
505 window->setGeometry(geomRect);
508 if (QBackingStore *store = q->backingStore()) {
509 if (store->size() != geomRect.size()) {
510 store->resize(geomRect.size());
514 invalidateBuffer(q->rect());
515 window->setVisible(true);
520 void QWidgetPrivate::hide_sys()
524 QWindow *window = q->windowHandle();
526 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
527 q->setAttribute(Qt::WA_Mapped, false);
528 if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
529 // remove our window from the modal window list
530 QGuiApplicationPrivate::hideModalWindow(window);
532 // do not return here, if window non-zero, we must hide it
535 deactivateWidgetCleanup();
537 if (!q->isWindow()) {
538 QWidget *p = q->parentWidget();
539 if (p &&p->isVisible()) {
540 invalidateBuffer(q->rect());
545 invalidateBuffer(q->rect());
548 window->setVisible(false);
551 void QWidgetPrivate::setMaxWindowState_helper()
555 const uint old_state = data.in_set_window_state;
556 data.in_set_window_state = 1;
558 const QRect desktop = qApp->desktop()->availableGeometry(qApp->desktop()->screenNumber(q));
559 q->setGeometry(desktop);
561 data.in_set_window_state = old_state;
564 void QWidgetPrivate::setFullScreenSize_helper()
568 const uint old_state = data.in_set_window_state;
569 data.in_set_window_state = 1;
571 const QRect screen = qApp->desktop()->screenGeometry(qApp->desktop()->screenNumber(q));
572 q->move(screen.topLeft());
573 q->resize(screen.size());
575 data.in_set_window_state = old_state;
578 Qt::WindowState effectiveState(Qt::WindowStates state)
580 if (state & Qt::WindowMinimized)
581 return Qt::WindowMinimized;
582 else if (state & Qt::WindowFullScreen)
583 return Qt::WindowFullScreen;
584 else if (state & Qt::WindowMaximized)
585 return Qt::WindowMaximized;
586 return Qt::WindowNoState;
589 void QWidget::setWindowState(Qt::WindowStates newstate)
592 Qt::WindowStates oldstate = windowState();
593 if (oldstate == newstate)
595 if (isWindow() && !testAttribute(Qt::WA_WState_Created))
598 data->window_state = newstate;
599 data->in_set_window_state = 1;
600 bool needShow = false;
601 Qt::WindowState newEffectiveState = effectiveState(newstate);
602 Qt::WindowState oldEffectiveState = effectiveState(oldstate);
603 if (isWindow() && newEffectiveState != oldEffectiveState) {
605 if (oldEffectiveState == Qt::WindowNoState)
606 d->topData()->normalGeometry = geometry();
608 Q_ASSERT(windowHandle());
609 windowHandle()->setWindowState(newEffectiveState);
610 bool supported = windowHandle()->windowState() == newEffectiveState;
613 // undo the effects of the old emulated state
614 if (oldEffectiveState == Qt::WindowFullScreen) {
615 setParent(0, d->topData()->savedFlags);
617 } else if (oldEffectiveState == Qt::WindowMinimized) {
621 // emulate the new window state
622 if (newEffectiveState == Qt::WindowMinimized) {
626 } else if (newEffectiveState == Qt::WindowFullScreen) {
627 d->topData()->savedFlags = windowFlags();
628 setParent(0, Qt::FramelessWindowHint | (windowFlags() & Qt::WindowStaysOnTopHint));
629 d->setFullScreenSize_helper();
632 } else if (newEffectiveState == Qt::WindowMaximized) {
634 d->setMaxWindowState_helper();
635 } else if (newEffectiveState == Qt::WindowNoState) {
636 // reset old geometry
637 QRect r = d->topData()->normalGeometry;
638 if (r.width() >= 0) {
639 d->topData()->normalGeometry = QRect(0,0,-1,-1);
645 data->in_set_window_state = 0;
650 if (newstate & Qt::WindowActive)
653 QWindowStateChangeEvent e(oldstate);
654 QApplication::sendEvent(this, &e);
657 void QWidgetPrivate::setFocus_sys()
662 void QWidgetPrivate::raise_sys()
666 q->windowHandle()->raise();
670 void QWidgetPrivate::lower_sys()
674 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
675 q->windowHandle()->lower();
676 } else if (QWidget *p = q->parentWidget()) {
677 setDirtyOpaqueRegion();
678 p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
682 void QWidgetPrivate::stackUnder_sys(QWidget*)
685 if (QWidget *p = q->parentWidget()) {
686 setDirtyOpaqueRegion();
687 p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
691 void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
694 if (extra) { // any size restrictions?
695 w = qMin(w,extra->maxw);
696 h = qMin(h,extra->maxh);
697 w = qMax(w,extra->minw);
698 h = qMax(h,extra->minh);
701 QPoint oldp = q->geometry().topLeft();
702 QSize olds = q->size();
705 bool isResize = olds != r.size();
706 isMove = oldp != r.topLeft(); //### why do we have isMove as a parameter?
709 // We only care about stuff that changes the geometry, or may
710 // cause the window manager to change its state
711 if (r.size() == olds && oldp == r.topLeft())
714 if (!data.in_set_window_state) {
715 q->data->window_state &= ~Qt::WindowMaximized;
716 q->data->window_state &= ~Qt::WindowFullScreen;
718 topData()->normalGeometry = QRect(0, 0, -1, -1);
721 QPoint oldPos = q->pos();
724 bool needsShow = false;
726 if (w == 0 || h == 0) {
727 q->setAttribute(Qt::WA_OutsideWSRange, true);
728 if (q->isVisible() && q->testAttribute(Qt::WA_Mapped))
730 data.crect = QRect(x, y, w, h);
731 } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) {
732 q->setAttribute(Qt::WA_OutsideWSRange, false);
736 if (q->isVisible()) {
737 if (!q->testAttribute(Qt::WA_DontShowOnScreen) && !q->testAttribute(Qt::WA_OutsideWSRange)) {
738 if (q->windowHandle()) {
740 q->windowHandle()->setGeometry(q->geometry());
742 QPoint posInNativeParent = q->mapTo(q->nativeParentWidget(),QPoint());
743 q->windowHandle()->setGeometry(QRect(posInNativeParent,r.size()));
745 const QWidgetBackingStore *bs = maybeBackingStore();
748 bs->store->resize(r.size());
754 if (isMove && !isResize)
755 moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y());
757 invalidateBuffer_resizeHelper(oldPos, olds);
762 QMoveEvent e(q->pos(), oldPos);
763 QApplication::sendEvent(q, &e);
766 QResizeEvent e(r.size(), olds);
767 QApplication::sendEvent(q, &e);
768 if (q->windowHandle())
771 } else { // not visible
772 if (isMove && q->pos() != oldPos)
773 q->setAttribute(Qt::WA_PendingMoveEvent, true);
775 q->setAttribute(Qt::WA_PendingResizeEvent, true);
780 void QWidgetPrivate::setConstraints_sys()
783 if (extra && q->windowHandle()) {
784 QWindow *win = q->windowHandle();
785 QWindowPrivate *winp = qt_window_private(win);
787 winp->minimumSize = QSize(extra->minw, extra->minh);
788 winp->maximumSize = QSize(extra->maxw, extra->maxh);
790 if (extra->topextra) {
791 winp->baseSize = QSize(extra->topextra->basew, extra->topextra->baseh);
792 winp->sizeIncrement = QSize(extra->topextra->incw, extra->topextra->inch);
795 if (winp->platformWindow) {
796 fixPosIncludesFrame();
797 winp->platformWindow->propagateSizeHints();
802 void QWidgetPrivate::scroll_sys(int dx, int dy)
805 scrollChildren(dx, dy);
806 scrollRect(q->rect(), dx, dy);
809 void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
811 scrollRect(r, dx, dy);
814 int QWidget::metric(PaintDeviceMetric m) const
819 if (QWidget *topLevel = window())
820 if (QWindow *topLevelWindow = topLevel->windowHandle()) {
821 QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow);
823 screen = platformScreen->screen();
825 if (!screen && QGuiApplication::primaryScreen())
826 screen = QGuiApplication::primaryScreen();
829 if (m == PdmDpiX || m == PdmDpiY)
831 return QPaintDevice::metric(m);
835 val = data->crect.width();
836 } else if (m == PdmWidthMM) {
837 val = data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
838 } else if (m == PdmHeight) {
839 val = data->crect.height();
840 } else if (m == PdmHeightMM) {
841 val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
842 } else if (m == PdmDepth) {
843 return screen->depth();
844 } else if (m == PdmDpiX) {
845 if (d->extra && d->extra->customDpiX)
846 return d->extra->customDpiX;
848 return static_cast<QWidget *>(d->parent)->metric(m);
849 return qRound(screen->logicalDotsPerInchX());
850 } else if (m == PdmDpiY) {
851 if (d->extra && d->extra->customDpiY)
852 return d->extra->customDpiY;
854 return static_cast<QWidget *>(d->parent)->metric(m);
855 return qRound(screen->logicalDotsPerInchY());
856 } else if (m == PdmPhysicalDpiX) {
857 return qRound(screen->physicalDotsPerInchX());
858 } else if (m == PdmPhysicalDpiY) {
859 return qRound(screen->physicalDotsPerInchY());
861 val = QPaintDevice::metric(m);// XXX
869 Returns the QPlatformWindow this widget will be drawn into.
871 QWindow *QWidget::windowHandle() const
874 QTLWExtra *extra = d->maybeTopData();
876 return extra->window;
881 void QWidgetPrivate::createSysExtra()
885 void QWidgetPrivate::deleteSysExtra()
890 void QWidgetPrivate::createTLSysExtra()
893 extra->topextra->screenIndex = 0;
894 extra->topextra->window = 0;
895 if (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow())
896 extra->topextra->window = new QWidgetWindow(q);
899 void QWidgetPrivate::deleteTLSysExtra()
901 if (extra && extra->topextra) {
902 //the toplevel might have a context with a "qglcontext associated with it. We need to
903 //delete the qglcontext before we delete the qplatformopenglcontext.
904 //One unfortunate thing about this is that we potentially create a glContext just to
905 //delete it straight afterwards.
906 if (extra->topextra->window) {
907 extra->topextra->window->destroy();
910 //hmmm. should we delete window..
911 delete extra->topextra->window;
912 extra->topextra->window = 0;
916 void QWidgetPrivate::registerDropSite(bool on)
921 void QWidgetPrivate::setMask_sys(const QRegion ®ion)
927 void QWidgetPrivate::updateFrameStrut()
930 if (q->data->fstrut_dirty) {
931 if (QTLWExtra *te = maybeTopData()) {
933 if (const QPlatformWindow *pw = te->window->handle()) {
934 const QMargins margins = pw->frameMargins();
935 if (!margins.isNull()) {
936 te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
937 q->data->fstrut_dirty = false;
945 void QWidgetPrivate::setWindowOpacity_sys(qreal level)
948 if (q->windowHandle())
949 q->windowHandle()->setOpacity(level);
952 void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
959 QPaintEngine *QWidget::paintEngine() const
961 qWarning("QWidget::paintEngine: Should no longer be called");
962 return 0; //##### @@@
965 void QWidgetPrivate::setModal_sys()
968 if (q->windowHandle())
969 q->windowHandle()->setWindowModality(q->windowModality());
973 static inline void applyCursor(QWidget *w, QCursor c)
975 if (QWindow *window = w->windowHandle())
976 if (const QScreen *screen = window->screen())
977 if (QPlatformCursor *cursor = screen->handle()->cursor())
978 cursor->changeCursor(&c, window);
981 void qt_qpa_set_cursor(QWidget *w, bool force)
983 if (!w->testAttribute(Qt::WA_WState_Created))
986 static QPointer<QWidget> lastUnderMouse = 0;
989 } else if (lastUnderMouse && lastUnderMouse->effectiveWinId() == w->effectiveWinId()) {
991 } else if (!w->internalWinId()) {
992 return; // The mouse is not under this widget, and it's not native, so don't change it.
995 while (!w->internalWinId() && w->parentWidget() && !w->isWindow()
996 && !w->testAttribute(Qt::WA_SetCursor))
997 w = w->parentWidget();
999 QWidget *nativeParent = w;
1000 if (!w->internalWinId())
1001 nativeParent = w->nativeParentWidget();
1002 if (!nativeParent || !nativeParent->internalWinId())
1005 if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {
1006 QCursor *oc = QApplication::overrideCursor();
1008 applyCursor(nativeParent, *oc);
1009 else if (w->isEnabled())
1010 applyCursor(nativeParent, w->cursor());
1012 // Enforce the windows behavior of clearing the cursor on
1013 // disabled widgets.
1014 applyCursor(nativeParent, Qt::ArrowCursor);
1016 applyCursor(nativeParent, Qt::ArrowCursor);
1019 #endif //QT_NO_CURSOR