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>
26 #include <osl/diagnose.h>
27 #include <sfx2/sfx.hrc>
30 TYPEINIT1_FACTORY(SvxZoomItem
,SfxUInt16Item
, new SvxZoomItem
);
32 #define ZOOM_PARAM_VALUE "Value"
33 #define ZOOM_PARAM_VALUESET "ValueSet"
34 #define ZOOM_PARAM_TYPE "Type"
39 SvxZoomItem::SvxZoomItem
41 SvxZoomType eZoomType
,
45 : SfxUInt16Item( _nWhich
, nVal
),
46 nValueSet( SvxZoomEnableFlags::ALL
),
53 SvxZoomItem::SvxZoomItem( const SvxZoomItem
& rOrig
)
54 : SfxUInt16Item( rOrig
.Which(), rOrig
.GetValue() ),
55 nValueSet( rOrig
.GetValueSet() ),
56 eType( rOrig
.GetType() )
62 SvxZoomItem::~SvxZoomItem()
68 SfxPoolItem
* SvxZoomItem::Clone( SfxItemPool
* /*pPool*/ ) const
70 return new SvxZoomItem( *this );
75 SfxPoolItem
* SvxZoomItem::Create( SvStream
& rStrm
, sal_uInt16
/*nVersion*/ ) const
80 rStrm
.ReadUInt16( nValue
).ReadUInt16( nValSet
).ReadSChar( nType
);
81 SvxZoomItem
* pNew
= new SvxZoomItem( (SvxZoomType
)nType
, nValue
, Which() );
82 pNew
->SetValueSet( static_cast<SvxZoomEnableFlags
>(nValSet
) );
88 SvStream
& SvxZoomItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
90 rStrm
.WriteUInt16( GetValue() )
91 .WriteUInt16( static_cast<sal_uInt16
>(nValueSet
) )
92 .WriteSChar( static_cast<int>(eType
) );
98 bool SvxZoomItem::operator==( const SfxPoolItem
& rAttr
) const
100 DBG_ASSERT( SfxPoolItem::operator==(rAttr
), "unequal types" );
102 const SvxZoomItem
& rItem
= static_cast<const SvxZoomItem
&>(rAttr
);
104 return ( GetValue() == rItem
.GetValue() &&
105 nValueSet
== rItem
.GetValueSet() &&
106 eType
== rItem
.GetType() );
109 bool SvxZoomItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
111 nMemberId
&= ~CONVERT_TWIPS
;
116 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq( ZOOM_PARAMS
);
117 aSeq
[0].Name
= ZOOM_PARAM_VALUE
;
118 aSeq
[0].Value
<<= sal_Int32( GetValue() );
119 aSeq
[1].Name
= ZOOM_PARAM_VALUESET
;
120 aSeq
[1].Value
<<= sal_Int16( nValueSet
);
121 aSeq
[2].Name
= ZOOM_PARAM_TYPE
;
122 aSeq
[2].Value
<<= sal_Int16( eType
);
127 case MID_VALUE
: rVal
<<= (sal_Int32
) GetValue(); break;
128 case MID_VALUESET
: rVal
<<= (sal_Int16
) nValueSet
; break;
129 case MID_TYPE
: rVal
<<= (sal_Int16
) eType
; break;
131 OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
138 bool SvxZoomItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
140 nMemberId
&= ~CONVERT_TWIPS
;
145 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq
;
146 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == ZOOM_PARAMS
))
148 sal_Int32
nValueTmp( 0 );
149 sal_Int16
nValueSetTmp( 0 );
150 sal_Int16
nTypeTmp( 0 );
151 bool bAllConverted( true );
152 sal_Int16
nConvertedCount( 0 );
153 for ( sal_Int32 i
= 0; i
< aSeq
.getLength(); i
++ )
155 if ( aSeq
[i
].Name
== ZOOM_PARAM_VALUE
)
157 bAllConverted
&= ( aSeq
[i
].Value
>>= nValueTmp
);
160 else if ( aSeq
[i
].Name
== ZOOM_PARAM_VALUESET
)
162 bAllConverted
&= ( aSeq
[i
].Value
>>= nValueSetTmp
);
165 else if ( aSeq
[i
].Name
== ZOOM_PARAM_TYPE
)
167 bAllConverted
&= ( aSeq
[i
].Value
>>= nTypeTmp
);
172 if ( bAllConverted
&& nConvertedCount
== ZOOM_PARAMS
)
174 SetValue( (sal_uInt16
)nValueTmp
);
175 nValueSet
= static_cast<SvxZoomEnableFlags
>(nValueSetTmp
);
176 eType
= static_cast<SvxZoomType
>(nTypeTmp
);
187 SetValue( (sal_uInt16
)nVal
);
200 if ( nMemberId
== MID_VALUESET
)
201 nValueSet
= static_cast<SvxZoomEnableFlags
>(nVal
);
202 else if ( nMemberId
== MID_TYPE
)
203 eType
= static_cast<SvxZoomType
>(nVal
);
211 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */