|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 |
|
42 #ifdef Q_WS_WINCE |
|
43 |
|
44 #include "qguifunctions_wince.h" |
|
45 |
|
46 QT_BEGIN_NAMESPACE |
|
47 |
|
48 const QString qt_reg_winclass(QWidget *w); // defined in qapplication_win.cpp |
|
49 extern "C" LRESULT CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM); |
|
50 |
|
51 //#define TABLET_DEBUG |
|
52 #define PACKETDATA (PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE \ |
|
53 | PK_ORIENTATION | PK_CURSOR | PK_Z) |
|
54 #define PACKETMODE 0 |
|
55 |
|
56 typedef HCTX (API *PtrWTOpen)(HWND, LPLOGCONTEXT, BOOL); |
|
57 typedef BOOL (API *PtrWTClose)(HCTX); |
|
58 typedef UINT (API *PtrWTInfo)(UINT, UINT, LPVOID); |
|
59 typedef BOOL (API *PtrWTEnable)(HCTX, BOOL); |
|
60 typedef BOOL (API *PtrWTOverlap)(HCTX, BOOL); |
|
61 typedef int (API *PtrWTPacketsGet)(HCTX, int, LPVOID); |
|
62 typedef BOOL (API *PtrWTGet)(HCTX, LPLOGCONTEXT); |
|
63 typedef int (API *PtrWTQueueSizeGet)(HCTX); |
|
64 typedef BOOL (API *PtrWTQueueSizeSet)(HCTX, int); |
|
65 |
|
66 static void qt_tablet_init_wce(); |
|
67 static void qt_tablet_cleanup_wce(); |
|
68 |
|
69 static void qt_tablet_init_wce() { |
|
70 static bool firstTime = true; |
|
71 if (!firstTime) |
|
72 return; |
|
73 firstTime = false; |
|
74 qt_tablet_widget = new QWidget(0); |
|
75 qt_tablet_widget->createWinId(); |
|
76 qt_tablet_widget->setObjectName(QLatin1String("Qt internal tablet widget")); |
|
77 LOGCONTEXT lcMine; |
|
78 qAddPostRoutine(qt_tablet_cleanup_wce); |
|
79 struct tagAXIS tpOri[3]; |
|
80 if (ptrWTInfo && ptrWTOpen && ptrWTQueueSizeGet && ptrWTQueueSizeSet) { |
|
81 // make sure we have WinTab |
|
82 if (!ptrWTInfo(0, 0, NULL)) { |
|
83 #ifdef TABLET_DEBUG |
|
84 qWarning("QWidget: Wintab services not available"); |
|
85 #endif |
|
86 return; |
|
87 } |
|
88 |
|
89 // some tablets don't support tilt, check if it is possible, |
|
90 qt_tablet_tilt_support = ptrWTInfo(WTI_DEVICES, DVC_ORIENTATION, &tpOri); |
|
91 if (qt_tablet_tilt_support) { |
|
92 // check for azimuth and altitude |
|
93 qt_tablet_tilt_support = tpOri[0].axResolution && tpOri[1].axResolution; |
|
94 } |
|
95 // build our context from the default context |
|
96 ptrWTInfo(WTI_DEFSYSCTX, 0, &lcMine); |
|
97 // Go for the raw coordinates, the tablet event will return good stuff |
|
98 lcMine.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES; |
|
99 lcMine.lcPktData = PACKETDATA; |
|
100 lcMine.lcPktMode = PACKETMODE; |
|
101 lcMine.lcMoveMask = PACKETDATA; |
|
102 lcMine.lcOutOrgX = 0; |
|
103 lcMine.lcOutExtX = lcMine.lcInExtX; |
|
104 lcMine.lcOutOrgY = 0; |
|
105 lcMine.lcOutExtY = -lcMine.lcInExtY; |
|
106 qt_tablet_context = ptrWTOpen(qt_tablet_widget->winId(), &lcMine, true); |
|
107 #ifdef TABLET_DEBUG |
|
108 qDebug("Tablet is %p", qt_tablet_context); |
|
109 #endif |
|
110 if (!qt_tablet_context) { |
|
111 #ifdef TABLET_DEBUG |
|
112 qWarning("QWidget: Failed to open the tablet"); |
|
113 #endif |
|
114 return; |
|
115 } |
|
116 // Set the size of the Packet Queue to the correct size... |
|
117 int currSize = ptrWTQueueSizeGet(qt_tablet_context); |
|
118 if (!ptrWTQueueSizeSet(qt_tablet_context, QT_TABLET_NPACKETQSIZE)) { |
|
119 // Ideally one might want to use a smaller |
|
120 // multiple, but for now, since we managed to destroy |
|
121 // the existing Q with the previous call, set it back |
|
122 // to the other size, which should work. If not, |
|
123 // there will be trouble. |
|
124 if (!ptrWTQueueSizeSet(qt_tablet_context, currSize)) { |
|
125 Q_ASSERT_X(0, "Qt::Internal", "There is no packet queue for" |
|
126 " the tablet. The tablet will not work"); |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 static void qt_tablet_cleanup_wce() { |
|
133 if (ptrWTClose) |
|
134 ptrWTClose(qt_tablet_context); |
|
135 delete qt_tablet_widget; |
|
136 qt_tablet_widget = 0; |
|
137 } |
|
138 |
|
139 |
|
140 // The internal qWinRequestConfig, defined in qapplication_win.cpp, stores move, |
|
141 // resize and setGeometry requests for a widget that is already |
|
142 // processing a config event. The purpose is to avoid recursion. |
|
143 // |
|
144 void qWinRequestConfig(WId, int, int, int, int, int); |
|
145 |
|
146 void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) { |
|
147 Q_Q(QWidget); |
|
148 static int sw = -1, sh = -1; |
|
149 |
|
150 Qt::WindowType type = q->windowType(); |
|
151 Qt::WindowFlags flags = data.window_flags; |
|
152 |
|
153 bool topLevel = (flags & Qt::Window); |
|
154 bool popup = (type == Qt::Popup); |
|
155 bool dialog = (type == Qt::Dialog |
|
156 || type == Qt::Sheet |
|
157 || (flags & Qt::MSWindowsFixedSizeDialogHint)); |
|
158 bool desktop = (type == Qt::Desktop); |
|
159 bool tool = (type == Qt::Tool || type == Qt::Drawer); |
|
160 |
|
161 HINSTANCE appinst = qWinAppInst(); |
|
162 HWND parentw, destroyw = 0; |
|
163 WId id; |
|
164 |
|
165 QString windowClassName = qt_reg_winclass(q); |
|
166 |
|
167 if (!window) // always initialize |
|
168 initializeWindow = true; |
|
169 |
|
170 if (popup) |
|
171 flags |= Qt::WindowStaysOnTopHint; // a popup stays on top |
|
172 |
|
173 if (flags & (Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowContextHelpButtonHint)) { |
|
174 flags |= Qt::WindowSystemMenuHint; |
|
175 flags |= Qt::WindowTitleHint; |
|
176 flags &= ~Qt::FramelessWindowHint; |
|
177 } |
|
178 |
|
179 if (sw < 0) { // get the (primary) screen size |
|
180 sw = GetSystemMetrics(SM_CXSCREEN); |
|
181 sh = GetSystemMetrics(SM_CYSCREEN); |
|
182 } |
|
183 |
|
184 if (desktop) { // desktop widget |
|
185 popup = false; // force this flags off |
|
186 data.crect.setRect(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); |
|
187 } |
|
188 |
|
189 parentw = q->parentWidget() ? q->parentWidget()->effectiveWinId() : 0; |
|
190 |
|
191 QString title; |
|
192 int style = WS_CHILD; |
|
193 int exsty = WS_EX_NOPARENTNOTIFY; |
|
194 |
|
195 if (topLevel) { |
|
196 if (!(flags & Qt::FramelessWindowHint) && !tool && !q->testAttribute(Qt::WA_DontShowOnScreen)) |
|
197 style = (WS_OVERLAPPED) | WS_SYSMENU; |
|
198 else |
|
199 style = WS_POPUP; |
|
200 if ((type == Qt::ToolTip) || (type == Qt::SplashScreen)) { |
|
201 style = WS_POPUP; |
|
202 exsty |= WS_EX_NOANIMATION; |
|
203 } else { |
|
204 if (flags & Qt::WindowTitleHint) |
|
205 style |= WS_CAPTION; |
|
206 if (flags & Qt::WindowSystemMenuHint) |
|
207 style |= WS_SYSMENU; |
|
208 if (flags & Qt::WindowContextHelpButtonHint) |
|
209 exsty |= WS_EX_CONTEXTHELP; |
|
210 #ifndef Q_WS_WINCE_WM |
|
211 if (flags & Qt::WindowMinimizeButtonHint) |
|
212 style |= WS_MINIMIZEBOX; |
|
213 if (shouldShowMaximizeButton()) |
|
214 style |= WS_MAXIMIZEBOX; |
|
215 #endif |
|
216 if (tool) |
|
217 exsty |= WS_EX_TOOLWINDOW; |
|
218 } |
|
219 } |
|
220 if (dialog) { |
|
221 style = WS_BORDER | WS_CAPTION; |
|
222 if (flags & Qt::WindowOkButtonHint) |
|
223 exsty |= WS_EX_CAPTIONOKBTN; |
|
224 if (flags & Qt::WindowCancelButtonHint || flags & Qt::WA_DeleteOnClose) |
|
225 style |= WS_SYSMENU; |
|
226 if (flags & Qt::WindowContextHelpButtonHint) |
|
227 exsty |= WS_EX_CONTEXTHELP; |
|
228 } |
|
229 if (popup) { |
|
230 style = WS_POPUP; |
|
231 exsty |= WS_EX_NOANIMATION; |
|
232 } |
|
233 |
|
234 if (flags & Qt::WindowTitleHint) { |
|
235 title = q->isWindow() ? qAppName() : q->objectName(); |
|
236 } |
|
237 |
|
238 // The Qt::WA_WState_Created flag is checked by translateConfigEvent() in |
|
239 // qapplication_win.cpp. We switch it off temporarily to avoid move |
|
240 // and resize events during creationt |
|
241 q->setAttribute(Qt::WA_WState_Created, false); |
|
242 |
|
243 if (window) { // override the old window |
|
244 if (destroyOldWindow) |
|
245 destroyw = data.winid; |
|
246 id = window; |
|
247 setWinId(window); |
|
248 LONG res = SetWindowLong(window, GWL_STYLE, style); |
|
249 if (!res) |
|
250 qErrnoWarning("QWidget::create: Failed to set window style"); |
|
251 |
|
252 res = SetWindowLong( window, GWL_WNDPROC, (LONG)QtWndProc ); |
|
253 |
|
254 if (!res) |
|
255 qErrnoWarning("QWidget::create: Failed to set window procedure"); |
|
256 } else if (desktop) { // desktop widget |
|
257 id = GetDesktopWindow(); |
|
258 if (!id) { //Create a dummy desktop |
|
259 RECT r; |
|
260 SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0); |
|
261 id = CreateWindow(reinterpret_cast<const wchar_t *>(windowClassName.utf16()), |
|
262 reinterpret_cast<const wchar_t *>(title.utf16()), style, |
|
263 r.left, r.top, r.right - r.left, r.bottom - r.top, |
|
264 0, 0, appinst, 0); |
|
265 } |
|
266 setWinId(id); |
|
267 } else if (topLevel) { // create top-level widget |
|
268 const bool wasMoved = q->testAttribute(Qt::WA_Moved); |
|
269 |
|
270 int x, y; |
|
271 if (qt_wince_is_mobile()) { |
|
272 x = wasMoved ? data.crect.left() : CW_USEDEFAULT; |
|
273 y = wasMoved ? data.crect.top() : CW_USEDEFAULT; |
|
274 } else { |
|
275 x = wasMoved ? data.crect.left() : 100; |
|
276 y = wasMoved ? data.crect.top() : 100; |
|
277 } |
|
278 |
|
279 int w = CW_USEDEFAULT; |
|
280 int h = CW_USEDEFAULT; |
|
281 |
|
282 // Adjust for framestrut when needed |
|
283 RECT rect = {0,0,0,0}; |
|
284 if (AdjustWindowRectEx(&rect, style, FALSE, exsty)) { |
|
285 QTLWExtra *td = maybeTopData(); |
|
286 if (wasMoved && (td && !td->posFromMove)) { |
|
287 x = data.crect.x() + rect.left; |
|
288 y = data.crect.y() + rect.top; |
|
289 } |
|
290 |
|
291 if (q->testAttribute(Qt::WA_Resized)) { |
|
292 w = data.crect.width() + (rect.right - rect.left); |
|
293 h = data.crect.height() + (rect.bottom - rect.top); |
|
294 } |
|
295 } |
|
296 |
|
297 id = CreateWindowEx(exsty, reinterpret_cast<const wchar_t *>(windowClassName.utf16()), |
|
298 reinterpret_cast<const wchar_t *>(title.utf16()), style, |
|
299 x, y, w, h, |
|
300 0, 0, appinst, 0); |
|
301 |
|
302 if (!id) |
|
303 qErrnoWarning("QWidget::create: Failed to create window"); |
|
304 setWinId(id); |
|
305 if ((flags & Qt::WindowStaysOnTopHint) || (type == Qt::ToolTip)) |
|
306 SetWindowPos(id, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
|
307 } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create child widget |
|
308 id = CreateWindowEx(exsty, (wchar_t*)windowClassName.utf16(), (wchar_t*)title.utf16(), style, |
|
309 data.crect.left(), data.crect.top(), data.crect.width(), data.crect.height(), |
|
310 parentw, NULL, appinst, NULL); |
|
311 if (!id) |
|
312 qErrnoWarning("QWidget::create: Failed to create window"); |
|
313 SetWindowPos(id, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
|
314 setWinId(id); |
|
315 } |
|
316 |
|
317 if (desktop) { |
|
318 q->setAttribute(Qt::WA_WState_Visible); |
|
319 } else if (topLevel && !q->testAttribute(Qt::WA_DontShowOnScreen)) { |
|
320 RECT cr; |
|
321 GetClientRect(id, &cr); |
|
322 // one cannot trust cr.left and cr.top, use a correction POINT instead |
|
323 POINT pt; |
|
324 pt.x = 0; |
|
325 pt.y = 0; |
|
326 if (!q->testAttribute(Qt::WA_DontShowOnScreen) || q->testAttribute(Qt::WA_Moved)) |
|
327 ClientToScreen(id, &pt); |
|
328 data.crect = QRect(QPoint(pt.x, pt.y), |
|
329 QPoint(pt.x + cr.right - 1, pt.y + cr.bottom - 1)); |
|
330 |
|
331 if (data.fstrut_dirty) { |
|
332 // be nice to activeqt |
|
333 updateFrameStrut(); |
|
334 } |
|
335 } |
|
336 |
|
337 q->setAttribute(Qt::WA_WState_Created); // accept move/resize events |
|
338 hd = 0; // no display context |
|
339 |
|
340 if (window) { // got window from outside |
|
341 if (IsWindowVisible(window)) |
|
342 q->setAttribute(Qt::WA_WState_Visible); |
|
343 else |
|
344 q->setAttribute(Qt::WA_WState_Visible, false); |
|
345 } |
|
346 |
|
347 if (extra && !extra->mask.isEmpty()) |
|
348 setMask_sys(extra->mask); |
|
349 |
|
350 #if defined(QT_NON_COMMERCIAL) |
|
351 QT_NC_WIDGET_CREATE |
|
352 #endif |
|
353 |
|
354 if (q->hasFocus() && q->testAttribute(Qt::WA_InputMethodEnabled)) |
|
355 q->inputContext()->setFocusWidget(q); |
|
356 |
|
357 if (destroyw) { |
|
358 DestroyWindow(destroyw); |
|
359 } |
|
360 |
|
361 if (q != qt_tablet_widget && QWidgetPrivate::mapper) |
|
362 qt_tablet_init_wce(); |
|
363 |
|
364 if (q->testAttribute(Qt::WA_DropSiteRegistered)) |
|
365 registerDropSite(true); |
|
366 |
|
367 if (maybeTopData() && maybeTopData()->opacity != 255) |
|
368 q->setWindowOpacity(maybeTopData()->opacity/255.); |
|
369 |
|
370 if (!topLevel && q->testAttribute(Qt::WA_NativeWindow) && q->testAttribute(Qt::WA_Mapped)) { |
|
371 Q_ASSERT(q->internalWinId()); |
|
372 ShowWindow(q->internalWinId(), SW_SHOW); |
|
373 } |
|
374 } |
|
375 |
|
376 /* |
|
377 \internal |
|
378 Platform-specific part of QWidget::show(). |
|
379 */ |
|
380 void QWidgetPrivate::show_sys() { |
|
381 Q_Q(QWidget); |
|
382 #if defined(QT_NON_COMMERCIAL) |
|
383 QT_NC_SHOW_WINDOW |
|
384 #endif |
|
385 if (q->testAttribute(Qt::WA_OutsideWSRange)) |
|
386 return; |
|
387 |
|
388 q->setAttribute(Qt::WA_Mapped); |
|
389 |
|
390 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
391 |
|
392 if (q->testAttribute(Qt::WA_DontShowOnScreen)) { |
|
393 invalidateBuffer(q->rect()); |
|
394 return; |
|
395 } |
|
396 |
|
397 |
|
398 int sm = SW_SHOW; |
|
399 bool fakedMaximize = false; |
|
400 if (q->isWindow()) { |
|
401 #ifndef Q_WS_WINCE_WM |
|
402 if (q->isMinimized()) { |
|
403 sm = SW_SHOWMINIMIZED; |
|
404 } else if (q->isMaximized()) { |
|
405 sm = SW_SHOWMAXIMIZED; |
|
406 // Windows will not behave correctly when we try to maximize a window which does not |
|
407 // have minimize nor maximize buttons in the window frame. Windows would then ignore |
|
408 // non-available geometry, and rather maximize the widget to the full screen, minus the |
|
409 // window frame (caption). So, we do a trick here, by adding a maximize button before |
|
410 // maximizing the widget, and then remove the maximize button afterwards. |
|
411 Qt::WindowFlags &flags = data.window_flags; |
|
412 if (flags & Qt::WindowTitleHint && |
|
413 !(flags & (Qt::WindowMinMaxButtonsHint | Qt::FramelessWindowHint))) { |
|
414 fakedMaximize = TRUE; |
|
415 int style = GetWindowLong(q->internalWinId(), GWL_STYLE); |
|
416 SetWindowLong(q->internalWinId(), GWL_STYLE, style | WS_MAXIMIZEBOX); |
|
417 } |
|
418 } else |
|
419 #else |
|
420 // Imitate minimizing on Windows mobile by hiding the widget. |
|
421 if (q->isMinimized()) |
|
422 sm = SW_HIDE; |
|
423 #endif |
|
424 if (q->isHidden()) { |
|
425 sm = SW_HIDE; |
|
426 } |
|
427 } |
|
428 if (q->testAttribute(Qt::WA_ShowWithoutActivating) |
|
429 || (q->windowType() == Qt::Popup) |
|
430 || (q->windowType() == Qt::ToolTip) |
|
431 || (q->windowType() == Qt::Tool)) { |
|
432 sm = SW_SHOWNOACTIVATE; |
|
433 } |
|
434 |
|
435 ShowWindow(q->internalWinId(), sm); |
|
436 |
|
437 if (q->isMaximized() && q->isWindow()) |
|
438 qt_wince_maximize(q); |
|
439 |
|
440 #ifndef Q_WS_WINCE_WM |
|
441 if (!qt_wince_is_mobile() && q->isFullScreen()) { |
|
442 HWND handle = FindWindow(L"HHTaskBar", L""); |
|
443 if (handle) { |
|
444 ShowWindow(handle, SW_HIDE); |
|
445 EnableWindow(handle, false); |
|
446 } |
|
447 } |
|
448 |
|
449 if (fakedMaximize) { |
|
450 int style = GetWindowLong(q->internalWinId(), GWL_STYLE); |
|
451 SetWindowLong(q->internalWinId(), GWL_STYLE, style & ~WS_MAXIMIZEBOX); |
|
452 SetWindowPos(q->internalWinId(), 0, 0, 0, 0, 0, |
|
453 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER |
|
454 | SWP_FRAMECHANGED); |
|
455 } |
|
456 #else |
|
457 Q_UNUSED(fakedMaximize); |
|
458 #endif |
|
459 |
|
460 if (q->isWindow() && sm == SW_SHOW) |
|
461 SetForegroundWindow(q->internalWinId()); |
|
462 |
|
463 invalidateBuffer(q->rect()); |
|
464 } |
|
465 |
|
466 void QWidget::setWindowState(Qt::WindowStates newstate) |
|
467 { |
|
468 Q_D(QWidget); |
|
469 Qt::WindowStates oldstate = windowState(); |
|
470 if (oldstate == newstate) |
|
471 return; |
|
472 |
|
473 int max = SW_SHOWNORMAL; |
|
474 int normal = SW_SHOWNOACTIVATE; |
|
475 |
|
476 if ((oldstate & Qt::WindowMinimized) && !(newstate & Qt::WindowMinimized)) |
|
477 newstate |= Qt::WindowActive; |
|
478 if (newstate & Qt::WindowActive) |
|
479 normal = SW_SHOWNORMAL; |
|
480 if (isWindow()) { |
|
481 createWinId(); |
|
482 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
483 // Ensure the initial size is valid, since we store it as normalGeometry below. |
|
484 if ((!testAttribute(Qt::WA_Resized) && !isVisible())) |
|
485 adjustSize(); |
|
486 if (!d->topData()->normalGeometry.isValid()) { |
|
487 if (newstate & Qt::WindowMaximized && !(oldstate & Qt::WindowFullScreen)) |
|
488 d->topData()->normalGeometry = geometry(); |
|
489 if (newstate & Qt::WindowMinimized && !(oldstate & Qt::WindowFullScreen)) |
|
490 d->topData()->normalGeometry = geometry(); |
|
491 } |
|
492 if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) { |
|
493 if (!(newstate & Qt::WindowMaximized)) { |
|
494 int style = GetWindowLong(internalWinId(), GWL_STYLE) | WS_BORDER | WS_POPUP | WS_CAPTION; |
|
495 SetWindowLong(internalWinId(), GWL_STYLE, style); |
|
496 SetWindowLong(internalWinId(), GWL_EXSTYLE, GetWindowLong (internalWinId(), GWL_EXSTYLE) & ~ WS_EX_NODRAG); |
|
497 } |
|
498 if (isVisible() && newstate & Qt::WindowMaximized) |
|
499 qt_wince_maximize(this); |
|
500 if (isVisible() && !(newstate & Qt::WindowMinimized)) { |
|
501 ShowWindow(internalWinId(), (newstate & Qt::WindowMaximized) ? max : normal); |
|
502 if (!(newstate & Qt::WindowFullScreen)) { |
|
503 QRect r = d->topData()->normalGeometry; |
|
504 if (!(newstate & Qt::WindowMaximized) && r.width() >= 0) { |
|
505 if (pos() != r.topLeft() || size() !=r.size()) { |
|
506 d->topData()->normalGeometry = QRect(0,0,-1,-1); |
|
507 setGeometry(r); |
|
508 } |
|
509 } |
|
510 } else { |
|
511 d->updateFrameStrut(); |
|
512 } |
|
513 } |
|
514 } |
|
515 if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) { |
|
516 if (newstate & Qt::WindowFullScreen) { |
|
517 if (d->topData()->normalGeometry.width() < 0 && !(oldstate & Qt::WindowMaximized)) |
|
518 d->topData()->normalGeometry = geometry(); |
|
519 d->topData()->savedFlags = (Qt::WindowFlags)GetWindowLong(internalWinId(), GWL_STYLE); |
|
520 UINT style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP; |
|
521 if (isVisible()) |
|
522 style |= WS_VISIBLE; |
|
523 SetWindowLong(internalWinId(), GWL_STYLE, style); |
|
524 QRect r = qApp->desktop()->screenGeometry(this); |
|
525 UINT swpf = SWP_FRAMECHANGED; |
|
526 if (newstate & Qt::WindowActive) |
|
527 swpf |= SWP_NOACTIVATE; |
|
528 qt_wince_full_screen(internalWinId(), true, swpf); |
|
529 d->updateFrameStrut(); |
|
530 } else { |
|
531 UINT style = d->topData()->savedFlags; |
|
532 if (isVisible()) |
|
533 style |= WS_VISIBLE; |
|
534 SetWindowLong(internalWinId(), GWL_STYLE, style); |
|
535 UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE; |
|
536 if (newstate & Qt::WindowActive) |
|
537 swpf |= SWP_NOACTIVATE; |
|
538 qt_wince_full_screen(internalWinId(), false, swpf); |
|
539 d->updateFrameStrut(); |
|
540 |
|
541 // preserve maximized state |
|
542 if (isVisible()) { |
|
543 ShowWindow(internalWinId(), (newstate & Qt::WindowMaximized) ? max : normal); |
|
544 if (newstate & Qt::WindowMaximized) |
|
545 qt_wince_maximize(this); |
|
546 } |
|
547 if (!(newstate & Qt::WindowMaximized)) { |
|
548 QRect r = d->topData()->normalGeometry; |
|
549 d->topData()->normalGeometry = QRect(0,0,-1,-1); |
|
550 if (r.isValid()) |
|
551 setGeometry(r); |
|
552 } |
|
553 } |
|
554 } |
|
555 if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) { |
|
556 if (newstate & Qt::WindowMinimized) |
|
557 qt_wince_minimize(internalWinId()); |
|
558 else if (newstate & Qt::WindowMaximized) { |
|
559 ShowWindow(internalWinId(), max); |
|
560 qt_wince_maximize(this); |
|
561 } else { |
|
562 ShowWindow(internalWinId(), normal); |
|
563 } |
|
564 } |
|
565 } |
|
566 data->window_state = newstate; |
|
567 QWindowStateChangeEvent e(oldstate); |
|
568 QApplication::sendEvent(this, &e); |
|
569 } |
|
570 |
|
571 void QWidgetPrivate::deleteSysExtra() |
|
572 { |
|
573 Q_Q(QWidget); |
|
574 if (!qt_wince_is_mobile() && q->isFullScreen()) { |
|
575 HWND handle = FindWindow(L"HHTaskBar", L""); |
|
576 if (handle) { |
|
577 ShowWindow(handle, SW_SHOWNORMAL); |
|
578 EnableWindow(handle, true); |
|
579 } |
|
580 } |
|
581 } |
|
582 |
|
583 void QWidgetPrivate::setWindowOpacity_sys(qreal level) { |
|
584 Q_UNUSED(level); |
|
585 return; |
|
586 } |
|
587 |
|
588 // The procedure does nothing, but is required for mousegrabbing to work |
|
589 LRESULT CALLBACK qJournalRecordProc(int nCode, WPARAM wParam, LPARAM lParam) { |
|
590 Q_UNUSED(nCode); |
|
591 Q_UNUSED(wParam); |
|
592 Q_UNUSED(lParam); |
|
593 return 0; |
|
594 } |
|
595 |
|
596 void QWidget::grabMouse() { |
|
597 if (!qt_nograb()) { |
|
598 if (mouseGrb) |
|
599 mouseGrb->releaseMouse(); |
|
600 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
601 SetCapture(internalWinId()); |
|
602 mouseGrb = this; |
|
603 } |
|
604 } |
|
605 |
|
606 #ifndef QT_NO_CURSOR |
|
607 void QWidget::grabMouse(const QCursor &cursor) { |
|
608 if (!qt_nograb()) { |
|
609 if (mouseGrb) |
|
610 mouseGrb->releaseMouse(); |
|
611 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
612 SetCapture(internalWinId()); |
|
613 mouseGrbCur = new QCursor(cursor); |
|
614 SetCursor(mouseGrbCur->handle()); |
|
615 mouseGrb = this; |
|
616 } |
|
617 } |
|
618 #endif |
|
619 |
|
620 void QWidget::releaseMouse() { |
|
621 if (!qt_nograb() && mouseGrb == this) { |
|
622 ReleaseCapture(); |
|
623 if (journalRec) { |
|
624 journalRec = 0; |
|
625 } |
|
626 if (mouseGrbCur) { |
|
627 delete mouseGrbCur; |
|
628 mouseGrbCur = 0; |
|
629 } |
|
630 mouseGrb = 0; |
|
631 } |
|
632 } |
|
633 |
|
634 void QWidget::show() |
|
635 { |
|
636 Qt::WindowFlags flags = windowFlags() & 0xff; |
|
637 int threshold = qApp->autoMaximizeThreshold(); |
|
638 if ((threshold < 0) || (windowState() & Qt::WindowFullScreen) || (windowState() & Qt::WindowMaximized)) { |
|
639 setVisible(true); |
|
640 return; |
|
641 } |
|
642 int height = sizeHint().height(); |
|
643 int screenHeight = (qreal(threshold) / 100.0f * qApp->desktop()->screenGeometry(this).height()); |
|
644 bool maximize = height > screenHeight; |
|
645 if (!maximize) { |
|
646 // If we do not maximize yet we check the widget and its child widgets whether they are |
|
647 //vertically expanding. If one of the widgets is expanding we maximize. |
|
648 QList<QWidget *> list = findChildren<QWidget *>(); |
|
649 bool expandingChild = sizePolicy().verticalPolicy () == QSizePolicy::Expanding; |
|
650 for (int i = 0; (i < list.size()) && !expandingChild; ++i) { |
|
651 expandingChild = list.at(i)->sizePolicy().verticalPolicy () == QSizePolicy::Expanding; |
|
652 } |
|
653 maximize = expandingChild; |
|
654 } |
|
655 if ((minimumSizeHint().height() > qApp->desktop()->screenGeometry(this).height()) || (minimumSizeHint().width() > qApp->desktop()->screenGeometry(this).width())) |
|
656 maximize = false; |
|
657 |
|
658 if ((flags == Qt::Window || flags == Qt::Dialog) && maximize) { |
|
659 setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) |
|
660 | Qt::WindowMaximized); |
|
661 setVisible(true); |
|
662 } |
|
663 else { |
|
664 setVisible(true); |
|
665 } |
|
666 } |
|
667 |
|
668 QT_END_NAMESPACE |
|
669 |
|
670 #endif // Q_WS_WINCE |