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