Changeset 605 for trunk/src/gui/kernel/qapplication_pm.cpp
- Timestamp:
- Feb 26, 2010, 12:33:58 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/kernel/qapplication_pm.cpp
r603 r605 451 451 } 452 452 453 /*! 454 Returns a QWidget pointer or 0 if there is no widget corresponding to the 455 given HWND. As opposed to QWidget::find(), correctly handles WC_FRAME 456 windows created for top level widgets. 457 */ 458 QWidget *qt_widget_from_hwnd(HWND hwnd) 459 { 460 char buf[10]; 461 if (WinQueryClassName(hwnd, sizeof(buf), buf)) { 462 if (!strcmp(buf, "#1")) // WC_FRAME 463 hwnd = WinWindowFromID(hwnd, FID_CLIENT); 464 return QWidget::find(hwnd); 465 } 466 return 0; 467 } 468 453 469 // application no-grab option 454 470 bool qt_nograb() … … 700 716 return 0; 701 717 702 QWidget *w = q WidgetFromHWND(hwnd);718 QWidget *w = qt_widget_from_hwnd(hwnd); 703 719 return w ? w->window() : 0; 704 720 } … … 796 812 797 813 #if defined(QT_DEBUGMSGFLOW) 798 { 799 QDbgStr str = qStrQMSG(qmsg); 800 if (!str.isEmpty()) 801 qDebug() << "*** [W]" << str; 802 } 814 if (qmsg.msg != WM_QUERYICON) 815 qDebug() << "*** [W]" << qmsg; 803 816 #endif 804 817 … … 1269 1282 1270 1283 #if defined(QT_DEBUGMSGFLOW) 1271 { 1272 QDbgStr str = qStrQMSG(qmsg); 1273 if (!str.isEmpty()) 1274 qDebug() << "*** [F]" << str; 1275 } 1284 if (qmsg.msg != WM_QUERYICON) 1285 qDebug() << "*** [F]" << qmsg; 1276 1286 #endif 1277 1287 … … 1368 1378 1369 1379 #if defined(QT_DEBUGMSGFLOW) 1370 { 1371 QDbgStr str = qStrQMSG(qmsg); 1372 if (!str.isEmpty()) 1373 qDebug() << "*** [FC]" << str; 1374 } 1380 if (qmsg.msg != WM_QUERYICON) 1381 qDebug() << "*** [FC]" << qmsg; 1375 1382 #endif 1376 1383 … … 1538 1545 setAutoCapture(popup->d_func()->frameWinId()); // grab mouse/keyboard 1539 1546 } 1540 if (!q WidgetFromHWND(WinQueryActiveWindow(HWND_DESKTOP))) {1547 if (!qt_widget_from_hwnd(WinQueryActiveWindow(HWND_DESKTOP))) { 1541 1548 // the popup is opened while another application is active. Steal 1542 1549 // the focus (to receive keyboard input and to make sure we get … … 2267 2274 2268 2275 #if defined(QT_DEBUGMSGFLOW) 2269 qDebug() << " PAINT BEGIN:" << rcl << "hps:" << qStrHPS(d_func()->hd);2276 qDebug() << "PAINT BEGIN:" << rcl << "hps" << qDebugFmtHex(d_func()->hd); 2270 2277 #endif 2271 2278 … … 2287 2294 updRect.translate(data->wrect.topLeft()); 2288 2295 #if defined(QT_DEBUGMSGFLOW) 2289 qDebug() << " 2296 qDebug() << "PAINT updRect:" << updRect; 2290 2297 #endif 2291 2298 … … 2297 2304 2298 2305 #if defined(QT_DEBUGMSGFLOW) 2299 qDebug() << " 2306 qDebug() << "PAINT END"; 2300 2307 #endif 2301 2308 … … 2552 2559 *****************************************************************************/ 2553 2560 2554 /*! 2555 Returns a QWidget pointer or 0 if there is no widget corresponding to the 2556 given HWND. As opposed to QWidget::find(), correctly handles WC_FRAME 2557 windows created for top level widgets. Used for debugging. 2558 */ 2559 QWidget *qWidgetFromHWND(HWND hwnd) 2560 { 2561 char buf[10]; 2562 if (WinQueryClassName(hwnd, sizeof(buf), buf)) { 2563 if (!strcmp(buf, "#1")) // WC_FRAME 2564 hwnd = WinWindowFromID(hwnd, FID_CLIENT); 2565 return QWidget::find(hwnd); 2566 } 2567 return 0; 2568 } 2569 2570 /*! 2571 \internal 2572 2573 Returns a human readable widget name in the form "class/name". Used for 2574 debugging. 2575 */ 2576 QDbgStr qWidgetName(QWidget *w) 2577 { 2578 if (w) 2579 return QString() 2580 .sprintf("%s.%s", w->metaObject()->className(), 2581 w->objectName().isEmpty() ? "<noname>" : 2582 w->objectName().toUtf8().constData()); 2583 return QString(QLatin1String("<no-widget>")); 2584 } 2585 2586 typedef QLatin1String QCStr; 2561 QDebug operator<<(QDebug debug, const QDebugHWND &d) 2562 { 2563 debug << qDebugFmtHex(d.hwnd) << qt_widget_from_hwnd(d.hwnd); 2564 return debug; 2565 } 2566 2567 QDebug operator<<(QDebug debug, const RECTL &rcl) 2568 { 2569 debug.nospace() << "RECTL(" << rcl.xLeft << "," << rcl.yBottom 2570 << " " << rcl.xRight << "," << rcl.yTop << ")"; 2571 return debug.space(); 2572 } 2587 2573 2588 2574 #define myDefFlagEx(var,fl,varstr,flstr) if (var & fl) { \ 2589 if (!varstr.isEmpty()) varstr += QCStr("|"); varstr += QCStr(flstr); \2575 if (!varstr.isEmpty()) varstr += "|"; varstr += flstr; \ 2590 2576 } else do {} while(0) 2591 2577 … … 2593 2579 #define myDefFlagCut(var,fl,varstr,pos) myDefFlagEx(var,fl,varstr,#fl + pos) 2594 2580 2595 QDbgStr qStrHWND(HWND hwnd) 2596 { 2597 return QString().sprintf("%08lX/", hwnd) + 2598 qWidgetName(qWidgetFromHWND(hwnd)); 2599 } 2600 2601 QDbgStr qStrHPS(HPS hps) 2602 { 2603 return QString().sprintf("%08lX", hps); 2604 } 2605 2606 QDbgStr qStrHPOINTER(HPOINTER hptr) 2607 { 2608 return QString().sprintf("%08lX", hptr); 2609 } 2610 2611 QDbgStr qStrHRGN(HRGN hrgn) 2612 { 2613 return QString().sprintf("%08lX", hrgn); 2614 } 2615 2616 QDbgStr qStrQMSG(const QMSG &qmsg) 2617 { 2618 QString str; 2619 2620 #define myCaseBegin(a) case a: { \ 2621 str = QString().sprintf(#a ": hwnd %08lX.", qmsg.hwnd); \ 2622 str += qWidgetName(qWidgetFromHWND(qmsg.hwnd)); 2623 #define myCaseEnd() } 2624 2625 switch (qmsg.msg) { 2626 2627 myCaseBegin(WM_CHAR) 2628 USHORT fl = SHORT1FROMMP(qmsg.mp1); 2629 UCHAR repeat = CHAR3FROMMP(qmsg.mp1); 2630 UCHAR scan = CHAR4FROMMP(qmsg.mp1); 2631 USHORT ch = SHORT1FROMMP(qmsg.mp2); 2632 USHORT vk = SHORT2FROMMP(qmsg.mp2); 2633 str += QString(). 2634 sprintf(" rep %02d scan %02X ch %04X (%s) vk %04X", 2635 repeat, scan, ch, (ch > 32 && ch < 254) ? 2636 qPrintable(QString::fromLocal8Bit((char *)&ch, 1)) : 2637 qPrintable(QString(QChar(QLatin1Char(' ')))), vk); 2638 QString flstr; 2639 myDefFlagEx(fl, KC_CHAR, flstr, "CHAR"); 2640 myDefFlagEx(fl, KC_VIRTUALKEY, flstr, "VIRT"); 2641 myDefFlagEx(fl, KC_SCANCODE, flstr, "SCAN"); 2642 myDefFlagEx(fl, KC_SHIFT, flstr, "SHIFT"); 2643 myDefFlagEx(fl, KC_CTRL, flstr, "CTRL"); 2644 myDefFlagEx(fl, KC_ALT, flstr, "ALT"); 2645 myDefFlagEx(fl, KC_KEYUP, flstr, "UP"); 2646 myDefFlagEx(fl, KC_PREVDOWN, flstr, "PREVDWN"); 2647 myDefFlagEx(fl, KC_LONEKEY, flstr, "LONE"); 2648 myDefFlagEx(fl, KC_DEADKEY, flstr, "DEAD"); 2649 myDefFlagEx(fl, KC_COMPOSITE, flstr, "COMP"); 2650 myDefFlagEx(fl, KC_INVALIDCOMP, flstr, "INVCMP"); 2651 myDefFlagEx(fl, KC_TOGGLE, flstr, "TGGL"); 2652 myDefFlagEx(fl, KC_INVALIDCHAR, flstr, "INVCHR"); 2653 str += QString().sprintf(" KC(%04X,", fl) + flstr + QCStr(")"); 2654 break; 2655 myCaseEnd() 2656 2657 myCaseBegin(WM_KBDLAYERCHANGED) 2658 str += QString().sprintf(" mp1 %p mp2 %p", qmsg.mp1, qmsg.mp2); 2659 break; 2660 myCaseEnd() 2661 2662 myCaseBegin(WM_PAINT) 2663 break; 2664 myCaseEnd() 2665 2666 myCaseBegin(WM_SIZE) 2667 str += QString(). 2668 sprintf(" old (%hd,%hd) new (%hd,%hd)", 2669 SHORT1FROMMP(qmsg.mp1), SHORT2FROMMP(qmsg.mp1), 2670 SHORT1FROMMP(qmsg.mp2), SHORT2FROMMP(qmsg.mp2)); 2671 SWP swp; 2672 WinQueryWindowPos(qmsg.hwnd, &swp); 2673 str += QCStr(" ") + qStrSWP(swp); 2674 HWND p = WinQueryWindow(qmsg.hwnd, QW_PARENT); 2675 if (p != NULLHANDLE && p != WinQueryDesktopWindow(0, 0)) { 2676 WinQueryWindowPos(p, &swp); 2677 str += QCStr(" p ") + qStrSWP(swp); 2678 } 2679 break; 2680 myCaseEnd() 2681 2682 myCaseBegin(WM_MOVE) 2683 SWP swp; 2684 WinQueryWindowPos(qmsg.hwnd, &swp); 2685 str += QCStr(" ") + qStrSWP(swp); 2686 HWND p = WinQueryWindow(qmsg.hwnd, QW_PARENT); 2687 if (p != NULLHANDLE && p != WinQueryDesktopWindow(0, 0)) { 2688 WinQueryWindowPos(p, &swp); 2689 str += QCStr(" p ") + qStrSWP(swp); 2690 } 2691 break; 2692 myCaseEnd() 2693 2694 myCaseBegin(WM_WINDOWPOSCHANGED) 2695 str += QCStr(" ") + qStrSWP(*((PSWP) qmsg.mp1)); 2696 ULONG awp = LONGFROMMP(qmsg.mp2); 2697 QString awpstr; 2698 myDefFlagEx(awp, AWP_MINIMIZED, awpstr, "MIN"); 2699 myDefFlagEx(awp, AWP_MAXIMIZED, awpstr, "MAX"); 2700 myDefFlagEx(awp, AWP_RESTORED, awpstr, "REST"); 2701 myDefFlagEx(awp, AWP_ACTIVATE, awpstr, "ACT"); 2702 myDefFlagEx(awp, AWP_DEACTIVATE, awpstr, "DEACT"); 2703 str += QCStr(" AWP(") + awpstr + QCStr(")"); 2704 break; 2705 myCaseEnd() 2706 2707 myCaseBegin(WM_MINMAXFRAME) 2708 str += QCStr(" ") + qStrSWP(*((PSWP) qmsg.mp1)); 2709 break; 2710 myCaseEnd() 2711 2712 myCaseBegin(WM_ACTIVATE) 2713 bool active = SHORT1FROMMP(qmsg.mp1); 2714 HWND hwnd = (HWND)qmsg.mp2; 2715 str += QCStr(" Active(") + QCStr(active ? "TRUE) " : "FALSE)"); 2716 str += QString().sprintf(" hwndActive %08lX.", hwnd); 2717 str += qWidgetName(qWidgetFromHWND(hwnd)); 2718 break; 2719 myCaseEnd() 2720 2721 myCaseBegin(WM_SETFOCUS) 2722 HWND hwnd = (HWND)qmsg.mp1; 2723 bool focus = SHORT1FROMMP(qmsg.mp2); 2724 str += QCStr(" Focus(") + QCStr(focus ? "TRUE) " : "FALSE)"); 2725 str += QString().sprintf(" hwndFocus %08lX.", hwnd); 2726 str += qWidgetName(qWidgetFromHWND(hwnd)); 2727 break; 2728 myCaseEnd() 2729 2730 myCaseBegin(WM_FOCUSCHANGE) 2731 HWND hwnd = (HWND)qmsg.mp1; 2732 bool focus = SHORT1FROMMP(qmsg.mp2); 2733 bool fl = SHORT2FROMMP(qmsg.mp2); 2734 QString flstr; 2735 myDefFlagEx(fl, FC_NOSETFOCUS, flstr, "NOSETFCS"); 2736 myDefFlagEx(fl, FC_NOLOSEFOCUS, flstr, "NOLOSEFCS"); 2737 myDefFlagEx(fl, FC_NOSETACTIVE, flstr, "NOSETACT"); 2738 myDefFlagEx(fl, FC_NOLOSEACTIVE, flstr, "NOLOSEACT"); 2739 myDefFlagEx(fl, FC_NOSETSELECTION, flstr, "NOSETSEL"); 2740 myDefFlagEx(fl, FC_NOLOSESELECTION, flstr, "NOSETSEL"); 2741 str += QCStr(" Focus(") + QCStr(focus ? "TRUE) " : "FALSE)"); 2742 str += QString().sprintf(" hwndFocus %08lX.", hwnd); 2743 str += qWidgetName(qWidgetFromHWND(hwnd)); 2744 str += QCStr(" FC(") + flstr + QCStr(")"); 2745 break; 2746 myCaseEnd() 2747 2748 default: 2749 #if 0 2750 if (qmsg.msg == WM_QUERYICON) 2751 break; 2752 str = QString().sprintf("WM_%04lX: hwnd %08lX.", qmsg.msg, qmsg.hwnd); 2753 str += qWidgetName(qWidgetFromHWND(qmsg.hwnd)); 2754 #endif 2755 break; 2756 } 2757 2758 return str; 2759 2760 #undef myCaseEnd 2761 #undef myCaseBegin 2762 } 2763 2764 QDbgStr qStrRECTL(const RECTL &rcl) 2765 { 2766 return QString().sprintf("RECTL(%ld,%ld %ld,%ld)", 2767 rcl.xLeft, rcl.yBottom, rcl.xRight, rcl.yTop); 2768 } 2769 2770 QDbgStr qStrSWP(const SWP &swp) 2771 { 2772 QString fl; 2581 QDebug operator<<(QDebug debug, const SWP &swp) 2582 { 2583 QByteArray fl; 2773 2584 myDefFlagEx(swp.fl, SWP_SIZE, fl, "SIZE"); 2774 2585 myDefFlagEx(swp.fl, SWP_MOVE, fl, "MOVE"); … … 2788 2599 myDefFlagEx(swp.fl, SWP_NOAUTOCLOSE, fl, "NOACLOSE"); 2789 2600 2790 return QString().sprintf("SWP(%ld,%ld %ldx%ld %08lX ", 2791 swp.x, swp.y, swp.cx, swp.cy, swp.hwndInsertBehind) + 2792 fl + QLatin1String(")"); 2601 debug.nospace() << "SWP(" << swp.x << "," << swp.y 2602 << " " << swp.cx << "x" << swp.cy << " " 2603 << qDebugFmtHex(swp.hwndInsertBehind) 2604 << fl.constData() << ")"; 2605 return debug.space(); 2606 } 2607 2608 QDebug operator<<(QDebug debug, const QMSG &qmsg) 2609 { 2610 #define myCaseBegin(a) case a: { \ 2611 debug << #a": hwnd" << qDebugHWND(qmsg.hwnd); 2612 #define myCaseEnd() } 2613 2614 switch (qmsg.msg) { 2615 2616 myCaseBegin(WM_CHAR) 2617 USHORT fl = SHORT1FROMMP(qmsg.mp1); 2618 UCHAR repeat = CHAR3FROMMP(qmsg.mp1); 2619 UCHAR scan = CHAR4FROMMP(qmsg.mp1); 2620 USHORT ch = SHORT1FROMMP(qmsg.mp2); 2621 USHORT vk = SHORT2FROMMP(qmsg.mp2); 2622 QByteArray flstr; 2623 myDefFlagEx(fl, KC_CHAR, flstr, "CHAR"); 2624 myDefFlagEx(fl, KC_VIRTUALKEY, flstr, "VIRT"); 2625 myDefFlagEx(fl, KC_SCANCODE, flstr, "SCAN"); 2626 myDefFlagEx(fl, KC_SHIFT, flstr, "SHIFT"); 2627 myDefFlagEx(fl, KC_CTRL, flstr, "CTRL"); 2628 myDefFlagEx(fl, KC_ALT, flstr, "ALT"); 2629 myDefFlagEx(fl, KC_KEYUP, flstr, "UP"); 2630 myDefFlagEx(fl, KC_PREVDOWN, flstr, "PREVDWN"); 2631 myDefFlagEx(fl, KC_LONEKEY, flstr, "LONE"); 2632 myDefFlagEx(fl, KC_DEADKEY, flstr, "DEAD"); 2633 myDefFlagEx(fl, KC_COMPOSITE, flstr, "COMP"); 2634 myDefFlagEx(fl, KC_INVALIDCOMP, flstr, "INVCMP"); 2635 myDefFlagEx(fl, KC_TOGGLE, flstr, "TGGL"); 2636 myDefFlagEx(fl, KC_INVALIDCHAR, flstr, "INVCHR"); 2637 2638 debug << "rep" << qDebugFmt("%02d", repeat) 2639 << "scan" << qDebugFmtHex(scan) << "ch" << qDebugFmtHex(ch) 2640 << ((ch > 32 && ch < 254) ? QString::fromLocal8Bit((char *)&ch, 1) : 2641 QString(QLatin1String(" "))) 2642 << "vk" << qDebugFmtHex(vk); 2643 debug.nospace() << "KC(" << qDebugFmtHex(fl) << "," 2644 << flstr.constData() << ")"; 2645 debug.space(); 2646 break; 2647 myCaseEnd() 2648 2649 myCaseBegin(WM_KBDLAYERCHANGED) 2650 debug << "mp1" << qmsg.mp1 << "mp2" << qmsg.mp2; 2651 break; 2652 myCaseEnd() 2653 2654 myCaseBegin(WM_PAINT) 2655 debug << "mp1" << qmsg.mp1 << "mp2" << qmsg.mp2; 2656 break; 2657 myCaseEnd() 2658 2659 myCaseBegin(WM_SIZE) 2660 SWP swp; 2661 WinQueryWindowPos(qmsg.hwnd, &swp); 2662 debug << "old " << SHORT1FROMMP(qmsg.mp1) << SHORT2FROMMP(qmsg.mp1) 2663 << "new " << SHORT1FROMMP(qmsg.mp2) << SHORT2FROMMP(qmsg.mp2) 2664 << swp; 2665 HWND p = WinQueryWindow(qmsg.hwnd, QW_PARENT); 2666 if (p != NULLHANDLE && p != WinQueryDesktopWindow(0, 0)) { 2667 WinQueryWindowPos(p, &swp); 2668 debug << "parent" << swp; 2669 } 2670 break; 2671 myCaseEnd() 2672 2673 myCaseBegin(WM_MOVE) 2674 SWP swp; 2675 WinQueryWindowPos(qmsg.hwnd, &swp); 2676 debug << swp; 2677 HWND p = WinQueryWindow(qmsg.hwnd, QW_PARENT); 2678 if (p != NULLHANDLE && p != WinQueryDesktopWindow(0, 0)) { 2679 WinQueryWindowPos(p, &swp); 2680 debug << "parent" << swp; 2681 } 2682 break; 2683 myCaseEnd() 2684 2685 myCaseBegin(WM_WINDOWPOSCHANGED) 2686 debug << *((PSWP) qmsg.mp1); 2687 ULONG awp = LONGFROMMP(qmsg.mp2); 2688 QByteArray awpstr; 2689 myDefFlagEx(awp, AWP_MINIMIZED, awpstr, "MIN"); 2690 myDefFlagEx(awp, AWP_MAXIMIZED, awpstr, "MAX"); 2691 myDefFlagEx(awp, AWP_RESTORED, awpstr, "REST"); 2692 myDefFlagEx(awp, AWP_ACTIVATE, awpstr, "ACT"); 2693 myDefFlagEx(awp, AWP_DEACTIVATE, awpstr, "DEACT"); 2694 debug.nospace() << "AWP(" << awpstr.constData() << ")"; 2695 debug.space(); 2696 break; 2697 myCaseEnd() 2698 2699 myCaseBegin(WM_MINMAXFRAME) 2700 debug << *((PSWP) qmsg.mp1); 2701 break; 2702 myCaseEnd() 2703 2704 myCaseBegin(WM_ACTIVATE) 2705 bool active = SHORT1FROMMP(qmsg.mp1); 2706 HWND hwnd = (HWND)qmsg.mp2; 2707 debug.nospace() << "Active(" << (active ? "TRUE)" : "FALSE)"); 2708 debug.space() << "hwndActive" << qDebugHWND(hwnd); 2709 break; 2710 myCaseEnd() 2711 2712 myCaseBegin(WM_SETFOCUS) 2713 HWND hwnd = (HWND)qmsg.mp1; 2714 bool focus = SHORT1FROMMP(qmsg.mp2); 2715 debug.nospace() << "Focus(" << (focus ? "TRUE) " : "FALSE)"); 2716 debug.space() << "hwndFocus" << qDebugHWND(hwnd); 2717 break; 2718 myCaseEnd() 2719 2720 myCaseBegin(WM_FOCUSCHANGE) 2721 HWND hwnd = (HWND)qmsg.mp1; 2722 bool focus = SHORT1FROMMP(qmsg.mp2); 2723 bool fl = SHORT2FROMMP(qmsg.mp2); 2724 QByteArray flstr; 2725 myDefFlagEx(fl, FC_NOSETFOCUS, flstr, "NOSETFCS"); 2726 myDefFlagEx(fl, FC_NOLOSEFOCUS, flstr, "NOLOSEFCS"); 2727 myDefFlagEx(fl, FC_NOSETACTIVE, flstr, "NOSETACT"); 2728 myDefFlagEx(fl, FC_NOLOSEACTIVE, flstr, "NOLOSEACT"); 2729 myDefFlagEx(fl, FC_NOSETSELECTION, flstr, "NOSETSEL"); 2730 myDefFlagEx(fl, FC_NOLOSESELECTION, flstr, "NOSETSEL"); 2731 debug.nospace() << "Focus(" << (focus ? "TRUE) " : "FALSE)"); 2732 debug.space() << "hwndFocus" << qDebugHWND(hwnd); 2733 debug.nospace() << "FC(" << flstr.constData() << ")"; 2734 debug.space(); 2735 break; 2736 myCaseEnd() 2737 2738 default: 2739 debug.nospace() << "WM_" << qDebugFmtHex(qmsg.msg) << ":"; 2740 debug.space() << qDebugHWND(qmsg.hwnd); 2741 debug << "mp1" << qmsg.mp1 << "mp2" << qmsg.mp2; 2742 break; 2743 } 2744 2745 return debug; 2746 2747 #undef myCaseEnd 2748 #undef myCaseBegin 2793 2749 } 2794 2750
Note:
See TracChangeset
for help on using the changeset viewer.