LCOV - code coverage report
Current view: top level - svx/source/items - zoomslideritem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 66 102 64.7 %
Date: 2014-11-03 Functions: 14 16 87.5 %
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             : 
      20             : #include <tools/stream.hxx>
      21             : 
      22             : #include <svx/zoomslideritem.hxx>
      23             : #include <com/sun/star/beans/PropertyValue.hpp>
      24             : 
      25             : 
      26             : 
      27       15034 : TYPEINIT1_FACTORY(SvxZoomSliderItem,SfxUInt16Item, new SvxZoomSliderItem);
      28             : 
      29             : #define ZOOMSLIDER_PARAM_CURRENTZOOM    "Columns"
      30             : #define ZOOMSLIDER_PARAM_SNAPPINGPOINTS "SnappingPoints"
      31             : #define ZOOMSLIDER_PARAM_MINZOOM        "MinValue"
      32             : #define ZOOMSLIDER_PARAM_MAXZOOM        "MaxValue"
      33             : #define ZOOMSLIDER_PARAMS           4
      34             : 
      35             : 
      36             : 
      37        3458 : SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, sal_uInt16 _nWhich )
      38        3458 : :   SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
      39             : {
      40        3458 : }
      41             : 
      42             : 
      43             : 
      44        3692 : SvxZoomSliderItem::SvxZoomSliderItem( const SvxZoomSliderItem& rOrig )
      45        7384 : : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() )
      46             : , maValues( rOrig.maValues )
      47             : , mnMinZoom( rOrig.mnMinZoom )
      48        7384 : , mnMaxZoom( rOrig.mnMaxZoom )
      49             : {
      50        3692 : }
      51             : 
      52             : 
      53             : 
      54       12552 : SvxZoomSliderItem::~SvxZoomSliderItem()
      55             : {
      56       12552 : }
      57             : 
      58             : 
      59             : 
      60        3692 : SfxPoolItem* SvxZoomSliderItem::Clone( SfxItemPool * /*pPool*/ ) const
      61             : {
      62        3692 :     return new SvxZoomSliderItem( *this );
      63             : }
      64             : 
      65             : 
      66             : 
      67           0 : SfxPoolItem* SvxZoomSliderItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const
      68             : {
      69           0 :     return 0;
      70             : }
      71             : 
      72             : 
      73             : 
      74           0 : SvStream& SvxZoomSliderItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
      75             : {
      76           0 :     return rStrm;
      77             : }
      78             : 
      79             : 
      80             : 
      81          44 : bool SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const
      82             : {
      83             :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
      84             : 
      85          44 :     const SvxZoomSliderItem& rItem = static_cast<const SvxZoomSliderItem&>(rAttr);
      86             : 
      87         116 :     return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
      88         116 :              mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
      89             : }
      90             : 
      91        1712 : bool SvxZoomSliderItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
      92             : {
      93        1712 :     nMemberId &= ~CONVERT_TWIPS;
      94        1712 :     switch ( nMemberId )
      95             :     {
      96             :         case 0 :
      97             :             {
      98        1712 :                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOMSLIDER_PARAMS );
      99        1712 :                 aSeq[0].Name = OUString( ZOOMSLIDER_PARAM_CURRENTZOOM );
     100        1712 :                 aSeq[0].Value <<= sal_Int32( GetValue() );
     101        1712 :                 aSeq[1].Name = OUString( ZOOMSLIDER_PARAM_SNAPPINGPOINTS );
     102        1712 :                 aSeq[1].Value <<= maValues;
     103        1712 :                 aSeq[2].Name = OUString( ZOOMSLIDER_PARAM_MINZOOM );
     104        1712 :                 aSeq[2].Value <<= mnMinZoom;
     105        1712 :                 aSeq[3].Name = OUString( ZOOMSLIDER_PARAM_MAXZOOM );
     106        1712 :                 aSeq[3].Value <<= mnMaxZoom;
     107        1712 :                 rVal <<= aSeq;
     108             :             }
     109        1712 :             break;
     110             : 
     111             :         case MID_ZOOMSLIDER_CURRENTZOOM :
     112             :             {
     113           0 :                 rVal <<= (sal_Int32) GetValue();
     114             :             }
     115           0 :             break;
     116             :         case MID_ZOOMSLIDER_SNAPPINGPOINTS:
     117             :             {
     118           0 :                  rVal <<= maValues;
     119             :             }
     120           0 :             break;
     121             :         case MID_ZOOMSLIDER_MINZOOM:
     122             :             {
     123           0 :                 rVal <<= mnMinZoom;
     124             :             }
     125           0 :             break;
     126             :         case MID_ZOOMSLIDER_MAXZOOM:
     127             :             {
     128           0 :                 rVal <<= mnMaxZoom;
     129             :             }
     130           0 :             break;
     131             :         default:
     132             :             OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
     133           0 :             return false;
     134             :     }
     135             : 
     136        1712 :     return true;
     137             : }
     138             : 
     139        1710 : bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
     140             : {
     141        1710 :     nMemberId &= ~CONVERT_TWIPS;
     142        1710 :     switch ( nMemberId )
     143             :     {
     144             :         case 0 :
     145             :             {
     146        1710 :                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
     147        1710 :                 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
     148             :                 {
     149        1710 :                     sal_Int32 nCurrentZoom( 0 );
     150        1710 :                     com::sun::star::uno::Sequence < sal_Int32 > aValues;
     151             : 
     152        1710 :                     bool bAllConverted( true );
     153        1710 :                     sal_Int16 nConvertedCount( 0 );
     154        1710 :                     sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
     155             : 
     156        8550 :                     for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
     157             :                     {
     158        6840 :                         if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_CURRENTZOOM ))
     159             :                         {
     160        1710 :                             bAllConverted &= ( aSeq[i].Value >>= nCurrentZoom );
     161        1710 :                             ++nConvertedCount;
     162             :                         }
     163        5130 :                         else if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_SNAPPINGPOINTS ))
     164             :                         {
     165        1710 :                             bAllConverted &= ( aSeq[i].Value >>= aValues );
     166        1710 :                             ++nConvertedCount;
     167             :                         }
     168        3420 :                         else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MINZOOM ) )
     169             :                         {
     170        1710 :                             bAllConverted &= ( aSeq[i].Value >>= nMinZoom );
     171        1710 :                             ++nConvertedCount;
     172             :                         }
     173        1710 :                         else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MAXZOOM ) )
     174             :                         {
     175        1710 :                             bAllConverted &= ( aSeq[i].Value >>= nMaxZoom );
     176        1710 :                             ++nConvertedCount;
     177             :                         }
     178             :                     }
     179             : 
     180        1710 :                     if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
     181             :                     {
     182        1710 :                         SetValue( (sal_uInt16)nCurrentZoom );
     183        1710 :                         maValues = aValues;
     184        1710 :                         mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
     185        1710 :                         mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
     186             : 
     187        1710 :                         return true;
     188           0 :                     }
     189             :                 }
     190             : 
     191           0 :                 return false;
     192             :             }
     193             : 
     194             :         case MID_ZOOMSLIDER_CURRENTZOOM:
     195             :             {
     196           0 :                 sal_Int32 nVal = 0;
     197           0 :                 if ( rVal >>= nVal )
     198             :                 {
     199           0 :                     SetValue( (sal_uInt16)nVal );
     200           0 :                     return true;
     201             :                 }
     202             :                 else
     203           0 :                     return false;
     204             :             }
     205             : 
     206             :         case MID_ZOOMSLIDER_SNAPPINGPOINTS:
     207             :             {
     208           0 :                 com::sun::star::uno::Sequence < sal_Int32 > aValues;
     209           0 :                 if ( rVal >>= aValues )
     210             :                 {
     211           0 :                     maValues = aValues;
     212           0 :                     return true;
     213             :                 }
     214             :                 else
     215           0 :                     return false;
     216             :             }
     217             :         case MID_ZOOMSLIDER_MINZOOM:
     218             :             {
     219           0 :                 sal_Int32 nVal = 0;
     220           0 :                 if( rVal >>= nVal )
     221             :                 {
     222           0 :                     mnMinZoom = (sal_uInt16)nVal;
     223           0 :                     return true;
     224             :                 }
     225             :                 else
     226           0 :                     return false;
     227             :             }
     228             :         case MID_ZOOMSLIDER_MAXZOOM:
     229             :             {
     230           0 :                 sal_Int32 nVal = 0;
     231           0 :                 if( rVal >>= nVal )
     232             :                 {
     233           0 :                     mnMaxZoom = (sal_uInt16)nVal;
     234           0 :                     return true;
     235             :                 }
     236             :                 else
     237           0 :                     return false;
     238             :             }
     239             :         default:
     240             :             OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
     241           0 :             return false;
     242             :     }
     243             : }
     244             : 
     245        4065 : void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew )
     246             : {
     247        4065 :     const sal_Int32 nValues = maValues.getLength();
     248        4065 :     maValues.realloc(  nValues + 1 );
     249        4065 :     sal_Int32* pValues = maValues.getArray();
     250        4065 :     pValues[ nValues ] = nNew;
     251        4065 : }
     252             : 
     253             : 
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10