LibreOffice Module svx (master) 1
zoomslideritem.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 <sal/config.h>
21
23#include <osl/diagnose.h>
24
26#include <com/sun/star/beans/PropertyValue.hpp>
27
28
30
31constexpr OUStringLiteral ZOOMSLIDER_PARAM_CURRENTZOOM = u"Columns";
32constexpr OUStringLiteral ZOOMSLIDER_PARAM_SNAPPINGPOINTS = u"SnappingPoints";
33constexpr OUStringLiteral ZOOMSLIDER_PARAM_MINZOOM = u"MinValue";
34constexpr OUStringLiteral ZOOMSLIDER_PARAM_MAXZOOM = u"MaxValue";
35#define ZOOMSLIDER_PARAMS 4
36
37
38SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, TypedWhichId<SvxZoomSliderItem> _nWhich )
39: SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
40{
41}
42
44{
45 return new SvxZoomSliderItem( *this );
46}
47
49{
50 assert(SfxPoolItem::operator==(rAttr));
51
52 const SvxZoomSliderItem& rItem = static_cast<const SvxZoomSliderItem&>(rAttr);
53
54 return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
55 mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
56}
57
58bool SvxZoomSliderItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
59{
60 nMemberId &= ~CONVERT_TWIPS;
61 switch ( nMemberId )
62 {
63 case 0 :
64 {
65 css::uno::Sequence< css::beans::PropertyValue > aSeq{
70 };
71 assert(aSeq.getLength() == ZOOMSLIDER_PARAMS);
72 rVal <<= aSeq;
73 }
74 break;
75
76 case MID_ZOOMSLIDER_CURRENTZOOM :
77 {
78 rVal <<= static_cast<sal_Int32>(GetValue());
79 }
80 break;
81 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
82 {
83 rVal <<= maValues;
84 }
85 break;
86 case MID_ZOOMSLIDER_MINZOOM:
87 {
88 rVal <<= mnMinZoom;
89 }
90 break;
91 case MID_ZOOMSLIDER_MAXZOOM:
92 {
93 rVal <<= mnMaxZoom;
94 }
95 break;
96 default:
97 OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
98 return false;
99 }
100
101 return true;
102}
103
104bool SvxZoomSliderItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
105{
106 nMemberId &= ~CONVERT_TWIPS;
107 switch ( nMemberId )
108 {
109 case 0 :
110 {
111 css::uno::Sequence< css::beans::PropertyValue > aSeq;
112 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
113 {
114 sal_Int32 nCurrentZoom( 0 );
115 css::uno::Sequence < sal_Int32 > aValues;
116
117 bool bAllConverted( true );
118 sal_Int16 nConvertedCount( 0 );
119 sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
120
121 for ( const auto& rProp : std::as_const(aSeq) )
122 {
123 if ( rProp.Name == ZOOMSLIDER_PARAM_CURRENTZOOM )
124 {
125 bAllConverted &= ( rProp.Value >>= nCurrentZoom );
126 ++nConvertedCount;
127 }
128 else if ( rProp.Name == ZOOMSLIDER_PARAM_SNAPPINGPOINTS )
129 {
130 bAllConverted &= ( rProp.Value >>= aValues );
131 ++nConvertedCount;
132 }
133 else if( rProp.Name == ZOOMSLIDER_PARAM_MINZOOM )
134 {
135 bAllConverted &= ( rProp.Value >>= nMinZoom );
136 ++nConvertedCount;
137 }
138 else if( rProp.Name == ZOOMSLIDER_PARAM_MAXZOOM )
139 {
140 bAllConverted &= ( rProp.Value >>= nMaxZoom );
141 ++nConvertedCount;
142 }
143 }
144
145 if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
146 {
147 SetValue( static_cast<sal_uInt16>(nCurrentZoom) );
148 maValues = aValues;
149 mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
150 mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
151
152 return true;
153 }
154 }
155
156 return false;
157 }
158
159 case MID_ZOOMSLIDER_CURRENTZOOM:
160 {
161 sal_Int32 nVal = 0;
162 if ( rVal >>= nVal )
163 {
164 SetValue( static_cast<sal_uInt16>(nVal) );
165 return true;
166 }
167 else
168 return false;
169 }
170
171 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
172 {
173 css::uno::Sequence < sal_Int32 > aValues;
174 if ( rVal >>= aValues )
175 {
176 maValues = aValues;
177 return true;
178 }
179 else
180 return false;
181 }
182 case MID_ZOOMSLIDER_MINZOOM:
183 {
184 sal_Int32 nVal = 0;
185 if( rVal >>= nVal )
186 {
187 mnMinZoom = static_cast<sal_uInt16>(nVal);
188 return true;
189 }
190 else
191 return false;
192 }
193 case MID_ZOOMSLIDER_MAXZOOM:
194 {
195 sal_Int32 nVal = 0;
196 if( rVal >>= nVal )
197 {
198 mnMaxZoom = static_cast<sal_uInt16>(nVal);
199 return true;
200 }
201 else
202 return false;
203 }
204 default:
205 OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
206 return false;
207 }
208}
209
211{
212 const sal_Int32 nValues = maValues.getLength();
213 maValues.realloc( nValues + 1 );
214 sal_Int32* pValues = maValues.getArray();
215 pValues[ nValues ] = nNew;
216}
217
218
219/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
sal_uInt16 GetValue() const
void SetValue(sal_uInt16 nTheValue)
virtual bool operator==(const SfxPoolItem &) const override
SvxZoomSliderItem(sal_uInt16 nCurrentZoom=100, sal_uInt16 nMinZoom=20, sal_uInt16 nMaxZoom=600, TypedWhichId< SvxZoomSliderItem > nWhich=SID_ATTR_ZOOMSLIDER)
virtual SvxZoomSliderItem * Clone(SfxItemPool *pPool=nullptr) const override
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
void AddSnappingPoint(sal_Int32 nNew)
static SfxPoolItem * CreateDefault()
css::uno::Sequence< sal_Int32 > maValues
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
float u
Sequence< sal_Int8 > aSeq
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
unsigned char sal_uInt8
constexpr OUStringLiteral ZOOMSLIDER_PARAM_CURRENTZOOM
constexpr OUStringLiteral ZOOMSLIDER_PARAM_MINZOOM
#define ZOOMSLIDER_PARAMS
constexpr OUStringLiteral ZOOMSLIDER_PARAM_MAXZOOM
constexpr OUStringLiteral ZOOMSLIDER_PARAM_SNAPPINGPOINTS