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/objectcontactofobjlistpainter.hxx>
31 #include <svx/sdr/contact/displayinfo.hxx>
32 #include <svx/sdr/contact/viewobjectcontact.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/svdobj.hxx>
35 #include <svx/sdr/contact/viewcontact.hxx>
36 #include <svx/svdmodel.hxx>
37 #include <drawinglayer/processor2d/vclprocessor2d.hxx>
38 #include <basegfx/matrix/b2dhommatrix.hxx>
39 #include <svx/sdr/contact/objectcontacttools.hxx>
40 #include <svx/unoapi.hxx>
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace sdr
45 {
46 	namespace contact
47 	{
48 		ObjectContactPainter::ObjectContactPainter()
49 		{
50 		}
51 
52 		// The destructor.
53 		ObjectContactPainter::~ObjectContactPainter()
54 		{
55 		}
56 	} // end of namespace contact
57 } // end of namespace sdr
58 
59 //////////////////////////////////////////////////////////////////////////////
60 
61 namespace sdr
62 {
63 	namespace contact
64 	{
65 		sal_uInt32 ObjectContactOfObjListPainter::GetPaintObjectCount() const
66 		{
67 			return maStartObjects.size();
68 		}
69 
70 		ViewContact& ObjectContactOfObjListPainter::GetPaintObjectViewContact(sal_uInt32 nIndex) const
71 		{
72 			const SdrObject* pObj = maStartObjects[nIndex];
73 			DBG_ASSERT(pObj, "ObjectContactOfObjListPainter: Corrupt SdrObjectVector (!)");
74 			return pObj->GetViewContact();
75 		}
76 
77 		ObjectContactOfObjListPainter::ObjectContactOfObjListPainter(
78 			OutputDevice& rTargetDevice,
79 			const SdrObjectVector& rObjects,
80             const SdrPage* pProcessedPage)
81 		:	ObjectContactPainter(),
82 			mrTargetOutputDevice(rTargetDevice),
83 			maStartObjects(rObjects),
84             mpProcessedPage(pProcessedPage)
85 		{
86 		}
87 
88 		ObjectContactOfObjListPainter::~ObjectContactOfObjListPainter()
89 		{
90 		}
91 
92 		// Process the whole displaying
93 		void ObjectContactOfObjListPainter::ProcessDisplay(DisplayInfo& rDisplayInfo)
94 		{
95 			const sal_uInt32 nCount(GetPaintObjectCount());
96 
97 			if(nCount)
98 			{
99 				OutputDevice* pTargetDevice = TryToGetOutputDevice();
100 
101 				if(pTargetDevice)
102 				{
103 					// update current ViewInformation2D at the ObjectContact
104 					const GDIMetaFile* pMetaFile = pTargetDevice->GetConnectMetaFile();
105 					const bool bOutputToRecordingMetaFile(pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
106 					basegfx::B2DRange aViewRange;
107 
108 					// create ViewRange
109 					if(!bOutputToRecordingMetaFile)
110 					{
111 						// use visible pixels, but transform to world coordinates
112 						const Size aOutputSizePixel(pTargetDevice->GetOutputSizePixel());
113 						aViewRange = ::basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
114 						aViewRange.transform(pTargetDevice->GetInverseViewTransformation());
115 					}
116 
117 					// upate local ViewInformation2D
118 					const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D(
119                         basegfx::B2DHomMatrix(),
120 						pTargetDevice->GetViewTransformation(),
121 						aViewRange,
122         				GetXDrawPageForSdrPage(const_cast< SdrPage* >(mpProcessedPage)),
123 						0.0,
124 						com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>());
125 					updateViewInformation2D(aNewViewInformation2D);
126 
127 					// collect primitive data in a sequence; this will already use the updated ViewInformation2D
128 					drawinglayer::primitive2d::Primitive2DSequence xPrimitiveSequence;
129 
130 					for(sal_uInt32 a(0L); a < nCount; a++)
131 					{
132 						const ViewObjectContact& rViewObjectContact = GetPaintObjectViewContact(a).GetViewObjectContact(*this);
133 
134 						drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xPrimitiveSequence,
135 							rViewObjectContact.getPrimitive2DSequenceHierarchy(rDisplayInfo));
136 					}
137 
138 					// if there is something to show, use a vclProcessor to render it
139 					if(xPrimitiveSequence.hasElements())
140 					{
141 						drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = createBaseProcessor2DFromOutputDevice(
142 							*pTargetDevice, getViewInformation2D());
143 
144 						if(pProcessor2D)
145 						{
146 							pProcessor2D->process(xPrimitiveSequence);
147 							delete pProcessor2D;
148 						}
149 					}
150 				}
151 			}
152 		}
153 
154 		// VirtualDevice?
155 		bool ObjectContactOfObjListPainter::isOutputToVirtualDevice() const
156 		{
157 			return (OUTDEV_VIRDEV == mrTargetOutputDevice.GetOutDevType());
158 		}
159 
160 		// recording MetaFile?
161 		bool ObjectContactOfObjListPainter::isOutputToRecordingMetaFile() const
162 		{
163 			GDIMetaFile* pMetaFile = mrTargetOutputDevice.GetConnectMetaFile();
164 			return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
165 		}
166 
167 		// pdf export?
168 		bool ObjectContactOfObjListPainter::isOutputToPDFFile() const
169 		{
170             return (0 != mrTargetOutputDevice.GetPDFWriter());
171 		}
172 
173 		OutputDevice* ObjectContactOfObjListPainter::TryToGetOutputDevice() const
174 		{
175 			return &mrTargetOutputDevice;
176 		}
177 	} // end of namespace contact
178 } // end of namespace sdr
179 
180 //////////////////////////////////////////////////////////////////////////////
181 
182 namespace sdr
183 {
184 	namespace contact
185 	{
186 		sal_uInt32 ObjectContactOfPagePainter::GetPaintObjectCount() const
187 		{
188 			return (GetStartPage() ? 1L : 0L);
189 		}
190 
191 		ViewContact& ObjectContactOfPagePainter::GetPaintObjectViewContact(sal_uInt32 /*nIndex*/) const
192 		{
193 			DBG_ASSERT(GetStartPage(), "ObjectContactOfPagePainter::GetPaintObjectViewContact: no StartPage set (!)");
194 			return GetStartPage()->GetViewContact();
195 		}
196 
197 		ObjectContactOfPagePainter::ObjectContactOfPagePainter(
198 			const SdrPage* pPage,
199 			ObjectContact& rOriginalObjectContact)
200 		:	ObjectContactPainter(),
201 			mrOriginalObjectContact(rOriginalObjectContact),
202 			mxStartPage(const_cast< SdrPage* >(pPage)) // no SdrPageWeakRef available to hold a const SdrPage*
203 		{
204 		}
205 
206 		ObjectContactOfPagePainter::~ObjectContactOfPagePainter()
207 		{
208 		}
209 
210 		void ObjectContactOfPagePainter::SetStartPage(const SdrPage* pPage)
211 		{
212 			if(pPage != GetStartPage())
213 			{
214 				mxStartPage.reset(const_cast< SdrPage* >(pPage)); // no SdrPageWeakRef available to hold a const SdrPage*
215 			}
216 		}
217 
218 		OutputDevice* ObjectContactOfPagePainter::TryToGetOutputDevice() const
219 		{
220 			return mrOriginalObjectContact.TryToGetOutputDevice();
221 		}
222 	} // end of namespace contact
223 } // end of namespace sdr
224 
225 //////////////////////////////////////////////////////////////////////////////
226 // eof
227