LCOV - code coverage report
Current view: top level - vbahelper/source/vbahelper - vbapagesetupbase.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 129 144 89.6 %
Date: 2015-06-13 12:38:46 Functions: 15 15 100.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 <vbahelper/vbapagesetupbase.hxx>
      20             : 
      21             : using namespace ::com::sun::star;
      22             : using namespace ::ooo::vba;
      23             : 
      24          56 : VbaPageSetupBase::VbaPageSetupBase(const uno::Reference< XHelperInterface >& xParent,
      25             :                 const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
      26             :     : VbaPageSetupBase_BASE( xParent, xContext )
      27             :     , mnOrientLandscape(0)
      28          56 :     , mnOrientPortrait(0)
      29             : {
      30          56 : }
      31             : 
      32           2 : double SAL_CALL VbaPageSetupBase::getTopMargin() throw (css::uno::RuntimeException, std::exception)
      33             : {
      34           2 :     sal_Int32 topMargin = 0;
      35             : 
      36             :     try
      37             :     {
      38           2 :         bool headerOn = false;
      39           2 :         sal_Int32 headerHeight = 0;
      40             : 
      41           2 :         uno::Any aValue = mxPageProps->getPropertyValue( "HeaderIsOn" );
      42           2 :         aValue >>= headerOn;
      43             : 
      44           2 :         aValue = mxPageProps->getPropertyValue( "TopMargin" );
      45           2 :         aValue >>= topMargin;
      46             : 
      47           2 :         if( headerOn )
      48             :         {
      49           1 :             aValue = mxPageProps->getPropertyValue( "HeaderHeight" );
      50           1 :             aValue >>= headerHeight;
      51           1 :             topMargin = topMargin + headerHeight;
      52           2 :         }
      53             :     }
      54           0 :     catch( uno::Exception& )
      55             :     {
      56             :     }
      57             : 
      58           2 :     return Millimeter::getInPoints( topMargin );
      59             : }
      60             : 
      61           2 : void SAL_CALL VbaPageSetupBase::setTopMargin( double margin ) throw (css::uno::RuntimeException, std::exception)
      62             : {
      63           2 :     sal_Int32 topMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
      64             : 
      65             :     try
      66             :     {
      67           2 :         bool headerOn = false;
      68           2 :         sal_Int32 headerHeight = 0;
      69             : 
      70           2 :         uno::Any aValue = mxPageProps->getPropertyValue( "HeaderIsOn" );
      71           2 :         aValue >>= headerOn;
      72             : 
      73           2 :         if( headerOn )
      74             :         {
      75           1 :             aValue = mxPageProps->getPropertyValue( "HeaderHeight" );
      76           1 :             aValue >>= headerHeight;
      77           1 :             topMargin -= headerHeight;
      78             :         }
      79             : 
      80           2 :         aValue <<= topMargin;
      81           2 :         mxPageProps->setPropertyValue( "TopMargin" , aValue );
      82             :     }
      83           0 :     catch( uno::Exception& )
      84             :     {
      85             :     }
      86           2 : }
      87             : 
      88           2 : double SAL_CALL VbaPageSetupBase::getBottomMargin() throw (css::uno::RuntimeException, std::exception)
      89             : {
      90           2 :     sal_Int32 bottomMargin = 0;
      91             : 
      92             :     try
      93             :     {
      94           2 :         bool footerOn = false;
      95           2 :         sal_Int32 footerHeight = 0;
      96             : 
      97           2 :         uno::Any aValue = mxPageProps->getPropertyValue( "FooterIsOn" );
      98           2 :         aValue >>= footerOn;
      99             : 
     100           2 :         aValue = mxPageProps->getPropertyValue( "BottomMargin" );
     101           2 :         aValue >>= bottomMargin;
     102             : 
     103           2 :         if( footerOn )
     104             :         {
     105           1 :             aValue = mxPageProps->getPropertyValue( "FooterHeight" );
     106           1 :             aValue >>= footerHeight;
     107           1 :             bottomMargin += footerHeight;
     108           2 :         }
     109             :     }
     110           0 :     catch( uno::Exception& )
     111             :     {
     112             :     }
     113             : 
     114           2 :     return Millimeter::getInPoints( bottomMargin );
     115             : }
     116             : 
     117           2 : void SAL_CALL VbaPageSetupBase::setBottomMargin( double margin ) throw (css::uno::RuntimeException, std::exception)
     118             : {
     119           2 :     sal_Int32 bottomMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
     120             : 
     121             :     try
     122             :     {
     123           2 :         bool footerOn = false;
     124           2 :         sal_Int32 footerHeight = 0;
     125             : 
     126           2 :         uno::Any aValue = mxPageProps->getPropertyValue( "FooterIsOn" );
     127           2 :         aValue >>= footerOn;
     128             : 
     129           2 :         if( footerOn )
     130             :         {
     131           1 :             aValue = mxPageProps->getPropertyValue( "FooterHeight" );
     132           1 :             aValue >>= footerHeight;
     133           1 :             bottomMargin -= footerHeight;
     134             :         }
     135             : 
     136           2 :         aValue <<= bottomMargin;
     137           2 :         mxPageProps->setPropertyValue( "BottomMargin" , aValue );
     138             :     }
     139           0 :     catch( uno::Exception& )
     140             :     {
     141             :     }
     142           2 : }
     143             : 
     144           1 : double SAL_CALL VbaPageSetupBase::getRightMargin() throw (css::uno::RuntimeException, std::exception)
     145             : {
     146           1 :     sal_Int32 rightMargin = 0;
     147             :     try
     148             :     {
     149           1 :         uno::Any aValue = mxPageProps->getPropertyValue( "RightMargin" );
     150           1 :         aValue >>= rightMargin;
     151             :     }
     152           0 :     catch( uno::Exception& )
     153             :     {
     154             :     }
     155             : 
     156           1 :     return Millimeter::getInPoints( rightMargin );
     157             : }
     158             : 
     159           1 : void SAL_CALL VbaPageSetupBase::setRightMargin( double margin ) throw (css::uno::RuntimeException, std::exception)
     160             : {
     161           1 :     sal_Int32 rightMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
     162             :     try
     163             :     {
     164           1 :         uno::Any aValue;
     165           1 :         aValue <<= rightMargin;
     166           1 :         mxPageProps->setPropertyValue( "RightMargin" , aValue );
     167             :     }
     168           0 :     catch( uno::Exception& )
     169             :     {
     170             :     }
     171             : 
     172           1 : }
     173             : 
     174           1 : double SAL_CALL VbaPageSetupBase::getLeftMargin() throw (css::uno::RuntimeException, std::exception)
     175             : {
     176           1 :     sal_Int32 leftMargin = 0;
     177             :     try
     178             :     {
     179           1 :         uno::Any aValue = mxPageProps->getPropertyValue( "LeftMargin" );
     180           1 :         aValue >>= leftMargin;
     181             :     }
     182           0 :     catch( uno::Exception& )
     183             :     {
     184             :     }
     185             : 
     186           1 :     return Millimeter::getInPoints( leftMargin );
     187             : }
     188             : 
     189           1 : void SAL_CALL VbaPageSetupBase::setLeftMargin( double margin ) throw (css::uno::RuntimeException, std::exception)
     190             : {
     191           1 :     sal_Int32 leftMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
     192             :     try
     193             :     {
     194           1 :         uno::Any aValue;
     195           1 :         aValue <<= leftMargin;
     196           1 :         mxPageProps->setPropertyValue( "LeftMargin" , aValue );
     197             :     }
     198           0 :     catch( uno::Exception& )
     199             :     {
     200             :     }
     201           1 : }
     202             : 
     203           1 : double SAL_CALL VbaPageSetupBase::getHeaderMargin() throw (css::uno::RuntimeException)
     204             : {
     205           1 :     sal_Int32 headerMargin = 0;
     206             :     try
     207             :     {
     208           1 :         uno::Any aValue = mxPageProps->getPropertyValue( "TopMargin" );
     209           1 :         aValue >>= headerMargin;
     210             :     }
     211           0 :     catch( uno::Exception& )
     212             :     {
     213             :     }
     214             : 
     215           1 :     return Millimeter::getInPoints( headerMargin );
     216             : }
     217             : 
     218           1 : void SAL_CALL VbaPageSetupBase::setHeaderMargin( double margin ) throw (css::uno::RuntimeException)
     219             : {
     220           1 :     sal_Int32 headerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
     221             :     try
     222             :     {
     223           1 :         uno::Any aValue;
     224           1 :         aValue <<= headerMargin;
     225           1 :         mxPageProps->setPropertyValue( "TopMargin" , aValue );
     226             :     }
     227           0 :     catch( uno::Exception& )
     228             :     {
     229             :     }
     230           1 : }
     231             : 
     232           1 : double SAL_CALL VbaPageSetupBase::getFooterMargin() throw (css::uno::RuntimeException)
     233             : {
     234           1 :     sal_Int32 footerMargin = 0;
     235             :     try
     236             :     {
     237           1 :         uno::Any aValue = mxPageProps->getPropertyValue( "BottomMargin" );
     238           1 :         aValue >>= footerMargin;
     239             :     }
     240           0 :     catch( uno::Exception& )
     241             :     {
     242             :     }
     243             : 
     244           1 :     return Millimeter::getInPoints( footerMargin );
     245             : }
     246             : 
     247           1 : void SAL_CALL VbaPageSetupBase::setFooterMargin( double margin ) throw (css::uno::RuntimeException)
     248             : {
     249           1 :     sal_Int32 footerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
     250             :     try
     251             :     {
     252           1 :         uno::Any aValue;
     253           1 :         aValue <<= footerMargin;
     254           1 :         mxPageProps->setPropertyValue( "BottomMargin" , aValue );
     255             :     }
     256           0 :     catch( uno::Exception& )
     257             :     {
     258             :     }
     259           1 : }
     260             : 
     261           1 : sal_Int32 SAL_CALL VbaPageSetupBase::getOrientation() throw (css::uno::RuntimeException, std::exception)
     262             : {
     263           1 :     sal_Int32 orientation = mnOrientPortrait;
     264             :     try
     265             :     {
     266           1 :         bool isLandscape = false;
     267           1 :         uno::Any aValue = mxPageProps->getPropertyValue( "IsLandscape" );
     268           1 :         aValue >>= isLandscape;
     269             : 
     270           1 :         if( isLandscape )
     271             :         {
     272           1 :             orientation = mnOrientLandscape;
     273           1 :         }
     274             :     }
     275           0 :     catch( uno::Exception& )
     276             :     {
     277             :     }
     278           1 :     return orientation;
     279             : }
     280             : 
     281           1 : void SAL_CALL VbaPageSetupBase::setOrientation( sal_Int32 orientation ) throw (css::uno::RuntimeException, std::exception)
     282             : {
     283           2 :     if( ( orientation != mnOrientPortrait ) &&
     284           1 :         ( orientation != mnOrientLandscape ) )
     285             :     {
     286           0 :         DebugHelper::runtimeexception(SbERR_BAD_PARAMETER, OUString() );
     287             :     }
     288             : 
     289             :     try
     290             :     {
     291           1 :         bool isLandscape = false;
     292           1 :         uno::Any aValue = mxPageProps->getPropertyValue( "IsLandscape" );
     293           1 :         aValue >>= isLandscape;
     294             : 
     295           1 :         bool switchOrientation = false;
     296           2 :         if(( isLandscape && orientation != mnOrientLandscape ) ||
     297           2 :             ( !isLandscape && orientation != mnOrientPortrait ))
     298             :         {
     299           1 :             switchOrientation = true;
     300             :         }
     301             : 
     302           1 :         if( switchOrientation )
     303             :         {
     304           1 :             aValue <<= !isLandscape;
     305           1 :             uno::Any aHeight = mxPageProps->getPropertyValue( "Height" );
     306           2 :             uno::Any aWidth = mxPageProps->getPropertyValue( "Width" );
     307           1 :             mxPageProps->setPropertyValue( "IsLandscape" , aValue );
     308           1 :             mxPageProps->setPropertyValue( "Width" ,  aHeight );
     309           2 :             mxPageProps->setPropertyValue( "Height" , aWidth );
     310           1 :         }
     311             :     }
     312           0 :     catch( uno::Exception& )
     313             :     {
     314             :     }
     315           1 : }
     316             : 
     317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11