LCOV - code coverage report
Current view: top level - chart2/source/controller/main - PositionAndSizeHelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 62 0.0 %
Date: 2014-04-14 Functions: 0 2 0.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 "PositionAndSizeHelper.hxx"
      21             : #include "macros.hxx"
      22             : #include "ChartModelHelper.hxx"
      23             : #include "ControllerLockGuard.hxx"
      24             : #include <com/sun/star/chart2/LegendPosition.hpp>
      25             : #include <com/sun/star/chart/ChartLegendExpansion.hpp>
      26             : #include <com/sun/star/chart2/RelativePosition.hpp>
      27             : #include <com/sun/star/chart2/RelativeSize.hpp>
      28             : #include "chartview/ExplicitValueProvider.hxx"
      29             : 
      30             : // header for class Rectangle
      31             : #include <tools/gen.hxx>
      32             : #include <com/sun/star/beans/XPropertySet.hpp>
      33             : 
      34             : namespace chart
      35             : {
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::chart2;
      38             : 
      39           0 : bool PositionAndSizeHelper::moveObject( ObjectType eObjectType
      40             :                 , const uno::Reference< beans::XPropertySet >& xObjectProp
      41             :                 , const awt::Rectangle& rNewPositionAndSize
      42             :                 , const awt::Rectangle& rPageRectangle
      43             :                 )
      44             : {
      45           0 :     if(!xObjectProp.is())
      46           0 :         return false;
      47           0 :     Rectangle aObjectRect( Point(rNewPositionAndSize.X,rNewPositionAndSize.Y), Size(rNewPositionAndSize.Width,rNewPositionAndSize.Height) );
      48           0 :     Rectangle aPageRect( Point(rPageRectangle.X,rPageRectangle.Y), Size(rPageRectangle.Width,rPageRectangle.Height) );
      49             : 
      50           0 :     if( OBJECTTYPE_TITLE==eObjectType )
      51             :     {
      52             :         //@todo decide whether x is primary or secondary
      53           0 :         chart2::RelativePosition aRelativePosition;
      54           0 :         aRelativePosition.Anchor = drawing::Alignment_CENTER;
      55             :         //the anchor point at the title object is top/middle
      56           0 :         Point aPos = aObjectRect.TopLeft();
      57           0 :         aRelativePosition.Primary = (double(aPos.X())+double(aObjectRect.getWidth())/2.0)/double(aPageRect.getWidth());
      58           0 :         aRelativePosition.Secondary = (double(aPos.Y())+double(aObjectRect.getHeight())/2.0)/double(aPageRect.getHeight());
      59           0 :         xObjectProp->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition) );
      60             :     }
      61           0 :     else if( OBJECTTYPE_DATA_CURVE_EQUATION==eObjectType )
      62             :     {
      63             :         //@todo decide whether x is primary or secondary
      64           0 :         chart2::RelativePosition aRelativePosition;
      65           0 :         aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
      66             :         //the anchor point at the title object is top/middle
      67           0 :         Point aPos = aObjectRect.TopLeft();
      68           0 :         aRelativePosition.Primary = double(aPos.X())/double(aPageRect.getWidth());
      69           0 :         aRelativePosition.Secondary = double(aPos.Y())/double(aPageRect.getHeight());
      70           0 :         xObjectProp->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition) );
      71             :     }
      72           0 :     else if(OBJECTTYPE_LEGEND==eObjectType)
      73             :     {
      74           0 :         xObjectProp->setPropertyValue( "AnchorPosition", uno::makeAny(LegendPosition(LegendPosition_CUSTOM)));
      75           0 :         xObjectProp->setPropertyValue( "Expansion", uno::makeAny(::com::sun::star::chart::ChartLegendExpansion_CUSTOM));
      76           0 :         chart2::RelativePosition aRelativePosition;
      77           0 :         chart2::RelativeSize aRelativeSize;
      78           0 :         Point aAnchor = aObjectRect.TopLeft();
      79             : 
      80             :         aRelativePosition.Primary =
      81           0 :             static_cast< double >( aAnchor.X()) /
      82           0 :             static_cast< double >( aPageRect.getWidth() );
      83             :         aRelativePosition.Secondary =
      84           0 :             static_cast< double >( aAnchor.Y()) /
      85           0 :             static_cast< double >( aPageRect.getHeight());
      86             : 
      87           0 :         xObjectProp->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition) );
      88             : 
      89             :         aRelativeSize.Primary =
      90           0 :             static_cast< double >( aObjectRect.getWidth()) /
      91           0 :             static_cast< double >( aPageRect.getWidth() );
      92           0 :         if (aRelativeSize.Primary > 1.0)
      93           0 :             aRelativeSize.Primary = 1.0;
      94             :         aRelativeSize.Secondary =
      95           0 :             static_cast< double >( aObjectRect.getHeight()) /
      96           0 :             static_cast< double >( aPageRect.getHeight());
      97           0 :         if (aRelativeSize.Secondary > 1.0)
      98           0 :             aRelativeSize.Secondary = 1.0;
      99             : 
     100           0 :         xObjectProp->setPropertyValue( "RelativeSize", uno::makeAny(aRelativeSize) );
     101             :     }
     102           0 :     else if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType)
     103             :     {
     104             :         //@todo decide whether x is primary or secondary
     105             : 
     106             :         //set position:
     107           0 :         chart2::RelativePosition aRelativePosition;
     108           0 :         aRelativePosition.Anchor = drawing::Alignment_CENTER;
     109             : 
     110           0 :         Point aPos = aObjectRect.Center();
     111           0 :         aRelativePosition.Primary = double(aPos.X())/double(aPageRect.getWidth());
     112           0 :         aRelativePosition.Secondary = double(aPos.Y())/double(aPageRect.getHeight());
     113           0 :         xObjectProp->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition) );
     114             : 
     115             :         //set size:
     116           0 :         RelativeSize aRelativeSize;
     117             :         //the anchor points for the diagram are in the middle of the diagram
     118             :         //and in the middle of the page
     119           0 :         aRelativeSize.Primary = double(aObjectRect.getWidth())/double(aPageRect.getWidth());
     120           0 :         aRelativeSize.Secondary = double(aObjectRect.getHeight())/double(aPageRect.getHeight());
     121           0 :         xObjectProp->setPropertyValue( "RelativeSize", uno::makeAny(aRelativeSize) );
     122             :     }
     123             :     else
     124           0 :         return false;
     125           0 :     return true;
     126             : }
     127             : 
     128           0 : bool PositionAndSizeHelper::moveObject( const OUString& rObjectCID
     129             :                 , const uno::Reference< frame::XModel >& xChartModel
     130             :                 , const awt::Rectangle& rNewPositionAndSize
     131             :                 , const awt::Rectangle& rPageRectangle
     132             :                 )
     133             : {
     134           0 :     ControllerLockGuardUNO aLockedControllers( xChartModel );
     135             : 
     136           0 :     awt::Rectangle aNewPositionAndSize( rNewPositionAndSize );
     137             : 
     138           0 :     uno::Reference< beans::XPropertySet > xObjectProp = ObjectIdentifier::getObjectPropertySet( rObjectCID, xChartModel );
     139           0 :     ObjectType eObjectType( ObjectIdentifier::getObjectType( rObjectCID ) );
     140           0 :     if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType)
     141             :     {
     142           0 :         xObjectProp = uno::Reference< beans::XPropertySet >( ObjectIdentifier::getDiagramForCID( rObjectCID, xChartModel ), uno::UNO_QUERY );
     143           0 :         if(!xObjectProp.is())
     144           0 :             return false;
     145             :     }
     146           0 :     return moveObject( eObjectType, xObjectProp, aNewPositionAndSize, rPageRectangle );
     147             : }
     148             : 
     149             : } //namespace chart
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10