1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
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
);
76 case MID_ZOOMSLIDER_CURRENTZOOM
:
78 rVal
<<= static_cast<sal_Int32
>(GetValue());
81 case MID_ZOOMSLIDER_SNAPPINGPOINTS
:
86 case MID_ZOOMSLIDER_MINZOOM
:
91 case MID_ZOOMSLIDER_MAXZOOM
:
97 OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
104 bool SvxZoomSliderItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
106 nMemberId
&= ~CONVERT_TWIPS
;
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
);
128 else if ( rProp
.Name
== ZOOMSLIDER_PARAM_SNAPPINGPOINTS
)
130 bAllConverted
&= ( rProp
.Value
>>= aValues
);
133 else if( rProp
.Name
== ZOOMSLIDER_PARAM_MINZOOM
)
135 bAllConverted
&= ( rProp
.Value
>>= nMinZoom
);
138 else if( rProp
.Name
== ZOOMSLIDER_PARAM_MAXZOOM
)
140 bAllConverted
&= ( rProp
.Value
>>= nMaxZoom
);
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
);
159 case MID_ZOOMSLIDER_CURRENTZOOM
:
164 SetValue( static_cast<sal_uInt16
>(nVal
) );
171 case MID_ZOOMSLIDER_SNAPPINGPOINTS
:
173 css::uno::Sequence
< sal_Int32
> aValues
;
174 if ( rVal
>>= aValues
)
176 maValues
= std::move(aValues
);
182 case MID_ZOOMSLIDER_MINZOOM
:
187 mnMinZoom
= static_cast<sal_uInt16
>(nVal
);
193 case MID_ZOOMSLIDER_MAXZOOM
:
198 mnMaxZoom
= static_cast<sal_uInt16
>(nVal
);
205 OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
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: */