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

Generated by: LCOV version 1.10