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 "qplatformwindow.h"
43 #include "qplatformwindow_p.h"
45 #include <qpa/qwindowsysteminterface.h>
46 #include <QtGui/qwindow.h>
47 #include <QtGui/qscreen.h>
52 Constructs a platform window with the given top level window.
55 QPlatformWindow::QPlatformWindow(QWindow *window)
56 : QPlatformSurface(window)
57 , d_ptr(new QPlatformWindowPrivate)
60 d->rect = window->geometry();
64 Virtual destructor does not delete its top level window.
66 QPlatformWindow::~QPlatformWindow()
71 Returns the window which belongs to the QPlatformWindow
73 QWindow *QPlatformWindow::window() const
75 return static_cast<QWindow *>(m_surface);
79 Returns the parent platform window (or 0 if orphan).
81 QPlatformWindow *QPlatformWindow::parent() const
83 return window()->parent() ? window()->parent()->handle() : 0;
87 Returns the platform screen handle corresponding to this platform window.
89 QPlatformScreen *QPlatformWindow::screen() const
91 return window()->screen()->handle();
95 Returns the actual surface format of the window.
97 QSurfaceFormat QPlatformWindow::format() const
99 return QSurfaceFormat();
103 This function is called by Qt whenever a window is moved or the window is resized. The resize
104 can happen programatically(from ie. user application) or by the window manager. This means that
105 there is no need to call this function specifically from the window manager callback, instead
106 call QWindowSystemInterface::handleGeometryChange(QWindow *w, const QRect &newRect);
108 The position(x, y) part of the rect might be inclusive or exclusive of the window frame
109 as returned by frameMargins(). You can detect this in the plugin by checking
110 qt_window_private(window())->positionPolicy.
112 void QPlatformWindow::setGeometry(const QRect &rect)
114 Q_D(QPlatformWindow);
119 Returnes the current geometry of a window
121 QRect QPlatformWindow::geometry() const
123 Q_D(const QPlatformWindow);
127 QMargins QPlatformWindow::frameMargins() const
133 Reimplemented in subclasses to show the surface
134 if \a visible is \c true, and hide it if \a visible is \c false.
136 The default implementation sends a synchronous expose event.
138 void QPlatformWindow::setVisible(bool visible)
141 QRect rect(QPoint(), geometry().size());
142 QWindowSystemInterface::handleSynchronousExposeEvent(window(), rect);
145 Requests setting the window flags of this surface
146 to \a type. Returns the actual flags set.
148 Qt::WindowFlags QPlatformWindow::setWindowFlags(Qt::WindowFlags flags)
156 Returns if this window is exposed in the windowing system.
158 An exposeEvent() is sent every time this value changes.
161 bool QPlatformWindow::isExposed() const
163 return window()->isVisible();
167 Returns true if the window should appear active from a style perspective.
169 This function can make platform-specific isActive checks, such as checking
170 if the QWindow is embedded in an active native window.
172 bool QPlatformWindow::isActive() const
178 Requests setting the window state of this surface
179 to \a type. Returns the actual state set.
181 Qt::WindowActive can be ignored.
183 Qt::WindowState QPlatformWindow::setWindowState(Qt::WindowState)
185 return Qt::WindowNoState;
189 Reimplement in subclasses to return a handle to the native window
191 WId QPlatformWindow::winId() const
193 // Return anything but 0. Returning 0 would cause havoc with QWidgets on
194 // very basic platform plugins that do not reimplement this function,
195 // because the top-level widget's internalWinId() would always be 0 which
196 // would mean top-levels are never treated as native.
201 This function is called to enable native child window in QPA. It is common not to support this
202 feature in Window systems, but can be faked. When this function is called all geometry of this
203 platform window will be relative to the parent.
205 //jl: It would be useful to have a property on the platform window which indicated if the sub-class
206 // supported the setParent. If not, then geometry would be in screen coordinates.
207 void QPlatformWindow::setParent(const QPlatformWindow *parent)
210 qWarning("This plugin does not support setParent!");
214 Reimplement to set the window title to \a title
216 void QPlatformWindow::setWindowTitle(const QString &title) { Q_UNUSED(title); }
219 Reimplement to set the window icon to \a icon
221 void QPlatformWindow::setWindowIcon(const QIcon &icon) { Q_UNUSED(icon); }
224 Reimplement to be able to let Qt raise windows to the top of the desktop
226 void QPlatformWindow::raise() { qWarning("This plugin does not support raise()"); }
229 Reimplement to be able to let Qt lower windows to the bottom of the desktop
231 void QPlatformWindow::lower() { qWarning("This plugin does not support lower()"); }
234 Reimplement to propagate the size hints of the QWindow.
236 The size hints include QWindow::minimumSize(), QWindow::maximumSize(),
237 QWindow::sizeIncrement(), and QWindow::baseSize().
239 void QPlatformWindow::propagateSizeHints() {qWarning("This plugin does not support propagateSizeHints()"); }
242 Reimplement to be able to let Qt set the opacity level of a window
244 void QPlatformWindow::setOpacity(qreal level)
247 qWarning("This plugin does not support setting window opacity");
251 Reimplement to be able to let Qt set the mask of a window
254 void QPlatformWindow::setMask(const QRegion ®ion)
257 qWarning("This plugin does not support setting window masks");
261 Reimplement to let Qt be able to request activation/focus for a window
263 Some window systems will probably not have callbacks for this functionality,
264 and then calling QWindowSystemInterface::handleWindowActivated(QWindow *w)
267 If the window system has some event handling/callbacks then call
268 QWindowSystemInterface::handleWindowActivated(QWindow *w) when the window system
269 gives the notification.
271 Default implementation calls QWindowSystem::handleWindowActivated(QWindow *w)
273 void QPlatformWindow::requestActivateWindow()
275 QWindowSystemInterface::handleWindowActivated(window());
279 Handle changes to the orientation of the platform window's contents.
281 This is a hint to the window manager in case it needs to display
282 additional content like popups, dialogs, status bars, or similar
283 in relation to the window.
285 \sa QWindow::reportContentOrientationChange()
287 void QPlatformWindow::handleContentOrientationChange(Qt::ScreenOrientation orientation)
289 Q_UNUSED(orientation);
293 Request a different orientation of the platform window.
295 This tells the window manager how the window wants to be rotated in order
296 to be displayed, and how input events should be translated.
298 As an example, a portrait compositor might rotate the window by 90 degrees,
299 if the window is in landscape. It will also rotate input coordinates from
300 portrait to landscape such that top right in portrait gets mapped to top
303 If the implementation doesn't support the requested orientation it should
304 signal this by returning an actual supported orientation.
306 If the implementation doesn't support rotating the window at all it should
307 return Qt::PrimaryOrientation, this is also the default value.
309 \sa QWindow::requestWindowOrientation()
311 Qt::ScreenOrientation QPlatformWindow::requestWindowOrientation(Qt::ScreenOrientation orientation)
313 Q_UNUSED(orientation);
314 return Qt::PrimaryOrientation;
317 bool QPlatformWindow::setKeyboardGrabEnabled(bool grab)
320 qWarning("This plugin does not support grabbing the keyboard");
324 bool QPlatformWindow::setMouseGrabEnabled(bool grab)
327 qWarning("This plugin does not support grabbing the mouse");
332 Reimplement to be able to let Qt indicate that the window has been
333 modified. Return true if the native window supports setting the modified
334 flag, false otherwise.
336 bool QPlatformWindow::setWindowModified(bool modified)
343 Reimplement this method to be able to do any platform specific event
344 handling. All events for window() are passed to this function before being
345 sent to QWindow::event().
347 The default implementation is empty and does nothing with \a event.
349 void QPlatformWindow::windowEvent(QEvent *event)
355 Reimplement this method to start a system size grip drag
356 operation if the system supports it and return true to indicate
358 It is called from the mouse press event handler of the size grip.
360 The default implementation is empty and does nothing with \a pos
364 bool QPlatformWindow::startSystemResize(const QPoint &pos, Qt::Corner corner)
372 Reimplement this method to set whether frame strut events
373 should be sent to \a enabled.
375 \sa frameStrutEventsEnabled
378 void QPlatformWindow::setFrameStrutEventsEnabled(bool enabled)
381 qWarning("This plugin does not support frame strut events.");
385 Reimplement this method to return whether
386 frame strut events are enabled.
389 bool QPlatformWindow::frameStrutEventsEnabled() const
395 \class QPlatformWindow
401 \brief The QPlatformWindow class provides an abstraction for top-level windows.
403 The QPlatformWindow abstraction is used by QWindow for all its top level windows. It is being
404 created by calling the createPlatformWindow function in the loaded QPlatformIntegration
407 QPlatformWindow is used to signal to the windowing system, how Qt perceives its frame.
408 However, it is not concerned with how Qt renders into the window it represents.
410 Visible QWindows will always have a QPlatformWindow. However, it is not necessary for
411 all windows to have a QBackingStore. This is the case for QOpenGLWidget. And could be the case for
412 windows where some 3.party renders into it.
414 The platform specific window handle can be retrieved by the winId function.
416 QPlatformWindow is also the way QPA defines how native child windows should be supported
417 through the setParent function.
419 The only way to retrieve a QPlatformOpenGLContext in QPA is by calling the glContext() function
422 \sa QBackingStore, QWindow