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/contact/objectcontact.hxx>
31 #include <tools/debug.hxx>
32 #include <svx/sdr/contact/viewobjectcontact.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/sdr/contact/viewcontact.hxx>
35 #include <svx/sdr/event/eventhandler.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <svx/sdr/animation/objectanimator.hxx>
38 #include <svx/sdr/event/eventhandler.hxx>
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 using namespace com::sun::star;
43 
44 //////////////////////////////////////////////////////////////////////////////
45 
46 namespace sdr
47 {
48 	namespace contact
49 	{
50 		ObjectContact::ObjectContact()
51 		:	maViewObjectContactVector(),
52 			maPrimitiveAnimator(),
53 			mpEventHandler(0),
54 			mpViewObjectContactRedirector(0),
55 			maViewInformation2D(uno::Sequence< beans::PropertyValue >()),
56 			mbIsPreviewRenderer(false)
57 		{
58 		}
59 
60 		ObjectContact::~ObjectContact()
61 		{
62 			// get rid of all registered contacts
63 			// #i84257# To avoid that each 'delete pCandidate' again uses
64 			// the local RemoveViewObjectContact with a search and removal in the
65 			// vector, simply copy and clear local vector.
66 			std::vector< ViewObjectContact* > aLocalVOCList(maViewObjectContactVector);
67 			maViewObjectContactVector.clear();
68 
69 			while(!aLocalVOCList.empty())
70 			{
71 				ViewObjectContact* pCandidate = aLocalVOCList.back();
72 				aLocalVOCList.pop_back();
73 				DBG_ASSERT(pCandidate, "Corrupted ViewObjectContactList (!)");
74 
75 				// ViewObjectContacts only make sense with View and Object contacts.
76 				// When the contact to the SdrObject is deleted like in this case,
77 				// all ViewObjectContacts can be deleted, too.
78 				delete pCandidate;
79 			}
80 
81 			// assert when there were new entries added during deletion
82 			DBG_ASSERT(maViewObjectContactVector.empty(), "Corrupted ViewObjectContactList (!)");
83 
84 			// delete the EventHandler. This will destroy all still contained events.
85 			DeleteEventHandler();
86 		}
87 
88 		// LazyInvalidate request. Default implementation directly handles
89 		// this by calling back triggerLazyInvalidate() at the VOC
90 		void ObjectContact::setLazyInvalidate(ViewObjectContact& rVOC)
91 		{
92 			rVOC.triggerLazyInvalidate();
93 		}
94 
95 		// call this to support evtl. preparations for repaint. Default does nothing
96 		void ObjectContact::PrepareProcessDisplay()
97 		{
98 		}
99 
100 		// A new ViewObjectContact was created and shall be remembered.
101 		void ObjectContact::AddViewObjectContact(ViewObjectContact& rVOContact)
102 		{
103 			maViewObjectContactVector.push_back(&rVOContact);
104 		}
105 
106 		// A ViewObjectContact was deleted and shall be forgotten.
107 		void ObjectContact::RemoveViewObjectContact(ViewObjectContact& rVOContact)
108 		{
109 			std::vector< ViewObjectContact* >::iterator aFindResult = std::find(maViewObjectContactVector.begin(), maViewObjectContactVector.end(), &rVOContact);
110 
111 			if(aFindResult != maViewObjectContactVector.end())
112 			{
113 				maViewObjectContactVector.erase(aFindResult);
114 			}
115 		}
116 
117 		// Process the whole displaying
118 		void ObjectContact::ProcessDisplay(DisplayInfo& /*rDisplayInfo*/)
119 		{
120 			// default does nothing
121 		}
122 
123 		// test if visualizing of entered groups is switched on at all
124 		bool ObjectContact::DoVisualizeEnteredGroup() const
125 		{
126 			// Don not do that as default
127 			return false;
128 		}
129 
130 		// get active group's (the entered group) ViewContact
131 		const ViewContact* ObjectContact::getActiveViewContact() const
132 		{
133 			// default has no active VC
134 			return 0;
135 		}
136 
137 		// Invalidate given rectangle at the window/output which is represented by
138 		// this ObjectContact.
139 		void ObjectContact::InvalidatePartOfView(const basegfx::B2DRange& /*rRange*/) const
140 		{
141 			// nothing to do here in the default version
142 		}
143 
144 		// Get info if given Rectangle is visible in this view
145 		bool ObjectContact::IsAreaVisible(const basegfx::B2DRange& /*rRange*/) const
146 		{
147 			// always visible in default version
148 			return true;
149 		}
150 
151 		// Get info about the need to visualize GluePoints
152 		bool ObjectContact::AreGluePointsVisible() const
153 		{
154 			return false;
155 		}
156 
157 		// method to create a EventHandler. Needs to give a result.
158 		sdr::event::TimerEventHandler* ObjectContact::CreateEventHandler()
159 		{
160 			// Create and return a new EventHandler
161 			return new sdr::event::TimerEventHandler();
162 		}
163 
164 		// method to get the primitiveAnimator
165 		sdr::animation::primitiveAnimator& ObjectContact::getPrimitiveAnimator()
166 		{
167 			return maPrimitiveAnimator;
168 		}
169 
170 		// method to get the EventHandler. It will
171 		// return a existing one or create a new one using CreateEventHandler().
172 		sdr::event::TimerEventHandler& ObjectContact::GetEventHandler() const
173 		{
174 			if(!HasEventHandler())
175 			{
176 				const_cast< ObjectContact* >(this)->mpEventHandler = const_cast< ObjectContact* >(this)->CreateEventHandler();
177 				DBG_ASSERT(mpEventHandler, "ObjectContact::GetEventHandler(): Got no EventHandler (!)");
178 			}
179 
180 			return *mpEventHandler;
181 		}
182 
183 		// delete the EventHandler
184 		void ObjectContact::DeleteEventHandler()
185 		{
186 			if(mpEventHandler)
187 			{
188 				// If there are still Events registered, something has went wrong
189 				delete mpEventHandler;
190 				mpEventHandler = 0L;
191 			}
192 		}
193 
194 		// test if there is an EventHandler without creating one on demand
195 		bool ObjectContact::HasEventHandler() const
196 		{
197 			return (0L != mpEventHandler);
198 		}
199 
200 		// check if text animation is allowed. Default is sal_true.
201 		bool ObjectContact::IsTextAnimationAllowed() const
202 		{
203 			return true;
204 		}
205 
206 		// check if graphic animation is allowed. Default is sal_true.
207 		bool ObjectContact::IsGraphicAnimationAllowed() const
208 		{
209 			return true;
210 		}
211 
212 		// check if asynchronious graphis loading is allowed. Default is false.
213 		bool ObjectContact::IsAsynchronGraphicsLoadingAllowed() const
214 		{
215 			return false;
216 		}
217 
218 		// access to ViewObjectContactRedirector
219 		ViewObjectContactRedirector* ObjectContact::GetViewObjectContactRedirector() const
220 		{
221 			return mpViewObjectContactRedirector;
222 		}
223 
224 		void ObjectContact::SetViewObjectContactRedirector(ViewObjectContactRedirector* pNew)
225 		{
226 			if(mpViewObjectContactRedirector != pNew)
227 			{
228 				mpViewObjectContactRedirector = pNew;
229 			}
230 		}
231 
232 		// check if buffering of MasterPages is allowed. Default is false.
233 		bool ObjectContact::IsMasterPageBufferingAllowed() const
234 		{
235 			return false;
236 		}
237 
238 		// print? Default is false
239 		bool ObjectContact::isOutputToPrinter() const
240 		{
241 			return false;
242 		}
243 
244 		// window? Default is true
245 		bool ObjectContact::isOutputToWindow() const
246 		{
247 			return true;
248 		}
249 
250 		// VirtualDevice? Default is false
251 		bool ObjectContact::isOutputToVirtualDevice() const
252 		{
253 			return false;
254 		}
255 
256 		// recording MetaFile? Default is false
257 		bool ObjectContact::isOutputToRecordingMetaFile() const
258 		{
259 			return false;
260 		}
261 
262 		// pdf export? Default is false
263 		bool ObjectContact::isOutputToPDFFile() const
264 		{
265 			return false;
266 		}
267 
268 		// gray display mode
269 		bool ObjectContact::isDrawModeGray() const
270 		{
271 			return false;
272 		}
273 
274 		// gray display mode
275 		bool ObjectContact::isDrawModeBlackWhite() const
276 		{
277 			return false;
278 		}
279 
280 		// high contrast display mode
281 		bool ObjectContact::isDrawModeHighContrast() const
282 		{
283 			return false;
284 		}
285 
286         // access to SdrPageView. Default implementation returns NULL
287 		SdrPageView* ObjectContact::TryToGetSdrPageView() const
288         {
289             return 0;
290         }
291 
292 		// access to OutputDevice. Default implementation returns NULL
293 		OutputDevice* ObjectContact::TryToGetOutputDevice() const
294         {
295             return 0;
296         }
297 
298         void ObjectContact::resetViewPort()
299         {
300 			const drawinglayer::geometry::ViewInformation2D& rCurrentVI2D = getViewInformation2D();
301 
302             if(!rCurrentVI2D.getViewport().isEmpty())
303             {
304                 const basegfx::B2DRange aEmptyRange;
305 
306                 drawinglayer::geometry::ViewInformation2D aNewVI2D(
307                     rCurrentVI2D.getObjectTransformation(),
308                     rCurrentVI2D.getViewTransformation(),
309                     aEmptyRange,
310                     rCurrentVI2D.getVisualizedPage(),
311                     rCurrentVI2D.getViewTime(),
312                     rCurrentVI2D.getExtendedInformationSequence());
313 
314                 updateViewInformation2D(aNewVI2D);
315             }
316         }
317 
318 	} // end of namespace contact
319 } // end of namespace sdr
320 
321 //////////////////////////////////////////////////////////////////////////////
322 // eof
323