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 <sfx2/zoomitem.hxx>
21 #include <com/sun/star/uno/Sequence.hxx>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <osl/diagnose.h>
26 SfxPoolItem
* SvxZoomItem::CreateDefault() { return new SvxZoomItem
; }
28 #define ZOOM_PARAM_VALUE "Value"
29 #define ZOOM_PARAM_VALUESET "ValueSet"
30 #define ZOOM_PARAM_TYPE "Type"
34 SvxZoomItem::SvxZoomItem
36 SvxZoomType eZoomType
,
40 : SfxUInt16Item( _nWhich
, nVal
),
41 nValueSet( SvxZoomEnableFlags::ALL
),
46 SvxZoomItem
* SvxZoomItem::Clone( SfxItemPool
* /*pPool*/ ) const
48 return new SvxZoomItem( *this );
51 bool SvxZoomItem::operator==( const SfxPoolItem
& rAttr
) const
53 assert(SfxPoolItem::operator==(rAttr
));
55 const SvxZoomItem
& rItem
= static_cast<const SvxZoomItem
&>(rAttr
);
57 return ( GetValue() == rItem
.GetValue() &&
58 nValueSet
== rItem
.GetValueSet() &&
59 eType
== rItem
.GetType() );
62 bool SvxZoomItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
64 nMemberId
&= ~CONVERT_TWIPS
;
69 css::uno::Sequence
< css::beans::PropertyValue
> aSeq( ZOOM_PARAMS
);
70 aSeq
[0].Name
= ZOOM_PARAM_VALUE
;
71 aSeq
[0].Value
<<= sal_Int32( GetValue() );
72 aSeq
[1].Name
= ZOOM_PARAM_VALUESET
;
73 aSeq
[1].Value
<<= sal_Int16( nValueSet
);
74 aSeq
[2].Name
= ZOOM_PARAM_TYPE
;
75 aSeq
[2].Value
<<= sal_Int16( eType
);
80 case MID_VALUE
: rVal
<<= static_cast<sal_Int32
>(GetValue()); break;
81 case MID_VALUESET
: rVal
<<= static_cast<sal_Int16
>(nValueSet
); break;
82 case MID_TYPE
: rVal
<<= static_cast<sal_Int16
>(eType
); break;
84 OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
91 bool SvxZoomItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
93 nMemberId
&= ~CONVERT_TWIPS
;
98 css::uno::Sequence
< css::beans::PropertyValue
> aSeq
;
99 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == ZOOM_PARAMS
))
101 sal_Int32
nValueTmp( 0 );
102 sal_Int16
nValueSetTmp( 0 );
103 sal_Int16
nTypeTmp( 0 );
104 bool bAllConverted( true );
105 sal_Int16
nConvertedCount( 0 );
106 for ( const auto& rProp
: std::as_const(aSeq
) )
108 if ( rProp
.Name
== ZOOM_PARAM_VALUE
)
110 bAllConverted
&= ( rProp
.Value
>>= nValueTmp
);
113 else if ( rProp
.Name
== ZOOM_PARAM_VALUESET
)
115 bAllConverted
&= ( rProp
.Value
>>= nValueSetTmp
);
118 else if ( rProp
.Name
== ZOOM_PARAM_TYPE
)
120 bAllConverted
&= ( rProp
.Value
>>= nTypeTmp
);
125 if ( bAllConverted
&& nConvertedCount
== ZOOM_PARAMS
)
127 SetValue( static_cast<sal_uInt16
>(nValueTmp
) );
128 nValueSet
= static_cast<SvxZoomEnableFlags
>(nValueSetTmp
);
129 eType
= static_cast<SvxZoomType
>(nTypeTmp
);
140 SetValue( static_cast<sal_uInt16
>(nVal
) );
153 if ( nMemberId
== MID_VALUESET
)
154 nValueSet
= static_cast<SvxZoomEnableFlags
>(nVal
);
155 else if ( nMemberId
== MID_TYPE
)
156 eType
= static_cast<SvxZoomType
>(nVal
);
164 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */