1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
27cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
28cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontact.hxx>
29cdf0e10cSrcweir #include <svx/svdpage.hxx>
30cdf0e10cSrcweir #include <svx/svdobj.hxx>
31cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx>
32cdf0e10cSrcweir #include <svx/svdmodel.hxx>
33cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
34*a7185797SArmin Le Grand #include <drawinglayer/processor2d/processor2dtools.hxx>
35cdf0e10cSrcweir #include <svx/unoapi.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace sdr
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	namespace contact
42cdf0e10cSrcweir 	{
ObjectContactPainter()43cdf0e10cSrcweir 		ObjectContactPainter::ObjectContactPainter()
44cdf0e10cSrcweir 		{
45cdf0e10cSrcweir 		}
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 		// The destructor.
~ObjectContactPainter()48cdf0e10cSrcweir 		ObjectContactPainter::~ObjectContactPainter()
49cdf0e10cSrcweir 		{
50cdf0e10cSrcweir 		}
51cdf0e10cSrcweir 	} // end of namespace contact
52cdf0e10cSrcweir } // end of namespace sdr
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
55cdf0e10cSrcweir 
56cdf0e10cSrcweir namespace sdr
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	namespace contact
59cdf0e10cSrcweir 	{
GetPaintObjectCount() const60cdf0e10cSrcweir 		sal_uInt32 ObjectContactOfObjListPainter::GetPaintObjectCount() const
61cdf0e10cSrcweir 		{
62cdf0e10cSrcweir 			return maStartObjects.size();
63cdf0e10cSrcweir 		}
64cdf0e10cSrcweir 
GetPaintObjectViewContact(sal_uInt32 nIndex) const65cdf0e10cSrcweir 		ViewContact& ObjectContactOfObjListPainter::GetPaintObjectViewContact(sal_uInt32 nIndex) const
66cdf0e10cSrcweir 		{
67cdf0e10cSrcweir 			const SdrObject* pObj = maStartObjects[nIndex];
68cdf0e10cSrcweir 			DBG_ASSERT(pObj, "ObjectContactOfObjListPainter: Corrupt SdrObjectVector (!)");
69cdf0e10cSrcweir 			return pObj->GetViewContact();
70cdf0e10cSrcweir 		}
71cdf0e10cSrcweir 
ObjectContactOfObjListPainter(OutputDevice & rTargetDevice,const SdrObjectVector & rObjects,const SdrPage * pProcessedPage)72cdf0e10cSrcweir 		ObjectContactOfObjListPainter::ObjectContactOfObjListPainter(
73cdf0e10cSrcweir 			OutputDevice& rTargetDevice,
74cdf0e10cSrcweir 			const SdrObjectVector& rObjects,
75cdf0e10cSrcweir             const SdrPage* pProcessedPage)
76cdf0e10cSrcweir 		:	ObjectContactPainter(),
77cdf0e10cSrcweir 			mrTargetOutputDevice(rTargetDevice),
78cdf0e10cSrcweir 			maStartObjects(rObjects),
79cdf0e10cSrcweir             mpProcessedPage(pProcessedPage)
80cdf0e10cSrcweir 		{
81cdf0e10cSrcweir 		}
82cdf0e10cSrcweir 
~ObjectContactOfObjListPainter()83cdf0e10cSrcweir 		ObjectContactOfObjListPainter::~ObjectContactOfObjListPainter()
84cdf0e10cSrcweir 		{
85cdf0e10cSrcweir 		}
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		// Process the whole displaying
ProcessDisplay(DisplayInfo & rDisplayInfo)88cdf0e10cSrcweir 		void ObjectContactOfObjListPainter::ProcessDisplay(DisplayInfo& rDisplayInfo)
89cdf0e10cSrcweir 		{
90cdf0e10cSrcweir 			const sal_uInt32 nCount(GetPaintObjectCount());
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 			if(nCount)
93cdf0e10cSrcweir 			{
94cdf0e10cSrcweir 				OutputDevice* pTargetDevice = TryToGetOutputDevice();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 				if(pTargetDevice)
97cdf0e10cSrcweir 				{
98cdf0e10cSrcweir 					// update current ViewInformation2D at the ObjectContact
99cdf0e10cSrcweir 					const GDIMetaFile* pMetaFile = pTargetDevice->GetConnectMetaFile();
100cdf0e10cSrcweir 					const bool bOutputToRecordingMetaFile(pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
101cdf0e10cSrcweir 					basegfx::B2DRange aViewRange;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 					// create ViewRange
104cdf0e10cSrcweir 					if(!bOutputToRecordingMetaFile)
105cdf0e10cSrcweir 					{
106cdf0e10cSrcweir 						// use visible pixels, but transform to world coordinates
107cdf0e10cSrcweir 						const Size aOutputSizePixel(pTargetDevice->GetOutputSizePixel());
108cdf0e10cSrcweir 						aViewRange = ::basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
109cdf0e10cSrcweir 						aViewRange.transform(pTargetDevice->GetInverseViewTransformation());
110cdf0e10cSrcweir 					}
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 					// upate local ViewInformation2D
113cdf0e10cSrcweir 					const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D(
114cdf0e10cSrcweir                         basegfx::B2DHomMatrix(),
115cdf0e10cSrcweir 						pTargetDevice->GetViewTransformation(),
116cdf0e10cSrcweir 						aViewRange,
117cdf0e10cSrcweir         				GetXDrawPageForSdrPage(const_cast< SdrPage* >(mpProcessedPage)),
118cdf0e10cSrcweir 						0.0,
119cdf0e10cSrcweir 						com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>());
120cdf0e10cSrcweir 					updateViewInformation2D(aNewViewInformation2D);
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 					// collect primitive data in a sequence; this will already use the updated ViewInformation2D
123cdf0e10cSrcweir 					drawinglayer::primitive2d::Primitive2DSequence xPrimitiveSequence;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 					for(sal_uInt32 a(0L); a < nCount; a++)
126cdf0e10cSrcweir 					{
127cdf0e10cSrcweir 						const ViewObjectContact& rViewObjectContact = GetPaintObjectViewContact(a).GetViewObjectContact(*this);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 						drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xPrimitiveSequence,
130cdf0e10cSrcweir 							rViewObjectContact.getPrimitive2DSequenceHierarchy(rDisplayInfo));
131cdf0e10cSrcweir 					}
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 					// if there is something to show, use a vclProcessor to render it
134cdf0e10cSrcweir 					if(xPrimitiveSequence.hasElements())
135cdf0e10cSrcweir 					{
136*a7185797SArmin Le Grand 						drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createProcessor2DFromOutputDevice(
137*a7185797SArmin Le Grand 							*pTargetDevice,
138*a7185797SArmin Le Grand                             getViewInformation2D());
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 						if(pProcessor2D)
141cdf0e10cSrcweir 						{
142cdf0e10cSrcweir 							pProcessor2D->process(xPrimitiveSequence);
143cdf0e10cSrcweir 							delete pProcessor2D;
144cdf0e10cSrcweir 						}
145cdf0e10cSrcweir 					}
146cdf0e10cSrcweir 				}
147cdf0e10cSrcweir 			}
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		// VirtualDevice?
isOutputToVirtualDevice() const151cdf0e10cSrcweir 		bool ObjectContactOfObjListPainter::isOutputToVirtualDevice() const
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			return (OUTDEV_VIRDEV == mrTargetOutputDevice.GetOutDevType());
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		// recording MetaFile?
isOutputToRecordingMetaFile() const157cdf0e10cSrcweir 		bool ObjectContactOfObjListPainter::isOutputToRecordingMetaFile() const
158cdf0e10cSrcweir 		{
159cdf0e10cSrcweir 			GDIMetaFile* pMetaFile = mrTargetOutputDevice.GetConnectMetaFile();
160cdf0e10cSrcweir 			return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		// pdf export?
isOutputToPDFFile() const164cdf0e10cSrcweir 		bool ObjectContactOfObjListPainter::isOutputToPDFFile() const
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir             return (0 != mrTargetOutputDevice.GetPDFWriter());
167cdf0e10cSrcweir 		}
168cdf0e10cSrcweir 
TryToGetOutputDevice() const169cdf0e10cSrcweir 		OutputDevice* ObjectContactOfObjListPainter::TryToGetOutputDevice() const
170cdf0e10cSrcweir 		{
171cdf0e10cSrcweir 			return &mrTargetOutputDevice;
172cdf0e10cSrcweir 		}
173cdf0e10cSrcweir 	} // end of namespace contact
174cdf0e10cSrcweir } // end of namespace sdr
175cdf0e10cSrcweir 
176cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
177cdf0e10cSrcweir 
178cdf0e10cSrcweir namespace sdr
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	namespace contact
181cdf0e10cSrcweir 	{
GetPaintObjectCount() const182cdf0e10cSrcweir 		sal_uInt32 ObjectContactOfPagePainter::GetPaintObjectCount() const
183cdf0e10cSrcweir 		{
184cdf0e10cSrcweir 			return (GetStartPage() ? 1L : 0L);
185cdf0e10cSrcweir 		}
186cdf0e10cSrcweir 
GetPaintObjectViewContact(sal_uInt32) const187cdf0e10cSrcweir 		ViewContact& ObjectContactOfPagePainter::GetPaintObjectViewContact(sal_uInt32 /*nIndex*/) const
188cdf0e10cSrcweir 		{
189cdf0e10cSrcweir 			DBG_ASSERT(GetStartPage(), "ObjectContactOfPagePainter::GetPaintObjectViewContact: no StartPage set (!)");
190cdf0e10cSrcweir 			return GetStartPage()->GetViewContact();
191cdf0e10cSrcweir 		}
192cdf0e10cSrcweir 
ObjectContactOfPagePainter(const SdrPage * pPage,ObjectContact & rOriginalObjectContact)193cdf0e10cSrcweir 		ObjectContactOfPagePainter::ObjectContactOfPagePainter(
194cdf0e10cSrcweir 			const SdrPage* pPage,
195cdf0e10cSrcweir 			ObjectContact& rOriginalObjectContact)
196cdf0e10cSrcweir 		:	ObjectContactPainter(),
197cdf0e10cSrcweir 			mrOriginalObjectContact(rOriginalObjectContact),
198cdf0e10cSrcweir 			mxStartPage(const_cast< SdrPage* >(pPage)) // no SdrPageWeakRef available to hold a const SdrPage*
199cdf0e10cSrcweir 		{
200cdf0e10cSrcweir 		}
201cdf0e10cSrcweir 
~ObjectContactOfPagePainter()202cdf0e10cSrcweir 		ObjectContactOfPagePainter::~ObjectContactOfPagePainter()
203cdf0e10cSrcweir 		{
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 
SetStartPage(const SdrPage * pPage)206cdf0e10cSrcweir 		void ObjectContactOfPagePainter::SetStartPage(const SdrPage* pPage)
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			if(pPage != GetStartPage())
209cdf0e10cSrcweir 			{
210cdf0e10cSrcweir 				mxStartPage.reset(const_cast< SdrPage* >(pPage)); // no SdrPageWeakRef available to hold a const SdrPage*
211cdf0e10cSrcweir 			}
212cdf0e10cSrcweir 		}
213cdf0e10cSrcweir 
TryToGetOutputDevice() const214cdf0e10cSrcweir 		OutputDevice* ObjectContactOfPagePainter::TryToGetOutputDevice() const
215cdf0e10cSrcweir 		{
216cdf0e10cSrcweir 			return mrOriginalObjectContact.TryToGetOutputDevice();
217cdf0e10cSrcweir 		}
218cdf0e10cSrcweir 	} // end of namespace contact
219cdf0e10cSrcweir } // end of namespace sdr
220cdf0e10cSrcweir 
221cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
222cdf0e10cSrcweir // eof
223