[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 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 |
|
---|
| 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 | {
|
---|
| 281 | return ((qt_wince_get_version() == 52) && (qt_wince_get_build() > 2000));
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | bool qt_wince_is_pocket_pc() {
|
---|
| 285 | return qt_wince_is_platform(QString::fromLatin1("PocketPC"));
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | bool qt_wince_is_smartphone() {
|
---|
| 289 | return qt_wince_is_platform(QString::fromLatin1("Smartphone"));
|
---|
| 290 | }
|
---|
| 291 | bool qt_wince_is_mobile() {
|
---|
| 292 | return (qt_wince_is_smartphone() || qt_wince_is_pocket_pc());
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | bool qt_wince_is_high_dpi() {
|
---|
| 296 | if (!qt_wince_is_pocket_pc())
|
---|
| 297 | return false;
|
---|
| 298 | HDC deviceContext = GetDC(0);
|
---|
| 299 | int dpi = GetDeviceCaps(deviceContext, LOGPIXELSX);
|
---|
| 300 | ReleaseDC(0, deviceContext);
|
---|
| 301 | if ((dpi < 1000) && (dpi > 0))
|
---|
| 302 | return dpi > 96;
|
---|
| 303 | else
|
---|
| 304 | return false;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | void qt_wince_maximize(QWidget *widget)
|
---|
| 308 | {
|
---|
| 309 | HWND hwnd = widget->winId();
|
---|
| 310 | if (qt_wince_is_mobile()) {
|
---|
| 311 | AygSHINITDLGINFO shidi;
|
---|
| 312 | shidi.dwMask = SHIDIM_FLAGS;
|
---|
| 313 | shidi.hDlg = hwnd;
|
---|
| 314 | shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
|
---|
| 315 | if (widget->windowFlags() & Qt::WindowCancelButtonHint)
|
---|
| 316 | shidi.dwFlags |= SHIDIF_CANCELBUTTON;
|
---|
| 317 | if (widget->windowFlags() & Qt::WindowOkButtonHint)
|
---|
| 318 | shidi.dwFlags |= SHIDIF_DONEBUTTON;
|
---|
| 319 | resolveAygLibs();
|
---|
| 320 | if (ptrAygInitDialog)
|
---|
| 321 | ptrAygInitDialog(&shidi);
|
---|
| 322 | } else {
|
---|
| 323 | RECT r;
|
---|
| 324 | SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
|
---|
| 325 | MoveWindow(hwnd, r.top, r.left, r.right - r.left, r.bottom - r.top, true);
|
---|
| 326 | SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong (hwnd, GWL_EXSTYLE) | WS_EX_NODRAG);
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | void qt_wince_minimize(HWND hwnd)
|
---|
| 331 | {
|
---|
| 332 | #ifdef Q_OS_WINCE_WM
|
---|
| 333 | ShowWindow(hwnd, SW_HIDE);
|
---|
| 334 | #else
|
---|
| 335 | if (!IsWindowVisible(hwnd)) {
|
---|
| 336 | // Hack for an initial showMinimized.
|
---|
| 337 | // Without it, our widget doesn't appear in the task bar.
|
---|
| 338 | ShowWindow(hwnd, SW_SHOW);
|
---|
| 339 | }
|
---|
| 340 | ShowWindow(hwnd, SW_MINIMIZE);
|
---|
| 341 | #endif
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | void qt_wince_hide_taskbar(HWND hwnd) {
|
---|
| 345 | if (ptrAygFullScreen)
|
---|
| 346 | ptrAygFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | void qt_wince_full_screen(HWND hwnd, bool fullScreen, UINT swpf) {
|
---|
| 350 | resolveAygLibs();
|
---|
| 351 | if (fullScreen) {
|
---|
| 352 | QRect r = qApp->desktop()->screenGeometry(QWidget::find(hwnd));
|
---|
| 353 | SetWindowPos(hwnd, HWND_TOP, r.left(), r.top(), r.width(), r.height(), swpf);
|
---|
| 354 | if (ptrAygFullScreen)
|
---|
| 355 | ptrAygFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
|
---|
| 356 | if (!qt_wince_is_mobile()) {
|
---|
| 357 | HWND handle = FindWindow(L"HHTaskBar", L"");
|
---|
| 358 | if (handle) {
|
---|
| 359 | ShowWindow(handle, 0);
|
---|
| 360 | EnableWindow(handle, false);
|
---|
| 361 | }
|
---|
| 362 | }
|
---|
| 363 | } else {
|
---|
| 364 | if (ptrAygFullScreen)
|
---|
| 365 | ptrAygFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON);
|
---|
| 366 | SetWindowPos(hwnd, 0, 0, 0, 0, 0, swpf);
|
---|
| 367 | if (!qt_wince_is_mobile()) {
|
---|
| 368 | HWND handle = FindWindow(L"HHTaskBar", L"");
|
---|
| 369 | if (handle) {
|
---|
| 370 | ShowWindow(handle, 1);
|
---|
| 371 | EnableWindow(handle, true);
|
---|
| 372 | }
|
---|
| 373 | }
|
---|
| 374 | }
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | void qt_wince_show_SIP(bool show)
|
---|
| 378 | {
|
---|
| 379 | resolveAygLibs();
|
---|
| 380 | if (!ptrAygSHSipInfo)
|
---|
| 381 | return;
|
---|
| 382 |
|
---|
| 383 | AygSIPINFO si;
|
---|
| 384 | memset(&si, 0, sizeof(si));
|
---|
| 385 | si.cbSize = sizeof(si);
|
---|
| 386 | ptrAygSHSipInfo(SPI_GETSIPINFO, 0, &si, 0);
|
---|
| 387 | si.cbSize = sizeof(si);
|
---|
| 388 | si.fdwFlags = (show ? SIPF_ON : SIPF_OFF);
|
---|
| 389 | ptrAygSHSipInfo(SPI_SETSIPINFO, 0, &si, 0);
|
---|
| 390 | }
|
---|