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 <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
21 : #include <svx/svdoole2.hxx>
22 : #include <svx/sdr/contact/viewobjectcontactofsdrole2obj.hxx>
23 : #include <basegfx/matrix/b2dhommatrix.hxx>
24 : #include <svx/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 <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx>
33 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
34 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
35 : #include <svx/charthelper.hxx>
36 :
37 :
38 :
39 : namespace sdr
40 : {
41 : namespace contact
42 : {
43 : // Create a Object-Specific ViewObjectContact, set ViewContact and
44 : // ObjectContact. Always needs to return something.
45 0 : ViewObjectContact& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
46 : {
47 0 : ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
48 : DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
49 :
50 0 : return *pRetval;
51 : }
52 :
53 0 : ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
54 : : ViewContactOfSdrRectObj(rOle2Obj),
55 0 : mxChartContent()
56 : {
57 0 : }
58 :
59 0 : ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
60 : {
61 0 : }
62 :
63 0 : basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const
64 : {
65 : // take unrotated snap rect (direct model data) for position and size
66 0 : Rectangle rRectangle = GetOle2Obj().GetGeoRect();
67 : // Hack for calc, transform position of object according
68 : // to current zoom so as objects relative position to grid
69 : // appears stable
70 0 : rRectangle += GetOle2Obj().GetGridOffset();
71 0 : const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
72 :
73 : // create object matrix
74 0 : const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
75 0 : const double fShearX(rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0);
76 0 : const double fRotate(rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0);
77 :
78 : return basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
79 : aObjectRange.getWidth(), aObjectRange.getHeight(),
80 : fShearX,
81 : fRotate,
82 0 : aObjectRange.getMinX(), aObjectRange.getMinY());
83 : }
84 :
85 0 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters() const
86 : {
87 : // get object transformation
88 0 : const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
89 :
90 : // Prepare attribute settings, will be used soon anyways
91 0 : const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
92 :
93 : // this may be refined more granular; if no content, attributes may get simpler
94 0 : const bool bHasContent(true);
95 : const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
96 : drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
97 : rItemSet,
98 0 : GetOle2Obj().getText(0),
99 0 : bHasContent));
100 0 : drawinglayer::primitive2d::Primitive2DReference xContent;
101 :
102 0 : if(GetOle2Obj().IsChart())
103 : {
104 : // #i123539# allow buffering and reuse of local chart data to not need to rebuild it
105 : // on every ViewObjectContact::getPrimitive2DSequence call. TTTT: No tneeded for
106 : // aw080, there this mechanism alraedy works differently
107 0 : if(mxChartContent.is())
108 : {
109 0 : xContent = mxChartContent;
110 : }
111 : else
112 : {
113 : // try to get chart primitives and chart range directly from xChartModel
114 0 : basegfx::B2DRange aChartContentRange;
115 : const drawinglayer::primitive2d::Primitive2DSequence aChartSequence(
116 : ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
117 0 : GetOle2Obj().getXModel(),
118 0 : aChartContentRange));
119 0 : const double fWidth(aChartContentRange.getWidth());
120 0 : const double fHeight(aChartContentRange.getHeight());
121 :
122 0 : if(aChartSequence.hasElements()
123 0 : && basegfx::fTools::more(fWidth, 0.0)
124 0 : && basegfx::fTools::more(fHeight, 0.0))
125 : {
126 : // create embedding transformation
127 : basegfx::B2DHomMatrix aEmbed(
128 : basegfx::tools::createTranslateB2DHomMatrix(
129 0 : -aChartContentRange.getMinX(),
130 0 : -aChartContentRange.getMinY()));
131 :
132 0 : aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
133 0 : aEmbed = aObjectMatrix * aEmbed;
134 0 : xContent = new drawinglayer::primitive2d::TransformPrimitive2D(
135 : aEmbed,
136 0 : aChartSequence);
137 : }
138 :
139 0 : if(xContent.is())
140 : {
141 0 : const_cast< ViewContactOfSdrOle2Obj* >(this)->mxChartContent = xContent;
142 0 : }
143 : }
144 : }
145 :
146 0 : if(!xContent.is())
147 : {
148 : // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
149 : // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
150 : // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
151 : // It will also take care of HighContrast and ScaleContent
152 0 : xContent = new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
153 : GetOle2Obj(),
154 : aObjectMatrix,
155 :
156 : // #i104867# add GraphicVersion number to be able to check for
157 : // content change in the primitive later
158 0 : GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion() );
159 : }
160 :
161 : // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
162 : // be used soon anyways. Always create primitives to allow the decomposition of
163 : // SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
164 : const drawinglayer::primitive2d::Primitive2DReference xReference(
165 : new drawinglayer::primitive2d::SdrOle2Primitive2D(
166 : drawinglayer::primitive2d::Primitive2DSequence(&xContent, 1),
167 : aObjectMatrix,
168 0 : aAttribute));
169 :
170 0 : return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
171 : }
172 :
173 0 : void ViewContactOfSdrOle2Obj::ActionChanged()
174 : {
175 : // call parent
176 0 : ViewContactOfSdrRectObj::ActionChanged();
177 :
178 : // #i123539# if we have buffered chart data, reset it
179 0 : if(mxChartContent.is())
180 : {
181 0 : mxChartContent.clear();
182 : }
183 0 : }
184 :
185 0 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const
186 : {
187 0 : return createPrimitive2DSequenceWithParameters();
188 : }
189 : } // end of namespace contact
190 : } // end of namespace sdr
191 :
192 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|