📄 qwscommand_qws_p.h
字号:
/******************************************************************************** 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.******************************************************************************/#ifndef QWSCOMMAND_QWS_P_H#define QWSCOMMAND_QWS_P_H//// W A R N I N G// -------------//// This file is not part of the Qt API. It exists purely as an// implementation detail. This header file may change from version to// version without notice, or even be removed.//// We mean it.//// When reading commands "off the wire" in the server, the rawLen is read// and then that many bytes are allocated. If the rawLen is corrupted (or// the protocol is being attacked) too many bytes can be allocated. Set// a hard limit here for security.#define MAX_COMMAND_SIZE (16 * 1024)#include <QtCore/qbytearray.h>#include <QtGui/qwsutils_qws.h>#include <QtGui/qfont.h>#include <QtCore/qdatastream.h>#include <QtCore/qvariant.h>#include <QtCore/qrect.h>#include <QtGui/qregion.h>#include <QtCore/qvector.h>#include <QtCore/qvarlengtharray.h>#include <QtGui/qwsevent_qws.h>#include "qwsprotocolitem_qws.h"QT_MODULE(Gui)#define QTE_PIPE "QtEmbedded-%1"class QRect;/********************************************************************* * * Functions to read/write commands on/from a socket * *********************************************************************/#ifndef QT_NO_QWS_MULTIPROCESSvoid qws_write_command(QIODevice *socket, int type, char *simpleData, int simpleLen, char *rawData, int rawLen);bool qws_read_command(QIODevice *socket, char *&simpleData, int &simpleLen, char *&rawData, int &rawLen, int &bytesRead);#endifstruct QWSCommand : QWSProtocolItem{ QWSCommand(int t, int len, char *ptr) : QWSProtocolItem(t,len,ptr) {} enum Type { Unknown = 0, Create, Shutdown, Region, RegionMove, RegionDestroy, SetProperty, AddProperty, RemoveProperty, GetProperty, SetSelectionOwner, ConvertSelection, RequestFocus, ChangeAltitude, SetOpacity, DefineCursor, SelectCursor, PositionCursor, GrabMouse, PlaySound, QCopRegisterChannel, QCopSend, RegionName, Identify, GrabKeyboard, RepaintRegion, IMMouse, IMUpdate, IMResponse, Embed, Font }; static QWSCommand *factory(int type);};const char *qws_getCommandTypeString( QWSCommand::Type tp );#ifndef QT_NO_DEBUGclass QDebug;QDebug &operator<<(QDebug &dbg, QWSCommand::Type tp);#endif // QT_NO_DEBUG/********************************************************************* * * Commands * *********************************************************************/struct QWSIdentifyCommand : public QWSCommand{ QWSIdentifyCommand() : QWSCommand(QWSCommand::Identify, sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) { simpleData.idLen = 0; simpleData.idLock = -1; } void setData(const char *d, int len, bool allocateMem) { QWSCommand::setData(d, len, allocateMem); if ( simpleData.idLen > MAX_COMMAND_SIZE ) { qWarning( "Identify command - name length %d - too big!", simpleData.idLen ); simpleData.idLen = MAX_COMMAND_SIZE; } if ( simpleData.idLen * int(sizeof(QChar)) > len ) { qWarning( "Identify command - name length %d - buffer size %d - buffer overrun!", simpleData.idLen, len ); } else { id = QString(reinterpret_cast<const QChar*>(d), simpleData.idLen); } } void setId(const QString& i, int lock) { id = i; simpleData.idLen = id.length(); simpleData.idLock = lock; setData(reinterpret_cast<const char*>(id.unicode()), simpleData.idLen*2, true); } struct SimpleData { int idLen; int idLock; } simpleData; QString id;};struct QWSCreateCommand : public QWSCommand{ QWSCreateCommand(int n = 1) : QWSCommand(QWSCommand::Create, sizeof(count), reinterpret_cast<char *>(&count)), count(n) {} int count;};struct QWSRegionNameCommand : public QWSCommand{ QWSRegionNameCommand() : QWSCommand(QWSCommand::RegionName, sizeof(simpleData), reinterpret_cast<char *>(&simpleData)) {} void setData(const char *d, int len, bool allocateMem) { QWSCommand::setData(d, len, allocateMem); if ( simpleData.nameLen > MAX_COMMAND_SIZE ) { qWarning( "region name command - name length too big!" ); simpleData.nameLen = MAX_COMMAND_SIZE; } if ( simpleData.captionLen > MAX_COMMAND_SIZE ) { qWarning( "region name command - caption length too big!" ); simpleData.captionLen = MAX_COMMAND_SIZE; } if ( simpleData.nameLen + simpleData.captionLen > len ) { qWarning( "region name command - name length %d - caption length %d - buffer size %d - buffer overrun!", simpleData.nameLen, simpleData.captionLen, len ); } else { name = QString(reinterpret_cast<const QChar*>(d), simpleData.nameLen/2); d += simpleData.nameLen; caption = QString(reinterpret_cast<const QChar*>(d), simpleData.captionLen/2); } } void setName(const QString& n, const QString &c) { name = n; caption = c; int l = simpleData.nameLen = name.length()*2; l += simpleData.captionLen = caption.length()*2; char *d = new char[l]; memcpy(d, name.unicode(), simpleData.nameLen); memcpy(d+simpleData.nameLen, caption.unicode(), simpleData.captionLen); setData(d, l, true); delete[] d; } struct SimpleData { int windowid; int nameLen; int captionLen; } simpleData; QString name; QString caption;};struct QWSRegionCommand : public QWSCommand{ QWSRegionCommand() : QWSCommand(QWSCommand::Region, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} void setData(const char *d, int len, bool allocateMem = true) { QWSCommand::setData(d, len, allocateMem); if( simpleData.nrectangles * int(sizeof(QRect)) + simpleData.surfacekeylength * int(sizeof(QChar)) + simpleData.surfacedatalength * int(sizeof(char)) > len ) { qWarning( "region command - rectangle count %d - surface key length %d - region data size %d - buffer size %d - buffer overrun!", simpleData.nrectangles, simpleData.surfacekeylength, simpleData.surfacedatalength, len ); } else { char *ptr = rawDataPtr; region.setRects(reinterpret_cast<QRect*>(ptr), simpleData.nrectangles); ptr += simpleData.nrectangles * sizeof(QRect); surfaceKey = QString(reinterpret_cast<QChar*>(ptr), simpleData.surfacekeylength); ptr += simpleData.surfacekeylength * sizeof(QChar); surfaceData = QByteArray(ptr, simpleData.surfacedatalength); } } void setData(int id, const QString &key, const QByteArray &data, const QRegion ®) { surfaceKey = key; surfaceData = data; region = reg; const QVector<QRect> rects = reg.rects(); simpleData.windowid = id; simpleData.surfacekeylength = key.size(); simpleData.surfacedatalength = data.size(); simpleData.nrectangles = rects.count(); QVarLengthArray<char, 256> buffer; buffer.append(reinterpret_cast<const char*>(rects.constData()), rects.count() * sizeof(QRect)); buffer.append(reinterpret_cast<const char*>(key.constData()), key.size() * sizeof(QChar)); buffer.append(data, data.size()); QWSCommand::setData(buffer.constData(), buffer.size(), true); } /* XXX this will pad out in a compiler dependent way, should move nrectangles to before windowtype, and add reserved bytes. Symptom will be valgrind reported uninitialized memory usage */ struct SimpleData { int windowid; int surfacekeylength; int surfacedatalength; int nrectangles; } simpleData; QString surfaceKey; QByteArray surfaceData; QRegion region;};struct QWSSetOpacityCommand : public QWSCommand{ QWSSetOpacityCommand() : QWSCommand(QWSCommand::SetOpacity, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} struct SimpleData { int windowid; uchar opacity; } simpleData;};struct QWSRegionMoveCommand : public QWSCommand{ QWSRegionMoveCommand() : QWSCommand(QWSCommand::RegionMove, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} struct SimpleData { int windowid; int dx; int dy; } simpleData;};struct QWSRegionDestroyCommand : public QWSCommand{ QWSRegionDestroyCommand() : QWSCommand(QWSCommand::RegionDestroy, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} struct SimpleData { int windowid; } simpleData;};struct QWSRequestFocusCommand : public QWSCommand{ QWSRequestFocusCommand() : QWSCommand(QWSCommand::RequestFocus, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} struct SimpleData { int windowid; int flag; } simpleData;};struct QWSChangeAltitudeCommand : public QWSCommand{ QWSChangeAltitudeCommand() : QWSCommand(QWSCommand::ChangeAltitude, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} enum Altitude { Lower = -1, Raise = 0, StaysOnTop = 1 }; struct SimpleData { int windowid; Altitude altitude; bool fixed; } simpleData;};struct QWSAddPropertyCommand : public QWSCommand{ QWSAddPropertyCommand() : QWSCommand(QWSCommand::AddProperty, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) {} struct SimpleData { int windowid, property; } simpleData;};struct QWSSetPropertyCommand : public QWSCommand{ QWSSetPropertyCommand() : QWSCommand(QWSCommand::SetProperty, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) { data = 0; } void setData(const char *d, int len, bool allocateMem = true) { QWSCommand::setData(d, len, allocateMem); data = rawDataPtr; } struct SimpleData { int windowid, property, mode; } simpleData; char *data;};struct QWSRepaintRegionCommand : public QWSCommand{ QWSRepaintRegionCommand() : QWSCommand(QWSCommand::RepaintRegion, sizeof(simpleData),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -