Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sdr/contact/viewcontactofsdrole2obj.hxx>
21 : #include <svx/svdoole2.hxx>
22 : #include <sdr/contact/viewobjectcontactofsdrole2obj.hxx>
23 : #include <basegfx/matrix/b2dhommatrix.hxx>
24 : #include <sdr/primitive2d/sdrole2primitive2d.hxx>
25 : #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
26 : #include <basegfx/polygon/b2dpolygontools.hxx>
27 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
28 : #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
29 : #include <svtools/colorcfg.hxx>
30 : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
31 : #include <vcl/svapp.hxx>
32 : #include <sdr/primitive2d/sdrolecontentprimitive2d.hxx>
33 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
34 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
35 : #include <svx/charthelper.hxx>
36 : #include <svtools/embedhlp.hxx>
37 :
38 : namespace sdr { namespace contact {
39 :
40 : // Create a Object-Specific ViewObjectContact, set ViewContact and
41 : // ObjectContact. Always needs to return something.
42 13 : ViewObjectContact& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
43 : {
44 13 : ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
45 : DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
46 :
47 13 : return *pRetval;
48 : }
49 :
50 296 : ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
51 : : ViewContactOfSdrRectObj(rOle2Obj),
52 296 : mxChartContent()
53 : {
54 296 : }
55 :
56 592 : ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
57 : {
58 592 : }
59 :
60 481 : basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const
61 : {
62 : // take unrotated snap rect (direct model data) for position and size
63 481 : Rectangle rRectangle = GetOle2Obj().GetGeoRect();
64 : // Hack for calc, transform position of object according
65 : // to current zoom so as objects relative position to grid
66 : // appears stable
67 481 : rRectangle += GetOle2Obj().GetGridOffset();
68 481 : const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
69 :
70 : // create object matrix
71 481 : const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
72 481 : const double fShearX(rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0);
73 481 : const double fRotate(rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0);
74 :
75 : return basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
76 : aObjectRange.getWidth(), aObjectRange.getHeight(),
77 : fShearX,
78 : fRotate,
79 481 : aObjectRange.getMinX(), aObjectRange.getMinY());
80 : }
81 :
82 347 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters() const
83 : {
84 : // get object transformation
85 347 : const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
86 :
87 : // Prepare attribute settings, will be used soon anyways
88 347 : const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
89 :
90 : // this may be refined more granular; if no content, attributes may get simpler
91 : const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
92 : drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
93 : rItemSet,
94 694 : GetOle2Obj().getText(0),
95 1041 : true));
96 694 : drawinglayer::primitive2d::Primitive2DReference xContent;
97 :
98 347 : if(GetOle2Obj().IsChart())
99 : {
100 : // #i123539# allow buffering and reuse of local chart data to not need to rebuild it
101 : // on every ViewObjectContact::getPrimitive2DSequence call. TTTT: No tneeded for
102 : // aw080, there this mechanism alraedy works differently
103 214 : if(mxChartContent.is())
104 : {
105 14 : xContent = mxChartContent;
106 : }
107 : else
108 : {
109 : // try to get chart primitives and chart range directly from xChartModel
110 200 : basegfx::B2DRange aChartContentRange;
111 : const drawinglayer::primitive2d::Primitive2DSequence aChartSequence(
112 : ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
113 200 : GetOle2Obj().getXModel(),
114 200 : aChartContentRange));
115 200 : const double fWidth(aChartContentRange.getWidth());
116 200 : const double fHeight(aChartContentRange.getHeight());
117 :
118 604 : if(aChartSequence.hasElements()
119 592 : && basegfx::fTools::more(fWidth, 0.0)
120 796 : && basegfx::fTools::more(fHeight, 0.0))
121 : {
122 : // create embedding transformation
123 : basegfx::B2DHomMatrix aEmbed(
124 : basegfx::tools::createTranslateB2DHomMatrix(
125 196 : -aChartContentRange.getMinX(),
126 392 : -aChartContentRange.getMinY()));
127 :
128 196 : aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
129 196 : aEmbed = aObjectMatrix * aEmbed;
130 392 : xContent = new drawinglayer::primitive2d::TransformPrimitive2D(
131 : aEmbed,
132 392 : aChartSequence);
133 : }
134 :
135 200 : if(xContent.is())
136 : {
137 196 : const_cast< ViewContactOfSdrOle2Obj* >(this)->mxChartContent = xContent;
138 200 : }
139 : }
140 : }
141 :
142 347 : if(!xContent.is())
143 : {
144 : // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
145 : // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
146 : // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
147 : // It will also take care of HighContrast and ScaleContent
148 411 : xContent = new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
149 : GetOle2Obj(),
150 : aObjectMatrix,
151 :
152 : // #i104867# add GraphicVersion number to be able to check for
153 : // content change in the primitive later
154 411 : GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion() );
155 : }
156 :
157 : // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
158 : // be used soon anyways. Always create primitives to allow the decomposition of
159 : // SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
160 : const drawinglayer::primitive2d::Primitive2DReference xReference(
161 : new drawinglayer::primitive2d::SdrOle2Primitive2D(
162 : drawinglayer::primitive2d::Primitive2DSequence(&xContent, 1),
163 : aObjectMatrix,
164 694 : aAttribute));
165 :
166 694 : return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
167 : }
168 :
169 134 : basegfx::B2DRange ViewContactOfSdrOle2Obj::getRange( const drawinglayer::geometry::ViewInformation2D& rViewInfo2D ) const
170 : {
171 : // this may be refined more granular; if no content, attributes may get simpler
172 : const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute =
173 : drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
174 134 : GetOle2Obj().GetMergedItemSet(),
175 268 : GetOle2Obj().getText(0),
176 268 : true);
177 :
178 268 : basegfx::B2DHomMatrix aObjectMatrix = createObjectTransform();
179 :
180 : drawinglayer::primitive2d::Primitive2DReference xContent =
181 : new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
182 : GetOle2Obj(),
183 : aObjectMatrix,
184 268 : GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion());
185 :
186 : const drawinglayer::primitive2d::Primitive2DReference xReference(
187 : new drawinglayer::primitive2d::SdrOle2Primitive2D(
188 : drawinglayer::primitive2d::Primitive2DSequence(&xContent, 1),
189 : aObjectMatrix,
190 268 : aAttribute));
191 :
192 : drawinglayer::primitive2d::Primitive2DSequence xSeq =
193 268 : drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
194 :
195 268 : return drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(xSeq, rViewInfo2D);
196 : }
197 :
198 3925 : void ViewContactOfSdrOle2Obj::ActionChanged()
199 : {
200 : // call parent
201 3925 : ViewContactOfSdrRectObj::ActionChanged();
202 :
203 : // #i123539# if we have buffered chart data, reset it
204 3925 : if(mxChartContent.is())
205 : {
206 113 : mxChartContent.clear();
207 : }
208 3925 : }
209 :
210 285 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const
211 : {
212 285 : return createPrimitive2DSequenceWithParameters();
213 : }
214 :
215 435 : }}
216 :
217 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|