1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/stream.hxx>
21 #include <basic/sbxvar.hxx>
23 #include <sfx2/zoomitem.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/beans/PropertyValue.hpp>
27 // -----------------------------------------------------------------------
29 TYPEINIT1_FACTORY(SvxZoomItem
,SfxUInt16Item
, new SvxZoomItem
);
31 #define ZOOM_PARAM_VALUE "Value"
32 #define ZOOM_PARAM_VALUESET "ValueSet"
33 #define ZOOM_PARAM_TYPE "Type"
36 // -----------------------------------------------------------------------
38 SvxZoomItem::SvxZoomItem
40 SvxZoomType eZoomType
,
44 : SfxUInt16Item( _nWhich
, nVal
),
45 nValueSet( SVX_ZOOM_ENABLE_ALL
),
50 // -----------------------------------------------------------------------
52 SvxZoomItem::SvxZoomItem( const SvxZoomItem
& rOrig
)
53 : SfxUInt16Item( rOrig
.Which(), rOrig
.GetValue() ),
54 nValueSet( rOrig
.GetValueSet() ),
55 eType( rOrig
.GetType() )
59 // -----------------------------------------------------------------------
61 SvxZoomItem::~SvxZoomItem()
65 // -----------------------------------------------------------------------
67 SfxPoolItem
* SvxZoomItem::Clone( SfxItemPool
* /*pPool*/ ) const
69 return new SvxZoomItem( *this );
72 // -----------------------------------------------------------------------
74 SfxPoolItem
* SvxZoomItem::Create( SvStream
& rStrm
, sal_uInt16
/*nVersion*/ ) const
79 rStrm
>> nValue
>> nValSet
>> nType
;
80 SvxZoomItem
* pNew
= new SvxZoomItem( (SvxZoomType
)nType
, nValue
, Which() );
81 pNew
->SetValueSet( nValSet
);
85 // -----------------------------------------------------------------------
87 SvStream
& SvxZoomItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
89 rStrm
<< (sal_uInt16
)GetValue()
95 // -----------------------------------------------------------------------
97 int SvxZoomItem::operator==( const SfxPoolItem
& rAttr
) const
99 DBG_ASSERT( SfxPoolItem::operator==(rAttr
), "unequal types" );
101 SvxZoomItem
& rItem
= (SvxZoomItem
&)rAttr
;
103 return ( GetValue() == rItem
.GetValue() &&
104 nValueSet
== rItem
.GetValueSet() &&
105 eType
== rItem
.GetType() );
108 bool SvxZoomItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
110 nMemberId
&= ~CONVERT_TWIPS
;
115 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq( ZOOM_PARAMS
);
116 aSeq
[0].Name
= OUString( ZOOM_PARAM_VALUE
);
117 aSeq
[0].Value
<<= sal_Int32( GetValue() );
118 aSeq
[1].Name
= OUString( ZOOM_PARAM_VALUESET
);
119 aSeq
[1].Value
<<= sal_Int16( nValueSet
);
120 aSeq
[2].Name
= OUString( ZOOM_PARAM_TYPE
);
121 aSeq
[2].Value
<<= sal_Int16( eType
);
126 case MID_VALUE
: rVal
<<= (sal_Int32
) GetValue(); break;
127 case MID_VALUESET
: rVal
<<= (sal_Int16
) nValueSet
; break;
128 case MID_TYPE
: rVal
<<= (sal_Int16
) eType
; break;
130 OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
137 bool SvxZoomItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
139 nMemberId
&= ~CONVERT_TWIPS
;
144 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq
;
145 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == ZOOM_PARAMS
))
147 sal_Int32
nValueTmp( 0 );
148 sal_Int16
nValueSetTmp( 0 );
149 sal_Int16
nTypeTmp( 0 );
150 sal_Bool
bAllConverted( sal_True
);
151 sal_Int16
nConvertedCount( 0 );
152 for ( sal_Int32 i
= 0; i
< aSeq
.getLength(); i
++ )
154 if ( aSeq
[i
].Name
.equalsAscii( ZOOM_PARAM_VALUE
))
156 bAllConverted
&= ( aSeq
[i
].Value
>>= nValueTmp
);
159 else if ( aSeq
[i
].Name
.equalsAscii( ZOOM_PARAM_VALUESET
))
161 bAllConverted
&= ( aSeq
[i
].Value
>>= nValueSetTmp
);
164 else if ( aSeq
[i
].Name
.equalsAscii( ZOOM_PARAM_TYPE
))
166 bAllConverted
&= ( aSeq
[i
].Value
>>= nTypeTmp
);
171 if ( bAllConverted
&& nConvertedCount
== ZOOM_PARAMS
)
173 SetValue( (sal_uInt16
)nValueTmp
);
174 nValueSet
= nValueSetTmp
;
175 eType
= SvxZoomType( nTypeTmp
);
186 SetValue( (sal_uInt16
)nVal
);
196 sal_Int16 nVal
= sal_Int16();
199 if ( nMemberId
== MID_VALUESET
)
200 nValueSet
= (sal_Int16
) nVal
;
201 else if ( nMemberId
== MID_TYPE
)
202 eType
= SvxZoomType( (sal_Int16
) nVal
);
210 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */