Changeset 114 for trunk/src


Ignore:
Timestamp:
Aug 14, 2009, 11:20:20 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: Implemented QWidget::map[To|From]Global.

Location:
trunk/src/gui/kernel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qapplication_pm.cpp

    r112 r114  
    132132//  inline void showChildren(bool spontaneous) { d_func()->showChildren(spontaneous); }
    133133//  inline void hideChildren(bool spontaneous) { d_func()->hideChildren(spontaneous); }
     134    inline void validateObstacles() { d_func()->validateObstacles(); }
    134135//  inline uint testWindowState(uint teststate){ return dataPtr()->window_state & teststate; }
    135136//  inline void forceUpdate() {
     
    14461447    // qwidget_pm.cpp), we have to validate areas that intersect with our
    14471448    // children and siblings, taking their clip regions into account.
    1448 //    validateObstacles();
     1449    validateObstacles();
    14491450
    14501451    Q_ASSERT(testAttribute(Qt::WA_WState_Created));
     
    14731474    d_func()->hd = WinBeginPaint(internalWinId(), 0, &rcl);
    14741475
     1476#if 1
     1477    qDebug("WM_PAINT: [%s] %ld,%ld:%ld,%ld",
     1478           QWidgetPrivate::name(this).constData(),
     1479           rcl.xLeft, rcl.yBottom, rcl.xRight, rcl.yTop);
     1480#endif
     1481
    14751482    // it's possible that the update rectangle is empty
    14761483    if (rcl.xRight <= rcl.xLeft || rcl.yTop <= rcl.yBottom) {
  • trunk/src/gui/kernel/qwidget_p.h

    r112 r114  
    633633
    634634    void setModal_sys();
     635
     636#ifdef Q_WS_PM
     637    void validateObstacles();
     638
     639    static QWidget *fromHWND(HWND hwnd);
     640    static QByteArray name(QWidget *w);
     641    inline static QByteArray name(HWND hwnd) { return name(fromHWND(hwnd)); }
     642#endif
     643
    635644    QSizePolicy size_policy;
    636645    QLocale locale;
  • trunk/src/gui/kernel/qwidget_pm.cpp

    r112 r114  
    107107}
    108108
    109 // Returns a QWidget pointer or 0 if there is no widget corresponding to the
    110 // given HWND. As opposed to QWidget::find(), correctly handles WC_FRAME windows
    111 // created for top level widgets. Used for debugging.
    112 static QWidget *widgetFromId(HWND hwnd)
    113 {
    114     char buf[10];
    115     if (WinQueryClassName(hwnd, sizeof(buf), buf)) {
    116         if (!strcmp(buf, "#1")) // WC_FRAME
    117             hwnd = WinWindowFromID(hwnd, FID_CLIENT);
    118         return QWidget::find(hwnd);
    119     }
    120     return 0;
    121 }
    122 
    123 // Returns a human readable widget name in the form "class/name".
    124 // Used for debugging.
    125 static QByteArray widgetName(QWidget *w)
    126 {
    127     if (w)
    128         return QString()
    129             .sprintf("%s/%s", w->metaObject()->className(),
    130                      w->objectName().toLocal8Bit().constData()).toLocal8Bit();
    131     return QByteArray("<no-widget>");
    132 }
    133 
    134109/*!
    135110    \internal
     
    170145    qDebug("qt_WinInvalidateRegionEx: hwnd=%08lX [%s] "
    171146           "hwndFrom=%08lX hwndTo=%08lX", hwnd,
    172            widgetName(widgetFromId(hwnd)).constData(),
     147           QWidgetPrivate::name(hwnd).constData(),
    173148           hwndFrom, hwndTo);
    174149#endif
     
    200175#if defined(QT_DEBUGWIDGETMASK)
    201176        qDebug(" child=%08lX [fl=%08lX] [%s]", child, swp.fl,
    202                widgetName(widgetFromId(child)).constData());
     177               QWidgetPrivate::name(child).constData());
    203178#endif
    204179        // proceed only if not hidden
     
    286261    qDebug("qt_WinProcessWindowObstacles: hwnd=%08lX [%s], prcl=%p "
    287262           "hrgn=%08lX, op=%ld flags=%08lX", hwnd,
    288            widgetName(widgetFromId(hwnd)).constData(),
     263           QWidgetPrivate::name(hwnd).constData(),
    289264           prcl, hrgn, op, flags);
    290265#endif
     
    339314#if defined(QT_DEBUGWIDGETMASK)
    340315                qDebug(" child=%08lX [fl=%08lX] [%s]", relative, swp.fl,
    341                        widgetName(widgetFromId(relative)).constData());
     316                       QWidgetPrivate::name(relative).constData());
    342317#endif
    343318                // skip if hidden
     
    379354#if defined(QT_DEBUGWIDGETMASK)
    380355            qDebug(" sibling=%08lX [fl=%08lX] [%s]", relative, swp.fl,
    381                    widgetName(widgetFromId(relative)).constData());
     356                   QWidgetPrivate::name(relative).constData());
    382357#endif
    383358            // skip if hidden
     
    429404#if defined(QT_DEBUGWIDGETMASK)
    430405            qDebug(" parent=%08lX [fl=%08lX] [%s]", parent, swp.fl,
    431                    widgetName(widgetFromId(parent)).constData());
     406                   QWidgetPrivate::name(parent).constData());
    432407#endif
    433408            delta.x += swp.x;
     
    438413#if defined(QT_DEBUGWIDGETMASK)
    439414                qDebug(" ancestor=%08lX [fl=%08lX] [%s]", relative, swp.fl,
    440                        widgetName(widgetFromId(parent)).constData());
     415                       QWidgetPrivate::name(parent).constData());
    441416#endif
    442417                // skip if hidden
     
    489464#if defined(QT_DEBUGWIDGETMASK)
    490465    qDebug("qt_WinSetWindowPos: hwnd=%08lX [%s] fl=%08lX", hwnd,
    491            widgetName(widgetFromId(hwnd)).constData(), fl);
     466           QWidgetPrivate::name(hwnd).constData(), fl);
    492467#endif
    493468
     
    577552        qDebug(" moving up? %ld", up);
    578553        qDebug(" hwndFrom=%08lX [%s]", hwndFrom,
    579                widgetName(widgetFromId(hwndFrom)).constData());
     554               QWidgetPrivate::name(hwndFrom).constData());
    580555        qDebug(" hwndTo=%08lX [%s]", hwndTo,
    581                widgetName(widgetFromId(hwndTo)).constData());
     556               QWidgetPrivate::name(hwndTo).constData());
    582557#endif
    583558
     
    593568#if defined(QT_DEBUGWIDGETMASK)
    594569                qDebug(" sibling=%08lX [fl=%08lX] [%s]", sibling, swp.fl,
    595                        widgetName(widgetFromId(sibling)).constData());
     570                       QWidgetPrivate::name(sibling).constData());
    596571#endif
    597572                // proceed only if not hidden
     
    624599#if defined(QT_DEBUGWIDGETMASK)
    625600                qDebug(" sibling=%08lX [fl=%08lX] [%s]", sibling, swp.fl,
    626                        widgetName(widgetFromId(sibling)).constData());
     601                       QWidgetPrivate::name(sibling).constData());
    627602#endif
    628603                // proceed only if not hidden
     
    904879                   "|  style = %08lX\n"
    905880                   "|  fcFlags = %08lX",
    906                    widgetName(q).constData(), ownerw, title.constData(), fStyle,
    907                    fcFlags);
     881                   QWidgetPrivate::name(q).constData(), ownerw,
     882                   title.constData(), fStyle, fcFlags);
    908883#endif
    909884            fId = WinCreateWindow(HWND_DESKTOP, WC_FRAME, title, fStyle,
     
    932907                   "|  title = '%s'\n"
    933908                   "|  style = %08lX",
    934                    widgetName(q).constData(), fId, className.constData(),
     909                   QWidgetPrivate::name(q).constData(), fId, className.constData(),
    935910                   title.constData(), style);
    936911#endif
     
    945920                   "|  title = '%s'\n"
    946921                   "|  style = %08lX",
    947                    widgetName(q).constData(), className.constData(),
     922                   QWidgetPrivate::name(q).constData(), className.constData(),
    948923                   title.constData(), style);
    949924#endif
     
    10591034               "|  title = '%s'\n"
    10601035               "|  style = %08lX",
    1061                widgetName(q).constData(), parentw, className.constData(),
     1036               QWidgetPrivate::name(q).constData(), parentw, className.constData(),
    10621037               title.constData(), style);
    10631038#endif
     
    11331108#if defined(QT_DEBUGWINCREATEDESTROY)
    11341109            qDebug("|Destroying window [%s]:\n"
    1135                    "|  hwnd = %08lX", widgetName(this).constData(), id);
     1110                   "|  hwnd = %08lX", QWidgetPrivate::name(this).constData(), id);
    11361111#endif
    11371112
     
    11491124QPoint QWidget::mapToGlobal(const QPoint &pos) const
    11501125{
    1151     // @todo implement
    1152     return QPoint();
     1126    Q_D(const QWidget);
     1127    QWidget *parentWindow = window();
     1128    if (!isVisible() || parentWindow->isMinimized() || !testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
     1129        QPoint toGlobal = mapTo(parentWindow, pos) + parentWindow->pos();
     1130        // Adjust for window decorations
     1131        toGlobal += parentWindow->geometry().topLeft() - parentWindow->frameGeometry().topLeft();
     1132        return toGlobal;
     1133    }
     1134    QPoint pos2 = d->mapToWS(pos);
     1135    POINTL ptl;
     1136    ptl.x = pos2.x();
     1137    // flip y (local) coordinate
     1138    ptl.y = height() - (pos2.y() + 1);
     1139    WinMapWindowPoints(internalWinId(), HWND_DESKTOP, &ptl, 1);
     1140    // flip y (global) coordinate
     1141    ptl.y = QApplication::desktop()->height() - (ptl.y + 1);
     1142    return QPoint(ptl.x, ptl.y);
    11531143}
    11541144
    11551145QPoint QWidget::mapFromGlobal(const QPoint &pos) const
    11561146{
    1157     // @todo implement
    1158     return QPoint();
     1147    Q_D(const QWidget);
     1148    QWidget *parentWindow = window();
     1149    if (!isVisible() || parentWindow->isMinimized() || !testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
     1150        QPoint fromGlobal = mapFrom(parentWindow, pos - parentWindow->pos());
     1151        // Adjust for window decorations
     1152        fromGlobal -= parentWindow->geometry().topLeft() - parentWindow->frameGeometry().topLeft();
     1153        return fromGlobal;
     1154    }
     1155    POINTL ptl;
     1156    ptl.x = pos.x();
     1157    // flip y (global) coordinate
     1158    ptl.y = QApplication::desktop()->height() - (pos.y() + 1);
     1159    WinMapWindowPoints(HWND_DESKTOP, internalWinId(), &ptl, 1);
     1160    // flip y (local) coordinate
     1161    ptl.y = height() - (ptl.y + 1);
     1162    return d->mapFromWS(QPoint(ptl.x, ptl.y));
    11591163}
    11601164
     
    15131517}
    15141518
     1519/*!
     1520    \internal
     1521
     1522    Validates areas of this widget covered by (intersected with) its children
     1523    and sibling widgets.
     1524
     1525    Clip regions of all relative widgets (set by WinSetClipRegion()) are taken
     1526    into account.
     1527 */
     1528void QWidgetPrivate::validateObstacles()
     1529{
     1530    Q_ASSERT(data.winid != NULLHANDLE);
     1531
     1532    RECTL updateRcl;
     1533    if (WinQueryUpdateRect(data.winid, &updateRcl)) {
     1534        // the update rectangle may be empty
     1535        if (updateRcl.xLeft != updateRcl.xRight &&
     1536            updateRcl.yBottom != updateRcl.yTop) {
     1537            qt_WinProcessWindowObstacles(data.winid, &updateRcl, 0, 0);
     1538        }
     1539    }
     1540}
     1541
     1542/*!
     1543    Returns a QWidget pointer or 0 if there is no widget corresponding to the
     1544    given HWND. As opposed to QWidget::find(), correctly handles WC_FRAME
     1545    windows created for top level widgets. Used for debugging.
     1546 */
     1547// static
     1548QWidget *QWidgetPrivate::fromHWND(HWND hwnd)
     1549{
     1550    char buf[10];
     1551    if (WinQueryClassName(hwnd, sizeof(buf), buf)) {
     1552        if (!strcmp(buf, "#1")) // WC_FRAME
     1553            hwnd = WinWindowFromID(hwnd, FID_CLIENT);
     1554        return QWidget::find(hwnd);
     1555    }
     1556    return 0;
     1557}
     1558
     1559/*!
     1560    \internal
     1561
     1562    Returns a human readable widget name in the form "class/name". Used for
     1563    debugging.
     1564 */
     1565// static
     1566QByteArray QWidgetPrivate::name(QWidget *w)
     1567{
     1568    if (w)
     1569        return QString()
     1570            .sprintf("%s/%s", w->metaObject()->className(),
     1571                     w->objectName().toLocal8Bit().constData()).toLocal8Bit();
     1572    return QByteArray("<no-widget>");
     1573}
     1574
     1575
    15151576QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.