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 <tools/stream.hxx>
22 #include <osl/diagnose.h>
24 #include <svx/zoomslideritem.hxx>
25 #include <com/sun/star/beans/PropertyValue.hpp>
29 TYPEINIT1_FACTORY(SvxZoomSliderItem
,SfxUInt16Item
, new SvxZoomSliderItem
);
31 #define ZOOMSLIDER_PARAM_CURRENTZOOM "Columns"
32 #define ZOOMSLIDER_PARAM_SNAPPINGPOINTS "SnappingPoints"
33 #define ZOOMSLIDER_PARAM_MINZOOM "MinValue"
34 #define ZOOMSLIDER_PARAM_MAXZOOM "MaxValue"
35 #define ZOOMSLIDER_PARAMS 4
39 SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom
, sal_uInt16 nMinZoom
, sal_uInt16 nMaxZoom
, sal_uInt16 _nWhich
)
40 : SfxUInt16Item( _nWhich
, nCurrentZoom
), mnMinZoom( nMinZoom
), mnMaxZoom( nMaxZoom
)
46 SvxZoomSliderItem::SvxZoomSliderItem( const SvxZoomSliderItem
& rOrig
)
47 : SfxUInt16Item( rOrig
.Which(), rOrig
.GetValue() )
48 , maValues( rOrig
.maValues
)
49 , mnMinZoom( rOrig
.mnMinZoom
)
50 , mnMaxZoom( rOrig
.mnMaxZoom
)
56 SvxZoomSliderItem::~SvxZoomSliderItem()
62 SfxPoolItem
* SvxZoomSliderItem::Clone( SfxItemPool
* /*pPool*/ ) const
64 return new SvxZoomSliderItem( *this );
69 SfxPoolItem
* SvxZoomSliderItem::Create( SvStream
& /*rStrm*/, sal_uInt16
/*nVersion*/ ) const
76 SvStream
& SvxZoomSliderItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
83 bool SvxZoomSliderItem::operator==( const SfxPoolItem
& rAttr
) const
85 DBG_ASSERT( SfxPoolItem::operator==(rAttr
), "unequal types" );
87 const SvxZoomSliderItem
& rItem
= static_cast<const SvxZoomSliderItem
&>(rAttr
);
89 return ( GetValue() == rItem
.GetValue() && maValues
== rItem
.maValues
&&
90 mnMinZoom
== rItem
.mnMinZoom
&& mnMaxZoom
== rItem
.mnMaxZoom
);
93 bool SvxZoomSliderItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
95 nMemberId
&= ~CONVERT_TWIPS
;
100 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq( ZOOMSLIDER_PARAMS
);
101 aSeq
[0].Name
= ZOOMSLIDER_PARAM_CURRENTZOOM
;
102 aSeq
[0].Value
<<= sal_Int32( GetValue() );
103 aSeq
[1].Name
= ZOOMSLIDER_PARAM_SNAPPINGPOINTS
;
104 aSeq
[1].Value
<<= maValues
;
105 aSeq
[2].Name
= ZOOMSLIDER_PARAM_MINZOOM
;
106 aSeq
[2].Value
<<= mnMinZoom
;
107 aSeq
[3].Name
= ZOOMSLIDER_PARAM_MAXZOOM
;
108 aSeq
[3].Value
<<= mnMaxZoom
;
113 case MID_ZOOMSLIDER_CURRENTZOOM
:
115 rVal
<<= (sal_Int32
) GetValue();
118 case MID_ZOOMSLIDER_SNAPPINGPOINTS
:
123 case MID_ZOOMSLIDER_MINZOOM
:
128 case MID_ZOOMSLIDER_MAXZOOM
:
134 OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
141 bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
143 nMemberId
&= ~CONVERT_TWIPS
;
148 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq
;
149 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == ZOOMSLIDER_PARAMS
))
151 sal_Int32
nCurrentZoom( 0 );
152 com::sun::star::uno::Sequence
< sal_Int32
> aValues
;
154 bool bAllConverted( true );
155 sal_Int16
nConvertedCount( 0 );
156 sal_Int32
nMinZoom( 0 ), nMaxZoom( 0 );
158 for ( sal_Int32 i
= 0; i
< aSeq
.getLength(); i
++ )
160 if ( aSeq
[i
].Name
== ZOOMSLIDER_PARAM_CURRENTZOOM
)
162 bAllConverted
&= ( aSeq
[i
].Value
>>= nCurrentZoom
);
165 else if ( aSeq
[i
].Name
== ZOOMSLIDER_PARAM_SNAPPINGPOINTS
)
167 bAllConverted
&= ( aSeq
[i
].Value
>>= aValues
);
170 else if( aSeq
[i
].Name
== ZOOMSLIDER_PARAM_MINZOOM
)
172 bAllConverted
&= ( aSeq
[i
].Value
>>= nMinZoom
);
175 else if( aSeq
[i
].Name
== ZOOMSLIDER_PARAM_MAXZOOM
)
177 bAllConverted
&= ( aSeq
[i
].Value
>>= nMaxZoom
);
182 if ( bAllConverted
&& nConvertedCount
== ZOOMSLIDER_PARAMS
)
184 SetValue( (sal_uInt16
)nCurrentZoom
);
186 mnMinZoom
= sal::static_int_cast
< sal_uInt16
>( nMinZoom
);
187 mnMaxZoom
= sal::static_int_cast
< sal_uInt16
>( nMaxZoom
);
196 case MID_ZOOMSLIDER_CURRENTZOOM
:
201 SetValue( (sal_uInt16
)nVal
);
208 case MID_ZOOMSLIDER_SNAPPINGPOINTS
:
210 com::sun::star::uno::Sequence
< sal_Int32
> aValues
;
211 if ( rVal
>>= aValues
)
219 case MID_ZOOMSLIDER_MINZOOM
:
224 mnMinZoom
= (sal_uInt16
)nVal
;
230 case MID_ZOOMSLIDER_MAXZOOM
:
235 mnMaxZoom
= (sal_uInt16
)nVal
;
242 OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
247 void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew
)
249 const sal_Int32 nValues
= maValues
.getLength();
250 maValues
.realloc( nValues
+ 1 );
251 sal_Int32
* pValues
= maValues
.getArray();
252 pValues
[ nValues
] = nNew
;
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */