1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svx.hxx" 30*cdf0e10cSrcweir #include <tools/stream.hxx> 31*cdf0e10cSrcweir #ifndef __SBX_SBXVARIABLE_HXX 32*cdf0e10cSrcweir #include <basic/sbxvar.hxx> 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <svx/zoomitem.hxx> 36*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 37*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // ----------------------------------------------------------------------- 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir TYPEINIT1_FACTORY(SvxZoomItem,SfxUInt16Item, new SvxZoomItem); 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #define ZOOM_PARAM_VALUE "Value" 44*cdf0e10cSrcweir #define ZOOM_PARAM_VALUESET "ValueSet" 45*cdf0e10cSrcweir #define ZOOM_PARAM_TYPE "Type" 46*cdf0e10cSrcweir #define ZOOM_PARAMS 3 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir // ----------------------------------------------------------------------- 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir SvxZoomItem::SvxZoomItem 51*cdf0e10cSrcweir ( 52*cdf0e10cSrcweir SvxZoomType eZoomType, 53*cdf0e10cSrcweir sal_uInt16 nVal, 54*cdf0e10cSrcweir sal_uInt16 _nWhich 55*cdf0e10cSrcweir ) 56*cdf0e10cSrcweir : SfxUInt16Item( _nWhich, nVal ), 57*cdf0e10cSrcweir nValueSet( SVX_ZOOM_ENABLE_ALL ), 58*cdf0e10cSrcweir eType( eZoomType ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir // ----------------------------------------------------------------------- 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir SvxZoomItem::SvxZoomItem( const SvxZoomItem& rOrig ) 65*cdf0e10cSrcweir : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ), 66*cdf0e10cSrcweir nValueSet( rOrig.GetValueSet() ), 67*cdf0e10cSrcweir eType( rOrig.GetType() ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // ----------------------------------------------------------------------- 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir SvxZoomItem::~SvxZoomItem() 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // ----------------------------------------------------------------------- 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir SfxPoolItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir return new SvxZoomItem( *this ); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir // ----------------------------------------------------------------------- 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir SfxPoolItem* SvxZoomItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir sal_uInt16 nValue; 89*cdf0e10cSrcweir sal_uInt16 nValSet; 90*cdf0e10cSrcweir sal_Int8 nType; 91*cdf0e10cSrcweir rStrm >> nValue >> nValSet >> nType; 92*cdf0e10cSrcweir SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() ); 93*cdf0e10cSrcweir pNew->SetValueSet( nValSet ); 94*cdf0e10cSrcweir return pNew; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // ----------------------------------------------------------------------- 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir SvStream& SvxZoomItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir rStrm << (sal_uInt16)GetValue() 102*cdf0e10cSrcweir << nValueSet 103*cdf0e10cSrcweir << (sal_Int8)eType; 104*cdf0e10cSrcweir return rStrm; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // ----------------------------------------------------------------------- 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir int SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir SvxZoomItem& rItem = (SvxZoomItem&)rAttr; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir return ( GetValue() == rItem.GetValue() && 116*cdf0e10cSrcweir nValueSet == rItem.GetValueSet() && 117*cdf0e10cSrcweir eType == rItem.GetType() ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir sal_Bool SvxZoomItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); 123*cdf0e10cSrcweir nMemberId &= ~CONVERT_TWIPS; 124*cdf0e10cSrcweir switch ( nMemberId ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir case 0 : 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOM_PARAMS ); 129*cdf0e10cSrcweir aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUE )); 130*cdf0e10cSrcweir aSeq[0].Value <<= sal_Int32( GetValue() ); 131*cdf0e10cSrcweir aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUESET )); 132*cdf0e10cSrcweir aSeq[1].Value <<= sal_Int16( nValueSet ); 133*cdf0e10cSrcweir aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_TYPE )); 134*cdf0e10cSrcweir aSeq[2].Value <<= sal_Int16( eType ); 135*cdf0e10cSrcweir rVal <<= aSeq; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir break; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir case MID_VALUE: rVal <<= (sal_Int32) GetValue(); break; 140*cdf0e10cSrcweir case MID_VALUESET: rVal <<= (sal_Int16) nValueSet; break; 141*cdf0e10cSrcweir case MID_TYPE: rVal <<= (sal_Int16) eType; break; 142*cdf0e10cSrcweir default: 143*cdf0e10cSrcweir DBG_ERROR("svx::SvxZoomItem::QueryValue(), Wrong MemberId!"); 144*cdf0e10cSrcweir return sal_False; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir return sal_True; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir sal_Bool SvxZoomItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); 153*cdf0e10cSrcweir nMemberId &= ~CONVERT_TWIPS; 154*cdf0e10cSrcweir switch ( nMemberId ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir case 0 : 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq; 159*cdf0e10cSrcweir if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS )) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir sal_Int32 nValueTmp( 0 ); 162*cdf0e10cSrcweir sal_Int16 nValueSetTmp( 0 ); 163*cdf0e10cSrcweir sal_Int16 nTypeTmp( 0 ); 164*cdf0e10cSrcweir sal_Bool bAllConverted( sal_True ); 165*cdf0e10cSrcweir sal_Int16 nConvertedCount( 0 ); 166*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUE )) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir bAllConverted &= ( aSeq[i].Value >>= nValueTmp ); 171*cdf0e10cSrcweir ++nConvertedCount; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUESET )) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir bAllConverted &= ( aSeq[i].Value >>= nValueSetTmp ); 176*cdf0e10cSrcweir ++nConvertedCount; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_TYPE )) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir bAllConverted &= ( aSeq[i].Value >>= nTypeTmp ); 181*cdf0e10cSrcweir ++nConvertedCount; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir if ( bAllConverted && nConvertedCount == ZOOM_PARAMS ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir SetValue( (sal_uInt16)nValueTmp ); 188*cdf0e10cSrcweir nValueSet = nValueSetTmp; 189*cdf0e10cSrcweir eType = SvxZoomType( nTypeTmp ); 190*cdf0e10cSrcweir return sal_True; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir return sal_False; 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir case MID_VALUE: 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir sal_Int32 nVal = 0; 200*cdf0e10cSrcweir if ( rVal >>= nVal ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir SetValue( (sal_uInt16)nVal ); 203*cdf0e10cSrcweir return sal_True; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir else 206*cdf0e10cSrcweir return sal_False; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir case MID_VALUESET: 210*cdf0e10cSrcweir case MID_TYPE: 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir sal_Int16 nVal = sal_Int16(); 213*cdf0e10cSrcweir if ( rVal >>= nVal ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir if ( nMemberId == MID_VALUESET ) 216*cdf0e10cSrcweir nValueSet = (sal_Int16) nVal; 217*cdf0e10cSrcweir else if ( nMemberId == MID_TYPE ) 218*cdf0e10cSrcweir eType = SvxZoomType( (sal_Int16) nVal ); 219*cdf0e10cSrcweir return sal_True; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir else 222*cdf0e10cSrcweir return sal_False; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir default: 226*cdf0e10cSrcweir DBG_ERROR("svx::SvxZoomItem::PutValue(), Wrong MemberId!"); 227*cdf0e10cSrcweir return sal_False; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir return sal_True; 231*cdf0e10cSrcweir } 232