qwindowsystem_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 QWINDOWSYSTEM_QWS_H
00043 #define QWINDOWSYSTEM_QWS_H
00044 
00045 #include <QtCore/qbytearray.h>
00046 #include <QtCore/qmap.h>
00047 #include <QtCore/qdatetime.h>
00048 #include <QtCore/qlist.h>
00049 
00050 #include <QtGui/qwsevent_qws.h>
00051 #include <QtGui/qkbd_qws.h>
00052 #include <QtGui/qregion.h>
00053 
00054 QT_BEGIN_HEADER
00055 
00056 QT_BEGIN_NAMESPACE
00057 
00058 QT_MODULE(Gui)
00059 
00060 struct QWSWindowPrivate;
00061 class QWSCursor;
00062 class QWSClient;
00063 class QWSRegionManager;
00064 class QBrush;
00065 class QVariant;
00066 class QInputMethodEvent;
00067 class QWSInputMethod;
00068 class QWSBackingStore;
00069 class QWSWindowSurface;
00070 
00071 #ifdef QT3_SUPPORT
00072 class QImage;
00073 class QColor;
00074 #endif
00075 
00076 class QWSInternalWindowInfo
00077 {
00078 public:
00079     int winid;
00080     unsigned int clientid;
00081     QString name;   // Corresponds to QObject name of top-level widget
00082 };
00083 
00084 
00085 class Q_GUI_EXPORT QWSScreenSaver
00086 {
00087 public:
00088     virtual ~QWSScreenSaver();
00089     virtual void restore()=0;
00090     virtual bool save(int level)=0;
00091 };
00092 
00093 
00094 class Q_GUI_EXPORT QWSWindow
00095 {
00096     friend class QWSServer;
00097     friend class QWSServerPrivate;
00098 
00099 public:
00100     QWSWindow(int i, QWSClient* client);
00101     ~QWSWindow();
00102 
00103     int winId() const { return id; }
00104     const QString &name() const { return rgnName; }
00105     const QString &caption() const { return rgnCaption; }
00106     QWSClient* client() const { return c; }
00107     const QRegion &requestedRegion() const { return requested_region; }
00108     QRegion allocatedRegion() const;
00109     QRegion paintedRegion() const;
00110     bool isVisible() const { return !requested_region.isEmpty(); }
00111     bool isPartiallyObscured() const { return requested_region != allocatedRegion(); }
00112     bool isFullyObscured() const { return allocatedRegion().isEmpty(); }
00113 
00114     enum State { NoState, Hidden, Showing, Visible, Hiding, Raising, Lowering, Moving, ChangingGeometry, Destroyed };
00115     State state() const;
00116     Qt::WindowFlags windowFlags() const;
00117     QRegion dirtyOnScreen() const;
00118 
00119     void raise();
00120     void lower();
00121     void show();
00122     void hide();
00123     void setActiveWindow();
00124 
00125     bool isOpaque() const {return opaque && _opacity == 255;}
00126     uint opacity() const { return _opacity; }
00127 
00128     QWSWindowSurface* windowSurface() const { return surface; }
00129 
00130 private:
00131     bool hidden() const { return requested_region.isEmpty(); }
00132     bool forClient(const QWSClient* cl) const { return cl==c; }
00133 
00134     void setName(const QString &n);
00135     void setCaption(const QString &c);
00136 
00137     void focus(bool get);
00138     int focusPriority() const { return last_focus_time; }
00139     void operation(QWSWindowOperationEvent::Operation o);
00140     void shuttingDown() { last_focus_time=0; }
00141 
00142 #ifdef QT_QWS_CLIENTBLIT
00143     QRegion directPaintRegion() const;
00144     inline void setDirectPaintRegion(const QRegion &topmost);
00145 #endif
00146     inline void setAllocatedRegion(const QRegion &region);
00147 
00148     void createSurface(const QString &key, const QByteArray &data);
00149 
00150 #ifndef QT_NO_QWSEMBEDWIDGET
00151     void startEmbed(QWSWindow *window);
00152     void stopEmbed(QWSWindow *window);
00153 #endif
00154 
00155 private:
00156     int id;
00157     QString rgnName;
00158     QString rgnCaption;
00159     bool modified;
00160     bool onTop;
00161     QWSClient* c;
00162     QRegion requested_region;
00163     QRegion exposed;
00164     int last_focus_time;
00165     QWSWindowSurface *surface;
00166     uint _opacity;
00167     bool opaque;
00168     QWSWindowPrivate *d;
00169 #ifdef QT3_SUPPORT
00170     inline QT3_SUPPORT QRegion requested() const { return requested_region; }
00171 //    inline QT3_SUPPORT QRegion allocation() const { return allocated_region; }
00172 #endif
00173 };
00174 
00175 
00176 #ifndef QT_NO_SOUND
00177 class QWSSoundServer;
00178 #ifdef QT_USE_OLD_QWS_SOUND
00179 class QWSSoundServerData;
00180 
00181 class Q_GUI_EXPORT QWSSoundServer : public QObject {
00182     Q_OBJECT
00183 public:
00184     QWSSoundServer(QObject* parent);
00185     ~QWSSoundServer();
00186     void playFile(const QString& filename);
00187 private Q_SLOTS:
00188     void feedDevice(int fd);
00189 private:
00190     QWSSoundServerData* d;
00191 };
00192 #endif
00193 #endif
00194 
00195 
00196 /*********************************************************************
00197  *
00198  * Class: QWSServer
00199  *
00200  *********************************************************************/
00201 
00202 class QWSMouseHandler;
00203 struct QWSCommandStruct;
00204 class QWSServerPrivate;
00205 class QWSServer;
00206 
00207 extern Q_GUI_EXPORT QWSServer *qwsServer;
00208 
00209 class Q_GUI_EXPORT QWSServer : public QObject
00210 {
00211     friend class QCopChannel;
00212     friend class QWSMouseHandler;
00213     friend class QWSWindow;
00214     friend class QWSDisplay;
00215     friend class QWSInputMethod;
00216     Q_OBJECT
00217     Q_DECLARE_PRIVATE(QWSServer)
00218 public:
00219     explicit QWSServer(int flags = 0, QObject *parent=0);
00220 #ifdef QT3_SUPPORT
00221     QT3_SUPPORT_CONSTRUCTOR QWSServer(int flags, QObject *parent, const char *name);
00222 #endif
00223     ~QWSServer();
00224     enum ServerFlags { DisableKeyboard = 0x01,
00225                        DisableMouse = 0x02 };
00226 
00227     static void sendKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
00228                              bool isPress, bool autoRepeat);
00229 #ifndef QT_NO_QWS_KEYBOARD
00230     static void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
00231                                 bool isPress, bool autoRepeat);
00232 #endif
00233 
00234     static QWSServer* instance() { return qwsServer; }
00235 
00236 #ifndef QT_NO_QWS_INPUTMETHODS
00237 #ifdef QT3_SUPPORT
00238     enum IMState { IMCompose, IMEnd, IMStart = IMCompose };
00239 #endif
00240     enum IMMouse { MousePress, MouseRelease, MouseMove, MouseOutside }; //MouseMove reserved but not used
00241     void sendIMEvent(const QInputMethodEvent*);
00242     void sendIMQuery(int property);
00243 #endif
00244 
00245 #ifndef QT_NO_QWS_KEYBOARD
00246     class KeyboardFilter
00247     {
00248     public:
00249         virtual ~KeyboardFilter() {}
00250         virtual bool filter(int unicode, int keycode, int modifiers,
00251                             bool isPress, bool autoRepeat)=0;
00252     };
00253     static void addKeyboardFilter(KeyboardFilter *f);
00254     static void removeKeyboardFilter();
00255 #endif
00256 
00257 #ifndef QT_NO_QWS_INPUTMETHODS
00258     static void setCurrentInputMethod(QWSInputMethod *im);
00259     static void resetInputMethod();
00260 #endif
00261 
00262     static void setDefaultMouse(const char *);
00263     static void setDefaultKeyboard(const char *);
00264     static void setMaxWindowRect(const QRect&);
00265     static void sendMouseEvent(const QPoint& pos, int state, int wheel = 0);
00266 
00267     static void setBackground(const QBrush &);
00268 #ifdef QT3_SUPPORT
00269     static QT3_SUPPORT void setDesktopBackground(const QImage &img);
00270     static QT3_SUPPORT void setDesktopBackground(const QColor &);
00271 #endif
00272     static QWSMouseHandler *mouseHandler();
00273     static const QList<QWSMouseHandler*>& mouseHandlers();
00274     static void setMouseHandler(QWSMouseHandler*);
00275 #ifndef QT_NO_QWS_KEYBOARD
00276     static QWSKeyboardHandler* keyboardHandler();
00277     static void setKeyboardHandler(QWSKeyboardHandler* kh);
00278 #endif
00279     QWSWindow *windowAt(const QPoint& pos);
00280 
00281     const QList<QWSWindow*> &clientWindows();
00282 
00283     void openMouse();
00284     void closeMouse();
00285     void suspendMouse();
00286     void resumeMouse();
00287 #ifndef QT_NO_QWS_KEYBOARD
00288     void openKeyboard();
00289     void closeKeyboard();
00290 #endif
00291 
00292     static void setScreenSaver(QWSScreenSaver*);
00293     static void setScreenSaverIntervals(int* ms);
00294     static void setScreenSaverInterval(int);
00295     static void setScreenSaverBlockLevel(int);
00296     static bool screenSaverActive();
00297     static void screenSaverActivate(bool);
00298 
00299     // the following are internal.
00300     void refresh();
00301     void refresh(QRegion &);
00302 
00303     void enablePainting(bool);
00304     static void processEventQueue();
00305     static QList<QWSInternalWindowInfo*> * windowList();
00306 
00307     void sendPropertyNotifyEvent(int property, int state);
00308 
00309     static QPoint mousePosition;
00310 
00311     static void startup(int flags);
00312     static void closedown();
00313 
00314     static void beginDisplayReconfigure();
00315     static void endDisplayReconfigure();
00316 
00317 #ifndef QT_NO_QWS_CURSOR
00318     static void setCursorVisible(bool);
00319     static bool isCursorVisible();
00320 #endif
00321 
00322     const QBrush &backgroundBrush() const;
00323 
00324     enum WindowEvent { Create=0x0001, Destroy=0x0002, Hide=0x0004, Show=0x0008,
00325                        Raise=0x0010, Lower=0x0020, Geometry=0x0040, Active = 0x0080,
00326                        Name=0x0100 };
00327 
00328 Q_SIGNALS:
00329     void windowEvent(QWSWindow *w, QWSServer::WindowEvent e);
00330 
00331 #ifndef QT_NO_COP
00332     void newChannel(const QString& channel);
00333     void removedChannel(const QString& channel);
00334 
00335 #endif
00336 #ifndef QT_NO_QWS_INPUTMETHODS
00337     void markedText(const QString &);
00338 #endif
00339 
00340 protected:
00341     void timerEvent(QTimerEvent *e);
00342 
00343 private:
00344     friend class QApplicationPrivate;
00345     void updateWindowRegions() const;
00346 
00347 #ifdef QT3_SUPPORT
00348 #ifndef QT_NO_QWS_KEYBOARD
00349     static inline QT3_SUPPORT void setKeyboardFilter(QWSServer::KeyboardFilter *f)
00350         { if (f) addKeyboardFilter(f); else removeKeyboardFilter(); }
00351 #endif
00352 #endif
00353 
00354 private:
00355 #ifndef QT_NO_QWS_MULTIPROCESS
00356     Q_PRIVATE_SLOT(d_func(), void _q_clientClosed())
00357     Q_PRIVATE_SLOT(d_func(), void _q_doClient())
00358     Q_PRIVATE_SLOT(d_func(), void _q_deleteWindowsLater())
00359 #endif
00360 
00361     Q_PRIVATE_SLOT(d_func(), void _q_screenSaverWake())
00362     Q_PRIVATE_SLOT(d_func(), void _q_screenSaverSleep())
00363     Q_PRIVATE_SLOT(d_func(), void _q_screenSaverTimeout())
00364 
00365 #ifndef QT_NO_QWS_MULTIPROCESS
00366     Q_PRIVATE_SLOT(d_func(), void _q_newConnection())
00367 #endif
00368 };
00369 
00370 #ifndef QT_NO_QWS_INPUTMETHODS
00371 class Q_GUI_EXPORT QWSInputMethod : public QObject
00372 {
00373     Q_OBJECT
00374 public:
00375     QWSInputMethod();
00376     virtual ~QWSInputMethod();
00377 
00378     enum UpdateType {Update, FocusIn, FocusOut, Reset, Destroyed};
00379 
00380     virtual bool filter(int unicode, int keycode, int modifiers,
00381                         bool isPress, bool autoRepeat);
00382 
00383     virtual bool filter(const QPoint &, int state, int wheel);
00384 
00385     virtual void reset();
00386     virtual void updateHandler(int type);
00387     virtual void mouseHandler(int pos, int state);
00388     virtual void queryResponse(int property, const QVariant&);
00389 
00390 protected:
00391     uint setInputResolution(bool isHigh);
00392     uint inputResolutionShift() const;
00393     // needed for required transform
00394     void sendMouseEvent(const QPoint &pos, int state, int wheel);
00395 
00396     void sendEvent(const QInputMethodEvent*);
00397     void sendPreeditString(const QString &preeditString, int cursorPosition, int selectionLength = 0);
00398     void sendCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0);
00399     void sendQuery(int property);
00400 
00401 #ifdef QT3_SUPPORT
00402     inline void sendIMEvent(QWSServer::IMState, const QString& txt, int cpos, int selLen = 0);
00403 #endif
00404 private:
00405     bool mIResolution;
00406 };
00407 
00408 inline void QWSInputMethod::sendEvent(const QInputMethodEvent *ime)
00409 {
00410     qwsServer->sendIMEvent(ime);
00411 }
00412 #ifdef QT3_SUPPORT
00413 inline void QWSInputMethod::sendIMEvent(QWSServer::IMState state, const QString& txt, int cpos, int selLen)
00414 {
00415     if (state == QWSServer::IMCompose) sendPreeditString(txt, cpos, selLen); else sendCommitString(txt);
00416 }
00417 #endif
00418 
00419 inline void QWSInputMethod::sendQuery(int property)
00420 {
00421     qwsServer->sendIMQuery(property);
00422 }
00423 
00424 // mouse events not inline as involve transformations.
00425 #endif // QT_NO_QWS_INPUTMETHODS
00426 
00427 
00428 
00429 /*********************************************************************
00430  *
00431  * Class: QWSClient
00432  *
00433  *********************************************************************/
00434 
00435 struct QWSMouseEvent;
00436 
00437 typedef QMap<int, QWSCursor*> QWSCursorMap;
00438 
00439 class QWSClientPrivate;
00440 class QWSCommand;
00441 class QWSConvertSelectionCommand;
00442 
00443 class Q_GUI_EXPORT QWSClient : public QObject
00444 {
00445     Q_OBJECT
00446     Q_DECLARE_PRIVATE(QWSClient)
00447 public:
00448     QWSClient(QObject* parent, QWS_SOCK_BASE *, int id);
00449     ~QWSClient();
00450 
00451     int socket() const;
00452 
00453     void setIdentity(const QString&);
00454     QString identity() const { return id; }
00455 
00456     void sendEvent(QWSEvent* event);
00457     void sendConnectedEvent(const char *display_spec);
00458     void sendMaxWindowRectEvent(const QRect &rect);
00459     void sendPropertyNotifyEvent(int property, int state);
00460     void sendPropertyReplyEvent(int property, int len, const char *data);
00461     void sendSelectionClearEvent(int windowid);
00462     void sendSelectionRequestEvent(QWSConvertSelectionCommand *cmd, int windowid);
00463 #ifndef QT_QWS_CLIENTBLIT
00464     void sendRegionEvent(int winid, QRegion rgn, int type);
00465 #else
00466     void sendRegionEvent(int winid, QRegion rgn, int type, int id = 0);
00467 #endif
00468 #ifndef QT_NO_QWSEMBEDWIDGET
00469     void sendEmbedEvent(int winid, QWSEmbedEvent::Type type,
00470                         const QRegion &region = QRegion());
00471 #endif
00472     QWSCommand* readMoreCommand();
00473 
00474     int clientId() const { return cid; }
00475 
00476     QWSCursorMap cursors; // cursors defined by this client
00477 Q_SIGNALS:
00478     void connectionClosed();
00479     void readyRead();
00480 private Q_SLOTS:
00481     void closeHandler();
00482     void errorHandler();
00483 
00484 private:
00485 #ifndef QT_NO_QWS_MULTIPROCESS
00486     friend class QWSWindow;
00487     void removeUnbufferedSurface();
00488     void addUnbufferedSurface();
00489 #endif
00490 
00491 private:
00492     int socketDescriptor;
00493 #ifndef QT_NO_QWS_MULTIPROCESS
00494     QWSSocket *csocket;
00495 #endif
00496     QWSCommand* command;
00497     uint isClosed : 1;
00498     QString id;
00499     int cid;
00500 
00501     friend class QWSServerPrivate;
00502 };
00503 
00504 QT_END_NAMESPACE
00505 
00506 QT_END_HEADER
00507 
00508 #endif // QWINDOWSYSTEM_QWS_H