source: trunk/src/gui/painting/qregion_win.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 4.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
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**
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** 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**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
51QT_BEGIN_NAMESPACE
52
53QRegion::QRegionData QRegion::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0 };
54
55HRGN 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
80QRegion 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
110void qt_win_dispose_rgn(HRGN r)
111{
112 if (r)
113 DeleteObject(r);
114}
115
116static 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
130void 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
149QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.