[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
[561] | 42 | #include "qatomic.h"
|
---|
[2] | 43 | #include "qbitmap.h"
|
---|
| 44 | #include "qbuffer.h"
|
---|
| 45 | #include "qimage.h"
|
---|
| 46 | #include "qpolygon.h"
|
---|
| 47 | #include "qregion.h"
|
---|
| 48 | #include "qt_windows.h"
|
---|
[561] | 49 | #include "qpainterpath.h"
|
---|
[2] | 50 |
|
---|
| 51 | QT_BEGIN_NAMESPACE
|
---|
| 52 |
|
---|
[561] | 53 | QRegion::QRegionData QRegion::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0 };
|
---|
[2] | 54 |
|
---|
| 55 | HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int right, int bottom)
|
---|
| 56 | {
|
---|
| 57 | const int tries = 10;
|
---|
| 58 | for (int i = 0; i < tries; ++i) {
|
---|
[561] | 59 | HRGN region = 0;
|
---|
[2] | 60 | switch (type) {
|
---|
| 61 | case QRegion::Rectangle:
|
---|
| 62 | region = CreateRectRgn(left, top, right, bottom);
|
---|
| 63 | break;
|
---|
| 64 | case QRegion::Ellipse:
|
---|
| 65 | #ifndef Q_OS_WINCE
|
---|
| 66 | region = CreateEllipticRgn(left, top, right, bottom);
|
---|
| 67 | #endif
|
---|
| 68 | break;
|
---|
| 69 | }
|
---|
| 70 | if (region) {
|
---|
| 71 | if (GetRegionData(region, 0, 0))
|
---|
| 72 | return region;
|
---|
| 73 | else
|
---|
| 74 | DeleteObject(region);
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | return 0;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[561] | 80 | QRegion qt_region_from_HRGN(HRGN rgn)
|
---|
[2] | 81 | {
|
---|
[561] | 82 | int numBytes = GetRegionData(rgn, 0, 0);
|
---|
| 83 | if (numBytes == 0)
|
---|
[2] | 84 | return QRegion();
|
---|
| 85 |
|
---|
| 86 | char *buf = new char[numBytes];
|
---|
| 87 | if (buf == 0)
|
---|
[561] | 88 | return QRegion();
|
---|
[2] | 89 |
|
---|
| 90 | RGNDATA *rd = reinterpret_cast<RGNDATA*>(buf);
|
---|
[561] | 91 | if (GetRegionData(rgn, numBytes, rd) == 0) {
|
---|
[2] | 92 | delete [] buf;
|
---|
[561] | 93 | return QRegion();
|
---|
[2] | 94 | }
|
---|
| 95 |
|
---|
[561] | 96 | QRegion region;
|
---|
[2] | 97 | RECT *r = reinterpret_cast<RECT*>(rd->Buffer);
|
---|
[561] | 98 | for (uint i = 0; i < rd->rdh.nCount; ++i) {
|
---|
| 99 | QRect rect;
|
---|
| 100 | rect.setCoords(r->left, r->top, r->right - 1, r->bottom - 1);
|
---|
[2] | 101 | ++r;
|
---|
[561] | 102 | region |= rect;
|
---|
[2] | 103 | }
|
---|
| 104 |
|
---|
| 105 | delete [] buf;
|
---|
| 106 |
|
---|
[561] | 107 | return region;
|
---|
[2] | 108 | }
|
---|
| 109 |
|
---|
[561] | 110 | void qt_win_dispose_rgn(HRGN r)
|
---|
[2] | 111 | {
|
---|
[561] | 112 | if (r)
|
---|
| 113 | DeleteObject(r);
|
---|
[2] | 114 | }
|
---|
| 115 |
|
---|
[561] | 116 | static void qt_add_rect(HRGN &winRegion, QRect r)
|
---|
[2] | 117 | {
|
---|
[561] | 118 | HRGN rgn = CreateRectRgn(r.left(), r.top(), r.x() + r.width(), r.y() + r.height());
|
---|
| 119 | if (rgn) {
|
---|
| 120 | HRGN dest = CreateRectRgn(0,0,0,0);
|
---|
| 121 | int result = CombineRgn(dest, winRegion, rgn, RGN_OR);
|
---|
| 122 | if (result) {
|
---|
| 123 | DeleteObject(winRegion);
|
---|
| 124 | winRegion = dest;
|
---|
| 125 | }
|
---|
| 126 | DeleteObject(rgn);
|
---|
[2] | 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[561] | 130 | void QRegion::ensureHandle() const
|
---|
[2] | 131 | {
|
---|
[561] | 132 | if (d->rgn)
|
---|
| 133 | DeleteObject(d->rgn);
|
---|
| 134 | d->rgn = CreateRectRgn(0,0,0,0);
|
---|
| 135 | if (d->qt_rgn) {
|
---|
| 136 | if (d->qt_rgn->numRects == 1) {
|
---|
| 137 | QRect r = d->qt_rgn->extents;
|
---|
| 138 | qt_add_rect(d->rgn, r);
|
---|
| 139 | return;
|
---|
| 140 | }
|
---|
| 141 | for (int i = 0;i < d->qt_rgn->numRects;i++) {
|
---|
| 142 | QRect r = d->qt_rgn->rects.at(i);
|
---|
| 143 | qt_add_rect(d->rgn, r);
|
---|
| 144 | }
|
---|
[2] | 145 | }
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | QT_END_NAMESPACE
|
---|