source: trunk/src/gui/kernel/qguifunctions_wince.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 11.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
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**
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.
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**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41#include "qguifunctions_wince.h"
42#include <shellapi.h>
43#include <QtCore/qlibrary.h>
44
45QT_USE_NAMESPACE
46
47struct AygSHINITDLGINFO
48{
49 DWORD dwMask;
50 HWND hDlg;
51 DWORD dwFlags;
52};
53
54struct AygSIPINFO
55{
56 DWORD cbSize;
57 DWORD fdwFlags;
58 RECT rcVisibleDesktop;
59 RECT rcSipRect;
60 DWORD dwImDataSize;
61 void *pvImData;
62};
63
64#ifndef SHIDIF_CANCELBUTTON
65#define SHIDIF_CANCELBUTTON 0x0080
66#endif
67
68#ifndef SHIDIM_FLAGS
69#define SHIDIM_FLAGS 0x0001
70#endif
71
72#ifndef SHIDIF_DONEBUTTON
73#define SHIDIF_DONEBUTTON 0x0001
74#endif
75#ifndef SHIDIF_SIZEDLGFULLSCREEN
76#define SHIDIF_SIZEDLGFULLSCREEN 0x0004
77#endif
78
79#ifndef SHDB_HIDE
80#define SHDB_HIDE 0x0002
81#endif
82
83#ifndef SHFS_SHOWTASKBAR
84#define SHFS_SHOWTASKBAR 0x0001
85#endif
86#ifndef SHFS_HIDETASKBAR
87#define SHFS_HIDETASKBAR 0x0002
88#endif
89#ifndef SHFS_SHOWSIPBUTTON
90#define SHFS_SHOWSIPBUTTON 0x0004
91#endif
92#ifndef SHFS_HIDESIPBUTTON
93#define SHFS_HIDESIPBUTTON 0x0008
94#endif
95#ifndef SHFS_SHOWSTARTICON
96#define SHFS_SHOWSTARTICON 0x0010
97#endif
98#ifndef SHFS_HIDESTARTICON
99#define SHFS_HIDESTARTICON 0x0020
100#endif
101
102#ifndef SIPF_OFF
103#define SIPF_OFF 0x00000000
104#endif
105#ifndef SIPF_ON
106#define SIPF_ON 0x00000001
107#endif
108
109#ifndef SPI_SETSIPINFO
110#define SPI_SETSIPINFO 224
111#endif
112#ifndef SPI_GETSIPINFO
113#define SPI_GETSIPINFO 225
114#endif
115
116typedef BOOL (*AygInitDialog)(AygSHINITDLGINFO*);
117typedef BOOL (*AygFullScreen)(HWND, DWORD);
118typedef BOOL (*AygSHSipInfo)(UINT, UINT, PVOID, UINT);
119typedef BOOL (*AygSHDoneButton)(HWND, DWORD);
120
121static AygInitDialog ptrAygInitDialog = 0;
122static AygFullScreen ptrAygFullScreen = 0;
123static AygSHSipInfo ptrAygSHSipInfo = 0;
124static AygSHDoneButton ptrAygSHDoneButton = 0;
125static bool aygResolved = false;
126
127static void resolveAygLibs()
128{
129 if (!aygResolved) {
130 aygResolved = true;
131 QLibrary ayglib(QLatin1String("aygshell"));
132 if (!ayglib.load())
133 return;
134 ptrAygInitDialog = (AygInitDialog) ayglib.resolve("SHInitDialog");
135 ptrAygFullScreen = (AygFullScreen) ayglib.resolve("SHFullScreen");
136 ptrAygSHSipInfo = (AygSHSipInfo) ayglib.resolve("SHSipInfo");
137 ptrAygSHDoneButton = (AygSHDoneButton) ayglib.resolve("SHDoneButton");
138 }
139}
140
141int qt_wince_GetDIBits(HDC /*hdc*/ , HBITMAP hSourceBitmap, uint, uint, LPVOID lpvBits, LPBITMAPINFO, uint)
142{
143 if (!lpvBits) {
144 qWarning("::GetDIBits(), lpvBits NULL");
145 return 0;
146 }
147 BITMAP bm;
148 GetObject(hSourceBitmap, sizeof(BITMAP), &bm);
149 bm.bmHeight = qAbs(bm.bmHeight);
150
151 HBITMAP hTargetBitmap;
152 void *pixels;
153
154 BITMAPINFO dibInfo;
155 memset(&dibInfo, 0, sizeof(dibInfo));
156 dibInfo.bmiHeader.biBitCount = 32;
157 dibInfo.bmiHeader.biClrImportant = 0;
158 dibInfo.bmiHeader.biClrUsed = 0;
159 dibInfo.bmiHeader.biCompression = BI_RGB;;
160 dibInfo.bmiHeader.biHeight = -bm.bmHeight;
161 dibInfo.bmiHeader.biWidth = bm.bmWidth;
162 dibInfo.bmiHeader.biPlanes = 1;
163 dibInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
164 dibInfo.bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4;
165
166 HDC displayDC = GetDC(NULL);
167 if (!displayDC) {
168 qWarning("::GetDIBits(), failed to GetDC");
169 return 0;
170 }
171
172 int ret = bm.bmHeight;
173
174 hTargetBitmap = CreateDIBSection(displayDC, (const BITMAPINFO*) &dibInfo, DIB_RGB_COLORS,
175 (void**)&pixels, NULL, 0);
176 if (!hTargetBitmap) {
177 qWarning("::GetDIBits(), failed to CreateDIBSection");
178 return 0;
179 }
180
181 HDC hdcSrc = CreateCompatibleDC(displayDC);
182 HDC hdcDst = CreateCompatibleDC(displayDC);
183
184 if (!(hdcDst && hdcSrc)) {
185 qWarning("::GetDIBits(), failed to CreateCompatibleDC");
186 ret = 0;
187 }
188
189 HBITMAP hOldBitmap1 = (HBITMAP) SelectObject(hdcSrc, hSourceBitmap);
190 HBITMAP hOldBitmap2 = (HBITMAP) SelectObject(hdcDst, hTargetBitmap);
191
192 if (!(hOldBitmap1 && hOldBitmap2)) {
193 qWarning("::GetDIBits(), failed to SelectObject for bitmaps");
194 ret = 0;
195 }
196
197 if (!BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY)) {
198 qWarning("::GetDIBits(), BitBlt failed");
199 ret = 0;
200 }
201
202 SelectObject(hdcSrc, hOldBitmap1);
203 SelectObject(hdcDst, hOldBitmap2);
204
205 DeleteDC(hdcSrc);
206 DeleteDC(hdcDst);
207
208 ReleaseDC(NULL, displayDC);
209
210 memcpy(lpvBits, pixels, dibInfo.bmiHeader.biSizeImage);
211
212 DeleteObject(hTargetBitmap);
213 return ret;
214}
215
216HINSTANCE qt_wince_ShellExecute(HWND hwnd, LPCWSTR, LPCWSTR file, LPCWSTR params, LPCWSTR dir, int showCmd)
217{
218 SHELLEXECUTEINFO info;
219 info.hwnd = hwnd;
220 info.lpVerb = L"Open";
221 info.lpFile = file;
222 info.lpParameters = params;
223 info.lpDirectory = dir;
224 info.nShow = showCmd;
225 info.cbSize = sizeof(info);
226 ShellExecuteEx(&info);
227 return info.hInstApp;
228}
229
230// Clipboard --------------------------------------------------------
231BOOL qt_wince_ChangeClipboardChain( HWND /*hWndRemove*/, HWND /*hWndNewNext*/ )
232{
233 return FALSE;
234}
235
236HWND qt_wince_SetClipboardViewer( HWND /*hWndNewViewer*/ )
237{
238 return NULL;
239}
240
241
242// Graphics ---------------------------------------------------------
243COLORREF qt_wince_PALETTEINDEX( WORD /*wPaletteIndex*/)
244{
245 return 0;
246}
247
248// Internal Qt -----------------------------------------------------
249bool qt_wince_is_platform(const QString &platformString) {
250 wchar_t tszPlatform[64];
251 if (SystemParametersInfo(SPI_GETPLATFORMTYPE, sizeof(tszPlatform) / sizeof(wchar_t), tszPlatform, 0))
252 if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform))
253 return true;
254 return false;
255}
256
257int qt_wince_get_build()
258{
259 OSVERSIONINFO osvi;
260 osvi.dwOSVersionInfoSize = sizeof(osvi);
261 if (GetVersionEx(&osvi)) {
262 return osvi.dwBuildNumber;
263 }
264 return 0;
265}
266
267int qt_wince_get_version()
268{
269 OSVERSIONINFO osvi;
270 osvi.dwOSVersionInfoSize = sizeof(osvi);
271 if (GetVersionEx(&osvi)) {
272 return (osvi.dwMajorVersion * 10 + osvi.dwMinorVersion);
273 }
274 return 0;
275}
276
277bool qt_wince_is_windows_mobile_65()
278{
279 const DWORD dwFirstWM65BuildNumber = 21139;
280 OSVERSIONINFO osvi;
281 osvi.dwOSVersionInfoSize = sizeof(osvi);
282 if (!GetVersionEx(&osvi))
283 return false;
284 return osvi.dwMajorVersion > 5
285 || (osvi.dwMajorVersion == 5 && (osvi.dwMinorVersion > 2 ||
286 (osvi.dwMinorVersion == 2 && osvi.dwBuildNumber >= dwFirstWM65BuildNumber)));
287}
288
289bool qt_wince_is_pocket_pc() {
290 return qt_wince_is_platform(QString::fromLatin1("PocketPC"));
291}
292
293bool qt_wince_is_smartphone() {
294 return qt_wince_is_platform(QString::fromLatin1("Smartphone"));
295}
296bool qt_wince_is_mobile() {
297 return (qt_wince_is_smartphone() || qt_wince_is_pocket_pc());
298}
299
300bool qt_wince_is_high_dpi() {
301 if (!qt_wince_is_pocket_pc())
302 return false;
303 HDC deviceContext = GetDC(0);
304 int dpi = GetDeviceCaps(deviceContext, LOGPIXELSX);
305 ReleaseDC(0, deviceContext);
306 if ((dpi < 1000) && (dpi > 0))
307 return dpi > 96;
308 else
309 return false;
310}
311
312void qt_wince_maximize(QWidget *widget)
313{
314 HWND hwnd = widget->winId();
315 if (qt_wince_is_mobile()) {
316 AygSHINITDLGINFO shidi;
317 shidi.dwMask = SHIDIM_FLAGS;
318 shidi.hDlg = hwnd;
319 shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
320 if (widget->windowFlags() & Qt::WindowCancelButtonHint)
321 shidi.dwFlags |= SHIDIF_CANCELBUTTON;
322 if (widget->windowFlags() & Qt::WindowOkButtonHint)
323 shidi.dwFlags |= SHIDIF_DONEBUTTON;
324 if (!(widget->windowFlags() & (Qt::WindowCancelButtonHint | Qt::WindowOkButtonHint)))
325 shidi.dwFlags |= SHIDIF_CANCELBUTTON;
326 resolveAygLibs();
327 if (ptrAygInitDialog)
328 ptrAygInitDialog(&shidi);
329 } else {
330 RECT r;
331 SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
332 MoveWindow(hwnd, r.top, r.left, r.right - r.left, r.bottom - r.top, true);
333 SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong (hwnd, GWL_EXSTYLE) | WS_EX_NODRAG);
334 }
335}
336
337void qt_wince_unmaximize(QWidget *widget)
338{
339 if (ptrAygSHDoneButton && qt_wince_is_mobile()
340 && !(widget->windowFlags() & (Qt::WindowCancelButtonHint | Qt::WindowOkButtonHint)))
341 {
342 // Hide the [X] button, we've added in qt_wince_maximize.
343 ptrAygSHDoneButton(widget->winId(), SHDB_HIDE);
344 }
345}
346
347void qt_wince_minimize(HWND hwnd)
348{
349#ifdef Q_OS_WINCE_WM
350 ShowWindow(hwnd, SW_HIDE);
351#else
352 if (!IsWindowVisible(hwnd)) {
353 // Hack for an initial showMinimized.
354 // Without it, our widget doesn't appear in the task bar.
355 ShowWindow(hwnd, SW_SHOW);
356 }
357 ShowWindow(hwnd, SW_MINIMIZE);
358#endif
359}
360
361void qt_wince_hide_taskbar(HWND hwnd) {
362 if (ptrAygFullScreen)
363 ptrAygFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
364}
365
366void qt_wince_full_screen(HWND hwnd, bool fullScreen, UINT swpf) {
367 resolveAygLibs();
368 if (fullScreen) {
369 QRect r = qApp->desktop()->screenGeometry(QWidget::find(hwnd));
370 SetWindowPos(hwnd, HWND_TOP, r.left(), r.top(), r.width(), r.height(), swpf);
371 if (ptrAygFullScreen)
372 ptrAygFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
373 if (!qt_wince_is_mobile()) {
374 HWND handle = FindWindow(L"HHTaskBar", L"");
375 if (handle) {
376 ShowWindow(handle, 0);
377 EnableWindow(handle, false);
378 }
379 }
380 } else {
381 if (ptrAygFullScreen)
382 ptrAygFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON);
383 SetWindowPos(hwnd, 0, 0, 0, 0, 0, swpf);
384 if (!qt_wince_is_mobile()) {
385 HWND handle = FindWindow(L"HHTaskBar", L"");
386 if (handle) {
387 ShowWindow(handle, 1);
388 EnableWindow(handle, true);
389 }
390 }
391 }
392}
393
394void qt_wince_show_SIP(bool show)
395{
396 resolveAygLibs();
397 if (!ptrAygSHSipInfo)
398 return;
399
400 AygSIPINFO si;
401 memset(&si, 0, sizeof(si));
402 si.cbSize = sizeof(si);
403 ptrAygSHSipInfo(SPI_GETSIPINFO, 0, &si, 0);
404 si.cbSize = sizeof(si);
405 si.fdwFlags = (show ? SIPF_ON : SIPF_OFF);
406 ptrAygSHSipInfo(SPI_SETSIPINFO, 0, &si, 0);
407}
Note: See TracBrowser for help on using the repository browser.