1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** Copyright (C) 2009 netlabs.org. OS/2 parts.
|
---|
7 | **
|
---|
8 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
9 | **
|
---|
10 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
11 | ** Commercial Usage
|
---|
12 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
13 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
14 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
15 | ** a written agreement between you and Nokia.
|
---|
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, Nokia gives you certain
|
---|
26 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
27 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
28 | ** package.
|
---|
29 | **
|
---|
30 | ** GNU General Public License Usage
|
---|
31 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
32 | ** General Public License version 3.0 as published by the Free Software
|
---|
33 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
34 | ** packaging of this file. Please review the following information to
|
---|
35 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
36 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
37 | **
|
---|
38 | ** If you are unsure which license is appropriate for your use, please
|
---|
39 | ** contact the sales department at [email protected].
|
---|
40 | ** $QT_END_LICENSE$
|
---|
41 | **
|
---|
42 | ****************************************************************************/
|
---|
43 |
|
---|
44 | #include "qt_os2.h"
|
---|
45 |
|
---|
46 | #include "qdebug.h"
|
---|
47 |
|
---|
48 | #include "qapplication.h"
|
---|
49 | #include "qapplication_p.h"
|
---|
50 |
|
---|
51 | #include "qwidget.h"
|
---|
52 | #include "qpointer.h"
|
---|
53 | #include "qcolormap.h"
|
---|
54 | #include "qpixmapcache.h"
|
---|
55 | #include "qdesktopwidget.h"
|
---|
56 |
|
---|
57 | #include "qset.h"
|
---|
58 |
|
---|
59 | #include "private/qeventdispatcher_pm_p.h"
|
---|
60 | #include "private/qbackingstore_p.h"
|
---|
61 |
|
---|
62 | #include "qwidget_p.h"
|
---|
63 | #include "qkeymapper_p.h"
|
---|
64 | #include "qcursor_p.h"
|
---|
65 |
|
---|
66 | //#define QT_DEBUGMSGFLOW
|
---|
67 |
|
---|
68 | QT_BEGIN_NAMESPACE
|
---|
69 |
|
---|
70 | /*****************************************************************************
|
---|
71 | Internal variables and functions
|
---|
72 | *****************************************************************************/
|
---|
73 |
|
---|
74 | static HWND curWin = 0; // current window
|
---|
75 | static HPS displayPS = 0; // display presentation space
|
---|
76 |
|
---|
77 | #if !defined (QT_NO_SESSIONMANAGER)
|
---|
78 |
|
---|
79 | // Session management
|
---|
80 | static bool sm_blockUserInput = FALSE;
|
---|
81 |
|
---|
82 | //#define DEBUG_SESSIONMANAGER
|
---|
83 |
|
---|
84 | #endif
|
---|
85 |
|
---|
86 | static bool replayPopupMouseEvent = false; // replay handling when popups close
|
---|
87 |
|
---|
88 | // ignore the next release event if return from a modal widget
|
---|
89 | static bool ignoreNextMouseReleaseEvent = false;
|
---|
90 |
|
---|
91 | #if defined(QT_DEBUG)
|
---|
92 | static bool appNoGrab = false; // mouse/keyboard grabbing
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | static bool app_do_modal = false; // modal mode
|
---|
96 | extern QWidgetList *qt_modal_stack;
|
---|
97 | extern QDesktopWidget *qt_desktopWidget;
|
---|
98 | static QPointer<QWidget> popupButtonFocus;
|
---|
99 | static bool qt_try_modal(QWidget*, QMSG*, MRESULT&);
|
---|
100 |
|
---|
101 | QWidget *qt_button_down = 0; // widget got last button-down
|
---|
102 | QPointer<QWidget> qt_last_mouse_receiver = 0;
|
---|
103 |
|
---|
104 | static HWND autoCaptureWnd = NULLHANDLE;
|
---|
105 | static bool autoCaptureReleased = FALSE;
|
---|
106 | static void setAutoCapture(HWND); // automatic capture
|
---|
107 | static void releaseAutoCapture();
|
---|
108 |
|
---|
109 | extern QCursor *qt_grab_cursor();
|
---|
110 |
|
---|
111 | extern void qt_WinQueryClipRegionOrRect(HWND hwnd, HRGN hrgn); // qwidget_pm.cpp
|
---|
112 |
|
---|
113 | extern QRegion qt_dirtyRegion(QWidget *); // qbackingstore.cpp
|
---|
114 |
|
---|
115 | MRESULT EXPENTRY QtWndProc(HWND, ULONG, MPARAM, MPARAM);
|
---|
116 |
|
---|
117 | class QETWidget : public QWidget // event translator widget
|
---|
118 | {
|
---|
119 | public:
|
---|
120 | QWExtra *xtra() { return d_func()->extraData(); }
|
---|
121 | QTLWExtra *topData() { return d_func()->topData(); }
|
---|
122 | QTLWExtra *maybeTopData() { return d_func()->maybeTopData(); }
|
---|
123 | // @todo later
|
---|
124 | // void syncBackingStore(const QRegion &rgn) { d_func()->syncBackingStore(rgn); }
|
---|
125 | // void syncBackingStore() { d_func()->syncBackingStore(); }
|
---|
126 | QWidgetData *dataPtr() { return data; }
|
---|
127 | QWidgetPrivate *dptr() { return d_func(); }
|
---|
128 | QRect frameStrut() const { return d_func()->frameStrut(); }
|
---|
129 | bool pmEvent(QMSG *m, MRESULT *r) { return QWidget::pmEvent(m, r); }
|
---|
130 | // void markFrameStrutDirty() { data->fstrut_dirty = 1; }
|
---|
131 | bool translateMouseEvent(const QMSG &qmsg);
|
---|
132 | #ifndef QT_NO_WHEELEVENT
|
---|
133 | bool translateWheelEvent(const QMSG &qmsg);
|
---|
134 | #endif
|
---|
135 | bool translatePaintEvent(const QMSG &qmsg);
|
---|
136 | bool translateConfigEvent(const QMSG &qmsg);
|
---|
137 | bool translateCloseEvent(const QMSG &qmsg);
|
---|
138 | // void repolishStyle(QStyle &style);
|
---|
139 | // inline void showChildren(bool spontaneous) { d_func()->showChildren(spontaneous); }
|
---|
140 | // inline void hideChildren(bool spontaneous) { d_func()->hideChildren(spontaneous); }
|
---|
141 | // inline void validateObstacles() { d_func()->validateObstacles(); }
|
---|
142 | // inline uint testWindowState(uint teststate){ return dataPtr()->window_state & teststate; }
|
---|
143 | // inline void forceUpdate() {
|
---|
144 | // QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
|
---|
145 | // if (tlwExtra && tlwExtra->backingStore)
|
---|
146 | // tlwExtra->backingStore->markDirty(rect(), this, true, true);
|
---|
147 | // }
|
---|
148 | };
|
---|
149 |
|
---|
150 | static QRgb qt_sysclr2qrgb(LONG sysClr)
|
---|
151 | {
|
---|
152 | // QRgb has the same RGB format (0xaarrggbb) as OS/2 uses (ignoring the
|
---|
153 | // highest alpha byte) so we just cast the OS/2 LONG RGB value to qRgb
|
---|
154 | // which is an unsigned int actually.
|
---|
155 | return ((QRgb)WinQuerySysColor(HWND_DESKTOP, sysClr, 0)) & RGB_MASK;
|
---|
156 | }
|
---|
157 |
|
---|
158 | static QFont qt_sysfont2qfont(const PSZ scope)
|
---|
159 | {
|
---|
160 | // note: 10.System Proportional is de-facto the default font selected into
|
---|
161 | // the presentation space
|
---|
162 |
|
---|
163 | static const PSZ app = "PM_SystemFonts";
|
---|
164 | static const PSZ def = "10.System Proportional";
|
---|
165 |
|
---|
166 | ULONG keyLen = 0;
|
---|
167 | QFont f("System Proportional", 10);
|
---|
168 |
|
---|
169 | if (PrfQueryProfileSize(HINI_USERPROFILE, app, scope, &keyLen) && keyLen) {
|
---|
170 | keyLen++; // reserve space for the dot
|
---|
171 | char *buf = new char[keyLen];
|
---|
172 | ULONG realLen = PrfQueryProfileString(HINI_USERPROFILE, app, scope, def,
|
---|
173 | buf, keyLen);
|
---|
174 | realLen--; // excude terminating NULL
|
---|
175 |
|
---|
176 | // parse the font definition
|
---|
177 | int height = 0;
|
---|
178 | char *dot = strchr(buf, '.'), *dot2 = 0;
|
---|
179 | if (dot) {
|
---|
180 | *dot = 0;
|
---|
181 | height = strtoul(buf, NULL, 10);
|
---|
182 | dot2 = strchr(++ dot, '.');
|
---|
183 | if (dot2) {
|
---|
184 | // process simulated styles
|
---|
185 | buf[realLen] = '.';
|
---|
186 | buf[realLen+1] = 0;
|
---|
187 | strupr( dot2 );
|
---|
188 | // @todo currently, simulated bold and italic font styles are not
|
---|
189 | // supported by Qt/OS2 because Qt doesn't support style simulation
|
---|
190 | // explicitly. the code below is commented out to prevent selecting
|
---|
191 | // true fonts when simulated ones are actually requested.
|
---|
192 | // if (strstr(dot2, ".BOLD.")) f.setBold(true);
|
---|
193 | // if (strstr(dot2, ".ITALIC.")) f.setItalic(true);
|
---|
194 | if (strstr(dot2, ".UNDERSCORE.")) f.setUnderline(true);
|
---|
195 | if (strstr(dot2, ".UNDERLINED.")) f.setUnderline(true);
|
---|
196 | if (strstr(dot2, ".STRIKEOUT.")) f.setStrikeOut(true);
|
---|
197 | *dot2 = 0;
|
---|
198 | }
|
---|
199 | // query non-simulated styles
|
---|
200 | FONTMETRICS fm;
|
---|
201 | LONG cnt = 1; // use the first match
|
---|
202 | GpiQueryFonts(qt_display_ps(), QF_PUBLIC, dot, &cnt, sizeof(FONTMETRICS), &fm);
|
---|
203 | if (cnt) {
|
---|
204 | if (fm.fsSelection & FM_SEL_ITALIC) f.setItalic(true);
|
---|
205 | if (fm.fsType & FM_TYPE_FIXED) f.setFixedPitch(true);
|
---|
206 | USHORT weight = fm.usWeightClass;
|
---|
207 | USHORT width = fm.usWidthClass;
|
---|
208 | if (weight < 4) f.setWeight( QFont::Light );
|
---|
209 | else if (weight < 6) f.setWeight(QFont::Normal);
|
---|
210 | else if (weight < 7) f.setWeight(QFont::DemiBold);
|
---|
211 | else if (weight < 8) f.setWeight(QFont::Bold);
|
---|
212 | else f.setWeight(QFont::Black);
|
---|
213 | switch (width) {
|
---|
214 | case 1: f.setStretch(QFont::UltraCondensed); break;
|
---|
215 | case 2: f.setStretch(QFont::ExtraCondensed); break;
|
---|
216 | case 3: f.setStretch(QFont::Condensed); break;
|
---|
217 | case 4: f.setStretch(QFont::SemiCondensed); break;
|
---|
218 | case 5: f.setStretch(QFont::Unstretched); break;
|
---|
219 | case 6: f.setStretch(QFont::SemiExpanded); break;
|
---|
220 | case 7: f.setStretch(QFont::Expanded); break;
|
---|
221 | case 8: f.setStretch(QFont::ExtraExpanded); break;
|
---|
222 | case 9: f.setStretch(QFont::UltraExpanded); break;
|
---|
223 | default: f.setStretch(QFont::Unstretched); break;
|
---|
224 | }
|
---|
225 | f.setFamily(fm.szFamilyname);
|
---|
226 | f.setPointSize(height);
|
---|
227 | }
|
---|
228 | }
|
---|
229 | delete[] buf;
|
---|
230 | }
|
---|
231 | return f;
|
---|
232 | }
|
---|
233 |
|
---|
234 | static void qt_set_pm_resources()
|
---|
235 | {
|
---|
236 | QFont menuFont = qt_sysfont2qfont("Menus");
|
---|
237 | QFont iconFont = qt_sysfont2qfont("IconText");
|
---|
238 | QFont titleFont = qt_sysfont2qfont("WindowTitles");
|
---|
239 |
|
---|
240 | QApplication::setFont(menuFont, "QMenu");
|
---|
241 | QApplication::setFont(menuFont, "QMenuBar");
|
---|
242 | QApplication::setFont(titleFont, "Q3TitleBar");
|
---|
243 | QApplication::setFont(titleFont, "QWorkspaceTitleBar");
|
---|
244 | QApplication::setFont(iconFont, "QAbstractItemView");
|
---|
245 | QApplication::setFont(iconFont, "QDockWidgetTitle");
|
---|
246 |
|
---|
247 | // let QPallette calculate all colors automatically based on the
|
---|
248 | // base PM window background color -- to be on the safe side in case if we
|
---|
249 | // don't set some role explicitly below (like QPalette::AlternateBase)
|
---|
250 | QPalette pal = QPalette(QColor(qt_sysclr2qrgb(SYSCLR_DIALOGBACKGROUND)));
|
---|
251 |
|
---|
252 | pal.setColor(QPalette::WindowText,
|
---|
253 | QColor(qt_sysclr2qrgb(SYSCLR_WINDOWTEXT)));
|
---|
254 | pal.setColor(QPalette::Window,
|
---|
255 | QColor(qt_sysclr2qrgb(SYSCLR_DIALOGBACKGROUND)));
|
---|
256 | pal.setColor(QPalette::ButtonText,
|
---|
257 | QColor(qt_sysclr2qrgb(SYSCLR_MENUTEXT)));
|
---|
258 | pal.setColor(QPalette::Button,
|
---|
259 | QColor(qt_sysclr2qrgb(SYSCLR_BUTTONMIDDLE)));
|
---|
260 | pal.setColor(QPalette::Light,
|
---|
261 | QColor(qt_sysclr2qrgb(SYSCLR_BUTTONLIGHT)));
|
---|
262 | pal.setColor(QPalette::Dark,
|
---|
263 | QColor(qt_sysclr2qrgb(SYSCLR_BUTTONDARK)));
|
---|
264 | pal.setColor(QPalette::Midlight,
|
---|
265 | QColor((pal.light().color().red() + pal.button().color().red()) / 2,
|
---|
266 | (pal.light().color().green() + pal.button().color().green()) / 2,
|
---|
267 | (pal.light().color().blue() + pal.button().color().blue()) / 2));
|
---|
268 | pal.setColor(QPalette::Mid,
|
---|
269 | QColor((pal.dark().color().red() + pal.button().color().red()) / 2,
|
---|
270 | (pal.dark().color().green() + pal.button().color().green()) / 2,
|
---|
271 | (pal.dark().color().blue() + pal.button().color().blue()) / 2));
|
---|
272 | pal.setColor(QPalette::Shadow, // note: SYSCLR_SHADOW often = SYSCLR_BUTTONDARK
|
---|
273 | QColor(qt_sysclr2qrgb(SYSCLR_BUTTONDEFAULT)));
|
---|
274 | pal.setColor(QPalette::Text,
|
---|
275 | QColor(qt_sysclr2qrgb(SYSCLR_WINDOWTEXT)));
|
---|
276 | pal.setColor(QPalette::Base,
|
---|
277 | QColor(qt_sysclr2qrgb(SYSCLR_ENTRYFIELD)));
|
---|
278 | pal.setColor(QPalette::BrightText,
|
---|
279 | QColor(qt_sysclr2qrgb(SYSCLR_BUTTONLIGHT)));
|
---|
280 | pal.setColor(QPalette::Highlight,
|
---|
281 | QColor(qt_sysclr2qrgb(SYSCLR_HILITEBACKGROUND)));
|
---|
282 | pal.setColor(QPalette::HighlightedText,
|
---|
283 | QColor(qt_sysclr2qrgb(SYSCLR_HILITEFOREGROUND)));
|
---|
284 | // these colors are not present in the PM system palette
|
---|
285 | pal.setColor(QPalette::Link, Qt::blue);
|
---|
286 | pal.setColor(QPalette::LinkVisited, Qt::magenta);
|
---|
287 |
|
---|
288 | // disabled colors
|
---|
289 | // note: it should be SYSCLR_MENUDISABLEDTEXT but many styles use etched
|
---|
290 | // appearance for disabled elements (in combination with QPalette::Light)
|
---|
291 | // which gives weakly readable text. Make it somewhat darker.
|
---|
292 | pal.setColor(QPalette::Disabled, QPalette::WindowText,
|
---|
293 | QColor(qt_sysclr2qrgb(SYSCLR_BUTTONDARK)));
|
---|
294 | pal.setColor(QPalette::Disabled, QPalette::ButtonText,
|
---|
295 | QColor(qt_sysclr2qrgb(SYSCLR_BUTTONDARK)));
|
---|
296 | pal.setColor(QPalette::Disabled, QPalette::Text,
|
---|
297 | QColor(qt_sysclr2qrgb(SYSCLR_BUTTONDARK)));
|
---|
298 |
|
---|
299 | QApplicationPrivate::setSystemPalette(pal);
|
---|
300 |
|
---|
301 | // special palete: menus
|
---|
302 | QPalette spal = pal;
|
---|
303 | spal.setColor(QPalette::Window,
|
---|
304 | QColor(qt_sysclr2qrgb(SYSCLR_MENU)));
|
---|
305 | spal.setColor(QPalette::WindowText,
|
---|
306 | QColor(qt_sysclr2qrgb(SYSCLR_MENUTEXT)));
|
---|
307 | spal.setColor(QPalette::Highlight,
|
---|
308 | QColor(qt_sysclr2qrgb( SYSCLR_MENUHILITEBGND)));
|
---|
309 | spal.setColor(QPalette::HighlightedText,
|
---|
310 | QColor(qt_sysclr2qrgb(SYSCLR_MENUHILITE)));
|
---|
311 |
|
---|
312 | QApplication::setPalette(spal, "QMenu");
|
---|
313 | QApplication::setPalette(spal, "QMenuBar");
|
---|
314 |
|
---|
315 | // special palete: static widget text
|
---|
316 | spal = pal;
|
---|
317 | QColor staticTextCol(qt_sysclr2qrgb( SYSCLR_WINDOWSTATICTEXT));
|
---|
318 | spal.setColor(QPalette::WindowText, staticTextCol);
|
---|
319 | spal.setColor(QPalette::Text, staticTextCol);
|
---|
320 |
|
---|
321 | QApplication::setPalette(spal, "QLabel");
|
---|
322 | QApplication::setPalette(spal, "QGroupBox");
|
---|
323 | };
|
---|
324 |
|
---|
325 | /*****************************************************************************
|
---|
326 | qt_init() - initializes Qt for PM
|
---|
327 | *****************************************************************************/
|
---|
328 |
|
---|
329 | void qt_init(QApplicationPrivate *priv, int)
|
---|
330 | {
|
---|
331 |
|
---|
332 | int argc = priv->argc;
|
---|
333 | char **argv = priv->argv;
|
---|
334 | int i, j;
|
---|
335 |
|
---|
336 | // Get command line params
|
---|
337 |
|
---|
338 | j = argc ? 1 : 0;
|
---|
339 | for (i=1; i<argc; i++) {
|
---|
340 | if (argv[i] && *argv[i] != '-') {
|
---|
341 | argv[j++] = argv[i];
|
---|
342 | continue;
|
---|
343 | }
|
---|
344 | #if defined(QT_DEBUG)
|
---|
345 | if (qstrcmp(argv[i], "-nograb") == 0)
|
---|
346 | appNoGrab = !appNoGrab;
|
---|
347 | else
|
---|
348 | #endif // QT_DEBUG
|
---|
349 | argv[j++] = argv[i];
|
---|
350 | }
|
---|
351 | if(j < priv->argc) {
|
---|
352 | priv->argv[j] = 0;
|
---|
353 | priv->argc = j;
|
---|
354 | }
|
---|
355 |
|
---|
356 | // initialize key mapper
|
---|
357 | QKeyMapper::changeKeyboard();
|
---|
358 |
|
---|
359 | QColormap::initialize();
|
---|
360 | QFont::initialize();
|
---|
361 | #ifndef QT_NO_CURSOR
|
---|
362 | QCursorData::initialize();
|
---|
363 | #endif
|
---|
364 | qApp->setObjectName(priv->appName());
|
---|
365 |
|
---|
366 | // @todo search for QTPM_USE_WINDOWFONT in Qt3 for OS/2 sources for a
|
---|
367 | // discussion on whether to use PM_Fonts/DefaultFont or WindowText as the
|
---|
368 | // default one. So far, the latter is used.
|
---|
369 | QApplicationPrivate::setSystemFont(qt_sysfont2qfont("WindowText"));
|
---|
370 |
|
---|
371 | // QFont::locale_init(); ### Uncomment when it does something on OS/2
|
---|
372 |
|
---|
373 | if (QApplication::desktopSettingsAware())
|
---|
374 | qt_set_pm_resources();
|
---|
375 | }
|
---|
376 |
|
---|
377 | /*****************************************************************************
|
---|
378 | qt_cleanup() - cleans up when the application is finished
|
---|
379 | *****************************************************************************/
|
---|
380 |
|
---|
381 | void qt_cleanup()
|
---|
382 | {
|
---|
383 | QPixmapCache::clear();
|
---|
384 |
|
---|
385 | #ifndef QT_NO_CURSOR
|
---|
386 | QCursorData::cleanup();
|
---|
387 | #endif
|
---|
388 | QFont::cleanup();
|
---|
389 | QColormap::cleanup();
|
---|
390 |
|
---|
391 | if (displayPS) {
|
---|
392 | WinReleasePS(displayPS);
|
---|
393 | displayPS = 0;
|
---|
394 | }
|
---|
395 |
|
---|
396 | #ifdef QT_LOG_BLITSPEED
|
---|
397 | extern unsigned long long qt_total_blit_ms;
|
---|
398 | extern unsigned long long qt_total_blit_pixels;
|
---|
399 | printf("*** qt_total_blit_ms %llu\n"
|
---|
400 | "*** qt_total_blit_pixels %llu\n"
|
---|
401 | "*** speed %llu pixels/ms",
|
---|
402 | qt_total_blit_ms, qt_total_blit_pixels,
|
---|
403 | qt_total_blit_pixels / qt_total_blit_ms);
|
---|
404 | #endif
|
---|
405 | }
|
---|
406 |
|
---|
407 | /*****************************************************************************
|
---|
408 | Platform specific global and internal functions
|
---|
409 | *****************************************************************************/
|
---|
410 |
|
---|
411 | Q_GUI_EXPORT HPS qt_display_ps()
|
---|
412 | {
|
---|
413 | Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());
|
---|
414 | if (!displayPS)
|
---|
415 | displayPS = WinGetScreenPS(HWND_DESKTOP);
|
---|
416 | return displayPS;
|
---|
417 | }
|
---|
418 |
|
---|
419 | // application no-grab option
|
---|
420 | bool qt_nograb()
|
---|
421 | {
|
---|
422 | #if defined(QT_DEBUG)
|
---|
423 | return appNoGrab;
|
---|
424 | #else
|
---|
425 | return false;
|
---|
426 | #endif
|
---|
427 | }
|
---|
428 |
|
---|
429 | /*****************************************************************************
|
---|
430 | Safe configuration (move,resize,setGeometry) mechanism to avoid
|
---|
431 | recursion when processing messages.
|
---|
432 | *****************************************************************************/
|
---|
433 |
|
---|
434 | struct QPMConfigRequest {
|
---|
435 | WId id; // widget to be configured
|
---|
436 | int req; // 0=move, 1=resize, 2=setGeo
|
---|
437 | int x, y, w, h; // request parameters
|
---|
438 | };
|
---|
439 |
|
---|
440 | Q_GLOBAL_STATIC(QList<QPMConfigRequest*>, configRequests);
|
---|
441 |
|
---|
442 | void qPMRequestConfig(WId id, int req, int x, int y, int w, int h)
|
---|
443 | {
|
---|
444 | QPMConfigRequest *r = new QPMConfigRequest;
|
---|
445 | r->id = id;
|
---|
446 | r->req = req;
|
---|
447 | r->x = x;
|
---|
448 | r->y = y;
|
---|
449 | r->w = w;
|
---|
450 | r->h = h;
|
---|
451 | configRequests()->append(r);
|
---|
452 | }
|
---|
453 |
|
---|
454 | /*****************************************************************************
|
---|
455 | GUI event dispatcher
|
---|
456 | *****************************************************************************/
|
---|
457 |
|
---|
458 | class QGuiEventDispatcherPM : public QEventDispatcherPM
|
---|
459 | {
|
---|
460 | public:
|
---|
461 | QGuiEventDispatcherPM(QObject *parent = 0);
|
---|
462 | bool processEvents(QEventLoop::ProcessEventsFlags flags);
|
---|
463 | };
|
---|
464 |
|
---|
465 | QGuiEventDispatcherPM::QGuiEventDispatcherPM(QObject *parent)
|
---|
466 | : QEventDispatcherPM(parent)
|
---|
467 | {
|
---|
468 | // pre-create the message queue early as we'll need it anyway in GUI mode
|
---|
469 | createMsgQueue();
|
---|
470 | }
|
---|
471 |
|
---|
472 | bool QGuiEventDispatcherPM::processEvents(QEventLoop::ProcessEventsFlags flags)
|
---|
473 | {
|
---|
474 | if (!QEventDispatcherPM::processEvents(flags))
|
---|
475 | return false;
|
---|
476 |
|
---|
477 | QPMConfigRequest *r;
|
---|
478 | for (;;) {
|
---|
479 | if (configRequests()->isEmpty())
|
---|
480 | break;
|
---|
481 | r = configRequests()->takeLast();
|
---|
482 | QWidget *w = QWidget::find(r->id);
|
---|
483 | QRect rect(r->x, r->y, r->w, r->h);
|
---|
484 | int req = r->req;
|
---|
485 | delete r;
|
---|
486 |
|
---|
487 | if (w) { // widget exists
|
---|
488 | if (w->testAttribute(Qt::WA_WState_ConfigPending))
|
---|
489 | break; // biting our tail
|
---|
490 | if (req == 0)
|
---|
491 | w->move(rect.topLeft());
|
---|
492 | else if (req == 1)
|
---|
493 | w->resize(rect.size());
|
---|
494 | else
|
---|
495 | w->setGeometry(rect);
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | return true;
|
---|
500 | }
|
---|
501 |
|
---|
502 | void QApplicationPrivate::createEventDispatcher()
|
---|
503 | {
|
---|
504 | Q_Q(QApplication);
|
---|
505 | if (q->type() != QApplication::Tty)
|
---|
506 | eventDispatcher = new QGuiEventDispatcherPM(q);
|
---|
507 | else
|
---|
508 | eventDispatcher = new QEventDispatcherPM(q);
|
---|
509 | }
|
---|
510 |
|
---|
511 | /*****************************************************************************
|
---|
512 | Platform specific QApplication members
|
---|
513 | *****************************************************************************/
|
---|
514 |
|
---|
515 | void QApplicationPrivate::initializeWidgetPaletteHash()
|
---|
516 | {
|
---|
517 | }
|
---|
518 |
|
---|
519 | QString QApplicationPrivate::appName() const
|
---|
520 | {
|
---|
521 | return QCoreApplicationPrivate::appName();
|
---|
522 | }
|
---|
523 |
|
---|
524 | void QApplication::setCursorFlashTime(int msecs)
|
---|
525 | {
|
---|
526 | WinSetSysValue(HWND_DESKTOP, SV_CURSORRATE, msecs / 2);
|
---|
527 | QApplicationPrivate::cursor_flash_time = msecs;
|
---|
528 | }
|
---|
529 |
|
---|
530 | int QApplication::cursorFlashTime()
|
---|
531 | {
|
---|
532 | int blink = (int)WinQuerySysValue(HWND_DESKTOP, SV_CURSORRATE);
|
---|
533 | if (!blink)
|
---|
534 | return QApplicationPrivate::cursor_flash_time;
|
---|
535 | if (blink > 0)
|
---|
536 | return 2 * blink;
|
---|
537 | return 0;
|
---|
538 | }
|
---|
539 |
|
---|
540 | void QApplication::setDoubleClickInterval(int ms)
|
---|
541 | {
|
---|
542 | WinSetSysValue(HWND_DESKTOP, SV_DBLCLKTIME, ms);
|
---|
543 | QApplicationPrivate::mouse_double_click_time = ms;
|
---|
544 | }
|
---|
545 |
|
---|
546 | int QApplication::doubleClickInterval()
|
---|
547 | {
|
---|
548 | int ms = (int) WinQuerySysValue(HWND_DESKTOP, SV_DBLCLKTIME);
|
---|
549 | if (ms != 0)
|
---|
550 | return ms;
|
---|
551 | return QApplicationPrivate::mouse_double_click_time;
|
---|
552 | }
|
---|
553 |
|
---|
554 | void QApplication::setKeyboardInputInterval(int ms)
|
---|
555 | {
|
---|
556 | QApplicationPrivate::keyboard_input_time = ms;
|
---|
557 | }
|
---|
558 |
|
---|
559 | int QApplication::keyboardInputInterval()
|
---|
560 | {
|
---|
561 | // FIXME: get from the system
|
---|
562 | return QApplicationPrivate::keyboard_input_time;
|
---|
563 | }
|
---|
564 |
|
---|
565 | #ifndef QT_NO_WHEELEVENT
|
---|
566 | void QApplication::setWheelScrollLines(int n)
|
---|
567 | {
|
---|
568 | QApplicationPrivate::wheel_scroll_lines = n;
|
---|
569 | }
|
---|
570 |
|
---|
571 | int QApplication::wheelScrollLines()
|
---|
572 | {
|
---|
573 | return QApplicationPrivate::wheel_scroll_lines;
|
---|
574 | }
|
---|
575 | #endif //QT_NO_WHEELEVENT
|
---|
576 |
|
---|
577 | void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)
|
---|
578 | {
|
---|
579 | // @todo implement
|
---|
580 | }
|
---|
581 |
|
---|
582 | bool QApplication::isEffectEnabled(Qt::UIEffect effect)
|
---|
583 | {
|
---|
584 | // @todo implement
|
---|
585 | return false;
|
---|
586 | }
|
---|
587 |
|
---|
588 | void QApplication::beep()
|
---|
589 | {
|
---|
590 | WinAlarm(HWND_DESKTOP, WA_WARNING);
|
---|
591 | }
|
---|
592 |
|
---|
593 | void QApplication::alert(QWidget *widget, int duration)
|
---|
594 | {
|
---|
595 | // @todo implement
|
---|
596 | }
|
---|
597 |
|
---|
598 | /*****************************************************************************
|
---|
599 | QApplication cursor stack
|
---|
600 | *****************************************************************************/
|
---|
601 |
|
---|
602 | #ifndef QT_NO_CURSOR
|
---|
603 |
|
---|
604 | void QApplication::setOverrideCursor(const QCursor &cursor)
|
---|
605 | {
|
---|
606 | qApp->d_func()->cursor_list.prepend(cursor);
|
---|
607 | WinSetPointer(HWND_DESKTOP, qApp->d_func()->cursor_list.first().handle());
|
---|
608 | }
|
---|
609 |
|
---|
610 | void QApplication::restoreOverrideCursor()
|
---|
611 | {
|
---|
612 | if (qApp->d_func()->cursor_list.isEmpty())
|
---|
613 | return;
|
---|
614 | qApp->d_func()->cursor_list.removeFirst();
|
---|
615 |
|
---|
616 | if (!qApp->d_func()->cursor_list.isEmpty()) {
|
---|
617 | WinSetPointer(HWND_DESKTOP, qApp->d_func()->cursor_list.first().handle());
|
---|
618 | } else {
|
---|
619 | QWidget *w = QWidget::find(curWin);
|
---|
620 | if (w)
|
---|
621 | WinSetPointer(HWND_DESKTOP, w->cursor().handle());
|
---|
622 | else
|
---|
623 | WinSetPointer(HWND_DESKTOP, QCursor(Qt::ArrowCursor).handle());
|
---|
624 | }
|
---|
625 | }
|
---|
626 |
|
---|
627 | /*
|
---|
628 | Internal function called from QWidget::setCursor()
|
---|
629 | force is true if this function is called from dispatchEnterLeave, it means that the
|
---|
630 | mouse is actually directly under this widget.
|
---|
631 | */
|
---|
632 | void qt_pm_set_cursor(QWidget *w, bool force)
|
---|
633 | {
|
---|
634 | static QPointer<QWidget> lastUnderMouse = 0;
|
---|
635 | if (force) {
|
---|
636 | lastUnderMouse = w;
|
---|
637 | } else if (w->testAttribute(Qt::WA_WState_Created) && lastUnderMouse
|
---|
638 | && lastUnderMouse->effectiveWinId() == w->effectiveWinId()) {
|
---|
639 | w = lastUnderMouse;
|
---|
640 | }
|
---|
641 |
|
---|
642 | if (!curWin && w && w->internalWinId())
|
---|
643 | return;
|
---|
644 | QWidget* cW = w && !w->internalWinId() ? w : QWidget::find(curWin);
|
---|
645 | if (!cW || cW->window() != w->window() ||
|
---|
646 | !cW->isVisible() || !cW->underMouse() || QApplication::overrideCursor())
|
---|
647 | return;
|
---|
648 |
|
---|
649 | WinSetPointer(HWND_DESKTOP, cW->cursor().handle());
|
---|
650 | }
|
---|
651 |
|
---|
652 | #endif // QT_NO_CURSOR
|
---|
653 |
|
---|
654 | /*****************************************************************************
|
---|
655 | Routines to find a Qt widget from a screen position
|
---|
656 | *****************************************************************************/
|
---|
657 |
|
---|
658 | QWidget *QApplication::topLevelAt(const QPoint &pos)
|
---|
659 | {
|
---|
660 | // flip y coordinate
|
---|
661 | int y = desktop()->height() - (pos.y() + 1);
|
---|
662 | POINTL ptl = { pos.x(), y };
|
---|
663 | HWND hwnd = WinWindowFromPoint(HWND_DESKTOP, &ptl, FALSE);
|
---|
664 | if (hwnd == NULLHANDLE)
|
---|
665 | return 0;
|
---|
666 |
|
---|
667 | QWidget *w = qWidgetFromHWND(hwnd);
|
---|
668 | return w ? w->window() : 0;
|
---|
669 | }
|
---|
670 |
|
---|
671 | /*****************************************************************************
|
---|
672 | Main event loop
|
---|
673 | *****************************************************************************/
|
---|
674 |
|
---|
675 | // sent to hwnd that has been entered to by a mouse pointer.
|
---|
676 | // FID_CLIENT also receives enter messages of its WC_FRAME.
|
---|
677 | // mp1 = hwnd that is entered, mp2 = hwnd that is left
|
---|
678 | #define WM_U_MOUSEENTER 0x41E
|
---|
679 | // sent to hwnd that has been left by a mouse pointer.
|
---|
680 | // FID_CLIENT also receives leave messages of its WC_FRAME.
|
---|
681 | // mp1 = hwnd that is left, mp2 = hwnd that is entered
|
---|
682 | #define WM_U_MOUSELEAVE 0x41F
|
---|
683 |
|
---|
684 | // some undocumented system values
|
---|
685 | #define SV_WORKAREA_YTOP 51
|
---|
686 | #define SV_WORKAREA_YBOTTOM 52
|
---|
687 | #define SV_WORKAREA_XRIGHT 53
|
---|
688 | #define SV_WORKAREA_XLEFT 54
|
---|
689 |
|
---|
690 | /*!
|
---|
691 | \internal
|
---|
692 | \since 4.1
|
---|
693 |
|
---|
694 | If \a gotFocus is true, \a widget will become the active window.
|
---|
695 | Otherwise the active window is reset to 0.
|
---|
696 | */
|
---|
697 | void QApplication::pmFocus(QWidget *widget, bool gotFocus)
|
---|
698 | {
|
---|
699 | if (gotFocus) {
|
---|
700 | setActiveWindow(widget);
|
---|
701 | if (QApplicationPrivate::active_window
|
---|
702 | && (QApplicationPrivate::active_window->windowType() == Qt::Dialog)) {
|
---|
703 | // raise the entire application, not just the dialog
|
---|
704 | QWidget* mw = QApplicationPrivate::active_window;
|
---|
705 | while(mw->parentWidget() && (mw->windowType() == Qt::Dialog))
|
---|
706 | mw = mw->parentWidget()->window();
|
---|
707 | if (mw->testAttribute(Qt::WA_WState_Created) && mw != QApplicationPrivate::active_window)
|
---|
708 | WinSetWindowPos(mw->d_func()->frameWinId(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
|
---|
709 | }
|
---|
710 | } else {
|
---|
711 | setActiveWindow(0);
|
---|
712 | }
|
---|
713 | }
|
---|
714 |
|
---|
715 | // QtWndProc() receives all messages from the main event loop
|
---|
716 |
|
---|
717 | MRESULT EXPENTRY QtWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
718 | {
|
---|
719 | do {
|
---|
720 | if (!qApp) // unstable app state
|
---|
721 | break;
|
---|
722 | #if 0
|
---|
723 | // make sure we show widgets (e.g. scrollbars) when the user resizes
|
---|
724 | if (qApp->loopLevel())
|
---|
725 | qApp->sendPostedEvents(0, QEvent::ShowWindowRequest);
|
---|
726 | #endif
|
---|
727 |
|
---|
728 | MRESULT rc = (MRESULT) FALSE;
|
---|
729 | QETWidget *widget = 0;
|
---|
730 |
|
---|
731 | bool isTranslatableMouseEvent =
|
---|
732 | (msg >= WM_MOUSEFIRST && msg <= WM_MOUSELAST) ||
|
---|
733 | (msg >= WM_EXTMOUSEFIRST && msg <= WM_EXTMOUSELAST);
|
---|
734 |
|
---|
735 | QMSG qmsg; // create QMSG structure
|
---|
736 | qmsg.hwnd = hwnd;
|
---|
737 | qmsg.msg = msg;
|
---|
738 | qmsg.mp1 = mp1;
|
---|
739 | qmsg.mp2 = mp2;
|
---|
740 | qmsg.time = WinQueryMsgTime(0);
|
---|
741 |
|
---|
742 | if (isTranslatableMouseEvent || msg == WM_CONTEXTMENU) {
|
---|
743 | qmsg.ptl.x = (short)SHORT1FROMMP(mp1);
|
---|
744 | qmsg.ptl.y = (short)SHORT2FROMMP(mp1);
|
---|
745 | WinMapWindowPoints(qmsg.hwnd, HWND_DESKTOP, &qmsg.ptl, 1);
|
---|
746 | } else {
|
---|
747 | WinQueryMsgPos(0, &qmsg.ptl);
|
---|
748 | }
|
---|
749 | // flip y coordinate
|
---|
750 | qmsg.ptl.y = QApplication::desktop()->height() - (qmsg.ptl.y + 1);
|
---|
751 |
|
---|
752 | #if defined(QT_DEBUGMSGFLOW)
|
---|
753 | {
|
---|
754 | QDbgStr str = qStrQMSG(qmsg);
|
---|
755 | if (!str.isEmpty())
|
---|
756 | qDebug() << "*** [W]" << str;
|
---|
757 | }
|
---|
758 | #endif
|
---|
759 |
|
---|
760 | // send through app filter
|
---|
761 | if (qApp->filterEvent(&qmsg, reinterpret_cast<long *>(&rc)))
|
---|
762 | return rc;
|
---|
763 |
|
---|
764 | switch(msg) {
|
---|
765 |
|
---|
766 | case WM_SYSVALUECHANGED: {
|
---|
767 | // This message is sent to all top-level widgets, handle only once
|
---|
768 | QWidgetList list = QApplication::topLevelWidgets();
|
---|
769 | bool firstWidget = list.first()->winId() == hwnd;
|
---|
770 | if (!firstWidget)
|
---|
771 | break;
|
---|
772 | LONG from = (LONG) mp1;
|
---|
773 | LONG to = (LONG) mp2;
|
---|
774 | #define MY_IS_SV(sv) (from >= (sv) && to <= (sv))
|
---|
775 | if (MY_IS_SV(SV_WORKAREA_XLEFT) || MY_IS_SV(SV_WORKAREA_XRIGHT) ||
|
---|
776 | MY_IS_SV(SV_WORKAREA_YBOTTOM) || MY_IS_SV(SV_WORKAREA_YTOP)) {
|
---|
777 | // send a special invalid resize event to QDesktopWidget
|
---|
778 | QApplication::sendEvent(qt_desktopWidget, 0);
|
---|
779 | // @todo enumerate all top-level widgets and
|
---|
780 | // remaximize those that are maximized
|
---|
781 | } else {
|
---|
782 | /// @todo call qt_set_pm_resources() in the way it is
|
---|
783 | // done in WM_SYSCOLORCHANGE for relevant SV_ values.
|
---|
784 | }
|
---|
785 | #undef MY_IS_SV
|
---|
786 | break;
|
---|
787 | }
|
---|
788 |
|
---|
789 | case WM_BUTTON1DOWN:
|
---|
790 | case WM_BUTTON2DOWN:
|
---|
791 | case WM_BUTTON3DOWN:
|
---|
792 | if (ignoreNextMouseReleaseEvent)
|
---|
793 | ignoreNextMouseReleaseEvent = false;
|
---|
794 | break;
|
---|
795 | case WM_BUTTON1UP:
|
---|
796 | case WM_BUTTON2UP:
|
---|
797 | case WM_BUTTON3UP:
|
---|
798 | if (ignoreNextMouseReleaseEvent) {
|
---|
799 | ignoreNextMouseReleaseEvent = false;
|
---|
800 | if (qt_button_down && qt_button_down->internalWinId() == autoCaptureWnd) {
|
---|
801 | releaseAutoCapture();
|
---|
802 | qt_button_down = 0;
|
---|
803 | }
|
---|
804 | return (MRESULT)TRUE;
|
---|
805 | }
|
---|
806 | break;
|
---|
807 |
|
---|
808 | default:
|
---|
809 | break;
|
---|
810 | }
|
---|
811 |
|
---|
812 | if (!widget)
|
---|
813 | widget = (QETWidget*)QWidget::find(hwnd);
|
---|
814 | if (!widget) // don't know this widget
|
---|
815 | break;
|
---|
816 |
|
---|
817 | if (app_do_modal) { // modal event handling
|
---|
818 | if (!qt_try_modal(widget, &qmsg, rc))
|
---|
819 | return rc;
|
---|
820 | }
|
---|
821 |
|
---|
822 | if (widget->pmEvent(&qmsg, &rc)) // send through widget filter
|
---|
823 | return rc;
|
---|
824 |
|
---|
825 | if (isTranslatableMouseEvent) {
|
---|
826 | if (qApp->activePopupWidget() != 0) { // in popup mode
|
---|
827 | QWidget *w = QApplication::widgetAt(qmsg.ptl.x, qmsg.ptl.y);
|
---|
828 | if (w)
|
---|
829 | widget = (QETWidget*)w;
|
---|
830 | }
|
---|
831 | if (widget->translateMouseEvent(qmsg)) // mouse event
|
---|
832 | return (MRESULT)TRUE;
|
---|
833 | #ifndef QT_NO_WHEELEVENT
|
---|
834 | } else if (msg == WM_VSCROLL || msg == WM_HSCROLL) {
|
---|
835 | if (widget->translateWheelEvent(qmsg))
|
---|
836 | return (MRESULT)TRUE;
|
---|
837 | #endif
|
---|
838 | #ifndef QT_NO_DRAGANDDROP
|
---|
839 | } else if (msg >= WM_DRAGFIRST && msg <= WM_DRAGLAST) {
|
---|
840 | return qt_dispatchDragAndDrop(widget, qmsg);
|
---|
841 | #endif
|
---|
842 | } else {
|
---|
843 | switch(msg) {
|
---|
844 |
|
---|
845 | case WM_CHAR: { // keyboard event
|
---|
846 | QWidget *g = QWidget::keyboardGrabber();
|
---|
847 | if (g)
|
---|
848 | widget = (QETWidget*)g;
|
---|
849 | else if (QApplication::activePopupWidget())
|
---|
850 | widget = (QETWidget*)QApplication::activePopupWidget()->focusWidget()
|
---|
851 | ? (QETWidget*)QApplication::activePopupWidget()->focusWidget()
|
---|
852 | : (QETWidget*)QApplication::activePopupWidget();
|
---|
853 | else if (qApp->focusWidget())
|
---|
854 | widget = (QETWidget*)QApplication::focusWidget();
|
---|
855 | else if (widget->internalWinId() == WinQueryFocus(HWND_DESKTOP)) {
|
---|
856 | // We faked the message to go to exactly that widget.
|
---|
857 | widget = (QETWidget*)widget->window();
|
---|
858 | }
|
---|
859 | if (widget->isEnabled()) {
|
---|
860 | bool result =
|
---|
861 | #if !defined (QT_NO_SESSIONMANAGER)
|
---|
862 | sm_blockUserInput ? true :
|
---|
863 | #endif
|
---|
864 | qt_keymapper_private()->translateKeyEvent(widget, qmsg, g != 0);
|
---|
865 | if (result)
|
---|
866 | return (MRESULT)TRUE;
|
---|
867 | }
|
---|
868 | break;
|
---|
869 | }
|
---|
870 |
|
---|
871 | case WM_PAINT: { // paint event
|
---|
872 | if (widget->translatePaintEvent(qmsg))
|
---|
873 | return (MRESULT)TRUE;
|
---|
874 | break;
|
---|
875 | }
|
---|
876 |
|
---|
877 | case WM_ERASEBACKGROUND: { // erase window background
|
---|
878 | // flush WM_PAINT messages here to update window contents
|
---|
879 | // instantly while tracking the resize frame (normally these
|
---|
880 | // messages are delivered after the user has stopped resizing
|
---|
881 | // for some time). this slows down resizing slightly but gives a
|
---|
882 | // better look (no invalid window contents can be seen during
|
---|
883 | // resize). the alternative could be to erase the background only,
|
---|
884 | // but we need to do it for every non-toplevel window, which can
|
---|
885 | // also be time-consuming (WM_ERASEBACKGROUND is sent to WC_FRAME
|
---|
886 | // clients only, so we would have to do all calculations ourselves).
|
---|
887 | WinUpdateWindow(widget->effectiveWinId());
|
---|
888 | return FALSE;
|
---|
889 | }
|
---|
890 |
|
---|
891 | case WM_CALCVALIDRECTS: {
|
---|
892 | // we must always return this value here to cause PM to reposition
|
---|
893 | // our children accordingly (othwerwise we would have to do it
|
---|
894 | // ourselves to keep them top-left aligned).
|
---|
895 | return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
|
---|
896 | }
|
---|
897 |
|
---|
898 | case WM_SIZE: { // resize window
|
---|
899 | if (widget->translateConfigEvent(qmsg))
|
---|
900 | return (MRESULT)TRUE;
|
---|
901 | break;
|
---|
902 | }
|
---|
903 |
|
---|
904 | case WM_ACTIVATE: {
|
---|
905 | qApp->pmFocus(widget, SHORT1FROMMP(mp1));
|
---|
906 | break;
|
---|
907 | }
|
---|
908 |
|
---|
909 | case WM_SETFOCUS: {
|
---|
910 | HWND hwnd = (HWND)mp1;
|
---|
911 | bool focus = SHORT1FROMMP(mp2);
|
---|
912 | if (!focus) {
|
---|
913 | if (!QWidget::find(hwnd)) {
|
---|
914 | // we don't get focus, so unset it now
|
---|
915 | if (QApplication::activePopupWidget()) {
|
---|
916 | // Another application was activated while our popups are open,
|
---|
917 | // then close all popups. In case some popup refuses to close,
|
---|
918 | // we give up after 1024 attempts (to avoid an infinite loop).
|
---|
919 | int maxiter = 1024;
|
---|
920 | QWidget *popup;
|
---|
921 | while ((popup=QApplication::activePopupWidget()) && maxiter--)
|
---|
922 | popup->close();
|
---|
923 | }
|
---|
924 | // non-Qt ownees of our WC_FRAME window (such as
|
---|
925 | // FID_SYSMENU) should not cause the focus to be lost.
|
---|
926 | if (WinQueryWindow(hwnd, QW_OWNER) ==
|
---|
927 | ((QETWidget*)widget->window())->dptr()->frameWinId())
|
---|
928 | break;
|
---|
929 | if (!widget->isWindow())
|
---|
930 | qApp->pmFocus(widget, focus);
|
---|
931 | }
|
---|
932 | }
|
---|
933 | break;
|
---|
934 | }
|
---|
935 |
|
---|
936 | case WM_SHOW: {
|
---|
937 | // @todo there is some more processing in Qt4, see
|
---|
938 | // WM_SHOWWINDOW in qapplication_win.cpp
|
---|
939 | if (!SHORT1FROMMP(mp1) && autoCaptureWnd == widget->internalWinId())
|
---|
940 | releaseAutoCapture();
|
---|
941 | break;
|
---|
942 | }
|
---|
943 |
|
---|
944 | case WM_CLOSE: { // close window
|
---|
945 | widget->translateCloseEvent(qmsg);
|
---|
946 | return (MRESULT)TRUE;
|
---|
947 | }
|
---|
948 |
|
---|
949 | case WM_DESTROY: { // destroy window
|
---|
950 | if (hwnd == curWin) {
|
---|
951 | QWidget *enter = QWidget::mouseGrabber();
|
---|
952 | if (enter == widget)
|
---|
953 | enter = 0;
|
---|
954 | QApplicationPrivate::dispatchEnterLeave(enter, widget);
|
---|
955 | curWin = enter ? enter->effectiveWinId() : 0;
|
---|
956 | qt_last_mouse_receiver = enter;
|
---|
957 | }
|
---|
958 | if (widget == popupButtonFocus)
|
---|
959 | popupButtonFocus = 0;
|
---|
960 | break;
|
---|
961 | }
|
---|
962 |
|
---|
963 | #ifndef QT_NO_CONTEXTMENU
|
---|
964 | case WM_CONTEXTMENU: {
|
---|
965 | if (SHORT2FROMMP(mp2)) {
|
---|
966 | // keyboard event
|
---|
967 | QWidget *fw = qApp->focusWidget();
|
---|
968 | if (fw && fw->isEnabled()) {
|
---|
969 | QContextMenuEvent e(QContextMenuEvent::Keyboard,
|
---|
970 | QPoint(5, 5),
|
---|
971 | fw->mapToGlobal(QPoint(5, 5)), 0);
|
---|
972 | if (qt_sendSpontaneousEvent(fw, &e))
|
---|
973 | return (MRESULT)TRUE;
|
---|
974 | }
|
---|
975 | } else {
|
---|
976 | // mouse event
|
---|
977 | if (widget->translateMouseEvent(qmsg))
|
---|
978 | return (MRESULT)TRUE;
|
---|
979 | }
|
---|
980 | break;
|
---|
981 | }
|
---|
982 | #endif
|
---|
983 |
|
---|
984 | case WM_U_MOUSELEAVE: {
|
---|
985 | // We receive a mouse leave for curWin, meaning
|
---|
986 | // the mouse was moved outside our widgets
|
---|
987 | if (widget->internalWinId() == curWin) {
|
---|
988 | bool dispatch = !widget->underMouse();
|
---|
989 | // hasMouse is updated when dispatching enter/leave,
|
---|
990 | // so test if it is actually up-to-date
|
---|
991 | if (!dispatch) {
|
---|
992 | QRect geom = widget->geometry();
|
---|
993 | if (widget->parentWidget() && !widget->isWindow()) {
|
---|
994 | QPoint gp = widget->parentWidget()->mapToGlobal(widget->pos());
|
---|
995 | geom.setX(gp.x());
|
---|
996 | geom.setY(gp.y());
|
---|
997 | }
|
---|
998 | QPoint cpos = QCursor::pos();
|
---|
999 | dispatch = !geom.contains(cpos);
|
---|
1000 | if ( !dispatch && !QWidget::mouseGrabber()) {
|
---|
1001 | QWidget *hittest = QApplication::widgetAt(cpos);
|
---|
1002 | dispatch = !hittest || hittest->internalWinId() != curWin;
|
---|
1003 | }
|
---|
1004 | if (!dispatch) {
|
---|
1005 | HPS hps = qt_display_ps();
|
---|
1006 | HRGN hrgn = GpiCreateRegion(hps, 0, NULL);
|
---|
1007 | qt_WinQueryClipRegionOrRect(hwnd, hrgn);
|
---|
1008 | QPoint lcpos = widget->mapFromGlobal(cpos);
|
---|
1009 | // flip y coordinate
|
---|
1010 | POINTL pt = { lcpos.x(), widget->height() - (lcpos.y() + 1) };
|
---|
1011 | dispatch = !GpiPtInRegion(hps, hrgn, &pt);
|
---|
1012 | GpiDestroyRegion(hps, hrgn);
|
---|
1013 | }
|
---|
1014 | }
|
---|
1015 | if (dispatch) {
|
---|
1016 | if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
|
---|
1017 | QApplicationPrivate::dispatchEnterLeave(0, qt_last_mouse_receiver);
|
---|
1018 | else
|
---|
1019 | QApplicationPrivate::dispatchEnterLeave(0, QWidget::find((WId)curWin));
|
---|
1020 | curWin = 0;
|
---|
1021 | qt_last_mouse_receiver = 0;
|
---|
1022 | }
|
---|
1023 | }
|
---|
1024 | break;
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | case WM_MINMAXFRAME: {
|
---|
1028 | PSWP pswp = (PSWP)mp1;
|
---|
1029 |
|
---|
1030 | bool window_state_change = false;
|
---|
1031 | Qt::WindowStates oldstate = Qt::WindowStates(widget->dataPtr()->window_state);
|
---|
1032 |
|
---|
1033 | if (pswp->fl & SWP_MINIMIZE) {
|
---|
1034 | window_state_change = true;
|
---|
1035 | widget->dataPtr()->window_state |= Qt::WindowMinimized;
|
---|
1036 | if (widget->isVisible()) {
|
---|
1037 | QHideEvent e;
|
---|
1038 | qt_sendSpontaneousEvent(widget, &e);
|
---|
1039 | widget->dptr()->hideChildren(true);
|
---|
1040 | const QString title = widget->windowIconText();
|
---|
1041 | if (!title.isEmpty())
|
---|
1042 | widget->dptr()->setWindowTitle_helper(title);
|
---|
1043 | }
|
---|
1044 | } else if (pswp->fl & (SWP_MAXIMIZE | SWP_RESTORE)) {
|
---|
1045 | window_state_change = true;
|
---|
1046 | if (pswp->fl & SWP_MAXIMIZE) {
|
---|
1047 | widget->topData()->normalGeometry = widget->geometry();
|
---|
1048 | widget->dataPtr()->window_state |= Qt::WindowMaximized;
|
---|
1049 | }
|
---|
1050 | else if (!widget->isMinimized()) {
|
---|
1051 | widget->dataPtr()->window_state &= ~Qt::WindowMaximized;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | if (widget->isMinimized()) {
|
---|
1055 | widget->dataPtr()->window_state &= ~Qt::WindowMinimized;
|
---|
1056 | widget->dptr()->showChildren(true);
|
---|
1057 | QShowEvent e;
|
---|
1058 | qt_sendSpontaneousEvent(widget, &e);
|
---|
1059 | const QString title = widget->windowTitle();
|
---|
1060 | if (!title.isEmpty())
|
---|
1061 | widget->dptr()->setWindowTitle_helper(title);
|
---|
1062 | }
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | if (window_state_change) {
|
---|
1066 | QWindowStateChangeEvent e(oldstate);
|
---|
1067 | qt_sendSpontaneousEvent(widget, &e);
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | break;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | default:
|
---|
1074 | break;
|
---|
1075 | }
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | } while(0);
|
---|
1079 |
|
---|
1080 | return WinDefWindowProc(hwnd, msg, mp1, mp2);
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | PFNWP QtOldFrameProc = 0;
|
---|
1084 |
|
---|
1085 | MRESULT EXPENTRY QtFrameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
1086 | {
|
---|
1087 | do {
|
---|
1088 | if (!qApp) // unstable app state
|
---|
1089 | break;
|
---|
1090 | #if 0
|
---|
1091 | // make sure we show widgets (e.g. scrollbars) when the user resizes
|
---|
1092 | if (qApp->loopLevel())
|
---|
1093 | qApp->sendPostedEvents(0, QEvent::ShowWindowRequest);
|
---|
1094 | #endif
|
---|
1095 |
|
---|
1096 | MRESULT rc = (MRESULT) FALSE;
|
---|
1097 |
|
---|
1098 | HWND hwndC = WinWindowFromID(hwnd, FID_CLIENT);
|
---|
1099 | QETWidget *widget = (QETWidget*)QWidget::find(hwndC);
|
---|
1100 | if (!widget) // don't know this widget
|
---|
1101 | break;
|
---|
1102 |
|
---|
1103 | Q_ASSERT(widget->isWindow());
|
---|
1104 |
|
---|
1105 | QMSG qmsg; // create QMSG structure
|
---|
1106 | qmsg.hwnd = hwnd;
|
---|
1107 | qmsg.msg = msg;
|
---|
1108 | qmsg.mp1 = mp1;
|
---|
1109 | qmsg.mp2 = mp2;
|
---|
1110 |
|
---|
1111 | #if defined(QT_DEBUGMSGFLOW)
|
---|
1112 | {
|
---|
1113 | QDbgStr str = qStrQMSG(qmsg);
|
---|
1114 | if (!str.isEmpty())
|
---|
1115 | qDebug() << "*** [F]" << str;
|
---|
1116 | }
|
---|
1117 | #endif
|
---|
1118 |
|
---|
1119 | switch(msg) {
|
---|
1120 |
|
---|
1121 | case WM_MOVE: { // move window
|
---|
1122 | // note that we handle it nere instead of having CS_MOVENOTIFY
|
---|
1123 | // on the client and handling in QtWndProc because we don't want
|
---|
1124 | // client inside frame window move messages that would appear during
|
---|
1125 | // minimize/maximize otherwise
|
---|
1126 | if (widget->translateConfigEvent(qmsg))
|
---|
1127 | return (MRESULT)TRUE;
|
---|
1128 | break;
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | case WM_QUERYTRACKINFO: {
|
---|
1132 | QWExtra *x = widget->xtra();
|
---|
1133 | if (x) {
|
---|
1134 | rc = QtOldFrameProc(hwnd, msg, mp1, mp2);
|
---|
1135 | PTRACKINFO pti = (PTRACKINFO) mp2;
|
---|
1136 | int minw = 0, minh = 0;
|
---|
1137 | int maxw = QWIDGETSIZE_MAX, maxh = QWIDGETSIZE_MAX;
|
---|
1138 | QRect fs = widget->frameStrut();
|
---|
1139 | if (x->minw > 0)
|
---|
1140 | minw = x->minw + fs.left() + fs.right();
|
---|
1141 | if (x->minh > 0)
|
---|
1142 | minh = x->minh + fs.top() + fs.bottom();
|
---|
1143 | if (x->maxw < QWIDGETSIZE_MAX)
|
---|
1144 | maxw = x->maxw > x->minw ? x->maxw + fs.left() + fs.right() : minw;
|
---|
1145 | if (x->maxh < QWIDGETSIZE_MAX)
|
---|
1146 | maxh = x->maxh > x->minh ? x->maxh + fs.top() + fs.bottom() : minh;
|
---|
1147 | // obey system recommended minimum size (to emulate Qt/Win32)
|
---|
1148 | pti->ptlMinTrackSize.x = qMax<LONG>(minw, pti->ptlMinTrackSize.x);
|
---|
1149 | pti->ptlMinTrackSize.y = qMax<LONG>(minh, pti->ptlMinTrackSize.y);
|
---|
1150 | // we assume that PM doesn't restrict the maximum size by default
|
---|
1151 | // and use it as an absolute maximum (values above it will cause
|
---|
1152 | // PM to disable window sizing and moving for some reason)
|
---|
1153 | pti->ptlMaxTrackSize.x = qMin<LONG>(maxw, pti->ptlMaxTrackSize.x);
|
---|
1154 | pti->ptlMaxTrackSize.y = qMin<LONG>(maxh, pti->ptlMaxTrackSize.y);
|
---|
1155 | return rc;
|
---|
1156 | }
|
---|
1157 | break;
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | case WM_TRACKFRAME: {
|
---|
1161 | if (QApplication::activePopupWidget()) {
|
---|
1162 | // Another application was activated while our popups are open,
|
---|
1163 | // then close all popups. In case some popup refuses to close,
|
---|
1164 | // we give up after 1024 attempts (to avoid an infinite loop).
|
---|
1165 | int maxiter = 1024;
|
---|
1166 | QWidget *popup;
|
---|
1167 | while ((popup=QApplication::activePopupWidget()) && maxiter--)
|
---|
1168 | popup->close();
|
---|
1169 | }
|
---|
1170 | break;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | default:
|
---|
1174 | break;
|
---|
1175 | }
|
---|
1176 | } while(0);
|
---|
1177 |
|
---|
1178 | return QtOldFrameProc(hwnd, msg, mp1, mp2);
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | /*****************************************************************************
|
---|
1182 | Modal widgets; We have implemented our own modal widget mechanism
|
---|
1183 | to get total control.
|
---|
1184 | A modal widget without a parent becomes application-modal.
|
---|
1185 | A modal widget with a parent becomes modal to its parent and grandparents..
|
---|
1186 |
|
---|
1187 | QApplicationPrivate::enterModal()
|
---|
1188 | Enters modal state
|
---|
1189 | Arguments:
|
---|
1190 | QWidget *widget A modal widget
|
---|
1191 |
|
---|
1192 | QApplicationPrivate::leaveModal()
|
---|
1193 | Leaves modal state for a widget
|
---|
1194 | Arguments:
|
---|
1195 | QWidget *widget A modal widget
|
---|
1196 | *****************************************************************************/
|
---|
1197 |
|
---|
1198 | bool QApplicationPrivate::modalState()
|
---|
1199 | {
|
---|
1200 | return app_do_modal;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | void QApplicationPrivate::enterModal_sys(QWidget *widget)
|
---|
1204 | {
|
---|
1205 | if (!qt_modal_stack)
|
---|
1206 | qt_modal_stack = new QWidgetList;
|
---|
1207 |
|
---|
1208 | releaseAutoCapture();
|
---|
1209 | QWidget *leave = qt_last_mouse_receiver;
|
---|
1210 | if (!leave)
|
---|
1211 | leave = QWidget::find(curWin);
|
---|
1212 | QApplicationPrivate::dispatchEnterLeave(0, leave);
|
---|
1213 | qt_modal_stack->insert(0, widget);
|
---|
1214 | app_do_modal = true;
|
---|
1215 | curWin = 0;
|
---|
1216 | qt_last_mouse_receiver = 0;
|
---|
1217 | ignoreNextMouseReleaseEvent = false;
|
---|
1218 |
|
---|
1219 | // go through all top-level widgets and disable those that should be
|
---|
1220 | // blocked by the modality (this in particular will disable activation
|
---|
1221 | // through clicking on the title bar and also state change throuhg titlebar
|
---|
1222 | // buttons)
|
---|
1223 | QWidgetList list = QApplication::topLevelWidgets();
|
---|
1224 | foreach(QWidget *w, list) {
|
---|
1225 | if (QApplicationPrivate::isBlockedByModal(w))
|
---|
1226 | WinEnableWindow(w->d_func()->frameWinId(), FALSE);
|
---|
1227 | }
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | void QApplicationPrivate::leaveModal_sys(QWidget *widget)
|
---|
1231 | {
|
---|
1232 | if (qt_modal_stack) {
|
---|
1233 | // go through all affected top-level widgets and re-enable them
|
---|
1234 | QWidgetList list = QApplication::topLevelWidgets();
|
---|
1235 | foreach(QWidget *w, list) {
|
---|
1236 | if (QApplicationPrivate::isBlockedByModal(w))
|
---|
1237 | WinEnableWindow(w->d_func()->frameWinId(), TRUE);
|
---|
1238 | }
|
---|
1239 | if (qt_modal_stack->removeAll(widget)) {
|
---|
1240 | if (qt_modal_stack->isEmpty()) {
|
---|
1241 | delete qt_modal_stack;
|
---|
1242 | qt_modal_stack = 0;
|
---|
1243 | QPoint p(QCursor::pos());
|
---|
1244 | app_do_modal = false; // necessary, we may get recursively into qt_try_modal below
|
---|
1245 | QWidget* w = QApplication::widgetAt(p.x(), p.y());
|
---|
1246 | QWidget *leave = qt_last_mouse_receiver;
|
---|
1247 | if (!leave)
|
---|
1248 | leave = QWidget::find(curWin);
|
---|
1249 | if (QWidget *grabber = QWidget::mouseGrabber()) {
|
---|
1250 | w = grabber;
|
---|
1251 | if (leave == w)
|
---|
1252 | leave = 0;
|
---|
1253 | }
|
---|
1254 | QApplicationPrivate::dispatchEnterLeave(w, leave); // send synthetic enter event
|
---|
1255 | curWin = w ? w->effectiveWinId() : 0;
|
---|
1256 | qt_last_mouse_receiver = w;
|
---|
1257 | }
|
---|
1258 | }
|
---|
1259 | ignoreNextMouseReleaseEvent = true;
|
---|
1260 | }
|
---|
1261 | app_do_modal = qt_modal_stack != 0;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | bool qt_try_modal(QWidget *widget, QMSG *qmsg, MRESULT &rc)
|
---|
1265 | {
|
---|
1266 | QWidget *top = 0;
|
---|
1267 |
|
---|
1268 | if (QApplicationPrivate::tryModalHelper(widget, &top))
|
---|
1269 | return true;
|
---|
1270 |
|
---|
1271 | int type = qmsg->msg;
|
---|
1272 |
|
---|
1273 | bool block_event = false;
|
---|
1274 | if ((type >= WM_MOUSEFIRST && type <= WM_MOUSELAST) ||
|
---|
1275 | (type >= WM_EXTMOUSEFIRST && type <= WM_EXTMOUSELAST) ||
|
---|
1276 | type == WM_VSCROLL || type == WM_HSCROLL ||
|
---|
1277 | type == WM_U_MOUSELEAVE ||
|
---|
1278 | type == WM_CHAR) {
|
---|
1279 | if (type == WM_MOUSEMOVE) {
|
---|
1280 | #ifndef QT_NO_CURSOR
|
---|
1281 | QCursor *c = qt_grab_cursor();
|
---|
1282 | if (!c)
|
---|
1283 | c = QApplication::overrideCursor();
|
---|
1284 | if (c) // application cursor defined
|
---|
1285 | WinSetPointer(HWND_DESKTOP, c->handle());
|
---|
1286 | else
|
---|
1287 | WinSetPointer(HWND_DESKTOP, QCursor(Qt::ArrowCursor).handle());
|
---|
1288 | #endif // QT_NO_CURSOR
|
---|
1289 | } else if (type == WM_BUTTON1DOWN || type == type == WM_BUTTON2DOWN ||
|
---|
1290 | type == WM_BUTTON3DOWN) {
|
---|
1291 | if (!top->isActiveWindow()) {
|
---|
1292 | top->activateWindow();
|
---|
1293 | } else {
|
---|
1294 | QApplication::beep();
|
---|
1295 | }
|
---|
1296 | }
|
---|
1297 | block_event = true;
|
---|
1298 | } else if (type == WM_CLOSE) {
|
---|
1299 | block_event = true;
|
---|
1300 | } else if (type == WM_SYSCOMMAND) {
|
---|
1301 | if (!(SHORT1FROMMP(qmsg->mp1) == SC_RESTORE && widget->isMinimized()))
|
---|
1302 | block_event = true;
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 | return !block_event;
|
---|
1306 | }
|
---|
1307 |
|
---|
1308 | /*****************************************************************************
|
---|
1309 | Popup widget mechanism
|
---|
1310 |
|
---|
1311 | openPopup()
|
---|
1312 | Adds a widget to the list of popup widgets
|
---|
1313 | Arguments:
|
---|
1314 | QWidget *widget The popup widget to be added
|
---|
1315 |
|
---|
1316 | closePopup()
|
---|
1317 | Removes a widget from the list of popup widgets
|
---|
1318 | Arguments:
|
---|
1319 | QWidget *widget The popup widget to be removed
|
---|
1320 | *****************************************************************************/
|
---|
1321 |
|
---|
1322 | void QApplicationPrivate::openPopup(QWidget *popup)
|
---|
1323 | {
|
---|
1324 | if (!QApplicationPrivate::popupWidgets)
|
---|
1325 | QApplicationPrivate::popupWidgets = new QWidgetList;
|
---|
1326 | QApplicationPrivate::popupWidgets->append(popup);
|
---|
1327 | if (!popup->isEnabled())
|
---|
1328 | return;
|
---|
1329 |
|
---|
1330 | if (QApplicationPrivate::popupWidgets->count() == 1 && !qt_nograb()) {
|
---|
1331 | Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created));
|
---|
1332 | setAutoCapture(popup->d_func()->frameWinId()); // grab mouse/keyboard
|
---|
1333 | }
|
---|
1334 | // Popups are not focus-handled by the window system (the first
|
---|
1335 | // popup grabbed the keyboard), so we have to do that manually: A
|
---|
1336 | // new popup gets the focus
|
---|
1337 | if (popup->focusWidget()) {
|
---|
1338 | popup->focusWidget()->setFocus(Qt::PopupFocusReason);
|
---|
1339 | } else if (QApplicationPrivate::popupWidgets->count() == 1) { // this was the first popup
|
---|
1340 | if (QWidget *fw = q_func()->focusWidget()) {
|
---|
1341 | QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason);
|
---|
1342 | q_func()->sendEvent(fw, &e);
|
---|
1343 | }
|
---|
1344 | }
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | void QApplicationPrivate::closePopup(QWidget *popup)
|
---|
1348 | {
|
---|
1349 | if (!QApplicationPrivate::popupWidgets)
|
---|
1350 | return;
|
---|
1351 | QApplicationPrivate::popupWidgets->removeAll(popup);
|
---|
1352 | POINTL curPos;
|
---|
1353 | WinQueryPointerPos(HWND_DESKTOP, &curPos);
|
---|
1354 | // flip y coordinate
|
---|
1355 | curPos.y = q_func()->desktop()->height() - (curPos.y + 1);
|
---|
1356 |
|
---|
1357 | if (QApplicationPrivate::popupWidgets->isEmpty()) { // this was the last popup
|
---|
1358 | delete QApplicationPrivate::popupWidgets;
|
---|
1359 | QApplicationPrivate::popupWidgets = 0;
|
---|
1360 | replayPopupMouseEvent = (!popup->geometry().contains(QPoint(curPos.x, curPos.y))
|
---|
1361 | && !popup->testAttribute(Qt::WA_NoMouseReplay));
|
---|
1362 | if (!popup->isEnabled())
|
---|
1363 | return;
|
---|
1364 | if (!qt_nograb()) // grabbing not disabled
|
---|
1365 | releaseAutoCapture();
|
---|
1366 | QWidget *fw = QApplicationPrivate::active_window ? QApplicationPrivate::active_window->focusWidget()
|
---|
1367 | : q_func()->focusWidget();
|
---|
1368 | if (fw) {
|
---|
1369 | if (fw != q_func()->focusWidget()) {
|
---|
1370 | fw->setFocus(Qt::PopupFocusReason);
|
---|
1371 | } else {
|
---|
1372 | QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason);
|
---|
1373 | q_func()->sendEvent(fw, &e);
|
---|
1374 | }
|
---|
1375 | }
|
---|
1376 | } else {
|
---|
1377 | // Popups are not focus-handled by the window system (the
|
---|
1378 | // first popup grabbed the keyboard), so we have to do that
|
---|
1379 | // manually: A popup was closed, so the previous popup gets
|
---|
1380 | // the focus.
|
---|
1381 | QWidget* aw = QApplicationPrivate::popupWidgets->last();
|
---|
1382 | if (QApplicationPrivate::popupWidgets->count() == 1) {
|
---|
1383 | Q_ASSERT(aw->testAttribute(Qt::WA_WState_Created));
|
---|
1384 | setAutoCapture(aw->internalWinId());
|
---|
1385 | }
|
---|
1386 | if (QWidget *fw = aw->focusWidget())
|
---|
1387 | fw->setFocus(Qt::PopupFocusReason);
|
---|
1388 | }
|
---|
1389 | }
|
---|
1390 |
|
---|
1391 | /*****************************************************************************
|
---|
1392 | Event translation; translates PM events to Qt events
|
---|
1393 | *****************************************************************************/
|
---|
1394 |
|
---|
1395 | static int mouseButtonState()
|
---|
1396 | {
|
---|
1397 | int state = 0;
|
---|
1398 |
|
---|
1399 | if (WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
|
---|
1400 | state |= Qt::LeftButton;
|
---|
1401 | if (WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
|
---|
1402 | state |= Qt::RightButton;
|
---|
1403 | if (WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
|
---|
1404 | state |= Qt::MidButton;
|
---|
1405 |
|
---|
1406 | return state;
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | //
|
---|
1410 | // Auto-capturing for mouse press and mouse release
|
---|
1411 | //
|
---|
1412 |
|
---|
1413 | static void setAutoCapture(HWND h)
|
---|
1414 | {
|
---|
1415 | if (autoCaptureWnd)
|
---|
1416 | releaseAutoCapture();
|
---|
1417 | autoCaptureWnd = h;
|
---|
1418 |
|
---|
1419 | if (!mouseButtonState()) {
|
---|
1420 | // all buttons released, we don't actually capture the mouse
|
---|
1421 | // (see QWidget::translateMouseEvent())
|
---|
1422 | autoCaptureReleased = true;
|
---|
1423 | } else {
|
---|
1424 | autoCaptureReleased = false;
|
---|
1425 | WinSetCapture(HWND_DESKTOP, h);
|
---|
1426 | }
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | static void releaseAutoCapture()
|
---|
1430 | {
|
---|
1431 | if (autoCaptureWnd) {
|
---|
1432 | if (!autoCaptureReleased) {
|
---|
1433 | WinSetCapture(HWND_DESKTOP, NULLHANDLE);
|
---|
1434 | autoCaptureReleased = true;
|
---|
1435 | }
|
---|
1436 | autoCaptureWnd = NULLHANDLE;
|
---|
1437 | }
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | //
|
---|
1441 | // Mouse event translation
|
---|
1442 | //
|
---|
1443 |
|
---|
1444 | static ushort mouseTbl[] = {
|
---|
1445 | WM_MOUSEMOVE, QEvent::MouseMove, 0,
|
---|
1446 | WM_BUTTON1DOWN, QEvent::MouseButtonPress, Qt::LeftButton,
|
---|
1447 | WM_BUTTON1UP, QEvent::MouseButtonRelease, Qt::LeftButton,
|
---|
1448 | WM_BUTTON1DBLCLK, QEvent::MouseButtonDblClick, Qt::LeftButton,
|
---|
1449 | WM_BUTTON2DOWN, QEvent::MouseButtonPress, Qt::RightButton,
|
---|
1450 | WM_BUTTON2UP, QEvent::MouseButtonRelease, Qt::RightButton,
|
---|
1451 | WM_BUTTON2DBLCLK, QEvent::MouseButtonDblClick, Qt::RightButton,
|
---|
1452 | WM_BUTTON3DOWN, QEvent::MouseButtonPress, Qt::MidButton,
|
---|
1453 | WM_BUTTON3UP, QEvent::MouseButtonRelease, Qt::MidButton,
|
---|
1454 | WM_BUTTON3DBLCLK, QEvent::MouseButtonDblClick, Qt::MidButton,
|
---|
1455 | WM_CONTEXTMENU, QEvent::ContextMenu, 0,
|
---|
1456 | 0, 0, 0
|
---|
1457 | };
|
---|
1458 |
|
---|
1459 | static int translateButtonState(USHORT s, int type, int button)
|
---|
1460 | {
|
---|
1461 | Q_UNUSED(button);
|
---|
1462 |
|
---|
1463 | int bst = mouseButtonState();
|
---|
1464 |
|
---|
1465 | if (type == QEvent::ContextMenu) {
|
---|
1466 | if (WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
|
---|
1467 | bst |= Qt::ShiftModifier;
|
---|
1468 | if (WinGetKeyState(HWND_DESKTOP, VK_ALT) & 0x8000)
|
---|
1469 | bst |= Qt::AltModifier;
|
---|
1470 | if (WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
|
---|
1471 | bst |= Qt::ControlModifier;
|
---|
1472 | } else {
|
---|
1473 | if (s & KC_SHIFT)
|
---|
1474 | bst |= Qt::ShiftModifier;
|
---|
1475 | if ((s & KC_ALT))
|
---|
1476 | bst |= Qt::AltModifier;
|
---|
1477 | if (s & KC_CTRL)
|
---|
1478 | bst |= Qt::ControlModifier;
|
---|
1479 | }
|
---|
1480 | if (qt_keymapper_private()->extraKeyState & Qt::AltModifier)
|
---|
1481 | bst |= Qt::AltModifier;
|
---|
1482 | if (qt_keymapper_private()->extraKeyState & Qt::MetaModifier)
|
---|
1483 | bst |= Qt::MetaModifier;
|
---|
1484 |
|
---|
1485 | return bst;
|
---|
1486 | }
|
---|
1487 |
|
---|
1488 | bool QETWidget::translateMouseEvent(const QMSG &qmsg)
|
---|
1489 | {
|
---|
1490 | #if defined(QT_DEBUGMSGFLOW) && 0
|
---|
1491 | static const char *msgNames[] = { // 11 items
|
---|
1492 | "WM_MOUSEMOVE",
|
---|
1493 | "WM_BUTTON1DOWN", "WM_BUTTON1UP", "WM_BUTTON1DBLCLK",
|
---|
1494 | "WM_BUTTON2DOWN", "WM_BUTTON2UP", "WM_BUTTON2DBLCLK",
|
---|
1495 | "WM_BUTTON3DOWN", "WM_BUTTON3UP", "WM_BUTTON3DBLCLK",
|
---|
1496 | "WM_???"
|
---|
1497 | };
|
---|
1498 | int msgIdx = qmsg.msg - WM_MOUSEMOVE;
|
---|
1499 | if (msgIdx < 0 || msgIdx > 9)
|
---|
1500 | msgIdx = 10;
|
---|
1501 | qDebug("%s (%04lX): [%08lX/%p:%s] %04hd,%04hd hit=%04hX fl=%04hX",
|
---|
1502 | msgNames[msgIdx], qmsg.msg, qmsg.hwnd, this, widgetName(this),
|
---|
1503 | SHORT1FROMMP(qmsg.mp1), SHORT2FROMMP(qmsg.mp1),
|
---|
1504 | SHORT1FROMMP(qmsg.mp2), SHORT2FROMMP(qmsg.mp2));
|
---|
1505 | #endif
|
---|
1506 |
|
---|
1507 | if (!isWindow() && testAttribute(Qt::WA_NativeWindow))
|
---|
1508 | Q_ASSERT(internalWinId() != NULLHANDLE);
|
---|
1509 |
|
---|
1510 | static QPoint pos; // window pos (y flipped)
|
---|
1511 | static POINTL gpos = { -1, -1 }; // global pos (y flipped)
|
---|
1512 | QEvent::Type type; // event parameters
|
---|
1513 | int button;
|
---|
1514 | int state;
|
---|
1515 | int i;
|
---|
1516 |
|
---|
1517 | // candidate for the double click event
|
---|
1518 | static HWND dblClickCandidateWin = 0;
|
---|
1519 |
|
---|
1520 | #if !defined (QT_NO_SESSIONMANAGER)
|
---|
1521 | if (sm_blockUserInput) //block user interaction during session management
|
---|
1522 | return true;
|
---|
1523 | #endif
|
---|
1524 |
|
---|
1525 | // Compress mouse move events
|
---|
1526 | if (qmsg.msg == WM_MOUSEMOVE) {
|
---|
1527 | QMSG mouseMsg;
|
---|
1528 | mouseMsg.msg = WM_NULL;
|
---|
1529 | while (WinPeekMsg(0, &mouseMsg, qmsg.hwnd, WM_MOUSEMOVE,
|
---|
1530 | WM_MOUSEMOVE, PM_NOREMOVE)) {
|
---|
1531 | if (mouseMsg.mp2 != qmsg.mp2)
|
---|
1532 | break; // leave the message in the queue because
|
---|
1533 | // the key state has changed
|
---|
1534 | // Remove the mouse move message
|
---|
1535 | WinPeekMsg(0, &mouseMsg, qmsg.hwnd, WM_MOUSEMOVE,
|
---|
1536 | WM_MOUSEMOVE, PM_REMOVE);
|
---|
1537 | }
|
---|
1538 | // Update the passed in QMSG structure with the
|
---|
1539 | // most recent one.
|
---|
1540 | if (mouseMsg.msg != WM_NULL) {
|
---|
1541 | PQMSG pqmsg = (PQMSG)&qmsg;
|
---|
1542 | pqmsg->mp1 = mouseMsg.mp1;
|
---|
1543 | pqmsg->mp2 = mouseMsg.mp2;
|
---|
1544 | pqmsg->time = mouseMsg.time;
|
---|
1545 | pqmsg->ptl.x = (short)SHORT1FROMMP(mouseMsg.mp1);
|
---|
1546 | pqmsg->ptl.y = (short)SHORT2FROMMP(mouseMsg.mp1);
|
---|
1547 | WinMapWindowPoints(pqmsg->hwnd, HWND_DESKTOP, &pqmsg->ptl, 1);
|
---|
1548 | // flip y coordinate
|
---|
1549 | pqmsg->ptl.y = QApplication::desktop()->height() - (pqmsg->ptl.y + 1);
|
---|
1550 | }
|
---|
1551 | }
|
---|
1552 |
|
---|
1553 | for (i = 0; mouseTbl[i] && (ULONG)mouseTbl[i] != qmsg.msg; i += 3)
|
---|
1554 | ;
|
---|
1555 | if (!mouseTbl[i])
|
---|
1556 | return true;
|
---|
1557 |
|
---|
1558 | type = (QEvent::Type)mouseTbl[++i]; // event type
|
---|
1559 | button = mouseTbl[++i]; // which button
|
---|
1560 | state = translateButtonState(SHORT2FROMMP(qmsg.mp2), type, button); // button state
|
---|
1561 |
|
---|
1562 | // It seems, that PM remembers only the WM_BUTTONxDOWN message (instead of
|
---|
1563 | // the WM_BUTTONxDOWN + WM_BUTTONxUP pair) to detect whether the next button
|
---|
1564 | // press should be converted to WM_BUTTONxDBLCLK or not. As a result, the
|
---|
1565 | // window gets WM_BUTTONxDBLCLK even if it didn't receive the preceeding
|
---|
1566 | // WM_BUTTONxUP (this happens if we issue WinSetCapture() on the first
|
---|
1567 | // WM_BUTTONxDOWN), which is obviously wrong and makes problems for QWorkspace
|
---|
1568 | // and QTitleBar system menu handlers that don't expect a double click after
|
---|
1569 | // they opened a popup menu. dblClickCandidateWin is reset to 0 (see a ***
|
---|
1570 | // remmark below) when WinSetCapture is issued that directs messages
|
---|
1571 | // to a window other than one received the first WM_BUTTONxDOWN,
|
---|
1572 | // so we can fix it here. Note that if there is more than one popup window,
|
---|
1573 | // WinSetCapture is issued only for the first of them, so this code doesn't
|
---|
1574 | // prevent MouseButtonDblClick from being delivered to a popup when another
|
---|
1575 | // popup gets closed on the first WM_BUTTONxDOWN (Qt/Win32 behaves in the
|
---|
1576 | // same way, so it's left for compatibility).
|
---|
1577 | if (type == QEvent::MouseButtonPress) {
|
---|
1578 | dblClickCandidateWin = qmsg.hwnd;
|
---|
1579 | } else if (type == QEvent::MouseButtonDblClick) {
|
---|
1580 | if (dblClickCandidateWin != qmsg.hwnd)
|
---|
1581 | type = QEvent::MouseButtonPress;
|
---|
1582 | dblClickCandidateWin = 0;
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | const QPoint widgetPos = mapFromGlobal(QPoint(qmsg.ptl.x, qmsg.ptl.y));
|
---|
1586 |
|
---|
1587 | QWidget *alienWidget = !internalWinId() ? this : childAt(widgetPos);
|
---|
1588 | if (alienWidget && alienWidget->internalWinId())
|
---|
1589 | alienWidget = 0;
|
---|
1590 |
|
---|
1591 | if (type == QEvent::MouseMove) {
|
---|
1592 | if (!(state & Qt::MouseButtonMask))
|
---|
1593 | qt_button_down = 0;
|
---|
1594 | #ifndef QT_NO_CURSOR
|
---|
1595 | QCursor *c = qt_grab_cursor();
|
---|
1596 | if (!c)
|
---|
1597 | c = QApplication::overrideCursor();
|
---|
1598 | if (c) // application cursor defined
|
---|
1599 | WinSetPointer(HWND_DESKTOP, c->handle());
|
---|
1600 | else if (!qt_button_down) {
|
---|
1601 | QWidget *w = alienWidget ? alienWidget : this;
|
---|
1602 | while (!w->isWindow() && !w->isEnabled())
|
---|
1603 | w = w->parentWidget();
|
---|
1604 | WinSetPointer(HWND_DESKTOP, w->cursor().handle());
|
---|
1605 | }
|
---|
1606 | #else
|
---|
1607 | // pass the msg to the default proc to let it change the pointer shape
|
---|
1608 | WinDefWindowProc(qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2);
|
---|
1609 | #endif
|
---|
1610 |
|
---|
1611 | HWND id = effectiveWinId();
|
---|
1612 | QWidget *mouseGrabber = QWidget::mouseGrabber();
|
---|
1613 | QWidget *activePopupWidget = qApp->activePopupWidget();
|
---|
1614 | if (mouseGrabber) {
|
---|
1615 | if (!activePopupWidget || (activePopupWidget == this && !rect().contains(widgetPos)))
|
---|
1616 | id = mouseGrabber->effectiveWinId();
|
---|
1617 | } else if (type == QEvent::NonClientAreaMouseMove) {
|
---|
1618 | id = 0;
|
---|
1619 | }
|
---|
1620 |
|
---|
1621 | if (curWin != id) { // new current window
|
---|
1622 | // @todo
|
---|
1623 | // add CS_HITTEST to our window classes and handle WM_HITTEST,
|
---|
1624 | // otherwise disabled windows will not get mouse events?
|
---|
1625 | if (id == 0) {
|
---|
1626 | QWidget *leave = qt_last_mouse_receiver;
|
---|
1627 | if (!leave)
|
---|
1628 | leave = QWidget::find(curWin);
|
---|
1629 | QApplicationPrivate::dispatchEnterLeave(0, leave);
|
---|
1630 | qt_last_mouse_receiver = 0;
|
---|
1631 | curWin = 0;
|
---|
1632 | } else {
|
---|
1633 | QWidget *leave = 0;
|
---|
1634 | if (curWin && qt_last_mouse_receiver)
|
---|
1635 | leave = qt_last_mouse_receiver;
|
---|
1636 | else
|
---|
1637 | leave = QWidget::find(curWin);
|
---|
1638 | QWidget *enter = alienWidget ? alienWidget : this;
|
---|
1639 | if (mouseGrabber && activePopupWidget) {
|
---|
1640 | if (leave != mouseGrabber)
|
---|
1641 | enter = mouseGrabber;
|
---|
1642 | else
|
---|
1643 | enter = activePopupWidget == this ? this : mouseGrabber;
|
---|
1644 | }
|
---|
1645 | QApplicationPrivate::dispatchEnterLeave(enter, leave);
|
---|
1646 | qt_last_mouse_receiver = enter;
|
---|
1647 | curWin = enter ? enter->effectiveWinId() : 0;
|
---|
1648 | }
|
---|
1649 | }
|
---|
1650 |
|
---|
1651 | // *** PM posts a dummy WM_MOUSEMOVE message (with the same, uncahnged
|
---|
1652 | // pointer coordinates) after every WinSetCapture that actually changes
|
---|
1653 | // the capture target. I.e., if the argument of WinSetCapture is
|
---|
1654 | // NULLHANDLE, a window under the mouse pointer gets this message,
|
---|
1655 | // otherwise the specified window gets it unless it is already under the
|
---|
1656 | // pointer. We use this info to check whether the window can be a double
|
---|
1657 | // click candidate (see above).
|
---|
1658 | if (qmsg.ptl.x == gpos.x && qmsg.ptl.y == gpos.y) {
|
---|
1659 | if (dblClickCandidateWin != qmsg.hwnd)
|
---|
1660 | dblClickCandidateWin = 0;
|
---|
1661 | return true;
|
---|
1662 | }
|
---|
1663 |
|
---|
1664 | gpos = qmsg.ptl;
|
---|
1665 |
|
---|
1666 | Q_ASSERT(testAttribute(Qt::WA_WState_Created));
|
---|
1667 |
|
---|
1668 | POINTL curPos = gpos;
|
---|
1669 | WinMapWindowPoints(internalWinId(), HWND_DESKTOP, &curPos, 1);
|
---|
1670 |
|
---|
1671 | pos.rx() = curPos.x;
|
---|
1672 | pos.ry() = curPos.y;
|
---|
1673 | pos = d_func()->mapFromWS(pos);
|
---|
1674 | } else {
|
---|
1675 | if (type == QEvent::MouseButtonPress && !isActiveWindow())
|
---|
1676 | activateWindow();
|
---|
1677 |
|
---|
1678 | gpos = qmsg.ptl;
|
---|
1679 | pos = mapFromGlobal(QPoint(gpos.x, gpos.y));
|
---|
1680 |
|
---|
1681 | // mouse button pressed
|
---|
1682 | if (!qt_button_down && (type == QEvent::MouseButtonPress || type == QEvent::MouseButtonDblClick)) {
|
---|
1683 | QWidget *tlw = window();
|
---|
1684 | if (QWidget *child = tlw->childAt(mapTo(tlw, pos)))
|
---|
1685 | qt_button_down = child;
|
---|
1686 | else
|
---|
1687 | qt_button_down = this;
|
---|
1688 | }
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 | // detect special button states
|
---|
1692 | enum { Other, SinglePressed, AllReleased } btnState = Other;
|
---|
1693 | int bs = state & Qt::MouseButtonMask;
|
---|
1694 | if ((type == QEvent::MouseButtonPress ||
|
---|
1695 | type == QEvent::MouseButtonDblClick) && bs == button) {
|
---|
1696 | btnState = SinglePressed;
|
---|
1697 | } else if (type == QEvent::MouseButtonRelease && bs == 0) {
|
---|
1698 | btnState = AllReleased;
|
---|
1699 | }
|
---|
1700 |
|
---|
1701 | bool res = false;
|
---|
1702 |
|
---|
1703 | if (qApp->d_func()->inPopupMode()) { // in popup mode
|
---|
1704 | if (!autoCaptureReleased && btnState == AllReleased) {
|
---|
1705 | // in order to give non-Qt windows the opportunity to see mouse
|
---|
1706 | // messages while our popups are active we need to release the
|
---|
1707 | // mouse capture which is absolute in OS/2. we do it directly
|
---|
1708 | // (not through releaseAutoCapture()) in order to keep
|
---|
1709 | // autoCaptureWnd nonzero to keep forwarding mouse move events
|
---|
1710 | // (actually sent to one of Qt widgets) to the active popup.
|
---|
1711 | autoCaptureReleased = true;
|
---|
1712 | WinSetCapture(HWND_DESKTOP, 0);
|
---|
1713 | } else if (autoCaptureReleased && btnState == SinglePressed) {
|
---|
1714 | // set the mouse capture back if a button is pressed.
|
---|
1715 | if ( autoCaptureWnd ) {
|
---|
1716 | autoCaptureReleased = false;
|
---|
1717 | WinSetCapture(HWND_DESKTOP, autoCaptureWnd);
|
---|
1718 | }
|
---|
1719 | }
|
---|
1720 |
|
---|
1721 | replayPopupMouseEvent = false;
|
---|
1722 | QWidget* activePopupWidget = qApp->activePopupWidget();
|
---|
1723 | QWidget *target = activePopupWidget;
|
---|
1724 | const QPoint globalPos(gpos.x, gpos.y);
|
---|
1725 |
|
---|
1726 | if (target != this) {
|
---|
1727 | if ((windowType() == Qt::Popup) && rect().contains(pos) && 0)
|
---|
1728 | target = this;
|
---|
1729 | else // send to last popup
|
---|
1730 | pos = target->mapFromGlobal(globalPos);
|
---|
1731 | }
|
---|
1732 | QWidget *popupChild = target->childAt(pos);
|
---|
1733 | bool releaseAfter = false;
|
---|
1734 | switch (type) {
|
---|
1735 | case QEvent::MouseButtonPress:
|
---|
1736 | case QEvent::MouseButtonDblClick:
|
---|
1737 | popupButtonFocus = popupChild;
|
---|
1738 | break;
|
---|
1739 | case QEvent::MouseButtonRelease:
|
---|
1740 | releaseAfter = true;
|
---|
1741 | break;
|
---|
1742 | default:
|
---|
1743 | break; // nothing for mouse move
|
---|
1744 | }
|
---|
1745 |
|
---|
1746 | if (target->isEnabled()) {
|
---|
1747 | if (popupButtonFocus) {
|
---|
1748 | target = popupButtonFocus;
|
---|
1749 | } else if (popupChild) {
|
---|
1750 | // forward mouse events to the popup child. mouse move events
|
---|
1751 | // are only forwarded to popup children that enable mouse tracking.
|
---|
1752 | if (type != QEvent::MouseMove || popupChild->hasMouseTracking())
|
---|
1753 | target = popupChild;
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 | pos = target->mapFromGlobal(globalPos);
|
---|
1757 | #ifndef QT_NO_CONTEXTMENU
|
---|
1758 | if (type == QEvent::ContextMenu) {
|
---|
1759 | QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos,
|
---|
1760 | Qt::KeyboardModifiers(state & Qt::KeyboardModifierMask));
|
---|
1761 | res = QApplication::sendSpontaneousEvent(target, &e);
|
---|
1762 | res = res && e.isAccepted();
|
---|
1763 | }
|
---|
1764 | else
|
---|
1765 | #endif
|
---|
1766 | {
|
---|
1767 | QMouseEvent e(type, pos, globalPos,
|
---|
1768 | Qt::MouseButton(button),
|
---|
1769 | Qt::MouseButtons(state & Qt::MouseButtonMask),
|
---|
1770 | Qt::KeyboardModifiers(state & Qt::KeyboardModifierMask));
|
---|
1771 | res = QApplicationPrivate::sendMouseEvent(target, &e, alienWidget, this, &qt_button_down,
|
---|
1772 | qt_last_mouse_receiver);
|
---|
1773 | res = res && e.isAccepted();
|
---|
1774 | }
|
---|
1775 | } else {
|
---|
1776 | // close disabled popups when a mouse button is pressed or released
|
---|
1777 | switch (type) {
|
---|
1778 | case QEvent::MouseButtonPress:
|
---|
1779 | case QEvent::MouseButtonDblClick:
|
---|
1780 | case QEvent::MouseButtonRelease:
|
---|
1781 | target->close();
|
---|
1782 | break;
|
---|
1783 | default:
|
---|
1784 | break;
|
---|
1785 | }
|
---|
1786 | }
|
---|
1787 |
|
---|
1788 | if (releaseAfter) {
|
---|
1789 | popupButtonFocus = 0;
|
---|
1790 | qt_button_down = 0;
|
---|
1791 | }
|
---|
1792 |
|
---|
1793 | if (type == QEvent::MouseButtonPress
|
---|
1794 | && qApp->activePopupWidget() != activePopupWidget
|
---|
1795 | && replayPopupMouseEvent) {
|
---|
1796 | // the popup dissappeared. Replay the event
|
---|
1797 | QWidget* w = QApplication::widgetAt(gpos.x, gpos.y);
|
---|
1798 | if (w && !QApplicationPrivate::isBlockedByModal(w)) {
|
---|
1799 | Q_ASSERT(w->testAttribute(Qt::WA_WState_Created));
|
---|
1800 | HWND hwndTarget = w->effectiveWinId();
|
---|
1801 | if (QWidget::mouseGrabber() == 0)
|
---|
1802 | setAutoCapture(hwndTarget);
|
---|
1803 | if (!w->isActiveWindow())
|
---|
1804 | w->activateWindow();
|
---|
1805 | POINTL pt = gpos;
|
---|
1806 | WinMapWindowPoints(HWND_DESKTOP, hwndTarget, &pt, 1);
|
---|
1807 | // flip y coordinate
|
---|
1808 | pt.y = w->height() - (pt.y + 1);
|
---|
1809 | WinPostMsg(hwndTarget, qmsg.msg,
|
---|
1810 | MPFROM2SHORT(pt.x, pt.y), qmsg.mp2);
|
---|
1811 | }
|
---|
1812 | }
|
---|
1813 | } else { // not popup mode
|
---|
1814 | if (btnState == SinglePressed && QWidget::mouseGrabber() == 0) {
|
---|
1815 | Q_ASSERT(testAttribute(Qt::WA_WState_Created));
|
---|
1816 | setAutoCapture(internalWinId());
|
---|
1817 | } else if (btnState == AllReleased && QWidget::mouseGrabber() == 0) {
|
---|
1818 | releaseAutoCapture();
|
---|
1819 | }
|
---|
1820 |
|
---|
1821 | const QPoint globalPos(gpos.x,gpos.y);
|
---|
1822 | QWidget *widget = QApplicationPrivate::pickMouseReceiver(this, globalPos, pos, type,
|
---|
1823 | Qt::MouseButtons(bs),
|
---|
1824 | qt_button_down, alienWidget);
|
---|
1825 | if (!widget)
|
---|
1826 | return false; // don't send event
|
---|
1827 |
|
---|
1828 | #ifndef QT_NO_CONTEXTMENU
|
---|
1829 | if (type == QEvent::ContextMenu) {
|
---|
1830 | QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos,
|
---|
1831 | Qt::KeyboardModifiers(state & Qt::KeyboardModifierMask));
|
---|
1832 | res = QApplication::sendSpontaneousEvent(widget, &e);
|
---|
1833 | res = res && e.isAccepted();
|
---|
1834 | } else
|
---|
1835 | #endif
|
---|
1836 | {
|
---|
1837 | QMouseEvent e(type, pos, globalPos, Qt::MouseButton(button),
|
---|
1838 | Qt::MouseButtons(state & Qt::MouseButtonMask),
|
---|
1839 | Qt::KeyboardModifiers(state & Qt::KeyboardModifierMask));
|
---|
1840 |
|
---|
1841 | res = QApplicationPrivate::sendMouseEvent(widget, &e, alienWidget, this, &qt_button_down,
|
---|
1842 | qt_last_mouse_receiver);
|
---|
1843 | res = res && e.isAccepted();
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | if (type != QEvent::MouseMove)
|
---|
1847 | pos.rx() = pos.ry() = -9999; // init for move compression
|
---|
1848 | }
|
---|
1849 |
|
---|
1850 | return res;
|
---|
1851 | }
|
---|
1852 |
|
---|
1853 | #ifndef QT_NO_WHEELEVENT
|
---|
1854 | bool QETWidget::translateWheelEvent(const QMSG &qmsg)
|
---|
1855 | {
|
---|
1856 | enum { WHEEL_DELTA = 120 };
|
---|
1857 |
|
---|
1858 | #ifndef QT_NO_SESSIONMANAGER
|
---|
1859 | if (sm_blockUserInput) // block user interaction during session management
|
---|
1860 | return true;
|
---|
1861 | #endif
|
---|
1862 |
|
---|
1863 | // consume duplicate wheel events sent by the AMouse driver to emulate
|
---|
1864 | // multiline scrolls. we need this since currently Qt (QScrollBar, for
|
---|
1865 | // instance) maintains the number of lines to scroll per wheel rotation
|
---|
1866 | // (including the special handling of CTRL and SHIFT modifiers) on its own
|
---|
1867 | // and doesn't have a setting to tell it to be aware of system settings
|
---|
1868 | // for the mouse wheel. if we had processed events as they are, we would
|
---|
1869 | // get a confusing behavior (too many lines scrolled etc.).
|
---|
1870 | {
|
---|
1871 | int devh = QApplication::desktop()->height();
|
---|
1872 | QMSG wheelMsg;
|
---|
1873 | while (WinPeekMsg(0, &wheelMsg, qmsg.hwnd, qmsg.msg, qmsg.msg, PM_NOREMOVE)) {
|
---|
1874 | // PM bug: ptl contains SHORT coordinates although fields are LONG
|
---|
1875 | wheelMsg.ptl.x = (short) wheelMsg.ptl.x;
|
---|
1876 | wheelMsg.ptl.y = (short) wheelMsg.ptl.y;
|
---|
1877 | // flip y coordinate
|
---|
1878 | wheelMsg.ptl.y = devh - (wheelMsg.ptl.y + 1);
|
---|
1879 | if (wheelMsg.mp1 != qmsg.mp1 ||
|
---|
1880 | wheelMsg.mp2 != qmsg.mp2 ||
|
---|
1881 | wheelMsg.ptl.x != qmsg.ptl.x ||
|
---|
1882 | wheelMsg.ptl.y != qmsg.ptl.y)
|
---|
1883 | break;
|
---|
1884 | WinPeekMsg(0, &wheelMsg, qmsg.hwnd, qmsg.msg, qmsg.msg, PM_REMOVE);
|
---|
1885 | }
|
---|
1886 | }
|
---|
1887 |
|
---|
1888 | int delta;
|
---|
1889 | USHORT cmd = SHORT2FROMMP(qmsg.mp2);
|
---|
1890 | switch (cmd) {
|
---|
1891 | case SB_LINEUP:
|
---|
1892 | case SB_PAGEUP:
|
---|
1893 | delta = WHEEL_DELTA;
|
---|
1894 | break;
|
---|
1895 | case SB_LINEDOWN:
|
---|
1896 | case SB_PAGEDOWN:
|
---|
1897 | delta = -WHEEL_DELTA;
|
---|
1898 | break;
|
---|
1899 | default:
|
---|
1900 | return false;
|
---|
1901 | }
|
---|
1902 |
|
---|
1903 | int state = 0;
|
---|
1904 | if (WinGetKeyState(HWND_DESKTOP, VK_SHIFT ) & 0x8000)
|
---|
1905 | state |= Qt::ShiftModifier;
|
---|
1906 | if (WinGetKeyState(HWND_DESKTOP, VK_ALT) & 0x8000 ||
|
---|
1907 | (qt_keymapper_private()->extraKeyState & Qt::AltModifier))
|
---|
1908 | state |= Qt::AltModifier;
|
---|
1909 | if (WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
|
---|
1910 | state |= Qt::ControlModifier;
|
---|
1911 | if (qt_keymapper_private()->extraKeyState & Qt::MetaModifier)
|
---|
1912 | state |= Qt::MetaModifier;
|
---|
1913 |
|
---|
1914 | Qt::Orientation orient;
|
---|
1915 | // Alt inverts scroll orientation (Qt/Win32 behavior)
|
---|
1916 | if (state & Qt::AltModifier)
|
---|
1917 | orient = qmsg.msg == WM_VSCROLL ? Qt::Horizontal : Qt::Vertical;
|
---|
1918 | else
|
---|
1919 | orient = qmsg.msg == WM_VSCROLL ? Qt::Vertical : Qt::Horizontal;
|
---|
1920 |
|
---|
1921 | QPoint globalPos(qmsg.ptl.x, qmsg.ptl.y);
|
---|
1922 |
|
---|
1923 | // if there is a widget under the mouse and it is not shadowed
|
---|
1924 | // by modality, we send the event to it first
|
---|
1925 | MRESULT rc = FALSE;
|
---|
1926 | QWidget* w = QApplication::widgetAt(globalPos);
|
---|
1927 | if (!w || !qt_try_modal(w, (QMSG*)&qmsg, rc)) {
|
---|
1928 | //synaptics touchpad shows its own widget at this position
|
---|
1929 | //so widgetAt() will fail with that HWND, try child of this widget
|
---|
1930 | w = this->childAt(this->mapFromGlobal(globalPos));
|
---|
1931 | if (!w)
|
---|
1932 | w = this;
|
---|
1933 | }
|
---|
1934 |
|
---|
1935 | // send the event to the widget or its ancestors
|
---|
1936 | {
|
---|
1937 | QWidget* popup = qApp->activePopupWidget();
|
---|
1938 | if (popup && w->window() != popup)
|
---|
1939 | popup->close();
|
---|
1940 | #ifndef QT_NO_WHEELEVENT
|
---|
1941 | QWheelEvent e(w->mapFromGlobal(globalPos), globalPos, delta,
|
---|
1942 | Qt::MouseButtons(state & Qt::MouseButtonMask),
|
---|
1943 | Qt::KeyboardModifier(state & Qt::KeyboardModifierMask), orient);
|
---|
1944 |
|
---|
1945 | if (QApplication::sendSpontaneousEvent(w, &e))
|
---|
1946 | #else
|
---|
1947 | Q_UNUSED(orient);
|
---|
1948 | #endif //QT_NO_WHEELEVENT
|
---|
1949 | return true;
|
---|
1950 | }
|
---|
1951 |
|
---|
1952 | // send the event to the widget that has the focus or its ancestors, if different
|
---|
1953 | if (w != qApp->focusWidget() && (w = qApp->focusWidget())) {
|
---|
1954 | QWidget* popup = qApp->activePopupWidget();
|
---|
1955 | if (popup && w->window() != popup)
|
---|
1956 | popup->close();
|
---|
1957 | #ifndef QT_NO_WHEELEVENT
|
---|
1958 | QWheelEvent e(w->mapFromGlobal(globalPos), globalPos, delta,
|
---|
1959 | Qt::MouseButtons(state & Qt::MouseButtonMask),
|
---|
1960 | Qt::KeyboardModifier(state & Qt::KeyboardModifierMask), orient);
|
---|
1961 | if (QApplication::sendSpontaneousEvent(w, &e))
|
---|
1962 | #endif //QT_NO_WHEELEVENT
|
---|
1963 | return true;
|
---|
1964 | }
|
---|
1965 |
|
---|
1966 | return false;
|
---|
1967 | }
|
---|
1968 | #endif
|
---|
1969 |
|
---|
1970 | //
|
---|
1971 | // Paint event translation
|
---|
1972 | //
|
---|
1973 | bool QETWidget::translatePaintEvent(const QMSG &qmsg)
|
---|
1974 | {
|
---|
1975 | if (!isWindow() && testAttribute(Qt::WA_NativeWindow))
|
---|
1976 | Q_ASSERT(internalWinId());
|
---|
1977 |
|
---|
1978 | HPS displayPS = qt_display_ps();
|
---|
1979 |
|
---|
1980 | // Since we don't use WS_CLIPSIBLINGS and WS_CLIPCHILDREN bits (see
|
---|
1981 | // qwidget_pm.cpp), we have to validate areas that intersect with our
|
---|
1982 | // children and siblings, taking their clip regions into account.
|
---|
1983 | d_func()->validateObstacles();
|
---|
1984 |
|
---|
1985 | Q_ASSERT(testAttribute(Qt::WA_WState_Created));
|
---|
1986 |
|
---|
1987 | HRGN hrgn = GpiCreateRegion(displayPS, 0, NULL);
|
---|
1988 | LONG rc = WinQueryUpdateRegion(internalWinId(), hrgn);
|
---|
1989 | if (rc == RGN_ERROR) { // The update bounding rect is invalid
|
---|
1990 | GpiDestroyRegion(displayPS, hrgn);
|
---|
1991 | d_func()->hd = NULLHANDLE;
|
---|
1992 | setAttribute(Qt::WA_PendingUpdate, false);
|
---|
1993 | return false;
|
---|
1994 | }
|
---|
1995 |
|
---|
1996 | setAttribute(Qt::WA_PendingUpdate, false);
|
---|
1997 |
|
---|
1998 | const QRegion dirtyInBackingStore(qt_dirtyRegion(this));
|
---|
1999 | // Make sure the invalidated region contains the region we're about to repaint.
|
---|
2000 | // BeginPaint will set the clip to the invalidated region and it is impossible
|
---|
2001 | // to enlarge it afterwards (only shrink it).
|
---|
2002 | if (!dirtyInBackingStore.isEmpty())
|
---|
2003 | WinInvalidateRegion(internalWinId(), dirtyInBackingStore.handle(height()), FALSE);
|
---|
2004 |
|
---|
2005 | RECTL rcl;
|
---|
2006 | d_func()->hd = WinBeginPaint(internalWinId(), 0, &rcl);
|
---|
2007 |
|
---|
2008 | #if defined(QT_DEBUGMSGFLOW)
|
---|
2009 | qDebug() << " PAINT BEGIN:" << rcl << "hps:" << qStrHPS(d_func()->hd);
|
---|
2010 | #endif
|
---|
2011 |
|
---|
2012 | // it's possible that the update rectangle is empty
|
---|
2013 | if (rcl.xRight <= rcl.xLeft || rcl.yTop <= rcl.yBottom) {
|
---|
2014 | WinEndPaint(d_func()->hd);
|
---|
2015 | GpiDestroyRegion(displayPS, hrgn);
|
---|
2016 | d_func()->hd = NULLHANDLE;
|
---|
2017 | setAttribute(Qt::WA_PendingUpdate, false);
|
---|
2018 | return true;
|
---|
2019 | }
|
---|
2020 |
|
---|
2021 | // flip y coordinate
|
---|
2022 | rcl.yBottom = height() - (rcl.yBottom + 1);
|
---|
2023 | rcl.yTop = height() - (rcl.yTop + 1);
|
---|
2024 |
|
---|
2025 | // note: right top point is exlusive in rcl
|
---|
2026 | QRect updRect(QPoint(rcl.xLeft, rcl.yTop + 1),
|
---|
2027 | QPoint(rcl.xRight - 1, rcl.yBottom));
|
---|
2028 |
|
---|
2029 | // Mapping region from system to qt (32 bit) coordinate system.
|
---|
2030 | updRect.translate(data->wrect.topLeft());
|
---|
2031 | #if defined(QT_DEBUGMSGFLOW)
|
---|
2032 | qDebug() << " PAINT updRect:" << updRect;
|
---|
2033 | #endif
|
---|
2034 |
|
---|
2035 | // @todo use hrgn here converted to QRegion?
|
---|
2036 | d_func()->syncBackingStore(updRect);
|
---|
2037 |
|
---|
2038 | WinEndPaint(d_func()->hd);
|
---|
2039 | d_func()->hd = NULLHANDLE;
|
---|
2040 |
|
---|
2041 | #if defined(QT_DEBUGMSGFLOW)
|
---|
2042 | qDebug() << " PAINT END";
|
---|
2043 | #endif
|
---|
2044 |
|
---|
2045 | return true;
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 | //
|
---|
2049 | // Window move and resize (configure) events
|
---|
2050 | //
|
---|
2051 |
|
---|
2052 | bool QETWidget::translateConfigEvent(const QMSG &qmsg)
|
---|
2053 | {
|
---|
2054 | if (!testAttribute(Qt::WA_WState_Created)) // in QWidget::create()
|
---|
2055 | return true;
|
---|
2056 | if (testAttribute(Qt::WA_WState_ConfigPending))
|
---|
2057 | return true;
|
---|
2058 | if (testAttribute(Qt::WA_DontShowOnScreen))
|
---|
2059 | return true;
|
---|
2060 |
|
---|
2061 | // @todo there are other isWindow() checks below (same in Windows code).
|
---|
2062 | // Either they or this return statement are leftovers. The assertion may
|
---|
2063 | // tell the truth.
|
---|
2064 | Q_ASSERT(isWindow());
|
---|
2065 | if (!isWindow())
|
---|
2066 | return true;
|
---|
2067 |
|
---|
2068 | // When the window is minimized, PM moves it to -32000,-32000 and resizes
|
---|
2069 | // to 48x50. We don't want these useless actions to be seen by Qt.
|
---|
2070 | if (isMinimized())
|
---|
2071 | return true;
|
---|
2072 |
|
---|
2073 | setAttribute(Qt::WA_WState_ConfigPending); // set config flag
|
---|
2074 |
|
---|
2075 | HWND fId = NULLHANDLE;
|
---|
2076 | ULONG fStyle = 0;
|
---|
2077 | if (isWindow()) {
|
---|
2078 | fId = d_func()->frameWinId();
|
---|
2079 | fStyle = WinQueryWindowULong(fId, QWL_STYLE);
|
---|
2080 | }
|
---|
2081 |
|
---|
2082 | // Note: due to the vertical coordinate space flip in PM, WM_SIZE events may
|
---|
2083 | // also mean moving the widget in Qt coordinates
|
---|
2084 |
|
---|
2085 | if (qmsg.msg == WM_MOVE || qmsg.msg == WM_SIZE) { // move event
|
---|
2086 | QPoint oldPos = data->crect.topLeft();
|
---|
2087 | SWP swp;
|
---|
2088 | if (isWindow()) {
|
---|
2089 | WinQueryWindowPos(fId, &swp);
|
---|
2090 | // flip y coordinate
|
---|
2091 | swp.y = QApplication::desktop()->height() - (swp.y + swp.cy);
|
---|
2092 | QTLWExtra *top = d_func()->topData();
|
---|
2093 | swp.x += top->frameStrut.left();
|
---|
2094 | swp.y += top->frameStrut.top();
|
---|
2095 | } else {
|
---|
2096 | WinQueryWindowPos(internalWinId(), &swp);
|
---|
2097 | // flip y coordinate
|
---|
2098 | swp.y = parentWidget()->height() - (swp.y + swp.cy);
|
---|
2099 | }
|
---|
2100 | QPoint newCPos(swp.x, swp.y);
|
---|
2101 | if (newCPos != oldPos) {
|
---|
2102 | data->crect.moveTopLeft(newCPos);
|
---|
2103 | if (isVisible()) {
|
---|
2104 | QMoveEvent e(newCPos, oldPos); // cpos (client position)
|
---|
2105 | QApplication::sendSpontaneousEvent(this, &e);
|
---|
2106 | } else {
|
---|
2107 | QMoveEvent *e = new QMoveEvent(newCPos, oldPos);
|
---|
2108 | QApplication::postEvent(this, e);
|
---|
2109 | }
|
---|
2110 | }
|
---|
2111 | }
|
---|
2112 | if (qmsg.msg == WM_SIZE) { // resize event
|
---|
2113 | QSize oldSize = data->crect.size();
|
---|
2114 | QSize newSize = QSize(SHORT1FROMMP(qmsg.mp2), SHORT2FROMMP(qmsg.mp2));
|
---|
2115 | data->crect.setSize(newSize);
|
---|
2116 | if (isWindow()) { // update title/icon text
|
---|
2117 | d_func()->createTLExtra();
|
---|
2118 | QString title;
|
---|
2119 | if ((fStyle & WS_MINIMIZED))
|
---|
2120 | title = windowIconText();
|
---|
2121 | if (title.isEmpty())
|
---|
2122 | title = windowTitle();
|
---|
2123 | if (!title.isEmpty())
|
---|
2124 | d_func()->setWindowTitle_helper(title);
|
---|
2125 | }
|
---|
2126 | if (oldSize != newSize) {
|
---|
2127 | // Spontaneous (external to Qt) WM_SIZE messages should occur only
|
---|
2128 | // on top-level widgets. If we get them for a non top-level widget,
|
---|
2129 | // the result will most likely be incorrect because widget masks will
|
---|
2130 | // not be properly processed (i.e. in the way it is done in
|
---|
2131 | // QWidget::setGeometry_sys() when the geometry is changed from
|
---|
2132 | // within Qt). So far, I see no need to support this (who will ever
|
---|
2133 | // need to move a non top-level window of a foreign process?).
|
---|
2134 | Q_ASSERT(isWindow());
|
---|
2135 | if (isVisible()) {
|
---|
2136 | QTLWExtra *tlwExtra = d_func()->maybeTopData();
|
---|
2137 | static bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt();
|
---|
2138 | const bool hasStaticContents = tlwExtra && tlwExtra->backingStore
|
---|
2139 | && tlwExtra->backingStore->hasStaticContents();
|
---|
2140 | // If we have a backing store with static contents, we have to disable the top-level
|
---|
2141 | // resize optimization in order to get invalidated regions for resized widgets.
|
---|
2142 | // The optimization discards all invalidateBuffer() calls since we're going to
|
---|
2143 | // repaint everything anyways, but that's not the case with static contents.
|
---|
2144 | if (!slowResize && tlwExtra && !hasStaticContents)
|
---|
2145 | tlwExtra->inTopLevelResize = true;
|
---|
2146 | QResizeEvent e(newSize, oldSize);
|
---|
2147 | QApplication::sendSpontaneousEvent(this, &e);
|
---|
2148 | if (d_func()->paintOnScreen()) {
|
---|
2149 | QRegion updateRegion(rect());
|
---|
2150 | if (testAttribute(Qt::WA_StaticContents))
|
---|
2151 | updateRegion -= QRect(0, 0, oldSize.width(), oldSize.height());
|
---|
2152 | // syncBackingStore() should have already flushed the widget
|
---|
2153 | // contents to the screen, so no need to redraw the exposed
|
---|
2154 | // areas in WM_PAINT once more
|
---|
2155 | d_func()->syncBackingStore(updateRegion);
|
---|
2156 | WinValidateRegion(internalWinId(),
|
---|
2157 | updateRegion.handle(newSize.height()), FALSE);
|
---|
2158 | } else {
|
---|
2159 | d_func()->syncBackingStore();
|
---|
2160 | // see above
|
---|
2161 | RECTL rcl = { 0, 0, newSize.width(), newSize.height() };
|
---|
2162 | WinValidateRect(internalWinId(), &rcl, FALSE);
|
---|
2163 | }
|
---|
2164 | if (!slowResize && tlwExtra)
|
---|
2165 | tlwExtra->inTopLevelResize = false;
|
---|
2166 | } else {
|
---|
2167 | QResizeEvent *e = new QResizeEvent(newSize, oldSize);
|
---|
2168 | QApplication::postEvent(this, e);
|
---|
2169 | }
|
---|
2170 | }
|
---|
2171 | }
|
---|
2172 | setAttribute(Qt::WA_WState_ConfigPending, false); // clear config flag
|
---|
2173 | return true;
|
---|
2174 | }
|
---|
2175 |
|
---|
2176 | //
|
---|
2177 | // Close window event translation.
|
---|
2178 | //
|
---|
2179 | // This class is a friend of QApplication because it needs to emit the
|
---|
2180 | // lastWindowClosed() signal when the last top level widget is closed.
|
---|
2181 | //
|
---|
2182 |
|
---|
2183 | bool QETWidget::translateCloseEvent(const QMSG &)
|
---|
2184 | {
|
---|
2185 | return d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
|
---|
2186 | }
|
---|
2187 |
|
---|
2188 |
|
---|
2189 | /*!
|
---|
2190 | Returns a QWidget pointer or 0 if there is no widget corresponding to the
|
---|
2191 | given HWND. As opposed to QWidget::find(), correctly handles WC_FRAME
|
---|
2192 | windows created for top level widgets. Used for debugging.
|
---|
2193 | */
|
---|
2194 | QWidget *qWidgetFromHWND(HWND hwnd)
|
---|
2195 | {
|
---|
2196 | char buf[10];
|
---|
2197 | if (WinQueryClassName(hwnd, sizeof(buf), buf)) {
|
---|
2198 | if (!strcmp(buf, "#1")) // WC_FRAME
|
---|
2199 | hwnd = WinWindowFromID(hwnd, FID_CLIENT);
|
---|
2200 | return QWidget::find(hwnd);
|
---|
2201 | }
|
---|
2202 | return 0;
|
---|
2203 | }
|
---|
2204 |
|
---|
2205 | /*!
|
---|
2206 | \internal
|
---|
2207 |
|
---|
2208 | Returns a human readable widget name in the form "class/name". Used for
|
---|
2209 | debugging.
|
---|
2210 | */
|
---|
2211 | QDbgStr qWidgetName(QWidget *w)
|
---|
2212 | {
|
---|
2213 | if (w)
|
---|
2214 | return QString()
|
---|
2215 | .sprintf("%s.%s", w->metaObject()->className(),
|
---|
2216 | w->objectName().isEmpty() ? "<noname>" :
|
---|
2217 | w->objectName().toUtf8().constData());
|
---|
2218 | return QString(QLatin1String("<no-widget>"));
|
---|
2219 | }
|
---|
2220 |
|
---|
2221 | /*****************************************************************************
|
---|
2222 | PM struct/message debug helpers
|
---|
2223 | *****************************************************************************/
|
---|
2224 |
|
---|
2225 | typedef QLatin1String QCStr;
|
---|
2226 |
|
---|
2227 | #define myDefFlagEx(var,fl,varstr,flstr) if (var & fl) { \
|
---|
2228 | if (!varstr.isEmpty()) varstr += QCStr("|"); varstr += QCStr(flstr); \
|
---|
2229 | } else do {} while(0)
|
---|
2230 |
|
---|
2231 | #define myDefFlag(var,fl,varstr) myDefFlagEx(var,fl,varstr,#fl)
|
---|
2232 | #define myDefFlagCut(var,fl,varstr,pos) myDefFlagEx(var,fl,varstr,#fl + pos)
|
---|
2233 |
|
---|
2234 | QDbgStr qStrHWND(HWND hwnd)
|
---|
2235 | {
|
---|
2236 | return QString().sprintf("%08lX/", hwnd) +
|
---|
2237 | qWidgetName(qWidgetFromHWND(hwnd));
|
---|
2238 | }
|
---|
2239 |
|
---|
2240 | QDbgStr qStrHPS(HPS hps)
|
---|
2241 | {
|
---|
2242 | return QString().sprintf("%08lX", hps);
|
---|
2243 | }
|
---|
2244 |
|
---|
2245 | QDbgStr qStrHPOINTER(HPOINTER hptr)
|
---|
2246 | {
|
---|
2247 | return QString().sprintf("%08lX", hptr);
|
---|
2248 | }
|
---|
2249 |
|
---|
2250 | QDbgStr qStrHRGN(HRGN hrgn)
|
---|
2251 | {
|
---|
2252 | return QString().sprintf("%08lX", hrgn);
|
---|
2253 | }
|
---|
2254 |
|
---|
2255 | QDbgStr qStrQMSG(const QMSG &qmsg)
|
---|
2256 | {
|
---|
2257 | QString str;
|
---|
2258 |
|
---|
2259 | #define myCaseBegin(a) case a: { \
|
---|
2260 | str = QString().sprintf(#a ": hwnd %08lX.", qmsg.hwnd); \
|
---|
2261 | str += qWidgetName(qWidgetFromHWND(qmsg.hwnd));
|
---|
2262 | #define myCaseEnd() }
|
---|
2263 |
|
---|
2264 | switch (qmsg.msg) {
|
---|
2265 |
|
---|
2266 | myCaseBegin(WM_CHAR)
|
---|
2267 | USHORT fl = SHORT1FROMMP(qmsg.mp1);
|
---|
2268 | UCHAR repeat = CHAR3FROMMP(qmsg.mp1);
|
---|
2269 | UCHAR scan = CHAR4FROMMP(qmsg.mp1);
|
---|
2270 | USHORT ch = SHORT1FROMMP(qmsg.mp2);
|
---|
2271 | USHORT vk = SHORT2FROMMP(qmsg.mp2);
|
---|
2272 | str += QString().
|
---|
2273 | sprintf(" rep %02d scan %02X ch %04X (%s) vk %04X",
|
---|
2274 | repeat, scan, ch, (ch > 32 && ch < 254) ?
|
---|
2275 | qPrintable(QString::fromLocal8Bit((char *)&ch, 1)) :
|
---|
2276 | qPrintable(QString(QChar(' '))), vk);
|
---|
2277 | QString flstr;
|
---|
2278 | myDefFlagEx(fl, KC_CHAR, flstr, "CHAR");
|
---|
2279 | myDefFlagEx(fl, KC_VIRTUALKEY, flstr, "VIRT");
|
---|
2280 | myDefFlagEx(fl, KC_SCANCODE, flstr, "SCAN");
|
---|
2281 | myDefFlagEx(fl, KC_SHIFT, flstr, "SHIFT");
|
---|
2282 | myDefFlagEx(fl, KC_CTRL, flstr, "CTRL");
|
---|
2283 | myDefFlagEx(fl, KC_ALT, flstr, "ALT");
|
---|
2284 | myDefFlagEx(fl, KC_KEYUP, flstr, "UP");
|
---|
2285 | myDefFlagEx(fl, KC_PREVDOWN, flstr, "PREVDWN");
|
---|
2286 | myDefFlagEx(fl, KC_LONEKEY, flstr, "LONE");
|
---|
2287 | myDefFlagEx(fl, KC_DEADKEY, flstr, "DEAD");
|
---|
2288 | myDefFlagEx(fl, KC_COMPOSITE, flstr, "COMP");
|
---|
2289 | myDefFlagEx(fl, KC_INVALIDCOMP, flstr, "INVCMP");
|
---|
2290 | myDefFlagEx(fl, KC_TOGGLE, flstr, "TGGL");
|
---|
2291 | myDefFlagEx(fl, KC_INVALIDCHAR, flstr, "INVCHR");
|
---|
2292 | str += QString().sprintf(" KC(%04X,", fl) + flstr + QCStr(")");
|
---|
2293 | break;
|
---|
2294 | myCaseEnd()
|
---|
2295 |
|
---|
2296 | myCaseBegin(WM_PAINT)
|
---|
2297 | break;
|
---|
2298 | myCaseEnd()
|
---|
2299 |
|
---|
2300 | myCaseBegin(WM_SIZE)
|
---|
2301 | str += QString().
|
---|
2302 | sprintf(" old (%hd,%hd) new (%hd,%hd)",
|
---|
2303 | SHORT1FROMMP(qmsg.mp1), SHORT2FROMMP(qmsg.mp1),
|
---|
2304 | SHORT1FROMMP(qmsg.mp2), SHORT2FROMMP(qmsg.mp2));
|
---|
2305 | SWP swp;
|
---|
2306 | WinQueryWindowPos(qmsg.hwnd, &swp);
|
---|
2307 | str += QCStr(" ") + qStrSWP(swp);
|
---|
2308 | HWND p = WinQueryWindow(qmsg.hwnd, QW_PARENT);
|
---|
2309 | if (p != NULLHANDLE && p != WinQueryDesktopWindow(0, 0)) {
|
---|
2310 | WinQueryWindowPos(p, &swp);
|
---|
2311 | str += QCStr(" p ") + qStrSWP(swp);
|
---|
2312 | }
|
---|
2313 | break;
|
---|
2314 | myCaseEnd()
|
---|
2315 |
|
---|
2316 | myCaseBegin(WM_MOVE)
|
---|
2317 | SWP swp;
|
---|
2318 | WinQueryWindowPos(qmsg.hwnd, &swp);
|
---|
2319 | str += QCStr(" ") + qStrSWP(swp);
|
---|
2320 | HWND p = WinQueryWindow(qmsg.hwnd, QW_PARENT);
|
---|
2321 | if (p != NULLHANDLE && p != WinQueryDesktopWindow(0, 0)) {
|
---|
2322 | WinQueryWindowPos(p, &swp);
|
---|
2323 | str += QCStr(" p ") + qStrSWP(swp);
|
---|
2324 | }
|
---|
2325 | break;
|
---|
2326 | myCaseEnd()
|
---|
2327 |
|
---|
2328 | myCaseBegin(WM_WINDOWPOSCHANGED)
|
---|
2329 | str += QCStr(" ") + qStrSWP(*((PSWP) qmsg.mp1));
|
---|
2330 | ULONG awp = LONGFROMMP(qmsg.mp2);
|
---|
2331 | QString awpstr;
|
---|
2332 | myDefFlagEx(awp, AWP_MINIMIZED, awpstr, "MIN");
|
---|
2333 | myDefFlagEx(awp, AWP_MAXIMIZED, awpstr, "MAX");
|
---|
2334 | myDefFlagEx(awp, AWP_RESTORED, awpstr, "REST");
|
---|
2335 | myDefFlagEx(awp, AWP_ACTIVATE, awpstr, "ACT");
|
---|
2336 | myDefFlagEx(awp, AWP_DEACTIVATE, awpstr, "DEACT");
|
---|
2337 | str += QCStr(" AWP(") + awpstr + QCStr(")");
|
---|
2338 | break;
|
---|
2339 | myCaseEnd()
|
---|
2340 |
|
---|
2341 | myCaseBegin(WM_MINMAXFRAME)
|
---|
2342 | str += QCStr(" ") + qStrSWP(*((PSWP) qmsg.mp1));
|
---|
2343 | break;
|
---|
2344 | myCaseEnd()
|
---|
2345 |
|
---|
2346 | myCaseBegin(WM_ACTIVATE)
|
---|
2347 | bool active = SHORT1FROMMP(qmsg.mp1);
|
---|
2348 | HWND hwnd = (HWND)qmsg.mp2;
|
---|
2349 | str += QCStr(" Active(") + QCStr(active ? "TRUE) " : "FALSE)");
|
---|
2350 | str += QString().sprintf(" hwnd %08lX.", hwnd);
|
---|
2351 | str += qWidgetName(qWidgetFromHWND(hwnd));
|
---|
2352 | break;
|
---|
2353 | myCaseEnd()
|
---|
2354 |
|
---|
2355 | myCaseBegin(WM_SETFOCUS)
|
---|
2356 | HWND hwnd = (HWND)qmsg.mp1;
|
---|
2357 | bool focus = SHORT1FROMMP(qmsg.mp2);
|
---|
2358 | str += QCStr(" Focus(") + QCStr(focus ? "TRUE) " : "FALSE)");
|
---|
2359 | str += QString().sprintf(" hwnd %08lX.", hwnd);
|
---|
2360 | str += qWidgetName(qWidgetFromHWND(hwnd));
|
---|
2361 | break;
|
---|
2362 | myCaseEnd()
|
---|
2363 |
|
---|
2364 | default:
|
---|
2365 | #if 0
|
---|
2366 | if (qmsg.msg == WM_QUERYICON)
|
---|
2367 | break;
|
---|
2368 | str = QString().sprintf("WM_%04lX: hwnd %08lX.", qmsg.msg, qmsg.hwnd);
|
---|
2369 | str += qWidgetName(qWidgetFromHWND(qmsg.hwnd));
|
---|
2370 | #endif
|
---|
2371 | break;
|
---|
2372 | }
|
---|
2373 |
|
---|
2374 | return str;
|
---|
2375 |
|
---|
2376 | #undef myCaseEnd
|
---|
2377 | #undef myCaseBegin
|
---|
2378 | }
|
---|
2379 |
|
---|
2380 | QDbgStr qStrRECTL(const RECTL &rcl)
|
---|
2381 | {
|
---|
2382 | return QString().sprintf("RECTL(%ld,%ld %ld,%ld)",
|
---|
2383 | rcl.xLeft, rcl.yBottom, rcl.xRight, rcl.yTop);
|
---|
2384 | }
|
---|
2385 |
|
---|
2386 | QDbgStr qStrSWP(const SWP &swp)
|
---|
2387 | {
|
---|
2388 | QString fl;
|
---|
2389 | myDefFlagEx(swp.fl, SWP_SIZE, fl, "SIZE");
|
---|
2390 | myDefFlagEx(swp.fl, SWP_MOVE, fl, "MOVE");
|
---|
2391 | myDefFlagEx(swp.fl, SWP_ZORDER, fl, "ZORD");
|
---|
2392 | myDefFlagEx(swp.fl, SWP_SHOW, fl, "SHOW");
|
---|
2393 | myDefFlagEx(swp.fl, SWP_HIDE, fl, "HIDE");
|
---|
2394 | myDefFlagEx(swp.fl, SWP_NOREDRAW, fl, "NORDR");
|
---|
2395 | myDefFlagEx(swp.fl, SWP_NOADJUST, fl, "NOADJ");
|
---|
2396 | myDefFlagEx(swp.fl, SWP_ACTIVATE, fl, "ACT");
|
---|
2397 | myDefFlagEx(swp.fl, SWP_DEACTIVATE, fl, "DEACT");
|
---|
2398 | myDefFlagEx(swp.fl, SWP_EXTSTATECHANGE, fl, "EXTST");
|
---|
2399 | myDefFlagEx(swp.fl, SWP_MINIMIZE, fl, "MIN");
|
---|
2400 | myDefFlagEx(swp.fl, SWP_MAXIMIZE, fl, "MAX");
|
---|
2401 | myDefFlagEx(swp.fl, SWP_RESTORE, fl, "REST");
|
---|
2402 | myDefFlagEx(swp.fl, SWP_FOCUSACTIVATE, fl, "FCSACT");
|
---|
2403 | myDefFlagEx(swp.fl, SWP_FOCUSDEACTIVATE, fl, "FCSDEACT");
|
---|
2404 | myDefFlagEx(swp.fl, SWP_NOAUTOCLOSE, fl, "NOACLOSE");
|
---|
2405 |
|
---|
2406 | return QString().sprintf("SWP(%ld,%ld %ldx%ld %08lX ",
|
---|
2407 | swp.x, swp.y, swp.cx, swp.cy, swp.hwndInsertBehind) +
|
---|
2408 | fl + QLatin1String(")");
|
---|
2409 | }
|
---|
2410 |
|
---|
2411 | #undef myDefFlagCut
|
---|
2412 | #undef myDefFlag
|
---|
2413 | #undef myDefFlagEx
|
---|
2414 |
|
---|
2415 | QT_END_NAMESPACE
|
---|