OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
region.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TRegion, a GDI Region object encapsulation
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/gdiobjec.h>
10
11#if defined(__BORLANDC__)
12# pragma option -w-ccc // Disable "Condition is always true/false"
13#endif
14
15using namespace std;
16
17namespace owl {
18
20DIAG_DECLARE_GROUP(OwlGDI); // General GDI diagnostic group
21
22//
23/// The default constructor creates an empty TRegion object.
24/// ShouldDelete is set to true.
25//
27{
28 Handle = ::CreateRectRgn(0, 0, 0, 0);
29 WARNX(OwlGDI, !Handle, 0, "Cannot create empty rect region");
30 CheckValid();
31}
32
33//
34/// Creates a TRegion object and sets the Handle data member to the given borrowed
35/// handle. The ShouldDelete data member defaults to false, ensuring that the
36/// borrowed handle is not deleted when the C++ object is destroyed. HRGN is the
37/// data type representing the handle to an abstract shape.
38//
44
45//
46/// This public copy constructor creates a copy of the given TRegion object as in:
47/// \code
48/// TRegion myRegion = yourRegion;
49/// \endcode
50//
52{
53 Handle = ::CreateRectRgn(0, 0, 0, 0);
54 WARNX(OwlGDI, !Handle, 0, "Cannot create copy of region " << static_cast<void*>(source.GetHandle()));
55 CheckValid();
56 ::CombineRgn(static_cast<HRGN>(Handle), source, nullptr, RGN_COPY);
57}
58
59//
60/// Creates a region object from the given TRect object as in:
61/// \code
62/// TRegion myRegion(rect1);
63/// TRegion* pRegion;
64/// pRegion = new TRegion(rect2);
65/// \endcode
66//
68{
70 WARNX(OwlGDI, !Handle, 0, "Cannot create rect region " << rect);
71 CheckValid();
72}
73
74//
75/// Creates the elliptical TRegion object that inscribes the given rectangle E. The
76/// TEllipse argument distinguishes this constructor from the TRegion(const TRect&
77/// rect) constructor.
78//
80{
82 WARNX(OwlGDI, !Handle, 0, "Cannot create elliptic region " << rect);
83 CheckValid();
84}
85
86//
87/// Creates a rounded rectangular TRegion object from the given rect corner.
88//
90{
91 Handle = ::CreateRoundRectRgn(rect.left, rect.top, rect.right, rect.bottom,
92 corner.cx, corner.cy);
93 WARNX(OwlGDI, !Handle, 0, "Cannot create roundrect region " << rect << corner);
94 CheckValid();
95}
96
97//
98/// Creates a filled TRegion object from the polygons given by points and fillMode.
99//
100TRegion::TRegion(const TPoint* points, int count, int fillMode)
101{
102 Init(points, count, fillMode);
103}
104
105void TRegion::Init(const TPoint* points, int count, int fillMode)
106{
108 WARNX(OwlGDI, !Handle, 0, "Cannot create poly region with " << count << " points "
109 << "@" << static_cast<const void*>(points));
110 CheckValid();
111}
112
113//
114/// Creates a filled TRegion object from the poly-polygons given by points and fillMode.
115/// The 'points' argument should point into an array of points for all the polygons, and
116/// polyCounts should point into an array containing the number of points in each polygon.
117/// The 'count' argument should specify the number of polygons.
118//
119TRegion::TRegion(const TPoint* points, const int* polyCounts, int count, int fillMode)
120{
121 Init(points, polyCounts, count, fillMode);
122}
123
124void TRegion::Init(const TPoint* points, const int* polyCounts, int count, int fillMode)
125{
127 WARNX(OwlGDI, !Handle, 0, "Cannot create polypoly region with " << count << " polygons "
128 << "@" << static_cast<const void*>(points));
129 CheckValid();
130}
131
132//
133// No orphan control for regions since they are not selectable into DCs,
134// just delete
135//
142
143//
144/// Creates the intersection of this region with the given
145/// rectangle, and returns a reference to the result.
146//
147TRegion&
149{
151 return *this;
152}
153
154//
155/// Creates the union of this region and the given rectangle, and
156/// returns a reference to the result.
157//
158TRegion&
160{
162 return *this;
163}
164
165//
166/// Creates the exclusive-or of this region and the given rectangle.
167/// Returns a reference to the resulting region object.
168//
169TRegion&
171{
173 return *this;
174}
175
176} // OWL namespace
177/* ========================================================================== */
178
#define WARNX(group, condition, level, message)
Definition checks.h:277
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
Root and abstract class for Windows object wrappers.
Definition gdibase.h:79
void CheckValid(uint resId=IDS_GDIFAILURE)
Definition gdibase.cpp:49
bool ShouldDelete
Should object delete GDI handle in dtor?
Definition gdibase.h:82
HANDLE Handle
GDI handle of this object.
Definition gdibase.h:81
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TRegion, derived from TGdiObject, represents GDI abstract shapes or regions.
Definition gdiobjec.h:581
TRegion & operator|=(const TRegion &source)
Creates the union of this region and the given source region , and returns a reference to the result.
Definition gdiobjec.h:1555
TEllipse
Defines the class-specific constant Ellipse, used to distinguish the ellipse constructor from the rec...
Definition gdiobjec.h:596
TRegion & operator&=(const TRegion &source)
Creates the intersection of this region with the given source region and returns a reference to the r...
Definition gdiobjec.h:1545
TRegion & operator^=(const TRegion &source)
Creates the exclusive-or of this region and the given source region.
Definition gdiobjec.h:1565
TRegion()
The default constructor creates an empty TRegion object.
Definition region.cpp:26
The tagSIZE struct is defined as.
Definition geometry.h:234
static void Raise(uint resId=IDS_GDIFAILURE, HANDLE handle=0)
Throws the exception.
Definition gdibase.cpp:112
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14