LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ChartController_Position.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 78 1.3 %
Date: 2015-06-13 12:38:46 Functions: 2 4 50.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 "ChartController.hxx"
      21             : 
      22             : #include "macros.hxx"
      23             : #include "ChartWindow.hxx"
      24             : #include "DrawViewWrapper.hxx"
      25             : #include "PositionAndSizeHelper.hxx"
      26             : #include "ChartModelHelper.hxx"
      27             : #include "UndoGuard.hxx"
      28             : #include "Strings.hrc"
      29             : #include "ObjectNameProvider.hxx"
      30             : #include "DiagramHelper.hxx"
      31             : #include "chartview/ExplicitValueProvider.hxx"
      32             : #include "CommonConverters.hxx"
      33             : #include <svx/ActionDescriptionProvider.hxx>
      34             : 
      35             : #include <vcl/msgbox.hxx>
      36             : #include <svx/svxids.hrc>
      37             : #include <svx/rectenum.hxx>
      38             : #include <svl/aeitem.hxx>
      39             : #include <svx/svxdlg.hxx>
      40             : #include <svx/dialogs.hrc>
      41             : #include <vcl/svapp.hxx>
      42             : #include <osl/mutex.hxx>
      43             : #include <boost/scoped_ptr.hpp>
      44             : 
      45             : namespace chart
      46             : {
      47             : using namespace ::com::sun::star;
      48             : using namespace ::com::sun::star::chart2;
      49             : 
      50           0 : void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, awt::Rectangle& rPosAndSize, const awt::Size& rOriginalSize )
      51             : {
      52           0 :     long nPosX(0);
      53           0 :     long nPosY(0);
      54           0 :     long nSizX(0);
      55           0 :     long nSizY(0);
      56             : 
      57           0 :     RECT_POINT eRP = (RECT_POINT)RP_LT;
      58             : 
      59           0 :     const SfxPoolItem* pPoolItem=NULL;
      60             :     //read position
      61           0 :     if (SfxItemState::SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_X,true,&pPoolItem))
      62           0 :         nPosX= static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
      63           0 :     if (SfxItemState::SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_Y,true,&pPoolItem))
      64           0 :         nPosY=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
      65             :     //read size
      66           0 :     if (SfxItemState::SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_WIDTH,true,&pPoolItem))
      67           0 :         nSizX=static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
      68           0 :     if (SfxItemState::SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_HEIGHT,true,&pPoolItem))
      69           0 :         nSizY=static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
      70           0 :     if (SfxItemState::SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_SIZE_POINT,true,&pPoolItem))
      71           0 :         eRP=(RECT_POINT)static_cast<const SfxAllEnumItem*>(pPoolItem)->GetValue();
      72             : 
      73           0 :     switch( eRP )
      74             :     {
      75             :         case RP_LT:
      76           0 :             break;
      77             :         case RP_MT:
      78           0 :             nPosX += ( rOriginalSize.Width - nSizX ) / 2;
      79           0 :             break;
      80             :         case RP_RT:
      81           0 :             nPosX += rOriginalSize.Width - nSizX;
      82           0 :             break;
      83             :         case RP_LM:
      84           0 :             nPosY += ( rOriginalSize.Height - nSizY ) / 2;
      85           0 :             break;
      86             :         case RP_MM:
      87           0 :             nPosX += ( rOriginalSize.Width  - nSizX ) / 2;
      88           0 :             nPosY += ( rOriginalSize.Height - nSizY ) / 2;
      89           0 :             break;
      90             :         case RP_RM:
      91           0 :             nPosX += rOriginalSize.Width - nSizX;
      92           0 :             nPosY += ( rOriginalSize.Height - nSizY ) / 2;
      93           0 :             break;
      94             :         case RP_LB:
      95           0 :             nPosY += rOriginalSize.Height - nSizY;
      96           0 :             break;
      97             :         case RP_MB:
      98           0 :             nPosX += ( rOriginalSize.Width - nSizX ) / 2;
      99           0 :             nPosY += rOriginalSize.Height - nSizY;
     100           0 :             break;
     101             :         case RP_RB:
     102           0 :             nPosX += rOriginalSize.Width - nSizX;
     103           0 :             nPosY += rOriginalSize.Height - nSizY;
     104           0 :             break;
     105             :         default:
     106           0 :             break;
     107             :     }
     108             : 
     109           0 :     rPosAndSize = awt::Rectangle(nPosX,nPosY,nSizX,nSizY);
     110           0 : }
     111             : 
     112           0 : void ChartController::executeDispatch_PositionAndSize()
     113             : {
     114           0 :     const OUString aCID( m_aSelection.getSelectedCID() );
     115             : 
     116           0 :     if( aCID.isEmpty() )
     117           0 :         return;
     118             : 
     119           0 :     awt::Size aSelectedSize;
     120           0 :     ExplicitValueProvider* pProvider( ExplicitValueProvider::getExplicitValueProvider( m_xChartView ) );
     121           0 :     if( pProvider )
     122           0 :         aSelectedSize = ToSize( ( pProvider->getRectangleOfObject( aCID ) ) );
     123             : 
     124           0 :     ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
     125             : 
     126             :     UndoGuard aUndoGuard(
     127             :         ActionDescriptionProvider::createDescription(
     128             :             ActionDescriptionProvider::POS_SIZE,
     129             :             ObjectNameProvider::getName( eObjectType)),
     130           0 :         m_xUndoManager );
     131             : 
     132             :     try
     133             :     {
     134           0 :         SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
     135             : 
     136             :         //prepare and open dialog
     137           0 :         SdrView* pSdrView = m_pDrawViewWrapper;
     138           0 :         bool bResizePossible = m_aSelection.isResizeableObjectSelected();
     139             : 
     140           0 :         SolarMutexGuard aGuard;
     141           0 :         SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
     142             :         OSL_ENSURE( pFact, "No dialog factory" );
     143             :         boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSchTransformTabDialog(
     144           0 :             m_pChartWindow, &aItemSet, pSdrView, RID_SCH_TransformTabDLG_SVXPAGE_ANGLE, bResizePossible ));
     145             :         OSL_ENSURE( pDlg, "Couldn't create SchTransformTabDialog" );
     146             : 
     147           0 :         if( pDlg->Execute() == RET_OK )
     148             :         {
     149           0 :             const SfxItemSet* pOutItemSet = pDlg->GetOutputItemSet();
     150           0 :             if(pOutItemSet)
     151             :             {
     152           0 :                 awt::Rectangle aObjectRect;
     153           0 :                 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
     154           0 :                 lcl_getPositionAndSizeFromItemSet( aItemSet, aObjectRect, aSelectedSize );
     155           0 :                 awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
     156           0 :                 awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
     157             : 
     158           0 :                 bool bChanged = false;
     159           0 :                 if ( eObjectType == OBJECTTYPE_LEGEND )
     160             :                 {
     161           0 :                     ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel().get());
     162           0 :                     bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning(rModel, false , true);
     163             :                 }
     164             : 
     165           0 :                 bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getModel()
     166           0 :                             , aObjectRect, aPageRect );
     167           0 :                 if( bMoved || bChanged )
     168           0 :                     aUndoGuard.commit();
     169             :             }
     170           0 :         }
     171             :     }
     172           0 :     catch(const uno::Exception& e)
     173             :     {
     174             :         ASSERT_EXCEPTION( e );
     175           0 :     }
     176             : }
     177             : 
     178          57 : } //namespace chart
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11