LCOV - code coverage report
Current view: top level - svx/source/items - zoomslideritem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 71 104 68.3 %
Date: 2012-08-25 Functions: 15 17 88.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 65 144 45.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <tools/stream.hxx>
      30                 :            : 
      31                 :            : #include <svx/zoomslideritem.hxx>
      32                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      33                 :            : 
      34                 :            : // -----------------------------------------------------------------------
      35                 :            : 
      36 [ -  + ][ -  + ]:      17642 : TYPEINIT1_FACTORY(SvxZoomSliderItem,SfxUInt16Item, new SvxZoomSliderItem);
                 [ +  - ]
      37                 :            : 
      38                 :            : #define ZOOMSLIDER_PARAM_CURRENTZOOM    "Columns"
      39                 :            : #define ZOOMSLIDER_PARAM_SNAPPINGPOINTS "SnappingPoints"
      40                 :            : #define ZOOMSLIDER_PARAM_MINZOOM        "MinValue"
      41                 :            : #define ZOOMSLIDER_PARAM_MAXZOOM        "MaxValue"
      42                 :            : #define ZOOMSLIDER_PARAMS           4
      43                 :            : 
      44                 :            : // -----------------------------------------------------------------------
      45                 :            : 
      46                 :       3825 : SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, sal_uInt16 _nWhich )
      47         [ +  - ]:       3825 : :   SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
      48                 :            : {
      49                 :       3825 : }
      50                 :            : 
      51                 :            : // -----------------------------------------------------------------------
      52                 :            : 
      53                 :       4517 : SvxZoomSliderItem::SvxZoomSliderItem( const SvxZoomSliderItem& rOrig )
      54                 :       4517 : : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() )
      55                 :            : , maValues( rOrig.maValues )
      56                 :            : , mnMinZoom( rOrig.mnMinZoom )
      57         [ +  - ]:       4517 : , mnMaxZoom( rOrig.mnMaxZoom )
      58                 :            : {
      59                 :       4517 : }
      60                 :            : 
      61                 :            : // -----------------------------------------------------------------------
      62                 :            : 
      63         [ +  - ]:       8338 : SvxZoomSliderItem::~SvxZoomSliderItem()
      64                 :            : {
      65         [ -  + ]:      14662 : }
      66                 :            : 
      67                 :            : // -----------------------------------------------------------------------
      68                 :            : 
      69                 :       4517 : SfxPoolItem* SvxZoomSliderItem::Clone( SfxItemPool * /*pPool*/ ) const
      70                 :            : {
      71         [ +  - ]:       4517 :     return new SvxZoomSliderItem( *this );
      72                 :            : }
      73                 :            : 
      74                 :            : // -----------------------------------------------------------------------
      75                 :            : 
      76                 :          0 : SfxPoolItem* SvxZoomSliderItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const
      77                 :            : {
      78                 :          0 :     return 0;
      79                 :            : }
      80                 :            : 
      81                 :            : // -----------------------------------------------------------------------
      82                 :            : 
      83                 :          0 : SvStream& SvxZoomSliderItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
      84                 :            : {
      85                 :          0 :     return rStrm;
      86                 :            : }
      87                 :            : 
      88                 :            : // -----------------------------------------------------------------------
      89                 :            : 
      90                 :        226 : int SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const
      91                 :            : {
      92                 :            :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
      93                 :            : 
      94                 :        226 :     SvxZoomSliderItem& rItem = (SvxZoomSliderItem&)rAttr;
      95                 :            : 
      96                 :        430 :     return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
      97 [ +  - ][ +  - ]:        430 :              mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
           [ +  +  +  + ]
      98                 :            : }
      99                 :            : 
     100                 :       1814 : bool SvxZoomSliderItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
     101                 :            : {
     102                 :       1814 :     nMemberId &= ~CONVERT_TWIPS;
     103   [ +  -  -  -  :       1814 :     switch ( nMemberId )
                   -  - ]
     104                 :            :     {
     105                 :            :         case 0 :
     106                 :            :             {
     107         [ +  - ]:       1814 :                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOMSLIDER_PARAMS );
     108 [ +  - ][ +  - ]:       1814 :                 aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_CURRENTZOOM ));
     109 [ +  - ][ +  - ]:       1814 :                 aSeq[0].Value <<= sal_Int32( GetValue() );
     110 [ +  - ][ +  - ]:       1814 :                 aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_SNAPPINGPOINTS ));
     111 [ +  - ][ +  - ]:       1814 :                 aSeq[1].Value <<= maValues;
     112 [ +  - ][ +  - ]:       1814 :                 aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_MINZOOM ) );
     113 [ +  - ][ +  - ]:       1814 :                 aSeq[2].Value <<= mnMinZoom;
     114 [ +  - ][ +  - ]:       1814 :                 aSeq[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_MAXZOOM ) );
     115 [ +  - ][ +  - ]:       1814 :                 aSeq[3].Value <<= mnMaxZoom;
     116 [ +  - ][ +  - ]:       1814 :                 rVal <<= aSeq;
     117                 :            :             }
     118                 :       1814 :             break;
     119                 :            : 
     120                 :            :         case MID_ZOOMSLIDER_CURRENTZOOM :
     121                 :            :             {
     122         [ #  # ]:          0 :                 rVal <<= (sal_Int32) GetValue();
     123                 :            :             }
     124                 :          0 :             break;
     125                 :            :         case MID_ZOOMSLIDER_SNAPPINGPOINTS:
     126                 :            :             {
     127                 :          0 :                  rVal <<= maValues;
     128                 :            :             }
     129                 :          0 :             break;
     130                 :            :         case MID_ZOOMSLIDER_MINZOOM:
     131                 :            :             {
     132                 :          0 :                 rVal <<= mnMinZoom;
     133                 :            :             }
     134                 :          0 :             break;
     135                 :            :         case MID_ZOOMSLIDER_MAXZOOM:
     136                 :            :             {
     137                 :          0 :                 rVal <<= mnMaxZoom;
     138                 :            :             }
     139                 :          0 :             break;
     140                 :            :         default:
     141                 :            :             OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
     142                 :          0 :             return false;
     143                 :            :     }
     144                 :            : 
     145                 :       1814 :     return true;
     146                 :            : }
     147                 :            : 
     148                 :       1811 : bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
     149                 :            : {
     150                 :       1811 :     nMemberId &= ~CONVERT_TWIPS;
     151   [ +  -  -  -  :       1811 :     switch ( nMemberId )
                   -  - ]
     152                 :            :     {
     153                 :            :         case 0 :
     154                 :            :             {
     155         [ +  - ]:       1811 :                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
     156 [ +  - ][ +  - ]:       1811 :                 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
         [ +  - ][ +  - ]
     157                 :            :                 {
     158                 :       1811 :                     sal_Int32 nCurrentZoom( 0 );
     159         [ +  - ]:       1811 :                     com::sun::star::uno::Sequence < sal_Int32 > aValues;
     160                 :            : 
     161                 :       1811 :                     sal_Bool  bAllConverted( sal_True );
     162                 :       1811 :                     sal_Int16 nConvertedCount( 0 );
     163                 :       1811 :                     sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
     164                 :            : 
     165         [ +  + ]:       9055 :                     for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
     166                 :            :                     {
     167 [ +  - ][ +  + ]:       7244 :                         if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_CURRENTZOOM ))
     168                 :            :                         {
     169         [ +  - ]:       1811 :                             bAllConverted &= ( aSeq[i].Value >>= nCurrentZoom );
     170                 :       1811 :                             ++nConvertedCount;
     171                 :            :                         }
     172 [ +  - ][ +  + ]:       5433 :                         else if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_SNAPPINGPOINTS ))
     173                 :            :                         {
     174 [ +  - ][ +  - ]:       1811 :                             bAllConverted &= ( aSeq[i].Value >>= aValues );
     175                 :       1811 :                             ++nConvertedCount;
     176                 :            :                         }
     177 [ +  - ][ +  + ]:       3622 :                         else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MINZOOM ) )
     178                 :            :                         {
     179         [ +  - ]:       1811 :                             bAllConverted &= ( aSeq[i].Value >>= nMinZoom );
     180                 :       1811 :                             ++nConvertedCount;
     181                 :            :                         }
     182 [ +  - ][ +  - ]:       1811 :                         else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MAXZOOM ) )
     183                 :            :                         {
     184         [ +  - ]:       1811 :                             bAllConverted &= ( aSeq[i].Value >>= nMaxZoom );
     185                 :       1811 :                             ++nConvertedCount;
     186                 :            :                         }
     187                 :            :                     }
     188                 :            : 
     189 [ +  - ][ +  - ]:       1811 :                     if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
     190                 :            :                     {
     191                 :       1811 :                         SetValue( (sal_uInt16)nCurrentZoom );
     192         [ +  - ]:       1811 :                         maValues = aValues;
     193                 :       1811 :                         mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
     194                 :       1811 :                         mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
     195                 :            : 
     196                 :       1811 :                         return true;
     197 [ +  - ][ -  + ]:       1811 :                     }
     198                 :            :                 }
     199                 :            : 
     200         [ +  - ]:       1811 :                 return false;
     201                 :            :             }
     202                 :            : 
     203                 :            :         case MID_ZOOMSLIDER_CURRENTZOOM:
     204                 :            :             {
     205                 :          0 :                 sal_Int32 nVal = 0;
     206         [ #  # ]:          0 :                 if ( rVal >>= nVal )
     207                 :            :                 {
     208                 :          0 :                     SetValue( (sal_uInt16)nVal );
     209                 :          0 :                     return true;
     210                 :            :                 }
     211                 :            :                 else
     212                 :          0 :                     return false;
     213                 :            :             }
     214                 :            : 
     215                 :            :         case MID_ZOOMSLIDER_SNAPPINGPOINTS:
     216                 :            :             {
     217         [ #  # ]:          0 :                 com::sun::star::uno::Sequence < sal_Int32 > aValues;
     218 [ #  # ][ #  # ]:          0 :                 if ( rVal >>= aValues )
     219                 :            :                 {
     220         [ #  # ]:          0 :                     maValues = aValues;
     221                 :          0 :                     return true;
     222                 :            :                 }
     223                 :            :                 else
     224         [ #  # ]:          0 :                     return false;
     225                 :            :             }
     226                 :            :         case MID_ZOOMSLIDER_MINZOOM:
     227                 :            :             {
     228                 :          0 :                 sal_Int32 nVal = 0;
     229         [ #  # ]:          0 :                 if( rVal >>= nVal )
     230                 :            :                 {
     231                 :          0 :                     mnMinZoom = (sal_uInt16)nVal;
     232                 :          0 :                     return true;
     233                 :            :                 }
     234                 :            :                 else
     235                 :          0 :                     return false;
     236                 :            :             }
     237                 :            :         case MID_ZOOMSLIDER_MAXZOOM:
     238                 :            :             {
     239                 :          0 :                 sal_Int32 nVal = 0;
     240         [ #  # ]:          0 :                 if( rVal >>= nVal )
     241                 :            :                 {
     242                 :          0 :                     mnMaxZoom = (sal_uInt16)nVal;
     243                 :          0 :                     return true;
     244                 :            :                 }
     245                 :            :                 else
     246                 :          0 :                     return false;
     247                 :            :             }
     248                 :            :         default:
     249                 :            :             OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
     250                 :       1811 :             return false;
     251                 :            :     }
     252                 :            : }
     253                 :            : 
     254                 :       5008 : void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew )
     255                 :            : {
     256                 :       5008 :     const sal_Int32 nValues = maValues.getLength();
     257                 :       5008 :     maValues.realloc(  nValues + 1 );
     258                 :       5008 :     sal_Int32* pValues = maValues.getArray();
     259                 :       5008 :     pValues[ nValues ] = nNew;
     260                 :       5008 : }
     261                 :            : 
     262                 :       1811 : const com::sun::star::uno::Sequence < sal_Int32 >& SvxZoomSliderItem::GetSnappingPoints() const
     263                 :            : {
     264                 :       1811 :     return maValues;
     265                 :            : }
     266                 :            : 
     267                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10