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>
30 #include <svtools/colorcfg.hxx>
32 #include <vcl/canvastools.hxx>
33 #include <vcl/svapp.hxx>
34 #include <tools/debug.hxx>
38 #include <svx/charthelper.hxx>
39 #include <svtools/embedhlp.hxx>
40 
41 namespace sdr { namespace contact {
42 
43 // Create an Object-Specific ViewObjectContact, set ViewContact and
44 // ObjectContact. Always needs to return something.
46 {
47  ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
48  DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
49 
50  return *pRetval;
51 }
52 
54 : ViewContactOfSdrRectObj(rOle2Obj),
55  mxChartContent()
56 {
57 }
58 
60 {
61 }
62 
64 {
65  // take unrotated snap rect (direct model data) for position and size
66  const tools::Rectangle aRectangle(GetOle2Obj().GetGeoRect());
67  const basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(aRectangle);
68 
69  // create object matrix
70  const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
71  const double fShearX(rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0);
72  const double fRotate(rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0);
73 
75  aObjectRange.getWidth(), aObjectRange.getHeight(),
76  fShearX,
77  fRotate,
78  aObjectRange.getMinX(), aObjectRange.getMinY());
79 }
80 
82 {
83  // get object transformation
84  const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
85 
86  // Prepare attribute settings, will be used soon anyways
87  const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
88 
89  // this may be refined more granular; if no content, attributes may get simpler
92  rItemSet,
93  GetOle2Obj().getText(0),
94  true));
96 
97  if(GetOle2Obj().IsChart())
98  {
99  // #i123539# allow buffering and reuse of local chart data to not need to rebuild it
100  // on every ViewObjectContact::getPrimitive2DSequence call. TTTT: Not needed for
101  // aw080, there this mechanism already works differently
102  if(mxChartContent.is())
103  {
104  xContent = mxChartContent;
105  }
106  else
107  {
108  // try to get chart primitives and chart range directly from xChartModel
109  basegfx::B2DRange aChartContentRange;
112  GetOle2Obj().getXModel(),
113  aChartContentRange));
114  const double fWidth(aChartContentRange.getWidth());
115  const double fHeight(aChartContentRange.getHeight());
116 
117  if(!aChartSequence.empty()
118  && basegfx::fTools::more(fWidth, 0.0)
119  && basegfx::fTools::more(fHeight, 0.0))
120  {
121  // create embedding transformation
122  basegfx::B2DHomMatrix aEmbed(
124  -aChartContentRange.getMinX(),
125  -aChartContentRange.getMinY()));
126 
127  aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
128  aEmbed = aObjectMatrix * aEmbed;
130  aEmbed,
131  aChartSequence);
132  }
133 
134  if(xContent.is())
135  {
136  const_cast< ViewContactOfSdrOle2Obj* >(this)->mxChartContent = xContent;
137  }
138  }
139  }
140 
141  if(!xContent.is())
142  {
143  // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
144  // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
145  // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
146  // It will also take care of HighContrast and ScaleContent
148  GetOle2Obj(),
149  aObjectMatrix,
150 
151  // #i104867# add GraphicVersion number to be able to check for
152  // content change in the primitive later
153  GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion() );
154  }
155 
156  // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
157  // be used soon anyways. Always create primitives to allow the decomposition of
158  // SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
162  aObjectMatrix,
163  aAttribute));
164 
166 }
167 
169 {
170  // this may be refined more granular; if no content, attributes may get simpler
173  GetOle2Obj().GetMergedItemSet(),
174  GetOle2Obj().getText(0),
175  true);
176 
178 
181  GetOle2Obj(),
182  aObjectMatrix,
183  GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion());
184 
188  aObjectMatrix,
189  aAttribute));
190 
192 }
193 
195 {
196  // call parent
198 
199  // #i123539# if we have buffered chart data, reset it
200  if(mxChartContent.is())
201  {
202  mxChartContent.clear();
203  }
204 }
205 
207 {
209 }
210 
211 }}
212 
213 /* 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:58
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:1911
#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