LibreOffice Module sfx2 (master) 1
zoomitem.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sfx2/zoomitem.hxx>
21#include <com/sun/star/uno/Sequence.hxx>
22#include <com/sun/star/beans/PropertyValue.hpp>
23
25#include <osl/diagnose.h>
26
27#include <cassert>
28
29
31
32constexpr OUStringLiteral ZOOM_PARAM_VALUE = u"Value";
33constexpr OUStringLiteral ZOOM_PARAM_VALUESET = u"ValueSet";
34constexpr OUStringLiteral ZOOM_PARAM_TYPE = u"Type";
35#define ZOOM_PARAMS 3
36
37
39(
40 SvxZoomType eZoomType,
41 sal_uInt16 nVal,
43)
44: SfxUInt16Item( _nWhich, nVal ),
45 nValueSet( SvxZoomEnableFlags::ALL ),
46 eType( eZoomType )
47{
48}
49
51{
52 return new SvxZoomItem( *this );
53}
54
55bool SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
56{
57 assert(SfxPoolItem::operator==(rAttr));
58
59 const SvxZoomItem& rItem = static_cast<const SvxZoomItem&>(rAttr);
60
61 return ( GetValue() == rItem.GetValue() &&
62 nValueSet == rItem.GetValueSet() &&
63 eType == rItem.GetType() );
64}
65
66bool SvxZoomItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
67{
68 nMemberId &= ~CONVERT_TWIPS;
69 switch( nMemberId )
70 {
71 case 0:
72 {
73 css::uno::Sequence< css::beans::PropertyValue > aSeq{
77 };
78 assert(aSeq.getLength() == ZOOM_PARAMS);
79 rVal <<= aSeq;
80 break;
81 }
82
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;
89 }
90
91 return true;
92}
93
94bool SvxZoomItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
95{
96 nMemberId &= ~CONVERT_TWIPS;
97 switch( nMemberId )
98 {
99 case 0:
100 {
101 css::uno::Sequence< css::beans::PropertyValue > aSeq;
102 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
103 {
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) )
110 {
111 if ( rProp.Name == ZOOM_PARAM_VALUE )
112 {
113 bAllConverted &= ( rProp.Value >>= nValueTmp );
114 ++nConvertedCount;
115 }
116 else if ( rProp.Name == ZOOM_PARAM_VALUESET )
117 {
118 bAllConverted &= ( rProp.Value >>= nValueSetTmp );
119 ++nConvertedCount;
120 }
121 else if ( rProp.Name == ZOOM_PARAM_TYPE )
122 {
123 bAllConverted &= ( rProp.Value >>= nTypeTmp );
124 ++nConvertedCount;
125 }
126 }
127
128 if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
129 {
130 SetValue( static_cast<sal_uInt16>(nValueTmp) );
131 nValueSet = static_cast<SvxZoomEnableFlags>(nValueSetTmp);
132 eType = static_cast<SvxZoomType>(nTypeTmp);
133 return true;
134 }
135 }
136 return false;
137 }
138 case MID_VALUE:
139 {
140 sal_Int32 nVal = 0;
141 if ( rVal >>= nVal )
142 {
143 SetValue( static_cast<sal_uInt16>(nVal) );
144 return true;
145 }
146 else
147 return false;
148 }
149
150 case MID_VALUESET:
151 case MID_TYPE:
152 {
153 sal_Int16 nVal;
154 if ( rVal >>= nVal )
155 {
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;
161 }
162 else
163 return false;
164 }
165
166 default:
167 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
168 return false;
169 }
170}
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetValue() const
void SetValue(sal_uInt16 nTheValue)
SvxZoomEnableFlags GetValueSet() const
Definition: zoomitem.hxx:67
virtual SvxZoomItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: zoomitem.cxx:50
SvxZoomEnableFlags nValueSet
Definition: zoomitem.hxx:57
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: zoomitem.cxx:94
static SfxPoolItem * CreateDefault()
Definition: zoomitem.cxx:30
virtual bool operator==(const SfxPoolItem &) const override
Definition: zoomitem.cxx:55
SvxZoomType GetType() const
Definition: zoomitem.hxx:69
SvxZoomItem(SvxZoomType eZoomType=SvxZoomType::PERCENT, sal_uInt16 nVal=0, TypedWhichId< SvxZoomItem > nWhich=SID_ATTR_ZOOM)
Definition: zoomitem.cxx:39
SvxZoomType eType
Definition: zoomitem.hxx:58
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: zoomitem.cxx:66
float u
DocumentType eType
Sequence< sal_Int8 > aSeq
Definition: lnkbase2.cxx:83
#define MID_TYPE
#define MID_VALUE
#define MID_VALUESET
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
unsigned char sal_uInt8
constexpr OUStringLiteral ZOOM_PARAM_VALUE
Definition: zoomitem.cxx:32
constexpr OUStringLiteral ZOOM_PARAM_TYPE
Definition: zoomitem.cxx:34
#define ZOOM_PARAMS
Definition: zoomitem.cxx:35
constexpr OUStringLiteral ZOOM_PARAM_VALUESET
Definition: zoomitem.cxx:33
SvxZoomType
Definition: zoomitem.hxx:29
SvxZoomEnableFlags
Definition: zoomitem.hxx:38