Revert "Revert "Revert "stronger typing for SwClient::GetRegisteredIn"" and fix SwIte...
[LibreOffice.git] / svx / source / items / zoomslideritem.cxx
blobba54a68e77390deeaf5c9f4f56c8170bbe5c19ae
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 <sal/config.h>
22 #include <comphelper/propertyvalue.hxx>
23 #include <osl/diagnose.h>
25 #include <svx/zoomslideritem.hxx>
26 #include <com/sun/star/beans/PropertyValue.hpp>
29 SfxPoolItem* SvxZoomSliderItem::CreateDefault() { return new SvxZoomSliderItem; }
31 constexpr OUString ZOOMSLIDER_PARAM_CURRENTZOOM = u"Columns"_ustr;
32 constexpr OUString ZOOMSLIDER_PARAM_SNAPPINGPOINTS = u"SnappingPoints"_ustr;
33 constexpr OUString ZOOMSLIDER_PARAM_MINZOOM = u"MinValue"_ustr;
34 constexpr OUString ZOOMSLIDER_PARAM_MAXZOOM = u"MaxValue"_ustr;
35 #define ZOOMSLIDER_PARAMS 4
38 SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, TypedWhichId<SvxZoomSliderItem> _nWhich )
39 : SfxUInt16Item( _nWhich, nCurrentZoom, SfxItemType::SvxZoomSliderItemType ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
43 SvxZoomSliderItem* SvxZoomSliderItem::Clone( SfxItemPool * /*pPool*/ ) const
45 return new SvxZoomSliderItem( *this );
48 bool SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const
50 assert(SfxPoolItem::operator==(rAttr));
52 const SvxZoomSliderItem& rItem = static_cast<const SvxZoomSliderItem&>(rAttr);
54 return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
55 mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
58 bool SvxZoomSliderItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
60 nMemberId &= ~CONVERT_TWIPS;
61 switch ( nMemberId )
63 case 0 :
65 css::uno::Sequence< css::beans::PropertyValue > aSeq{
66 comphelper::makePropertyValue(ZOOMSLIDER_PARAM_CURRENTZOOM, sal_Int32( GetValue() )),
67 comphelper::makePropertyValue(ZOOMSLIDER_PARAM_SNAPPINGPOINTS, maValues),
68 comphelper::makePropertyValue(ZOOMSLIDER_PARAM_MINZOOM, mnMinZoom),
69 comphelper::makePropertyValue(ZOOMSLIDER_PARAM_MAXZOOM, mnMaxZoom)
71 assert(aSeq.getLength() == ZOOMSLIDER_PARAMS);
72 rVal <<= aSeq;
74 break;
76 case MID_ZOOMSLIDER_CURRENTZOOM :
78 rVal <<= static_cast<sal_Int32>(GetValue());
80 break;
81 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
83 rVal <<= maValues;
85 break;
86 case MID_ZOOMSLIDER_MINZOOM:
88 rVal <<= mnMinZoom;
90 break;
91 case MID_ZOOMSLIDER_MAXZOOM:
93 rVal <<= mnMaxZoom;
95 break;
96 default:
97 OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
98 return false;
101 return true;
104 bool SvxZoomSliderItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
106 nMemberId &= ~CONVERT_TWIPS;
107 switch ( nMemberId )
109 case 0 :
111 css::uno::Sequence< css::beans::PropertyValue > aSeq;
112 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
114 sal_Int32 nCurrentZoom( 0 );
115 css::uno::Sequence < sal_Int32 > aValues;
117 bool bAllConverted( true );
118 sal_Int16 nConvertedCount( 0 );
119 sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
121 for (const auto& rProp : aSeq)
123 if ( rProp.Name == ZOOMSLIDER_PARAM_CURRENTZOOM )
125 bAllConverted &= ( rProp.Value >>= nCurrentZoom );
126 ++nConvertedCount;
128 else if ( rProp.Name == ZOOMSLIDER_PARAM_SNAPPINGPOINTS )
130 bAllConverted &= ( rProp.Value >>= aValues );
131 ++nConvertedCount;
133 else if( rProp.Name == ZOOMSLIDER_PARAM_MINZOOM )
135 bAllConverted &= ( rProp.Value >>= nMinZoom );
136 ++nConvertedCount;
138 else if( rProp.Name == ZOOMSLIDER_PARAM_MAXZOOM )
140 bAllConverted &= ( rProp.Value >>= nMaxZoom );
141 ++nConvertedCount;
145 if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
147 SetValue( static_cast<sal_uInt16>(nCurrentZoom) );
148 maValues = std::move(aValues);
149 mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
150 mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
152 return true;
156 return false;
159 case MID_ZOOMSLIDER_CURRENTZOOM:
161 sal_Int32 nVal = 0;
162 if ( rVal >>= nVal )
164 SetValue( static_cast<sal_uInt16>(nVal) );
165 return true;
167 else
168 return false;
171 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
173 css::uno::Sequence < sal_Int32 > aValues;
174 if ( rVal >>= aValues )
176 maValues = std::move(aValues);
177 return true;
179 else
180 return false;
182 case MID_ZOOMSLIDER_MINZOOM:
184 sal_Int32 nVal = 0;
185 if( rVal >>= nVal )
187 mnMinZoom = static_cast<sal_uInt16>(nVal);
188 return true;
190 else
191 return false;
193 case MID_ZOOMSLIDER_MAXZOOM:
195 sal_Int32 nVal = 0;
196 if( rVal >>= nVal )
198 mnMaxZoom = static_cast<sal_uInt16>(nVal);
199 return true;
201 else
202 return false;
204 default:
205 OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
206 return false;
210 void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew )
212 const sal_Int32 nValues = maValues.getLength();
213 maValues.realloc( nValues + 1 );
214 sal_Int32* pValues = maValues.getArray();
215 pValues[ nValues ] = nNew;
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */