summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwindow.cpp
blob: 9c6b6c4bf72974771ef354ae24843d0eb46da969 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qwindow.h"

#include "qplatformwindow_qpa.h"
#include "qplatformintegration_qpa.h"
#include "qsurfaceformat.h"
#ifndef QT_NO_OPENGL
#include "qplatformopenglcontext_qpa.h"
#include "qopenglcontext.h"
#endif
#include "qscreen.h"

#include "qwindow_p.h"
#include "qguiapplication_p.h"

#include <private/qevent_p.h>

#include <QtCore/QDebug>

#include <QStyleHints>

QT_BEGIN_NAMESPACE

/*!
    \class QWindow
    \brief The QWindow class encapsulates an independent window in a Windowing System.

    A window that is supplied a parent become a native child window of
    their parent window.

    Windows can potentially use a lot of memory. A usual measurement is
    width * height * depth. A window might also include multiple buffers
    to support double and triple buffering. To release a windows memory
    resources, the destroy() function.

    \section1 Window and content orientation

    QWindow has reportContentOrientationChange() and
    requestWindowOrientation() that can be used to specify the
    layout of the window contents in relation to the screen. The
    window orientation determines the actual buffer layout of the
    window, and the windowing system uses this value to rotate the
    window before it ends up on the display, and to ensure that input
    coordinates are in the correct coordinate space relative to the
    application.

    On the other hand, the content orientation is simply a hint to the
    windowing system about which orientation the window contents are in.
    It's useful when you wish to keep the same buffer layout, but rotate
    the contents instead, especially when doing rotation animations
    between different orientations. The windowing system might use this
    value to determine the layout of system popups or dialogs.
*/
QWindow::QWindow(QScreen *targetScreen)
    : QObject(*new QWindowPrivate(), 0)
    , QSurface(QSurface::Window)
{
    Q_D(QWindow);
    d->screen = targetScreen;
    if (!d->screen)
        d->screen = QGuiApplication::primaryScreen();

    //if your applications aborts here, then chances are your creating a QWindow before the
    //screen list is populated.
    Q_ASSERT(d->screen);

    connect(d->screen, SIGNAL(destroyed(QObject *)), this, SLOT(screenDestroyed(QObject *)));
    QGuiApplicationPrivate::window_list.prepend(this);
}

QWindow::QWindow(QWindow *parent)
    : QObject(*new QWindowPrivate(), parent)
    , QSurface(QSurface::Window)
{
    Q_D(QWindow);
    d->parentWindow = parent;
    if (parent)
        d->screen = parent->screen();
    if (!d->screen)
        d->screen = QGuiApplication::primaryScreen();
    QGuiApplicationPrivate::window_list.prepend(this);
}

QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
    : QObject(dd, parent)
    , QSurface(QSurface::Window)
{
    Q_D(QWindow);
    d->parentWindow = parent;
    if (parent)
        d->screen = parent->screen();
    if (!d->screen)
        d->screen = QGuiApplication::primaryScreen();
    QGuiApplicationPrivate::window_list.prepend(this);
}

QWindow::~QWindow()
{
    if (QGuiApplicationPrivate::focus_window == this)
        QGuiApplicationPrivate::focus_window = 0;
    QGuiApplicationPrivate::window_list.removeAll(this);
    destroy();
}

QSurface::~QSurface()
{
}

void QWindow::setSurfaceType(SurfaceType surfaceType)
{
    Q_D(QWindow);
    d->surfaceType = surfaceType;
}

QWindow::SurfaceType QWindow::surfaceType() const
{
    Q_D(const QWindow);
    return d->surfaceType;
}

