LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/sdr/contact - viewcontactofsdrole2obj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 47 100.0 %
Date: 2013-07-09 Functions: 9 9 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 <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           9 :         ViewObjectContact& ViewContactOfSdrOle2Obj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
      46             :         {
      47           9 :             ViewObjectContact* pRetval = new ViewObjectContactOfSdrOle2Obj(rObjectContact, *this);
      48             :             DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
      49             : 
      50           9 :             return *pRetval;
      51             :         }
      52             : 
      53          79 :         ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
      54          79 :         :   ViewContactOfSdrRectObj(rOle2Obj)
      55             :         {
      56          79 :         }
      57             : 
      58         158 :         ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
      59             :         {
      60         158 :         }
      61             : 
      62         140 :         basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const
      63             :         {
      64             :             // take unrotated snap rect (direct model data) for position and size
      65         140 :             Rectangle rRectangle = GetOle2Obj().GetGeoRect();
      66             :             // Hack for calc, transform position of object according
      67             :             // to current zoom so as objects relative position to grid
      68             :             // appears stable
      69         140 :             rRectangle += GetOle2Obj().GetGridOffset();
      70         140 :             const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
      71             : 
      72             :             // create object matrix
      73         140 :             const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
      74         140 :             const double fShearX(rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0);
      75         140 :             const double fRotate(rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0);
      76             : 
      77             :             return basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
      78             :                 aObjectRange.getWidth(), aObjectRange.getHeight(),
      79             :                 fShearX,
      80             :                 fRotate,
      81         140 :                 aObjectRange.getMinX(), aObjectRange.getMinY());
      82             :         }
      83             : 
      84         140 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters() const
      85             :         {
      86             :             // get object transformation
      87         140 :             const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
      88             : 
      89             :             // Prepare attribute settings, will be used soon anyways
      90         140 :             const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
      91             : 
      92             :             // this may be refined more granular; if no content, attributes may get simpler
      93         140 :             const bool bHasContent(true);
      94             :             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
      95             :                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
      96             :                     rItemSet,
      97         280 :                     GetOle2Obj().getText(0),
      98         420 :                     bHasContent));
      99         280 :             drawinglayer::primitive2d::Primitive2DReference xContent;
     100             : 
     101         140 :             if(GetOle2Obj().IsChart())
     102             :             {
     103             :                 // try to get chart primitives and chart range directly from xChartModel
     104         134 :                 basegfx::B2DRange aChartContentRange;
     105             :                 const drawinglayer::primitive2d::Primitive2DSequence aChartSequence(
     106             :                     ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
     107         134 :                         GetOle2Obj().getXModel(),
     108         134 :                         aChartContentRange));
     109         134 :                 const double fWidth(aChartContentRange.getWidth());
     110         134 :                 const double fHeight(aChartContentRange.getHeight());
     111             : 
     112         402 :                 if(aChartSequence.hasElements()
     113         402 :                     && basegfx::fTools::more(fWidth, 0.0)
     114         536 :                     && basegfx::fTools::more(fHeight, 0.0))
     115             :                 {
     116             :                     // create embedding transformation
     117             :                     basegfx::B2DHomMatrix aEmbed(
     118             :                         basegfx::tools::createTranslateB2DHomMatrix(
     119         134 :                             -aChartContentRange.getMinX(),
     120         268 :                             -aChartContentRange.getMinY()));
     121             : 
     122         134 :                     aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
     123         134 :                     aEmbed = aObjectMatrix * aEmbed;
     124         268 :                     xContent = new drawinglayer::primitive2d::TransformPrimitive2D(
     125             :                         aEmbed,
     126         268 :                         aChartSequence);
     127         134 :                 }
     128             :             }
     129             : 
     130         140 :             if(!xContent.is())
     131             :             {
     132             :                 // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
     133             :                 // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
     134             :                 // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
     135             :                 // It will also take care of HighContrast and ScaleContent
     136          18 :                 xContent = new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
     137             :                     GetOle2Obj(),
     138             :                     aObjectMatrix,
     139             : 
     140             :                     // #i104867# add GraphicVersion number to be able to check for
     141             :                     // content change in the primitive later
     142          18 :                     GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion() );
     143             :             }
     144             : 
     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(
     150             :                     drawinglayer::primitive2d::Primitive2DSequence(&xContent, 1),
     151             :                     aObjectMatrix,
     152         280 :                     aAttribute));
     153             : 
     154         280 :             return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     155             :         }
     156             : 
     157          58 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const
     158             :         {
     159          58 :             return createPrimitive2DSequenceWithParameters();
     160             :         }
     161             :     } // end of namespace contact
     162         258 : } // end of namespace sdr
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10