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>
24 #include <comphelper/propertyvalue.hxx>
25 #include <osl/diagnose.h>
30 SfxPoolItem
* SvxZoomItem::CreateDefault() { return new SvxZoomItem
; }
32 constexpr OUStringLiteral ZOOM_PARAM_VALUE
= u
"Value";
33 constexpr OUStringLiteral ZOOM_PARAM_VALUESET
= u
"ValueSet";
34 constexpr OUStringLiteral ZOOM_PARAM_TYPE
= u
"Type";
38 SvxZoomItem::SvxZoomItem
40 SvxZoomType eZoomType
,
44 : SfxUInt16Item( _nWhich
, nVal
),
45 nValueSet( SvxZoomEnableFlags::ALL
),
50 SvxZoomItem
* SvxZoomItem::Clone( SfxItemPool
* /*pPool*/ ) const
52 return new SvxZoomItem( *this );
55 bool SvxZoomItem::operator==( const SfxPoolItem
& rAttr
) const
57 assert(SfxPoolItem::operator==(rAttr
));
59 const SvxZoomItem
& rItem
= static_cast<const SvxZoomItem
&>(rAttr
);
61 return ( GetValue() == rItem
.GetValue() &&
62 nValueSet
== rItem
.GetValueSet() &&
63 eType
== rItem
.GetType() );
66 bool SvxZoomItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
68 nMemberId
&= ~CONVERT_TWIPS
;
73 css::uno::Sequence
< css::beans::PropertyValue
> aSeq
{
74 comphelper::makePropertyValue(ZOOM_PARAM_VALUE
, sal_Int32( GetValue() )),
75 comphelper::makePropertyValue(ZOOM_PARAM_VALUESET
, sal_Int16( nValueSet
)),
76 comphelper::makePropertyValue(ZOOM_PARAM_TYPE
, sal_Int16( eType
))
78 assert(aSeq
.getLength() == ZOOM_PARAMS
);
83 case MID_VALUE
: rVal
<<= static_cast<sal_Int32
>(GetValue()); break;
84 case MID_VALUESET
: rVal
<<= static_cast<sal_Int16
>(nValueSet
); break;
85 case MID_TYPE
: rVal
<<= static_cast<sal_Int16
>(eType
); break;
87 OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
94 bool SvxZoomItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
96 nMemberId
&= ~CONVERT_TWIPS
;
101 css::uno::Sequence
< css::beans::PropertyValue
> aSeq
;
102 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == ZOOM_PARAMS
))
104 sal_Int32
nValueTmp( 0 );
105 sal_Int16
nValueSetTmp( 0 );
106 sal_Int16
nTypeTmp( 0 );
107 bool bAllConverted( true );
108 sal_Int16
nConvertedCount( 0 );
109 for ( const auto& rProp
: std::as_const(aSeq
) )
111 if ( rProp
.Name
== ZOOM_PARAM_VALUE
)
113 bAllConverted
&= ( rProp
.Value
>>= nValueTmp
);
116 else if ( rProp
.Name
== ZOOM_PARAM_VALUESET
)
118 bAllConverted
&= ( rProp
.Value
>>= nValueSetTmp
);
121 else if ( rProp
.Name
== ZOOM_PARAM_TYPE
)
123 bAllConverted
&= ( rProp
.Value
>>= nTypeTmp
);
128 if ( bAllConverted
&& nConvertedCount
== ZOOM_PARAMS
)
130 SetValue( static_cast<sal_uInt16
>(nValueTmp
) );
131 nValueSet
= static_cast<SvxZoomEnableFlags
>(nValueSetTmp
);
132 eType
= static_cast<SvxZoomType
>(nTypeTmp
);
143 SetValue( static_cast<sal_uInt16
>(nVal
) );
156 if ( nMemberId
== MID_VALUESET
)
157 nValueSet
= static_cast<SvxZoomEnableFlags
>(nVal
);
158 else if ( nMemberId
== MID_TYPE
)
159 eType
= static_cast<SvxZoomType
>(nVal
);
167 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */