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