| 1 | #include"qwextend.h"
|
|---|
| 2 |
|
|---|
| 3 | #ifdef Q_WS_X11
|
|---|
| 4 |
|
|---|
| 5 | #define protected public
|
|---|
| 6 | #define private public
|
|---|
| 7 | #include<qwidget.h>
|
|---|
| 8 | #undef protected
|
|---|
| 9 | #undef private
|
|---|
| 10 |
|
|---|
| 11 | #include<qcursor.h>
|
|---|
| 12 | #include<qobjectlist.h>
|
|---|
| 13 | #include<qpixmap.h>
|
|---|
| 14 | #include<X11/Xlib.h>
|
|---|
| 15 | #include<X11/Xutil.h>
|
|---|
| 16 |
|
|---|
| 17 | // taken from qt/x11 (doing this sucks sucks sucks sucks sucks)
|
|---|
| 18 | void reparent_good(QWidget *that, WFlags f, bool showIt)
|
|---|
| 19 | {
|
|---|
| 20 | extern void qPRCreate( const QWidget *, Window );
|
|---|
| 21 | extern void qt_XDestroyWindow( const QWidget *destroyer, Display *display, Window window );
|
|---|
| 22 | extern bool qt_dnd_enable( QWidget* w, bool on );
|
|---|
| 23 |
|
|---|
| 24 | QWidget *parent = 0;
|
|---|
| 25 | Display *dpy = that->x11Display();
|
|---|
| 26 | QCursor oldcurs;
|
|---|
| 27 | bool setcurs = that->testWState(Qt::WState_OwnCursor);
|
|---|
| 28 | if ( setcurs ) {
|
|---|
| 29 | oldcurs = that->cursor();
|
|---|
| 30 | that->unsetCursor();
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | // dnd unregister (we will register again below)
|
|---|
| 34 | bool accept_drops = that->acceptDrops();
|
|---|
| 35 | that->setAcceptDrops( FALSE );
|
|---|
| 36 |
|
|---|
| 37 | // clear mouse tracking, re-enabled below
|
|---|
| 38 | bool mouse_tracking = that->hasMouseTracking();
|
|---|
| 39 | that->clearWState(Qt::WState_MouseTracking);
|
|---|
| 40 |
|
|---|
| 41 | QWidget* oldtlw = that->topLevelWidget();
|
|---|
| 42 | QWidget *oldparent = that->parentWidget();
|
|---|
| 43 | WId old_winid = that->winid;
|
|---|
| 44 | if ( that->testWFlags(Qt::WType_Desktop) )
|
|---|
| 45 | old_winid = 0;
|
|---|
| 46 | that->setWinId( 0 );
|
|---|
| 47 |
|
|---|
| 48 | // hide and reparent our own window away. Otherwise we might get
|
|---|
| 49 | // destroyed when emitting the child remove event below. See QWorkspace.
|
|---|
| 50 | XUnmapWindow( that->x11Display(), old_winid );
|
|---|
| 51 | XReparentWindow( that->x11Display(), old_winid,
|
|---|
| 52 | RootWindow( that->x11Display(), that->x11Screen() ), 0, 0 );
|
|---|
| 53 |
|
|---|
| 54 | if ( that->isTopLevel() ) {
|
|---|
| 55 | // input contexts are associated with toplevel widgets, so we need
|
|---|
| 56 | // destroy the context here. if we are reparenting back to toplevel,
|
|---|
| 57 | // then we will have another context created, otherwise we will
|
|---|
| 58 | // use our new toplevel's context
|
|---|
| 59 | that->destroyInputContext();
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | if ( that->isTopLevel() || !parent ) // we are toplevel, or reparenting to toplevel
|
|---|
| 63 | that->topData()->parentWinId = 0;
|
|---|
| 64 |
|
|---|
| 65 | if ( parent != that->parentObj ) {
|
|---|
| 66 | if ( that->parentObj ) // remove from parent
|
|---|
| 67 | that->parentObj->removeChild( that );
|
|---|
| 68 | if ( parent ) // insert into new parent
|
|---|
| 69 | parent->insertChild( that );
|
|---|
| 70 | }
|
|---|
| 71 | bool enable = that->isEnabled(); // remember status
|
|---|
| 72 | QWidget::FocusPolicy fp = that->focusPolicy();
|
|---|
| 73 | QSize s = that->size();
|
|---|
| 74 | QPixmap *bgp = (QPixmap *)that->backgroundPixmap();
|
|---|
| 75 | QColor bgc = that->bg_col; // save colors
|
|---|
| 76 | QString capt= that->caption();
|
|---|
| 77 | that->widget_flags = f;
|
|---|
| 78 | that->clearWState( Qt::WState_Created | Qt::WState_Visible | Qt::WState_ForceHide );
|
|---|
| 79 | that->create();
|
|---|
| 80 | if ( that->isTopLevel() || (!parent || parent->isVisible() ) )
|
|---|
| 81 | that->setWState( Qt::WState_ForceHide ); // new widgets do not show up in already visible parents
|
|---|
| 82 |
|
|---|
| 83 | const QObjectList *chlist = that->children();
|
|---|
| 84 | if ( chlist ) { // reparent children
|
|---|
| 85 | QObjectListIt it( *chlist );
|
|---|
| 86 | QObject *obj;
|
|---|
| 87 | while ( (obj=it.current()) ) {
|
|---|
| 88 | if ( obj->isWidgetType() ) {
|
|---|
| 89 | QWidget *w = (QWidget *)obj;
|
|---|
| 90 | if ( !w->isTopLevel() ) {
|
|---|
| 91 | XReparentWindow( that->x11Display(), w->winId(), that->winId(),
|
|---|
| 92 | w->geometry().x(), w->geometry().y() );
|
|---|
| 93 | } else if ( w->isPopup()
|
|---|
| 94 | || w->testWFlags(Qt::WStyle_DialogBorder)
|
|---|
| 95 | || w->testWFlags(Qt::WType_Dialog)
|
|---|
| 96 | || w->testWFlags(Qt::WStyle_Tool) ) {
|
|---|
| 97 | XSetTransientForHint( that->x11Display(), w->winId(), that->winId() );
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 | ++it;
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | qPRCreate( that, old_winid );
|
|---|
| 104 | if ( bgp )
|
|---|
| 105 | XSetWindowBackgroundPixmap( dpy, that->winid, bgp->handle() );
|
|---|
| 106 | else
|
|---|
| 107 | XSetWindowBackground( dpy, that->winid, bgc.pixel(that->x11Screen()) );
|
|---|
| 108 |
|
|---|
| 109 | // all this just to do a stupid resize instead of setGeometry
|
|---|
| 110 | //setGeometry( p.x(), p.y(), s.width(), s.height() );
|
|---|
| 111 | that->resize(s.width(), s.height());
|
|---|
| 112 |
|
|---|
| 113 | that->setEnabled( enable );
|
|---|
| 114 | that->setFocusPolicy( fp );
|
|---|
| 115 | if ( !capt.isNull() ) {
|
|---|
| 116 | that->extra->topextra->caption = QString::null;
|
|---|
| 117 | that->setCaption( capt );
|
|---|
| 118 | }
|
|---|
| 119 | if ( showIt )
|
|---|
| 120 | that->show();
|
|---|
| 121 | if ( old_winid )
|
|---|
| 122 | qt_XDestroyWindow( that, dpy, old_winid );
|
|---|
| 123 | if ( setcurs )
|
|---|
| 124 | that->setCursor(oldcurs);
|
|---|
| 125 |
|
|---|
| 126 | that->reparentFocusWidgets( oldtlw );
|
|---|
| 127 |
|
|---|
| 128 | // re-register dnd
|
|---|
| 129 | if (oldparent)
|
|---|
| 130 | oldparent->checkChildrenDnd();
|
|---|
| 131 |
|
|---|
| 132 | if ( accept_drops )
|
|---|
| 133 | that->setAcceptDrops( TRUE );
|
|---|
| 134 | else {
|
|---|
| 135 | that->checkChildrenDnd();
|
|---|
| 136 | that->topData()->dnd = 0;
|
|---|
| 137 | qt_dnd_enable(that, (that->extra && that->extra->children_use_dnd));
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | // re-enable mouse tracking
|
|---|
| 141 | if (mouse_tracking)
|
|---|
| 142 | that->setMouseTracking(mouse_tracking);
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | #endif
|
|---|