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.
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)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 
ViewContactOfSdrOle2Obj(SdrOle2Obj & rOle2Obj)60 		ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
61 		:	ViewContactOfSdrRectObj(rOle2Obj),
62             mxChartContent()
63 		{
64 		}
65 
~ViewContactOfSdrOle2Obj()66 		ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
67 		{
68 		}
69 
createObjectTransform() const70         basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const
71         {
72             // take unrotated snap rect (direct model data) for position and size
73             const Rectangle& rRectangle = GetOle2Obj().GetGeoRect();
74             const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
75 
76             // create object matrix
77             const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
78             const double fShearX(rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0);
79             const double fRotate(rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0);
80 
81             return basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
82                 aObjectRange.getWidth(), aObjectRange.getHeight(),
83                 fShearX,
84                 fRotate,
85                 aObjectRange.getMinX(), aObjectRange.getMinY());
86         }
87 
createPrimitive2DSequenceWithParameters(bool bHighContrast) const88         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters(
89             bool bHighContrast) const
90         {
91             // get object transformation
92             const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
93 
94 		    // Prepare attribute settings, will be used soon anyways
95 			const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
96 
97             // this may be refined more granular; if no content, attributes may get simpler
98             const bool bHasContent(true);
99 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
100 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
101                     rItemSet,
102                     GetOle2Obj().getText(0),
103                     bHasContent));
104             drawinglayer::primitive2d::Primitive2DReference xContent;
105 
106             if(GetOle2Obj().IsChart())
107             {
108                 // #123539# allow buffering and reuse of local chart data to not need to rebuild it
109                 // on every ViewObjectContact::getPrimitive2DSequence call. TTTT: No tneeded for
110                 // aw080, there this mechanism alraedy works differently
111                 if(mxChartContent.is())
112                 {
113                     xContent = mxChartContent;
114                 }
115                 else
116                 {
117                     // try to get chart primitives and chart range directly from xChartModel
118                     basegfx::B2DRange aChartContentRange;
119                     const drawinglayer::primitive2d::Primitive2DSequence aChartSequence(
120                         ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
121                             GetOle2Obj().getXModel(),
122                             aChartContentRange));
123                     const double fWidth(aChartContentRange.getWidth());
124                     const double fHeight(aChartContentRange.getHeight());
125 
126                     if(aChartSequence.hasElements()
127                         && basegfx::fTools::more(fWidth, 0.0)
128                         && basegfx::fTools::more(fHeight, 0.0))
129                     {
130                         // create embedding transformation
131                         basegfx::B2DHomMatrix aEmbed(
132                             basegfx::tools::createTranslateB2DHomMatrix(
133                                 -aChartContentRange.getMinX(),
134                                 -aChartContentRange.getMinY()));
135 
136                         aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
137                         aEmbed = aObjectMatrix * aEmbed;
138                         xContent = new drawinglayer::primitive2d::TransformPrimitive2D(
139                             aEmbed,
140                             aChartSequence);
141                     }
142 
143                     if(xContent.is())
144                     {
145                         const_cast< ViewContactOfSdrOle2Obj* >(this)->mxChartContent = xContent;
146                     }
147                 }
148             }
149 
150             if(!xContent.is())
151             {
152                 // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
153                 // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
154                 // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
155                 // It will also take care of HighContrast and ScaleContent
156                 xContent = new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
157                     GetOle2Obj(),
158                     aObjectMatrix,
159 
160                     // #i104867# add GraphicVersion number to be able to check for
161                     // content change in the primitive later
162                     GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion(),
163 
164                     bHighContrast);
165             }
166 
167             // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
168 			// be used soon anyways. Always create primitives to allow the decomposition of
169 			// SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
170             const drawinglayer::primitive2d::Primitive2DReference xReference(
171                 new drawinglayer::primitive2d::SdrOle2Primitive2D(
172 			        drawinglayer::primitive2d::Primitive2DSequence(&xContent, 1),
173 			        aObjectMatrix,
174 			        aAttribute));
175 
176 			return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
177         }
178 
ActionChanged()179         void ViewContactOfSdrOle2Obj::ActionChanged()
180         {
181             // call parent
182             ViewContactOfSdrRectObj::ActionChanged();
183 
184             // #123539# if we have buffered chart data, reset it
185             if(mxChartContent.is())
186             {
187                 mxChartContent.clear();
188             }
189         }
190 
createViewIndependentPrimitive2DSequence() const191 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const
192 		{
193             // do as if no HC and call standard creator
194             return createPrimitive2DSequenceWithParameters(false);
195 		}
196 	} // end of namespace contact
197 } // end of namespace sdr
198 
199 //////////////////////////////////////////////////////////////////////////////
200 // eof
201