author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 14 | c0432d11811c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qatomic.h" |
|
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" |
|
49 |
#include "qpainterpath.h" |
|
50 |
||
51 |
QT_BEGIN_NAMESPACE |
|
52 |
||
53 |
QRegion::QRegionData QRegion::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0 }; |
|
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) { |
|
59 |
HRGN region = 0; |
|
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 |
||
80 |
QRegion qt_region_from_HRGN(HRGN rgn) |
|
81 |
{ |
|
82 |
int numBytes = GetRegionData(rgn, 0, 0); |
|
83 |
if (numBytes == 0) |
|
84 |
return QRegion(); |
|
85 |
||
86 |
char *buf = new char[numBytes]; |
|
87 |
if (buf == 0) |
|
88 |
return QRegion(); |
|
89 |
||
90 |
RGNDATA *rd = reinterpret_cast<RGNDATA*>(buf); |
|
91 |
if (GetRegionData(rgn, numBytes, rd) == 0) { |
|
92 |
delete [] buf; |
|
93 |
return QRegion(); |
|
94 |
} |
|
95 |
||
96 |
QRegion region; |
|
97 |
RECT *r = reinterpret_cast<RECT*>(rd->Buffer); |
|
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); |
|
101 |
++r; |
|
102 |
region |= rect; |
|
103 |
} |
|
104 |
||
105 |
delete [] buf; |
|
106 |
||
107 |
return region; |
|
108 |
} |
|
109 |
||
110 |
void qt_win_dispose_rgn(HRGN r) |
|
111 |
{ |
|
112 |
if (r) |
|
113 |
DeleteObject(r); |
|
114 |
} |
|
115 |
||
116 |
static void qt_add_rect(HRGN &winRegion, QRect r) |
|
117 |
{ |
|
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); |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
void QRegion::ensureHandle() const |
|
131 |
{ |
|
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 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
||
149 |
QT_END_NAMESPACE |