| 1 | /**************************************************************************** | 
|---|
| 2 | ** $Id: qinternal_p.h 2 2005-11-16 15:49:26Z dmik $ | 
|---|
| 3 | ** | 
|---|
| 4 | ** Definition of some shared interal classes | 
|---|
| 5 | ** | 
|---|
| 6 | ** Created : 010427 | 
|---|
| 7 | ** | 
|---|
| 8 | ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved. | 
|---|
| 9 | ** | 
|---|
| 10 | ** This file is part of the kernel module of the Qt GUI Toolkit. | 
|---|
| 11 | ** | 
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License | 
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file | 
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file. | 
|---|
| 15 | ** | 
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the | 
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 19 | ** packaging of this file. | 
|---|
| 20 | ** | 
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License | 
|---|
| 23 | ** Agreement provided with the Software. | 
|---|
| 24 | ** | 
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 
|---|
| 27 | ** | 
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 
|---|
| 29 | **   information about Qt Commercial License Agreements. | 
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 
|---|
| 32 | ** | 
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are | 
|---|
| 34 | ** not clear to you. | 
|---|
| 35 | ** | 
|---|
| 36 | **********************************************************************/ | 
|---|
| 37 |  | 
|---|
| 38 | #ifndef QINTERNAL_P_H | 
|---|
| 39 | #define QINTERNAL_P_H | 
|---|
| 40 |  | 
|---|
| 41 | // | 
|---|
| 42 | //  W A R N I N G | 
|---|
| 43 | //  ------------- | 
|---|
| 44 | // | 
|---|
| 45 | // This file is not part of the Qt API.  It exists for the convenience | 
|---|
| 46 | // of a number of Qt sources files.  This header file may change from | 
|---|
| 47 | // version to version without notice, or even be removed. | 
|---|
| 48 | // | 
|---|
| 49 | // We mean it. | 
|---|
| 50 | // | 
|---|
| 51 | // | 
|---|
| 52 | #ifndef QT_H | 
|---|
| 53 | #include "qnamespace.h" | 
|---|
| 54 | #include "qrect.h" | 
|---|
| 55 | #include "qptrlist.h" | 
|---|
| 56 | #include "qcstring.h" | 
|---|
| 57 | #include "qiodevice.h" | 
|---|
| 58 | #endif // QT_H | 
|---|
| 59 |  | 
|---|
| 60 | class QWidget; | 
|---|
| 61 | class QPainter; | 
|---|
| 62 | class QPixmap; | 
|---|
| 63 |  | 
|---|
| 64 | class Q_EXPORT QSharedDoubleBuffer | 
|---|
| 65 | { | 
|---|
| 66 | public: | 
|---|
| 67 | enum DoubleBufferFlags { | 
|---|
| 68 | NoFlags         = 0x00, | 
|---|
| 69 | InitBG          = 0x01, | 
|---|
| 70 | Force           = 0x02, | 
|---|
| 71 | Default         = InitBG | Force | 
|---|
| 72 | }; | 
|---|
| 73 | typedef uint DBFlags; | 
|---|
| 74 |  | 
|---|
| 75 | QSharedDoubleBuffer( DBFlags f = Default ); | 
|---|
| 76 | QSharedDoubleBuffer( QWidget* widget, | 
|---|
| 77 | int x = 0, int y = 0, int w = -1, int h = -1, | 
|---|
| 78 | DBFlags f = Default ); | 
|---|
| 79 | QSharedDoubleBuffer( QPainter* painter, | 
|---|
| 80 | int x = 0, int y = 0, int w = -1, int h = -1, | 
|---|
| 81 | DBFlags f = Default ); | 
|---|
| 82 | QSharedDoubleBuffer( QWidget *widget, const QRect &r, DBFlags f = Default ); | 
|---|
| 83 | QSharedDoubleBuffer( QPainter *painter, const QRect &r, DBFlags f = Default ); | 
|---|
| 84 | ~QSharedDoubleBuffer(); | 
|---|
| 85 |  | 
|---|
| 86 | bool begin( QWidget* widget, int x = 0, int y = 0, int w = -1, int h = -1 ); | 
|---|
| 87 | bool begin( QPainter* painter, int x = 0, int y = 0, int w = -1, int h = -1); | 
|---|
| 88 | bool begin( QWidget* widget, const QRect &r ); | 
|---|
| 89 | bool begin( QPainter* painter, const QRect &r ); | 
|---|
| 90 | bool end(); | 
|---|
| 91 |  | 
|---|
| 92 | QPainter* painter() const; | 
|---|
| 93 |  | 
|---|
| 94 | bool isActive() const; | 
|---|
| 95 | bool isBuffered() const; | 
|---|
| 96 | void flush(); | 
|---|
| 97 |  | 
|---|
| 98 | static bool isDisabled() { return !dblbufr; } | 
|---|
| 99 | static void setDisabled( bool off ) { dblbufr = !off; } | 
|---|
| 100 |  | 
|---|
| 101 | static void cleanup(); | 
|---|
| 102 |  | 
|---|
| 103 | private: | 
|---|
| 104 | enum DoubleBufferState { | 
|---|
| 105 | Active          = 0x0100, | 
|---|
| 106 | BufferActive    = 0x0200, | 
|---|
| 107 | ExternalPainter = 0x0400 | 
|---|
| 108 | }; | 
|---|
| 109 | typedef uint DBState; | 
|---|
| 110 |  | 
|---|
| 111 | QPixmap *getPixmap(); | 
|---|
| 112 | void releasePixmap(); | 
|---|
| 113 |  | 
|---|
| 114 | QWidget *wid; | 
|---|
| 115 | int rx, ry, rw, rh; | 
|---|
| 116 | DBFlags flags; | 
|---|
| 117 | DBState state; | 
|---|
| 118 |  | 
|---|
| 119 | QPainter *p, *external_p; | 
|---|
| 120 | QPixmap *pix; | 
|---|
| 121 |  | 
|---|
| 122 | static bool dblbufr; | 
|---|
| 123 | }; | 
|---|
| 124 |  | 
|---|
| 125 | inline bool QSharedDoubleBuffer::begin( QWidget* widget, const QRect &r ) | 
|---|
| 126 | { return begin( widget, r.x(), r.y(), r.width(), r.height() ); } | 
|---|
| 127 |  | 
|---|
| 128 | inline bool QSharedDoubleBuffer::begin( QPainter *painter, const QRect &r ) | 
|---|
| 129 | { return begin( painter, r.x(), r.y(), r.width(), r.height() ); } | 
|---|
| 130 |  | 
|---|
| 131 | inline QPainter* QSharedDoubleBuffer::painter() const | 
|---|
| 132 | { return p; } | 
|---|
| 133 |  | 
|---|
| 134 | inline bool QSharedDoubleBuffer::isActive() const | 
|---|
| 135 | { return ( state & Active ); } | 
|---|
| 136 |  | 
|---|
| 137 | inline bool QSharedDoubleBuffer::isBuffered() const | 
|---|
| 138 | { return ( state & BufferActive ); } | 
|---|
| 139 |  | 
|---|
| 140 |  | 
|---|
| 141 | class QVirtualDestructor { | 
|---|
| 142 | public: | 
|---|
| 143 | virtual ~QVirtualDestructor() {} | 
|---|
| 144 | }; | 
|---|
| 145 |  | 
|---|
| 146 | template <class T> | 
|---|
| 147 | class QAutoDeleter : public QVirtualDestructor { | 
|---|
| 148 | public: | 
|---|
| 149 | QAutoDeleter( T* p ) : ptr( p ) {} | 
|---|
| 150 | ~QAutoDeleter() { delete ptr; } | 
|---|
| 151 | T* data() const { return ptr; } | 
|---|
| 152 | private: | 
|---|
| 153 | T* ptr; | 
|---|
| 154 | }; | 
|---|
| 155 |  | 
|---|
| 156 | template <class T> | 
|---|
| 157 | T* qAutoDeleterData( QAutoDeleter<T>* ad ) | 
|---|
| 158 | { | 
|---|
| 159 | if ( !ad ) | 
|---|
| 160 | return 0; | 
|---|
| 161 | return ad->data(); | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | template <class T> | 
|---|
| 165 | QAutoDeleter<T>* qAutoDeleter( T* p ) | 
|---|
| 166 | { | 
|---|
| 167 | return new QAutoDeleter<T>( p ); | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 | class Q_EXPORT QMembuf | 
|---|
| 171 | { | 
|---|
| 172 | public: | 
|---|
| 173 | QMembuf(); | 
|---|
| 174 | ~QMembuf(); | 
|---|
| 175 |  | 
|---|
| 176 | void append( QByteArray *ba ); | 
|---|
| 177 | void clear(); | 
|---|
| 178 |  | 
|---|
| 179 | bool consumeBytes( Q_ULONG nbytes, char *sink ); | 
|---|
| 180 | QByteArray readAll(); | 
|---|
| 181 | bool scanNewline( QByteArray *store ); | 
|---|
| 182 | bool canReadLine() const; | 
|---|
| 183 |  | 
|---|
| 184 | int ungetch( int ch ); | 
|---|
| 185 |  | 
|---|
| 186 | QIODevice::Offset size() const; | 
|---|
| 187 |  | 
|---|
| 188 | private: | 
|---|
| 189 |  | 
|---|
| 190 | QPtrList<QByteArray> *buf; | 
|---|
| 191 | QIODevice::Offset _size; | 
|---|
| 192 | QIODevice::Offset _index; | 
|---|
| 193 | }; | 
|---|
| 194 |  | 
|---|
| 195 | inline void QMembuf::append( QByteArray *ba ) | 
|---|
| 196 | { buf->append( ba ); _size += ba->size(); } | 
|---|
| 197 |  | 
|---|
| 198 | inline void QMembuf::clear() | 
|---|
| 199 | { buf->clear(); _size=0; _index=0; } | 
|---|
| 200 |  | 
|---|
| 201 | inline QByteArray QMembuf::readAll() | 
|---|
| 202 | { QByteArray ba(_size); consumeBytes(_size,ba.data()); return ba; } | 
|---|
| 203 |  | 
|---|
| 204 | inline bool QMembuf::canReadLine() const | 
|---|
| 205 | { return ((QMembuf*)this)->scanNewline( 0 ); } | 
|---|
| 206 |  | 
|---|
| 207 | inline QIODevice::Offset QMembuf::size() const | 
|---|
| 208 | { return _size; } | 
|---|
| 209 |  | 
|---|
| 210 | #endif // QINTERNAL_P_H | 
|---|