QPlatformWindow: Add Window masks.
[profile/ivi/qtbase.git] / src / gui / kernel / qplatformwindow_qpa.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qplatformwindow.h"
43
44 #include <QtGui/qwindowsysteminterface_qpa.h>
45 #include <QtGui/qwindow.h>
46 #include <QtGui/qscreen.h>
47
48 QT_BEGIN_NAMESPACE
49
50 class QPlatformWindowPrivate
51 {
52     QRect rect;
53     friend class QPlatformWindow;
54 };
55
56 /*!
57     Constructs a platform window with the given top level window.
58 */
59
60 QPlatformWindow::QPlatformWindow(QWindow *window)
61     : QPlatformSurface(window)
62     , d_ptr(new QPlatformWindowPrivate)
63 {
64     Q_D(QPlatformWindow);
65     d->rect = window->geometry();
66 }
67
68 /*!
69     Virtual destructor does not delete its top level window.
70 */
71 QPlatformWindow::~QPlatformWindow()
72 {
73 }
74
75 /*!
76     Returns the window which belongs to the QPlatformWindow
77 */
78 QWindow *QPlatformWindow::window() const
79 {
80     return static_cast<QWindow *>(m_surface);
81 }
82
83 /*!
84     Returns the parent platform window (or 0 if orphan).
85 */
86 QPlatformWindow *QPlatformWindow::parent() const
87 {
88     return window()->parent() ? window()->parent()->handle() : 0;
89 }
90
91 /*!
92     Returns the platform screen handle corresponding to this platform window.
93 */
94 QPlatformScreen *QPlatformWindow::screen() const
95 {
96     return window()->screen()->handle();
97 }
98
99 /*!
100     Returns the actual surface format of the window.
101 */
102 QSurfaceFormat QPlatformWindow::format() const
103 {
104     return QSurfaceFormat();
105 }
106
107 /*!
108     This function is called by Qt whenever a window is moved or the window is resized. The resize
109     can happen programatically(from ie. user application) or by the window manager. This means that
110     there is no need to call this function specifically from the window manager callback, instead
111     call QWindowSystemInterface::handleGeometryChange(QWindow *w, const QRect &newRect);
112
113     The position(x, y) part of the rect might be inclusive or exclusive of the window frame
114     as returned by frameMargins(). You can detect this in the plugin by checking
115     qt_window_private(window())->positionPolicy.
116 */
117 void QPlatformWindow::setGeometry(const QRect &rect)
118 {
119     Q_D(QPlatformWindow);
120     d->rect = rect;
121 }
122
123 /*!
124     Returnes the current geometry of a window
125 */
126 QRect QPlatformWindow::geometry() const
127 {
128     Q_D(const QPlatformWindow);
129     return d->rect;
130 }
131
132 QMargins QPlatformWindow::frameMargins() const
133 {
134     return QMargins();
135 }
136
137 /*!
138     Reimplemented in subclasses to show the surface
139     if \a visible is \c true, and hide it if \a visible is \c false.
140
141     The default implementation sends a synchronous expose event.
142 */
143 void QPlatformWindow::setVisible(bool visible)
144 {
145     Q_UNUSED(visible);
146     QRect rect(QPoint(), geometry().size());
147     QWindowSystemInterface::handleSynchronousExposeEvent(window(), rect);
148 }
149 /*!
150     Requests setting the window flags of this surface
151     to \a type. Returns the actual flags set.
152 */
153 Qt::WindowFlags QPlatformWindow::setWindowFlags(Qt::WindowFlags flags)
154 {
155     return flags;
156 }
157
158
159
160 /*!
161     Returns if this window is exposed in the windowing system.
162
163     An exposeEvent() is sent every time this value changes.
164  */
165
166 bool QPlatformWindow::isExposed() const
167 {
168     return window()->isVisible();
169 }
170
171 /*!
172     Requests setting the window state of this surface
173     to \a type. Returns the actual state set.
174
175     Qt::WindowActive can be ignored.
176 */
177 Qt::WindowState QPlatformWindow::setWindowState(Qt::WindowState)
178 {
179     return Qt::WindowNoState;
180 }
181
182 /*!
183   Reimplement in subclasses to return a handle to the native window
184 */
185 WId QPlatformWindow::winId() const
186 {
187     // Return anything but 0. Returning 0 would cause havoc with QWidgets on
188     // very basic platform plugins that do not reimplement this function,
189     // because the top-level widget's internalWinId() would always be 0 which
190     // would mean top-levels are never treated as native.
191     return WId(1);
192 }
193
194 /*!
195     This function is called to enable native child window in QPA. It is common not to support this
196     feature in Window systems, but can be faked. When this function is called all geometry of this
197     platform window will be relative to the parent.
198 */
199 //jl: It would be useful to have a property on the platform window which indicated if the sub-class
200 // supported the setParent. If not, then geometry would be in screen coordinates.
201 void QPlatformWindow::setParent(const QPlatformWindow *parent)
202 {
203     Q_UNUSED(parent);
204     qWarning("This plugin does not support setParent!");
205 }
206
207 /*!
208   Reimplement to set the window title to \a title
209 */
210 void QPlatformWindow::setWindowTitle(const QString &title) { Q_UNUSED(title); }
211
212 /*!
213   Reimplement to set the window icon to \a icon
214 */
215 void QPlatformWindow::setWindowIcon(const QIcon &icon) { Q_UNUSED(icon); }
216
217 /*!
218   Reimplement to be able to let Qt raise windows to the top of the desktop
219 */
220 void QPlatformWindow::raise() { qWarning("This plugin does not support raise()"); }
221
222 /*!
223   Reimplement to be able to let Qt lower windows to the bottom of the desktop
224 */
225 void QPlatformWindow::lower() { qWarning("This plugin does not support lower()"); }
226
227 /*!
228   Reimplement to propagate the size hints of the QWindow.
229
230   The size hints include QWindow::minimumSize(), QWindow::maximumSize(),
231   QWindow::sizeIncrement(), and QWindow::baseSize().
232 */
233 void QPlatformWindow::propagateSizeHints() {qWarning("This plugin does not support propagateSizeHints()"); }
234
235 /*!
236   Reimplement to be able to let Qt set the opacity level of a window
237 */
238 void QPlatformWindow::setOpacity(qreal level)
239 {
240     Q_UNUSED(level);
241     qWarning("This plugin does not support setting window opacity");
242 }
243
244 /*!
245   Reimplement to  be able to let Qt set the mask of a window
246 */
247
248 void QPlatformWindow::setMask(const QRegion &region)
249 {
250     Q_UNUSED(region);
251     qWarning("This plugin does not support setting window masks");
252 }
253
254 /*!
255   Reimplement to let Qt be able to request activation/focus for a window
256
257   Some window systems will probably not have callbacks for this functionality,
258   and then calling QWindowSystemInterface::handleWindowActivated(QWindow *w)
259   would be sufficient.
260
261   If the window system has some event handling/callbacks then call
262   QWindowSystemInterface::handleWindowActivated(QWindow *w) when the window system
263   gives the notification.
264
265   Default implementation calls QWindowSystem::handleWindowActivated(QWindow *w)
266 */
267 void QPlatformWindow::requestActivateWindow()
268 {
269     QWindowSystemInterface::handleWindowActivated(window());
270 }
271
272 /*!
273   Handle changes to the orientation of the platform window's contents.
274
275   This is a hint to the window manager in case it needs to display
276   additional content like popups, dialogs, status bars, or similar
277   in relation to the window.
278
279   \sa QWindow::reportContentOrientationChange()
280 */
281 void QPlatformWindow::handleContentOrientationChange(Qt::ScreenOrientation orientation)
282 {
283     Q_UNUSED(orientation);
284 }
285
286 /*!
287   Request a different orientation of the platform window.
288
289   This tells the window manager how the window wants to be rotated in order
290   to be displayed, and how input events should be translated.
291
292   As an example, a portrait compositor might rotate the window by 90 degrees,
293   if the window is in landscape. It will also rotate input coordinates from
294   portrait to landscape such that top right in portrait gets mapped to top
295   left in landscape.
296
297   If the implementation doesn't support the requested orientation it should
298   signal this by returning an actual supported orientation.
299
300   If the implementation doesn't support rotating the window at all it should
301   return Qt::PrimaryOrientation, this is also the default value.
302
303   \sa QWindow::requestWindowOrientation()
304 */
305 Qt::ScreenOrientation QPlatformWindow::requestWindowOrientation(Qt::ScreenOrientation orientation)
306 {
307     Q_UNUSED(orientation);
308     return Qt::PrimaryOrientation;
309 }
310
311 bool QPlatformWindow::setKeyboardGrabEnabled(bool grab)
312 {
313     Q_UNUSED(grab);
314     qWarning("This plugin does not support grabbing the keyboard");
315     return false;
316 }
317
318 bool QPlatformWindow::setMouseGrabEnabled(bool grab)
319 {
320     Q_UNUSED(grab);
321     qWarning("This plugin does not support grabbing the mouse");
322     return false;
323 }
324
325 /*!
326     Reimplement to be able to let Qt indicate that the window has been
327     modified. Return true if the native window supports setting the modified
328     flag, false otherwise.
329 */
330 bool QPlatformWindow::setWindowModified(bool modified)
331 {
332     Q_UNUSED(modified);
333     return false;
334 }
335
336 /*!
337     Reimplement this method to be able to do any platform specific event
338     handling. All events for window() are passed to this function before being
339     sent to QWindow::event().
340
341     The default implementation is empty and does nothing with \a event.
342 */
343 void QPlatformWindow::windowEvent(QEvent *event)
344 {
345     Q_UNUSED(event);
346 }
347
348 /*!
349     Reimplement this method to start a system size grip drag
350     operation if the system supports it and return true to indicate
351     success.
352     It is called from the mouse press event handler of the size grip.
353
354     The default implementation is empty and does nothing with \a pos
355     and \a corner.
356 */
357
358 bool QPlatformWindow::startSystemResize(const QPoint &pos, Qt::Corner corner)
359 {
360     Q_UNUSED(pos)
361     Q_UNUSED(corner)
362     return false;
363 }
364
365 /*!
366     \class QPlatformWindow
367     \since 4.8
368     \internal
369     \preliminary
370     \ingroup qpa
371
372     \brief The QPlatformWindow class provides an abstraction for top-level windows.
373
374     The QPlatformWindow abstraction is used by QWindow for all its top level windows. It is being
375     created by calling the createPlatformWindow function in the loaded QPlatformIntegration
376     instance.
377
378     QPlatformWindow is used to signal to the windowing system, how Qt perceives its frame.
379     However, it is not concerned with how Qt renders into the window it represents.
380
381     Visible QWindows will always have a QPlatformWindow. However, it is not necessary for
382     all windows to have a QBackingStore. This is the case for QOpenGLWidget. And could be the case for
383     windows where some  3.party renders into it.
384
385     The platform specific window handle can be retrieved by the winId function.
386
387     QPlatformWindow is also the way QPA defines how native child windows should be supported
388     through the setParent function.
389
390     The only way to retrieve a QPlatformOpenGLContext in QPA is by calling the glContext() function
391     on QPlatformWindow.
392
393     \sa QBackingStore, QWindow
394 */
395
396 QT_END_NAMESPACE