kernel/qplatformwindow.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qplatformwindow.h" -
43#include "qplatformwindow_p.h" -
44 -
45#include <qpa/qwindowsysteminterface.h> -
46#include <QtGui/qwindow.h> -
47#include <QtGui/qscreen.h> -
48 -
49QT_BEGIN_NAMESPACE -
50 -
51/*! -
52 Constructs a platform window with the given top level window. -
53*/ -
54 -
55QPlatformWindow::QPlatformWindow(QWindow *window) -
56 : QPlatformSurface(window) -
57 , d_ptr(new QPlatformWindowPrivate) -
58{ -
59 Q_D(QPlatformWindow);
executed (the execution status of this line is deduced): QPlatformWindowPrivate * const d = d_func();
-
60 d->rect = window->geometry();
executed (the execution status of this line is deduced): d->rect = window->geometry();
-
61}
executed: }
Execution Count:1649
1649
62 -
63/*! -
64 Virtual destructor does not delete its top level window. -
65*/ -
66QPlatformWindow::~QPlatformWindow() -
67{ -
68} -
69 -
70/*! -
71 Returns the window which belongs to the QPlatformWindow -
72*/ -
73QWindow *QPlatformWindow::window() const -
74{ -
75 return static_cast<QWindow *>(m_surface);
executed: return static_cast<QWindow *>(m_surface);
Execution Count:97297
97297
76} -
77 -
78/*! -
79 Returns the parent platform window (or 0 if orphan). -
80*/ -
81QPlatformWindow *QPlatformWindow::parent() const -
82{ -
83 return window()->parent() ? window()->parent()->handle() : 0;
executed: return window()->parent() ? window()->parent()->handle() : 0;
Execution Count:2589
2589
84} -
85 -
86/*! -
87 Returns the platform screen handle corresponding to this platform window. -
88*/ -
89QPlatformScreen *QPlatformWindow::screen() const -
90{ -
91 return window()->screen()->handle();
executed: return window()->screen()->handle();
Execution Count:214
214
92} -
93 -
94/*! -
95 Returns the actual surface format of the window. -
96*/ -
97QSurfaceFormat QPlatformWindow::format() const -
98{ -
99 return QSurfaceFormat();
never executed: return QSurfaceFormat();
0
100} -
101 -
102/*! -
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); -
107 -
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. -
111*/ -
112void QPlatformWindow::setGeometry(const QRect &rect) -
113{ -
114 Q_D(QPlatformWindow);
executed (the execution status of this line is deduced): QPlatformWindowPrivate * const d = d_func();
-
115 d->rect = rect;
executed (the execution status of this line is deduced): d->rect = rect;
-
116}
executed: }
Execution Count:4092
4092
117 -
118/*! -
119 Returnes the current geometry of a window -
120*/ -
121QRect QPlatformWindow::geometry() const -
122{ -
123 Q_D(const QPlatformWindow);
executed (the execution status of this line is deduced): const QPlatformWindowPrivate * const d = d_func();
-
124 return d->rect;
executed: return d->rect;
Execution Count:41059
41059
125} -
126 -
127QMargins QPlatformWindow::frameMargins() const -
128{ -
129 return QMargins();
never executed: return QMargins();
0
130} -
131 -
132/*! -
133 Reimplemented in subclasses to show the surface -
134 if \a visible is \c true, and hide it if \a visible is \c false. -
135 -
136 The default implementation sends a synchronous expose event. -
137*/ -
138void QPlatformWindow::setVisible(bool visible) -
139{ -
140 Q_UNUSED(visible);
never executed (the execution status of this line is deduced): (void)visible;;
-
141 QRect rect(QPoint(), geometry().size());
never executed (the execution status of this line is deduced): QRect rect(QPoint(), geometry().size());
-
142 QWindowSystemInterface::handleExposeEvent(window(), rect);
never executed (the execution status of this line is deduced): QWindowSystemInterface::handleExposeEvent(window(), rect);
-
143 QWindowSystemInterface::flushWindowSystemEvents();
never executed (the execution status of this line is deduced): QWindowSystemInterface::flushWindowSystemEvents();
-
144}
never executed: }
0
145 -
146/*! -
147 Requests setting the window flags of this surface -
148 to \a flags. -
149*/ -
150void QPlatformWindow::setWindowFlags(Qt::WindowFlags flags) -
151{ -
152 Q_UNUSED(flags);
never executed (the execution status of this line is deduced): (void)flags;;
-
153}
never executed: }
0
154 -
155/*! -
156 Returns if this window is exposed in the windowing system. -
157 -
158 An exposeEvent() is sent every time this value changes. -
159 */ -
160 -
161bool QPlatformWindow::isExposed() const -
162{ -
163 return window()->isVisible();
never executed: return window()->isVisible();
0
164} -
165 -
166/*! -
167 Returns true if the window should appear active from a style perspective. -
168 -
169 This function can make platform-specific isActive checks, such as checking -
170 if the QWindow is embedded in an active native window. -
171*/ -
172bool QPlatformWindow::isActive() const -
173{ -
174 return false;
executed: return false;
Execution Count:138743
138743
175} -
176 -
177/*! -
178 Returns true if the window is a descendant of an embedded non-Qt window. -
179 Example of an embedded non-Qt window is the parent window of an in-process QAxServer. -
180 -
181 If \a parentWindow is nonzero, only check if the window is embedded in the -
182 specified \a parentWindow. -
183*/ -
184bool QPlatformWindow::isEmbedded(const QPlatformWindow *parentWindow) const -
185{ -
186 Q_UNUSED(parentWindow);
executed (the execution status of this line is deduced): (void)parentWindow;;
-
187 return false;
executed: return false;
Execution Count:19144
19144
188} -
189 -
190/*! -
191 Translates the window coordinate \a pos to global screen -
192 coordinates using native methods. This is required for embedded windows, -
193 where the topmost QWindow coordinates are not global screen coordinates. -
194 -
195 Returns \a pos if there is no platform specific implementation. -
196*/ -
197QPoint QPlatformWindow::mapToGlobal(const QPoint &pos) const -
198{ -
199 return pos;
never executed: return pos;
0
200} -
201 -
202/*! -
203 Translates the global screen coordinate \a pos to window -
204 coordinates using native methods. This is required for embedded windows, -
205 where the topmost QWindow coordinates are not global screen coordinates. -
206 -
207 Returns \a pos if there is no platform specific implementation. -
208*/ -
209QPoint QPlatformWindow::mapFromGlobal(const QPoint &pos) const -
210{ -
211 return pos;
never executed: return pos;
0
212} -
213 -
214/*! -
215 Requests setting the window state of this surface -
216 to \a type. -
217 -
218 Qt::WindowActive can be ignored. -
219*/ -
220void QPlatformWindow::setWindowState(Qt::WindowState) -
221{ -
222} -
223 -
224/*! -
225 Reimplement in subclasses to return a handle to the native window -
226*/ -
227WId QPlatformWindow::winId() const -
228{ -
229 // Return anything but 0. Returning 0 would cause havoc with QWidgets on -
230 // very basic platform plugins that do not reimplement this function, -
231 // because the top-level widget's internalWinId() would always be 0 which -
232 // would mean top-levels are never treated as native. -
233 return WId(1);
never executed: return WId(1);
0
234} -
235 -
236/*! -
237 This function is called to enable native child window in QPA. It is common not to support this -
238 feature in Window systems, but can be faked. When this function is called all geometry of this -
239 platform window will be relative to the parent. -
240*/ -
241//jl: It would be useful to have a property on the platform window which indicated if the sub-class -
242// supported the setParent. If not, then geometry would be in screen coordinates. -
243void QPlatformWindow::setParent(const QPlatformWindow *parent) -
244{ -
245 Q_UNUSED(parent);
never executed (the execution status of this line is deduced): (void)parent;;
-
246 qWarning("This plugin does not support setParent!");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qplatformwindow.cpp", 246, __PRETTY_FUNCTION__).warning("This plugin does not support setParent!");
-
247}
never executed: }
0
248 -
249/*! -
250 Reimplement to set the window title to \a title. -
251 -
252 The implementation might want to append the application display name to -
253 the window title, like Windows and Linux do. -
254 -
255 \sa QGuiApplication::applicationDisplayName() -
256*/ -
257void QPlatformWindow::setWindowTitle(const QString &title) { Q_UNUSED(title); }
never executed: }
0
258 -
259/*! -
260 Reimplement to set the window file path to \a filePath -
261*/ -
262void QPlatformWindow::setWindowFilePath(const QString &filePath) { Q_UNUSED(filePath); }
never executed: }
0
263 -
264/*! -
265 Reimplement to set the window icon to \a icon -
266*/ -
267void QPlatformWindow::setWindowIcon(const QIcon &icon) { Q_UNUSED(icon); }
never executed: }
0
268 -
269/*! -
270 Reimplement to be able to let Qt raise windows to the top of the desktop -
271*/ -
272void QPlatformWindow::raise() { qWarning("This plugin does not support raise()"); }
never executed: }
0
273 -
274/*! -
275 Reimplement to be able to let Qt lower windows to the bottom of the desktop -
276*/ -
277void QPlatformWindow::lower() { qWarning("This plugin does not support lower()"); }
never executed: }
0
278 -
279/*! -
280 Reimplement to propagate the size hints of the QWindow. -
281 -
282 The size hints include QWindow::minimumSize(), QWindow::maximumSize(), -
283 QWindow::sizeIncrement(), and QWindow::baseSize(). -
284*/ -
285void QPlatformWindow::propagateSizeHints() {qWarning("This plugin does not support propagateSizeHints()"); }
never executed: }
0
286 -
287/*! -
288 Reimplement to be able to let Qt set the opacity level of a window -
289*/ -
290void QPlatformWindow::setOpacity(qreal level) -
291{ -
292 Q_UNUSED(level);
never executed (the execution status of this line is deduced): (void)level;;
-
293 qWarning("This plugin does not support setting window opacity");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qplatformwindow.cpp", 293, __PRETTY_FUNCTION__).warning("This plugin does not support setting window opacity");
-
294}
never executed: }
0
295 -
296/*! -
297 Reimplement to be able to let Qt set the mask of a window -
298*/ -
299 -
300void QPlatformWindow::setMask(const QRegion &region) -
301{ -
302 Q_UNUSED(region);
never executed (the execution status of this line is deduced): (void)region;;
-
303 qWarning("This plugin does not support setting window masks");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qplatformwindow.cpp", 303, __PRETTY_FUNCTION__).warning("This plugin does not support setting window masks");
-
304}
never executed: }
0
305 -
306/*! -
307 Reimplement to let Qt be able to request activation/focus for a window -
308 -
309 Some window systems will probably not have callbacks for this functionality, -
310 and then calling QWindowSystemInterface::handleWindowActivated(QWindow *w) -
311 would be sufficient. -
312 -
313 If the window system has some event handling/callbacks then call -
314 QWindowSystemInterface::handleWindowActivated(QWindow *w) when the window system -
315 gives the notification. -
316 -
317 Default implementation calls QWindowSystem::handleWindowActivated(QWindow *w) -
318*/ -
319void QPlatformWindow::requestActivateWindow() -
320{ -
321 QWindowSystemInterface::handleWindowActivated(window());
never executed (the execution status of this line is deduced): QWindowSystemInterface::handleWindowActivated(window());
-
322}
never executed: }
0
323 -
324/*! -
325 Handle changes to the orientation of the platform window's contents. -
326 -
327 This is a hint to the window manager in case it needs to display -
328 additional content like popups, dialogs, status bars, or similar -
329 in relation to the window. -
330 -
331 \sa QWindow::reportContentOrientationChange() -
332*/ -
333void QPlatformWindow::handleContentOrientationChange(Qt::ScreenOrientation orientation) -
334{ -
335 Q_UNUSED(orientation);
executed (the execution status of this line is deduced): (void)orientation;;
-
336}
executed: }
Execution Count:3
3
337 -
338/*! -
339 Reimplement this function in subclass to return the device pixel ratio -
340 for the window. This is the ratio between physical pixels -
341 and device-independent pixels. -
342 -
343 \sa QPlatformWindow::devicePixelRatio(); -
344*/ -
345qreal QPlatformWindow::devicePixelRatio() const -
346{ -
347 return 1.0;
never executed: return 1.0;
0
348} -
349 -
350bool QPlatformWindow::setKeyboardGrabEnabled(bool grab) -
351{ -
352 Q_UNUSED(grab);
never executed (the execution status of this line is deduced): (void)grab;;
-
353 qWarning("This plugin does not support grabbing the keyboard");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qplatformwindow.cpp", 353, __PRETTY_FUNCTION__).warning("This plugin does not support grabbing the keyboard");
-
354 return false;
never executed: return false;
0
355} -
356 -
357bool QPlatformWindow::setMouseGrabEnabled(bool grab) -
358{ -
359 Q_UNUSED(grab);
never executed (the execution status of this line is deduced): (void)grab;;
-
360 qWarning("This plugin does not support grabbing the mouse");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qplatformwindow.cpp", 360, __PRETTY_FUNCTION__).warning("This plugin does not support grabbing the mouse");
-
361 return false;
never executed: return false;
0
362} -
363 -
364/*! -
365 Reimplement to be able to let Qt indicate that the window has been -
366 modified. Return true if the native window supports setting the modified -
367 flag, false otherwise. -
368*/ -
369bool QPlatformWindow::setWindowModified(bool modified) -
370{ -
371 Q_UNUSED(modified);
executed (the execution status of this line is deduced): (void)modified;;
-
372 return false;
executed: return false;
Execution Count:1776
1776
373} -
374 -
375/*! -
376 Reimplement this method to be able to do any platform specific event -
377 handling. All events for window() are passed to this function before being -
378 sent to QWindow::event(). -
379 -
380 The default implementation is empty and does nothing with \a event. -
381*/ -
382void QPlatformWindow::windowEvent(QEvent *event) -
383{ -
384 Q_UNUSED(event);
executed (the execution status of this line is deduced): (void)event;;
-
385}
executed: }
Execution Count:5605
5605
386 -
387/*! -
388 Reimplement this method to start a system size grip drag -
389 operation if the system supports it and return true to indicate -
390 success. -
391 It is called from the mouse press event handler of the size grip. -
392 -
393 The default implementation is empty and does nothing with \a pos -
394 and \a corner. -
395*/ -
396 -
397bool QPlatformWindow::startSystemResize(const QPoint &pos, Qt::Corner corner) -
398{ -
399 Q_UNUSED(pos)
never executed (the execution status of this line is deduced): (void)pos;
-
400 Q_UNUSED(corner)
never executed (the execution status of this line is deduced): (void)corner;
-
401 return false;
never executed: return false;
0
402} -
403 -
404/*! -
405 Reimplement this method to set whether frame strut events -
406 should be sent to \a enabled. -
407 -
408 \sa frameStrutEventsEnabled -
409*/ -
410 -
411void QPlatformWindow::setFrameStrutEventsEnabled(bool enabled) -
412{ -
413 if (enabled)
never evaluated: enabled
0
414 qWarning("This plugin does not support frame strut events.");
never executed: QMessageLogger("kernel/qplatformwindow.cpp", 414, __PRETTY_FUNCTION__).warning("This plugin does not support frame strut events.");
0
415}
never executed: }
0
416 -
417/*! -
418 Reimplement this method to return whether -
419 frame strut events are enabled. -
420*/ -
421 -
422bool QPlatformWindow::frameStrutEventsEnabled() const -
423{ -
424 return false;
never executed: return false;
0
425} -
426 -
427/*! -
428 \class QPlatformWindow -
429 \since 4.8 -
430 \internal -
431 \preliminary -
432 \ingroup qpa -
433 -
434 \brief The QPlatformWindow class provides an abstraction for top-level windows. -
435 -
436 The QPlatformWindow abstraction is used by QWindow for all its top level windows. It is being -
437 created by calling the createPlatformWindow function in the loaded QPlatformIntegration -
438 instance. -
439 -
440 QPlatformWindow is used to signal to the windowing system, how Qt perceives its frame. -
441 However, it is not concerned with how Qt renders into the window it represents. -
442 -
443 Visible QWindows will always have a QPlatformWindow. However, it is not necessary for -
444 all windows to have a QBackingStore. This is the case for QOpenGLWidget. And could be the case for -
445 windows where some 3.party renders into it. -
446 -
447 The platform specific window handle can be retrieved by the winId function. -
448 -
449 QPlatformWindow is also the way QPA defines how native child windows should be supported -
450 through the setParent function. -
451 -
452 \section1 Implementation Aspects -
453 -
454 \list 1 -
455 \li Mouse grab: Qt expects windows to automatically grab the mouse if the user presses -
456 a button until the button is released. -
457 Automatic grab should be released if some window is explicitly grabbed. -
458 \li Enter/Leave events: If there is a window explicitly grabbing mouse events -
459 (\c{setMouseGrabEnabled()}), enter and leave events should only be sent to the -
460 grabbing window when mouse cursor passes over the grabbing window boundary. -
461 Other windows will not receive enter or leave events while the grab is active. -
462 While an automatic mouse grab caused by a mouse button press is active, no window -
463 will receive enter or leave events. When the last mouse button is released, the -
464 autograbbing window will receive leave event if mouse cursor is no longer within -
465 the window boundary. -
466 When any grab starts, the window under cursor will receive a leave event unless -
467 it is the grabbing window. -
468 When any grab ends, the window under cursor will receive an enter event unless it -
469 was the grabbing window. -
470 \li Window positioning: When calling \c{QWindow::setFramePosition()}, the flag -
471 \c{QWindowPrivate::positionPolicy} is set to \c{QWindowPrivate::WindowFrameInclusive}. -
472 This means the position includes the window frame, whose size is at this point -
473 unknown and the geometry's topleft point is the position of the window frame. -
474 \endlist -
475 -
476 Apart from the auto-tests (\c{tests/auto/gui/kernel/qwindow}, -
477 \c{tests/auto/gui/kernel/qguiapplication} and \c{tests/auto/widgets/kernel/qwidget}), -
478 there are a number of manual tests and examples that can help testing a platform plugin: -
479 -
480 \list 1 -
481 \li \c{examples/qpa/windows}: Basic \c{QWindow} creation. -
482 \li \c{examples/opengl/hellowindow}: Basic Open GL windows. -
483 \li \c{tests/manual/windowflags}: Tests setting the window flags. -
484 \li \c{tests/manual/windowgeometry} Tests setting the window geometry. -
485 \li \c{tests/manual/windowmodality} Tests setting the window modality. -
486 \li \c{tests/manual/widgetgrab} Tests mouse grab and dialogs. -
487 \endlist -
488 -
489 \sa QBackingStore, QWindow -
490*/ -
491 -
492QT_END_NAMESPACE -
493 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial