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/viewcontactofgraphic.hxx>
31*cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofgraphic.hxx>
32*cdf0e10cSrcweir #include <svx/svdograf.hxx>
33*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
34*cdf0e10cSrcweir #include <svl/itemset.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #ifndef ITEMID_GRF_CROP
37*cdf0e10cSrcweir #define ITEMID_GRF_CROP	0
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <svx/sdgcpitm.hxx>
41*cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
42*cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontact.hxx>
43*cdf0e10cSrcweir #include <svx/sdr/contact/objectcontact.hxx>
44*cdf0e10cSrcweir #include <svx/sdr/event/eventhandler.hxx>
45*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
46*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrgrafprimitive2d.hxx>
47*cdf0e10cSrcweir #include "svx/svdstr.hrc"
48*cdf0e10cSrcweir #include <svx/svdglob.hxx>
49*cdf0e10cSrcweir #include <vcl/svapp.hxx>
50*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
51*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
52*cdf0e10cSrcweir #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
53*cdf0e10cSrcweir #include <drawinglayer/primitive2d/textprimitive2d.hxx>
54*cdf0e10cSrcweir #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
55*cdf0e10cSrcweir #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
56*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrtextprimitive2d.hxx>
57*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
58*cdf0e10cSrcweir #include <editeng/colritem.hxx>
59*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
60*cdf0e10cSrcweir #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir namespace sdr
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir 	namespace contact
67*cdf0e10cSrcweir 	{
68*cdf0e10cSrcweir 		// Create a Object-Specific ViewObjectContact, set ViewContact and
69*cdf0e10cSrcweir 		// ObjectContact. Always needs to return something.
70*cdf0e10cSrcweir 		ViewObjectContact& ViewContactOfGraphic::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
71*cdf0e10cSrcweir 		{
72*cdf0e10cSrcweir 			ViewObjectContact* pRetval = new ViewObjectContactOfGraphic(rObjectContact, *this);
73*cdf0e10cSrcweir 			DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 			return *pRetval;
76*cdf0e10cSrcweir 		}
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		ViewContactOfGraphic::ViewContactOfGraphic(SdrGrafObj& rGrafObj)
79*cdf0e10cSrcweir 		:	ViewContactOfTextObj(rGrafObj)
80*cdf0e10cSrcweir 		{
81*cdf0e10cSrcweir 		}
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 		ViewContactOfGraphic::~ViewContactOfGraphic()
84*cdf0e10cSrcweir 		{
85*cdf0e10cSrcweir 		}
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 		void ViewContactOfGraphic::flushGraphicObjects()
88*cdf0e10cSrcweir 		{
89*cdf0e10cSrcweir 			// #i102380# The graphic is swapped out. To let that have an effect ist is necessary to
90*cdf0e10cSrcweir 			// delete copies of the GraphicObject which are not swapped out and have no SwapHandler set
91*cdf0e10cSrcweir 			// (this is what happnes when the GraphicObject gets copied to a SdrGrafPrimitive2D). This
92*cdf0e10cSrcweir 			// is best achieved for the VC by clearing the local decomposition cache. It would be possible
93*cdf0e10cSrcweir 			// to also do this for the VOC cache, but that VOCs exist exactly expresss that the object
94*cdf0e10cSrcweir 			// gets visualised, so this would be wrong.
95*cdf0e10cSrcweir 			flushViewIndependentPrimitive2DSequence();
96*cdf0e10cSrcweir 		}
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfGraphic::createVIP2DSForPresObj(
99*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rObjectMatrix,
100*cdf0e10cSrcweir 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute& rAttribute,
101*cdf0e10cSrcweir 			const GraphicAttr& rLocalGrafInfo) const
102*cdf0e10cSrcweir 		{
103*cdf0e10cSrcweir 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
104*cdf0e10cSrcweir             GraphicObject aEmptyGraphicObject;
105*cdf0e10cSrcweir 			GraphicAttr	aEmptyGraphicAttr;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir             // SdrGrafPrimitive2D without content in original size which carries all eventual attributes and texts
108*cdf0e10cSrcweir             const drawinglayer::primitive2d::Primitive2DReference xReferenceA(new drawinglayer::primitive2d::SdrGrafPrimitive2D(
109*cdf0e10cSrcweir 			    rObjectMatrix,
110*cdf0e10cSrcweir 				rAttribute,
111*cdf0e10cSrcweir 				aEmptyGraphicObject,
112*cdf0e10cSrcweir 				aEmptyGraphicAttr));
113*cdf0e10cSrcweir 		    xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReferenceA, 1);
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir             // SdrGrafPrimitive2D with content (which is the preview graphic) scaled to smaller size and
116*cdf0e10cSrcweir             // without attributes
117*cdf0e10cSrcweir             basegfx::B2DHomMatrix aSmallerMatrix;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir             // #i94431# for some reason, i forgot to take the PrefMapMode of the graphic
120*cdf0e10cSrcweir             // into account. Since EmptyPresObj's are only used in Draw/Impress, it is
121*cdf0e10cSrcweir             // safe to assume 100th mm as target.
122*cdf0e10cSrcweir 			Size aPrefSize(GetGrafObject().GetGrafPrefSize());
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir             if(MAP_PIXEL == GetGrafObject().GetGrafPrefMapMode().GetMapUnit())
125*cdf0e10cSrcweir             {
126*cdf0e10cSrcweir                 aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MAP_100TH_MM);
127*cdf0e10cSrcweir             }
128*cdf0e10cSrcweir             else
129*cdf0e10cSrcweir             {
130*cdf0e10cSrcweir                 aPrefSize = Application::GetDefaultDevice()->LogicToLogic(aPrefSize, GetGrafObject().GetGrafPrefMapMode(), MAP_100TH_MM);
131*cdf0e10cSrcweir             }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 			// decompose object matrix to get single values
134*cdf0e10cSrcweir 			basegfx::B2DVector aScale, aTranslate;
135*cdf0e10cSrcweir 			double fRotate, fShearX;
136*cdf0e10cSrcweir 			rObjectMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 			const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
139*cdf0e10cSrcweir             const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir             if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
142*cdf0e10cSrcweir             {
143*cdf0e10cSrcweir 				// create the EmptyPresObj fallback visualisation. The fallback graphic
144*cdf0e10cSrcweir 				// is already provided in rGraphicObject in this case, use it
145*cdf0e10cSrcweir 				aSmallerMatrix = basegfx::tools::createScaleTranslateB2DHomMatrix(aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY);
146*cdf0e10cSrcweir 				aSmallerMatrix = basegfx::tools::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
147*cdf0e10cSrcweir 					* aSmallerMatrix;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 				const GraphicObject& rGraphicObject = GetGrafObject().GetGraphicObject(false);
150*cdf0e10cSrcweir                 const drawinglayer::primitive2d::Primitive2DReference xReferenceB(new drawinglayer::primitive2d::SdrGrafPrimitive2D(
151*cdf0e10cSrcweir 				    aSmallerMatrix,
152*cdf0e10cSrcweir 					drawinglayer::attribute::SdrLineFillShadowTextAttribute(),
153*cdf0e10cSrcweir 					rGraphicObject,
154*cdf0e10cSrcweir 					rLocalGrafInfo));
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir                 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, xReferenceB);
157*cdf0e10cSrcweir             }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 			return xRetval;
160*cdf0e10cSrcweir 		}
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfGraphic::createVIP2DSForDraft(
163*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rObjectMatrix,
164*cdf0e10cSrcweir 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute& rAttribute) const
165*cdf0e10cSrcweir 		{
166*cdf0e10cSrcweir 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
167*cdf0e10cSrcweir             GraphicObject aEmptyGraphicObject;
168*cdf0e10cSrcweir 			GraphicAttr	aEmptyGraphicAttr;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir             // SdrGrafPrimitive2D without content in original size which carries all eventual attributes and texts
171*cdf0e10cSrcweir             const drawinglayer::primitive2d::Primitive2DReference xReferenceA(new drawinglayer::primitive2d::SdrGrafPrimitive2D(
172*cdf0e10cSrcweir 			    rObjectMatrix,
173*cdf0e10cSrcweir 				rAttribute,
174*cdf0e10cSrcweir 				aEmptyGraphicObject,
175*cdf0e10cSrcweir 				aEmptyGraphicAttr));
176*cdf0e10cSrcweir 		    xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReferenceA, 1);
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 			if(rAttribute.getLine().isDefault())
179*cdf0e10cSrcweir 			{
180*cdf0e10cSrcweir 				// create a surrounding frame when no linestyle given
181*cdf0e10cSrcweir 		        const Color aColor(Application::GetSettings().GetStyleSettings().GetShadowColor());
182*cdf0e10cSrcweir 				const basegfx::BColor aBColor(aColor.getBColor());
183*cdf0e10cSrcweir 				basegfx::B2DPolygon aOutline(basegfx::tools::createUnitPolygon());
184*cdf0e10cSrcweir 				aOutline.transform(rObjectMatrix);
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 				drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval,
187*cdf0e10cSrcweir 					drawinglayer::primitive2d::Primitive2DReference(
188*cdf0e10cSrcweir 						new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
189*cdf0e10cSrcweir 							aOutline,
190*cdf0e10cSrcweir 							aBColor)));
191*cdf0e10cSrcweir 			}
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 			// decompose object matrix to get single values
194*cdf0e10cSrcweir 			basegfx::B2DVector aScale, aTranslate;
195*cdf0e10cSrcweir 			double fRotate, fShearX;
196*cdf0e10cSrcweir 			rObjectMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 			// define a distance value, used for distance from bitmap to borders and from bitmap
199*cdf0e10cSrcweir 			// to text, too (2 mm)
200*cdf0e10cSrcweir 			const double fDistance(200.0);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 			// consume borders from values
203*cdf0e10cSrcweir 			aScale.setX(std::max(0.0, aScale.getX() - (2.0 * fDistance)));
204*cdf0e10cSrcweir 			aScale.setY(std::max(0.0, aScale.getY() - (2.0 * fDistance)));
205*cdf0e10cSrcweir 			aTranslate.setX(aTranslate.getX() + fDistance);
206*cdf0e10cSrcweir 			aTranslate.setY(aTranslate.getY() + fDistance);
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 			// draw a draft bitmap
209*cdf0e10cSrcweir 			const Bitmap aDraftBitmap(ResId(BMAP_GrafikEi, *ImpGetResMgr()));
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 			if(!aDraftBitmap.IsEmpty())
212*cdf0e10cSrcweir 			{
213*cdf0e10cSrcweir 				Size aPrefSize(aDraftBitmap.GetPrefSize());
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 				if(MAP_PIXEL == aDraftBitmap.GetPrefMapMode().GetMapUnit())
216*cdf0e10cSrcweir 				{
217*cdf0e10cSrcweir 					aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aDraftBitmap.GetSizePixel(), MAP_100TH_MM);
218*cdf0e10cSrcweir 				}
219*cdf0e10cSrcweir 				else
220*cdf0e10cSrcweir 				{
221*cdf0e10cSrcweir 					aPrefSize = Application::GetDefaultDevice()->LogicToLogic(aPrefSize, aDraftBitmap.GetPrefMapMode(), MAP_100TH_MM);
222*cdf0e10cSrcweir 				}
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir                 const double fBitmapScaling(2.0);
225*cdf0e10cSrcweir 				const double fWidth(aPrefSize.getWidth() * fBitmapScaling);
226*cdf0e10cSrcweir 				const double fHeight(aPrefSize.getHeight() * fBitmapScaling);
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 				if(basegfx::fTools::more(fWidth, 1.0)
229*cdf0e10cSrcweir 					&& basegfx::fTools::more(fHeight, 1.0)
230*cdf0e10cSrcweir 					&& basegfx::fTools::lessOrEqual(fWidth, aScale.getX())
231*cdf0e10cSrcweir 					&& basegfx::fTools::lessOrEqual(fHeight, aScale.getY()))
232*cdf0e10cSrcweir 				{
233*cdf0e10cSrcweir 					const basegfx::B2DHomMatrix aBitmapMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
234*cdf0e10cSrcweir 						fWidth, fHeight, fShearX, fRotate, aTranslate.getX(), aTranslate.getY()));
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 					drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval,
237*cdf0e10cSrcweir 						drawinglayer::primitive2d::Primitive2DReference(
238*cdf0e10cSrcweir 							new drawinglayer::primitive2d::BitmapPrimitive2D(
239*cdf0e10cSrcweir 								BitmapEx(aDraftBitmap),
240*cdf0e10cSrcweir 								aBitmapMatrix)));
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 					// consume bitmap size in X
243*cdf0e10cSrcweir 					aScale.setX(std::max(0.0, aScale.getX() - (fWidth + fDistance)));
244*cdf0e10cSrcweir 					aTranslate.setX(aTranslate.getX() + fWidth + fDistance);
245*cdf0e10cSrcweir 				}
246*cdf0e10cSrcweir 			}
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 			// Build the text for the draft object
249*cdf0e10cSrcweir 			XubString aDraftText = GetGrafObject().GetFileName();
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 			if(!aDraftText.Len())
252*cdf0e10cSrcweir 			{
253*cdf0e10cSrcweir 				aDraftText = GetGrafObject().GetName();
254*cdf0e10cSrcweir 				aDraftText.AppendAscii(" ...");
255*cdf0e10cSrcweir 			}
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 			if(aDraftText.Len() && GetGrafObject().GetModel())
258*cdf0e10cSrcweir 			{
259*cdf0e10cSrcweir                 // #i103255# Goal is to produce TextPrimitives which hold the given text as
260*cdf0e10cSrcweir                 // BlockText in the available space. It would be very tricky to do
261*cdf0e10cSrcweir                 // an own word wrap/line layout here.
262*cdf0e10cSrcweir                 // Using SdrBlockTextPrimitive2D OTOH is critical since it internally
263*cdf0e10cSrcweir                 // uses the SdrObject it references. To solve this, create a temp
264*cdf0e10cSrcweir                 // SdrObject with Attributes and Text, generate a SdrBlockTextPrimitive2D
265*cdf0e10cSrcweir                 // directly and immediately decompose it. After that, it is no longer
266*cdf0e10cSrcweir                 // needed and can be deleted.
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir                 // create temp RectObj as TextObj and set needed attributes
269*cdf0e10cSrcweir                 SdrRectObj aRectObj(OBJ_TEXT);
270*cdf0e10cSrcweir                 aRectObj.SetModel(GetGrafObject().GetModel());
271*cdf0e10cSrcweir                 aRectObj.NbcSetText(aDraftText);
272*cdf0e10cSrcweir                 aRectObj.SetMergedItem(SvxColorItem(Color(COL_LIGHTRED), EE_CHAR_COLOR));
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir                 // get SdrText and OPO
275*cdf0e10cSrcweir                 SdrText* pSdrText = aRectObj.getText(0);
276*cdf0e10cSrcweir                 OutlinerParaObject* pOPO = aRectObj.GetOutlinerParaObject();
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir                 if(pSdrText && pOPO)
279*cdf0e10cSrcweir                 {
280*cdf0e10cSrcweir                     // directly use the remaining space as TextRangeTransform
281*cdf0e10cSrcweir 					const basegfx::B2DHomMatrix aTextRangeTransform(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
282*cdf0e10cSrcweir 						aScale, fShearX, fRotate, aTranslate));
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir                     // directly create temp SdrBlockTextPrimitive2D
285*cdf0e10cSrcweir                     drawinglayer::primitive2d::SdrBlockTextPrimitive2D aBlockTextPrimitive(
286*cdf0e10cSrcweir                         pSdrText,
287*cdf0e10cSrcweir                         *pOPO,
288*cdf0e10cSrcweir                         aTextRangeTransform,
289*cdf0e10cSrcweir                         SDRTEXTHORZADJUST_LEFT,
290*cdf0e10cSrcweir                         SDRTEXTVERTADJUST_TOP,
291*cdf0e10cSrcweir                         false,
292*cdf0e10cSrcweir                         false,
293*cdf0e10cSrcweir                         false,
294*cdf0e10cSrcweir                         false,
295*cdf0e10cSrcweir 						false);
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir                     // decompose immediately with neutral ViewInformation. This will
298*cdf0e10cSrcweir                     // layout the text to more simple TextPrimitives from drawinglayer
299*cdf0e10cSrcweir                     const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir                     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
302*cdf0e10cSrcweir                         xRetval,
303*cdf0e10cSrcweir                         aBlockTextPrimitive.get2DDecomposition(aViewInformation2D));
304*cdf0e10cSrcweir                 }
305*cdf0e10cSrcweir             }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 			return xRetval;
308*cdf0e10cSrcweir 		}
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfGraphic::createViewIndependentPrimitive2DSequence() const
311*cdf0e10cSrcweir 		{
312*cdf0e10cSrcweir 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
313*cdf0e10cSrcweir 			const SfxItemSet& rItemSet = GetGrafObject().GetMergedItemSet();
314*cdf0e10cSrcweir 			drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
315*cdf0e10cSrcweir 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
316*cdf0e10cSrcweir                     rItemSet,
317*cdf0e10cSrcweir                     GetGrafObject().getText(0)));
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 			// create and fill GraphicAttr
320*cdf0e10cSrcweir 			GraphicAttr	aLocalGrafInfo;
321*cdf0e10cSrcweir 			const sal_uInt16 nTrans(((SdrGrafTransparenceItem&)rItemSet.Get(SDRATTR_GRAFTRANSPARENCE)).GetValue());
322*cdf0e10cSrcweir 			const SdrGrafCropItem& rCrop((const SdrGrafCropItem&)rItemSet.Get(SDRATTR_GRAFCROP));
323*cdf0e10cSrcweir 			aLocalGrafInfo.SetLuminance(((SdrGrafLuminanceItem&)rItemSet.Get(SDRATTR_GRAFLUMINANCE)).GetValue());
324*cdf0e10cSrcweir 			aLocalGrafInfo.SetContrast(((SdrGrafContrastItem&)rItemSet.Get(SDRATTR_GRAFCONTRAST)).GetValue());
325*cdf0e10cSrcweir 			aLocalGrafInfo.SetChannelR(((SdrGrafRedItem&)rItemSet.Get(SDRATTR_GRAFRED)).GetValue());
326*cdf0e10cSrcweir 			aLocalGrafInfo.SetChannelG(((SdrGrafGreenItem&)rItemSet.Get(SDRATTR_GRAFGREEN)).GetValue());
327*cdf0e10cSrcweir 			aLocalGrafInfo.SetChannelB(((SdrGrafBlueItem&)rItemSet.Get(SDRATTR_GRAFBLUE)).GetValue());
328*cdf0e10cSrcweir 			aLocalGrafInfo.SetGamma(((SdrGrafGamma100Item&)rItemSet.Get(SDRATTR_GRAFGAMMA)).GetValue() * 0.01);
329*cdf0e10cSrcweir 			aLocalGrafInfo.SetTransparency((sal_uInt8)::basegfx::fround(Min(nTrans, (sal_uInt16)100) * 2.55));
330*cdf0e10cSrcweir 			aLocalGrafInfo.SetInvert(((SdrGrafInvertItem&)rItemSet.Get(SDRATTR_GRAFINVERT)).GetValue());
331*cdf0e10cSrcweir 			aLocalGrafInfo.SetDrawMode(((SdrGrafModeItem&)rItemSet.Get(SDRATTR_GRAFMODE)).GetValue());
332*cdf0e10cSrcweir 			aLocalGrafInfo.SetCrop(rCrop.GetLeft(), rCrop.GetTop(), rCrop.GetRight(), rCrop.GetBottom());
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir             if(aAttribute.isDefault() && 255L != aLocalGrafInfo.GetTransparency())
335*cdf0e10cSrcweir 			{
336*cdf0e10cSrcweir 				// no fill, no line, no text (invisible), but the graphic content is visible.
337*cdf0e10cSrcweir 				// Create evtl. shadow for content which was not created by createNewSdrLineFillShadowTextAttribute yet
338*cdf0e10cSrcweir 				const drawinglayer::attribute::SdrShadowAttribute aShadow(
339*cdf0e10cSrcweir 					drawinglayer::primitive2d::createNewSdrShadowAttribute(rItemSet));
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir                 if(!aShadow.isDefault())
342*cdf0e10cSrcweir                 {
343*cdf0e10cSrcweir 				    // create new attribute set if indeed shadow is used
344*cdf0e10cSrcweir 				    aAttribute = drawinglayer::attribute::SdrLineFillShadowTextAttribute(
345*cdf0e10cSrcweir 					    aAttribute.getLine(),
346*cdf0e10cSrcweir 					    aAttribute.getFill(),
347*cdf0e10cSrcweir 					    aAttribute.getLineStartEnd(),
348*cdf0e10cSrcweir 					    aShadow,
349*cdf0e10cSrcweir 					    aAttribute.getFillFloatTransGradient(),
350*cdf0e10cSrcweir 					    aAttribute.getText());
351*cdf0e10cSrcweir                 }
352*cdf0e10cSrcweir 			}
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 			// take unrotated snap rect for position and size. Directly use model data, not getBoundRect() or getSnapRect()
355*cdf0e10cSrcweir 			// which will use the primitive data we just create in the near future
356*cdf0e10cSrcweir 			const Rectangle& rRectangle = GetGrafObject().GetGeoRect();
357*cdf0e10cSrcweir 			const ::basegfx::B2DRange aObjectRange(
358*cdf0e10cSrcweir                 rRectangle.Left(), rRectangle.Top(),
359*cdf0e10cSrcweir                 rRectangle.Right(), rRectangle.Bottom());
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 			// look for mirroring
362*cdf0e10cSrcweir 			const GeoStat& rGeoStat(GetGrafObject().GetGeoStat());
363*cdf0e10cSrcweir 			const sal_Int32 nDrehWink(rGeoStat.nDrehWink);
364*cdf0e10cSrcweir 			const bool bRota180(18000 == nDrehWink);
365*cdf0e10cSrcweir 			const bool bMirrored(GetGrafObject().IsMirrored());
366*cdf0e10cSrcweir 			const sal_uInt16 nMirrorCase(bRota180 ? (bMirrored ? 3 : 4) : (bMirrored ? 2 : 1));
367*cdf0e10cSrcweir 			bool bHMirr((2 == nMirrorCase ) || (4 == nMirrorCase));
368*cdf0e10cSrcweir 			bool bVMirr((3 == nMirrorCase ) || (4 == nMirrorCase));
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir 			// set mirror flags at LocalGrafInfo. Take into account that the geometry in
371*cdf0e10cSrcweir 			// aObjectRange is already changed and rotated when bRota180 is used. To rebuild
372*cdf0e10cSrcweir 			// that old behaviour (as long as part of the model data), correct the H/V flags
373*cdf0e10cSrcweir 			// accordingly. The created bitmapPrimitive WILL use the rotation, too.
374*cdf0e10cSrcweir 			if(bRota180)
375*cdf0e10cSrcweir 			{
376*cdf0e10cSrcweir 				// if bRota180 which is used for vertical mirroring, the graphic will already be rotated
377*cdf0e10cSrcweir 				// by 180 degrees. To correct, switch off VMirror and invert HMirroring.
378*cdf0e10cSrcweir 				bHMirr = !bHMirr;
379*cdf0e10cSrcweir 				bVMirr = false;
380*cdf0e10cSrcweir 			}
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 			if(bHMirr || bVMirr)
383*cdf0e10cSrcweir 			{
384*cdf0e10cSrcweir 				aLocalGrafInfo.SetMirrorFlags((bHMirr ? BMP_MIRROR_HORZ : 0)|(bVMirr ? BMP_MIRROR_VERT : 0));
385*cdf0e10cSrcweir 			}
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 			// fill object matrix
388*cdf0e10cSrcweir             const double fShearX(rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0);
389*cdf0e10cSrcweir             const double fRotate(nDrehWink ? (36000 - nDrehWink) * F_PI18000 : 0.0);
390*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
391*cdf0e10cSrcweir 				aObjectRange.getWidth(), aObjectRange.getHeight(),
392*cdf0e10cSrcweir 				fShearX, fRotate,
393*cdf0e10cSrcweir 				aObjectRange.getMinX(), aObjectRange.getMinY()));
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 			// get the current, unchenged graphic obect from SdrGrafObj
396*cdf0e10cSrcweir 			const GraphicObject& rGraphicObject = GetGrafObject().GetGraphicObject(false);
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir 			if(visualisationUsesPresObj())
399*cdf0e10cSrcweir             {
400*cdf0e10cSrcweir                 // it's an EmptyPresObj, create the SdrGrafPrimitive2D without content and another scaled one
401*cdf0e10cSrcweir                 // with the content which is the placeholder graphic
402*cdf0e10cSrcweir 				xRetval = createVIP2DSForPresObj(aObjectMatrix, aAttribute, aLocalGrafInfo);
403*cdf0e10cSrcweir             }
404*cdf0e10cSrcweir             else if(visualisationUsesDraft())
405*cdf0e10cSrcweir             {
406*cdf0e10cSrcweir 			    // #i102380# The graphic is swapped out. To not force a swap-in here, there is a mechanism
407*cdf0e10cSrcweir 			    // which shows a swapped-out-visualisation (which gets created here now) and an asynchronious
408*cdf0e10cSrcweir 			    // visual update mechanism for swapped-out grapgics when they were loaded (see AsynchGraphicLoadingEvent
409*cdf0e10cSrcweir 			    // and ViewObjectContactOfGraphic implementation). Not forcing the swap-in here allows faster
410*cdf0e10cSrcweir 			    // (non-blocking) processing here and thus in the effect e.g. fast scrolling through pages
411*cdf0e10cSrcweir 			    xRetval = createVIP2DSForDraft(aObjectMatrix, aAttribute);
412*cdf0e10cSrcweir             }
413*cdf0e10cSrcweir             else
414*cdf0e10cSrcweir             {
415*cdf0e10cSrcweir 			    // create primitive. Info: Calling the copy-constructor of GraphicObject in this
416*cdf0e10cSrcweir 				// SdrGrafPrimitive2D constructor will force a full swap-in of the graphic
417*cdf0e10cSrcweir 			    const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::SdrGrafPrimitive2D(
418*cdf0e10cSrcweir 				    aObjectMatrix,
419*cdf0e10cSrcweir 					aAttribute,
420*cdf0e10cSrcweir 					rGraphicObject,
421*cdf0e10cSrcweir 					aLocalGrafInfo));
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 			    xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
424*cdf0e10cSrcweir             }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir 			// always append an invisible outline for the cases where no visible content exists
427*cdf0e10cSrcweir 			drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval,
428*cdf0e10cSrcweir 				drawinglayer::primitive2d::createHiddenGeometryPrimitives2D(
429*cdf0e10cSrcweir 					false, aObjectMatrix));
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir 			return xRetval;
432*cdf0e10cSrcweir 		}
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir         bool ViewContactOfGraphic::visualisationUsesPresObj() const
435*cdf0e10cSrcweir         {
436*cdf0e10cSrcweir             return GetGrafObject().IsEmptyPresObj();
437*cdf0e10cSrcweir         }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir         bool ViewContactOfGraphic::visualisationUsesDraft() const
440*cdf0e10cSrcweir         {
441*cdf0e10cSrcweir             // no draft when already PresObj
442*cdf0e10cSrcweir             if(visualisationUsesPresObj())
443*cdf0e10cSrcweir                 return false;
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir             // draft when swapped out
446*cdf0e10cSrcweir 			const GraphicObject& rGraphicObject = GetGrafObject().GetGraphicObject(false);
447*cdf0e10cSrcweir             static bool bAllowReplacements(true);
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir             if(rGraphicObject.IsSwappedOut() && bAllowReplacements)
450*cdf0e10cSrcweir                 return true;
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir             // draft when no graphic
453*cdf0e10cSrcweir             if(GRAPHIC_NONE == rGraphicObject.GetType() || GRAPHIC_DEFAULT == rGraphicObject.GetType())
454*cdf0e10cSrcweir                return true;
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir             return false;
457*cdf0e10cSrcweir         }
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 	} // end of namespace contact
460*cdf0e10cSrcweir } // end of namespace sdr
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
463*cdf0e10cSrcweir // eof
464