xref: /aoo41x/main/svx/source/items/zoomitem.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <tools/stream.hxx>
27cdf0e10cSrcweir #ifndef __SBX_SBXVARIABLE_HXX
28cdf0e10cSrcweir #include <basic/sbxvar.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svx/zoomitem.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
33cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // -----------------------------------------------------------------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir TYPEINIT1_FACTORY(SvxZoomItem,SfxUInt16Item, new SvxZoomItem);
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #define ZOOM_PARAM_VALUE    "Value"
40cdf0e10cSrcweir #define ZOOM_PARAM_VALUESET "ValueSet"
41cdf0e10cSrcweir #define ZOOM_PARAM_TYPE     "Type"
42cdf0e10cSrcweir #define ZOOM_PARAMS         3
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // -----------------------------------------------------------------------
45cdf0e10cSrcweir 
SvxZoomItem(SvxZoomType eZoomType,sal_uInt16 nVal,sal_uInt16 _nWhich)46cdf0e10cSrcweir SvxZoomItem::SvxZoomItem
47cdf0e10cSrcweir (
48cdf0e10cSrcweir 	SvxZoomType eZoomType,
49cdf0e10cSrcweir 	sal_uInt16		nVal,
50cdf0e10cSrcweir     sal_uInt16      _nWhich
51cdf0e10cSrcweir )
52cdf0e10cSrcweir :   SfxUInt16Item( _nWhich, nVal ),
53cdf0e10cSrcweir 	nValueSet( SVX_ZOOM_ENABLE_ALL ),
54cdf0e10cSrcweir 	eType( eZoomType )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // -----------------------------------------------------------------------
59cdf0e10cSrcweir 
SvxZoomItem(const SvxZoomItem & rOrig)60cdf0e10cSrcweir SvxZoomItem::SvxZoomItem( const SvxZoomItem& rOrig )
61cdf0e10cSrcweir :	SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
62cdf0e10cSrcweir 	nValueSet( rOrig.GetValueSet() ),
63cdf0e10cSrcweir 	eType( rOrig.GetType() )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // -----------------------------------------------------------------------
68cdf0e10cSrcweir 
~SvxZoomItem()69cdf0e10cSrcweir SvxZoomItem::~SvxZoomItem()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // -----------------------------------------------------------------------
74cdf0e10cSrcweir 
Clone(SfxItemPool *) const75cdf0e10cSrcweir SfxPoolItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	return new SvxZoomItem( *this );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir // -----------------------------------------------------------------------
81cdf0e10cSrcweir 
Create(SvStream & rStrm,sal_uInt16) const82cdf0e10cSrcweir SfxPoolItem* SvxZoomItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	sal_uInt16 nValue;
85cdf0e10cSrcweir 	sal_uInt16 nValSet;
86cdf0e10cSrcweir 	sal_Int8 nType;
87cdf0e10cSrcweir 	rStrm >> nValue >> nValSet >> nType;
88cdf0e10cSrcweir 	SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
89cdf0e10cSrcweir 	pNew->SetValueSet( nValSet );
90cdf0e10cSrcweir 	return pNew;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir // -----------------------------------------------------------------------
94cdf0e10cSrcweir 
Store(SvStream & rStrm,sal_uInt16) const95cdf0e10cSrcweir SvStream& SvxZoomItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	rStrm << (sal_uInt16)GetValue()
98cdf0e10cSrcweir 		  << nValueSet
99cdf0e10cSrcweir 		  << (sal_Int8)eType;
100cdf0e10cSrcweir 	return rStrm;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // -----------------------------------------------------------------------
104cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rAttr) const105cdf0e10cSrcweir int SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	SvxZoomItem& rItem = (SvxZoomItem&)rAttr;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	return ( GetValue() == rItem.GetValue() 	&&
112cdf0e10cSrcweir 			 nValueSet 	== rItem.GetValueSet() 	&&
113cdf0e10cSrcweir 			 eType 		== rItem.GetType() 			);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8 nMemberId) const116cdf0e10cSrcweir sal_Bool SvxZoomItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir //  sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
119cdf0e10cSrcweir 	nMemberId &= ~CONVERT_TWIPS;
120cdf0e10cSrcweir     switch ( nMemberId )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         case 0 :
123cdf0e10cSrcweir         {
124cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOM_PARAMS );
125cdf0e10cSrcweir             aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUE ));
126cdf0e10cSrcweir             aSeq[0].Value <<= sal_Int32( GetValue() );
127cdf0e10cSrcweir             aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUESET ));
128cdf0e10cSrcweir             aSeq[1].Value <<= sal_Int16( nValueSet );
129cdf0e10cSrcweir             aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_TYPE ));
130cdf0e10cSrcweir             aSeq[2].Value <<= sal_Int16( eType );
131cdf0e10cSrcweir             rVal <<= aSeq;
132cdf0e10cSrcweir         }
133cdf0e10cSrcweir         break;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         case MID_VALUE: rVal <<= (sal_Int32) GetValue(); break;
136cdf0e10cSrcweir         case MID_VALUESET: rVal <<= (sal_Int16) nValueSet; break;
137cdf0e10cSrcweir         case MID_TYPE: rVal <<= (sal_Int16) eType; break;
138cdf0e10cSrcweir 		default:
139cdf0e10cSrcweir 			DBG_ERROR("svx::SvxZoomItem::QueryValue(), Wrong MemberId!");
140cdf0e10cSrcweir 			return sal_False;
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     return sal_True;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8 nMemberId)146cdf0e10cSrcweir sal_Bool SvxZoomItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir //  sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
149cdf0e10cSrcweir 	nMemberId &= ~CONVERT_TWIPS;
150cdf0e10cSrcweir     switch ( nMemberId )
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         case 0 :
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
155cdf0e10cSrcweir             if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
156cdf0e10cSrcweir             {
157cdf0e10cSrcweir                 sal_Int32 nValueTmp( 0 );
158cdf0e10cSrcweir                 sal_Int16 nValueSetTmp( 0 );
159cdf0e10cSrcweir                 sal_Int16 nTypeTmp( 0 );
160cdf0e10cSrcweir                 sal_Bool  bAllConverted( sal_True );
161cdf0e10cSrcweir                 sal_Int16 nConvertedCount( 0 );
162cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
163cdf0e10cSrcweir                 {
164cdf0e10cSrcweir                     if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUE ))
165cdf0e10cSrcweir                     {
166cdf0e10cSrcweir                         bAllConverted &= ( aSeq[i].Value >>= nValueTmp );
167cdf0e10cSrcweir                         ++nConvertedCount;
168cdf0e10cSrcweir                     }
169cdf0e10cSrcweir                     else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUESET ))
170cdf0e10cSrcweir                     {
171cdf0e10cSrcweir                         bAllConverted &= ( aSeq[i].Value >>= nValueSetTmp );
172cdf0e10cSrcweir                         ++nConvertedCount;
173cdf0e10cSrcweir                     }
174cdf0e10cSrcweir                     else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_TYPE ))
175cdf0e10cSrcweir                     {
176cdf0e10cSrcweir                         bAllConverted &= ( aSeq[i].Value >>= nTypeTmp );
177cdf0e10cSrcweir                         ++nConvertedCount;
178cdf0e10cSrcweir                     }
179cdf0e10cSrcweir                 }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir                 if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
182cdf0e10cSrcweir                 {
183cdf0e10cSrcweir                     SetValue( (sal_uInt16)nValueTmp );
184cdf0e10cSrcweir                     nValueSet = nValueSetTmp;
185cdf0e10cSrcweir                     eType = SvxZoomType( nTypeTmp );
186cdf0e10cSrcweir                     return sal_True;
187cdf0e10cSrcweir                 }
188cdf0e10cSrcweir             }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             return sal_False;
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         case MID_VALUE:
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir             sal_Int32 nVal = 0;
196cdf0e10cSrcweir             if ( rVal >>= nVal )
197cdf0e10cSrcweir             {
198cdf0e10cSrcweir                 SetValue( (sal_uInt16)nVal );
199cdf0e10cSrcweir                 return sal_True;
200cdf0e10cSrcweir             }
201cdf0e10cSrcweir             else
202cdf0e10cSrcweir                 return sal_False;
203cdf0e10cSrcweir         }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         case MID_VALUESET:
206cdf0e10cSrcweir         case MID_TYPE:
207cdf0e10cSrcweir         {
208cdf0e10cSrcweir             sal_Int16 nVal = sal_Int16();
209cdf0e10cSrcweir             if ( rVal >>= nVal )
210cdf0e10cSrcweir             {
211cdf0e10cSrcweir                 if ( nMemberId == MID_VALUESET )
212cdf0e10cSrcweir                     nValueSet = (sal_Int16) nVal;
213cdf0e10cSrcweir                 else if ( nMemberId == MID_TYPE )
214cdf0e10cSrcweir                     eType = SvxZoomType( (sal_Int16) nVal );
215cdf0e10cSrcweir                 return sal_True;
216cdf0e10cSrcweir             }
217cdf0e10cSrcweir             else
218cdf0e10cSrcweir                 return sal_False;
219cdf0e10cSrcweir         }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         default:
222cdf0e10cSrcweir 			DBG_ERROR("svx::SvxZoomItem::PutValue(), Wrong MemberId!");
223cdf0e10cSrcweir 			return sal_False;
224cdf0e10cSrcweir     }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     return sal_True;
227cdf0e10cSrcweir }
228