Changeset 128 for trunk/src


Ignore:
Timestamp:
Aug 26, 2009, 9:00:24 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: Implemented QWidget::setParent_sys(). Many examples started to launch now.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qwidget_p.h

    r121 r128  
    372372#endif
    373373
    374 #if defined (Q_WS_WIN)
     374#if defined(Q_WS_WIN) || defined(Q_WS_PM)
    375375    void reparentChildren();
    376376#endif
  • trunk/src/gui/kernel/qwidget_pm.cpp

    r124 r128  
    12541254}
    12551255
     1256void QWidgetPrivate::reparentChildren()
     1257{
     1258    Q_Q(QWidget);
     1259    QObjectList chlist = q->children();
     1260    for (int i = 0; i < chlist.size(); ++i) { // reparent children
     1261        QObject *obj = chlist.at(i);
     1262        if (obj->isWidgetType()) {
     1263            QWidget *w = (QWidget *)obj;
     1264            if ((w->windowType() == Qt::Popup)) {
     1265                ;
     1266            } else if (w->isWindow()) {
     1267                bool showIt = w->isVisible();
     1268                QPoint old_pos = w->pos();
     1269                w->setParent(q, w->windowFlags());
     1270                w->move(old_pos);
     1271                if (showIt)
     1272                    w->show();
     1273            } else {
     1274                w->d_func()->invalidateBuffer(w->rect());
     1275                WinSetParent(w->effectiveWinId(), q->effectiveWinId(), FALSE);
     1276                WinSetOwner(w->effectiveWinId(), q->effectiveWinId());
     1277                w->d_func()->reparentChildren();
     1278#if 0 // @todo check if this is really necessary any longer
     1279                // bring PM coords into accordance with Qt coords,
     1280                // otherwise setGeometry() below will wrongly position
     1281                // children if this widget manages their layout.
     1282                SWP swp;
     1283                int hd = q->height() - old_height;
     1284                WinQueryWindowPos(w->effectiveWinId(), &swp);
     1285                swp.y += hd;
     1286                WinSetWindowPos(w->effectiveWinId(), 0, swp.x, swp.y, 0, 0, SWP_MOVE);
     1287#endif
     1288            }
     1289        }
     1290    }
     1291}
     1292
    12561293void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
    12571294{
    1258     // @todo implement
     1295    Q_Q(QWidget);
     1296    bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
     1297    if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
     1298        q->parentWidget()->d_func()->invalidateBuffer(q->geometry());
     1299
     1300    WId old_fid = frameWinId();
     1301
     1302    // hide and reparent our own window away. Otherwise we might get
     1303    // destroyed when emitting the child remove event below. See QWorkspace.
     1304    if (q->isVisible() && old_fid != NULLHANDLE) {
     1305        qt_WinSetWindowPos(old_fid, 0, 0, 0, 0, 0, SWP_HIDE);
     1306        WinSetParent(old_fid, HWND_OBJECT, FALSE);
     1307        WinSetOwner(old_fid, NULLHANDLE);
     1308    }
     1309    bool dropSiteWasRegistered = false;
     1310    if (q->testAttribute(Qt::WA_DropSiteRegistered)) {
     1311        dropSiteWasRegistered = true;
     1312        q->setAttribute(Qt::WA_DropSiteRegistered, false); // ole dnd unregister (we will register again below)
     1313    }
     1314
     1315    if ((q->windowType() == Qt::Desktop))
     1316        old_fid = NULLHANDLE;
     1317    setWinId(0);
     1318
     1319    QObjectPrivate::setParent_helper(parent);
     1320    bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
     1321
     1322    data.window_flags = f;
     1323    data.fstrut_dirty = true;
     1324    q->setAttribute(Qt::WA_WState_Created, false);
     1325    q->setAttribute(Qt::WA_WState_Visible, false);
     1326    q->setAttribute(Qt::WA_WState_Hidden, false);
     1327    adjustFlags(data.window_flags, q);
     1328    // keep compatibility with previous versions, we need to preserve the created state
     1329    // (but we recreate the winId for the widget being reparented, again for compatibility)
     1330    if (wasCreated || (!q->isWindow() && parent->testAttribute(Qt::WA_WState_Created)))
     1331        createWinId();
     1332    if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)
     1333        q->setAttribute(Qt::WA_WState_Hidden);
     1334    q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
     1335
     1336    if (wasCreated) {
     1337        reparentChildren();
     1338    }
     1339
     1340    if (extra && !extra->mask.isEmpty()) {
     1341        QRegion r = extra->mask;
     1342        extra->mask = QRegion();
     1343        q->setMask(r);
     1344    }
     1345    if (extra && extra->topextra && !extra->topextra->caption.isEmpty()) {
     1346        setWindowIcon_sys(true);
     1347        setWindowTitle_helper(extra->topextra->caption);
     1348    }
     1349    if (old_fid != NULLHANDLE)
     1350        qt_WinDestroyWindow(old_fid);
     1351
     1352    if (q->testAttribute(Qt::WA_AcceptDrops) || dropSiteWasRegistered
     1353        || (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)))
     1354        q->setAttribute(Qt::WA_DropSiteRegistered, true);
     1355
     1356    invalidateBuffer(q->rect());
    12591357}
    12601358
Note: See TracChangeset for help on using the changeset viewer.