qwsevent_qws.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QWSEVENT_QWS_H
00043 #define QWSEVENT_QWS_H
00044 
00045 #include <QtGui/qwsutils_qws.h>
00046 #include <QtGui/qwsprotocolitem_qws.h>
00047 #include <QtCore/qrect.h>
00048 #include <QtGui/qregion.h>
00049 #include <QtCore/qvector.h>
00050 
00051 QT_BEGIN_HEADER
00052 
00053 QT_BEGIN_NAMESPACE
00054 
00055 QT_MODULE(Gui)
00056 
00057 struct QWSMouseEvent;
00058 
00059 struct QWSEvent : QWSProtocolItem {
00060 
00061     QWSEvent(int t, int len, char *ptr) : QWSProtocolItem(t,len,ptr) {}
00062 
00063 
00064 
00065     enum Type {
00066         NoEvent,
00067         Connected,
00068         Mouse,
00069         Focus,
00070         Key,
00071         Region,
00072         Creation,
00073         PropertyNotify,
00074         PropertyReply,
00075         SelectionClear,
00076         SelectionRequest,
00077         SelectionNotify,
00078         MaxWindowRect,
00079         QCopMessage,
00080         WindowOperation,
00081         IMEvent,
00082         IMQuery,
00083         IMInit,
00084         Embed,
00085         Font,
00086         ScreenTransformation,
00087         NEvent
00088     };
00089 
00090     QWSMouseEvent *asMouse()
00091         { return type == Mouse ? reinterpret_cast<QWSMouseEvent*>(this) : 0; }
00092     int window() { return *(reinterpret_cast<int*>(simpleDataPtr)); }
00093     int window() const { return *(reinterpret_cast<int*>(simpleDataPtr)); }
00094     static QWSEvent *factory(int type);
00095 };
00096 
00097 
00098 //All events must start with windowID
00099 
00100 struct QWSConnectedEvent : QWSEvent {
00101     QWSConnectedEvent()
00102         : QWSEvent(QWSEvent::Connected, sizeof(simpleData),
00103                 reinterpret_cast<char*>(&simpleData)) {}
00104 
00105     void setData(const char *d, int len, bool allocateMem = true) {
00106         QWSEvent::setData(d, len, allocateMem);
00107         display = reinterpret_cast<char*>(rawDataPtr);
00108     }
00109 
00110     struct SimpleData {
00111         int window;
00112         int len;
00113         int clientId;
00114         int servershmid;
00115     } simpleData;
00116 
00117     char *display;
00118 };
00119 
00120 struct QWSMaxWindowRectEvent : QWSEvent {
00121     QWSMaxWindowRectEvent()
00122         : QWSEvent(MaxWindowRect, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) { }
00123     struct SimpleData {
00124         int window;
00125         QRect rect;
00126     } simpleData;
00127 };
00128 
00129 struct QWSMouseEvent : QWSEvent {
00130     QWSMouseEvent()
00131         : QWSEvent(QWSEvent::Mouse, sizeof(simpleData),
00132                 reinterpret_cast<char*>(&simpleData)) {}
00133     struct SimpleData {
00134         int window;
00135         int x_root, y_root, state, delta;
00136         int time; // milliseconds
00137     } simpleData;
00138 };
00139 
00140 struct QWSFocusEvent : QWSEvent {
00141     QWSFocusEvent()
00142         : QWSEvent(QWSEvent::Focus, sizeof(simpleData), reinterpret_cast<char*>(&simpleData))
00143         { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); }
00144     struct SimpleData {
00145         int window;
00146         uint get_focus:1;
00147     } simpleData;
00148 };
00149 
00150 struct QWSKeyEvent: QWSEvent {
00151     QWSKeyEvent()
00152         : QWSEvent(QWSEvent::Key, sizeof(simpleData),
00153               reinterpret_cast<char*>(&simpleData)) {}
00154     struct SimpleData {
00155         int window;
00156         uint keycode;
00157         Qt::KeyboardModifiers modifiers;
00158         ushort unicode;
00159         uint is_press:1;
00160         uint is_auto_repeat:1;
00161     } simpleData;
00162 };
00163 
00164 
00165 struct QWSCreationEvent : QWSEvent {
00166     QWSCreationEvent()
00167         : QWSEvent(QWSEvent::Creation, sizeof(simpleData),
00168               reinterpret_cast<char*>(&simpleData)) {}
00169     struct SimpleData {
00170         int objectid;
00171         int count;
00172     } simpleData;
00173 };
00174 
00175 #ifndef QT_NO_QWS_PROPERTIES
00176 struct QWSPropertyNotifyEvent : QWSEvent {
00177     QWSPropertyNotifyEvent()
00178         : QWSEvent(QWSEvent::PropertyNotify, sizeof(simpleData),
00179               reinterpret_cast<char*>(&simpleData)) {}
00180     enum State {
00181         PropertyNewValue,
00182         PropertyDeleted
00183     };
00184     struct SimpleData {
00185         int window;
00186         int property;
00187         int state;
00188     } simpleData;
00189 };
00190 #endif
00191 
00192 struct QWSSelectionClearEvent : QWSEvent {
00193     QWSSelectionClearEvent()
00194         : QWSEvent(QWSEvent::SelectionClear, sizeof(simpleData),
00195               reinterpret_cast<char*>(&simpleData)) {}
00196     struct SimpleData {
00197         int window;
00198     } simpleData;
00199 };
00200 
00201 struct QWSSelectionRequestEvent : QWSEvent {
00202     QWSSelectionRequestEvent()
00203         : QWSEvent(QWSEvent::SelectionRequest, sizeof(simpleData),
00204               reinterpret_cast<char*>(&simpleData)) {}
00205     struct SimpleData {
00206         int window;
00207         int requestor; // window which wants the selection
00208         int property; // property on requestor into which the selection should be stored, normally QWSProperty::PropSelection
00209         int mimeTypes; // Value is stored in the property mimeType on the requestor window. This value may contain
00210         // multiple mimeTypes separated by ;; where the order reflects the priority
00211     } simpleData;
00212 };
00213 
00214 struct QWSSelectionNotifyEvent : QWSEvent {
00215     QWSSelectionNotifyEvent()
00216         : QWSEvent(QWSEvent::SelectionNotify, sizeof(simpleData),
00217               reinterpret_cast<char*>(&simpleData)) {}
00218     struct SimpleData {
00219         int window;
00220         int requestor; // the window which wanted the selection and to which this event is sent
00221         int property; // property of requestor in which the data of the selection is stored
00222         int mimeType; // a property on the requestor in which the mime type in which the selection is, is stored
00223     } simpleData;
00224 };
00225 
00226 //complex events:
00227 
00228 struct QWSRegionEvent : QWSEvent {
00229     QWSRegionEvent()
00230         : QWSEvent(QWSEvent::Region, sizeof(simpleData),
00231                 reinterpret_cast<char*>(&simpleData))
00232         { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); }
00233 
00234     void setData(const char *d, int len, bool allocateMem = true) {
00235         QWSEvent::setData(d, len, allocateMem);
00236         rectangles = reinterpret_cast<QRect*>(rawDataPtr);
00237     }
00238 
00239     void setData(int winId, const QRegion &region, uint type) {
00240         const QVector<QRect> rects = region.rects();
00241         setData(reinterpret_cast<const char*>(rects.constData()),
00242             rects.size() * sizeof(QRect));
00243         simpleData.window = winId;
00244         simpleData.nrectangles = rects.size();
00245         simpleData.type = type;
00246 #ifdef QT_QWS_CLIENTBLIT
00247         simpleData.id = 0;
00248 #endif
00249     }
00250 
00251     enum Type {Allocation
00252 #ifdef QT_QWS_CLIENTBLIT
00253         , DirectPaint
00254 #endif
00255     };
00256     struct SimpleData {
00257         int window;
00258         int nrectangles;
00259 #ifdef QT_QWS_CLIENTBLIT
00260         int id;
00261 #endif
00262         uint type:8;
00263     } simpleData;
00264 
00265     QRect *rectangles;
00266 };
00267 
00268 #ifndef QT_NO_QWSEMBEDWIDGET
00269 struct QWSEmbedEvent : QWSEvent
00270 {
00271     QWSEmbedEvent() : QWSEvent(QWSEvent::Embed, sizeof(simpleData),
00272                                reinterpret_cast<char*>(&simpleData))
00273     {}
00274 
00275     enum Type { StartEmbed = 1, StopEmbed = 2, Region = 4 };
00276 
00277     void setData(const char *d, int len, bool allocateMem = true) {
00278         QWSEvent::setData(d, len, allocateMem);
00279         region.setRects(reinterpret_cast<const QRect *>(rawDataPtr),
00280                         simpleData.nrectangles);
00281     }
00282 
00283     void setData(int winId, Type type, const QRegion &reg = QRegion()) {
00284         simpleData.window = winId;
00285         simpleData.nrectangles = reg.rects().size();
00286         simpleData.type = type;
00287         region = reg;
00288         const QVector<QRect> rects = reg.rects();
00289         QWSEvent::setData(reinterpret_cast<const char*>(rects.data()),
00290                           rects.size() * sizeof(QRect));
00291     }
00292 
00293     struct SimpleData {
00294         int window;
00295         int nrectangles;
00296         Type type;
00297     } simpleData;
00298 
00299     QRegion region;
00300 };
00301 #endif // QT_NO_QWSEMBEDWIDGET
00302 
00303 #ifndef QT_NO_QWS_PROPERTIES
00304 struct QWSPropertyReplyEvent : QWSEvent {
00305     QWSPropertyReplyEvent()
00306         : QWSEvent(QWSEvent::PropertyReply, sizeof(simpleData),
00307                 reinterpret_cast<char*>(&simpleData)) {}
00308 
00309     void setData(const char *d, int len, bool allocateMem = true) {
00310         QWSEvent::setData(d, len, allocateMem);
00311         data = reinterpret_cast<char*>(rawDataPtr);
00312     }
00313 
00314     struct SimpleData {
00315         int window;
00316         int property;
00317         int len;
00318     } simpleData;
00319     char *data;
00320 };
00321 #endif //QT_NO_QWS_PROPERTIES
00322 
00323 #ifndef QT_NO_COP
00324 struct QWSQCopMessageEvent : QWSEvent {
00325     QWSQCopMessageEvent()
00326         : QWSEvent(QWSEvent::QCopMessage, sizeof(simpleData),
00327                 reinterpret_cast<char*>(&simpleData))
00328         { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); }
00329 
00330     void setData(const char *d, int len, bool allocateMem = true) {
00331         QWSEvent::setData(d, len, allocateMem);
00332         char* p = rawDataPtr;
00333     channel = QByteArray(p, simpleData.lchannel);
00334         p += simpleData.lchannel;
00335         message = QByteArray(p, simpleData.lmessage);
00336         p += simpleData.lmessage;
00337         data = QByteArray(p, simpleData.ldata);
00338     }
00339 
00340     void setDataDirect(const char *d, int len) {
00341         QWSEvent::setData(d, len, false);
00342         deleteRaw = true;
00343     }
00344 
00345     struct SimpleData {
00346         bool is_response;
00347         int lchannel;
00348         int lmessage;
00349         int ldata;
00350     } simpleData;
00351 
00352     QByteArray channel;
00353     QByteArray message;
00354     QByteArray data;
00355 };
00356 
00357 #endif
00358 
00359 struct QWSWindowOperationEvent : QWSEvent {
00360     QWSWindowOperationEvent()
00361         : QWSEvent(WindowOperation, sizeof(simpleData), reinterpret_cast<char*>(&simpleData)) { }
00362 
00363     enum Operation { Show, Hide, ShowMaximized, ShowNormal, ShowMinimized, Close };
00364     struct SimpleData {
00365         int window;
00366         Operation op;
00367     } simpleData;
00368 };
00369 
00370 #ifndef QT_NO_QWS_INPUTMETHODS
00371 
00372 
00373 struct QWSIMEvent : QWSEvent {
00374     QWSIMEvent()
00375         : QWSEvent(IMEvent, sizeof(simpleData), reinterpret_cast<char*>(&simpleData))
00376    { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); }
00377 
00378     struct SimpleData {
00379         int window;
00380         int replaceFrom;
00381         int replaceLength;
00382     } simpleData;
00383 
00384     void setData(const char *d, int len, bool allocateMem = true) {
00385         QWSEvent::setData(d, len, allocateMem);
00386         streamingData = QByteArray::fromRawData(rawDataPtr, len);
00387     }
00388     QByteArray streamingData;
00389 };
00390 
00391 
00392 struct QWSIMInitEvent : QWSEvent {
00393     QWSIMInitEvent()
00394         : QWSEvent(IMInit, sizeof(simpleData), reinterpret_cast<char*>(&simpleData))
00395    { memset(reinterpret_cast<char*>(&simpleData),0,sizeof(simpleData)); }
00396 
00397     struct SimpleData {
00398         int window;
00399         int existence;
00400     } simpleData;
00401 
00402     void setData(const char *d, int len, bool allocateMem = true) {
00403         QWSEvent::setData(d, len, allocateMem);
00404         streamingData = QByteArray::fromRawData(rawDataPtr, len);
00405     }
00406     QByteArray streamingData;
00407 };
00408 
00409 
00410 struct QWSIMQueryEvent : QWSEvent {
00411     QWSIMQueryEvent()
00412         : QWSEvent(QWSEvent::IMQuery, sizeof(simpleData),
00413               reinterpret_cast<char*>(&simpleData)) {}
00414 
00415     struct SimpleData {
00416         int window;
00417         int property;
00418     } simpleData;
00419 
00420 };
00421 
00422 #endif
00423 
00424 struct QWSFontEvent : QWSEvent {
00425     QWSFontEvent()
00426         : QWSEvent(QWSEvent::Font, sizeof(simpleData),
00427                 reinterpret_cast<char*>(&simpleData)) {}
00428 
00429     enum EventType {
00430         FontRemoved
00431     };
00432 
00433     void setData(const char *d, int len, bool allocateMem = true) {
00434         QWSEvent::setData(d, len, allocateMem);
00435         fontName = QByteArray::fromRawData(rawDataPtr, len);
00436     }
00437 
00438     struct SimpleData {
00439         uchar type;
00440     } simpleData;
00441     QByteArray fontName;
00442 };
00443 
00444 struct QWSScreenTransformationEvent : QWSEvent {
00445     QWSScreenTransformationEvent()
00446         : QWSEvent(QWSEvent::ScreenTransformation, sizeof(simpleData),
00447                    reinterpret_cast<char*>(&simpleData)) {}
00448 
00449     struct SimpleData {
00450         int screen;
00451         int transformation;
00452     } simpleData;
00453 };
00454 
00455 QT_END_NAMESPACE
00456 
00457 QT_END_HEADER
00458 
00459 #endif // QWSEVENT_QWS_H