1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: zoomitem.cxx,v $
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>
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"
51 // -----------------------------------------------------------------------
53 SvxZoomItem::SvxZoomItem
55 SvxZoomType eZoomType
,
59 : SfxUInt16Item( _nWhich
, nVal
),
60 nValueSet( SVX_ZOOM_ENABLE_ALL
),
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
94 rStrm
>> nValue
>> nValSet
>> nType
;
95 SvxZoomItem
* pNew
= new SvxZoomItem( (SvxZoomType
)nType
, nValue
, Which() );
96 pNew
->SetValueSet( nValSet
);
100 // -----------------------------------------------------------------------
102 SvStream
& SvxZoomItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
104 rStrm
<< (sal_uInt16
)GetValue()
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
;
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
);
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;
146 DBG_ERROR("svx::SvxZoomItem::QueryValue(), Wrong MemberId!");
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
;
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
);
176 else if ( aSeq
[i
].Name
.equalsAscii( ZOOM_PARAM_VALUESET
))
178 bAllConverted
&= ( aSeq
[i
].Value
>>= nValueSetTmp
);
181 else if ( aSeq
[i
].Name
.equalsAscii( ZOOM_PARAM_TYPE
))
183 bAllConverted
&= ( aSeq
[i
].Value
>>= nTypeTmp
);
188 if ( bAllConverted
&& nConvertedCount
== ZOOM_PARAMS
)
190 SetValue( (UINT16
)nValueTmp
);
191 nValueSet
= nValueSetTmp
;
192 eType
= SvxZoomType( nTypeTmp
);
205 SetValue( (UINT16
)nVal
);
215 sal_Int16 nVal
= sal_Int16();
218 if ( nMemberId
== MID_VALUESET
)
219 nValueSet
= (sal_Int16
) nVal
;
220 else if ( nMemberId
== MID_TYPE
)
221 eType
= SvxZoomType( (sal_Int16
) nVal
);
229 DBG_ERROR("svx::SvxZoomItem::PutValue(), Wrong MemberId!");