update dev300-m58
[ooovba.git] / svx / source / items / zoomitem.cxx
blobab13d3c09fee8bfd2fd069f7e604b4286b92993a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: zoomitem.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <tools/stream.hxx>
34 #ifndef __SBX_SBXVARIABLE_HXX
35 #include <basic/sbxvar.hxx>
36 #endif
38 #include <svx/zoomitem.hxx>
39 #include <com/sun/star/uno/Sequence.hxx>
40 #include <com/sun/star/beans/PropertyValue.hpp>
42 // -----------------------------------------------------------------------
44 TYPEINIT1_FACTORY(SvxZoomItem,SfxUInt16Item, new SvxZoomItem);
46 #define ZOOM_PARAM_VALUE "Value"
47 #define ZOOM_PARAM_VALUESET "ValueSet"
48 #define ZOOM_PARAM_TYPE "Type"
49 #define ZOOM_PARAMS 3
51 // -----------------------------------------------------------------------
53 SvxZoomItem::SvxZoomItem
55 SvxZoomType eZoomType,
56 sal_uInt16 nVal,
57 sal_uInt16 _nWhich
59 : SfxUInt16Item( _nWhich, nVal ),
60 nValueSet( SVX_ZOOM_ENABLE_ALL ),
61 eType( eZoomType )
65 // -----------------------------------------------------------------------
67 SvxZoomItem::SvxZoomItem( const SvxZoomItem& rOrig )
68 : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
69 nValueSet( rOrig.GetValueSet() ),
70 eType( rOrig.GetType() )
74 // -----------------------------------------------------------------------
76 SvxZoomItem::~SvxZoomItem()
80 // -----------------------------------------------------------------------
82 SfxPoolItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const
84 return new SvxZoomItem( *this );
87 // -----------------------------------------------------------------------
89 SfxPoolItem* SvxZoomItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
91 sal_uInt16 nValue;
92 sal_uInt16 nValSet;
93 sal_Int8 nType;
94 rStrm >> nValue >> nValSet >> nType;
95 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
96 pNew->SetValueSet( nValSet );
97 return pNew;
100 // -----------------------------------------------------------------------
102 SvStream& SvxZoomItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
104 rStrm << (sal_uInt16)GetValue()
105 << nValueSet
106 << (sal_Int8)eType;
107 return rStrm;
110 // -----------------------------------------------------------------------
112 int SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
114 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
116 SvxZoomItem& rItem = (SvxZoomItem&)rAttr;
118 return ( GetValue() == rItem.GetValue() &&
119 nValueSet == rItem.GetValueSet() &&
120 eType == rItem.GetType() );
123 sal_Bool SvxZoomItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId ) const
125 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
126 nMemberId &= ~CONVERT_TWIPS;
127 switch ( nMemberId )
129 case 0 :
131 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOM_PARAMS );
132 aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUE ));
133 aSeq[0].Value <<= sal_Int32( GetValue() );
134 aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUESET ));
135 aSeq[1].Value <<= sal_Int16( nValueSet );
136 aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_TYPE ));
137 aSeq[2].Value <<= sal_Int16( eType );
138 rVal <<= aSeq;
140 break;
142 case MID_VALUE: rVal <<= (sal_Int32) GetValue(); break;
143 case MID_VALUESET: rVal <<= (sal_Int16) nValueSet; break;
144 case MID_TYPE: rVal <<= (sal_Int16) eType; break;
145 default:
146 DBG_ERROR("svx::SvxZoomItem::QueryValue(), Wrong MemberId!");
147 return sal_False;
150 return sal_True;
153 sal_Bool SvxZoomItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId )
155 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
156 nMemberId &= ~CONVERT_TWIPS;
157 switch ( nMemberId )
159 case 0 :
161 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
162 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
164 sal_Int32 nValueTmp( 0 );
165 sal_Int16 nValueSetTmp( 0 );
166 sal_Int16 nTypeTmp( 0 );
167 sal_Bool bAllConverted( sal_True );
168 sal_Int16 nConvertedCount( 0 );
169 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
171 if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUE ))
173 bAllConverted &= ( aSeq[i].Value >>= nValueTmp );
174 ++nConvertedCount;
176 else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUESET ))
178 bAllConverted &= ( aSeq[i].Value >>= nValueSetTmp );
179 ++nConvertedCount;
181 else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_TYPE ))
183 bAllConverted &= ( aSeq[i].Value >>= nTypeTmp );
184 ++nConvertedCount;
188 if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
190 SetValue( (UINT16)nValueTmp );
191 nValueSet = nValueSetTmp;
192 eType = SvxZoomType( nTypeTmp );
193 return sal_True;
197 return sal_False;
200 case MID_VALUE:
202 sal_Int32 nVal = 0;
203 if ( rVal >>= nVal )
205 SetValue( (UINT16)nVal );
206 return sal_True;
208 else
209 return sal_False;
212 case MID_VALUESET:
213 case MID_TYPE:
215 sal_Int16 nVal = sal_Int16();
216 if ( rVal >>= nVal )
218 if ( nMemberId == MID_VALUESET )
219 nValueSet = (sal_Int16) nVal;
220 else if ( nMemberId == MID_TYPE )
221 eType = SvxZoomType( (sal_Int16) nVal );
222 return sal_True;
224 else
225 return sal_False;
228 default:
229 DBG_ERROR("svx::SvxZoomItem::PutValue(), Wrong MemberId!");
230 return sal_False;
233 return sal_True;