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