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

📄 qwidget_x11.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** 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 "qevent.h"#include "qwidget.h"#include "qdesktopwidget.h"#include "qapplication.h"#include "qapplication_p.h"#include "qnamespace.h"#include "qpainter.h"#include "qbitmap.h"#include "qlayout.h"#include "qtextcodec.h"#include "qdatetime.h"#include "qcursor.h"#include "qstack.h"#include "qcolormap.h"#include "qdebug.h"#include "private/qbackingstore_p.h"extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); //qapplication_x11.cpp#include <private/qpixmap_p.h>#include <private/qpaintengine_x11_p.h>#include "qt_x11_p.h"#include "qx11info_x11.h"#include <stdlib.h>// defined in qapplication_x11.cppbool qt_wstate_iconified(WId);void qt_updated_rootinfo();#if !defined(QT_NO_IM)#include "qinputcontext.h"#include "qinputcontextfactory.h"#endif#include "qwidget_p.h"#define XCOORD_MAX 16383#define WRECT_MAX 8191extern bool qt_nograb();static QWidget *mouseGrb    = 0;static QWidget *keyboardGrb = 0;int qt_x11_create_desktop_on_screen = -1;// MWM supportstruct QtMWMHints {    ulong flags, functions, decorations;    long input_mode;    ulong status;};enum {    MWM_HINTS_FUNCTIONS   = (1L << 0),    MWM_FUNC_ALL      = (1L << 0),    MWM_FUNC_RESIZE   = (1L << 1),    MWM_FUNC_MOVE     = (1L << 2),    MWM_FUNC_MINIMIZE = (1L << 3),    MWM_FUNC_MAXIMIZE = (1L << 4),    MWM_FUNC_CLOSE    = (1L << 5),    MWM_HINTS_DECORATIONS = (1L << 1),    MWM_DECOR_ALL      = (1L << 0),    MWM_DECOR_BORDER   = (1L << 1),    MWM_DECOR_RESIZEH  = (1L << 2),    MWM_DECOR_TITLE    = (1L << 3),    MWM_DECOR_MENU     = (1L << 4),    MWM_DECOR_MINIMIZE = (1L << 5),    MWM_DECOR_MAXIMIZE = (1L << 6),    MWM_HINTS_INPUT_MODE = (1L << 2),    MWM_INPUT_MODELESS                  = 0L,    MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L,    MWM_INPUT_FULL_APPLICATION_MODAL    = 3L};static QtMWMHints GetMWMHints(Display *display, Window window){    QtMWMHints mwmhints;    Atom type;    int format;    ulong nitems, bytesLeft;    uchar *data = 0;    if ((XGetWindowProperty(display, window, ATOM(_MOTIF_WM_HINTS), 0, 5, false,                            ATOM(_MOTIF_WM_HINTS), &type, &format, &nitems, &bytesLeft,                            &data) == Success)        && (type == ATOM(_MOTIF_WM_HINTS)            && format == 32            && nitems >= 5)) {        mwmhints = *(reinterpret_cast<QtMWMHints *>(data));    } else {        mwmhints.flags = 0L;        mwmhints.functions = MWM_FUNC_ALL;        mwmhints.decorations = MWM_DECOR_ALL;        mwmhints.input_mode = 0L;        mwmhints.status = 0L;    }    if (data)        XFree(data);    return mwmhints;}static void SetMWMHints(Display *display, Window window, const QtMWMHints &mwmhints){    if (mwmhints.flags != 0l) {        XChangeProperty(display, window, ATOM(_MOTIF_WM_HINTS), ATOM(_MOTIF_WM_HINTS), 32,                        PropModeReplace, (unsigned char *) &mwmhints, 5);    } else {        XDeleteProperty(display, window, ATOM(_MOTIF_WM_HINTS));    }}// Returns true if we should set WM_TRANSIENT_FOR on \a wstatic inline bool isTransient(const QWidget *w){    return ((w->windowType() == Qt::Dialog             || w->windowType() == Qt::Sheet             || w->windowType() == Qt::Tool             || w->windowType() == Qt::SplashScreen             || w->windowType() == Qt::ToolTip             || w->windowType() == Qt::Drawer)            // In 4.4, Qt::WA_X11BypassTransientForHint = 99            && !w->testAttribute(Qt::WidgetAttribute(99)));}static void do_size_hints(QWidget* widget, QWExtra *x);/*****************************************************************************  QWidget member functions *****************************************************************************/const uint stdWidgetEventMask =                        // X event mask        (uint)(            KeyPressMask | KeyReleaseMask |            ButtonPressMask | ButtonReleaseMask |            KeymapStateMask |            ButtonMotionMask | PointerMotionMask |            EnterWindowMask | LeaveWindowMask |            FocusChangeMask |            ExposureMask |            PropertyChangeMask |            StructureNotifyMask       );const uint stdDesktopEventMask =                        // X event mask       (uint)(           KeymapStateMask |           EnterWindowMask | LeaveWindowMask |           PropertyChangeMask      );/*  The qt_ functions below are implemented in qwidgetcreate_x11.cpp.*/Window qt_XCreateWindow(const QWidget *creator,                         Display *display, Window parent,                         int x, int y, uint w, uint h,                         int borderwidth, int depth,                         uint windowclass, Visual *visual,                         ulong valuemask, XSetWindowAttributes *attributes);Window qt_XCreateSimpleWindow(const QWidget *creator,                               Display *display, Window parent,                               int x, int y, uint w, uint h, int borderwidth,                               ulong border, ulong background);void qt_XDestroyWindow(const QWidget *destroyer,                        Display *display, Window window);static void qt_insert_sip(QWidget* scrolled_widget, int dx, int dy){    QX11Data::ScrollInProgress sip = { X11->sip_serial++, scrolled_widget, dx, dy };    X11->sip_list.append(sip);    XClientMessageEvent client_message;    client_message.type = ClientMessage;    client_message.window = scrolled_widget->internalWinId();    client_message.format = 32;    client_message.message_type = ATOM(_QT_SCROLL_DONE);    client_message.data.l[0] = sip.id;    XSendEvent(X11->display, scrolled_widget->internalWinId(), False, NoEventMask,        (XEvent*)&client_message);}static int qt_sip_count(QWidget* scrolled_widget){    int sips=0;    for (int i = 0; i < X11->sip_list.size(); ++i) {        const QX11Data::ScrollInProgress &sip = X11->sip_list.at(i);        if (sip.scrolled_widget == scrolled_widget)            sips++;    }    return sips;}static void create_wm_client_leader(){    if (X11->wm_client_leader) return;    X11->wm_client_leader =        XCreateSimpleWindow(X11->display,                             QX11Info::appRootWindow(),                             0, 0, 1, 1, 0, 0, 0);    // set client leader property to itself    XChangeProperty(X11->display,                     X11->wm_client_leader, ATOM(WM_CLIENT_LEADER),                     XA_WINDOW, 32, PropModeReplace,                     (unsigned char *)&X11->wm_client_leader, 1);#ifndef QT_NO_SESSIONMANAGER    // If we are session managed, inform the window manager about it    QByteArray session = qApp->sessionId().toLatin1();    if (!session.isEmpty()) {        XChangeProperty(X11->display,                         X11->wm_client_leader, ATOM(SM_CLIENT_ID),                         XA_STRING, 8, PropModeReplace,                         (unsigned char *)session.data(), session.size());    }#endif}Q_GUI_EXPORT void qt_x11_enforce_cursor(QWidget * w){    if (!w->testAttribute(Qt::WA_WState_Created))        return;    if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {        QCursor *oc = QApplication::overrideCursor();        if (oc) {            XDefineCursor(X11->display, w->internalWinId(), oc->handle());        } else if (w->isEnabled()) {            XDefineCursor(X11->display, w->internalWinId(), w->cursor().handle());        } else {            // enforce the windows behavior of clearing the cursor on            // disabled widgets            XDefineCursor(X11->display, w->internalWinId(), XNone);        }    } else {        XDefineCursor(X11->display, w->internalWinId(), XNone);    }}Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w){    QApplication::flush();    XEvent ev;    QTime t;    t.start();    if (!w->testAttribute(Qt::WA_WState_Created))        return;    while (!XCheckTypedWindowEvent(X11->display, w->internalWinId(), ReparentNotify, &ev)) {        if (XCheckTypedWindowEvent(X11->display, w->internalWinId(), MapNotify, &ev))            break;        if (t.elapsed() > 500)            return; // give up, no event available        qApp->syncX(); // non-busy wait    }    qApp->x11ProcessEvent(&ev);    if (XCheckTypedWindowEvent(X11->display, w->internalWinId(), ConfigureNotify, &ev))        qApp->x11ProcessEvent(&ev);}void qt_change_net_wm_state(const QWidget* w, bool set, Atom one, Atom two = 0){    if (!w->isVisible()) // not managed by the window manager        return;    XEvent e;    e.xclient.type = ClientMessage;    e.xclient.message_type = ATOM(_NET_WM_STATE);    e.xclient.display = X11->display;    e.xclient.window = w->internalWinId();    e.xclient.format = 32;    e.xclient.data.l[0] = set ? 1 : 0;    e.xclient.data.l[1] = one;    e.xclient.data.l[2] = two;    e.xclient.data.l[3] = 0;    e.xclient.data.l[4] = 0;    XSendEvent(X11->display, RootWindow(X11->display, w->x11Info().screen()),               false, (SubstructureNotifyMask | SubstructureRedirectMask), &e);}static QVector<Atom> getNetWmState(QWidget *w){    QVector<Atom> returnValue;    // Don't read anything, just get the size of the property data    Atom actualType;    int actualFormat;    ulong propertyLength;    ulong bytesLeft;    uchar *propertyData = 0;    if (XGetWindowProperty(X11->display, w->internalWinId(), ATOM(_NET_WM_STATE), 0, 0,                           False, XA_ATOM, &actualType, &actualFormat,                           &propertyLength, &bytesLeft, &propertyData) == Success        && actualType == XA_ATOM && actualFormat == 32) {        returnValue.resize(bytesLeft / 4);        XFree((char*) propertyData);        // fetch all data        if (XGetWindowProperty(X11->display, w->internalWinId(), ATOM(_NET_WM_STATE), 0,                               returnValue.size(), False, XA_ATOM, &actualType, &actualFormat,                               &propertyLength, &bytesLeft, &propertyData) != Success) {            returnValue.clear();        } else if (propertyLength != (ulong)returnValue.size()) {            returnValue.resize(propertyLength);        }

⌨️ 快捷键说明

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