LCOV - code coverage report
Current view: top level - libreoffice/svx/source/sdr/contact - viewcontactofsdrole2obj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 34 42 81.0 %
Date: 2012-12-27 Functions: 6 7 85.7 %
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           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          49 :         ViewContactOfSdrOle2Obj::ViewContactOfSdrOle2Obj(SdrOle2Obj& rOle2Obj)
      54          49 :         :   ViewContactOfSdrRectObj(rOle2Obj)
      55             :         {
      56          49 :         }
      57             : 
      58          98 :         ViewContactOfSdrOle2Obj::~ViewContactOfSdrOle2Obj()
      59             :         {
      60          98 :         }
      61             : 
      62          41 :         basegfx::B2DHomMatrix ViewContactOfSdrOle2Obj::createObjectTransform() const
      63             :         {
      64             :             // take unrotated snap rect (direct model data) for position and size
      65          41 :             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          41 :             rRectangle += GetOle2Obj().GetGridOffset();
      70          41 :             const basegfx::B2DRange aObjectRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
      71             : 
      72             :             // create object matrix
      73          41 :             const GeoStat& rGeoStat(GetOle2Obj().GetGeoStat());
      74          41 :             const double fShearX(rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0);
      75          41 :             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          41 :                 aObjectRange.getMinX(), aObjectRange.getMinY());
      82             :         }
      83             : 
      84          41 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createPrimitive2DSequenceWithParameters() const
      85             :         {
      86             :             // get object transformation
      87          41 :             const basegfx::B2DHomMatrix aObjectMatrix(createObjectTransform());
      88             : 
      89             :             // Prepare attribute settings, will be used soon anyways
      90          41 :             const SfxItemSet& rItemSet = GetOle2Obj().GetMergedItemSet();
      91             :             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
      92             :                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
      93             :                     rItemSet,
      94          41 :                     GetOle2Obj().getText(0)));
      95          41 :             drawinglayer::primitive2d::Primitive2DReference xContent;
      96             : 
      97          41 :             if(GetOle2Obj().IsChart())
      98             :             {
      99             :                 // try to get chart primitives and chart range directly from xChartModel
     100          41 :                 basegfx::B2DRange aChartContentRange;
     101             :                 const drawinglayer::primitive2d::Primitive2DSequence aChartSequence(
     102             :                     ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
     103          41 :                         GetOle2Obj().getXModel(),
     104          41 :                         aChartContentRange));
     105          41 :                 const double fWidth(aChartContentRange.getWidth());
     106          41 :                 const double fHeight(aChartContentRange.getHeight());
     107             : 
     108          82 :                 if(aChartSequence.hasElements()
     109          41 :                     && basegfx::fTools::more(fWidth, 0.0)
     110          41 :                     && basegfx::fTools::more(fHeight, 0.0))
     111             :                 {
     112             :                     // create embedding transformation
     113             :                     basegfx::B2DHomMatrix aEmbed(
     114             :                         basegfx::tools::createTranslateB2DHomMatrix(
     115           0 :                             -aChartContentRange.getMinX(),
     116           0 :                             -aChartContentRange.getMinY()));
     117             : 
     118           0 :                     aEmbed.scale(1.0 / fWidth, 1.0 / fHeight);
     119           0 :                     aEmbed = aObjectMatrix * aEmbed;
     120             :                     xContent = new drawinglayer::primitive2d::TransformPrimitive2D(
     121             :                         aEmbed,
     122           0 :                         aChartSequence);
     123          41 :                 }
     124             :             }
     125             : 
     126          41 :             if(!xContent.is())
     127             :             {
     128             :                 // #i102063# embed OLE content in an own primitive; this will be able to decompose accessing
     129             :                 // the weak SdrOle2 reference and will also implement getB2DRange() for fast BoundRect
     130             :                 // calculations without OLE Graphic access (which may trigger e.g. chart recalculation).
     131             :                 // It will also take care of HighContrast and ScaleContent
     132             :                 xContent = new drawinglayer::primitive2d::SdrOleContentPrimitive2D(
     133             :                     GetOle2Obj(),
     134             :                     aObjectMatrix,
     135             : 
     136             :                     // #i104867# add GraphicVersion number to be able to check for
     137             :                     // content change in the primitive later
     138          41 :                     GetOle2Obj().getEmbeddedObjectRef().getGraphicVersion() );
     139             :             }
     140             : 
     141             :             // create primitive. Use Ole2 primitive here. Prepare attribute settings, will
     142             :             // be used soon anyways. Always create primitives to allow the decomposition of
     143             :             // SdrOle2Primitive2D to create needed invisible elements for HitTest and/or BoundRect
     144             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     145             :                 new drawinglayer::primitive2d::SdrOle2Primitive2D(
     146             :                     drawinglayer::primitive2d::Primitive2DSequence(&xContent, 1),
     147             :                     aObjectMatrix,
     148          41 :                     aAttribute));
     149             : 
     150          41 :             return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     151             :         }
     152             : 
     153          41 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrOle2Obj::createViewIndependentPrimitive2DSequence() const
     154             :         {
     155          41 :             return createPrimitive2DSequenceWithParameters();
     156             :         }
     157             :     } // end of namespace contact
     158             : } // end of namespace sdr
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10