LibreOffice Module svx (master)  1
viewcontactofsdrole2obj.cxx
Go to the documentation of this file.
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 
22 #include <svx/svdoole2.hxx>
27 #include <vcl/canvastools.hxx>
28 #include <tools/debug.hxx>
32 #include <svx/charthelper.hxx>
33 #include <svtools/embedhlp.hxx>
34 
35 namespace sdr::contact {
36 
37 // Create an Object-Specific ViewObjectContact, set ViewContact and
38 // ObjectContact. Always needs to return something.
40 {
41  ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
42  DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
43 
44  return *pRetval;
45 }
46 
48 : ViewContactOfSdrRectObj(rOle2Obj),
49  mxChartContent()
50 {
51 }
52 
54 {
55 }
56 
58 {
59  // take unrotated snap rect (direct model data) for position and size
60  const tools::Rectangle aRectangle(GetOle2Obj().GetGeoRect());
61  const basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(aRectangle);
62 
63  // create object matrix
64  const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
65  const double fShearX(rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0);
66  const double fRotate(rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0);
67 
69  aObjectRange.getWidth(), aObjectRange.getHeight(),
70  fShearX,
71  fRotate,
72  aObjectRange.getMinX(), aObjectRange.getMinY());
73 }
74 
76 {
77  // get object transformation
78  const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
79 
80  // Prepare attribute settings, will be used soon anyways
81  const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
82 
83  // this may be refined more granular; if no content, attributes may get simpler
86  rItemSet,
87  GetOle2Obj().getText(0),
88  true));
90 
91  if(GetOle2Obj().IsChart())
92  {
93  // #i123539# allow buffering and reuse of local chart data to not need to rebuild it
94  // on every ViewObjectContact::getPrimitive2DSequence call. TTTT: Not needed for
95  // aw080, there this mechanism already works differently
96  if(mxChartContent.is())
97  {
98  xContent = mxChartContent;
99  }
100  else
101  {
102  // try to get chart primitives and chart range directly from xChartModel
103  basegfx::B2DRange aChartContentRange;
106  GetOle2Obj().getXModel(),
107  aChartContentRange));
108  const double fWidth(aChartContentRange.getWidth());
109  const double fHeight(aChartContentRange.getHeight());
110 
111  if(!aChartSequence.empty()
112  && basegfx::fTools::more(fWidth, 0.0)
113  && basegfx::fTools::more(fHeight, 0.0))
114  {
115  // create embedding transformation
116  basegfx::B2DHomMatrix aEmbed(
118  -aChartContentRange.getMinX(),
119  -aChartContentRange.getMinY()));
120 
121  aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
122  aEmbed = aObjectMatrix * aEmbed;
124  aEmbed,
125  aChartSequence);
126  }
127 
128  if(xContent.is())
129  {
130  const_cast< ViewContactOfSdrOle2Obj* >(this)->mxChartContent = xContent;
131  }
132  }
133  }
134 
135  if(!xContent.is())
136  {
137  // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
138  // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
139  // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
140  // It will also take care of HighContrast and ScaleContent
142  GetOle2Obj(),
143  aObjectMatrix,
144 
145  // #i104867# add GraphicVersion number to be able to check for
146  // content change in the primitive later
147  GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion() );
148  }
149 
150  // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
151  // be used soon anyways. Always create primitives to allow the decomposition of
152  // SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
156  aObjectMatrix,
157  aAttribute));
158 
160 }
161 
163 {
164  // this may be refined more granular; if no content, attributes may get simpler
167  GetOle2Obj().GetMergedItemSet(),
168  GetOle2Obj().getText(0),
169  true);
170 
172 
175  GetOle2Obj(),
176  aObjectMatrix,
177  GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion());
178 
182  aObjectMatrix,
183  aAttribute));
184 
186 }
187 
189 {
190  // call parent
192 
193  // #i123539# if we have buffered chart data, reset it
194  if(mxChartContent.is())
195  {
196  mxChartContent.clear();
197  }
198 }
199 
201 {
203 }
204 
205 }
206 
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double getHeight() const
static bool more(const double &rfValA, const double &rfValB)
long nRotationAngle
Definition: svdtrans.hxx:216
drawinglayer::primitive2d::Primitive2DReference mxChartContent
double getWidth() const
static drawinglayer::primitive2d::Primitive2DContainer tryToGetChartContentAsPrimitive2DSequence(const css::uno::Reference< css::frame::XModel > &rXModel, basegfx::B2DRange &rRange)
Definition: charthelper.cxx:54
B2DHomMatrix createScaleShearXRotateTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
Definition: svdtrans.hxx:214
virtual ViewObjectContact & CreateObjectSpecificViewObjectContact(ObjectContact &rObjectContact) override
drawinglayer::primitive2d::Primitive2DContainer createPrimitive2DSequenceWithParameters() const
attribute::SdrLineFillShadowTextAttribute createNewSdrLineFillShadowTextAttribute(const SfxItemSet &rSet, const SdrText *pText, bool bHasContent)
#define DBG_ASSERT(sCon, aError)
void scale(double fX, double fY)
basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference &rCandidate, const geometry::ViewInformation2D &aViewInformation)
Reference< XModel > getXModel(const Reference< XInterface > &_rxComponent)
long nShearAngle
Definition: svdtrans.hxx:217
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
double getMinY() const
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1883
#define F_PI18000
virtual drawinglayer::primitive2d::Primitive2DContainer createViewIndependentPrimitive2DSequence() const override
uno::Reference< ucb::XContent > xContent
double getMinX() const
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
virtual basegfx::B2DRange getRange(const drawinglayer::geometry::ViewInformation2D &rViewInfo2D) const override
basegfx::B2DHomMatrix createObjectTransform() const
helper to create transformation from SdrObject