1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
28 #include <svx/svdoole2.hxx>
29 #include <svx/sdr/contact/viewobjectcontactofsdrole2obj.hxx>
30 #include <basegfx/matrix/b2dhommatrix.hxx>
31 #include <svx/sdr/primitive2d/sdrole2primitive2d.hxx>
32 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
33 #include <basegfx/polygon/b2dpolygontools.hxx>
34 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
35 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
36 #include <svtools/colorcfg.hxx>
37 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
38 #include <vcl/svapp.hxx>
39 #include <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx>
40 #include <basegfx/matrix/b2dhommatrixtools.hxx>
41 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
42 #include <svx/charthelper.hxx>
43 
44 //////////////////////////////////////////////////////////////////////////////
45 
46 namespace sdr
47 {
48 	namespace contact
49 	{
50 		// Create a Object-Specific ViewObjectContact, set ViewContact and
51 		// ObjectContact. Always needs to return something.
52 		ViewObjectContact& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
53 		{
54 			ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
55 			DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
56 
57 			return *pRetval;
58 		}
59 
60 		ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
61 		:	ViewContactOfSdrRectObj(rOle2Obj)
62 		{
63 		}
64 
65 		ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
66 		{
67 		}
68 
69         basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const
70         {
71             // take unrotated snap rect (direct model data) for position and size
72             const Rectangle& rRectangle = GetOle2Obj().GetGeoRect();
73             const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
74 
75             // create object matrix
76             const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
77             const double fShearX(rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0);
78             const double fRotate(rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0);
79 
80             return basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
81                 aObjectRange.getWidth(), aObjectRange.getHeight(),
82                 fShearX,
83                 fRotate,
84                 aObjectRange.getMinX(), aObjectRange.getMinY());
85         }
86 
87         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters(
88             bool bHighContrast) const
89         {
90             // get object transformation
91             const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
92 
93 		    // Prepare attribute settings, will be used soon anyways
94 			const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
95 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
96 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
97                     rItemSet,
98                     GetOle2Obj().getText(0)));
99             drawinglayer::primitive2d::Primitive2DReference xContent;
100 
101             if(GetOle2Obj().IsChart())
102             {
103                 // try to get chart primitives and chart range directly from xChartModel
104                 basegfx::B2DRange aChartContentRange;
105                 const drawinglayer::primitive2d::Primitive2DSequence aChartSequence(
106                     ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
107                         GetOle2Obj().getXModel(),
108                         aChartContentRange));
109                 const double fWidth(aChartContentRange.getWidth());
110                 const double fHeight(aChartContentRange.getHeight());
111 
112                 if(aChartSequence.hasElements()
113                     && basegfx::fTools::more(fWidth, 0.0)
114                     && basegfx::fTools::more(fHeight, 0.0))
115                 {
116                     // create embedding transformation
117                     basegfx::B2DHomMatrix aEmbed(
118                         basegfx::tools::createTranslateB2DHomMatrix(
119                             -aChartContentRange.getMinX(),
120                             -aChartContentRange.getMinY()));
121 
122                     aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
123                     aEmbed = aObjectMatrix * aEmbed;
124                     xContent = new drawinglayer::primitive2d::TransformPrimitive2D(
125                         aEmbed,
126                         aChartSequence);
127                 }
128             }
129 
130             if(!xContent.is())
131             {
132                 // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
133                 // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
134                 // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
135                 // It will also take care of HighContrast and ScaleContent
136                 xContent = new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
137                     GetOle2Obj(),
138                     aObjectMatrix,
139 
140                     // #i104867# add GraphicVersion number to be able to check for
141                     // content change in the primitive later
142                     GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion(),
143 
144                     bHighContrast);
145             }
146 
147             // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
148 			// be used soon anyways. Always create primitives to allow the decomposition of
149 			// SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
150             const drawinglayer::primitive2d::Primitive2DReference xReference(
151                 new drawinglayer::primitive2d::SdrOle2Primitive2D(
152 			        drawinglayer::primitive2d::Primitive2DSequence(&xContent, 1),
153 			        aObjectMatrix,
154 			        aAttribute));
155 
156 			return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
157         }
158 
159 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const
160 		{
161             // do as if no HC and call standard creator
162             return createPrimitive2DSequenceWithParameters(false);
163 		}
164 	} // end of namespace contact
165 } // end of namespace sdr
166 
167 //////////////////////////////////////////////////////////////////////////////
168 // eof
169