Qt 4.8
qwidget_win.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 
42 #include "qapplication.h"
43 #include "qapplication_p.h"
44 #include "qbitmap.h"
45 #include "qcursor.h"
46 #include "qdesktopwidget.h"
47 #include "qevent.h"
48 #include "qimage.h"
49 #include "qlayout.h"
50 #include "qpainter.h"
51 #include "qstack.h"
52 #include "qthread.h"
53 #include "qt_windows.h"
54 #include "qwidget.h"
55 #include "qwidget_p.h"
56 #include "private/qbackingstore_p.h"
57 #include "private/qwindowsurface_raster_p.h"
58 
59 #include "qscrollbar.h"
60 #include "qabstractscrollarea.h"
61 #include <private/qabstractscrollarea_p.h>
62 
63 #include <qdebug.h>
64 
65 #include <private/qapplication_p.h>
66 #include <private/qwininputcontext_p.h>
67 #include <private/qpaintengine_raster_p.h>
68 #include <private/qsystemlibrary_p.h>
69 
70 #if defined(Q_WS_WINCE)
71 #include "qguifunctions_wince.h"
73 extern void qt_wince_maximize(QWidget *widget); //defined in qguifunctions_wince.cpp
74 extern void qt_wince_unmaximize(QWidget *widget); //defined in qguifunctions_wince.cpp
75 extern void qt_wince_minimize(HWND hwnd); //defined in qguifunctions_wince.cpp
76 extern void qt_wince_full_screen(HWND hwnd, bool fullScreen, UINT swpf); //defined in qguifunctions_wince.cpp
77 extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
78 #endif
79 
80 typedef BOOL (WINAPI *PtrSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
82 
83 #ifndef QT_NO_DIRECTDRAW
84 #include <ddraw.h>
85 #include <private/qimage_p.h>
86 static IDirectDraw *qt_ddraw_object;
87 static IDirectDrawSurface *qt_ddraw_primary;
88 #endif
89 
90 
91 
92 #if defined(QT_NON_COMMERCIAL)
93 #include "qnc_win.h"
94 #endif
95 
96 #if !defined(WS_EX_TOOLWINDOW)
97 #define WS_EX_TOOLWINDOW 0x00000080
98 #endif
99 
100 #if !defined(GWLP_WNDPROC)
101 #define GWLP_WNDPROC GWL_WNDPROC
102 #endif
103 
104 //#define TABLET_DEBUG
105 #define PACKETDATA (PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE \
106  | PK_ORIENTATION | PK_CURSOR | PK_Z)
107 #define PACKETMODE 0
108 #include <wintab.h>
109 #include <pktdef.h>
110 
112 
113 typedef HCTX (API *PtrWTOpen)(HWND, LPLOGCONTEXT, BOOL);
114 typedef BOOL (API *PtrWTClose)(HCTX);
115 typedef UINT (API *PtrWTInfo)(UINT, UINT, LPVOID);
116 typedef BOOL (API *PtrWTEnable)(HCTX, BOOL);
117 typedef BOOL (API *PtrWTOverlap)(HCTX, BOOL);
118 typedef int (API *PtrWTPacketsGet)(HCTX, int, LPVOID);
119 typedef BOOL (API *PtrWTGet)(HCTX, LPLOGCONTEXT);
120 typedef int (API *PtrWTQueueSizeGet)(HCTX);
121 typedef BOOL (API *PtrWTQueueSizeSet)(HCTX, int);
122 
123 static PtrWTOpen ptrWTOpen = 0;
125 static PtrWTInfo ptrWTInfo = 0;
128 #ifndef QT_NO_TABLETEVENT
129 static void init_wintab_functions();
130 static void qt_tablet_init();
131 static void qt_tablet_cleanup();
132 #endif // QT_NO_TABLETEVENT
133 extern HCTX qt_tablet_context;
134 extern bool qt_tablet_tilt_support;
135 
138 {
139  return qt_tablet_widget;
140 }
141 
142 extern bool qt_is_gui_used;
143 
144 #ifndef QT_NO_TABLETEVENT
146 {
147 #if defined(Q_OS_WINCE)
148  return;
149 #else
150  if (!qt_is_gui_used)
151  return;
152  QSystemLibrary library(QLatin1String("wintab32"));
153  ptrWTOpen = (PtrWTOpen)library.resolve("WTOpenW");
154  ptrWTInfo = (PtrWTInfo)library.resolve("WTInfoW");
155  ptrWTClose = (PtrWTClose)library.resolve("WTClose");
156  ptrWTQueueSizeGet = (PtrWTQueueSizeGet)library.resolve("WTQueueSizeGet");
157  ptrWTQueueSizeSet = (PtrWTQueueSizeSet)library.resolve("WTQueueSizeSet");
158 #endif // Q_OS_WINCE
159 }
160 
161 static void qt_tablet_init()
162 {
163  static bool firstTime = true;
164  if (!firstTime)
165  return;
166  firstTime = false;
167  qt_tablet_widget = new QWidget(0);
168  qt_tablet_widget->createWinId();
169  qt_tablet_widget->setObjectName(QLatin1String("Qt internal tablet widget"));
170  // We don't need this internal widget to appear in QApplication::topLevelWidgets()
172  QWidgetPrivate::allWidgets->remove(qt_tablet_widget);
173  LOGCONTEXT lcMine;
175  struct tagAXIS tpOri[3];
178  // make sure we have WinTab
179  if (!ptrWTInfo(0, 0, NULL)) {
180 #ifdef TABLET_DEBUG
181  qWarning("QWidget: Wintab services not available");
182 #endif
183  return;
184  }
185 
186  // some tablets don't support tilt, check if it is possible,
187  qt_tablet_tilt_support = ptrWTInfo(WTI_DEVICES, DVC_ORIENTATION, &tpOri);
189  // check for azimuth and altitude
190  qt_tablet_tilt_support = tpOri[0].axResolution && tpOri[1].axResolution;
191  }
192  // build our context from the default context
193  ptrWTInfo(WTI_DEFSYSCTX, 0, &lcMine);
194  // Go for the raw coordinates, the tablet event will return good stuff
195  lcMine.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES;
196  lcMine.lcPktData = PACKETDATA;
197  lcMine.lcPktMode = PACKETMODE;
198  lcMine.lcMoveMask = PACKETDATA;
199  lcMine.lcOutOrgX = 0;
200  lcMine.lcOutExtX = lcMine.lcInExtX;
201  lcMine.lcOutOrgY = 0;
202  lcMine.lcOutExtY = -lcMine.lcInExtY;
203  qt_tablet_context = ptrWTOpen(qt_tablet_widget->winId(), &lcMine, true);
204 #ifdef TABLET_DEBUG
205  qDebug("Tablet is %p", qt_tablet_context);
206 #endif
207  if (!qt_tablet_context) {
208 #ifdef TABLET_DEBUG
209  qWarning("QWidget: Failed to open the tablet");
210 #endif
211  return;
212  }
213  // Set the size of the Packet Queue to the correct size...
214  int currSize = ptrWTQueueSizeGet(qt_tablet_context);
216  // Ideally one might want to use a smaller
217  // multiple, but for now, since we managed to destroy
218  // the existing Q with the previous call, set it back
219  // to the other size, which should work. If not,
220  // there will be trouble.
221  if (!ptrWTQueueSizeSet(qt_tablet_context, currSize)) {
222  Q_ASSERT_X(0, "Qt::Internal", "There is no packet queue for"
223  " the tablet. The tablet will not work");
224  }
225  }
226  }
227 }
228 
229 static void qt_tablet_cleanup()
230 {
231  if (ptrWTClose)
233  delete qt_tablet_widget;
234  qt_tablet_widget = 0;
235 }
236 #endif // QT_NO_TABLETEVENT
237 
238 const QString qt_reg_winclass(QWidget *w); // defined in qapplication_win.cpp
239 
240 #ifndef QT_NO_DRAGANDDROP
241 void qt_olednd_unregister(QWidget* widget, QOleDropTarget *dst); // dnd_win
243 #endif
244 
245 extern bool qt_nograb();
246 extern HRGN qt_win_bitmapToRegion(const QBitmap& bitmap);
247 
248 static QWidget *mouseGrb = 0;
249 static QCursor *mouseGrbCur = 0;
250 static QWidget *keyboardGrb = 0;
251 static HHOOK journalRec = 0;
252 
253 extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM);
254 
255 #define XCOORD_MAX 16383
256 #define WRECT_MAX 16383
257 
258 /*****************************************************************************
259  QWidget member functions
260  *****************************************************************************/
261 
262 #ifndef Q_WS_WINCE
263 void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
264 {
265  Q_Q(QWidget);
266  static int sw = -1, sh = -1;
267 
268  Qt::WindowType type = q->windowType();
269  Qt::WindowFlags flags = data.window_flags;
270 
271  bool topLevel = (flags & Qt::Window);
272  bool popup = (type == Qt::Popup);
273  bool dialog = (type == Qt::Dialog
274  || type == Qt::Sheet
275  || (flags & Qt::MSWindowsFixedSizeDialogHint));
276  bool desktop = (type == Qt::Desktop);
277  bool tool = (type == Qt::Tool || type == Qt::Drawer);
278 
279  HINSTANCE appinst = qWinAppInst();
280  HWND parentw, destroyw = 0;
281  WId id = 0;
282 
283  QString windowClassName = qt_reg_winclass(q);
284 
285  if (!window) // always initialize
286  initializeWindow = true;
287 
288  if (popup)
289  flags |= Qt::WindowStaysOnTopHint; // a popup stays on top
290 
291  if (sw < 0) { // get the (primary) screen size
292  sw = GetSystemMetrics(SM_CXSCREEN);
293  sh = GetSystemMetrics(SM_CYSCREEN);
294  }
295 
296  if (desktop && !q->testAttribute(Qt::WA_DontShowOnScreen)) { // desktop widget
297  popup = false; // force this flags off
298  data.crect.setRect(GetSystemMetrics(76 /* SM_XVIRTUALSCREEN */), GetSystemMetrics(77 /* SM_YVIRTUALSCREEN */),
299  GetSystemMetrics(78 /* SM_CXVIRTUALSCREEN */), GetSystemMetrics(79 /* SM_CYVIRTUALSCREEN */));
300  }
301 
302  parentw = q->parentWidget() ? q->parentWidget()->effectiveWinId() : 0;
303 
304  QString title;
305  int style = WS_CHILD;
306  int exsty = 0;
307 
308  if (window) {
309  style = GetWindowLong(window, GWL_STYLE);
310  if (!style)
311  qErrnoWarning("QWidget::create: GetWindowLong failed");
312  topLevel = false; // #### needed for some IE plugins??
313  } else if (popup || (type == Qt::ToolTip) || (type == Qt::SplashScreen)) {
314  style = WS_POPUP;
315  } else if (topLevel && !desktop) {
316  if (flags & Qt::FramelessWindowHint)
317  style = WS_POPUP; // no border
318  else if (flags & Qt::WindowTitleHint)
319  style = WS_OVERLAPPED;
320  else
321  style = 0;
322  }
323  if (!desktop) {
324  // if (!testAttribute(Qt::WA_PaintUnclipped))
325  // ### Commented out for now as it causes some problems, but
326  // this should be correct anyway, so dig some more into this
327 #ifndef Q_FLATTEN_EXPOSE
328  style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
329 #endif
330  if (topLevel) {
331  if ((type == Qt::Window || dialog || tool)) {
332  if (!(flags & Qt::FramelessWindowHint)) {
333  style |= WS_POPUP;
334  if (!(flags & Qt::MSWindowsFixedSizeDialogHint))
335  style |= WS_THICKFRAME;
336  else
337  style |= WS_DLGFRAME;
338  }
339  if (flags & Qt::WindowTitleHint)
340  style |= WS_CAPTION;
341  if (flags & Qt::WindowSystemMenuHint)
342  style |= WS_SYSMENU;
343  if (flags & Qt::WindowMinimizeButtonHint)
344  style |= WS_MINIMIZEBOX;
345  if (shouldShowMaximizeButton())
346  style |= WS_MAXIMIZEBOX;
347  if (tool)
348  exsty |= WS_EX_TOOLWINDOW;
350  exsty |= WS_EX_CONTEXTHELP;
351  } else {
352  exsty |= WS_EX_TOOLWINDOW;
353  }
354  }
355  }
356 
357  if (flags & Qt::WindowTitleHint) {
358  title = q->isWindow() ? qAppName() : q->objectName();
359  }
360 
361  // The Qt::WA_WState_Created flag is checked by translateConfigEvent() in
362  // qapplication_win.cpp. We switch it off temporarily to avoid move
363  // and resize events during creationt
364  q->setAttribute(Qt::WA_WState_Created, false);
365 
366  if (window) { // override the old window
367  if (destroyOldWindow)
368  destroyw = data.winid;
369  id = window;
370  setWinId(window);
371  LONG res = SetWindowLong(window, GWL_STYLE, style);
372  if (!res)
373  qErrnoWarning("QWidget::create: Failed to set window style");
374 #ifdef _WIN64
375  res = SetWindowLongPtr( window, GWLP_WNDPROC, (LONG_PTR)QtWndProc );
376 #else
377  res = SetWindowLong( window, GWL_WNDPROC, (LONG)QtWndProc );
378 #endif
379  if (!res)
380  qErrnoWarning("QWidget::create: Failed to set window procedure");
381  } else if (desktop) { // desktop widget
382  id = GetDesktopWindow();
383 // QWidget *otherDesktop = QWidget::find(id); // is there another desktop?
384 // if (otherDesktop && otherDesktop->testWFlags(Qt::WPaintDesktop)) {
385 // otherDesktop->d_func()->setWinId(0); // remove id from widget mapper
386 // d->setWinId(id); // make sure otherDesktop is
387 // otherDesktop->d_func()->setWinId(id); // found first
388 // } else {
389  setWinId(id);
390 // }
391  } else if (topLevel) { // create top-level widget
392  if (popup)
393  parentw = 0;
394 
395  const bool wasMoved = q->testAttribute(Qt::WA_Moved);
396  int x = wasMoved ? data.crect.left() : CW_USEDEFAULT;
397  int y = wasMoved ? data.crect.top() : CW_USEDEFAULT;
398  int w = CW_USEDEFAULT;
399  int h = CW_USEDEFAULT;
400 
401  // Adjust for framestrut when needed
402  RECT rect = {0,0,0,0};
403  bool isVisibleOnScreen = !q->testAttribute(Qt::WA_DontShowOnScreen);
404  if (isVisibleOnScreen && AdjustWindowRectEx(&rect, style & ~WS_OVERLAPPED, FALSE, exsty)) {
405  QTLWExtra *td = maybeTopData();
406  if (wasMoved && (td && !td->posFromMove)) {
407  x = data.crect.x() + rect.left;
408  y = data.crect.y() + rect.top;
409  }
410 
411  if (q->testAttribute(Qt::WA_Resized)) {
412  w = data.crect.width() + (rect.right - rect.left);
413  h = data.crect.height() + (rect.bottom - rect.top);
414  }
415  }
416  //update position & initial size of POPUP window
417  if (isVisibleOnScreen && topLevel && initializeWindow && (style & WS_POPUP)) {
418  if (!q->testAttribute(Qt::WA_Resized)) {
419  w = sw/2;
420  h = 4*sh/10;
421  if (extra) {
422  int dx = rect.right - rect.left;
423  int dy = rect.bottom - rect.top;
424  w = qMin(w, extra->maxw + dx);
425  h = qMin(h, extra->maxh + dy);
426  w = qMax(w, extra->minw + dx);
427  h = qMax(h, extra->minh + dy);
428  }
429  }
430  if (!wasMoved) {
431  x = qMax(sw/2 - w/2, 0);
432  y = qMax(sh/2 - h/2, 0);
433  }
434  }
435 
436  id = CreateWindowEx(exsty, reinterpret_cast<const wchar_t *>(windowClassName.utf16()),
437  reinterpret_cast<const wchar_t *>(title.utf16()), style,
438  x, y, w, h,
439  parentw, NULL, appinst, NULL);
440  if (!id)
441  qErrnoWarning("QWidget::create: Failed to create window");
442  setWinId(id);
443  if ((flags & Qt::WindowStaysOnTopHint) || (type == Qt::ToolTip)) {
444  SetWindowPos(id, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
445  if (flags & Qt::WindowStaysOnBottomHint)
446  qWarning() << "QWidget: Incompatible window flags: the window can't be on top and on bottom at the same time";
447  } else if (flags & Qt::WindowStaysOnBottomHint)
448  SetWindowPos(id, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
449  winUpdateIsOpaque();
450  } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create child widget
451  id = CreateWindowEx(exsty, reinterpret_cast<const wchar_t *>(windowClassName.utf16()),
452  reinterpret_cast<const wchar_t *>(title.utf16()), style,
454  parentw, NULL, appinst, NULL);
455  if (!id)
456  qErrnoWarning("QWidget::create: Failed to create window");
457  SetWindowPos(id, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
458  setWinId(id);
459  }
460 
461  if (desktop) {
462  q->setAttribute(Qt::WA_WState_Visible);
463  } else if (topLevel && !q->testAttribute(Qt::WA_DontShowOnScreen)) {
464  RECT cr;
465  GetClientRect(id, &cr);
466  // one cannot trust cr.left and cr.top, use a correction POINT instead
467  POINT pt;
468  pt.x = 0;
469  pt.y = 0;
470  ClientToScreen(id, &pt);
471 
472  if (data.crect.width() == 0 || data.crect.height() == 0) {
473  data.crect = QRect(pt.x, pt.y, data.crect.width(), data.crect.height());
474  } else {
475  data.crect = QRect(QPoint(pt.x, pt.y),
476  QPoint(pt.x + cr.right - 1, pt.y + cr.bottom - 1));
477  }
478 
479  if (data.fstrut_dirty) {
480  // be nice to activeqt
482  }
483  }
484 
485  if (topLevel) {
487  && data.window_flags & Qt::WindowTitleHint) {
488  HMENU systemMenu = GetSystemMenu((HWND)q->internalWinId(), FALSE);
490  EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
491  else
492  EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
493  }
494  }
495 
496  q->setAttribute(Qt::WA_WState_Created); // accept move/resize events
497  hd = 0; // no display context
498 
499  if (q->testAttribute(Qt::WA_AcceptTouchEvents))
500  registerTouchWindow();
501 
502  if (window) { // got window from outside
503  if (IsWindowVisible(window))
504  q->setAttribute(Qt::WA_WState_Visible);
505  else
506  q->setAttribute(Qt::WA_WState_Visible, false);
507  }
508 
509  if (extra && !extra->mask.isEmpty())
511 
512 #if defined(QT_NON_COMMERCIAL)
513  QT_NC_WIDGET_CREATE
514 #endif
515 
516 #ifndef QT_NO_IM
517  if (q->hasFocus() && q->testAttribute(Qt::WA_InputMethodEnabled))
518  q->inputContext()->setFocusWidget(q);
519 #endif
520 
521  if (destroyw) {
522  DestroyWindow(destroyw);
523  }
524 
525 #ifndef QT_NO_TABLETEVENT
526  if (q != qt_tablet_widget && QWidgetPrivate::mapper)
527  qt_tablet_init();
528 #endif // QT_NO_TABLETEVENT
529 
530  if (q->testAttribute(Qt::WA_DropSiteRegistered))
531  registerDropSite(true);
532 
533  if (maybeTopData() && maybeTopData()->opacity != 255)
534  q->setWindowOpacity(maybeTopData()->opacity/255.);
535 
536  if (topLevel && (data.crect.width() == 0 || data.crect.height() == 0)) {
537  q->setAttribute(Qt::WA_OutsideWSRange, true);
538  }
539 
540  if (!topLevel && q->testAttribute(Qt::WA_NativeWindow) && q->testAttribute(Qt::WA_Mapped)) {
541  Q_ASSERT(q->internalWinId());
542  ShowWindow(q->internalWinId(), SW_SHOW);
543  }
544 }
545 
546 #endif //Q_WS_WINCE
547 
548 
549 void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
550 {
551  Q_D(QWidget);
552  d->aboutToDestroy();
553  if (!isWindow() && parentWidget())
554  parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
555  d->deactivateWidgetCleanup();
556  if (testAttribute(Qt::WA_WState_Created)) {
557  setAttribute(Qt::WA_WState_Created, false);
558  for(int i = 0; i < d->children.size(); ++i) { // destroy all widget children
559  register QObject *obj = d->children.at(i);
560  if (obj->isWidgetType())
561  ((QWidget*)obj)->destroy(destroySubWindows,
562  destroySubWindows);
563  }
564  if (mouseGrb == this)
565  releaseMouse();
566  if (keyboardGrb == this)
567  releaseKeyboard();
568  if (testAttribute(Qt::WA_ShowModal)) // just be sure we leave modal
570  else if ((windowType() == Qt::Popup))
571  qApp->d_func()->closePopup(this);
572  if (destroyWindow && !(windowType() == Qt::Desktop) && internalWinId()) {
573  DestroyWindow(internalWinId());
574  }
575 #ifdef Q_WS_WINCE
576  if (destroyWindow && (windowType() == Qt::Desktop) && !GetDesktopWindow()) {
577  DestroyWindow(internalWinId());
578  }
579 
580 #endif
581  QT_TRY {
582  d->setWinId(0);
583  } QT_CATCH (const std::bad_alloc &) {
584  // swallow - destructors must not throw
585  }
586  }
587 }
588 
589 void QWidgetPrivate::reparentChildren()
590 {
591  Q_Q(QWidget);
592  QObjectList chlist = q->children();
593  for(int i = 0; i < chlist.size(); ++i) { // reparent children
594  QObject *obj = chlist.at(i);
595  if (obj->isWidgetType()) {
596  QWidget *w = (QWidget *)obj;
597  if ((w->windowType() == Qt::Popup)) {
598  ;
599  } else if (w->isWindow()) {
600  bool showIt = w->isVisible();
601  QPoint old_pos = w->pos();
602  w->setParent(q, w->windowFlags());
603  w->move(old_pos);
604  if (showIt)
605  w->show();
606  } else {
607  w->d_func()->invalidateBuffer(w->rect());
608  SetParent(w->effectiveWinId(), q->effectiveWinId());
609  w->d_func()->reparentChildren();
610  }
611  }
612  }
613 }
614 
615 void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
616 {
617  Q_Q(QWidget);
618  bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
619  if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
620  q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
621 
622  WId old_winid = data.winid;
623  // hide and reparent our own window away. Otherwise we might get
624  // destroyed when emitting the child remove event below. See QWorkspace.
625  if (q->isVisible() && data.winid) {
626  ShowWindow(data.winid, SW_HIDE);
627  SetParent(data.winid, 0);
628  }
629  bool dropSiteWasRegistered = false;
630  if (q->testAttribute(Qt::WA_DropSiteRegistered)) {
631  dropSiteWasRegistered = true;
632  q->setAttribute(Qt::WA_DropSiteRegistered, false); // ole dnd unregister (we will register again below)
633  }
634  QList<QWidget *> registeredDropChildren;
635  if (QWidget *nativeParent = q->internalWinId() ? q : q->nativeParentWidget()) {
636  if (const QWExtra *extra = nativeParent->d_func()->extra) {
637  foreach (QWidget *w, extra->oleDropWidgets) {
638  if (w && q->isAncestorOf(w)) {
639  registeredDropChildren.push_back(w);
641  }
642  }
643  }
644  }
645  if ((q->windowType() == Qt::Desktop))
646  old_winid = 0;
647  setWinId(0);
648 
650  bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
651 
652  data.window_flags = f;
653  data.fstrut_dirty = true;
654  q->setAttribute(Qt::WA_WState_Created, false);
655  q->setAttribute(Qt::WA_WState_Visible, false);
656  q->setAttribute(Qt::WA_WState_Hidden, false);
658  // keep compatibility with previous versions, we need to preserve the created state
659  // (but we recreate the winId for the widget being reparented, again for compatibility)
660  if (wasCreated || (!q->isWindow() && parent->testAttribute(Qt::WA_WState_Created)))
661  createWinId();
662  if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)
663  q->setAttribute(Qt::WA_WState_Hidden);
664  q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
665 
666  if (wasCreated) {
667  reparentChildren();
668  }
669 
670  if (extra && !extra->mask.isEmpty()) {
671  QRegion r = extra->mask;
672  extra->mask = QRegion();
673  q->setMask(r);
674  }
675  if (extra && extra->topextra && !extra->topextra->caption.isEmpty()) {
676  setWindowIcon_sys(true);
678  }
679  if (old_winid) {
680 #ifndef QT_NO_DRAGANDDROP
681  if (extra && extra->dropTarget) {
682  // NOTE: It is possible that the current widget has already registered an ole drop target
683  // without Qt::WA_DropSiteRegistered being set. In this case we have to call RevokeDragDrop()
684  // to drop the reference count of the ole drop target object held by windows to prevent leak
685  // and re-register the old drop target object to the new window handle if possible
686  RevokeDragDrop(old_winid);
687  if (q->internalWinId())
688  RegisterDragDrop(q->internalWinId(), extra->dropTarget);
689  }
690 #endif // !QT_NO_DRAGANDDROP
691  DestroyWindow(old_winid);
692  }
693 
694  if (q->testAttribute(Qt::WA_AcceptDrops) || dropSiteWasRegistered
695  || (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)))
696  q->setAttribute(Qt::WA_DropSiteRegistered, true);
697  foreach (QWidget *w, registeredDropChildren)
699 
700 #ifdef Q_WS_WINCE
701  // Show borderless toplevel windows in tasklist & NavBar
702  if (!parent) {
703  QString txt = q->windowTitle().isEmpty()?qAppName():q->windowTitle();
704  SetWindowText(q->internalWinId(), (wchar_t*)txt.utf16());
705  }
706 #endif
707  invalidateBuffer(q->rect());
708 }
709 
710 
711 QPoint QWidget::mapToGlobal(const QPoint &pos) const
712 {
713  Q_D(const QWidget);
714  QWidget *parentWindow = window();
715  QWExtra *extra = parentWindow->d_func()->extra;
716  if (!isVisible() || parentWindow->isMinimized() || !testAttribute(Qt::WA_WState_Created) || !internalWinId()
717  || (extra
718 #ifndef QT_NO_GRAPHICSVIEW
719  && extra->proxyWidget
720 #endif //QT_NO_GRAPHICSVIEW
721  )) {
722  if (extra && extra->topextra && extra->topextra->embedded) {
723  QPoint pt = mapTo(parentWindow, pos);
724  POINT p = {pt.x(), pt.y()};
725  ClientToScreen(parentWindow->effectiveWinId(), &p);
726  return QPoint(p.x, p.y);
727  } else {
728  QPoint toGlobal = mapTo(parentWindow, pos) + parentWindow->pos();
729  // Adjust for window decorations
730  toGlobal += parentWindow->geometry().topLeft() - parentWindow->frameGeometry().topLeft();
731  return toGlobal;
732  }
733  }
734  POINT p;
735  QPoint tmp = d->mapToWS(pos);
736  p.x = tmp.x();
737  p.y = tmp.y();
738  ClientToScreen(internalWinId(), &p);
739  return QPoint(p.x, p.y);
740 }
741 
742 QPoint QWidget::mapFromGlobal(const QPoint &pos) const
743 {
744  Q_D(const QWidget);
745  QWidget *parentWindow = window();
746  QWExtra *extra = parentWindow->d_func()->extra;
747  if (!isVisible() || parentWindow->isMinimized() || !testAttribute(Qt::WA_WState_Created) || !internalWinId()
748  || (extra
749 #ifndef QT_NO_GRAPHICSVIEW
750  && extra->proxyWidget
751 #endif //QT_NO_GRAPHICSVIEW
752  )) {
753  if (extra && extra->topextra && extra->topextra->embedded) {
754  POINT p = {pos.x(), pos.y()};
755  ScreenToClient(parentWindow->effectiveWinId(), &p);
756  return mapFrom(parentWindow, QPoint(p.x, p.y));
757  } else {
758  QPoint fromGlobal = mapFrom(parentWindow, pos - parentWindow->pos());
759  // Adjust for window decorations
760  fromGlobal -= parentWindow->geometry().topLeft() - parentWindow->frameGeometry().topLeft();
761  return fromGlobal;
762  }
763  }
764  POINT p;
765  p.x = pos.x();
766  p.y = pos.y();
767  ScreenToClient(internalWinId(), &p);
768  return d->mapFromWS(QPoint(p.x, p.y));
769 }
770 
772 
773 #ifndef QT_NO_CURSOR
774 void QWidgetPrivate::setCursor_sys(const QCursor &cursor)
775 {
776  Q_UNUSED(cursor);
777  Q_Q(QWidget);
778  qt_win_set_cursor(q, false);
779 }
780 
782 {
783  Q_Q(QWidget);
784  qt_win_set_cursor(q, false);
785 }
786 #endif
787 
788 void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
789 {
790  Q_Q(QWidget);
791  if (!q->isWindow())
792  return;
793 
794  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
795  SetWindowText(q->internalWinId(), (wchar_t*)caption.utf16());
796 }
797 
798 HICON qt_createIcon(QIcon icon, int xSize, int ySize, QPixmap **cache)
799 {
800  HICON result = 0;
801  if (!icon.isNull()) { // valid icon
802  QSize size = icon.actualSize(QSize(xSize, ySize));
803  QPixmap pm = icon.pixmap(size);
804  if (pm.isNull())
805  return 0;
806 
807  result = pm.toWinHICON();
808 
809  if (cache) {
810  delete *cache;
811  *cache = new QPixmap(pm);;
812  }
813  }
814  return result;
815 }
816 
817 void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
818 {
819  Q_Q(QWidget);
820  if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow())
821  return;
822  QTLWExtra* x = topData();
823  if (x->iconPixmap && !forceReset)
824  // already been set
825  return;
826 
827  if (x->winIconBig) {
828  DestroyIcon(x->winIconBig);
829  x->winIconBig = 0;
830  }
831  if (x->winIconSmall) {
832  DestroyIcon(x->winIconSmall);
833  x->winIconSmall = 0;
834  }
835 
836  x->winIconSmall = qt_createIcon(q->windowIcon(),
837  GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
838  &(x->iconPixmap));
839  x->winIconBig = qt_createIcon(q->windowIcon(),
840  GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
841  &(x->iconPixmap));
842  if (x->winIconBig) {
843  SendMessage(q->internalWinId(), WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)x->winIconSmall);
844  SendMessage(q->internalWinId(), WM_SETICON, 1 /* ICON_BIG */, (LPARAM)x->winIconBig);
845  } else {
846  SendMessage(q->internalWinId(), WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)x->winIconSmall);
847  SendMessage(q->internalWinId(), WM_SETICON, 1 /* ICON_BIG */, (LPARAM)x->winIconSmall);
848  }
849 }
850 
851 
853 {
854  Q_UNUSED(iconText);
855 }
856 
857 
859 {
860  return mouseGrbCur;
861 }
862 
863 // The procedure does nothing, but is required for mousegrabbing to work
864 #ifndef Q_WS_WINCE
865 LRESULT QT_WIN_CALLBACK qJournalRecordProc(int nCode, WPARAM wParam, LPARAM lParam)
866 {
867  return CallNextHookEx(journalRec, nCode, wParam, lParam);
868 }
869 #endif //Q_WS_WINCE
870 
871 /* Works only as long as pointer is inside the application's window,
872  which is good enough for QDockWidget.
873 
874  Doesn't call SetWindowsHookEx() - this function causes a system-wide
875  freeze if any other app on the system installs a hook and fails to
876  process events. */
877 void QWidgetPrivate::grabMouseWhileInWindow()
878 {
879  Q_Q(QWidget);
880  if (!qt_nograb()) {
881  if (mouseGrb)
882  mouseGrb->releaseMouse();
883  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
884  SetCapture(q->effectiveWinId());
885  mouseGrb = q;
886 #ifndef QT_NO_CURSOR
887  mouseGrbCur = new QCursor(mouseGrb->cursor());
888 #endif
889  }
890 }
891 
892 #ifndef Q_WS_WINCE
893 void QWidget::grabMouse()
894 {
895  if (!qt_nograb()) {
896  if (mouseGrb)
897  mouseGrb->releaseMouse();
898  journalRec = SetWindowsHookEx(WH_JOURNALRECORD, (HOOKPROC)qJournalRecordProc, GetModuleHandle(0), 0);
899  Q_ASSERT(testAttribute(Qt::WA_WState_Created));
900  SetCapture(effectiveWinId());
901  mouseGrb = this;
902 #ifndef QT_NO_CURSOR
903  mouseGrbCur = new QCursor(mouseGrb->cursor());
904 #endif
905  }
906 }
907 
908 #ifndef QT_NO_CURSOR
909 void QWidget::grabMouse(const QCursor &cursor)
910 {
911  if (!qt_nograb()) {
912  if (mouseGrb)
913  mouseGrb->releaseMouse();
914  journalRec = SetWindowsHookEx(WH_JOURNALRECORD, (HOOKPROC)qJournalRecordProc, GetModuleHandle(0), 0);
915  Q_ASSERT(testAttribute(Qt::WA_WState_Created));
916  SetCapture(effectiveWinId());
917  mouseGrbCur = new QCursor(cursor);
918  SetCursor(mouseGrbCur->handle());
919  mouseGrb = this;
920  }
921 }
922 #endif
923 
925 {
926  if (!qt_nograb() && mouseGrb == this) {
927  ReleaseCapture();
928  if (journalRec) {
929  UnhookWindowsHookEx(journalRec);
930  journalRec = 0;
931  }
932  if (mouseGrbCur) {
933  delete mouseGrbCur;
934  mouseGrbCur = 0;
935  }
936  mouseGrb = 0;
937  }
938 }
939 #endif
940 
942 {
943  if (!qt_nograb()) {
944  if (keyboardGrb)
945  keyboardGrb->releaseKeyboard();
946  keyboardGrb = this;
947  }
948 }
949 
951 {
952  if (!qt_nograb() && keyboardGrb == this)
953  keyboardGrb = 0;
954 }
955 
956 
958 {
959  return mouseGrb;
960 }
961 
963 {
964  return keyboardGrb;
965 }
966 
968 {
969  window()->createWinId();
970  SetForegroundWindow(window()->internalWinId());
971 }
972 
973 #ifndef Q_WS_WINCE
974 void QWidget::setWindowState(Qt::WindowStates newstate)
975 {
976  Q_D(QWidget);
977  Qt::WindowStates oldstate = windowState();
978  if (oldstate == newstate)
979  return;
980 
981  int max = SW_MAXIMIZE;
982  int min = SW_MINIMIZE;
983 
984  int normal = SW_SHOWNOACTIVATE;
985  if (newstate & Qt::WindowActive) {
986  max = SW_SHOWMAXIMIZED;
987  min = SW_SHOWMINIMIZED;
988  normal = SW_SHOWNORMAL;
989  }
990 
991  if (isWindow()) {
992  createWinId();
993  Q_ASSERT(testAttribute(Qt::WA_WState_Created));
994 
995  // Ensure the initial size is valid, since we store it as normalGeometry below.
996  if (!testAttribute(Qt::WA_Resized) && !isVisible())
997  adjustSize();
998 
999  if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) {
1000  if (newstate & Qt::WindowMaximized && !(oldstate & Qt::WindowFullScreen))
1001  d->topData()->normalGeometry = geometry();
1002  if (isVisible() && !(newstate & Qt::WindowMinimized)) {
1003  ShowWindow(internalWinId(), (newstate & Qt::WindowMaximized) ? max : normal);
1004  if (!(newstate & Qt::WindowFullScreen)) {
1005  QRect r = d->topData()->normalGeometry;
1006  if (!(newstate & Qt::WindowMaximized) && r.width() >= 0) {
1007  if (pos() != r.topLeft() || size() !=r.size()) {
1008  d->topData()->normalGeometry = QRect(0,0,-1,-1);
1009  setGeometry(r);
1010  }
1011  }
1012  } else {
1013  d->updateFrameStrut();
1014  }
1015  }
1016  }
1017 
1018  if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) {
1019  if (newstate & Qt::WindowFullScreen) {
1020  if (d->topData()->normalGeometry.width() < 0 && !(oldstate & Qt::WindowMaximized))
1021  d->topData()->normalGeometry = geometry();
1022  d->topData()->savedFlags = Qt::WindowFlags(GetWindowLong(internalWinId(), GWL_STYLE));
1023 #ifndef Q_FLATTEN_EXPOSE
1024  UINT style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP;
1025 #else
1026  UINT style = WS_POPUP;
1027 #endif
1028  if (ulong(d->topData()->savedFlags) & WS_SYSMENU)
1029  style |= WS_SYSMENU;
1030  if (isVisible())
1031  style |= WS_VISIBLE;
1032  SetWindowLong(internalWinId(), GWL_STYLE, style);
1034  UINT swpf = SWP_FRAMECHANGED;
1035  if (newstate & Qt::WindowActive)
1036  swpf |= SWP_NOACTIVATE;
1037 
1038  SetWindowPos(internalWinId(), HWND_TOP, r.left(), r.top(), r.width(), r.height(), swpf);
1039  d->updateFrameStrut();
1040  } else {
1041  UINT style = d->topData()->savedFlags;
1042  if (isVisible())
1043  style |= WS_VISIBLE;
1044  SetWindowLong(internalWinId(), GWL_STYLE, style);
1045 
1046  UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE;
1047  if (newstate & Qt::WindowActive)
1048  swpf |= SWP_NOACTIVATE;
1049  SetWindowPos(internalWinId(), 0, 0, 0, 0, 0, swpf);
1050  d->updateFrameStrut();
1051 
1052  // preserve maximized state
1053  if (isVisible())
1054  ShowWindow(internalWinId(), (newstate & Qt::WindowMaximized) ? max : normal);
1055 
1056  if (!(newstate & Qt::WindowMaximized)) {
1057  QRect r = d->topData()->normalGeometry;
1058  d->topData()->normalGeometry = QRect(0,0,-1,-1);
1059  if (r.isValid())
1060  setGeometry(r);
1061  }
1062  }
1063  }
1064 
1065  if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) {
1066  if (isVisible())
1067  ShowWindow(internalWinId(), (newstate & Qt::WindowMinimized) ? min :
1068  (newstate & Qt::WindowMaximized) ? max : normal);
1069  }
1070  }
1071  data->window_state = newstate;
1072  QWindowStateChangeEvent e(oldstate);
1073  QApplication::sendEvent(this, &e);
1074 }
1075 #endif //Q_WS_WINCE
1076 
1077 
1078 /*
1079  \internal
1080  Platform-specific part of QWidget::hide().
1081 */
1082 
1084 {
1085  Q_Q(QWidget);
1087  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1088 #ifdef Q_WS_WINCE
1089  if (!qt_wince_is_mobile() && q->isFullScreen()) {
1090  HWND handle = FindWindow(L"HHTaskBar", L"");
1091  if (handle) {
1092  ShowWindow(handle, 1);
1093  EnableWindow(handle, true);
1094  }
1095  }
1096 #endif
1097  if (q->windowFlags() != Qt::Desktop) {
1098  if ((q->windowFlags() & Qt::Popup) && q->internalWinId())
1099  ShowWindow(q->internalWinId(), SW_HIDE);
1100  else if (q->internalWinId())
1101  SetWindowPos(q->internalWinId(),0, 0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER);
1102  }
1103  if (q->isWindow()) {
1105  bs->releaseBuffer();
1106  } else {
1107  invalidateBuffer(q->rect());
1108  }
1109  q->setAttribute(Qt::WA_Mapped, false);
1110 }
1111 
1112 
1113 /*
1114  \internal
1115  Platform-specific part of QWidget::show().
1116 */
1117 #ifndef Q_WS_WINCE
1119 {
1120  Q_Q(QWidget);
1121 #if defined(QT_NON_COMMERCIAL)
1122  QT_NC_SHOW_WINDOW
1123 #endif
1124  if (q->testAttribute(Qt::WA_OutsideWSRange))
1125  return;
1126  q->setAttribute(Qt::WA_Mapped);
1127  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1128 
1129  if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
1130  invalidateBuffer(q->rect());
1131  return;
1132  }
1133 
1134  if (data.window_flags & Qt::Window) {
1135  QTLWExtra *extra = topData();
1136  if (!extra->hotkeyRegistered) {
1137  // Try to set the hotkey using information from STARTUPINFO
1138  STARTUPINFO startupInfo;
1139  GetStartupInfo(&startupInfo);
1140  // If STARTF_USEHOTKEY is set, hStdInput is the virtual keycode
1141  if (startupInfo.dwFlags & 0x00000200) {
1142  WPARAM hotKey = (WPARAM)startupInfo.hStdInput;
1143  SendMessage(data.winid, WM_SETHOTKEY, hotKey, 0);
1144  }
1145  extra->hotkeyRegistered = 1;
1146  }
1147  }
1148 
1149  int sm = SW_SHOWNORMAL;
1150  bool fakedMaximize = false;
1151  if (q->isWindow()) {
1152  if (q->isMinimized()) {
1153  sm = SW_SHOWMINIMIZED;
1154  if (!IsWindowVisible(q->internalWinId()))
1155  sm = SW_SHOWMINNOACTIVE;
1156  } else if (q->isMaximized()) {
1157  sm = SW_SHOWMAXIMIZED;
1158  // Windows will not behave correctly when we try to maximize a window which does not
1159  // have minimize nor maximize buttons in the window frame. Windows would then ignore
1160  // non-available geometry, and rather maximize the widget to the full screen, minus the
1161  // window frame (caption). So, we do a trick here, by adding a maximize button before
1162  // maximizing the widget, and then remove the maximize button afterwards.
1163  Qt::WindowFlags &flags = data.window_flags;
1164  if (flags & Qt::WindowTitleHint &&
1166  fakedMaximize = TRUE;
1167  int style = GetWindowLong(q->internalWinId(), GWL_STYLE);
1168  SetWindowLong(q->internalWinId(), GWL_STYLE, style | WS_MAXIMIZEBOX);
1169  }
1170  }
1171  }
1172  if (q->testAttribute(Qt::WA_ShowWithoutActivating)
1173  || (q->windowType() == Qt::Popup)
1174  || (q->windowType() == Qt::ToolTip)
1175  || (q->windowType() == Qt::Tool)) {
1176  sm = SW_SHOWNOACTIVATE;
1177  }
1178 
1179 
1180  if (q->internalWinId())
1181  ShowWindow(q->internalWinId(), sm);
1182 
1183  if (fakedMaximize) {
1184  int style = GetWindowLong(q->internalWinId(), GWL_STYLE);
1185  SetWindowLong(q->internalWinId(), GWL_STYLE, style & ~WS_MAXIMIZEBOX);
1186  SetWindowPos(q->internalWinId(), 0, 0, 0, 0, 0,
1187  SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER
1188  | SWP_FRAMECHANGED);
1189  }
1190 
1191  if (q->internalWinId()) {
1192  if (IsIconic(q->internalWinId()))
1194  if (IsZoomed(q->internalWinId()))
1196  // This is to resolve the problem where popups are opened from the
1197  // system tray and not being implicitly activated
1198  if (q->windowType() == Qt::Popup &&
1199  !q->parentWidget() && !qApp->activeWindow())
1200  q->activateWindow();
1201  }
1202 
1203  winSetupGestures();
1204 
1205  invalidateBuffer(q->rect());
1206 }
1207 #endif //Q_WS_WINCE
1208 
1210 {
1211  Q_Q(QWidget);
1212  if (q->testAttribute(Qt::WA_WState_Created) && q->window()->windowType() != Qt::Popup)
1213  SetFocus(q->effectiveWinId());
1214 }
1215 
1217 {
1218  Q_Q(QWidget);
1219  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1220  if (q->internalWinId())
1221  SetWindowPos(q->internalWinId(), HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1222 }
1223 
1225 {
1226  Q_Q(QWidget);
1227  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1228  if (q->internalWinId())
1229  SetWindowPos(q->internalWinId(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1230  invalidateBuffer(q->rect());
1231 }
1232 
1234 {
1235  Q_Q(QWidget);
1236  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1237  if (q->internalWinId() && w->internalWinId())
1238  SetWindowPos(q->internalWinId(), w->internalWinId() , 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1239  invalidateBuffer(q->rect());
1240 }
1241 
1242 
1243 /*
1244  Helper function for non-toplevel widgets. Helps to map Qt's 32bit
1245  coordinate system to Windpws's 16bit coordinate system.
1246 
1247  This code is duplicated from the X11 code, so any changes there
1248  should also (most likely) be reflected here.
1249 
1250  (In all comments below: s/X/Windows/g)
1251  */
1252 
1253 void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &)
1254 {
1255  Q_Q(QWidget);
1256  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1257 
1258  /*
1259  There are up to four different coordinate systems here:
1260  Qt coordinate system for this widget.
1261  X coordinate system for this widget (relative to wrect).
1262  Qt coordinate system for parent
1263  X coordinate system for parent (relative to parent's wrect).
1264  */
1265  QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX);
1266  QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX);
1267  QRect wrect;
1268  //xrect is the X geometry of my X widget. (starts out in parent's Qt coord sys, and ends up in parent's X coord sys)
1269  QRect xrect = data.crect;
1270 
1271  const QWidget *const parent = q->parentWidget();
1272  QRect parentWRect = parent->data->wrect;
1273 
1274  if (parentWRect.isValid()) {
1275  // parent is clipped, and we have to clip to the same limit as parent
1276  if (!parentWRect.contains(xrect)) {
1277  xrect &= parentWRect;
1278  wrect = xrect;
1279  //translate from parent's to my Qt coord sys
1280  wrect.translate(-data.crect.topLeft());
1281  }
1282  //translate from parent's Qt coords to parent's X coords
1283  xrect.translate(-parentWRect.topLeft());
1284 
1285  } else {
1286  // parent is not clipped, we may or may not have to clip
1287 
1288  if (data.wrect.isValid() && QRect(QPoint(),data.crect.size()).contains(data.wrect)) {
1289  // This is where the main optimization is: we are already
1290  // clipped, and if our clip is still valid, we can just
1291  // move our window, and do not need to move or clip
1292  // children
1293 
1294  QRect vrect = xrect & parent->rect();
1295  vrect.translate(-data.crect.topLeft()); //the part of me that's visible through parent, in my Qt coords
1296  if (data.wrect.contains(vrect)) {
1297  xrect = data.wrect;
1298  xrect.translate(data.crect.topLeft());
1299  if (q->internalWinId())
1300  MoveWindow(q->internalWinId(), xrect.x(), xrect.y(), xrect.width(), xrect.height(), true);
1301  return;
1302  }
1303  }
1304 
1305  if (!validRange.contains(xrect)) {
1306  // we are too big, and must clip
1307  xrect &=wrectRange;
1308  wrect = xrect;
1309  wrect.translate(-data.crect.topLeft());
1310  //parent's X coord system is equal to parent's Qt coord
1311  //sys, so we don't need to map xrect.
1312  }
1313 
1314  }
1315 
1316 
1317  // unmap if we are outside the valid window system coord system
1318  bool outsideRange = !xrect.isValid();
1319  bool mapWindow = false;
1320  if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) {
1321  q->setAttribute(Qt::WA_OutsideWSRange, outsideRange);
1322  if (outsideRange) {
1323  if (q->internalWinId())
1324  ShowWindow(q->internalWinId(), SW_HIDE);
1325  q->setAttribute(Qt::WA_Mapped, false);
1326  } else if (!q->isHidden()) {
1327  mapWindow = true;
1328  }
1329  }
1330 
1331  if (outsideRange)
1332  return;
1333 
1334  bool jump = (data.wrect != wrect);
1335  data.wrect = wrect;
1336 
1337  // and now recursively for all children...
1338  for (int i = 0; i < children.size(); ++i) {
1339  QObject *object = children.at(i);
1340  if (object->isWidgetType()) {
1341  QWidget *w = static_cast<QWidget *>(object);
1342  if (!w->isWindow() && w->testAttribute(Qt::WA_WState_Created))
1343  w->d_func()->setWSGeometry();
1344  }
1345  }
1346 
1347  // move ourselves to the new position and map (if necessary) after
1348  // the movement. Rationale: moving unmapped windows is much faster
1349  // than moving mapped windows
1350  if (q->internalWinId()) {
1351  if (!parent->internalWinId())
1352  xrect.translate(parent->mapTo(q->nativeParentWidget(), QPoint(0, 0)));
1353  MoveWindow(q->internalWinId(), xrect.x(), xrect.y(), xrect.width(), xrect.height(), !jump);
1354  }
1355  if (mapWindow && !dontShow) {
1356  q->setAttribute(Qt::WA_Mapped);
1357  if (q->internalWinId())
1358  ShowWindow(q->internalWinId(), SW_SHOWNOACTIVATE);
1359  }
1360 
1361  if (jump && q->internalWinId())
1362  InvalidateRect(q->internalWinId(), 0, false);
1363 
1364 }
1365 
1366 //
1367 // The internal qWinRequestConfig, defined in qapplication_win.cpp, stores move,
1368 // resize and setGeometry requests for a widget that is already
1369 // processing a config event. The purpose is to avoid recursion.
1370 //
1371 void qWinRequestConfig(WId, int, int, int, int, int);
1372 
1373 void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
1374 {
1375  Q_Q(QWidget);
1376  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1377  if (extra) { // any size restrictions?
1378  w = qMin(w,extra->maxw);
1379  h = qMin(h,extra->maxh);
1380  w = qMax(w,extra->minw);
1381  h = qMax(h,extra->minh);
1382  }
1383  if (q->isWindow())
1384  topData()->normalGeometry = QRect(0, 0, -1, -1);
1385 
1386  QSize oldSize(q->size());
1387  QPoint oldPos(q->pos());
1388 
1389  if (!q->isWindow())
1390  isMove = (data.crect.topLeft() != QPoint(x, y));
1391  bool isResize = w != oldSize.width() || h != oldSize.height();
1392 
1393  if (!isMove && !isResize)
1394  return;
1395 
1396  if (isResize && !q->testAttribute(Qt::WA_StaticContents) && q->internalWinId())
1397  ValidateRgn(q->internalWinId(), 0);
1398 
1399 #ifdef Q_WS_WINCE
1400  // On Windows CE we can't just fiddle around with the window state.
1401  // Too much magic in setWindowState.
1402  if (isResize && q->isMaximized())
1403  q->setWindowState(q->windowState() & ~Qt::WindowMaximized);
1404 #else
1405  if (isResize)
1407 #endif
1408 
1410  QTLWExtra *top = topData();
1411 
1412  if (q->isWindow()) {
1413  // We need to update these flags when we remove the full screen state
1414  // or the frame will not be updated
1415  UINT style = top->savedFlags;
1416  if (q->isVisible())
1417  style |= WS_VISIBLE;
1418  SetWindowLong(q->internalWinId(), GWL_STYLE, style);
1419 
1420  UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE;
1422  swpf |= SWP_NOACTIVATE;
1423  SetWindowPos(q->internalWinId(), 0, 0, 0, 0, 0, swpf);
1424  updateFrameStrut();
1425  }
1427  topData()->savedFlags = 0;
1428  }
1429 
1430  QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
1431  const bool inTopLevelResize = tlwExtra ? tlwExtra->inTopLevelResize : false;
1432  const bool isTranslucentWindow = !isOpaque && ptrUpdateLayeredWindowIndirect && (data.window_flags & Qt::FramelessWindowHint)
1433  && GetWindowLong(q->internalWinId(), GWL_EXSTYLE) & Q_WS_EX_LAYERED;
1434 
1435  if (q->testAttribute(Qt::WA_WState_ConfigPending)) { // processing config event
1436  if (q->internalWinId())
1437  qWinRequestConfig(q->internalWinId(), isMove ? 2 : 1, x, y, w, h);
1438  } else {
1439  if (!q->testAttribute(Qt::WA_DontShowOnScreen))
1440  q->setAttribute(Qt::WA_WState_ConfigPending);
1441  if (q->windowType() == Qt::Desktop) {
1442  data.crect.setRect(x, y, w, h);
1443  } else if (q->isWindow()) {
1444  QRect fs(frameStrut());
1445  if (extra) {
1446  fs.setLeft(x - fs.left());
1447  fs.setTop(y - fs.top());
1448  fs.setRight((x + w - 1) + fs.right());
1449  fs.setBottom((y + h - 1) + fs.bottom());
1450  }
1451  if (w == 0 || h == 0) {
1452  q->setAttribute(Qt::WA_OutsideWSRange, true);
1453  if (q->isVisible() && q->testAttribute(Qt::WA_Mapped))
1454  hide_sys();
1455  data.crect = QRect(x, y, w, h);
1456  } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) {
1457  q->setAttribute(Qt::WA_OutsideWSRange, false);
1458 
1459  // put the window in its place and show it
1460  MoveWindow(q->internalWinId(), fs.x(), fs.y(), fs.width(), fs.height(), true);
1461  RECT rect;
1462  if (!q->testAttribute(Qt::WA_DontShowOnScreen)) {
1463  GetClientRect(q->internalWinId(), &rect);
1464  data.crect.setRect(x, y, rect.right - rect.left, rect.bottom - rect.top);
1465  } else {
1466  data.crect.setRect(x, y, w, h);
1467  }
1468 
1469  show_sys();
1470  } else if (!q->testAttribute(Qt::WA_DontShowOnScreen)) {
1471  q->setAttribute(Qt::WA_OutsideWSRange, false);
1472 #ifndef Q_WS_WINCE
1473  // If the window is hidden and in maximized state or minimized, instead of moving the
1474  // window, set the normal position of the window.
1475  WINDOWPLACEMENT wndpl;
1476  GetWindowPlacement(q->internalWinId(), &wndpl);
1477  if ((wndpl.showCmd == SW_MAXIMIZE && !IsWindowVisible(q->internalWinId())) || wndpl.showCmd == SW_SHOWMINIMIZED) {
1478  RECT normal = {fs.x(), fs.y(), fs.x()+fs.width(), fs.y()+fs.height()};
1479  wndpl.rcNormalPosition = normal;
1480  wndpl.showCmd = wndpl.showCmd == SW_SHOWMINIMIZED ? SW_SHOWMINIMIZED : SW_HIDE;
1481  SetWindowPlacement(q->internalWinId(), &wndpl);
1482  } else {
1483 #else
1485  qt_wince_maximize(q);
1486  } else {
1487 #endif
1488  MoveWindow(q->internalWinId(), fs.x(), fs.y(), fs.width(), fs.height(), true);
1489  }
1490  if (!q->isVisible())
1491  InvalidateRect(q->internalWinId(), 0, FALSE);
1492  RECT rect;
1493  // If the layout has heightForWidth, the MoveWindow() above can
1494  // change the size/position, so refresh them.
1495 
1496  if (isTranslucentWindow) {
1497  data.crect.setRect(x, y, w, h);
1498  } else {
1499  GetClientRect(q->internalWinId(), &rect);
1500  RECT rcNormalPosition ={0, 0, 0, 0};
1501  // Use (0,0) as window position for embedded ActiveQt controls.
1502  if (!tlwExtra || !tlwExtra->embedded)
1503  GetWindowRect(q->internalWinId(), &rcNormalPosition);
1504  QRect fStrut(frameStrut());
1505  data.crect.setRect(rcNormalPosition.left + fStrut.left(),
1506  rcNormalPosition.top + fStrut.top(),
1507  rect.right - rect.left,
1508  rect.bottom - rect.top);
1509  isResize = data.crect.size() != oldSize;
1510  }
1511  } else {
1512  q->setAttribute(Qt::WA_OutsideWSRange, false);
1513  data.crect.setRect(x, y, w, h);
1514  }
1515  } else {
1516  QRect oldGeom(data.crect);
1517  data.crect.setRect(x, y, w, h);
1518  if (q->isVisible() && (!inTopLevelResize || q->internalWinId())) {
1519  // Top-level resize optimization does not work for native child widgets;
1520  // disable it for this particular widget.
1521  if (inTopLevelResize)
1522  tlwExtra->inTopLevelResize = false;
1523 
1524  if (!isResize)
1525  moveRect(QRect(oldPos, oldSize), x - oldPos.x(), y - oldPos.y());
1526  else
1527  invalidateBuffer_resizeHelper(oldPos, oldSize);
1528 
1529  if (inTopLevelResize)
1530  tlwExtra->inTopLevelResize = true;
1531  }
1532  if (q->testAttribute(Qt::WA_WState_Created))
1533  setWSGeometry();
1534  }
1535  q->setAttribute(Qt::WA_WState_ConfigPending, false);
1536  }
1537 
1538  if (q->isWindow() && q->isVisible() && isResize && !inTopLevelResize) {
1539  invalidateBuffer(q->rect()); //after the resize
1540  }
1541 
1542  // Process events immediately rather than in translateConfigEvent to
1543  // avoid windows message process delay.
1544  if (q->isVisible()) {
1545  if (isMove && q->pos() != oldPos) {
1546  QMoveEvent e(q->pos(), oldPos);
1547  QApplication::sendEvent(q, &e);
1548  }
1549  if (isResize) {
1550  static bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt();
1551  // If we have a backing store with static contents, we have to disable the top-level
1552  // resize optimization in order to get invalidated regions for resized widgets.
1553  // The optimization discards all invalidateBuffer() calls since we're going to
1554  // repaint everything anyways, but that's not the case with static contents.
1555  const bool setTopLevelResize = !slowResize && q->isWindow() && extra && extra->topextra
1557  && (!extra->topextra->backingStore
1559  if (setTopLevelResize)
1560  extra->topextra->inTopLevelResize = true;
1561  QResizeEvent e(q->size(), oldSize);
1562  QApplication::sendEvent(q, &e);
1563  if (setTopLevelResize)
1564  extra->topextra->inTopLevelResize = false;
1565  }
1566  } else {
1567  if (isMove && q->pos() != oldPos)
1568  q->setAttribute(Qt::WA_PendingMoveEvent, true);
1569  if (isResize)
1570  q->setAttribute(Qt::WA_PendingResizeEvent, true);
1571  }
1572 }
1573 
1574 bool QWidgetPrivate::shouldShowMaximizeButton()
1575 {
1577  return false;
1578  // if the user explicitly asked for the maximize button, we try to add
1579  // it even if the window has fixed size.
1582  return true;
1583  if (extra) {
1586  return false;
1587  }
1589 }
1590 
1591 void QWidgetPrivate::winUpdateIsOpaque()
1592 {
1593 #ifndef Q_WS_WINCE
1594  Q_Q(QWidget);
1595 
1596  if (!q->isWindow() || !q->testAttribute(Qt::WA_TranslucentBackground))
1597  return;
1598 
1600  return;
1601 
1603  SetWindowLong(q->internalWinId(), GWL_EXSTYLE,
1604  GetWindowLong(q->internalWinId(), GWL_EXSTYLE) | Q_WS_EX_LAYERED);
1605  } else {
1606  SetWindowLong(q->internalWinId(), GWL_EXSTYLE,
1607  GetWindowLong(q->internalWinId(), GWL_EXSTYLE) & ~Q_WS_EX_LAYERED);
1608  }
1609 #endif
1610 }
1611 
1613 {
1614 #ifndef Q_WS_WINCE_WM
1615  Q_Q(QWidget);
1616  if (q->isWindow() && q->testAttribute(Qt::WA_WState_Created)) {
1617  int style = GetWindowLong(q->internalWinId(), GWL_STYLE);
1618  if (shouldShowMaximizeButton())
1619  style |= WS_MAXIMIZEBOX;
1620  else
1621  style &= ~WS_MAXIMIZEBOX;
1622  SetWindowLong(q->internalWinId(), GWL_STYLE, style);
1623  }
1624 #endif
1625 }
1626 
1627 void QWidgetPrivate::scroll_sys(int dx, int dy)
1628 {
1629  Q_Q(QWidget);
1630  scrollChildren(dx, dy);
1631 
1632  if (!paintOnScreen()) {
1633  scrollRect(q->rect(), dx, dy);
1634  } else {
1635  UINT flags = SW_INVALIDATE;
1636  if (!q->testAttribute(Qt::WA_OpaquePaintEvent))
1637  flags |= SW_ERASE;
1638  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1639  ScrollWindowEx(q->internalWinId(), dx, dy, 0, 0, 0, 0, flags);
1640  UpdateWindow(q->internalWinId());
1641  }
1642 }
1643 
1644 void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
1645 {
1646  Q_Q(QWidget);
1647 
1648  if (!paintOnScreen()) {
1649  scrollRect(r, dx, dy);
1650  } else {
1651  RECT wr;
1652  wr.top = r.top();
1653  wr.left = r.left();
1654  wr.bottom = r.bottom()+1;
1655  wr.right = r.right()+1;
1656 
1657  UINT flags = SW_INVALIDATE;
1658  if (!q->testAttribute(Qt::WA_OpaquePaintEvent))
1659  flags |= SW_ERASE;
1660  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1661  ScrollWindowEx(q->internalWinId(), dx, dy, &wr, &wr, 0, 0, flags);
1662  UpdateWindow(q->internalWinId());
1663  }
1664 }
1665 
1666 extern Q_GUI_EXPORT HDC qt_win_display_dc();
1667 
1668 int QWidget::metric(PaintDeviceMetric m) const
1669 {
1670  Q_D(const QWidget);
1671  int val;
1672  if (m == PdmWidth) {
1673  val = data->crect.width();
1674  } else if (m == PdmHeight) {
1675  val = data->crect.height();
1676  } else {
1677  bool ownDC = QThread::currentThread() != qApp->thread();
1678  HDC gdc = ownDC ? GetDC(0) : qt_win_display_dc();
1679  switch (m) {
1680  case PdmDpiX:
1681  case PdmPhysicalDpiX:
1682  if (d->extra && d->extra->customDpiX)
1683  val = d->extra->customDpiX;
1684  else if (d->parent)
1685  val = static_cast<QWidget *>(d->parent)->metric(m);
1686  else
1687  val = GetDeviceCaps(gdc, LOGPIXELSX);
1688  break;
1689  case PdmDpiY:
1690  case PdmPhysicalDpiY:
1691  if (d->extra && d->extra->customDpiY)
1692  val = d->extra->customDpiY;
1693  else if (d->parent)
1694  val = static_cast<QWidget *>(d->parent)->metric(m);
1695  else
1696  val = GetDeviceCaps(gdc, LOGPIXELSY);
1697  break;
1698  case PdmWidthMM:
1699  val = data->crect.width()
1700  * GetDeviceCaps(gdc, HORZSIZE)
1701  / GetDeviceCaps(gdc, HORZRES);
1702  break;
1703  case PdmHeightMM:
1704  val = data->crect.height()
1705  * GetDeviceCaps(gdc, VERTSIZE)
1706  / GetDeviceCaps(gdc, VERTRES);
1707  break;
1708  case PdmNumColors:
1709  if (GetDeviceCaps(gdc, RASTERCAPS) & RC_PALETTE)
1710  val = GetDeviceCaps(gdc, SIZEPALETTE);
1711  else {
1712  HDC hd = d->hd ? HDC(d->hd) : gdc;
1713  int bpp = GetDeviceCaps(hd, BITSPIXEL);
1714  if (bpp == 32)
1715  val = INT_MAX; // ### this is bogus, it should be 2^24 colors for 32 bit as well
1716  else if(bpp<=8)
1717  val = GetDeviceCaps(hd, NUMCOLORS);
1718  else
1719  val = 1 << (bpp * GetDeviceCaps(hd, PLANES));
1720  }
1721  break;
1722  case PdmDepth:
1723  val = GetDeviceCaps(gdc, BITSPIXEL);
1724  break;
1725  default:
1726  val = 0;
1727  qWarning("QWidget::metric: Invalid metric command");
1728  }
1729  if (ownDC)
1730  ReleaseDC(0, gdc);
1731  }
1732  return val;
1733 }
1734 
1736 {
1737 #ifndef QT_NO_DRAGANDDROP
1738  extra->dropTarget = 0;
1739 #endif
1740 }
1741 
1742 #ifndef Q_WS_WINCE
1744 {
1745 }
1746 #endif //Q_WS_WINCE
1747 
1749 {
1750  extra->topextra->hotkeyRegistered = 0;
1751  extra->topextra->savedFlags = 0;
1752  extra->topextra->winIconBig = 0;
1753  extra->topextra->winIconSmall = 0;
1754 }
1755 
1757 {
1758  if (extra->topextra->winIconSmall)
1759  DestroyIcon(extra->topextra->winIconSmall);
1760  if (extra->topextra->winIconBig)
1761  DestroyIcon(extra->topextra->winIconBig);
1762 }
1763 
1765 {
1766  Q_Q(QWidget);
1767  if (!q->testAttribute(Qt::WA_WState_Created))
1768  return;
1769  // Enablement is defined by d->extra->dropTarget != 0.
1770  if (on) {
1771  // Turn on.
1772  createExtra();
1773 #ifndef QT_NO_DRAGANDDROP
1774  if (!q->internalWinId())
1775  q->nativeParentWidget()->d_func()->createExtra();
1776  QWExtra *extra = extraData();
1777  if (!extra->dropTarget)
1778  extra->dropTarget = registerOleDnd(q);
1779 #endif
1780  } else {
1781  // Turn off.
1782  QWExtra *extra = extraData();
1783 #ifndef QT_NO_DRAGANDDROP
1784  if (extra && extra->dropTarget) {
1785  unregisterOleDnd(q, extra->dropTarget);
1786  extra->dropTarget = 0;
1787  }
1788 #endif
1789  }
1790 }
1791 
1792 #ifndef QT_NO_DRAGANDDROP
1793 QOleDropTarget* QWidgetPrivate::registerOleDnd(QWidget *widget)
1794 {
1795  QOleDropTarget *dropTarget = new QOleDropTarget(widget);
1797  if (!widget->internalWinId()) {
1798  QWidget *nativeParent = widget->nativeParentWidget();
1799  Q_ASSERT(nativeParent);
1800  QWExtra *nativeExtra = nativeParent->d_func()->extra;
1801  Q_ASSERT(nativeExtra);
1802  if (!nativeExtra->oleDropWidgets.contains(widget))
1803  nativeExtra->oleDropWidgets.append(widget);
1804  if (!nativeExtra->dropTarget) {
1805  nativeExtra->dropTarget = registerOleDnd(nativeParent);
1806  Q_ASSERT(nativeExtra->dropTarget);
1807 #ifndef Q_OS_WINCE
1808  CoLockObjectExternal(nativeExtra->dropTarget, false, true);
1809 #endif
1810  RegisterDragDrop(nativeParent->internalWinId(), nativeExtra->dropTarget);
1811  }
1812  } else {
1813  RegisterDragDrop(widget->internalWinId(), dropTarget);
1814 #ifndef Q_OS_WINCE
1815  CoLockObjectExternal(dropTarget, true, true);
1816 #endif
1817  }
1818  return dropTarget;
1819 }
1820 
1821 void QWidgetPrivate::unregisterOleDnd(QWidget *widget, QOleDropTarget *dropTarget)
1822 {
1824  if (!widget->internalWinId()) {
1825  dropTarget->releaseQt();
1826  dropTarget->Release();
1827  QWidget *nativeParent = widget->nativeParentWidget();
1828  while (nativeParent) {
1829  QWExtra *nativeExtra = nativeParent->d_func()->extra;
1830  if (!nativeExtra) {
1831  nativeParent = nativeParent->nativeParentWidget();
1832  continue;
1833  }
1834 
1835  const int removeCounter = nativeExtra->oleDropWidgets.removeAll(widget);
1836  nativeExtra->oleDropWidgets.removeAll(static_cast<QWidget *>(0));
1837  if (nativeExtra->oleDropWidgets.isEmpty() && nativeExtra->dropTarget
1838  && !nativeParent->testAttribute(Qt::WA_DropSiteRegistered)) {
1839 #ifndef Q_OS_WINCE
1840  CoLockObjectExternal(nativeExtra->dropTarget, false, true);
1841 #endif
1842  nativeExtra->dropTarget->releaseQt();
1843  nativeExtra->dropTarget->Release();
1844  RevokeDragDrop(nativeParent->internalWinId());
1845  nativeExtra->dropTarget = 0;
1846  }
1847 
1848  if (removeCounter)
1849  break;
1850 
1851  nativeParent = nativeParent->nativeParentWidget();
1852  }
1853  } else {
1854 #ifndef Q_OS_WINCE
1855  CoLockObjectExternal(dropTarget, false, true);
1856 #endif
1857  dropTarget->releaseQt();
1858  dropTarget->Release();
1859  RevokeDragDrop(widget->internalWinId());
1860  }
1861 }
1862 
1863 #endif //QT_NO_DRAGANDDROP
1864 
1865 // from qregion_win.cpp
1866 extern HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int right, int bottom);
1867 void QWidgetPrivate::setMask_sys(const QRegion &region)
1868 {
1869  Q_Q(QWidget);
1870  if (!q->internalWinId())
1871  return;
1872 
1873  if (region.isEmpty()) {
1874  SetWindowRgn(q->internalWinId(), 0, true);
1875  return;
1876  }
1877 
1878  // Since SetWindowRegion takes ownership, and we need to translate,
1879  // we take a copy.
1880  HRGN wr = qt_tryCreateRegion(QRegion::Rectangle, 0,0,0,0);
1881  CombineRgn(wr, region.handle(), 0, RGN_COPY);
1882 
1883  QPoint offset = (q->isWindow()
1884  ? frameStrut().topLeft()
1885  : QPoint(0, 0));
1886  OffsetRgn(wr, offset.x(), offset.y());
1887 
1888  Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
1889  if (!SetWindowRgn(data.winid, wr, true))
1890  DeleteObject(wr);
1891 }
1892 
1894 {
1895  Q_Q(QWidget);
1896 
1897  if (!q->testAttribute(Qt::WA_WState_Created))
1898  return;
1899 
1900  if (!q->internalWinId()) {
1901  data.fstrut_dirty = false;
1902  return;
1903  }
1904 
1905  RECT rect = {0,0,0,0};
1906 
1907  QTLWExtra *top = topData();
1908  uint exstyle = GetWindowLong(q->internalWinId(), GWL_EXSTYLE);
1909  uint style = GetWindowLong(q->internalWinId(), GWL_STYLE);
1910 #ifndef Q_WS_WINCE
1911  if (AdjustWindowRectEx(&rect, style & ~(WS_OVERLAPPED), FALSE, exstyle)) {
1912 #else
1913  if (AdjustWindowRectEx(&rect, style, FALSE, exstyle)) {
1914 #endif
1915  top->frameStrut.setCoords(-rect.left, -rect.top, rect.right, rect.bottom);
1916  data.fstrut_dirty = false;
1917  }
1918 }
1919 
1920 #ifndef Q_WS_WINCE
1922 {
1923  Q_Q(QWidget);
1924 
1926  if (GetWindowLong(q->internalWinId(), GWL_EXSTYLE) & Q_WS_EX_LAYERED) {
1927  BLENDFUNCTION blend = {AC_SRC_OVER, 0, (BYTE)(255.0 * level), AC_SRC_ALPHA};
1928  ptrUpdateLayeredWindow(q->internalWinId(), NULL, NULL, NULL, NULL, NULL, 0, &blend, Q_ULW_ALPHA);
1929  }
1930  return;
1931  }
1932 
1933  static bool function_resolved = false;
1934  if (!function_resolved) {
1937  "SetLayeredWindowAttributes");
1938  function_resolved = true;
1939  }
1940 
1942  return;
1943 
1944  int wl = GetWindowLong(q->internalWinId(), GWL_EXSTYLE);
1945 
1946  if (level != 1.0) {
1947  if ((wl&Q_WS_EX_LAYERED) == 0)
1948  SetWindowLong(q->internalWinId(), GWL_EXSTYLE, wl | Q_WS_EX_LAYERED);
1949  } else if (wl&Q_WS_EX_LAYERED) {
1950  SetWindowLong(q->internalWinId(), GWL_EXSTYLE, wl & ~Q_WS_EX_LAYERED);
1951  }
1952  ptrSetLayeredWindowAttributes(q->internalWinId(), 0, (int)(level * 255), Q_LWA_ALPHA);
1953 }
1954 #endif //Q_WS_WINCE
1955 
1956 // class QGlobalRasterPaintEngine: public QRasterPaintEngine
1957 // {
1958 // public:
1959 // inline QGlobalRasterPaintEngine() : QRasterPaintEngine() { setFlushOnEnd(false); }
1960 // };
1961 // Q_GLOBAL_STATIC(QGlobalRasterPaintEngine, globalRasterPaintEngine)
1962 
1963 
1964 #ifndef QT_NO_DIRECTDRAW
1968 
1970 {
1971  HRESULT res;
1972 
1973  // Some initialization...
1974  if (!qt_ddraw_object) {
1975  res = DirectDrawCreate(0, &qt_ddraw_object, 0);
1976 
1977  if (res != DD_OK)
1978  qWarning("DirectDrawCreate failed: %d", res);
1979 
1980  qt_ddraw_object->SetCooperativeLevel(0, DDSCL_NORMAL);
1981 
1982  DDSURFACEDESC surfaceDesc;
1983  memset(&surfaceDesc, 0, sizeof(DDSURFACEDESC));
1984 
1985  surfaceDesc.dwSize = sizeof(DDSURFACEDESC);
1986  surfaceDesc.dwFlags = DDSD_CAPS;
1987  surfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
1988 
1989  res = qt_ddraw_object->CreateSurface(&surfaceDesc, &qt_ddraw_primary, 0);
1990  if (res != DD_OK)
1991  qWarning("CreateSurface failed: %d", res);
1992 
1993  memset(&surfaceDesc, 0, sizeof(DDSURFACEDESC));
1994  surfaceDesc.dwSize = sizeof(DDSURFACEDESC);
1995  res = qt_ddraw_primary->Lock(0, &surfaceDesc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, 0);
1996  if (res != DD_OK)
1997  qWarning("Locking surface failed: %d", res);
1998 
1999  if (surfaceDesc.ddpfPixelFormat.dwFlags == DDPF_RGB) {
2000  qt_primary_surface_bits = (uchar *) surfaceDesc.lpSurface;
2001  qt_primary_surface_stride = surfaceDesc.lPitch;
2002  qt_primary_surface_format = QImage::Format_RGB32;
2003  } else {
2004  qWarning("QWidget painting: unsupported device depth for onscreen painting...\n");
2005  }
2006 
2007  qt_ddraw_primary->Unlock(0);
2008  }
2009 }
2010 
2012 {
2013 public:
2014  // The image allocated here leaks... Fix if this code is ifdef'ed
2015  // in
2017  : QRasterPaintEngine(new QImage(qt_primary_surface_bits,
2018  QApplication::desktop()->width(),
2019  QApplication::desktop()->height(),
2020  qt_primary_surface_stride,
2021  qt_primary_surface_format))
2022  {
2023  device = static_cast<QImage *>(d_func()->device);
2024  }
2025 
2027  {
2028  QRegion clip = systemClip();
2029  originalSystemClip = clip;
2030  clip.translate(widget->mapToGlobal(QPoint(0, 0)));
2031  setSystemClip(clip);
2032 
2033  QRect bounds = clip.boundingRect();
2034  DDSURFACEDESC surface;
2035  surface.dwSize = sizeof(DDSURFACEDESC);
2036  HRESULT res = qt_ddraw_primary->Lock((RECT *) &bounds, &surface, DDLOCK_WAIT, 0);
2037  if (res != DD_OK) {
2038  qWarning("QWidget painting: locking onscreen bits failed: %d\n", res);
2039  return false;
2040  }
2041 
2042  if (surface.lpSurface == qt_primary_surface_bits) {
2043  qt_primary_surface_bits = (uchar *) surface.lpSurface;
2044  device->data_ptr()->data = qt_primary_surface_bits;
2045  }
2046 
2047  return QRasterPaintEngine::begin(device);
2048  }
2049 
2050  bool end()
2051  {
2052  HRESULT res = qt_ddraw_primary->Unlock(0);
2053  if (res != DD_OK)
2054  qWarning("QWidget::paint, failed to unlock DirectDraw surface: %d", res);
2055  bool ok = QRasterPaintEngine::end();
2056  setSystemClip(originalSystemClip);
2057  return ok;
2058  }
2059 
2061  return -widget->mapToGlobal(QPoint(0, 0));
2062  }
2063 
2064  const QWidget *widget;
2067 };
2068 Q_GLOBAL_STATIC(QOnScreenRasterPaintEngine, onScreenPaintEngine)
2069 #else
2071 #endif
2072 
2074 {
2075 #ifndef QT_NO_DIRECTDRAW
2076  QOnScreenRasterPaintEngine *pe = onScreenPaintEngine();
2077  pe->widget = this;
2078  return pe;
2079 #endif
2080 
2081  // We set this bit which is checked in setAttribute for
2082  // Qt::WA_PaintOnScreen. We do this to allow these two scenarios:
2083  //
2084  // 1. Users accidentally set Qt::WA_PaintOnScreen on X and port to
2085  // windows which would mean suddenly their widgets stop working.
2086  //
2087  // 2. Users set paint on screen and subclass paintEngine() to
2088  // return 0, in which case we have a "hole" in the backingstore
2089  // allowing use of GDI or DirectX directly.
2090  //
2091  // 1 is WRONG, but to minimize silent failures, we have set this
2092  // bit to ignore the setAttribute call. 2. needs to be
2093  // supported because its our only means of embeddeding native
2094  // graphics stuff.
2095  const_cast<QWidgetPrivate *>(d_func())->noPaintOnScreen = 1;
2096 
2097  return 0;
2098 }
2099 
2101 {
2102  Q_Q(QWidget);
2103  return new QRasterWindowSurface(q);
2104 }
2105 
2107 {
2108 }
2109 
2110 void QWidgetPrivate::registerTouchWindow()
2111 {
2112  Q_Q(QWidget);
2113 
2114  // enable WM_TOUCH* messages on our window
2115  if (q->testAttribute(Qt::WA_WState_Created)
2117  && q->windowType() != Qt::Desktop)
2118  QApplicationPrivate::RegisterTouchWindow(q->effectiveWinId(), 0);
2119 }
2120 
2121 void QWidgetPrivate::winSetupGestures()
2122 {
2123 #if !defined(QT_NO_GESTURES) && !defined(QT_NO_NATIVE_GESTURES)
2124  Q_Q(QWidget);
2125  if (!q || !q->isVisible() || !nativeGesturePanEnabled)
2126  return;
2127 
2129  return;
2131  if (!qAppPriv->SetGestureConfig)
2132  return;
2133  WId winid = q->internalWinId();
2134 
2135  bool needh = false;
2136  bool needv = false;
2137  bool singleFingerPanEnabled = false;
2138 
2139 #ifndef QT_NO_SCROLLAREA
2140  if (QAbstractScrollArea *asa = qobject_cast<QAbstractScrollArea*>(q->parent())) {
2141  QScrollBar *hbar = asa->horizontalScrollBar();
2142  QScrollBar *vbar = asa->verticalScrollBar();
2143  Qt::ScrollBarPolicy hbarpolicy = asa->horizontalScrollBarPolicy();
2144  Qt::ScrollBarPolicy vbarpolicy = asa->verticalScrollBarPolicy();
2145  needh = (hbarpolicy == Qt::ScrollBarAlwaysOn ||
2146  (hbarpolicy == Qt::ScrollBarAsNeeded && hbar->minimum() < hbar->maximum()));
2147  needv = (vbarpolicy == Qt::ScrollBarAlwaysOn ||
2148  (vbarpolicy == Qt::ScrollBarAsNeeded && vbar->minimum() < vbar->maximum()));
2149  singleFingerPanEnabled = asa->d_func()->singleFingerPanEnabled;
2150  if (!winid) {
2151  winid = q->winId(); // enforces the native winid on the viewport
2152  }
2153  }
2154 #endif //QT_NO_SCROLLAREA
2155  if (winid) {
2156  GESTURECONFIG gc[1];
2157  memset(gc, 0, sizeof(gc));
2158  gc[0].dwID = GID_PAN;
2159  if (nativeGesturePanEnabled) {
2160  gc[0].dwWant = GC_PAN;
2161  if (needv && singleFingerPanEnabled)
2163  else
2165  if (needh && singleFingerPanEnabled)
2167  else
2169  } else {
2170  gc[0].dwBlock = GC_PAN;
2171  }
2172 
2173  qAppPriv->SetGestureConfig(winid, 0, sizeof(gc)/sizeof(gc[0]), gc, sizeof(gc[0]));
2174  }
2175 #endif
2176 }
2177 
2179 
2180 #ifdef Q_WS_WINCE
2181 # include "qwidget_wince.cpp"
2182 #endif
bool qt_wince_is_mobile()
HCURSOR_or_HANDLE handle() const
Returns a platform-specific cursor handle.
Definition: qcursor_mac.mm:301
double d
Definition: qnumeric_p.h:62
static void jump(QtMsgType t, const char *m)
void setParent_sys(QWidget *parent, Qt::WindowFlags)
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
static uchar * qt_primary_surface_bits
Format
The following image formats are available in Qt.
Definition: qimage.h:91
static QWidget * qt_tablet_widget
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define GC_PAN_WITH_SINGLE_FINGER_VERTICALLY
unsigned long WId
Definition: qwindowdefs.h:119
void grabMouse()
Grabs the mouse input.
void setWindowIcon_sys(bool forceReset=false)
void push_back(const T &t)
This function is provided for STL compatibility.
Definition: qlist.h:296
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
PtrUpdateLayeredWindowIndirect ptrUpdateLayeredWindowIndirect
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int metric(PaintDeviceMetric) const
Internal implementation of the virtual QPaintDevice::metric() function.
Q_GUI_EXPORT HDC qt_win_display_dc()
HRGN qt_win_bitmapToRegion(const QBitmap &bitmap)
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
static void qt_tablet_cleanup()
QPointer< QWidget > widget
#define WS_EX_TOOLWINDOW
QRect frameStrut
Definition: qwidget_p.h:180
HICON qt_createIcon(QIcon icon, int xSize, int ySize, QPixmap **cache)
#define BYTE
void setWindowState(Qt::WindowStates state)
Sets the window state to windowState.
RegionType
Specifies the shape of the region to be created.
Definition: qregion.h:71
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
QRect crect
Definition: qwidget.h:131
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
Qt::HANDLE hd
Definition: qwidget_p.h:754
static IDirectDraw * qt_ddraw_object
Definition: qwidget_win.cpp:86
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
int minimum() const
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
QOleDropTarget * qt_olednd_register(QWidget *widget)
bool isVisible() const
Definition: qwidget.h:1005
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
bool paintOnScreen() const
Definition: qwidget.cpp:2255
bool remove(const T &value)
Definition: qset.h:89
static void adjustFlags(Qt::WindowFlags &flags, QWidget *w=0)
Definition: qwidget.cpp:1242
void qt_olednd_unregister(QWidget *widget, QOleDropTarget *dst)
bool end()
Reimplement this function to finish painting on the current paint device.
void setWindowTitle_sys(const QString &cap)
void moveRect(const QRect &, int dx, int dy)
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
uint window_state
Definition: qwidget.h:120
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define PACKETMODE
bool begin(QPaintDevice *device)
Reimplemented Function
QRect frameGeometry
geometry of the widget relative to its parent including any window frame
Definition: qwidget.h:159
static void qt_tablet_init()
PtrSetGestureConfig SetGestureConfig
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
uint inTopLevelResize
Definition: qwidget_p.h:188
int(API * PtrWTPacketsGet)(HCTX, int, LPVOID)
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
#define Q_LWA_ALPHA
BOOL(API * PtrWTClose)(HCTX)
void deleteTLSysExtra()
void qt_wince_unmaximize(QWidget *widget)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QPoint coordinateOffset() const
Returns the offset from the painters origo to the engines origo.
static QApplicationPrivate * instance()
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
static IDirectDrawSurface * qt_ddraw_primary
Definition: qwidget_win.cpp:87
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
void show_sys()
Platform-specific part of QWidget::show().
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define XCOORD_MAX
void qt_wince_full_screen(HWND hwnd, bool fullScreen, UINT swpf)
WindowType
Definition: qnamespace.h:270
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
BOOL(API * PtrWTEnable)(HCTX, BOOL)
QTLWExtra * maybeTopData() const
Definition: qwidget_p.h:1010
static PtrWTQueueSizeSet ptrWTQueueSizeSet
#define Q_D(Class)
Definition: qglobal.h:2482
void scrollChildren(int dx, int dy)
Definition: qwidget.cpp:421
QObjectList children
Definition: qobject.h:93
void setCursor_sys(const QCursor &cursor)
bool end()
Reimplemented Function
qint32 minw
Definition: qwidget_p.h:264
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
int(API * PtrWTQueueSizeGet)(HCTX)
QString qAppName()
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void registerDropSite(bool)
uint embedded
Definition: qwidget_p.h:190
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
UINT(API * PtrWTInfo)(UINT, UINT, LPVOID)
QWidgetData data
Definition: qwidget_p.h:755
QGraphicsProxyWidget * proxyWidget
Definition: qwidget_p.h:251
void deactivateWidgetCleanup()
Definition: qwidget.cpp:2496
Q_CORE_EXPORT void qDebug(const char *,...)
QOleDropTarget * dropTarget
Definition: qwidget_p.h:283
HCTX(API * PtrWTOpen)(HWND, LPLOGCONTEXT, BOOL)
unsigned char uchar
Definition: qglobal.h:994
void setParent_helper(QObject *)
Definition: qobject.cpp:1974
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
NSWindow * window
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void createExtra()
Creates the widget extra data.
Definition: qwidget.cpp:1802
void create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
void unsetCursor_sys()
#define QT_WIN_CALLBACK
Definition: qglobal.h:1178
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QRect normalGeometry
Definition: qwidget_p.h:181
QWidget * nativeParentWidget() const
Returns the native parent for this widget, i.
Definition: qwidget.cpp:4514
The QMoveEvent class contains event parameters for move events.
Definition: qevent.h:334
#define HWND_TOPMOST
BOOL(WINAPI * PtrSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags)
Definition: qwidget_win.cpp:80
static PtrWTClose ptrWTClose
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
static QWidget * keyboardGrb
void destroy(bool destroyWindow=true, bool destroySubWindows=true)
Frees up window system resources.
#define WRECT_MAX
void releaseMouse()
Releases the mouse grab.
static QWidget * mouseGrabber()
Returns the widget that is currently grabbing the mouse input.
qint32 maxw
Definition: qwidget_p.h:266
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
#define qApp
QRect frameStrut() const
Definition: qwidget.cpp:12607
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
Qt::WindowFlags window_flags
Definition: qwidget.h:119
qint32 maxh
Definition: qwidget_p.h:267
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void hide_sys()
Platform-specific part of QWidget::hide().
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void setConstraints_sys()
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
void qt_wince_maximize(QWidget *widget)
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
QWidgetData * data
Definition: qwidget.h:815
void updateFrameStrut()
Computes the frame rectangle when needed.
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
BOOL(API * PtrWTOverlap)(HCTX, BOOL)
bool qt_nograb()
unsigned int uint
Definition: qglobal.h:996
#define GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY
void releaseQt()
Definition: qdnd_win.cpp:585
#define FALSE
Synonym for false.
Definition: qglobal.h:1019
static bool HasTouchSupport
static PtrWTOpen ptrWTOpen
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
bool hasStaticContents() const
Qt::WindowFlags savedFlags
Definition: qwidget_p.h:182
static PtrRegisterTouchWindow RegisterTouchWindow
QRect wrect
Definition: qwidget.h:145
static void init_wintab_functions()
QTLWExtra * topData() const
Definition: qwidget_p.h:1004
void setCoords(int x1, int y1, int x2, int y2)
Sets the coordinates of the rectangle&#39;s top-left corner to (x1, y1), and the coordinates of its botto...
Definition: qrect.h:416
unsigned long ulong
Definition: qglobal.h:997
void setWindowTitle_helper(const QString &cap)
Definition: qwidget.cpp:6285
void show()
Shows the widget and its child widgets.
BOOL(API * PtrWTQueueSizeSet)(HCTX, int)
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
void deleteSysExtra()
BOOL(API * PtrWTGet)(HCTX, LPLOGCONTEXT)
#define QT_CATCH(A)
Definition: qglobal.h:1537
static QWidgetSet * allWidgets
Definition: qwidget_p.h:715
#define GWLP_WNDPROC
void qt_wince_minimize(HWND hwnd)
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
The QWindowSurface class provides the drawing area for top-level windows.
static QWidget * parentWidget(const QWidget *w)
void invalidateBuffer(const QRegion &)
Invalidates the rgn (in widget&#39;s coordinates) of the backing store, i.e.
bool qt_tablet_tilt_support
static int qt_primary_surface_stride
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
#define TRUE
Synonym for true.
Definition: qglobal.h:1018
QList< QPointer< QWidget > > oleDropWidgets
Definition: qwidget_p.h:284
void grabKeyboard()
Grabs the keyboard input.
HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int right, int bottom)
Definition: qregion_win.cpp:55
long HRESULT
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QRegion mask
Definition: qwidget_p.h:260
void * resolve(const char *symbol)
const QRect screenGeometry(int screen=-1) const
The QWindowStateChangeEvent class provides the window state before a window state change...
Definition: qevent.h:705
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QTLWExtra * topextra
Definition: qwidget_p.h:249
void qt_win_set_cursor(QWidget *, bool)
QWindowSurface * createDefaultWindowSurface_sys()
static QWidget * mouseGrb
bool begin(QPaintDevice *)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
QPoint pos
the position of the widget within its parent widget
Definition: qwidget.h:163
bool qt_is_gui_used
HICON toWinHICON() const
Returns the HICON handle.
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
LRESULT QT_WIN_CALLBACK qJournalRecordProc(int nCode, WPARAM wParam, LPARAM lParam)
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
static HHOOK journalRec
QPaintEngine * paintEngine() const
Returns the widget&#39;s paint engine.
void setMask_sys(const QRegion &)
#define Q_WS_EX_LAYERED
LRESULT QT_WIN_CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM)
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
Definition: qicon.cpp:730
void createWinId(WId id=0)
Definition: qwidget.cpp:2574
ScrollBarPolicy
Definition: qnamespace.h:1420
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
#define SW_SHOWMINIMIZED
HCTX qt_tablet_context
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QWidget * keyboardGrabber()
Returns the widget that is currently grabbing the keyboard input.
uint opacity
Definition: qwidget_p.h:185
const QString qt_reg_winclass(QWidget *w)
static QCursor * mouseGrbCur
void scroll_sys(int dx, int dy)
bool isAncestorOf(const QWidget *child) const
Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child...
Definition: qwidget.cpp:8573
void setWindowOpacity_sys(qreal opacity)
QWidget * qt_get_tablet_widget()
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
#define GID_PAN
QPixmap * iconPixmap
Definition: qwidget_p.h:165
QWExtra * extra
Definition: qwidget_p.h:700
void releaseKeyboard()
Releases the keyboard grab.
friend class QWidget
Definition: qobject.h:329
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
QString caption
Definition: qwidget_p.h:171
void scrollRect(const QRect &, int dx, int dy)
void activateWindow()
Sets the top-level widget containing this widget to be the active window.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
bool isMinimized() const
Definition: qwidget.cpp:3027
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QObject * parent
Definition: qobject.h:92
void qWinRequestConfig(WId, int, int, int, int, int)
#define Q_ULW_ALPHA
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
Definition: qicon.cpp:693
static QWidgetMapper * mapper
Definition: qwidget_p.h:714
Q_CORE_EXPORT HINSTANCE qWinAppInst()
void createWinId()
Definition: qwidget.cpp:2626
qint32 minh
Definition: qwidget_p.h:265
uint posFromMove
Definition: qwidget_p.h:186
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
Definition: qregion.cpp:4116
static PtrWTQueueSizeGet ptrWTQueueSizeGet
void setWinId(WId)
Definition: qwidget.cpp:1726
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void qt_win_initialize_directdraw()
API
Definition: qegl_p.h:190
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition: qwidget.h:937
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
void createSysExtra()
uint fstrut_dirty
Definition: qwidget.h:126
QWExtra * extraData() const
Definition: qwidget_p.h:999
#define PACKETDATA
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize)
Invalidates the buffer when the widget is resized.
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
void createTLSysExtra()
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QWidgetBackingStoreTracker backingStore
Definition: qwidget_p.h:166
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
QWidgetBackingStore * maybeBackingStore() const
Definition: qwidget_p.h:1036
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56
int maximum() const
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
void updateSystemBackground()
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void qAddPostRoutine(QtCleanUpFunction ptr)
Adds a global routine that will be called from the QApplication destructor.
static void leaveModal(QWidget *)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
void setGeometry_sys(int, int, int, int, bool)
void stackUnder_sys(QWidget *)
#define QT_TRY
Definition: qglobal.h:1536
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
#define INT_MAX
PtrUpdateLayeredWindow ptrUpdateLayeredWindow
QRect effectiveRectFor(const QRect &rect) const
Definition: qwidget_p.h:658
#define WS_THICKFRAME
WId winid
Definition: qwidget.h:117
static PtrSetLayeredWindowAttributes ptrSetLayeredWindowAttributes
Definition: qwidget_win.cpp:81
Handle handle() const
Returns a platform-specific region handle.
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
static QImage::Format qt_primary_surface_format
static Qt::KeyboardModifiers oldstate
Definition: qdnd_qws.cpp:87
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
static PtrWTInfo ptrWTInfo
QCursor * qt_grab_cursor()
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
void setWindowIconText_sys(const QString &cap)
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60
#define GC_PAN