LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofsdrole2obj.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 56 56 100.0 %
Date: 2014-11-03 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          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 <sdr/contact/viewcontactofsdrole2obj.hxx>
      21             : #include <svx/svdoole2.hxx>
      22             : #include <sdr/contact/viewobjectcontactofsdrole2obj.hxx>
      23             : #include <basegfx/matrix/b2dhommatrix.hxx>
      24             : #include <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 <sdr/primitive2d/sdrolecontentprimitive2d.hxx>
      33             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      34             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      35             : #include <svx/charthelper.hxx>
      36             : #include <svtools/embedhlp.hxx>
      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          27 :         ViewObjectContact& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
      46             :         {
      47          27 :             ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
      48             :             DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
      49             : 
      50          27 :             return *pRetval;
      51             :         }
      52             : 
      53         464 :         ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
      54             :         :   ViewContactOfSdrRectObj(rOle2Obj),
      55         464 :             mxChartContent()
      56             :         {
      57         464 :         }
      58             : 
      59         928 :         ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
      60             :         {
      61         928 :         }
      62             : 
      63         546 :         basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const
      64             :         {
      65             :             // take unrotated snap rect (direct model data) for position and size
      66         546 :             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         546 :             rRectangle += GetOle2Obj().GetGridOffset();
      71         546 :             const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
      72             : 
      73             :             // create object matrix
      74         546 :             const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
      75         546 :             const double fShearX(rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0);
      76         546 :             const double fRotate(rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0);
      77             : 
      78             :             return basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
      79             :                 aObjectRange.getWidth(), aObjectRange.getHeight(),
      80             :                 fShearX,
      81             :                 fRotate,
      82         546 :                 aObjectRange.getMinX(), aObjectRange.getMinY());
      83             :         }
      84             : 
      85         546 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters() const
      86             :         {
      87             :             // get object transformation
      88         546 :             const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
      89             : 
      90             :             // Prepare attribute settings, will be used soon anyways
      91         546 :             const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
      92             : 
      93             :             // this may be refined more granular; if no content, attributes may get simpler
      94         546 :             const bool bHasContent(true);
      95             :             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
      96             :                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
      97             :                     rItemSet,
      98        1092 :                     GetOle2Obj().getText(0),
      99        1638 :                     bHasContent));
     100        1092 :             drawinglayer::primitive2d::Primitive2DReference xContent;
     101             : 
     102         546 :             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         386 :                 if(mxChartContent.is())
     108             :                 {
     109         110 :                     xContent = mxChartContent;
     110             :                 }
     111             :                 else
     112             :                 {
     113             :                     // try to get chart primitives and chart range directly from xChartModel
     114         276 :                     basegfx::B2DRange aChartContentRange;
     115             :                     const drawinglayer::primitive2d::Primitive2DSequence aChartSequence(
     116             :                         ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
     117         276 :                             GetOle2Obj().getXModel(),
     118         276 :                             aChartContentRange));
     119         276 :                     const double fWidth(aChartContentRange.getWidth());
     120         276 :                     const double fHeight(aChartContentRange.getHeight());
     121             : 
     122         832 :                     if(aChartSequence.hasElements()
     123         820 :                         && basegfx::fTools::more(fWidth, 0.0)
     124        1100 :                         && basegfx::fTools::more(fHeight, 0.0))
     125             :                     {
     126             :                         // create embedding transformation
     127             :                         basegfx::B2DHomMatrix aEmbed(
     128             :                             basegfx::tools::createTranslateB2DHomMatrix(
     129         272 :                                 -aChartContentRange.getMinX(),
     130         544 :                                 -aChartContentRange.getMinY()));
     131             : 
     132         272 :                         aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
     133         272 :                         aEmbed = aObjectMatrix * aEmbed;
     134         544 :                         xContent = new drawinglayer::primitive2d::TransformPrimitive2D(
     135             :                             aEmbed,
     136         544 :                             aChartSequence);
     137             :                     }
     138             : 
     139         276 :                     if(xContent.is())
     140             :                     {
     141         272 :                         const_cast< ViewContactOfSdrOle2Obj* >(this)->mxChartContent = xContent;
     142         276 :                     }
     143             :                 }
     144             :             }
     145             : 
     146         546 :             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         492 :                 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         492 :                     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        1092 :                     aAttribute));
     169             : 
     170        1092 :             return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     171             :         }
     172             : 
     173        5708 :         void ViewContactOfSdrOle2Obj::ActionChanged()
     174             :         {
     175             :             // call parent
     176        5708 :             ViewContactOfSdrRectObj::ActionChanged();
     177             : 
     178             :             // #i123539# if we have buffered chart data, reset it
     179        5708 :             if(mxChartContent.is())
     180             :             {
     181         178 :                 mxChartContent.clear();
     182             :             }
     183        5708 :         }
     184             : 
     185         349 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const
     186             :         {
     187         349 :             return createPrimitive2DSequenceWithParameters();
     188             :         }
     189             :     } // end of namespace contact
     190         651 : } // end of namespace sdr
     191             : 
     192             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10