1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawinglayer/primitive2d/Tools.hxx>
21 #include <sdr/contact/viewcontactofsdrole2obj.hxx>
22 #include <svx/svdoole2.hxx>
23 #include <sdr/contact/viewobjectcontactofsdrole2obj.hxx>
24 #include <basegfx/matrix/b2dhommatrix.hxx>
25 #include <sdr/primitive2d/sdrole2primitive2d.hxx>
26 #include <sdr/primitive2d/sdrattributecreator.hxx>
27 #include <vcl/canvastools.hxx>
28 #include <tools/debug.hxx>
29 #include <sdr/primitive2d/sdrolecontentprimitive2d.hxx>
30 #include <basegfx/matrix/b2dhommatrixtools.hxx>
31 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
32 #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
33 #include <svx/charthelper.hxx>
34 #include <svtools/embedhlp.hxx>
36 namespace sdr::contact
{
38 // Create an Object-Specific ViewObjectContact, set ViewContact and
39 // ObjectContact. Always needs to return something.
40 ViewObjectContact
& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact
& rObjectContact
)
42 ViewObjectContact
* pRetval
= new ViewObjectContactOfSdrOle2Obj(rObjectContact
, *this);
43 DBG_ASSERT(pRetval
, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
48 ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj
& rOle2Obj
)
49 : ViewContactOfSdrRectObj(rOle2Obj
)
53 ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
57 basegfx::B2DHomMatrix
ViewContactOfSdrOle2Obj::createObjectTransform() const
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
);
63 // create object matrix
64 const GeoStat
& rGeoStat(GetOle2Obj().GetGeoStat());
65 const double fShearX(-rGeoStat
.mfTanShearAngle
);
66 const double fRotate(rGeoStat
.m_nRotationAngle
? toRadians(36000_deg100
- rGeoStat
.m_nRotationAngle
) : 0.0);
68 return basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
69 aObjectRange
.getWidth(), aObjectRange
.getHeight(),
72 aObjectRange
.getMinX(), aObjectRange
.getMinY());
75 void ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters(drawinglayer::primitive2d::Primitive2DDecompositionVisitor
& rVisitor
) const
77 // get object transformation
78 const basegfx::B2DHomMatrix
aObjectMatrix(createObjectTransform());
80 // Prepare attribute settings, will be used soon anyways
81 const SfxItemSet
& rItemSet
= GetOle2Obj().GetMergedItemSet();
83 // this may be refined more granular; if no content, attributes may get simpler
84 const drawinglayer::attribute::SdrLineFillEffectsTextAttribute
aAttribute(
85 drawinglayer::primitive2d::createNewSdrLineFillEffectsTextAttribute(
87 GetOle2Obj().getText(0),
89 drawinglayer::primitive2d::Primitive2DContainer xContent
;
91 if(GetOle2Obj().IsChart())
93 // try to get chart primitives and chart range directly from xChartModel
94 basegfx::B2DRange aChartContentRange
;
95 drawinglayer::primitive2d::Primitive2DContainer
aChartSequence(
96 ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
97 GetOle2Obj().getXModel(),
99 const double fWidth(aChartContentRange
.getWidth());
100 const double fHeight(aChartContentRange
.getHeight());
102 if(!aChartSequence
.empty() && fWidth
> 0.0 && fHeight
> 0.0)
104 // create embedding transformation
105 basegfx::B2DHomMatrix
aEmbed(
106 basegfx::utils::createTranslateB2DHomMatrix(
107 -aChartContentRange
.getMinX(),
108 -aChartContentRange
.getMinY()));
110 aEmbed
.scale(1.0 / fWidth
, 1.0 / fHeight
);
111 aEmbed
= aObjectMatrix
* aEmbed
;
112 xContent
= drawinglayer::primitive2d::Primitive2DContainer
{
113 new drawinglayer::primitive2d::TransformPrimitive2D(aEmbed
,
114 std::move(aChartSequence
))
121 // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
122 // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
123 // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
124 // It will also take care of HighContrast and ScaleContent
125 xContent
= drawinglayer::primitive2d::Primitive2DContainer
{
126 new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
127 GetOle2Obj(), aObjectMatrix
,
129 // #i104867# add GraphicVersion number to be able to check for
130 // content change in the primitive later
131 GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion())
135 if (!GetOle2Obj().GetName().isEmpty() || !GetOle2Obj().GetTitle().isEmpty()
136 || !GetOle2Obj().GetDescription().isEmpty())
138 xContent
= drawinglayer::primitive2d::Primitive2DContainer
{
139 new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
140 std::move(xContent
), GetOle2Obj().GetName(), GetOle2Obj().GetTitle(),
141 GetOle2Obj().GetDescription())
145 // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
146 // be used soon anyways. Always create primitives to allow the decomposition of
147 // SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
148 const drawinglayer::primitive2d::Primitive2DReference
xReference(
149 new drawinglayer::primitive2d::SdrOle2Primitive2D(
154 rVisitor
.visit(xReference
);
157 basegfx::B2DRange
ViewContactOfSdrOle2Obj::getRange( const drawinglayer::geometry::ViewInformation2D
& rViewInfo2D
) const
159 // this may be refined more granular; if no content, attributes may get simpler
160 const drawinglayer::attribute::SdrLineFillEffectsTextAttribute aAttribute
=
161 drawinglayer::primitive2d::createNewSdrLineFillEffectsTextAttribute(
162 GetOle2Obj().GetMergedItemSet(),
163 GetOle2Obj().getText(0),
166 basegfx::B2DHomMatrix aObjectMatrix
= createObjectTransform();
168 const drawinglayer::primitive2d::Primitive2DReference
xReference(
169 new drawinglayer::primitive2d::SdrOle2Primitive2D(
170 drawinglayer::primitive2d::Primitive2DContainer
{
171 new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
174 GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion())
179 return drawinglayer::primitive2d::getB2DRangeFromPrimitive2DReference(xReference
, rViewInfo2D
);
182 void ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DDecompositionVisitor
& rVisitor
) const
184 createPrimitive2DSequenceWithParameters(rVisitor
);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */