Qt 4.8
qguifunctions_wince.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include "qguifunctions_wince.h"
42 #include <shellapi.h>
43 #include <QtCore/qlibrary.h>
44 
46 
48 {
49  DWORD dwMask;
50  HWND hDlg;
51  DWORD dwFlags;
52 };
53 
54 struct AygSIPINFO
55 {
56  DWORD cbSize;
57  DWORD fdwFlags;
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 #ifndef SPI_GETPLATFORMTYPE
116 #define SPI_GETPLATFORMTYPE 257
117 #endif
118 
119 typedef BOOL (*AygInitDialog)(AygSHINITDLGINFO*);
120 typedef BOOL (*AygFullScreen)(HWND, DWORD);
121 typedef BOOL (*AygSHSipInfo)(UINT, UINT, PVOID, UINT);
122 typedef BOOL (*AygSHDoneButton)(HWND, DWORD);
123 
128 static void resolveAygLibs()
129 {
130  static bool aygResolved = false;
131  if (!aygResolved) {
132  QLibrary ayglib(QLatin1String("aygshell"));
133  ptrAygInitDialog = (AygInitDialog) ayglib.resolve("SHInitDialog");
134  ptrAygFullScreen = (AygFullScreen) ayglib.resolve("SHFullScreen");
135  ptrAygSHSipInfo = (AygSHSipInfo) ayglib.resolve("SHSipInfo");
136  ptrAygSHDoneButton = (AygSHDoneButton) ayglib.resolve("SHDoneButton");
137  aygResolved = true;
138  }
139 }
140 
141 int 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 
216 HINSTANCE 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 --------------------------------------------------------
231 BOOL qt_wince_ChangeClipboardChain( HWND /*hWndRemove*/, HWND /*hWndNewNext*/ )
232 {
233  return FALSE;
234 }
235 
236 HWND qt_wince_SetClipboardViewer( HWND /*hWndNewViewer*/ )
237 {
238  return NULL;
239 }
240 
241 
242 // Graphics ---------------------------------------------------------
243 COLORREF qt_wince_PALETTEINDEX( WORD /*wPaletteIndex*/)
244 {
245  return 0;
246 }
247 
248 // Internal Qt -----------------------------------------------------
249 bool 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 
258 {
259  OSVERSIONINFO osvi;
260  osvi.dwOSVersionInfoSize = sizeof(osvi);
261  if (GetVersionEx(&osvi)) {
262  return osvi.dwBuildNumber;
263  }
264  return 0;
265 }
266 
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 
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 
290  return qt_wince_is_platform(QString::fromLatin1("PocketPC"));
291 }
292 
294  return qt_wince_is_platform(QString::fromLatin1("Smartphone"));
295 }
298 }
299 
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 
313 {
314  HWND hwnd = widget->winId();
315  if (qt_wince_is_mobile()) {
316  AygSHINITDLGINFO shidi;
317  shidi.dwMask = SHIDIM_FLAGS;
318  shidi.hDlg = hwnd;
320  if (widget->windowFlags() & Qt::WindowCancelButtonHint)
321  shidi.dwFlags |= SHIDIF_CANCELBUTTON;
323  shidi.dwFlags |= SHIDIF_DONEBUTTON;
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 
338 {
341  {
342  // Hide the [X] button, we've added in qt_wince_maximize.
343  ptrAygSHDoneButton(widget->winId(), SHDB_HIDE);
344  }
345 }
346 
347 void 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 
361 void qt_wince_hide_taskbar(HWND hwnd) {
362  if (ptrAygFullScreen)
364 }
365 
366 void 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)
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)
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 
394 void 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 }
BOOL qt_wince_ChangeClipboardChain(HWND, HWND)
void qt_wince_minimize(HWND hwnd)
bool qt_wince_is_high_dpi()
#define SHDB_HIDE
static mach_timebase_info_data_t info
#define SPI_GETSIPINFO
QPointer< QWidget > widget
#define SHIDIF_DONEBUTTON
#define SPI_GETWORKAREA
#define SHFS_SHOWSTARTICON
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define SHIDIM_FLAGS
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
COLORREF qt_wince_PALETTEINDEX(WORD)
void qt_wince_maximize(QWidget *widget)
BOOL(* AygInitDialog)(AygSHINITDLGINFO *)
#define SHFS_HIDESIPBUTTON
void * resolve(const char *symbol)
Returns the address of the exported symbol symbol.
Definition: qlibrary.cpp:1155
BOOL(* AygSHSipInfo)(UINT, UINT, PVOID, UINT)
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QString class provides a Unicode character string.
Definition: qstring.h:83
void qt_wince_full_screen(HWND hwnd, bool fullScreen, UINT swpf)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
static HDC displayDC
#define SPI_SETSIPINFO
#define SHFS_SHOWSIPBUTTON
#define SHFS_SHOWTASKBAR
static AygInitDialog ptrAygInitDialog
#define SPI_GETPLATFORMTYPE
#define SIPF_OFF
#define WS_EX_NODRAG
bool qt_wince_is_pocket_pc()
static AygSHDoneButton ptrAygSHDoneButton
#define qApp
void qt_wince_hide_taskbar(HWND hwnd)
void qt_wince_unmaximize(QWidget *widget)
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
Q_CORE_EXPORT void qWarning(const char *,...)
void qt_wince_show_SIP(bool show)
unsigned int uint
Definition: qglobal.h:996
bool qt_wince_is_windows_mobile_65()
HWND qt_wince_SetClipboardViewer(HWND)
#define FALSE
Synonym for false.
Definition: qglobal.h:1019
bool qt_wince_is_smartphone()
HINSTANCE qt_wince_ShellExecute(HWND hwnd, LPCWSTR, LPCWSTR file, LPCWSTR params, LPCWSTR dir, int showCmd)
bool qt_wince_is_mobile()
#define SHFS_HIDESTARTICON
#define SHIDIF_SIZEDLGFULLSCREEN
static AygFullScreen ptrAygFullScreen
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static AygSHSipInfo ptrAygSHSipInfo
#define SIPF_ON
int qt_wince_get_build()
bool qt_wince_is_platform(const QString &platformString)
int qt_wince_GetDIBits(HDC, HBITMAP hSourceBitmap, uint, uint, LPVOID lpvBits, LPBITMAPINFO, uint)
#define SHFS_HIDETASKBAR
BOOL(* AygSHDoneButton)(HWND, DWORD)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int qt_wince_get_version()
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
BOOL(* AygFullScreen)(HWND, DWORD)
static void resolveAygLibs()
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
#define SHIDIF_CANCELBUTTON
static bool aygResolved