void QWindow::setVisible(bool visible)
{
    Q_D(QWindow);

    if (d->visible == visible)
        return;
    d->visible = visible;
    emit visibleChanged(visible);

    if (!d->platformWindow)
        create();

    if (visible) {
        // remove posted quit events when showing a new window
        QCoreApplication::removePostedEvents(qApp, QEvent::Quit);

        QShowEvent showEvent;
        QGuiApplication::sendEvent(this, &showEvent);
    }

    d->platformWindow->setVisible(visible);

    if (!visible) {
        QHideEvent hideEvent;
        QGuiApplication::sendEvent(this, &hideEvent);
    }
}


bool QWindow::visible() const
{
    return isVisible();
}

bool QWindow::isVisible() const
{
    Q_D(const QWindow);

    return d->visible;
}

void QWindow::create()
{
    Q_D(QWindow);
    if (!d->platformWindow) {
        d->platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(this);
        QObjectList childObjects = children();
        for (int i = 0; i < childObjects.size(); i ++) {
            QObject *object = childObjects.at(i);
            if(object->isWindowType()) {
                QWindow *window = static_cast<QWindow *>(object);
                if (window->d_func()->platformWindow)
                    window->d_func()->platformWindow->setParent(d->platformWindow);
            }
        }
    }
}

WId QWindow::winId() const
{
    Q_D(const QWindow);
    if(!d->platformWindow)
        const_cast<QWindow *>(this)->create();

    WId id = d->platformWindow->winId();
    // See the QPlatformWindow::winId() documentation
    Q_ASSERT(id != WId(0));
    return id;
}

QWindow *QWindow::parent() const
{
    Q_D(const QWindow);
    return d->parentWindow;
}

/**
  Sets the parent Window. This will lead to the windowing system managing the clip of the window, so it will be clipped to the parent window.
  Setting parent to be 0(NULL) means map it as a top level window. If the parent window has grabbed its window system resources, then the current window will also grab its window system resources.
  **/

void QWindow::setParent(QWindow *parent)
{
    Q_D(QWindow);

    QObject::setParent(parent);

    if (d->platformWindow) {
        if (parent && parent->d_func()->platformWindow) {
            d->platformWindow->setParent(parent->d_func()->platformWindow);
        } else {
            d->platformWindow->setParent(0);
        }
    }

    d->parentWindow = parent;
}

/*!
   Returns whether the window is top level, i.e. has no parent window.
 */
bool QWindow::isTopLevel() const
{
    Q_D(const QWindow);
    return d->parentWindow == 0;
}

bool QWindow::isModal() const
{
    Q_D(const QWindow);
    return d->modality != Qt::NonModal;
}

Qt::WindowModality QWindow::windowModality() const
{
    Q_D(const QWindow);
    return d->modality;
}

void QWindow::setWindowModality(Qt::WindowModality windowModality)
{
    Q_D(QWindow);
    d->modality = windowModality;
}

void QWindow::setFormat(const QSurfaceFormat &format)
{
    Q_D(QWindow);
    d->requestedFormat = format;
}


/*!
    Returns the requested surfaceformat of this window.

    If the requested format was not supported by the platform implementation,
    the requestedFormat will differ from the actual window format.

    \sa format.
 */
QSurfaceFormat QWindow::requestedFormat() const
{
    Q_D(const QWindow);
    return d->requestedFormat;
}

QSurfaceFormat QWindow::format() const
{
    Q_D(const QWindow);
    if (d->platformWindow)
        return d->platformWindow->format();
    return d->requestedFormat;
}

void QWindow::setWindowFlags(Qt::WindowFlags flags)
{
    Q_D(QWindow);
    if (d->platformWindow)
        d->windowFlags = d->platformWindow->setWindowFlags(flags);
    else
        d->windowFlags = flags;
}

Qt::WindowFlags QWindow::windowFlags() const
{
    Q_D(const QWindow);
    return d->windowFlags;
}

Qt::WindowType QWindow::windowType() const
{
    Q_D(const QWindow);
    return static_cast<Qt::WindowType>(int(d->windowFlags & Qt::WindowType_Mask));
}

void QWindow::setWindowTitle(const QString &title)
{
    Q_D(QWindow);
    d->windowTitle = title;
    if (d->platformWindow) {
        d->platformWindow->setWindowTitle(title);
    }
}

QString QWindow::windowTitle() const
{
    Q_D(const QWindow);
    return d->windowTitle;
}

void QWindow::raise()
{
    Q_D(QWindow);
    if (d->platformWindow) {
        d->platformWindow->raise();
    }
}

void QWindow::lower()
{
    Q_D(QWindow);
    if (d->platformWindow) {
        d->platformWindow->lower();
    }
}

void QWindow::setOpacity(qreal level)
{
    Q_D(QWindow);
    if (d->platformWindow) {
        d->platformWindow->setOpacity(level);
    }
}

void QWindow::requestActivateWindow()
{
    Q_D(QWindow);
    if (d->platformWindow)
        d->platformWindow->requestActivateWindow();
}


/*!
    Returns if this window is exposed in the windowing system.

    When the window is not exposed, it is shown by the application
    but it is still not showing in the windowing system, so the application
    should minimize rendering and other graphical activities.

    An exposeEvent() is sent every time this value changes.
 */

bool QWindow::isExposed() const
{
    Q_D(const QWindow);
    if (d->platformWindow)
        return d->platformWindow->isExposed();
    return false;
}

/*!
    Returns true if the window should appear active from a style perspective.

    This is the case for the window that has input focus as well as windows
    that are in the same parent / transient parent chain as the focus window.

    To get the window that currently has focus, use QGuiApplication::focusWindow().
*/
bool QWindow::isActive() const
{
    Q_D(const QWindow);
    if (!d->platformWindow)
        return false;

    QWindow *focus = QGuiApplication::focusWindow();
    if (focus == this)
        return true;

    if (!parent() && !transientParent()) {
        return isAncestorOf(focus);
    } else {
        return (parent() && parent()->isActive()) || (transientParent() && transientParent()->isActive());
    }
}

/*!
  Reports that the orientation of the window's contents have changed.

  This is a hint to the window manager in case it needs to display
  additional content like popups, dialogs, status bars, or similar
  in relation to the window.

  The recommended orientation is QScreen::orientation() but
  an application doesn't have to support all possible orientations,
  and thus can opt to ignore the current screen orientation.

  The difference between the window and the content orientation
  determines how much to rotate the content by. QScreen::angleBetween(),
  QScreen::transformBetween(), and QScreen::mapBetween() can be used
  to compute the necessary transform.

  \sa requestWindowOrientation(), QScreen::orientation()
*/
void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
{
    Q_D(QWindow);
    if (d->contentOrientation == orientation)
        return;
    if (!d->platformWindow)
        create();
    Q_ASSERT(d->platformWindow);
    d->contentOrientation = orientation;
    d->platformWindow->handleContentOrientationChange(orientation);
    emit contentOrientationChanged(orientation);
}

/*!
  Returns the actual content orientation.

  This is the last value set with reportContentOrientationChange(). It defaults
  to Qt::PrimaryOrientation.
*/
Qt::ScreenOrientation QWindow::contentOrientation() const
{
    Q_D(const QWindow);
    return d->contentOrientation;
}

/*!
  Requests the given window orientation.

  The window orientation specifies how the window should be rotated
  by the window manager in order to be displayed. Input events will
  be correctly mapped to the given orientation.

  The return value is false if the system doesn't support the given
  orientation (for example when requesting a portrait orientation
  on a device that only handles landscape buffers, typically a desktop
  system).

  If the return value is false, call windowOrientation() to get the actual
  supported orientation.

  \sa windowOrientation(), reportContentOrientationChange(), QScreen::orientation()
*/
bool QWindow::requestWindowOrientation(Qt::ScreenOrientation orientation)
{
    Q_D(QWindow);
    if (!d->platformWindow)
        create();
    Q_ASSERT(d->platformWindow);
    d->windowOrientation = d->platformWindow->requestWindowOrientation(orientation);
    return d->windowOrientation == orientation;
}

/*!
  Returns the actual window orientation.

  The default value is Qt::PrimaryOrientation.

  \sa requestWindowOrientation()
*/
Qt::ScreenOrientation QWindow::windowOrientation() const
{
    Q_D(const QWindow);
    return d->windowOrientation;
}

Qt::WindowState QWindow::windowState() const
{
    Q_D(const QWindow);
    return d->windowState;
}

void QWindow::setWindowState(Qt::WindowState state)
{
    if (state == Qt::WindowActive) {
        qWarning() << "QWindow::setWindowState does not accept Qt::WindowActive";
        return;
    }

    Q_D(QWindow);
    if (d->platformWindow)
        d->windowState = d->platformWindow->setWindowState(state);
    else
        d->windowState = state;
}

/*!
  Sets the transient parent, which is a hint to the window manager that this window is a dialog or pop-up on behalf of the given window.
*/
void QWindow::setTransientParent(QWindow *parent)
{
    Q_D(QWindow);

    QWindow *previousParent = d->transientParent;

    d->transientParent = parent;
}

QWindow *QWindow::transientParent() const
{
    Q_D(const QWindow);
    return d->transientParent.data();
}

/*!
    \enum QWindow::AncestorMode

    This enum is used to control whether or not transient parents
    should be considered ancestors.

    \value ExcludeTransients Transient parents are not considered ancestors.
    \value IncludeTransients Transient parents are considered ancestors.
*/

/*!
  Returns true if the window is an ancestor of the given child. If mode is
  IncludeTransients transient parents are also considered ancestors.
*/
bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const
{
    if (child->parent() == this || (mode == IncludeTransients && child->transientParent() == this))
        return true;

    return (child->parent() && isAncestorOf(child->parent(), mode))
        || (mode == IncludeTransients && child->transientParent() && isAncestorOf(child->transientParent(), mode));
}

QSize QWindow::minimumSize() const
{
    Q_D(const QWindow);
    return d->minimumSize;
}

QSize QWindow::maximumSize() const
{
    Q_D(const QWindow);
    return d->maximumSize;
}

QSize QWindow::baseSize() const
{
    Q_D(const QWindow);
    return d->baseSize;
}

QSize QWindow::sizeIncrement() const
{
    Q_D(const QWindow);
    return d->sizeIncrement;
}

void QWindow::setMinimumSize(const QSize &size)
{
    Q_D(QWindow);
    QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));
    if (d->minimumSize == adjustedSize)
        return;
    d->minimumSize = adjustedSize;
    if (d->platformWindow && isTopLevel())
        d->platformWindow->propagateSizeHints();
}

void QWindow::setMaximumSize(const QSize &size)
{
    Q_D(QWindow);
    QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));
    if (d->maximumSize == adjustedSize)
        return;
    d->maximumSize = adjustedSize;
    if (d->platformWindow && isTopLevel())
        d->platformWindow->propagateSizeHints();
}

void QWindow::setBaseSize(const QSize &size)
{
    Q_D(QWindow);
    if (d->baseSize == size)
        return;
    d->baseSize = size;
    if (d->platformWindow && isTopLevel())
        d->platformWindow->propagateSizeHints();
}

void QWindow::setSizeIncrement(const QSize &size)
{
    Q_D(QWindow);
    if (d->sizeIncrement == size)
        return;
    d->sizeIncrement = size;
    if (d->platformWindow && isTopLevel())
        d->platformWindow->propagateSizeHints();
}

/*!
    Sets the geometry of the window excluding its window frame.
*/
void QWindow::setGeometry(const QRect &rect)
{
    Q_D(QWindow);
    if (rect == geometry())
        return;
    QRect oldRect = geometry();

    d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
    if (d->platformWindow) {
        d->platformWindow->setGeometry(rect);
    } else {
        d->geometry = rect;
    }

    if (rect.x() != oldRect.x())
        emit xChanged(rect.x());
    if (rect.y() != oldRect.y())
        emit yChanged(rect.y());
    if (rect.width() != oldRect.width())
        emit widthChanged(rect.width());
    if (rect.height() != oldRect.height())
        emit heightChanged(rect.height());
}

/*!
    Returns the geometry of the window excluding its window frame.
*/
QRect QWindow::geometry() const
{
    Q_D(const QWindow);
    if (d->platformWindow)
        return d->platformWindow->geometry();
    return d->geometry;
}

/*!
    Returns the window frame margins surrounding the window.
*/
QMargins QWindow::frameMargins() const
{
    Q_D(const QWindow);
    if (d->platformWindow)
        return d->platformWindow->frameMargins();
    return QMargins();
}

/*!
    Returns the geometry of the window including its window frame.
*/
QRect QWindow::frameGeometry() const
{
    Q_D(const QWindow);
    if (d->platformWindow) {
        QMargins m = frameMargins();
        return d->platformWindow->geometry().adjusted(-m.left(), -m.top(), m.right(), m.bottom());
    }
    return d->geometry;
}

/*!
    Returns the top left position of the window including its window frame.
*/
QPoint QWindow::framePos() const
{
    Q_D(const QWindow);
    if (d->platformWindow) {
        QMargins margins = frameMargins();
        return d->platformWindow->geometry().topLeft() - QPoint(margins.left(), margins.top());
    }
    return d->geometry.topLeft();
}

/*!
    Sets the upper left position of the window including its window frame.
*/
void QWindow::setFramePos(const QPoint &point)
{
    Q_D(QWindow);
    d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
    if (d->platformWindow) {
        d->platformWindow->setGeometry(QRect(point, size()));
    } else {
        d->geometry.setTopLeft(point);
    }
}

void QWindow::resize(const QSize &newSize)
{
    Q_D(QWindow);
    if (d->platformWindow) {
        d->platformWindow->setGeometry(QRect(pos(), newSize));
    } else {
        d->geometry.setSize(newSize);
    }
}

void QWindow::setWindowIcon(const QImage &icon) const
{
    Q_UNUSED(icon);
    qDebug() << "unimplemented:" << __FILE__ << __LINE__;
}



/*!
    Releases the native platform resources associated with this window.
 */

void QWindow::destroy()
{
    Q_D(QWindow);
    QObjectList childrenWindows = children();
    for (int i = 0; i < childrenWindows.size(); i++) {
        QObject *object = childrenWindows.at(i);
        if (object->isWindowType()) {
            QWindow *w = static_cast<QWindow*>(object);
            QGuiApplicationPrivate::window_list.removeAll(w);
            w->destroy();
        }
    }
    setVisible(false);
    delete d->platformWindow;
    d->platformWindow = 0;
}

QPlatformWindow *QWindow::handle() const
{
    Q_D(const QWindow);
    return d->platformWindow;
}

QPlatformSurface *QWindow::surfaceHandle() const
{
    Q_D(const QWindow);
    return d->platformWindow;
}

bool QWindow::setKeyboardGrabEnabled(bool grab)
{
    Q_D(QWindow);
    if (d->platformWindow)
        return d->platformWindow->setKeyboardGrabEnabled(grab);
    return false;
}

bool QWindow::setMouseGrabEnabled(bool grab)
{
    Q_D(QWindow);
    if (d->platformWindow)
        return d->platformWindow->setMouseGrabEnabled(grab);
    return false;
}

QScreen *QWindow::screen() const
{
    Q_D(const QWindow);
    return d->screen;
}

void QWindow::setScreen(QScreen *newScreen)
{
    Q_D(QWindow);
    if (!newScreen)
        newScreen = QGuiApplication::primaryScreen();
    if (newScreen != screen()) {
        const bool wasCreated = d->platformWindow != 0;
        if (wasCreated)
            destroy();
        if (d->screen)
            disconnect(d->screen, SIGNAL(destroyed(QObject *)), this, SLOT(screenDestroyed(QObject *)));
        d->screen = newScreen;
        if (newScreen) {
            connect(d->screen, SIGNAL(destroyed(QObject *)), this, SLOT(screenDestroyed(QObject *)));
            if (wasCreated)
                create();
        }
        emit screenChanged(newScreen);
    }
}

void QWindow::screenDestroyed(QObject *object)
{
    Q_D(QWindow);
    if (object == static_cast<QObject *>(d->screen))
        setScreen(0);
}

/*!
    \fn QWindow::screenChanged(QScreen *screen)

    This signal is emitted when a window's screen changes, either
    by being set explicitly with setScreen(), or automatically when
    the window's screen is removed.
*/

/*!
  Returns the accessibility interface for the object that the window represents
  \preliminary
  \sa QAccessible
  */
QAccessibleInterface *QWindow::accessibleRoot() const
{
    return 0;
}

/*!
    \fn QWindow::focusObjectChanged(QObject *focusObject)

    This signal is emitted when final receiver of events tied to focus is changed.
    \sa focusObject()
*/

/*!
  Returns the QObject that will be the final receiver of events tied focus, such
  as key events.
*/
QObject *QWindow::focusObject() const
{
    return const_cast<QWindow *>(this);
}

void QWindow::show()
{
    if (qApp->styleHints()->showIsFullScreen())
        showFullScreen();
    else
        showNormal();
}

void QWindow::hide()
{
    setVisible(false);
}

void QWindow::showMinimized()
{
    setWindowState(Qt::WindowMinimized);
    setVisible(true);
}

void QWindow::showMaximized()
{
    setWindowState(Qt::WindowMaximized);
    setVisible(true);
}

void QWindow::showFullScreen()
{
    setWindowState(Qt::WindowFullScreen);
    setVisible(true);
    requestActivateWindow();
}

void QWindow::showNormal()
{
    setWindowState(Qt::WindowNoState);
    setVisible(true);
}

bool QWindow::close()
{
    Q_D(QWindow);

    // Do not close non top level windows
    if (parent())
        return false;

    if (QGuiApplicationPrivate::focus_window == this)
        QGuiApplicationPrivate::focus_window = 0;

    QGuiApplicationPrivate::window_list.removeAll(this);
    destroy();
    d->maybeQuitOnLastWindowClosed();
    return true;
}



/*!
    The expose event is sent by the window system whenever the window's
    exposure on screen changes.

    If the window is moved off screen, is made totally obscured by another
    window, iconified or similar, this function might be called and the
    value of isExposed() might change to false. When this happens,
    an application should stop its rendering as it is no longer visible
    to the user.
 */

void QWindow::exposeEvent(QExposeEvent *ev)
{
    ev->ignore();
}

void QWindow::moveEvent(QMoveEvent *ev)
{
    ev->ignore();
}

void QWindow::resizeEvent(QResizeEvent *ev)
{
    ev->ignore();
}

void QWindow::showEvent(QShowEvent *ev)
{
    ev->ignore();
}

void QWindow::hideEvent(QHideEvent *ev)
{
    ev->ignore();
}

bool QWindow::event(QEvent *ev)
{
    switch (ev->type()) {
    case QEvent::MouseMove:
        mouseMoveEvent(static_cast<QMouseEvent*>(ev));
        break;

    case QEvent::MouseButtonPress:
        mousePressEvent(static_cast<QMouseEvent*>(ev));
        break;

    case QEvent::MouseButtonRelease:
        mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
        break;

    case QEvent::MouseButtonDblClick:
        mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
        break;

    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    case QEvent::TouchCancel:
        touchEvent(static_cast<QTouchEvent *>(ev));
        break;

    case QEvent::Move:
        moveEvent(static_cast<QMoveEvent*>(ev));
        break;

    case QEvent::Resize:
        resizeEvent(static_cast<QResizeEvent*>(ev));
        break;

    case QEvent::KeyPress:
        keyPressEvent(static_cast<QKeyEvent *>(ev));
        break;

    case QEvent::KeyRelease:
        keyReleaseEvent(static_cast<QKeyEvent *>(ev));
        break;

    case QEvent::FocusIn:
        focusInEvent(static_cast<QFocusEvent *>(ev));
        break;

    case QEvent::FocusOut:
        focusOutEvent(static_cast<QFocusEvent *>(ev));
        break;

#ifndef QT_NO_WHEELEVENT
    case QEvent::Wheel:
        wheelEvent(static_cast<QWheelEvent*>(ev));
        break;
#endif

    case QEvent::Close: {
        Q_D(QWindow);
        bool wasVisible = isVisible();
        destroy();
        if (wasVisible)
            d->maybeQuitOnLastWindowClosed();
        break; }

    case QEvent::Expose:
        exposeEvent(static_cast<QExposeEvent *>(ev));
        break;

    case QEvent::Show:
        showEvent(static_cast<QShowEvent *>(ev));
        break;

    case QEvent::Hide:
        hideEvent(static_cast<QHideEvent *>(ev));
        break;

    default:
        return QObject::event(ev);
    }
    return true;
}

void QWindow::keyPressEvent(QKeyEvent *ev)
{
    ev->ignore();
}

void QWindow::keyReleaseEvent(QKeyEvent *ev)
{
    ev->ignore();
}

void QWindow::focusInEvent(QFocusEvent *ev)
{
    ev->ignore();
}

void QWindow::focusOutEvent(QFocusEvent *ev)
{
    ev->ignore();
}

void QWindow::mousePressEvent(QMouseEvent *ev)
{
    ev->ignore();
}

void QWindow::mouseReleaseEvent(QMouseEvent *ev)
{
    ev->ignore();
}

void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
{
    ev->ignore();
}

void QWindow::mouseMoveEvent(QMouseEvent *ev)
{
    ev->ignore();
}

#ifndef QT_NO_WHEELEVENT
void QWindow::wheelEvent(QWheelEvent *ev)
{
    ev->ignore();
}
#endif //QT_NO_WHEELEVENT

void QWindow::touchEvent(QTouchEvent *ev)
{
    ev->ignore();
}

bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
    Q_UNUSED(eventType);
    Q_UNUSED(message);
    Q_UNUSED(result);
    return false;
}

/*!
    \fn QPoint QWindow::mapToGlobal(const QPoint &pos) const

    Translates the window coordinate \a pos to global screen
    coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give
    the global coordinates of the top-left pixel of the window.

    \sa mapFromGlobal()
*/

QPoint QWindow::mapToGlobal(const QPoint &pos) const
{
    return pos + d_func()->globalPosition();
}



/*!
    \fn QPoint QWindow::mapFromGlobal(const QPoint &pos) const

    Translates the global screen coordinate \a pos to window
    coordinates.

    \sa mapToGlobal()
*/

QPoint QWindow::mapFromGlobal(const QPoint &pos) const
{
    return pos - d_func()->globalPosition();
}



Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window)
{
    return window->d_func();
}

void QWindowPrivate::maybeQuitOnLastWindowClosed()
{
    Q_Q(QWindow);

    // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent
    bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent();

    if (quitOnClose) {
        QWindowList list = QGuiApplication::topLevelWindows();
        bool lastWindowClosed = true;
        for (int i = 0; i < list.size(); ++i) {
            QWindow *w = list.at(i);
            if (!w->isVisible())
                continue;
            lastWindowClosed = false;
            break;
        }
        if (lastWindowClosed) {
            QGuiApplicationPrivate::emitLastWindowClosed();
            QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance()));
            applicationPrivate->maybeQuit();
        }
    }

}

QT_END_NAMESPACE