1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx> 28 #include <svx/svdoole2.hxx> 29 #include <svx/sdr/contact/viewobjectcontactofsdrole2obj.hxx> 30 #include <basegfx/matrix/b2dhommatrix.hxx> 31 #include <svx/sdr/primitive2d/sdrole2primitive2d.hxx> 32 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx> 33 #include <basegfx/polygon/b2dpolygontools.hxx> 34 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 35 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 36 #include <svtools/colorcfg.hxx> 37 #include <svx/sdr/primitive2d/sdrattributecreator.hxx> 38 #include <vcl/svapp.hxx> 39 #include <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx> 40 #include <basegfx/matrix/b2dhommatrixtools.hxx> 41 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 42 #include <svx/charthelper.hxx> 43 44 ////////////////////////////////////////////////////////////////////////////// 45 46 namespace sdr 47 { 48 namespace contact 49 { 50 // Create a Object-Specific ViewObjectContact, set ViewContact and 51 // ObjectContact. Always needs to return something. 52 ViewObjectContact& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact) 53 { 54 ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this); 55 DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)"); 56 57 return *pRetval; 58 } 59 60 ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj) 61 : ViewContactOfSdrRectObj(rOle2Obj) 62 { 63 } 64 65 ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj() 66 { 67 } 68 69 basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const 70 { 71 // take unrotated snap rect (direct model data) for position and size 72 const Rectangle& rRectangle = GetOle2Obj().GetGeoRect(); 73 const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom()); 74 75 // create object matrix 76 const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat()); 77 const double fShearX(rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0); 78 const double fRotate(rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0); 79 80 return basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix( 81 aObjectRange.getWidth(), aObjectRange.getHeight(), 82 fShearX, 83 fRotate, 84 aObjectRange.getMinX(), aObjectRange.getMinY()); 85 } 86 87 drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters( 88 bool bHighContrast) const 89 { 90 // get object transformation 91 const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform()); 92 93 // Prepare attribute settings, will be used soon anyways 94 const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet(); 95 96 // this may be refined more granular; if no content, attributes may get simpler 97 const bool bHasContent(true); 98 const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute( 99 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute( 100 rItemSet, 101 GetOle2Obj().getText(0), 102 bHasContent)); 103 drawinglayer::primitive2d::Primitive2DReference xContent; 104 105 if(GetOle2Obj().IsChart()) 106 { 107 // try to get chart primitives and chart range directly from xChartModel 108 basegfx::B2DRange aChartContentRange; 109 const drawinglayer::primitive2d::Primitive2DSequence aChartSequence( 110 ChartHelper::tryToGetChartContentAsPrimitive2DSequence( 111 GetOle2Obj().getXModel(), 112 aChartContentRange)); 113 const double fWidth(aChartContentRange.getWidth()); 114 const double fHeight(aChartContentRange.getHeight()); 115 116 if(aChartSequence.hasElements() 117 && basegfx::fTools::more(fWidth, 0.0) 118 && basegfx::fTools::more(fHeight, 0.0)) 119 { 120 // create embedding transformation 121 basegfx::B2DHomMatrix aEmbed( 122 basegfx::tools::createTranslateB2DHomMatrix( 123 -aChartContentRange.getMinX(), 124 -aChartContentRange.getMinY())); 125 126 aEmbed.scale(1.0 / fWidth, 1.0 / fHeight); 127 aEmbed = aObjectMatrix * aEmbed; 128 xContent = new drawinglayer::primitive2d::TransformPrimitive2D( 129 aEmbed, 130 aChartSequence); 131 } 132 } 133 134 if(!xContent.is()) 135 { 136 // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing 137 // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect 138 // calculations without OLE Graphic access (which may trigger e.g. chart recalculation). 139 // It will also take care of HighContrast and ScaleContent 140 xContent = new drawinglayer::primitive2d::SdrOleContentPrimitive2D( 141 GetOle2Obj(), 142 aObjectMatrix, 143 144 // #i104867# add GraphicVersion number to be able to check for 145 // content change in the primitive later 146 GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion(), 147 148 bHighContrast); 149 } 150 151 // create primitive. Use Ole2 primitive here. Prepare attribute settings, will 152 // be used soon anyways. Always create primitives to allow the decomposition of 153 // SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect 154 const drawinglayer::primitive2d::Primitive2DReference xReference( 155 new drawinglayer::primitive2d::SdrOle2Primitive2D( 156 drawinglayer::primitive2d::Primitive2DSequence(&xContent, 1), 157 aObjectMatrix, 158 aAttribute)); 159 160 return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1); 161 } 162 163 drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const 164 { 165 // do as if no HC and call standard creator 166 return createPrimitive2DSequenceWithParameters(false); 167 } 168 } // end of namespace contact 169 } // end of namespace sdr 170 171 ////////////////////////////////////////////////////////////////////////////// 172 // eof 173