LCOV - code coverage report
Current view: top level - vbahelper/source/vbahelper - vbapictureformat.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 30 61 49.2 %
Date: 2014-11-03 Functions: 7 12 58.3 %
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 "vbapictureformat.hxx"
      20             : 
      21             : using namespace ooo::vba;
      22             : using namespace com::sun::star;
      23             : 
      24           4 : ScVbaPictureFormat::ScVbaPictureFormat( const css::uno::Reference< ov::XHelperInterface >& xParent,
      25             :     const css::uno::Reference< css::uno::XComponentContext >& xContext,
      26             :     uno::Reference< drawing::XShape > xShape )
      27             :     throw (lang::IllegalArgumentException, uno::RuntimeException)
      28           4 :     : ScVbaPictureFormat_BASE( xParent, xContext ), m_xShape( xShape )
      29             : {
      30           4 :     m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
      31           4 : }
      32             : 
      33             : void
      34          18 : ScVbaPictureFormat::checkParameterRangeInDouble( double nRange, double nMin, double nMax ) throw (css::uno::RuntimeException)
      35             : {
      36          18 :     if( nRange < nMin )
      37             :     {
      38           0 :         throw uno::RuntimeException( "Parameter out of range, value is too small." );
      39             :     }
      40          18 :     if( nRange > nMax )
      41             :     {
      42           0 :         throw uno::RuntimeException( "Parameter out of range, value is too high." );
      43             :     }
      44          18 : }
      45             : 
      46             : // Attributes
      47             : double SAL_CALL
      48           0 : ScVbaPictureFormat::getBrightness() throw (uno::RuntimeException, std::exception)
      49             : {
      50           0 :     sal_Int16 nLuminance = 0;
      51           0 :     m_xPropertySet->getPropertyValue( "AdjustLuminance" ) >>= nLuminance;
      52           0 :     double fBrightness = static_cast< double >( nLuminance );
      53           0 :     fBrightness = ( fBrightness +100 ) / 200;
      54           0 :     return fBrightness;
      55             : }
      56             : 
      57             : void SAL_CALL
      58           0 : ScVbaPictureFormat::setBrightness( double _brightness ) throw (uno::RuntimeException, std::exception)
      59             : {
      60           0 :     checkParameterRangeInDouble( _brightness, 0.0, 1.0 );
      61           0 :     double fLuminance = _brightness * 200 - 100;
      62           0 :     sal_Int16 nLuminance = static_cast< sal_Int16 >( fLuminance );
      63           0 :     m_xPropertySet->setPropertyValue( "AdjustLuminance" , uno::makeAny( nLuminance ) );
      64           0 : }
      65             : 
      66             : double SAL_CALL
      67          28 : ScVbaPictureFormat::getContrast() throw (uno::RuntimeException, std::exception)
      68             : {
      69          28 :     sal_Int16 nContrast = 0;
      70          28 :     m_xPropertySet->getPropertyValue( "AdjustContrast" ) >>= nContrast;
      71          28 :     double fContrast = static_cast< double >( nContrast );
      72          28 :     fContrast = ( fContrast + 100 ) / 200;
      73          28 :     return fContrast;
      74             : }
      75             : 
      76             : void SAL_CALL
      77          18 : ScVbaPictureFormat::setContrast( double _contrast ) throw (uno::RuntimeException, std::exception)
      78             : {
      79          18 :     checkParameterRangeInDouble( _contrast, 0.0, 1.0 );
      80          18 :     double fContrast = _contrast * 200 - 100;
      81          18 :     sal_Int16 nContrast = static_cast< sal_Int16 >( fContrast );
      82          18 :     m_xPropertySet->setPropertyValue( "AdjustContrast" , uno::makeAny( nContrast ) );
      83          18 : }
      84             : 
      85             : 
      86             : // Methods
      87             : void SAL_CALL
      88           0 : ScVbaPictureFormat::IncrementBrightness( double increment ) throw (uno::RuntimeException, std::exception)
      89             : {
      90           0 :     double fBrightness = getBrightness();
      91           0 :     fBrightness += increment;
      92           0 :     if( fBrightness < 0 )
      93             :     {
      94           0 :         fBrightness = 0.0;
      95             :     }
      96           0 :     if( fBrightness > 1 )
      97             :     {
      98           0 :         fBrightness = 1;
      99             :     }
     100           0 :     setBrightness( fBrightness );
     101           0 : }
     102             : 
     103             : void SAL_CALL
     104           8 : ScVbaPictureFormat::IncrementContrast( double increment ) throw (uno::RuntimeException, std::exception)
     105             : {
     106           8 :     double nContrast = getContrast();
     107           8 :     nContrast += increment;
     108           8 :     if( nContrast < 0 )
     109             :     {
     110           2 :         nContrast = 0.0;
     111             :     }
     112           8 :     if( nContrast > 1 )
     113             :     {
     114           2 :         nContrast = 1.0;
     115             :     }
     116           8 :     setContrast( nContrast );
     117           8 : }
     118             : 
     119             : OUString
     120           0 : ScVbaPictureFormat::getServiceImplName()
     121             : {
     122           0 :     return OUString("ScVbaPictureFormat");
     123             : }
     124             : 
     125             : uno::Sequence< OUString >
     126           0 : ScVbaPictureFormat::getServiceNames()
     127             : {
     128           0 :     static uno::Sequence< OUString > aServiceNames;
     129           0 :     if ( aServiceNames.getLength() == 0 )
     130             :     {
     131           0 :         aServiceNames.realloc( 1 );
     132           0 :         aServiceNames[ 0 ] = "ooo.vba.msform.PictureFormat";
     133             :     }
     134           0 :     return aServiceNames;
     135         480 : }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10