⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwidget_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qcursor.h"#include "qapplication.h"#include "qapplication_p.h"#include "qpainter.h"#include "qbitmap.h"#include "qimage.h"#include "qhash.h"#include "qstack.h"#include "qlayout.h"#include "qtextcodec.h"#include "qinputcontext.h"#include "qdesktopwidget.h"#include "qwsdisplay_qws.h"#include "private/qwsdisplay_qws_p.h"#include "qscreen_qws.h"#include "qwsmanager_qws.h"#include <private/qwsmanager_p.h>#include <private/qbackingstore_p.h>#include <private/qwindowsurface_qws_p.h>#include <private/qwslock_p.h>#include "qpaintengine.h"#include "qdebug.h"#include "qwidget_p.h"extern int *qt_last_x;extern int *qt_last_y;extern WId qt_last_cursor;extern bool qws_overrideCursor;extern QWidget *qt_pressGrab;extern QWidget *qt_mouseGrb;static QWidget *keyboardGrb = 0;static int takeLocalId(){    static int n=-1000;    return --n;}class QWSServer;extern QWSServer *qwsServer;static inline bool isServerProcess(){    return (qwsServer != 0);}/*****************************************************************************  QWidget member functions *****************************************************************************/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();    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("Qtopia Core " 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    // a popup stays on top    if (popup)        flags |= Qt::WindowStaysOnTopHint;    WId           id;    QWSDisplay* dpy = QWidget::qwsDisplay();    if (!window)                                // always initialize        initializeWindow = true;    if(topLevel && parentWidget) { // if our parent stays on top, so must we        QWidget *ptl = parentWidget->window();        if(ptl && (ptl->windowFlags() & Qt::WindowStaysOnTopHint))            flags |= Qt::WindowStaysOnTopHint;    }    int sw = dpy->width();    int sh = dpy->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)) {        data.crect.setSize(QSize(sw/2, 4*sh/10));    }    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)            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 QWidget::destroy(bool destroyWindow, bool destroySubWindows){    Q_D(QWidget);    if (!isWindow() && parentWidget())        parentWidget()->d_func()->invalidateBuffer(geometry());    d->deactivateWidgetCleanup();    if (testAttribute(Qt::WA_WState_Created)) {        setAttribute(Qt::WA_WState_Created, false);        QObjectList childObjects =  children();        for (int i = 0; i < childObjects.size(); ++i) {            QObject *obj = childObjects.at(i);            if (obj->isWidgetType())                static_cast<QWidget*>(obj)->destroy(destroySubWindows,                                                     destroySubWindows);        }        releaseMouse();        if (qt_pressGrab == this)          qt_pressGrab = 0;        if (keyboardGrb == this)            releaseKeyboard();        if (testAttribute(Qt::WA_ShowModal))                // just be sure we leave modal            QApplicationPrivate::leaveModal(this);        else if ((windowType() == Qt::Popup))            qApp->d_func()->closePopup(this);        if (d->ic) {            delete d->ic;            d->ic =0;        } else {            // release previous focus information participating with            // preedit preservation of qic -- while we still have a winId            QInputContext *qic = inputContext();            if (qic)                qic->widgetDestroyed(this);        }        if ((windowType() == Qt::Desktop)) {        } else {            if (parentWidget() && parentWidget()->testAttribute(Qt::WA_WState_Created)) {                d->hide_sys();            }            if (destroyWindow && isWindow()) {                d->extra->topextra->backingStore->windowSurface->setGeometry(QRect());                qwsDisplay()->destroyRegion(internalWinId());            }        }        d->setWinId(0);    }}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(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}QPoint QWidget::mapToGlobal(const QPoint &pos) const{    int           x=pos.x(), y=pos.y();    const QWidget* w = this;    while (w) {        x += w->data->crect.x();        y += w->data->crect.y();        w = w->isWindow() ? 0 : w->parentWidget();    }    return QPoint(x, y);}QPoint QWidget::mapFromGlobal(const QPoint &pos) const{    int           x=pos.x(), y=pos.y();    const QWidget* w = this;    while (w) {        x -= w->data->crect.x();        y -= w->data->crect.y();        w = w->isWindow() ? 0 : w->parentWidget();    }    return QPoint(x, y);}#if 0 // #####void QWidget::setMicroFocusHint(int x, int y, int width, int height,                                 bool text, QFont *){    if (QRect(x, y, width, height) != microFocusHint()) {        d->createExtra();        d->extra->micro_focus_hint.setRect(x, y, width, height);    }#ifndef QT_NO_QWS_INPUTMETHODS    if (text) {        QWidget *tlw = window();        int winid = tlw->internalWinId();        QPoint p(x, y + height);        QPoint gp = mapToGlobal(p);        QRect r = QRect(mapToGlobal(QPoint(0,0)),                         size());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -