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