LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ChartController_Position.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 80 0.0 %
Date: 2014-04-14 Functions: 0 4 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 "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             : // header for define RET_OK
      36             : #include <vcl/msgbox.hxx>
      37             : #include <svx/svxids.hrc>
      38             : #include <svx/rectenum.hxx>
      39             : #include <svl/aeitem.hxx>
      40             : #include <svx/svxdlg.hxx>
      41             : #include <svx/dialogs.hrc>
      42             : #include <vcl/svapp.hxx>
      43             : #include <osl/mutex.hxx>
      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 aOriginalSize )
      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 (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_X,true,&pPoolItem))
      62           0 :         nPosX=((const SfxInt32Item*)pPoolItem)->GetValue();
      63           0 :     if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_Y,true,&pPoolItem))
      64           0 :         nPosY=((const SfxInt32Item*)pPoolItem)->GetValue();
      65             :     //read size
      66           0 :     if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_WIDTH,true,&pPoolItem))
      67           0 :         nSizX=((const SfxUInt32Item*)pPoolItem)->GetValue();
      68           0 :     if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_HEIGHT,true,&pPoolItem))
      69           0 :         nSizY=((const SfxUInt32Item*)pPoolItem)->GetValue();
      70           0 :     if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_SIZE_POINT,true,&pPoolItem))
      71           0 :         eRP=(RECT_POINT)((const SfxAllEnumItem*)pPoolItem)->GetValue();
      72             : 
      73           0 :     switch( eRP )
      74             :     {
      75             :         case RP_LT:
      76           0 :             break;
      77             :         case RP_MT:
      78           0 :             nPosX += ( aOriginalSize.Width - nSizX ) / 2;
      79           0 :             break;
      80             :         case RP_RT:
      81           0 :             nPosX += aOriginalSize.Width - nSizX;
      82           0 :             break;
      83             :         case RP_LM:
      84           0 :             nPosY += ( aOriginalSize.Height - nSizY ) / 2;
      85           0 :             break;
      86             :         case RP_MM:
      87           0 :             nPosX += ( aOriginalSize.Width  - nSizX ) / 2;
      88           0 :             nPosY += ( aOriginalSize.Height - nSizY ) / 2;
      89           0 :             break;
      90             :         case RP_RM:
      91           0 :             nPosX += aOriginalSize.Width - nSizX;
      92           0 :             nPosY += ( aOriginalSize.Height - nSizY ) / 2;
      93           0 :             break;
      94             :         case RP_LB:
      95           0 :             nPosY += aOriginalSize.Height - nSizY;
      96           0 :             break;
      97             :         case RP_MB:
      98           0 :             nPosX += ( aOriginalSize.Width - nSizX ) / 2;
      99           0 :             nPosY += aOriginalSize.Height - nSizY;
     100           0 :             break;
     101             :         case RP_RB:
     102           0 :             nPosX += aOriginalSize.Width - nSizX;
     103           0 :             nPosY += aOriginalSize.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 SAL_CALL 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           0 :     SfxAbstractTabDialog * pDlg = NULL;
     133             :     try
     134             :     {
     135           0 :         SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
     136             : 
     137             :         //prepare and open dialog
     138           0 :         SdrView* pSdrView = m_pDrawViewWrapper;
     139           0 :         bool bResizePossible = m_aSelection.isResizeableObjectSelected();
     140             : 
     141           0 :         SolarMutexGuard aGuard;
     142           0 :         SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
     143             :         OSL_ENSURE( pFact, "No dialog factory" );
     144             :         pDlg = pFact->CreateSchTransformTabDialog(
     145           0 :             m_pChartWindow, &aItemSet, pSdrView, RID_SCH_TransformTabDLG_SVXPAGE_ANGLE, bResizePossible );
     146             :         OSL_ENSURE( pDlg, "Couldn't create SchTransformTabDialog" );
     147             : 
     148           0 :         if( pDlg->Execute() == RET_OK )
     149             :         {
     150           0 :             const SfxItemSet* pOutItemSet = pDlg->GetOutputItemSet();
     151           0 :             if(pOutItemSet)
     152             :             {
     153           0 :                 awt::Rectangle aObjectRect;
     154           0 :                 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
     155           0 :                 lcl_getPositionAndSizeFromItemSet( aItemSet, aObjectRect, aSelectedSize );
     156           0 :                 awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
     157           0 :                 awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
     158             : 
     159           0 :                 bool bChanged = false;
     160           0 :                 if ( eObjectType == OBJECTTYPE_LEGEND )
     161             :                 {
     162           0 :                     ChartModel* pModel = dynamic_cast<ChartModel*>(getModel().get());
     163           0 :                     bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning( *pModel, false , true );
     164             :                 }
     165             : 
     166           0 :                 bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getModel()
     167           0 :                             , aObjectRect, aPageRect );
     168           0 :                 if( bMoved || bChanged )
     169           0 :                     aUndoGuard.commit();
     170             :             }
     171             :         }
     172           0 :         delete pDlg;
     173             :     }
     174           0 :     catch(const uno::Exception& e)
     175             :     {
     176           0 :         delete pDlg;
     177             :         ASSERT_EXCEPTION( e );
     178           0 :     }
     179             : }
     180             : 
     181           0 : } //namespace chart
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10