1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qdesktopwidget.h"
43 #include "qapplication_p.h"
44 #include "qwidget_p.h"
45 #include "qt_s60_p.h"
46 #include <w32std.h>
47 #if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
48 #include <graphics/displaycontrol.h>
49 #endif
50
51 QT_BEGIN_NAMESPACE
52
53 extern int qt_symbian_create_desktop_on_screen;
54
55 class QSingleDesktopWidget : public QWidget
56 {
57 public:
58 QSingleDesktopWidget();
59 ~QSingleDesktopWidget();
60 };
61
QSingleDesktopWidget()62 QSingleDesktopWidget::QSingleDesktopWidget()
63 : QWidget(0, Qt::Desktop)
64 {
65 }
66
~QSingleDesktopWidget()67 QSingleDesktopWidget::~QSingleDesktopWidget()
68 {
69 const QObjectList &childList = children();
70 for (int i = childList.size(); i > 0 ;) {
71 --i;
72 childList.at(i)->setParent(0);
73 }
74 }
75
76 class QDesktopWidgetPrivate : public QWidgetPrivate
77 {
78 public:
79 QDesktopWidgetPrivate();
80 ~QDesktopWidgetPrivate();
81 static void init(QDesktopWidget *that);
82 static void cleanup();
83 static void init_sys();
84
85 static int screenCount;
86 static int primaryScreen;
87
88 static QVector<QRect> *rects;
89 static QVector<QRect> *workrects;
90 static QVector<QWidget *> *screens;
91
92 static int refcount;
93
94 #if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
95 static MDisplayControl *displayControl;
96 #endif
97 };
98
99 int QDesktopWidgetPrivate::screenCount = 1;
100 int QDesktopWidgetPrivate::primaryScreen = 0;
101 QVector<QRect> *QDesktopWidgetPrivate::rects = 0;
102 QVector<QRect> *QDesktopWidgetPrivate::workrects = 0;
103 QVector<QWidget *> *QDesktopWidgetPrivate::screens = 0;
104 int QDesktopWidgetPrivate::refcount = 0;
105 #if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
106 MDisplayControl *QDesktopWidgetPrivate::displayControl = 0;
107 #endif
108
QDesktopWidgetPrivate()109 QDesktopWidgetPrivate::QDesktopWidgetPrivate()
110 {
111 ++refcount;
112 }
113
~QDesktopWidgetPrivate()114 QDesktopWidgetPrivate::~QDesktopWidgetPrivate()
115 {
116 if (!--refcount)
117 cleanup();
118 }
119
init(QDesktopWidget * that)120 void QDesktopWidgetPrivate::init(QDesktopWidget *that)
121 {
122 // Note that on S^3 devices the screen count retrieved via RWsSession
123 // will always be 2 but the width and height for screen number 1 will
124 // be 0 as long as TV-out is not connected.
125 //
126 // On the other hand a valid size for screen 1 will be reported even
127 // after the cable is disconnected. In order to overcome this, we use
128 // MDisplayControl::NumberOfResolutions() to check if the display is
129 // valid or not.
130
131 screenCount = S60->screenCount();
132 #if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
133 if (displayControl) {
134 if (displayControl->NumberOfResolutions() < 1)
135 screenCount = 1;
136 }
137 #endif
138 if (screenCount < 1) {
139 qWarning("No screen available");
140 screenCount = 1;
141 }
142
143 rects = new QVector<QRect>();
144 workrects = new QVector<QRect>();
145 screens = new QVector<QWidget *>();
146
147 rects->resize(screenCount);
148 workrects->resize(screenCount);
149 screens->resize(screenCount);
150
151 for (int i = 0; i < screenCount; ++i) {
152 // All screens will have a position of (0, 0) as there is no true virtual desktop
153 // or pointer event support for multiple screens on Symbian.
154 QRect r(0, 0,
155 S60->screenWidthInPixelsForScreen[i], S60->screenHeightInPixelsForScreen[i]);
156 // Stop here if empty and ignore this screen.
157 if (r.isEmpty()) {
158 screenCount = i;
159 break;
160 }
161 (*rects)[i] = r;
162 QRect wr;
163 if (i == 0)
164 wr = qt_TRect2QRect(S60->clientRect());
165 else
166 wr = rects->at(i);
167 (*workrects)[i].setRect(wr.x(), wr.y(), wr.width(), wr.height());
168 (*screens)[i] = 0;
169 }
170 (*screens)[0] = that;
171 }
172
cleanup()173 void QDesktopWidgetPrivate::cleanup()
174 {
175 delete rects;
176 rects = 0;
177 delete workrects;
178 workrects = 0;
179 if (screens) {
180 // First item is the QDesktopWidget so skip it.
181 for (int i = 1; i < screens->count(); ++i)
182 delete screens->at(i);
183 }
184 delete screens;
185 screens = 0;
186 }
187
init_sys()188 void QDesktopWidgetPrivate::init_sys()
189 {
190 #if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
191 if (S60->screenCount() > 1) {
192 CWsScreenDevice *dev = S60->screenDevice(1);
193 if (dev) {
194 displayControl = static_cast<MDisplayControl *>(
195 dev->GetInterface(MDisplayControl::ETypeId));
196 if (displayControl) {
197 displayControl->EnableDisplayChangeEvents(ETrue);
198 }
199 }
200 }
201 #endif
202 }
203
204
QDesktopWidget()205 QDesktopWidget::QDesktopWidget()
206 : QWidget(*new QDesktopWidgetPrivate, 0, Qt::Desktop)
207 {
208 setObjectName(QLatin1String("desktop"));
209 QDesktopWidgetPrivate::init_sys();
210 QDesktopWidgetPrivate::init(this);
211 }
212
~QDesktopWidget()213 QDesktopWidget::~QDesktopWidget()
214 {
215 }
216
isVirtualDesktop() const217 bool QDesktopWidget::isVirtualDesktop() const
218 {
219 return false;
220 }
221
primaryScreen() const222 int QDesktopWidget::primaryScreen() const
223 {
224 return QDesktopWidgetPrivate::primaryScreen;
225 }
226
numScreens() const227 int QDesktopWidget::numScreens() const
228 {
229 Q_D(const QDesktopWidget);
230 return QDesktopWidgetPrivate::screenCount;
231 }
232
newSingleDesktopWidget(int screen)233 static inline QWidget *newSingleDesktopWidget(int screen)
234 {
235 qt_symbian_create_desktop_on_screen = screen;
236 QWidget *w = new QSingleDesktopWidget;
237 qt_symbian_create_desktop_on_screen = -1;
238 return w;
239 }
240
screen(int screen)241 QWidget *QDesktopWidget::screen(int screen)
242 {
243 Q_D(QDesktopWidget);
244 if (screen < 0 || screen >= d->screenCount)
245 screen = d->primaryScreen;
246 if (!d->screens->at(screen)
247 || d->screens->at(screen)->windowType() != Qt::Desktop)
248 (*d->screens)[screen] = newSingleDesktopWidget(screen);
249 return (*d->screens)[screen];
250 }
251
availableGeometry(int screen) const252 const QRect QDesktopWidget::availableGeometry(int screen) const
253 {
254 Q_D(const QDesktopWidget);
255 if (screen < 0 || screen >= d->screenCount)
256 screen = d->primaryScreen;
257
258 return d->workrects->at(screen);
259 }
260
screenGeometry(int screen) const261 const QRect QDesktopWidget::screenGeometry(int screen) const
262 {
263 Q_D(const QDesktopWidget);
264 if (screen < 0 || screen >= d->screenCount)
265 screen = d->primaryScreen;
266
267 return d->rects->at(screen);
268 }
269
screenNumber(const QWidget * widget) const270 int QDesktopWidget::screenNumber(const QWidget *widget) const
271 {
272 Q_D(const QDesktopWidget);
273 return widget
274 ? S60->screenNumberForWidget(widget)
275 : d->primaryScreen;
276 }
277
screenNumber(const QPoint & point) const278 int QDesktopWidget::screenNumber(const QPoint &point) const
279 {
280 Q_UNUSED(point);
281 Q_D(const QDesktopWidget);
282 return d->primaryScreen;
283 }
284
resizeEvent(QResizeEvent *)285 void QDesktopWidget::resizeEvent(QResizeEvent *)
286 {
287 Q_D(QDesktopWidget);
288 QVector<QRect> oldrects;
289 oldrects = *d->rects;
290 QVector<QRect> oldworkrects;
291 oldworkrects = *d->workrects;
292 int oldscreencount = d->screenCount;
293
294 QDesktopWidgetPrivate::cleanup();
295 QDesktopWidgetPrivate::init(this);
296
297 for (int i = 0; i < qMin(oldscreencount, d->screenCount); ++i) {
298 QRect oldrect = oldrects[i];
299 QRect newrect = d->rects->at(i);
300 if (oldrect != newrect)
301 emit resized(i);
302 }
303
304 for (int j = 0; j < qMin(oldscreencount, d->screenCount); ++j) {
305 QRect oldrect = oldworkrects[j];
306 QRect newrect = d->workrects->at(j);
307 if (oldrect != newrect)
308 emit workAreaResized(j);
309 }
310
311 if (oldscreencount != d->screenCount) {
312 emit screenCountChanged(d->screenCount);
313 }
314 }
315
316 QT_END_NAMESPACE
317