Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / include / vcl / region.hxx
blobaf4941df547086b63bb76f27a223b6c0b5b0cf8a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_REGION_HXX
21 #define INCLUDED_VCL_REGION_HXX
23 #include <tools/gen.hxx>
24 #include <vcl/dllapi.h>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 #include <boost/shared_ptr.hpp>
29 class ImplRegionBand;
30 class RegionBand;
31 class Polygon;
32 class PolyPolygon;
34 typedef boost::shared_ptr< RegionBand > RegionBandPtr;
35 typedef boost::shared_ptr< PolyPolygon > PolyPolygonPtr;
36 typedef boost::shared_ptr< basegfx::B2DPolyPolygon > B2DPolyPolygonPtr;
37 typedef std::vector< Rectangle > RectangleVector;
39 class VCL_DLLPUBLIC Region
41 private:
42 friend class OutputDevice;
43 friend class Window;
44 friend class Bitmap;
46 // possible contents
47 B2DPolyPolygonPtr mpB2DPolyPolygon;
48 PolyPolygonPtr mpPolyPolygon;
49 RegionBandPtr mpRegionBand;
51 /// bitfield
52 bool mbIsNull : 1;
54 // helpers
55 SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const PolyPolygon& rPolyPoly );
56 SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const basegfx::B2DPolyPolygon& rPolyPoly );
58 SAL_DLLPRIVATE PolyPolygon ImplCreatePolyPolygonFromRegionBand() const;
59 SAL_DLLPRIVATE basegfx::B2DPolyPolygon ImplCreateB2DPolyPolygonFromRegionBand() const;
61 public:
63 explicit Region(bool bIsNull = false); // default creates empty region, with true a null region is created
64 explicit Region(const Rectangle& rRect);
65 explicit Region(const Polygon& rPolygon);
66 explicit Region(const PolyPolygon& rPolyPoly);
67 explicit Region(const basegfx::B2DPolyPolygon&);
68 Region(const Region& rRegion);
69 ~Region();
71 // direct access to contents
72 const basegfx::B2DPolyPolygon* getB2DPolyPolygon() const { return mpB2DPolyPolygon.get(); }
73 const PolyPolygon* getPolyPolygon() const { return mpPolyPolygon.get(); }
74 const RegionBand* getRegionBand() const { return mpRegionBand.get(); }
76 // access with converters, the asked data will be created from the most
77 // valuable data, buffered and returned
78 const PolyPolygon GetAsPolyPolygon() const;
79 const basegfx::B2DPolyPolygon GetAsB2DPolyPolygon() const;
80 const RegionBand* GetAsRegionBand() const;
82 // manipulators
83 void Move( long nHorzMove, long nVertMove );
84 void Scale( double fScaleX, double fScaleY );
85 bool Union( const Rectangle& rRegion );
86 bool Intersect( const Rectangle& rRegion );
87 bool Exclude( const Rectangle& rRegion );
88 bool XOr( const Rectangle& rRegion );
89 bool Union( const Region& rRegion );
90 bool Intersect( const Region& rRegion );
91 bool Exclude( const Region& rRegion );
92 bool XOr( const Region& rRegion );
94 bool IsEmpty() const;
95 bool IsNull() const;
97 void SetEmpty();
98 void SetNull();
100 Rectangle GetBoundRect() const;
101 bool HasPolyPolygonOrB2DPolyPolygon() const { return (getB2DPolyPolygon() || getPolyPolygon()); }
102 void GetRegionRectangles(RectangleVector& rTarget) const;
104 bool IsInside( const Point& rPoint ) const;
105 bool IsInside( const Rectangle& rRect ) const;
106 bool IsOver( const Rectangle& rRect ) const;
108 Region& operator=( const Region& rRegion );
109 Region& operator=( const Rectangle& rRect );
111 bool operator==( const Region& rRegion ) const;
112 bool operator!=( const Region& rRegion ) const { return !(Region::operator==( rRegion )); }
114 friend VCL_DLLPUBLIC SvStream& ReadRegion( SvStream& rIStm, Region& rRegion );
115 friend VCL_DLLPUBLIC SvStream& WriteRegion( SvStream& rOStm, const Region& rRegion );
117 /* workaround: faster conversion for PolyPolygons
118 * if half of the Polygons contained in rPolyPoly are actually
119 * rectangles, then the returned Region will be constructed by
120 * XOr'ing the contained Polygons together; in the case of
121 * only Rectangles this can be up to eight times faster than
122 * Region( const PolyPolygon& ).
123 * Caution: this is only useful if the Region is known to be
124 * changed to rectangles; e.g. if being set as clip region
126 static Region GetRegionFromPolyPolygon( const PolyPolygon& rPolyPoly );
130 template< typename charT, typename traits >
131 inline std::basic_ostream<charT, traits> & operator <<(
132 std::basic_ostream<charT, traits> & stream, const Region& rRegion)
134 if (rRegion.IsEmpty())
135 return stream << "EMPTY";
136 if (rRegion.getB2DPolyPolygon())
137 return stream << "B2DPolyPolygon("
138 << *rRegion.getB2DPolyPolygon()
139 << ")";
140 if (rRegion.getPolyPolygon())
141 return stream << "PolyPolygon("
142 << *rRegion.getPolyPolygon()
143 << ")";
144 if (rRegion.getRegionBand())
145 { // inlined because RegionBand is private to vcl
146 stream << "RegionBand(";
147 RectangleVector rects;
148 rRegion.GetRegionRectangles(rects);
149 if (rects.empty())
150 stream << "EMPTY";
151 for (size_t i = 0; i < rects.size(); ++i)
152 stream << "[" << i << "] " << rects[i];
153 stream << ")";
155 return stream;
158 #endif // INCLUDED_VCL_REGION_HXX
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */