| 1 | /**************************************************************************** | 
|---|
| 2 | ** $Id: qregion.h 61 2006-02-06 21:43:39Z dmik $ | 
|---|
| 3 | ** | 
|---|
| 4 | ** Definition of QRegion class | 
|---|
| 5 | ** | 
|---|
| 6 | ** Created : 940514 | 
|---|
| 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 QREGION_H | 
|---|
| 39 | #define QREGION_H | 
|---|
| 40 |  | 
|---|
| 41 | #ifndef QT_H | 
|---|
| 42 | #include "qshared.h" | 
|---|
| 43 | #include "qrect.h" | 
|---|
| 44 | #endif // QT_H | 
|---|
| 45 |  | 
|---|
| 46 | #ifdef Q_WS_X11 | 
|---|
| 47 | struct QRegionPrivate; | 
|---|
| 48 | #endif | 
|---|
| 49 |  | 
|---|
| 50 | class Q_EXPORT QRegion | 
|---|
| 51 | { | 
|---|
| 52 | public: | 
|---|
| 53 | enum RegionType { Rectangle, Ellipse }; | 
|---|
| 54 |  | 
|---|
| 55 | QRegion(); | 
|---|
| 56 | QRegion( int x, int y, int w, int h, RegionType = Rectangle ); | 
|---|
| 57 | QRegion( const QRect &, RegionType = Rectangle ); | 
|---|
| 58 | QRegion( const QPointArray &, bool winding=FALSE ); | 
|---|
| 59 | QRegion( const QRegion & ); | 
|---|
| 60 | QRegion( const QBitmap & ); | 
|---|
| 61 | ~QRegion(); | 
|---|
| 62 | QRegion &operator=( const QRegion & ); | 
|---|
| 63 |  | 
|---|
| 64 | bool    isNull()   const; | 
|---|
| 65 | bool    isEmpty()  const; | 
|---|
| 66 |  | 
|---|
| 67 | bool    contains( const QPoint &p ) const; | 
|---|
| 68 | bool    contains( const QRect &r )  const; | 
|---|
| 69 |  | 
|---|
| 70 | void    translate( int dx, int dy ); | 
|---|
| 71 |  | 
|---|
| 72 | QRegion unite( const QRegion & )    const; | 
|---|
| 73 | QRegion intersect( const QRegion &) const; | 
|---|
| 74 | QRegion subtract( const QRegion & ) const; | 
|---|
| 75 | QRegion eor( const QRegion & )      const; | 
|---|
| 76 |  | 
|---|
| 77 | QRect   boundingRect() const; | 
|---|
| 78 | QMemArray<QRect> rects() const; | 
|---|
| 79 | void setRects( const QRect *, int ); | 
|---|
| 80 |  | 
|---|
| 81 | const QRegion operator|( const QRegion & ) const; | 
|---|
| 82 | const QRegion operator+( const QRegion & ) const; | 
|---|
| 83 | const QRegion operator&( const QRegion & ) const; | 
|---|
| 84 | const QRegion operator-( const QRegion & ) const; | 
|---|
| 85 | const QRegion operator^( const QRegion & ) const; | 
|---|
| 86 | QRegion& operator|=( const QRegion & ); | 
|---|
| 87 | QRegion& operator+=( const QRegion & ); | 
|---|
| 88 | QRegion& operator&=( const QRegion & ); | 
|---|
| 89 | QRegion& operator-=( const QRegion & ); | 
|---|
| 90 | QRegion& operator^=( const QRegion & ); | 
|---|
| 91 |  | 
|---|
| 92 | bool    operator==( const QRegion & )  const; | 
|---|
| 93 | bool    operator!=( const QRegion &r ) const | 
|---|
| 94 | { return !(operator==(r)); } | 
|---|
| 95 |  | 
|---|
| 96 | #if defined(Q_WS_WIN) | 
|---|
| 97 | HRGN    handle() const { return data->rgn; } | 
|---|
| 98 | #elif defined(Q_WS_PM) | 
|---|
| 99 | HRGN handle( int target_height = 0 ) const { | 
|---|
| 100 | if ( !data->rgn || data->hgt != target_height ) | 
|---|
| 101 | updateHandle( target_height ); | 
|---|
| 102 | return data->rgn; | 
|---|
| 103 | } | 
|---|
| 104 | #elif defined(Q_WS_X11) | 
|---|
| 105 | Region handle() const { if(!data->rgn) updateX11Region(); return data->rgn; } | 
|---|
| 106 | #elif defined(Q_WS_MAC) | 
|---|
| 107 | RgnHandle handle(bool require_rgn=FALSE) const; | 
|---|
| 108 | #elif defined(Q_WS_QWS) | 
|---|
| 109 | // QGfx_QWS needs this for region drawing | 
|---|
| 110 | void * handle() const { return data->rgn; } | 
|---|
| 111 | #endif | 
|---|
| 112 |  | 
|---|
| 113 | #ifndef QT_NO_DATASTREAM | 
|---|
| 114 | friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QRegion & ); | 
|---|
| 115 | friend Q_EXPORT QDataStream &operator>>( QDataStream &, QRegion & ); | 
|---|
| 116 | #endif | 
|---|
| 117 | private: | 
|---|
| 118 | QRegion( bool ); | 
|---|
| 119 | QRegion copy() const; | 
|---|
| 120 | void    detach(); | 
|---|
| 121 | #if defined(Q_WS_WIN) | 
|---|
| 122 | QRegion winCombine( const QRegion &, int ) const; | 
|---|
| 123 | #elif defined(Q_WS_PM) | 
|---|
| 124 | QRegion( HRGN hrgn, int target_height ); | 
|---|
| 125 | QRegion pmCombine( const QRegion &, int ) const; | 
|---|
| 126 | void updateHandle( int target_height ) const; | 
|---|
| 127 | #elif defined(Q_WS_X11) | 
|---|
| 128 | void updateX11Region() const; | 
|---|
| 129 | void *clipRectangles( int &num ) const; | 
|---|
| 130 | friend void *qt_getClipRects( const QRegion &, int & ); | 
|---|
| 131 | #endif | 
|---|
| 132 | void    exec( const QByteArray &, int ver = 0 ); | 
|---|
| 133 | struct QRegionData : public QShared { | 
|---|
| 134 | #if defined(Q_WS_WIN) | 
|---|
| 135 | HRGN   rgn; | 
|---|
| 136 | #elif defined(Q_WS_PM) | 
|---|
| 137 | HRGN rgn; | 
|---|
| 138 | int hgt; | 
|---|
| 139 | #elif defined(Q_WS_X11) | 
|---|
| 140 | Region rgn; | 
|---|
| 141 | void *xrectangles; | 
|---|
| 142 | QRegionPrivate *region; | 
|---|
| 143 | #elif defined(Q_WS_MAC) | 
|---|
| 144 | uint is_rect:1; | 
|---|
| 145 | QRect rect; | 
|---|
| 146 | RgnHandle rgn; | 
|---|
| 147 | #elif defined(Q_WS_QWS) | 
|---|
| 148 | void * rgn; | 
|---|
| 149 | #endif | 
|---|
| 150 | bool   is_null; | 
|---|
| 151 | } *data; | 
|---|
| 152 | #if defined(Q_WS_MAC) | 
|---|
| 153 | friend struct qt_mac_rgn_data_cache; | 
|---|
| 154 | friend QRegionData *qt_mac_get_rgn_data(); | 
|---|
| 155 | friend void qt_mac_free_rgn_data(QRegionData *); | 
|---|
| 156 | void rectifyRegion(); | 
|---|
| 157 | #elif defined(Q_WS_WIN) | 
|---|
| 158 | friend class QETWidget; | 
|---|
| 159 | #elif defined(Q_WS_PM) | 
|---|
| 160 | friend class QETWidget; | 
|---|
| 161 | friend class QPainter; | 
|---|
| 162 | #endif | 
|---|
| 163 |  | 
|---|
| 164 | }; | 
|---|
| 165 |  | 
|---|
| 166 |  | 
|---|
| 167 | #define QRGN_SETRECT            1               // region stream commands | 
|---|
| 168 | #define QRGN_SETELLIPSE         2               //  (these are internal) | 
|---|
| 169 | #define QRGN_SETPTARRAY_ALT     3 | 
|---|
| 170 | #define QRGN_SETPTARRAY_WIND    4 | 
|---|
| 171 | #define QRGN_TRANSLATE          5 | 
|---|
| 172 | #define QRGN_OR                 6 | 
|---|
| 173 | #define QRGN_AND                7 | 
|---|
| 174 | #define QRGN_SUB                8 | 
|---|
| 175 | #define QRGN_XOR                9 | 
|---|
| 176 | #define QRGN_RECTS             10 | 
|---|
| 177 |  | 
|---|
| 178 |  | 
|---|
| 179 | /***************************************************************************** | 
|---|
| 180 | QRegion stream functions | 
|---|
| 181 | *****************************************************************************/ | 
|---|
| 182 |  | 
|---|
| 183 | #ifndef QT_NO_DATASTREAM | 
|---|
| 184 | Q_EXPORT QDataStream &operator<<( QDataStream &, const QRegion & ); | 
|---|
| 185 | Q_EXPORT QDataStream &operator>>( QDataStream &, QRegion & ); | 
|---|
| 186 | #endif | 
|---|
| 187 |  | 
|---|
| 188 |  | 
|---|
| 189 | #endif // QREGION_H | 
|---|