LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/doc - zoomitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 64 82.8 %
Date: 2012-12-17 Functions: 13 15 86.7 %
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             : #include <basic/sbxvar.hxx>
      22             : 
      23             : #include <sfx2/zoomitem.hxx>
      24             : #include <com/sun/star/uno/Sequence.hxx>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : 
      27             : // -----------------------------------------------------------------------
      28             : 
      29         217 : TYPEINIT1_FACTORY(SvxZoomItem,SfxUInt16Item, new SvxZoomItem);
      30             : 
      31             : #define ZOOM_PARAM_VALUE    "Value"
      32             : #define ZOOM_PARAM_VALUESET "ValueSet"
      33             : #define ZOOM_PARAM_TYPE     "Type"
      34             : #define ZOOM_PARAMS         3
      35             : 
      36             : // -----------------------------------------------------------------------
      37             : 
      38          19 : SvxZoomItem::SvxZoomItem
      39             : (
      40             :     SvxZoomType eZoomType,
      41             :     sal_uInt16      nVal,
      42             :     sal_uInt16      _nWhich
      43             : )
      44             : :   SfxUInt16Item( _nWhich, nVal ),
      45             :     nValueSet( SVX_ZOOM_ENABLE_ALL ),
      46          19 :     eType( eZoomType )
      47             : {
      48          19 : }
      49             : 
      50             : // -----------------------------------------------------------------------
      51             : 
      52          39 : SvxZoomItem::SvxZoomItem( const SvxZoomItem& rOrig )
      53          78 : :   SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
      54          39 :     nValueSet( rOrig.GetValueSet() ),
      55         117 :     eType( rOrig.GetType() )
      56             : {
      57          39 : }
      58             : 
      59             : // -----------------------------------------------------------------------
      60             : 
      61          99 : SvxZoomItem::~SvxZoomItem()
      62             : {
      63          99 : }
      64             : 
      65             : // -----------------------------------------------------------------------
      66             : 
      67          39 : SfxPoolItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const
      68             : {
      69          39 :     return new SvxZoomItem( *this );
      70             : }
      71             : 
      72             : // -----------------------------------------------------------------------
      73             : 
      74           0 : SfxPoolItem* SvxZoomItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
      75             : {
      76             :     sal_uInt16 nValue;
      77             :     sal_uInt16 nValSet;
      78             :     sal_Int8 nType;
      79           0 :     rStrm >> nValue >> nValSet >> nType;
      80           0 :     SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
      81           0 :     pNew->SetValueSet( nValSet );
      82           0 :     return pNew;
      83             : }
      84             : 
      85             : // -----------------------------------------------------------------------
      86             : 
      87           0 : SvStream& SvxZoomItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
      88             : {
      89           0 :     rStrm << (sal_uInt16)GetValue()
      90           0 :           << nValueSet
      91           0 :           << (sal_Int8)eType;
      92           0 :     return rStrm;
      93             : }
      94             : 
      95             : // -----------------------------------------------------------------------
      96             : 
      97           1 : int SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
      98             : {
      99             :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
     100             : 
     101           1 :     SvxZoomItem& rItem = (SvxZoomItem&)rAttr;
     102             : 
     103           1 :     return ( GetValue() == rItem.GetValue()     &&
     104           1 :              nValueSet  == rItem.GetValueSet()  &&
     105           2 :              eType      == rItem.GetType()          );
     106             : }
     107             : 
     108           6 : bool SvxZoomItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
     109             : {
     110             : //  sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     111           6 :     nMemberId &= ~CONVERT_TWIPS;
     112             : 
     113             :     assert(nMemberId == 0);
     114             : 
     115           6 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOM_PARAMS );
     116           6 :     aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUE ));
     117           6 :     aSeq[0].Value <<= sal_Int32( GetValue() );
     118           6 :     aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUESET ));
     119           6 :     aSeq[1].Value <<= sal_Int16( nValueSet );
     120           6 :     aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_TYPE ));
     121           6 :     aSeq[2].Value <<= sal_Int16( eType );
     122           6 :     rVal <<= aSeq;
     123             : 
     124           6 :     return true;
     125             : }
     126             : 
     127           4 : bool SvxZoomItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
     128             : {
     129           4 :     nMemberId &= ~CONVERT_TWIPS;
     130             :     assert(nMemberId == 0);
     131             : 
     132           4 :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
     133           4 :     if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
     134             :     {
     135           4 :         sal_Int32 nValueTmp( 0 );
     136           4 :         sal_Int16 nValueSetTmp( 0 );
     137           4 :         sal_Int16 nTypeTmp( 0 );
     138           4 :         sal_Bool  bAllConverted( sal_True );
     139           4 :         sal_Int16 nConvertedCount( 0 );
     140          16 :         for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
     141             :         {
     142          12 :             if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUE ))
     143             :             {
     144           4 :                 bAllConverted &= ( aSeq[i].Value >>= nValueTmp );
     145           4 :                 ++nConvertedCount;
     146             :             }
     147           8 :             else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUESET ))
     148             :             {
     149           4 :                 bAllConverted &= ( aSeq[i].Value >>= nValueSetTmp );
     150           4 :                 ++nConvertedCount;
     151             :             }
     152           4 :             else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_TYPE ))
     153             :             {
     154           4 :                 bAllConverted &= ( aSeq[i].Value >>= nTypeTmp );
     155           4 :                 ++nConvertedCount;
     156             :             }
     157             :         }
     158             : 
     159           4 :         if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
     160             :         {
     161           4 :             SetValue( (sal_uInt16)nValueTmp );
     162           4 :             nValueSet = nValueSetTmp;
     163           4 :             eType = SvxZoomType( nTypeTmp );
     164           4 :             return true;
     165             :         }
     166             :     }
     167             : 
     168           0 :     return false;
     169             : }
     170             : 
     171             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10