author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
#include "qguifunctions_wince.h" |
|
42 |
#include <shellapi.h> |
|
43 |
#include <QtCore/qlibrary.h> |
|
44 |
||
45 |
QT_USE_NAMESPACE |
|
46 |
||
47 |
struct AygSHINITDLGINFO |
|
48 |
{ |
|
49 |
DWORD dwMask; |
|
50 |
HWND hDlg; |
|
51 |
DWORD dwFlags; |
|
52 |
}; |
|
53 |
||
54 |
struct 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 SHFS_SHOWTASKBAR |
|
80 |
#define SHFS_SHOWTASKBAR 0x0001 |
|
81 |
#endif |
|
82 |
#ifndef SHFS_HIDETASKBAR |
|
83 |
#define SHFS_HIDETASKBAR 0x0002 |
|
84 |
#endif |
|
85 |
#ifndef SHFS_SHOWSIPBUTTON |
|
86 |
#define SHFS_SHOWSIPBUTTON 0x0004 |
|
87 |
#endif |
|
88 |
#ifndef SHFS_HIDESIPBUTTON |
|
89 |
#define SHFS_HIDESIPBUTTON 0x0008 |
|
90 |
#endif |
|
91 |
#ifndef SHFS_SHOWSTARTICON |
|
92 |
#define SHFS_SHOWSTARTICON 0x0010 |
|
93 |
#endif |
|
94 |
#ifndef SHFS_HIDESTARTICON |
|
95 |
#define SHFS_HIDESTARTICON 0x0020 |
|
96 |
#endif |
|
97 |
||
98 |
#ifndef SIPF_OFF |
|
99 |
#define SIPF_OFF 0x00000000 |
|
100 |
#endif |
|
101 |
#ifndef SIPF_ON |
|
102 |
#define SIPF_ON 0x00000001 |
|
103 |
#endif |
|
104 |
||
105 |
#ifndef SPI_SETSIPINFO |
|
106 |
#define SPI_SETSIPINFO 224 |
|
107 |
#endif |
|
108 |
#ifndef SPI_GETSIPINFO |
|
109 |
#define SPI_GETSIPINFO 225 |
|
110 |
#endif |
|
111 |
||
112 |
typedef BOOL (*AygInitDialog)(AygSHINITDLGINFO*); |
|
113 |
typedef BOOL (*AygFullScreen)(HWND, DWORD); |
|
114 |
typedef BOOL (*AygSHSipInfo)(UINT, UINT, PVOID, UINT); |
|
115 |
||
116 |
static AygInitDialog ptrAygInitDialog = 0; |
|
117 |
static AygFullScreen ptrAygFullScreen = 0; |
|
118 |
static AygSHSipInfo ptrAygSHSipInfo = 0; |
|
119 |
static bool aygResolved = false; |
|
120 |
||
121 |
static void resolveAygLibs() |
|
122 |
{ |
|
123 |
if (!aygResolved) { |
|
124 |
aygResolved = true; |
|
125 |
QLibrary ayglib(QLatin1String("aygshell")); |
|
126 |
if (!ayglib.load()) |
|
127 |
return; |
|
128 |
ptrAygInitDialog = (AygInitDialog) ayglib.resolve("SHInitDialog"); |
|
129 |
ptrAygFullScreen = (AygFullScreen) ayglib.resolve("SHFullScreen"); |
|
130 |
ptrAygSHSipInfo = (AygSHSipInfo) ayglib.resolve("SHSipInfo"); |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
struct DIBINFO : public BITMAPINFO |
|
135 |
{ |
|
136 |
RGBQUAD arColors[255]; |
|
137 |
||
138 |
operator LPBITMAPINFO() { return (LPBITMAPINFO) this; } |
|
139 |
operator LPBITMAPINFOHEADER() { return &bmiHeader; } |
|
140 |
RGBQUAD* ColorTable() { return bmiColors; } |
|
141 |
}; |
|
142 |
||
143 |
int qt_wince_GetDIBits(HDC /*hdc*/ , HBITMAP hSourceBitmap, uint, uint, LPVOID lpvBits, LPBITMAPINFO, uint) |
|
144 |
{ |
|
145 |
if (!lpvBits) { |
|
146 |
qWarning("::GetDIBits(), lpvBits NULL"); |
|
147 |
return 0; |
|
148 |
} |
|
149 |
BITMAP bm; |
|
150 |
GetObject(hSourceBitmap, sizeof(BITMAP), &bm); |
|
151 |
bm.bmHeight = qAbs(bm.bmHeight); |
|
152 |
||
153 |
HBITMAP hTargetBitmap; |
|
154 |
void *pixels; |
|
155 |
||
156 |
BITMAPINFO dibInfo; |
|
157 |
memset(&dibInfo, 0, sizeof(dibInfo)); |
|
158 |
dibInfo.bmiHeader.biBitCount = 32; |
|
159 |
dibInfo.bmiHeader.biClrImportant = 0; |
|
160 |
dibInfo.bmiHeader.biClrUsed = 0; |
|
161 |
dibInfo.bmiHeader.biCompression = BI_RGB;; |
|
162 |
dibInfo.bmiHeader.biHeight = -bm.bmHeight; |
|
163 |
dibInfo.bmiHeader.biWidth = bm.bmWidth; |
|
164 |
dibInfo.bmiHeader.biPlanes = 1; |
|
165 |
dibInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
166 |
dibInfo.bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4; |
|
167 |
||
168 |
HDC displayDC = GetDC(NULL); |
|
169 |
if (!displayDC) { |
|
170 |
qWarning("::GetDIBits(), failed to GetDC"); |
|
171 |
return 0; |
|
172 |
} |
|
173 |
||
174 |
int ret = bm.bmHeight; |
|
175 |
||
176 |
hTargetBitmap = CreateDIBSection(displayDC, (const BITMAPINFO*) &dibInfo, DIB_RGB_COLORS, |
|
177 |
(void**)&pixels, NULL, 0); |
|
178 |
if (!hTargetBitmap) { |
|
179 |
qWarning("::GetDIBits(), failed to CreateDIBSection"); |
|
180 |
return 0; |
|
181 |
} |
|
182 |
||
183 |
HDC hdcSrc = CreateCompatibleDC(displayDC); |
|
184 |
HDC hdcDst = CreateCompatibleDC(displayDC); |
|
185 |
||
186 |
if (!(hdcDst && hdcSrc)) { |
|
187 |
qWarning("::GetDIBits(), failed to CreateCompatibleDC"); |
|
188 |
ret = 0; |
|
189 |
} |
|
190 |
||
191 |
HBITMAP hOldBitmap1 = (HBITMAP) SelectObject(hdcSrc, hSourceBitmap); |
|
192 |
HBITMAP hOldBitmap2 = (HBITMAP) SelectObject(hdcDst, hTargetBitmap); |
|
193 |
||
194 |
if (!(hOldBitmap1 && hOldBitmap2)) { |
|
195 |
qWarning("::GetDIBits(), failed to SelectObject for bitmaps"); |
|
196 |
ret = 0; |
|
197 |
} |
|
198 |
||
199 |
if (!BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY)) { |
|
200 |
qWarning("::GetDIBits(), BitBlt failed"); |
|
201 |
ret = 0; |
|
202 |
} |
|
203 |
||
204 |
SelectObject(hdcSrc, hOldBitmap1); |
|
205 |
SelectObject(hdcDst, hOldBitmap2); |
|
206 |
||
207 |
DeleteDC(hdcSrc); |
|
208 |
DeleteDC(hdcDst); |
|
209 |
||
210 |
ReleaseDC(NULL, displayDC); |
|
211 |
||
212 |
memcpy(lpvBits, pixels, dibInfo.bmiHeader.biSizeImage); |
|
213 |
||
214 |
DeleteObject(hTargetBitmap); |
|
215 |
return ret; |
|
216 |
} |
|
217 |
||
218 |
HINSTANCE qt_wince_ShellExecute(HWND hwnd, LPCWSTR, LPCWSTR file, LPCWSTR params, LPCWSTR dir, int showCmd) |
|
219 |
{ |
|
220 |
SHELLEXECUTEINFO info; |
|
221 |
info.hwnd = hwnd; |
|
222 |
info.lpVerb = L"Open"; |
|
223 |
info.lpFile = file; |
|
224 |
info.lpParameters = params; |
|
225 |
info.lpDirectory = dir; |
|
226 |
info.nShow = showCmd; |
|
227 |
info.cbSize = sizeof(info); |
|
228 |
ShellExecuteEx(&info); |
|
229 |
return info.hInstApp; |
|
230 |
} |
|
231 |
||
232 |
// Clipboard -------------------------------------------------------- |
|
233 |
BOOL qt_wince_ChangeClipboardChain( HWND /*hWndRemove*/, HWND /*hWndNewNext*/ ) |
|
234 |
{ |
|
235 |
return FALSE; |
|
236 |
} |
|
237 |
||
238 |
HWND qt_wince_SetClipboardViewer( HWND /*hWndNewViewer*/ ) |
|
239 |
{ |
|
240 |
return NULL; |
|
241 |
} |
|
242 |
||
243 |
||
244 |
// Graphics --------------------------------------------------------- |
|
245 |
COLORREF qt_wince_PALETTEINDEX( WORD /*wPaletteIndex*/) |
|
246 |
{ |
|
247 |
return 0; |
|
248 |
} |
|
249 |
||
250 |
// Internal Qt ----------------------------------------------------- |
|
251 |
bool qt_wince_is_platform(const QString &platformString) { |
|
252 |
wchar_t tszPlatform[64]; |
|
253 |
if (SystemParametersInfo(SPI_GETPLATFORMTYPE, sizeof(tszPlatform) / sizeof(wchar_t), tszPlatform, 0)) |
|
254 |
if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform)) |
|
255 |
return true; |
|
256 |
return false; |
|
257 |
} |
|
258 |
||
259 |
int qt_wince_get_build() |
|
260 |
{ |
|
261 |
OSVERSIONINFO osvi; |
|
262 |
osvi.dwOSVersionInfoSize = sizeof(osvi); |
|
263 |
if (GetVersionEx(&osvi)) { |
|
264 |
return osvi.dwBuildNumber; |
|
265 |
} |
|
266 |
return 0; |
|
267 |
} |
|
268 |
||
269 |
int qt_wince_get_version() |
|
270 |
{ |
|
271 |
OSVERSIONINFO osvi; |
|
272 |
osvi.dwOSVersionInfoSize = sizeof(osvi); |
|
273 |
if (GetVersionEx(&osvi)) { |
|
274 |
return (osvi.dwMajorVersion * 10 + osvi.dwMinorVersion); |
|
275 |
} |
|
276 |
return 0; |
|
277 |
} |
|
278 |
||
279 |
bool qt_wince_is_windows_mobile_65() |
|
280 |
{ |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
281 |
const DWORD dwFirstWM65BuildNumber = 21139; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
282 |
OSVERSIONINFO osvi; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
283 |
osvi.dwOSVersionInfoSize = sizeof(osvi); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
284 |
if (!GetVersionEx(&osvi)) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
285 |
return false; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
286 |
return osvi.dwMajorVersion > 5 |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
287 |
|| (osvi.dwMajorVersion == 5 && (osvi.dwMinorVersion > 2 || |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
288 |
(osvi.dwMinorVersion == 2 && osvi.dwBuildNumber >= dwFirstWM65BuildNumber))); |
0 | 289 |
} |
290 |
||
291 |
bool qt_wince_is_pocket_pc() { |
|
292 |
return qt_wince_is_platform(QString::fromLatin1("PocketPC")); |
|
293 |
} |
|
294 |
||
295 |
bool qt_wince_is_smartphone() { |
|
296 |
return qt_wince_is_platform(QString::fromLatin1("Smartphone")); |
|
297 |
} |
|
298 |
bool qt_wince_is_mobile() { |
|
299 |
return (qt_wince_is_smartphone() || qt_wince_is_pocket_pc()); |
|
300 |
} |
|
301 |
||
302 |
bool qt_wince_is_high_dpi() { |
|
303 |
if (!qt_wince_is_pocket_pc()) |
|
304 |
return false; |
|
305 |
HDC deviceContext = GetDC(0); |
|
306 |
int dpi = GetDeviceCaps(deviceContext, LOGPIXELSX); |
|
307 |
ReleaseDC(0, deviceContext); |
|
308 |
if ((dpi < 1000) && (dpi > 0)) |
|
309 |
return dpi > 96; |
|
310 |
else |
|
311 |
return false; |
|
312 |
} |
|
313 |
||
314 |
void qt_wince_maximize(QWidget *widget) |
|
315 |
{ |
|
316 |
HWND hwnd = widget->winId(); |
|
317 |
if (qt_wince_is_mobile()) { |
|
318 |
AygSHINITDLGINFO shidi; |
|
319 |
shidi.dwMask = SHIDIM_FLAGS; |
|
320 |
shidi.hDlg = hwnd; |
|
321 |
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN; |
|
322 |
if (widget->windowFlags() & Qt::WindowCancelButtonHint) |
|
323 |
shidi.dwFlags |= SHIDIF_CANCELBUTTON; |
|
324 |
if (widget->windowFlags() & Qt::WindowOkButtonHint) |
|
325 |
shidi.dwFlags |= SHIDIF_DONEBUTTON; |
|
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 |
||
337 |
void qt_wince_minimize(HWND hwnd) |
|
338 |
{ |
|
339 |
#ifdef Q_OS_WINCE_WM |
|
340 |
ShowWindow(hwnd, SW_HIDE); |
|
341 |
#else |
|
342 |
if (!IsWindowVisible(hwnd)) { |
|
343 |
// Hack for an initial showMinimized. |
|
344 |
// Without it, our widget doesn't appear in the task bar. |
|
345 |
ShowWindow(hwnd, SW_SHOW); |
|
346 |
} |
|
347 |
ShowWindow(hwnd, SW_MINIMIZE); |
|
348 |
#endif |
|
349 |
} |
|
350 |
||
351 |
void qt_wince_hide_taskbar(HWND hwnd) { |
|
352 |
if (ptrAygFullScreen) |
|
353 |
ptrAygFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON); |
|
354 |
} |
|
355 |
||
356 |
void qt_wince_full_screen(HWND hwnd, bool fullScreen, UINT swpf) { |
|
357 |
resolveAygLibs(); |
|
358 |
if (fullScreen) { |
|
359 |
QRect r = qApp->desktop()->screenGeometry(QWidget::find(hwnd)); |
|
360 |
SetWindowPos(hwnd, HWND_TOP, r.left(), r.top(), r.width(), r.height(), swpf); |
|
361 |
if (ptrAygFullScreen) |
|
362 |
ptrAygFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON); |
|
363 |
if (!qt_wince_is_mobile()) { |
|
364 |
HWND handle = FindWindow(L"HHTaskBar", L""); |
|
365 |
if (handle) { |
|
366 |
ShowWindow(handle, 0); |
|
367 |
EnableWindow(handle, false); |
|
368 |
} |
|
369 |
} |
|
370 |
} else { |
|
371 |
if (ptrAygFullScreen) |
|
372 |
ptrAygFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON); |
|
373 |
SetWindowPos(hwnd, 0, 0, 0, 0, 0, swpf); |
|
374 |
if (!qt_wince_is_mobile()) { |
|
375 |
HWND handle = FindWindow(L"HHTaskBar", L""); |
|
376 |
if (handle) { |
|
377 |
ShowWindow(handle, 1); |
|
378 |
EnableWindow(handle, true); |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
void qt_wince_show_SIP(bool show) |
|
385 |
{ |
|
386 |
resolveAygLibs(); |
|
387 |
if (!ptrAygSHSipInfo) |
|
388 |
return; |
|
389 |
||
390 |
AygSIPINFO si; |
|
391 |
memset(&si, 0, sizeof(si)); |
|
392 |
si.cbSize = sizeof(si); |
|
393 |
ptrAygSHSipInfo(SPI_GETSIPINFO, 0, &si, 0); |
|
394 |
si.cbSize = sizeof(si); |
|
395 |
si.fdwFlags = (show ? SIPF_ON : SIPF_OFF); |
|
396 |
ptrAygSHSipInfo(SPI_SETSIPINFO, 0, &si, 0); |
|
397 |
} |