void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) { Q_Q(QWidget); bool wasCreated = q->testAttribute(Qt::WA_WState_Created); if (q->isVisible() && q->parentWidget() && parent != q->parentWidget()) q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); #ifndef QT_NO_CURSOR QCursor oldcurs; bool setcurs=q->testAttribute(Qt::WA_SetCursor); if (setcurs) { oldcurs = q->cursor(); q->unsetCursor(); } #endif WId old_winid = data.winid; if ((q->windowType() == Qt::Desktop)) old_winid = 0; if (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_WState_Created)) hide_sys(); setWinId(0); if (parent != newparent) { QWidget *oldparent = q->parentWidget(); QObjectPrivate::setParent_helper(newparent); if (oldparent) { // oldparent->d_func()->setChildrenAllocatedDirty(); // oldparent->data->paintable_region_dirty = true; } if (newparent) { // newparent->d_func()->setChildrenAllocatedDirty(); // newparent->data->paintable_region_dirty = true; //@@@@@@@ } } Qt::FocusPolicy fp = q->focusPolicy(); QSize s = q->size(); //QBrush bgc = background(); // save colors bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide); data.window_flags = f; q->setAttribute(Qt::WA_WState_Created, false); q->setAttribute(Qt::WA_WState_Visible, false); q->setAttribute(Qt::WA_WState_Hidden, false); adjustFlags(data.window_flags, q); // keep compatibility with previous versions, we need to preserve the created state // (but we recreate the winId for the widget being reparented, again for compatibility) if (wasCreated || (!q->isWindow() && newparent->testAttribute(Qt::WA_WState_Created))) createWinId(); if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden) q->setAttribute(Qt::WA_WState_Hidden); q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden); if (q->isWindow()) { QRect fs = frameStrut(); data.crect = QRect(fs.left(), fs.top(), s.width(), s.height()); if ((data.window_flags & Qt::FramelessWindowHint) && extra && extra->topextra) extra->topextra->frameStrut.setCoords(0, 0, 0, 0); } else { data.crect = QRect(0, 0, s.width(), s.height()); } q->setFocusPolicy(fp); if (extra && !extra->mask.isEmpty()) { QRegion r = extra->mask; extra->mask = QRegion(); q->setMask(r); } if ((int)old_winid > 0) { QWidget::qwsDisplay()->destroyRegion(old_winid); extra->topextra->backingStore->windowSurface->setGeometry(QRect()); } #ifndef QT_NO_CURSOR if (setcurs) { q->setCursor(oldcurs); } #endif }
QWSYellowSurface::QWSYellowSurface(bool isClient) : QWSWindowSurface(), delay(10) { if (isClient) { setWinId(QWidget::qwsDisplay()->takeId()); QWidget::qwsDisplay()->nameRegion(winId(), QLatin1String("Debug flush paint"), QLatin1String("Silly yellow thing")); QWidget::qwsDisplay()->setAltitude(winId(), 1, true); } setSurfaceFlags(Buffered); }
QWSDirectPainterSurface::QWSDirectPainterSurface(bool isClient, QDirectPainter::SurfaceFlag flags) : QWSWindowSurface(), flushingRegionEvents(false), doLocking(false) { setSurfaceFlags(Opaque); synchronous = (flags == QDirectPainter::ReservedSynchronous); if (isClient) { setWinId(QWidget::qwsDisplay()->takeId()); QWidget::qwsDisplay()->nameRegion(winId(), QLatin1String("QDirectPainter reserved space"), QLatin1String("reserved")); } else { setWinId(0); } _screen = QScreen::instance(); if (!_screen->base()) { QList<QScreen*> subScreens = _screen->subScreens(); if (subScreens.size() < 1) _screen = 0; else _screen = subScreens.at(0); } }
void QWidget::destroy( bool destroyWindow, bool destroySubWindows ) { deactivateWidgetCleanup(); if ( testWState(WState_Created) ) { clearWState( WState_Created ); if ( children() ) { QObjectListIt it(*children()); register QObject *obj; while ( (obj=it.current()) ) { // destroy all widget children ++it; if ( obj->isWidgetType() ) ((QWidget*)obj)->destroy(destroySubWindows, destroySubWindows); } } releaseMouse(); if ( qt_pressGrab == this ) qt_pressGrab = 0; #ifndef QT_NO_QWS_MANAGER if (QWSManager::grabbedMouse() == this) { if ( extra && extra->topextra && extra->topextra->qwsManager ) { extra->topextra->qwsManager->releaseGrab(); } } #endif if ( keyboardGrb == this ) releaseKeyboard(); if ( testWFlags(WShowModal) ) // just be sure we leave modal qt_leave_modal( this ); else if ( testWFlags(WType_Popup) ) qApp->closePopup( this ); if ( testWFlags(WType_Desktop) ) { } else { if ( parentWidget() && parentWidget()->testWState(WState_Created) ) { hideWindow(); } if ( destroyWindow && isTopLevel() ) qwsDisplay()->destroyRegion( winId() ); } setWinId( 0 ); } }
void QWidgetPrivate::deleteTLSysExtra() { if (extra && extra->topextra) { //the toplevel might have a context with a "qglcontext associated with it. We need to //delete the qglcontext before we delete the qplatformopenglcontext. //One unfortunate thing about this is that we potentially create a glContext just to //delete it straight afterwards. if (extra->topextra->window) { extra->topextra->window->destroy(); } setWinId(0); delete extra->topextra->window; extra->topextra->window = 0; extra->topextra->backingStoreTracker.destroy(); delete extra->topextra->backingStore; extra->topextra->backingStore = 0; } }
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool /*destroyOldWindow*/) { Q_Q(QWidget); Qt::WindowType type = q->windowType(); // Make sure the WindowTitleHint is on if any of the title bar hints are set // Note: This might be moved to cross-platform QWidgetPrivate::adjustFlags() if ( !(data.window_flags & Qt::CustomizeWindowHint) && ( (data.window_flags & Qt::WindowSystemMenuHint) || (data.window_flags & Qt::WindowContextHelpButtonHint) || (data.window_flags & Qt::WindowMinimizeButtonHint) || (data.window_flags & Qt::WindowMaximizeButtonHint) || (data.window_flags & Qt::WindowCloseButtonHint) ) ) { data.window_flags |= Qt::WindowTitleHint; } // Decoration plugins on QWS don't support switching on the close button on its own if (data.window_flags & Qt::WindowCloseButtonHint) data.window_flags |= Qt::WindowSystemMenuHint; Qt::WindowFlags flags = data.window_flags; data.alloc_region_index = -1; // we don't have a "Drawer" window type if (type == Qt::Drawer) { type = Qt::Widget; flags &= ~Qt::WindowType_Mask; } bool topLevel = (flags & Qt::Window); bool popup = (type == Qt::Popup); bool dialog = (type == Qt::Dialog || type == Qt::Sheet || (flags & Qt::MSWindowsFixedSizeDialogHint)); bool desktop = (type == Qt::Desktop); bool tool = (type == Qt::Tool || type == Qt::SplashScreen || type == Qt::ToolTip); #ifndef QT_NO_WARNING_OUTPUT static bool toolWarningShown = false; if (!toolWarningShown && type == Qt::Tool && !(flags & Qt::FramelessWindowHint)) { qWarning("Qt for Embedded Linux " QT_VERSION_STR " does not support tool windows with frames.\n" "This behavior will change in a later release. To ensure compatibility with\n" "future versions, use (Qt::Tool | Qt::FramelessWindowHint)."); toolWarningShown = true; } #endif WId id; QWSDisplay* dpy = QWidget::qwsDisplay(); if (!window) // always initialize initializeWindow = true; // use the size of the primary screen to determine the default window size QList<QScreen *> screens = qt_screen->subScreens(); if (screens.isEmpty()) screens.append(qt_screen); int sw = screens[0]->width(); int sh = screens[0]->height(); if (desktop) { // desktop widget dialog = popup = false; // force these flags off data.crect.setRect(0, 0, sw, sh); } else if (topLevel && !q->testAttribute(Qt::WA_Resized)) { int width = sw / 2; int height = 4 * sh / 10; if (extra) { width = qMax(qMin(width, extra->maxw), extra->minw); height = qMax(qMin(height, extra->maxh), extra->minh); } data.crect.setSize(QSize(width, height)); } if (window) { // override the old window id = window; setWinId(window); } else if (desktop) { // desktop widget id = (WId)-2; // id = root window #if 0 QWidget *otherDesktop = q->find(id); // is there another desktop? if (otherDesktop && otherDesktop->testWFlags(Qt::WPaintDesktop)) { otherDesktop->d_func()->setWinId(0); // remove id from widget mapper setWinId(id); // make sure otherDesktop is otherDesktop->d_func()->setWinId(id); // found first } else #endif { setWinId(id); } } else { id = topLevel ? dpy->takeId() : takeLocalId(); setWinId(id); // set widget id/handle + hd } bool hasFrame = true; if (topLevel) { if (desktop || popup || tool || q->testAttribute(Qt::WA_DontShowOnScreen)) hasFrame = false; else hasFrame = !(flags & Qt::FramelessWindowHint); } if (desktop) { q->setAttribute(Qt::WA_WState_Visible); } else if (topLevel) { // set X cursor //QCursor *oc = QApplication::overrideCursor(); if (initializeWindow) { //XXX XDefineCursor(dpy, winid, oc ? oc->handle() : cursor().handle()); } QWidget::qwsDisplay()->nameRegion(q->internalWinId(), q->objectName(), q->windowTitle()); } if (topLevel) { createTLExtra(); QTLWExtra *topextra = extra->topextra; #ifndef QT_NO_QWS_MANAGER if (hasFrame) { // get size of wm decoration and make the old crect the new frect QRect cr = data.crect; QRegion r = QApplication::qwsDecoration().region(q, cr) | cr; QRect br(r.boundingRect()); topextra->frameStrut.setCoords(cr.x() - br.x(), cr.y() - br.y(), br.right() - cr.right(), br.bottom() - cr.bottom()); if (!q->testAttribute(Qt::WA_Moved) || topextra->posFromMove) data.crect.translate(topextra->frameStrut.left(), topextra->frameStrut.top()); if (!topData()->qwsManager) { topData()->qwsManager = new QWSManager(q); if((q->data->window_state & ~Qt::WindowActive) == Qt::WindowMaximized) topData()->qwsManager->maximize(); } } else if (topData()->qwsManager) { delete topData()->qwsManager; topData()->qwsManager = 0; data.crect.translate(-topextra->frameStrut.left(), -topextra->frameStrut.top()); topextra->frameStrut.setCoords(0, 0, 0, 0); } #endif if (!topextra->caption.isEmpty()) setWindowTitle_helper(topextra->caption); //XXX If we are session managed, inform the window manager about it } else { if (extra && extra->topextra) { // already allocated due to reparent? extra->topextra->frameStrut.setCoords(0, 0, 0, 0); } //updateRequestedRegion(mapToGlobal(QPoint(0,0))); } }
void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool destroyOldWindow) { Q_Q(QWidget); Qt::WindowType type = q->windowType(); Qt::WindowFlags &flags = data.window_flags; QWidget *parentWidget = q->parentWidget(); bool topLevel = (flags & Qt::Window); bool popup = (type == Qt::Popup); bool dialog = (type == Qt::Dialog || type == Qt::Sheet || (flags & Qt::MSWindowsFixedSizeDialogHint)); bool desktop = (type == Qt::Desktop); //bool tool = (type == Qt::Tool || type == Qt::Drawer); if (popup) flags |= Qt::WindowStaysOnTopHint; // a popup stays on top TRect clientRect = static_cast<CEikAppUi*>(S60->appUi())->ClientRect(); int sw = clientRect.Width(); int sh = clientRect.Height(); if (desktop) { TSize screenSize = S60->screenDevice()->SizeInPixels(); data.crect.setRect(0, 0, screenSize.iWidth, screenSize.iHeight); q->setAttribute(Qt::WA_DontShowOnScreen); } else if (topLevel && !q->testAttribute(Qt::WA_Resized)){ int width = sw; int height = sh; if (extra) { width = qMax(qMin(width, extra->maxw), extra->minw); height = qMax(qMin(height, extra->maxh), extra->minh); } data.crect.setSize(QSize(width, height)); } CCoeControl *const destroyw = destroyOldWindow ? data.winid : 0; createExtra(); if (window) { setWinId(window); TRect tr = window->Rect(); data.crect.setRect(tr.iTl.iX, tr.iTl.iY, tr.Width(), tr.Height()); } else if (topLevel) { if (!q->testAttribute(Qt::WA_Moved) && !q->testAttribute(Qt::WA_DontShowOnScreen)) data.crect.moveTopLeft(QPoint(clientRect.iTl.iX, clientRect.iTl.iY)); QScopedPointer<QSymbianControl> control( q_check_ptr(new QSymbianControl(q)) ); QT_TRAP_THROWING(control->ConstructL(true, desktop)); control->SetMopParent(static_cast<CEikAppUi*>(S60->appUi())); // Symbian windows are always created in an inactive state // We perform this assignment for the case where the window is being re-created // as a result of a call to setParent_sys, on either this widget or one of its // ancestors. extra->activated = 0; if (!desktop) { TInt stackingFlags; if ((q->windowType() & Qt::Popup) == Qt::Popup) { stackingFlags = ECoeStackFlagRefusesAllKeys | ECoeStackFlagRefusesFocus; } else { stackingFlags = ECoeStackFlagStandard; } control->MakeVisible(false); QT_TRAP_THROWING(control->ControlEnv()->AppUi()->AddToStackL(control.data(), ECoeStackPriorityDefault, stackingFlags)); // Avoid keyboard focus to a hidden window. control->setFocusSafely(false); RDrawableWindow *const drawableWindow = control->DrawableWindow(); // Request mouse move events. drawableWindow->PointerFilter(EPointerFilterEnterExit | EPointerFilterMove | EPointerFilterDrag, 0); drawableWindow->EnableVisibilityChangeEvents(); } q->setAttribute(Qt::WA_WState_Created); int x, y, w, h; data.crect.getRect(&x, &y, &w, &h); control->SetRect(TRect(TPoint(x, y), TSize(w, h))); // We wait until the control is fully constructed before calling setWinId, because // this generates a WinIdChanged event. setWinId(control.take()); if (!desktop) s60UpdateIsOpaque(); // must be called after setWinId() } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create native child widget QScopedPointer<QSymbianControl> control( q_check_ptr(new QSymbianControl(q)) ); QT_TRAP_THROWING(control->ConstructL(!parentWidget)); // Symbian windows are always created in an inactive state // We perform this assignment for the case where the window is being re-created // as a result of a call to setParent_sys, on either this widget or one of its // ancestors. extra->activated = 0; TInt stackingFlags; if ((q->windowType() & Qt::Popup) == Qt::Popup) { stackingFlags = ECoeStackFlagRefusesAllKeys | ECoeStackFlagRefusesFocus; } else { stackingFlags = ECoeStackFlagStandard; } control->MakeVisible(false); QT_TRAP_THROWING(control->ControlEnv()->AppUi()->AddToStackL(control.data(), ECoeStackPriorityDefault, stackingFlags)); // Avoid keyboard focus to a hidden window. control->setFocusSafely(false); q->setAttribute(Qt::WA_WState_Created); int x, y, w, h; data.crect.getRect(&x, &y, &w, &h); control->SetRect(TRect(TPoint(x, y), TSize(w, h))); RDrawableWindow *const drawableWindow = control->DrawableWindow(); // Request mouse move events. drawableWindow->PointerFilter(EPointerFilterEnterExit | EPointerFilterMove | EPointerFilterDrag, 0); drawableWindow->EnableVisibilityChangeEvents(); if (q->isVisible() && q->testAttribute(Qt::WA_Mapped)) { activateSymbianWindow(control.data()); control->MakeVisible(true); } // We wait until the control is fully constructed before calling setWinId, because // this generates a WinIdChanged event. setWinId(control.take()); } if (destroyw) { destroyw->ControlEnv()->AppUi()->RemoveFromStack(destroyw); // Delay deletion of the control in case this function is called in the // context of a CONE event handler such as // CCoeControl::ProcessPointerEventL QMetaObject::invokeMethod(q, "_q_delayedDestroy", Qt::QueuedConnection, Q_ARG(WId, destroyw)); } if (q->testAttribute(Qt::WA_AcceptTouchEvents)) registerTouchWindow(); }
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) { Q_Q(QWidget); Q_UNUSED(window); Q_UNUSED(initializeWindow); Q_UNUSED(destroyOldWindow); Qt::WindowFlags flags = data.window_flags; if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow()) return; // we only care about real toplevels QWindow *win = topData()->window; // topData() ensures the extra is created but does not ensure 'window' is non-null // in case the extra was already valid. if (!win) { createTLSysExtra(); win = topData()->window; } win->setFlags(data.window_flags); fixPosIncludesFrame(); if (q->testAttribute(Qt::WA_Moved)) win->setGeometry(q->geometry()); else win->resize(q->size()); win->setScreen(QGuiApplication::screens().value(topData()->screenIndex, 0)); if (q->testAttribute(Qt::WA_TranslucentBackground)) { QSurfaceFormat format; format.setAlphaBufferSize(8); win->setFormat(format); } if (QWidget *nativeParent = q->nativeParentWidget()) { if (nativeParent->windowHandle()) { if (flags & Qt::Window) { win->setTransientParent(nativeParent->windowHandle()); win->setParent(0); } else { win->setTransientParent(0); win->setParent(nativeParent->windowHandle()); } } } qt_window_private(win)->positionPolicy = topData()->posIncludesFrame ? QWindowPrivate::WindowFrameInclusive : QWindowPrivate::WindowFrameExclusive; win->create(); // Enable nonclient-area events for QDockWidget and other NonClientArea-mouse event processing. if ((flags & Qt::Desktop) == Qt::Window) win->handle()->setFrameStrutEventsEnabled(true); data.window_flags = win->flags(); QBackingStore *store = q->backingStore(); if (!store) { if (win && q->windowType() != Qt::Desktop) q->setBackingStore(new QBackingStore(win)); else q->setAttribute(Qt::WA_PaintOnScreen, true); } setWindowModified_helper(); setWinId(win->winId()); // Check children and create windows for them if necessary q_createNativeChildrenAndSetParent(q); if (extra && !extra->mask.isEmpty()) setMask_sys(extra->mask); // If widget is already shown, set window visible, too if (q->isVisible()) win->setVisible(true); }
void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) { Q_Q(QWidget); Qt::WindowFlags oldFlags = data.window_flags; bool wasCreated = q->testAttribute(Qt::WA_WState_Created); int targetScreen = -1; // Handle a request to move the widget to a particular screen if (newparent && newparent->windowType() == Qt::Desktop) { // make sure the widget is created on the same screen as the // programmer specified desktop widget // get the desktop's screen number targetScreen = newparent->window()->d_func()->topData()->screenIndex; newparent = 0; } setWinId(0); if (parent != newparent) { QObjectPrivate::setParent_helper(newparent); //### why does this have to be done in the _sys function??? if (q->windowHandle()) { q->windowHandle()->setFlags(f); QWidget *parentWithWindow = newparent ? (newparent->windowHandle() ? newparent : newparent->nativeParentWidget()) : 0; if (parentWithWindow) { if (f & Qt::Window) { q->windowHandle()->setTransientParent(parentWithWindow->windowHandle()); q->windowHandle()->setParent(0); } else { q->windowHandle()->setTransientParent(0); q->windowHandle()->setParent(parentWithWindow->windowHandle()); } } else { q->windowHandle()->setTransientParent(0); q->windowHandle()->setParent(0); } } } if (!newparent) { f |= Qt::Window; if (targetScreen == -1) { if (parent) targetScreen = q->parentWidget()->window()->d_func()->topData()->screenIndex; } } bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide); // Reparenting toplevel to child if (wasCreated && !(f & Qt::Window) && (oldFlags & Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) q->destroy(); adjustFlags(f, q); data.window_flags = f; q->setAttribute(Qt::WA_WState_Created, false); q->setAttribute(Qt::WA_WState_Visible, false); q->setAttribute(Qt::WA_WState_Hidden, false); if (newparent && wasCreated && (q->testAttribute(Qt::WA_NativeWindow) || (f & Qt::Window))) q->createWinId(); if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden) q->setAttribute(Qt::WA_WState_Hidden); q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden); // move the window to the selected screen if (!newparent && targetScreen != -1) { if (maybeTopData()) maybeTopData()->screenIndex = targetScreen; // only if it is already created if (q->testAttribute(Qt::WA_WState_Created)) { q->windowHandle()->setScreen(QGuiApplication::screens().value(targetScreen, 0)); } } }
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) { Q_Q(QWidget); static int sw = -1, sh = -1; Qt::WindowType type = q->windowType(); Qt::WindowFlags flags = data.window_flags; bool topLevel = (flags & Qt::Window); bool popup = (type == Qt::Popup); bool dialog = (type == Qt::Dialog || type == Qt::Sheet || (flags & Qt::MSWindowsFixedSizeDialogHint)); bool desktop = (type == Qt::Desktop); bool tool = (type == Qt::Tool || type == Qt::Drawer); HINSTANCE appinst = qWinAppInst(); HWND parentw, destroyw = 0; WId id; QString windowClassName = qt_reg_winclass(q); if (!window) // always initialize initializeWindow = true; if (popup) flags |= Qt::WindowStaysOnTopHint; // a popup stays on top if (flags & (Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowContextHelpButtonHint)) { flags |= Qt::WindowSystemMenuHint; flags |= Qt::WindowTitleHint; flags &= ~Qt::FramelessWindowHint; } if (sw < 0) { // get the (primary) screen size sw = GetSystemMetrics(SM_CXSCREEN); sh = GetSystemMetrics(SM_CYSCREEN); } if (desktop) { // desktop widget popup = false; // force this flags off data.crect.setRect(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); } parentw = q->parentWidget() ? q->parentWidget()->effectiveWinId() : 0; QString title; int style = WS_CHILD; int exsty = WS_EX_NOPARENTNOTIFY; if (topLevel) { if (!(flags & Qt::FramelessWindowHint) && !tool && !q->testAttribute(Qt::WA_DontShowOnScreen)) style = (WS_OVERLAPPED) | WS_SYSMENU; else style = WS_POPUP; if ((type == Qt::ToolTip) || (type == Qt::SplashScreen)) { style = WS_POPUP; exsty |= WS_EX_NOANIMATION; } else { if (flags & Qt::WindowTitleHint) style |= WS_CAPTION; if (flags & Qt::WindowSystemMenuHint) style |= WS_SYSMENU; if (flags & Qt::WindowContextHelpButtonHint) exsty |= WS_EX_CONTEXTHELP; #ifndef Q_WS_WINCE_WM if (flags & Qt::WindowMinimizeButtonHint) style |= WS_MINIMIZEBOX; if (shouldShowMaximizeButton()) style |= WS_MAXIMIZEBOX; #endif if (tool) exsty |= WS_EX_TOOLWINDOW; } } if (dialog) { style = WS_BORDER | WS_CAPTION; if (flags & Qt::WindowOkButtonHint) exsty |= WS_EX_CAPTIONOKBTN; if (flags & Qt::WindowCancelButtonHint || flags & Qt::WA_DeleteOnClose) style |= WS_SYSMENU; if (flags & Qt::WindowContextHelpButtonHint) exsty |= WS_EX_CONTEXTHELP; } if (popup) { style = WS_POPUP; exsty |= WS_EX_NOANIMATION; } if (flags & Qt::WindowTitleHint) { title = q->isWindow() ? qAppName() : q->objectName(); } // The Qt::WA_WState_Created flag is checked by translateConfigEvent() in // qapplication_win.cpp. We switch it off temporarily to avoid move // and resize events during creationt q->setAttribute(Qt::WA_WState_Created, false); if (window) { // override the old window if (destroyOldWindow) destroyw = data.winid; id = window; setWinId(window); LONG res = SetWindowLong(window, GWL_STYLE, style); if (!res) qErrnoWarning("QWidget::create: Failed to set window style"); res = SetWindowLong( window, GWL_WNDPROC, (LONG)QtWndProc ); if (!res) qErrnoWarning("QWidget::create: Failed to set window procedure"); } else if (desktop) { // desktop widget id = GetDesktopWindow(); if (!id) { //Create a dummy desktop RECT r; SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0); id = CreateWindow(reinterpret_cast<const wchar_t *>(windowClassName.utf16()), reinterpret_cast<const wchar_t *>(title.utf16()), style, r.left, r.top, r.right - r.left, r.bottom - r.top, 0, 0, appinst, 0); } setWinId(id); } else if (topLevel) { // create top-level widget const bool wasMoved = q->testAttribute(Qt::WA_Moved); int x, y; if (qt_wince_is_mobile()) { x = wasMoved ? data.crect.left() : CW_USEDEFAULT; y = wasMoved ? data.crect.top() : CW_USEDEFAULT; } else { x = wasMoved ? data.crect.left() : 100; y = wasMoved ? data.crect.top() : 100; } int w = CW_USEDEFAULT; int h = CW_USEDEFAULT; // Adjust for framestrut when needed RECT rect = {0,0,0,0}; if (AdjustWindowRectEx(&rect, style, FALSE, exsty)) { QTLWExtra *td = maybeTopData(); if (wasMoved && (td && !td->posFromMove)) { x = data.crect.x() + rect.left; y = data.crect.y() + rect.top; } if (q->testAttribute(Qt::WA_Resized)) { w = data.crect.width() + (rect.right - rect.left); h = data.crect.height() + (rect.bottom - rect.top); } } id = CreateWindowEx(exsty, reinterpret_cast<const wchar_t *>(windowClassName.utf16()), reinterpret_cast<const wchar_t *>(title.utf16()), style, x, y, w, h, 0, 0, appinst, 0); if (!id) qErrnoWarning("QWidget::create: Failed to create window"); setWinId(id); if ((flags & Qt::WindowStaysOnTopHint) || (type == Qt::ToolTip)) SetWindowPos(id, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create child widget id = CreateWindowEx(exsty, (wchar_t*)windowClassName.utf16(), (wchar_t*)title.utf16(), style, data.crect.left(), data.crect.top(), data.crect.width(), data.crect.height(), parentw, NULL, appinst, NULL); if (!id) qErrnoWarning("QWidget::create: Failed to create window"); SetWindowPos(id, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); setWinId(id); } if (desktop) { q->setAttribute(Qt::WA_WState_Visible); } else if (topLevel && !q->testAttribute(Qt::WA_DontShowOnScreen)) { RECT cr; GetClientRect(id, &cr); // one cannot trust cr.left and cr.top, use a correction POINT instead POINT pt; pt.x = 0; pt.y = 0; if (!q->testAttribute(Qt::WA_DontShowOnScreen) || q->testAttribute(Qt::WA_Moved)) ClientToScreen(id, &pt); data.crect = QRect(QPoint(pt.x, pt.y), QPoint(pt.x + cr.right - 1, pt.y + cr.bottom - 1)); if (data.fstrut_dirty) { // be nice to activeqt updateFrameStrut(); } } q->setAttribute(Qt::WA_WState_Created); // accept move/resize events hd = 0; // no display context if (window) { // got window from outside if (IsWindowVisible(window)) q->setAttribute(Qt::WA_WState_Visible); else q->setAttribute(Qt::WA_WState_Visible, false); } if (extra && !extra->mask.isEmpty()) setMask_sys(extra->mask); #if defined(QT_NON_COMMERCIAL) QT_NC_WIDGET_CREATE #endif if (q->hasFocus() && q->testAttribute(Qt::WA_InputMethodEnabled)) q->inputContext()->setFocusWidget(q); if (destroyw) { DestroyWindow(destroyw); } if (q != qt_tablet_widget && QWidgetPrivate::mapper) qt_tablet_init_wce(); if (q->testAttribute(Qt::WA_DropSiteRegistered)) registerDropSite(true); if (maybeTopData() && maybeTopData()->opacity != 255) q->setWindowOpacity(maybeTopData()->opacity/255.); if (!topLevel && q->testAttribute(Qt::WA_NativeWindow) && q->testAttribute(Qt::WA_Mapped)) { Q_ASSERT(q->internalWinId()); ShowWindow(q->internalWinId(), SW_SHOW); } }
void QWidget::reparentSys( QWidget *parent, WFlags f, const QPoint &p, bool showIt ) { QWidget* oldtlw = topLevelWidget(); #ifndef QT_NO_CURSOR QCursor oldcurs; bool setcurs=testWState(WState_OwnCursor); if ( setcurs ) { oldcurs = cursor(); unsetCursor(); } #endif WId old_winid = winid; if ( testWFlags(WType_Desktop) ) old_winid = 0; if ( !isTopLevel() && parentWidget() && parentWidget()->testWState(WState_Created) ) hideWindow(); setWinId( 0 ); if ( parentObj != parent ) { QWidget *oldparent = parentWidget(); if ( oldparent ) { // remove from parent oldparent->removeChild( this ); oldparent->setChildrenAllocatedDirty(); oldparent->paintable_region_dirty = TRUE; } if ( parent ) { // insert into new parent parent->insertChild( this ); parent->setChildrenAllocatedDirty(); parent->paintable_region_dirty = TRUE; } } bool enable = isEnabled(); // remember status FocusPolicy fp = focusPolicy(); QSize s = size(); //QPixmap *bgp = (QPixmap *)backgroundPixmap(); //QColor bgc = bg_col; // save colors #ifndef QT_NO_WIDGET_TOPEXTRA QString capt= caption(); #endif widget_flags = f; clearWState( WState_Created | WState_Visible | WState_ForceHide ); create(); if ( isTopLevel() || (!parent || parent->isVisible() ) ) setWState( WState_ForceHide ); // new widgets do not show up in already visible parents /* if ( bgp ) XSetWindowBackgroundPixmap( dpy, winid, bgp->handle() ); else XSetWindowBackground( dpy, winid, bgc.pixel() ); */ setGeometry( p.x(), p.y(), s.width(), s.height() ); setEnabled( enable ); setFocusPolicy( fp ); #ifndef QT_NO_WIDGET_TOPEXTRA if ( !capt.isNull() ) { extra->topextra->caption = QString::null; setCaption( capt ); } #endif if ( showIt ) show(); if ( (int)old_winid > 0 ) qwsDisplay()->destroyRegion( old_winid ); #ifndef QT_NO_CURSOR if ( setcurs ) { setCursor(oldcurs); } #endif reparentFocusWidgets( oldtlw ); // fix focus chains }
void QWidget::create( WId window, bool initializeWindow, bool /*destroyOldWindow*/) { if ( testWState(WState_Created) && window == 0 ) return; setWState( WState_Created ); // set created flag if ( !parentWidget() || parentWidget()->isDesktop() ) setWFlags( WType_TopLevel ); // top-level widget alloc_region_index = -1; alloc_region_revision = -1; isSettingGeometry = FALSE; overlapping_children = -1; bool topLevel = testWFlags(WType_TopLevel); bool popup = testWFlags(WType_Popup); bool dialog = testWFlags(WType_Dialog); bool desktop = testWFlags(WType_Desktop); WId id; QWSDisplay* dpy = qwsDisplay(); if ( !window ) // always initialize initializeWindow = TRUE; if ( popup ) { setWFlags(WStyle_Tool); // a popup is a tool window setWFlags(WStyle_StaysOnTop); // a popup stays on top } if ( topLevel && parentWidget() ) { // if our parent has WStyle_StaysOnTop, so must we QWidget *ptl = parentWidget()->topLevelWidget(); if ( ptl && ptl->testWFlags( WStyle_StaysOnTop ) ) setWFlags(WStyle_StaysOnTop); } int sw = dpy->width(); int sh = dpy->height(); if ( dialog || popup || desktop ) { // these are top-level, too topLevel = TRUE; setWFlags( WType_TopLevel ); } if ( desktop ) { // desktop widget dialog = popup = FALSE; // force these flags off crect.setRect( 0, 0, sw, sh ); } else if ( topLevel ) { // calc pos/size from screen crect.setRect( 0, 0, sw/2, 4*sh/10 ); } else { // child widget crect.setRect( 0, 0, 100, 30 ); } if ( window ) { // override the old window id = window; setWinId( window ); } else if ( desktop ) { // desktop widget id = (WId)-2; // id = root window QWidget *otherDesktop = find( id ); // is there another desktop? if ( otherDesktop && otherDesktop->testWFlags(WPaintDesktop) ) { otherDesktop->setWinId( 0 ); // remove id from widget mapper setWinId( id ); // make sure otherDesktop is otherDesktop->setWinId( id ); // found first } else { setWinId( id ); } } else { id = topLevel ? dpy->takeId() : takeLocalId(); setWinId( id ); // set widget id/handle + hd } if ( !topLevel ) { if ( !testWFlags(WStyle_Customize) ) setWFlags( WStyle_NormalBorder | WStyle_Title | WStyle_MinMax | WStyle_SysMenu ); } else if ( !(desktop || popup) ) { if ( testWFlags(WStyle_Customize) ) { // customize top-level widget if ( testWFlags(WStyle_NormalBorder) ) { // XXX ... } else { if ( !testWFlags(WStyle_DialogBorder) ) { // XXX ... } } if ( testWFlags(WStyle_Tool) ) { // XXX ... } } else { // normal top-level widget setWFlags( WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WStyle_MinMax ); } } alloc_region_dirty=FALSE; paintable_region_dirty=FALSE; if ( !initializeWindow ) { // do no initialization } else if ( popup ) { // popup widget } else if ( topLevel && !desktop ) { // top-level widget QWidget *p = parentWidget(); // real parent if (p) p = p->topLevelWidget(); if ( testWFlags(WStyle_DialogBorder) || testWFlags(WStyle_StaysOnTop) || testWFlags(WStyle_Dialog) || testWFlags(WStyle_Tool) ) { // XXX ... } // find the real client leader, i.e. a toplevel without parent while ( p && p->parentWidget()) { p = p->parentWidget()->topLevelWidget(); } // XXX ... } if ( initializeWindow ) { } setWState( WState_MouseTracking ); setMouseTracking( FALSE ); // also sets event mask if ( desktop ) { setWState( WState_Visible ); } else if ( topLevel ) { // set X cursor //QCursor *oc = QApplication::overrideCursor(); if ( initializeWindow ) { //XXX XDefineCursor( dpy, winid, oc ? oc->handle() : cursor().handle() ); } setWState( WState_OwnCursor ); #ifndef QT_NO_WIDGET_TOPEXTRA qwsDisplay()->nameRegion( winId(), name(""), caption() ); #else qwsDisplay()->nameRegion( winId(), name(""), QString::null ); #endif } if ( topLevel ) { #if !defined(QT_NO_WIDGET_TOPEXTRA) && !defined(QT_NO_QWS_MANAGER) createTLExtra(); #endif #ifndef QT_NO_QWS_MANAGER if ( testWFlags(WStyle_DialogBorder) || testWFlags(WStyle_NormalBorder)) { // get size of wm decoration QRegion r = QApplication::qwsDecoration().region(this, crect); QRect br( r.boundingRect() ); crect.moveBy( crect.x()-br.x(), crect.y()-br.y() ); extra->topextra->fleft = crect.x()-br.x(); extra->topextra->ftop = crect.y()-br.y(); extra->topextra->fright = br.right()-crect.right(); extra->topextra->fbottom = br.bottom()-crect.bottom(); topData()->qwsManager = new QWSManager(this); } else if ( topData()->qwsManager ) { delete topData()->qwsManager; topData()->qwsManager = 0; crect.moveBy( -extra->topextra->fleft, -extra->topextra->ftop ); extra->topextra->fleft = extra->topextra->ftop = extra->topextra->fright = extra->topextra->fbottom = 0; } #endif // declare the widget's object name as window role qt_fbdpy->addProperty(id,QT_QWS_PROPERTY_WINDOWNAME); qt_fbdpy->setProperty(id,QT_QWS_PROPERTY_WINDOWNAME,0,name()); // If we are session managed, inform the window manager about it if ( extra && !extra->mask.isNull() ) { req_region = extra->mask; req_region.translate(crect.x(),crect.y()); req_region &= crect; //??? this is optional } else { req_region = crect; } req_region = qt_screen->mapToDevice( req_region, QSize(qt_screen->width(), qt_screen->height()) ); } else { if ( extra && extra->topextra ) { // already allocated due to reparent? extra->topextra->fleft = 0; extra->topextra->ftop = 0; extra->topextra->fright = 0; extra->topextra->fbottom = 0; } //updateRequestedRegion( mapToGlobal(QPoint(0,0)) ); } }