Update git submodules
[LibreOffice.git] / sfx2 / source / doc / zoomitem.cxx
blobd346363b3f92a4b0575682506ba03163d33cd2c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <cassert>
30 SfxPoolItem* SvxZoomItem::CreateDefault() { return new SvxZoomItem; }
32 constexpr OUString ZOOM_PARAM_VALUE = u"Value"_ustr;
33 constexpr OUString ZOOM_PARAM_VALUESET = u"ValueSet"_ustr;
34 constexpr OUString ZOOM_PARAM_TYPE = u"Type"_ustr;
35 #define ZOOM_PARAMS 3
38 SvxZoomItem::SvxZoomItem
40 SvxZoomType eZoomType,
41 sal_uInt16 nVal,
42 TypedWhichId<SvxZoomItem> _nWhich
44 : SfxUInt16Item( _nWhich, nVal, SfxItemType::SfxZoomItemType ),
45 nValueSet( SvxZoomEnableFlags::ALL ),
46 eType( eZoomType )
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;
69 switch( nMemberId )
71 case 0:
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);
79 rVal <<= aSeq;
80 break;
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;
86 default:
87 OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
88 return false;
91 return true;
94 bool SvxZoomItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
96 nMemberId &= ~CONVERT_TWIPS;
97 switch( nMemberId )
99 case 0:
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 : aSeq)
111 if ( rProp.Name == ZOOM_PARAM_VALUE )
113 bAllConverted &= ( rProp.Value >>= nValueTmp );
114 ++nConvertedCount;
116 else if ( rProp.Name == ZOOM_PARAM_VALUESET )
118 bAllConverted &= ( rProp.Value >>= nValueSetTmp );
119 ++nConvertedCount;
121 else if ( rProp.Name == ZOOM_PARAM_TYPE )
123 bAllConverted &= ( rProp.Value >>= nTypeTmp );
124 ++nConvertedCount;
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);
133 return true;
136 return false;
138 case MID_VALUE:
140 sal_Int32 nVal = 0;
141 if ( rVal >>= nVal )
143 SetValue( static_cast<sal_uInt16>(nVal) );
144 return true;
146 else
147 return false;
150 case MID_VALUESET:
151 case MID_TYPE:
153 sal_Int16 nVal;
154 if ( rVal >>= nVal )
156 if ( nMemberId == MID_VALUESET )
157 nValueSet = static_cast<SvxZoomEnableFlags>(nVal);
158 else if ( nMemberId == MID_TYPE )
159 eType = static_cast<SvxZoomType>(nVal);
160 return true;
162 else
163 return false;
166 default:
167 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
168 return false;
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */