[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qdesktopwidget.h"
|
---|
| 43 | #include "qt_windows.h"
|
---|
| 44 | #include "qapplication_p.h"
|
---|
[846] | 45 | #include <private/qsystemlibrary_p.h>
|
---|
[2] | 46 | #include <qvector.h>
|
---|
| 47 | #include <limits.h>
|
---|
[561] | 48 | #ifdef Q_WS_WINCE
|
---|
[2] | 49 | #include <sipapi.h>
|
---|
| 50 | #endif
|
---|
| 51 | #include "qwidget_p.h"
|
---|
| 52 | #include "qdebug.h"
|
---|
| 53 |
|
---|
| 54 | QT_BEGIN_NAMESPACE
|
---|
| 55 |
|
---|
| 56 | class QDesktopWidgetPrivate : public QWidgetPrivate
|
---|
| 57 | {
|
---|
| 58 | public:
|
---|
| 59 | QDesktopWidgetPrivate();
|
---|
| 60 | ~QDesktopWidgetPrivate();
|
---|
| 61 |
|
---|
| 62 | static void init(QDesktopWidget *that);
|
---|
| 63 | static void cleanup();
|
---|
| 64 | static int screenCount;
|
---|
| 65 | static int primaryScreen;
|
---|
| 66 |
|
---|
| 67 | static QVector<QRect> *rects;
|
---|
| 68 | static QVector<QRect> *workrects;
|
---|
| 69 |
|
---|
| 70 | struct MONITORINFO
|
---|
| 71 | {
|
---|
| 72 | DWORD cbSize;
|
---|
| 73 | RECT rcMonitor;
|
---|
| 74 | RECT rcWork;
|
---|
| 75 | DWORD dwFlags;
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | typedef BOOL (WINAPI *InfoFunc)(HMONITOR, MONITORINFO*);
|
---|
[846] | 79 | typedef BOOL (QT_WIN_CALLBACK *EnumProc)(HMONITOR, HDC, LPRECT, LPARAM);
|
---|
[2] | 80 | typedef BOOL (WINAPI *EnumFunc)(HDC, LPCRECT, EnumProc, LPARAM);
|
---|
| 81 |
|
---|
| 82 | static EnumFunc enumDisplayMonitors;
|
---|
| 83 | static InfoFunc getMonitorInfo;
|
---|
| 84 | static int refcount;
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | int QDesktopWidgetPrivate::screenCount = 1;
|
---|
| 88 | int QDesktopWidgetPrivate::primaryScreen = 0;
|
---|
| 89 | QDesktopWidgetPrivate::EnumFunc QDesktopWidgetPrivate::enumDisplayMonitors = 0;
|
---|
| 90 | QDesktopWidgetPrivate::InfoFunc QDesktopWidgetPrivate::getMonitorInfo = 0;
|
---|
| 91 | QVector<QRect> *QDesktopWidgetPrivate::rects = 0;
|
---|
| 92 | QVector<QRect> *QDesktopWidgetPrivate::workrects = 0;
|
---|
| 93 | static int screen_number = 0;
|
---|
| 94 | int QDesktopWidgetPrivate::refcount = 0;
|
---|
[561] | 95 | #ifdef Q_WS_WINCE_WM
|
---|
[2] | 96 | // Use SIP information, if available
|
---|
| 97 | // SipGetInfo is not supported by SSDK (no definition!).
|
---|
| 98 | static inline void qt_get_sip_info(QRect &rect)
|
---|
| 99 | {
|
---|
| 100 | SIPINFO sip;
|
---|
| 101 | memset(&sip, 0, sizeof(SIPINFO));
|
---|
| 102 | sip.cbSize = sizeof(SIPINFO);
|
---|
| 103 | if (SipGetInfo(&sip))
|
---|
| 104 | rect = QRect(QPoint(sip.rcVisibleDesktop.left, sip.rcVisibleDesktop.top),
|
---|
| 105 | QPoint(sip.rcVisibleDesktop.right - 1, sip.rcVisibleDesktop.bottom - 1));
|
---|
| 106 | }
|
---|
| 107 | #endif
|
---|
| 108 |
|
---|
| 109 |
|
---|
[846] | 110 | BOOL QT_WIN_CALLBACK enumCallback(HMONITOR hMonitor, HDC, LPRECT, LPARAM)
|
---|
[2] | 111 | {
|
---|
| 112 | QDesktopWidgetPrivate::screenCount++;
|
---|
| 113 | QDesktopWidgetPrivate::rects->resize(QDesktopWidgetPrivate::screenCount);
|
---|
| 114 | QDesktopWidgetPrivate::workrects->resize(QDesktopWidgetPrivate::screenCount);
|
---|
| 115 | // Get the MONITORINFO block
|
---|
| 116 | QDesktopWidgetPrivate::MONITORINFO info;
|
---|
| 117 | memset(&info, 0, sizeof(QDesktopWidgetPrivate::MONITORINFO));
|
---|
| 118 | info.cbSize = sizeof(QDesktopWidgetPrivate::MONITORINFO);
|
---|
| 119 | BOOL res = QDesktopWidgetPrivate::getMonitorInfo(hMonitor, &info);
|
---|
| 120 | if (!res) {
|
---|
| 121 | (*QDesktopWidgetPrivate::rects)[screen_number] = QRect();
|
---|
| 122 | (*QDesktopWidgetPrivate::workrects)[screen_number] = QRect();
|
---|
| 123 | return true;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | // Fill list of rects
|
---|
| 127 | RECT r = info.rcMonitor;
|
---|
| 128 | QRect qr(QPoint(r.left, r.top), QPoint(r.right - 1, r.bottom - 1));
|
---|
| 129 | (*QDesktopWidgetPrivate::rects)[screen_number] = qr;
|
---|
| 130 |
|
---|
| 131 | r = info.rcWork;
|
---|
| 132 | qr = QRect(QPoint(r.left, r.top), QPoint(r.right - 1, r.bottom - 1));
|
---|
| 133 | (*QDesktopWidgetPrivate::workrects)[screen_number] = qr;
|
---|
| 134 |
|
---|
| 135 | if (info.dwFlags & 0x00000001) //MONITORINFOF_PRIMARY
|
---|
| 136 | QDesktopWidgetPrivate::primaryScreen = screen_number;
|
---|
| 137 |
|
---|
| 138 | ++screen_number;
|
---|
| 139 | // Stop the enumeration if we have them all
|
---|
| 140 | return true;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | QDesktopWidgetPrivate::QDesktopWidgetPrivate()
|
---|
| 144 | {
|
---|
| 145 | ++refcount;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | void QDesktopWidgetPrivate::init(QDesktopWidget *that)
|
---|
| 149 | {
|
---|
| 150 | if (rects)
|
---|
| 151 | return;
|
---|
| 152 |
|
---|
| 153 | rects = new QVector<QRect>();
|
---|
| 154 | workrects = new QVector<QRect>();
|
---|
[561] | 155 | screenCount = 0;
|
---|
[2] | 156 |
|
---|
| 157 | #ifndef Q_OS_WINCE
|
---|
[846] | 158 | QSystemLibrary user32Lib(QLatin1String("user32"));
|
---|
[561] | 159 | if (user32Lib.load()) {
|
---|
[2] | 160 | enumDisplayMonitors = (EnumFunc)user32Lib.resolve("EnumDisplayMonitors");
|
---|
[561] | 161 | getMonitorInfo = (InfoFunc)user32Lib.resolve("GetMonitorInfoW");
|
---|
| 162 | }
|
---|
[2] | 163 |
|
---|
[561] | 164 | if (!enumDisplayMonitors || !getMonitorInfo) {
|
---|
| 165 | screenCount = GetSystemMetrics(80); // SM_CMONITORS
|
---|
| 166 | rects->resize(screenCount);
|
---|
| 167 | for (int i = 0; i < screenCount; ++i)
|
---|
| 168 | rects->replace(i, that->rect());
|
---|
| 169 | return;
|
---|
[2] | 170 | }
|
---|
[561] | 171 | // Calls enumCallback
|
---|
| |
---|