LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbawrapformat.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 100 3.0 %
Date: 2015-06-13 12:38:46 Functions: 2 20 10.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             : #include "vbawrapformat.hxx"
      20             : #include <ooo/vba/word/WdWrapSideType.hpp>
      21             : #include <ooo/vba/word/WdWrapType.hpp>
      22             : #include <com/sun/star/text/WrapTextMode.hpp>
      23             : #include <vbahelper/vbahelper.hxx>
      24             : #include <vbahelper/helperdecl.hxx>
      25             : 
      26             : using namespace ooo::vba;
      27             : using namespace com::sun::star;
      28             : 
      29           0 : SwVbaWrapFormat::SwVbaWrapFormat( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) : SwVbaWrapFormat_BASE( getXSomethingFromArgs< XHelperInterface >( aArgs, 0 ), xContext ), m_xShape( getXSomethingFromArgs< drawing::XShape >( aArgs, 1, false ) ), mnWrapFormatType( 0 ), mnSide( word::WdWrapSideType::wdWrapBoth )
      30             : {
      31           0 :     m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
      32           0 : }
      33             : 
      34           0 : void SwVbaWrapFormat::makeWrap() throw (uno::RuntimeException)
      35             : {
      36           0 :     text::WrapTextMode eTextMode = text::WrapTextMode_NONE;
      37           0 :     if( mnSide == word::WdWrapSideType::wdWrapLeft )
      38             :     {
      39           0 :         eTextMode = text::WrapTextMode_LEFT;
      40             :     }
      41           0 :     else if(  mnSide == word::WdWrapSideType::wdWrapRight )
      42             :     {
      43           0 :         eTextMode = text::WrapTextMode_RIGHT;
      44             :     }
      45           0 :     else if( mnSide == word::WdWrapSideType::wdWrapBoth ||
      46           0 :             mnSide == word::WdWrapSideType::wdWrapLargest )
      47             :     {
      48           0 :         switch( mnWrapFormatType )
      49             :         {
      50             :             case word::WdWrapType::wdWrapNone:
      51             :             case word::WdWrapType::wdWrapThrough:
      52             :             {
      53           0 :                 eTextMode = text::WrapTextMode_THROUGHT;
      54           0 :                 break;
      55             :             }
      56             :             case word::WdWrapType::wdWrapInline:
      57             :             case word::WdWrapType::wdWrapTopBottom:
      58             :             {
      59           0 :                 eTextMode = text::WrapTextMode_NONE;
      60           0 :                 break;
      61             :             }
      62             :             case word::WdWrapType::wdWrapSquare:
      63             :             {
      64           0 :                 eTextMode = text::WrapTextMode_PARALLEL;
      65           0 :                 m_xPropertySet->setPropertyValue("SurroundContour", uno::makeAny( false ) );
      66           0 :                 break;
      67             :             }
      68             :             case word::WdWrapType::wdWrapTight:
      69             :             {
      70           0 :                 eTextMode = text::WrapTextMode_PARALLEL;
      71           0 :                 m_xPropertySet->setPropertyValue("SurroundContour", uno::makeAny( true ) );
      72           0 :                 break;
      73             :             }
      74             :             default:
      75             :             {
      76           0 :                 DebugHelper::runtimeexception(SbERR_BAD_ARGUMENT, OUString());
      77             :             }
      78             :         }
      79             :     }
      80           0 :     m_xPropertySet->setPropertyValue("TextWrap", uno::makeAny( eTextMode ) );
      81           0 : }
      82             : 
      83           0 : ::sal_Int32 SAL_CALL SwVbaWrapFormat::getType() throw (uno::RuntimeException, std::exception)
      84             : {
      85           0 :     sal_Int32 nType = word::WdWrapType::wdWrapSquare;
      86             :     text::WrapTextMode eTextMode;
      87           0 :     m_xPropertySet->getPropertyValue("TextWrap") >>= eTextMode;
      88           0 :     switch( eTextMode )
      89             :     {
      90             :         case text::WrapTextMode_NONE:
      91             :         {
      92           0 :             nType = word::WdWrapType::wdWrapTopBottom;
      93           0 :             break;
      94             :         }
      95             :         case text::WrapTextMode_THROUGHT:
      96             :         {
      97           0 :             nType = word::WdWrapType::wdWrapNone;
      98           0 :             break;
      99             :         }
     100             :         case text::WrapTextMode_PARALLEL:
     101             :         {
     102           0 :             bool bContour = false;
     103           0 :             m_xPropertySet->getPropertyValue("SurroundContour") >>= bContour;
     104           0 :             if( bContour )
     105           0 :                 nType = word::WdWrapType::wdWrapTight;
     106             :             else
     107           0 :                 nType = word::WdWrapType::wdWrapSquare;
     108           0 :             break;
     109             :         }
     110             :         case text::WrapTextMode_DYNAMIC:
     111             :         case text::WrapTextMode_LEFT:
     112             :         case text::WrapTextMode_RIGHT:
     113             :         {
     114           0 :             nType = word::WdWrapType::wdWrapThrough;
     115           0 :             break;
     116             :         }
     117             :         default:
     118             :         {
     119           0 :             nType = word::WdWrapType::wdWrapSquare;
     120             :         }
     121             :     }
     122           0 :     return nType;
     123             : }
     124             : 
     125           0 : void SAL_CALL SwVbaWrapFormat::setType( ::sal_Int32 _type ) throw (uno::RuntimeException, std::exception)
     126             : {
     127           0 :     mnWrapFormatType = _type;
     128           0 :     makeWrap();
     129           0 : }
     130             : 
     131           0 : ::sal_Int32 SAL_CALL SwVbaWrapFormat::getSide() throw (uno::RuntimeException, std::exception)
     132             : {
     133           0 :     sal_Int32 nSide = word::WdWrapSideType::wdWrapBoth;
     134             :     text::WrapTextMode eTextMode;
     135           0 :     m_xPropertySet->getPropertyValue("TextWrap") >>= eTextMode;
     136           0 :     switch( eTextMode )
     137             :     {
     138             :         case text::WrapTextMode_LEFT:
     139             :         {
     140           0 :             nSide = word::WdWrapSideType::wdWrapLeft;
     141           0 :             break;
     142             :         }
     143             :         case text::WrapTextMode_RIGHT:
     144             :         {
     145           0 :             nSide = word::WdWrapSideType::wdWrapRight;
     146           0 :             break;
     147             :         }
     148             :         default:
     149             :         {
     150           0 :             nSide = word::WdWrapSideType::wdWrapBoth;
     151             :         }
     152             :     }
     153           0 :     return nSide;
     154             : }
     155             : 
     156           0 : void SAL_CALL SwVbaWrapFormat::setSide( ::sal_Int32 _side ) throw (uno::RuntimeException, std::exception)
     157             : {
     158           0 :     mnSide = _side;
     159           0 :     makeWrap();
     160           0 : }
     161             : 
     162           0 : float SwVbaWrapFormat::getDistance( const OUString& sName ) throw (uno::RuntimeException)
     163             : {
     164           0 :     sal_Int32 nDistance = 0;
     165           0 :     m_xPropertySet->getPropertyValue( sName ) >>= nDistance;
     166           0 :     return static_cast< float >( Millimeter::getInPoints( nDistance ) );
     167             : }
     168             : 
     169           0 : void SwVbaWrapFormat::setDistance( const OUString& sName, float _distance ) throw (uno::RuntimeException)
     170             : {
     171           0 :     sal_Int32 nDistance = Millimeter::getInHundredthsOfOneMillimeter( _distance );
     172           0 :     m_xPropertySet->setPropertyValue( sName, uno::makeAny( nDistance ) );
     173           0 : }
     174             : 
     175           0 : float SAL_CALL SwVbaWrapFormat::getDistanceTop() throw (uno::RuntimeException, std::exception)
     176             : {
     177           0 :     return getDistance( OUString("TopMargin") );
     178             : }
     179             : 
     180           0 : void SAL_CALL SwVbaWrapFormat::setDistanceTop( float _distancetop ) throw (uno::RuntimeException, std::exception)
     181             : {
     182           0 :     setDistance( OUString("TopMargin"), _distancetop );
     183           0 : }
     184             : 
     185           0 : float SAL_CALL SwVbaWrapFormat::getDistanceBottom() throw (uno::RuntimeException, std::exception)
     186             : {
     187           0 :     return getDistance( OUString("BottomMargin") );
     188             : }
     189             : 
     190           0 : void SAL_CALL SwVbaWrapFormat::setDistanceBottom( float _distancebottom ) throw (uno::RuntimeException, std::exception)
     191             : {
     192           0 :     setDistance( OUString("BottomMargin"), _distancebottom );
     193           0 : }
     194             : 
     195           0 : float SAL_CALL SwVbaWrapFormat::getDistanceLeft() throw (uno::RuntimeException, std::exception)
     196             : {
     197           0 :     return getDistance( OUString("LeftMargin") );
     198             : }
     199             : 
     200           0 : void SAL_CALL SwVbaWrapFormat::setDistanceLeft( float _distanceleft ) throw (uno::RuntimeException, std::exception)
     201             : {
     202           0 :     setDistance( OUString("LeftMargin"), _distanceleft );
     203           0 : }
     204             : 
     205           0 : float SAL_CALL SwVbaWrapFormat::getDistanceRight() throw (uno::RuntimeException, std::exception)
     206             : {
     207           0 :     return getDistance( OUString("RightMargin") );
     208             : }
     209             : 
     210           0 : void SAL_CALL SwVbaWrapFormat::setDistanceRight( float _distanceright ) throw (uno::RuntimeException, std::exception)
     211             : {
     212           0 :     setDistance( OUString("RightMargin"), _distanceright );
     213           0 : }
     214             : 
     215             : OUString
     216           0 : SwVbaWrapFormat::getServiceImplName()
     217             : {
     218           0 :     return OUString("SwVbaWrapFormat");
     219             : }
     220             : 
     221             : uno::Sequence< OUString >
     222           0 : SwVbaWrapFormat::getServiceNames()
     223             : {
     224           0 :     static uno::Sequence< OUString > aServiceNames;
     225           0 :     if ( aServiceNames.getLength() == 0 )
     226             :     {
     227           0 :         aServiceNames.realloc( 1 );
     228           0 :         aServiceNames[ 0 ] = "ooo.vba.word.WrapFormat";
     229             :     }
     230           0 :     return aServiceNames;
     231             : }
     232             : 
     233             : namespace wrapformat
     234             : {
     235             : namespace sdecl = comphelper::service_decl;
     236           1 : sdecl::vba_service_class_<SwVbaWrapFormat, sdecl::with_args<true> > serviceImpl;
     237           1 : extern sdecl::ServiceDecl const serviceDecl(
     238             :     serviceImpl,
     239             :     "SwVbaWrapFormat",
     240             :     "ooo.vba.word.WrapFormat" );
     241           3 : }
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11