nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / source / doc / zoomitem.cxx
blob54855aff8a80ace775f1849efc05c55861eb185b
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>
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"
31 #define ZOOM_PARAMS 3
34 SvxZoomItem::SvxZoomItem
36 SvxZoomType eZoomType,
37 sal_uInt16 nVal,
38 sal_uInt16 _nWhich
40 : SfxUInt16Item( _nWhich, nVal ),
41 nValueSet( SvxZoomEnableFlags::ALL ),
42 eType( eZoomType )
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;
65 switch( nMemberId )
67 case 0:
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 );
76 rVal <<= aSeq;
77 break;
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;
83 default:
84 OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
85 return false;
88 return true;
91 bool SvxZoomItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
93 nMemberId &= ~CONVERT_TWIPS;
94 switch( nMemberId )
96 case 0:
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 );
111 ++nConvertedCount;
113 else if ( rProp.Name == ZOOM_PARAM_VALUESET )
115 bAllConverted &= ( rProp.Value >>= nValueSetTmp );
116 ++nConvertedCount;
118 else if ( rProp.Name == ZOOM_PARAM_TYPE )
120 bAllConverted &= ( rProp.Value >>= nTypeTmp );
121 ++nConvertedCount;
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);
130 return true;
133 return false;
135 case MID_VALUE:
137 sal_Int32 nVal = 0;
138 if ( rVal >>= nVal )
140 SetValue( static_cast<sal_uInt16>(nVal) );
141 return true;
143 else
144 return false;
147 case MID_VALUESET:
148 case MID_TYPE:
150 sal_Int16 nVal;
151 if ( rVal >>= nVal )
153 if ( nMemberId == MID_VALUESET )
154 nValueSet = static_cast<SvxZoomEnableFlags>(nVal);
155 else if ( nMemberId == MID_TYPE )
156 eType = static_cast<SvxZoomType>(nVal);
157 return true;
159 else
160 return false;
163 default:
164 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
165 return false;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */