1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include <svx/sdr/overlay/overlayobject.hxx>
31 #include <svx/sdr/overlay/overlaymanager.hxx>
32 #include <tools/debug.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <basegfx/vector/b2dvector.hxx>
35 #include <vcl/outdev.hxx>
36 #include <vcl/salbtype.hxx>
37 #include <basegfx/polygon/b2dpolygon.hxx>
38 #include <basegfx/polygon/b2dpolypolygon.hxx>
39 #include <basegfx/polygon/b2dpolygontools.hxx>
40 #include <basegfx/polygon/b2dpolypolygontools.hxx>
41 #include <svx/sdr/contact/objectcontacttools.hxx>
42 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
43 
44 //////////////////////////////////////////////////////////////////////////////
45 
46 namespace sdr
47 {
48 	namespace overlay
49 	{
50 		void OverlayObject::objectChange()
51 		{
52 			const basegfx::B2DRange aPreviousRange(maBaseRange);
53 			maBaseRange.reset();
54 			setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DSequence());
55 
56 			if(getOverlayManager() && !aPreviousRange.isEmpty())
57 			{
58 				getOverlayManager()->invalidateRange(aPreviousRange);
59 			}
60 
61 			const basegfx::B2DRange& rCurrentRange = getBaseRange();
62 
63 			if(getOverlayManager() && rCurrentRange != aPreviousRange && !rCurrentRange.isEmpty())
64 			{
65 				getOverlayManager()->invalidateRange(rCurrentRange);
66 			}
67 		}
68 
69 		// OverlayObject implementations.
70 		drawinglayer::primitive2d::Primitive2DSequence OverlayObject::createOverlayObjectPrimitive2DSequence()
71         {
72             // Default implementation has to assert a missing implementation. It cannot
73             // be useful to have overlay object derivations which have no visualisation
74             // at all
75             OSL_ENSURE(false, "OverlayObject derivation without visualisation definition (missing createOverlayObjectPrimitive2DSequence implementation) (!)");
76             return drawinglayer::primitive2d::Primitive2DSequence();
77         }
78 
79 		void OverlayObject::allowAntiAliase(bool bNew)
80         {
81 			if(bNew != (bool)mbAllowsAntiAliase)
82 			{
83 				// remember new value
84 				mbAllowsAntiAliase = bNew;
85 
86 				// register change (after change)
87 				objectChange();
88 			}
89         }
90 
91 		OverlayObject::OverlayObject(Color aBaseColor)
92 		:	Event(0),
93 			mpOverlayManager(0),
94 			maBaseColor(aBaseColor),
95 			mbIsVisible(true),
96 			mbIsHittable(true),
97 			mbAllowsAnimation(false),
98             mbAllowsAntiAliase(true)
99 		{
100 		}
101 
102 		OverlayObject::~OverlayObject()
103 		{
104 			OSL_ENSURE(0 == getOverlayManager(), "OverlayObject is destructed which is still registered at OverlayManager (!)");
105 		}
106 
107 		drawinglayer::primitive2d::Primitive2DSequence OverlayObject::getOverlayObjectPrimitive2DSequence() const
108 		{
109 			if(!getPrimitive2DSequence().hasElements())
110 			{
111 				// no existing sequence; create one
112 				const_cast< OverlayObject* >(this)->setPrimitive2DSequence(
113 					const_cast< OverlayObject* >(this)->createOverlayObjectPrimitive2DSequence());
114 			}
115 
116 			return getPrimitive2DSequence();
117 		}
118 
119 		const basegfx::B2DRange& OverlayObject::getBaseRange() const
120 		{
121 			if(getOverlayManager() && maBaseRange.isEmpty())
122 			{
123 				const drawinglayer::primitive2d::Primitive2DSequence& rSequence = getOverlayObjectPrimitive2DSequence();
124 
125 				if(rSequence.hasElements())
126 				{
127 					const drawinglayer::geometry::ViewInformation2D aViewInformation2D(getOverlayManager()->getCurrentViewInformation2D());
128 
129 					const_cast< sdr::overlay::OverlayObject* >(this)->maBaseRange =
130 						drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(rSequence, aViewInformation2D);
131 				}
132 			}
133 
134 			return maBaseRange;
135 		}
136 
137 		void OverlayObject::setVisible(bool bNew)
138 		{
139 			if(bNew != (bool)mbIsVisible)
140 			{
141 				// remember new value
142 				mbIsVisible = bNew;
143 
144 				// register change (after change)
145 				objectChange();
146 			}
147 		}
148 
149 		void OverlayObject::setHittable(bool bNew)
150 		{
151 			if(bNew != (bool)mbIsHittable)
152 			{
153 				// remember new value
154 				mbIsHittable = bNew;
155 
156 				// register change (after change)
157 				objectChange();
158 			}
159 		}
160 
161 		void OverlayObject::setBaseColor(Color aNew)
162 		{
163 			if(aNew != maBaseColor)
164 			{
165 				// remember new value
166 				maBaseColor = aNew;
167 
168 				// register change (after change)
169 				objectChange();
170 			}
171 		}
172 
173 		void OverlayObject::Trigger(sal_uInt32 /*nTime*/)
174 		{
175 			// default does not register again
176 		}
177 
178 		void OverlayObject::stripeDefinitionHasChanged()
179 		{
180 			// default does not need to do anything
181 		}
182 	} // end of namespace overlay
183 } // end of namespace sdr
184 
185 //////////////////////////////////////////////////////////////////////////////
186 
187 namespace sdr
188 {
189 	namespace overlay
190 	{
191 		OverlayObjectWithBasePosition::OverlayObjectWithBasePosition(const basegfx::B2DPoint& rBasePos, Color aBaseColor)
192 		:	OverlayObject(aBaseColor),
193 			maBasePosition(rBasePos)
194 		{
195 		}
196 
197 		OverlayObjectWithBasePosition::~OverlayObjectWithBasePosition()
198 		{
199 		}
200 
201 		void OverlayObjectWithBasePosition::setBasePosition(const basegfx::B2DPoint& rNew)
202 		{
203 			if(rNew != maBasePosition)
204 			{
205 				// remember new value
206 				maBasePosition = rNew;
207 
208 				// register change (after change)
209 				objectChange();
210 			}
211 		}
212 	} // end of namespace overlay
213 } // end of namespace sdr
214 
215 //////////////////////////////////////////////////////////////////////////////
216 // eof
217