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 
31 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <svx/sdr/contact/viewobjectcontactofsdrole2obj.hxx>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <svx/sdr/primitive2d/sdrole2primitive2d.hxx>
36 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
37 #include <basegfx/polygon/b2dpolygontools.hxx>
38 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
39 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
40 #include <svtools/colorcfg.hxx>
41 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
42 #include <vcl/svapp.hxx>
43 #include <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx>
44 #include <basegfx/matrix/b2dhommatrixtools.hxx>
45 
46 //////////////////////////////////////////////////////////////////////////////
47 
48 namespace sdr
49 {
50 	namespace contact
51 	{
52 		// Create a Object-Specific ViewObjectContact, set ViewContact and
53 		// ObjectContact. Always needs to return something.
54 		ViewObjectContact& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
55 		{
56 			ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
57 			DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
58 
59 			return *pRetval;
60 		}
61 
62 		ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
63 		:	ViewContactOfSdrRectObj(rOle2Obj)
64 		{
65 		}
66 
67 		ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
68 		{
69 		}
70 
71         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters(
72             bool bHighContrast) const
73         {
74             // take unrotated snap rect (direct model data) for position and size
75 		    const Rectangle& rRectangle = GetOle2Obj().GetGeoRect();
76 		    const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
77 
78 		    // create object matrix
79 		    const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
80             const double fShearX(rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0);
81             const double fRotate(rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0);
82 			const basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
83 				aObjectRange.getWidth(), aObjectRange.getHeight(), fShearX, fRotate,
84 				aObjectRange.getMinX(), aObjectRange.getMinY()));
85 
86 		    // Prepare attribute settings, will be used soon anyways
87 			const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
88 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
89 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
90                     rItemSet,
91                     GetOle2Obj().getText(0)));
92 
93             // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
94             // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
95             // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
96             // It will also take care of HighContrast and ScaleContent
97             const drawinglayer::primitive2d::Primitive2DReference xOleContent(
98                 new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
99                     GetOle2Obj(),
100                     aObjectMatrix,
101 
102                     // #i104867# add GraphicVersion number to be able to check for
103                     // content change in the primitive later
104                     GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion(),
105 
106                     bHighContrast));
107 
108             // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
109 			// be used soon anyways. Always create primitives to allow the decomposition of
110 			// SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
111             const drawinglayer::primitive2d::Primitive2DSequence xOLEContent(&xOleContent, 1);
112             const drawinglayer::primitive2d::Primitive2DReference xReference(
113                 new drawinglayer::primitive2d::SdrOle2Primitive2D(
114 			        xOLEContent,
115 			        aObjectMatrix,
116 			        aAttribute));
117 
118 			return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
119         }
120 
121 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const
122 		{
123             // do as if no HC and call standard creator
124             return createPrimitive2DSequenceWithParameters(false);
125 		}
126 	} // end of namespace contact
127 } // end of namespace sdr
128 
129 //////////////////////////////////////////////////////////////////////////////
130 // eof
131