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 <svx/zoomslideritem.hxx>
23 #include <com/sun/star/beans/PropertyValue.hpp>
25 // -----------------------------------------------------------------------
27 TYPEINIT1_FACTORY(SvxZoomSliderItem
,SfxUInt16Item
, new SvxZoomSliderItem
);
29 #define ZOOMSLIDER_PARAM_CURRENTZOOM "Columns"
30 #define ZOOMSLIDER_PARAM_SNAPPINGPOINTS "SnappingPoints"
31 #define ZOOMSLIDER_PARAM_MINZOOM "MinValue"
32 #define ZOOMSLIDER_PARAM_MAXZOOM "MaxValue"
33 #define ZOOMSLIDER_PARAMS 4
35 // -----------------------------------------------------------------------
37 SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom
, sal_uInt16 nMinZoom
, sal_uInt16 nMaxZoom
, sal_uInt16 _nWhich
)
38 : SfxUInt16Item( _nWhich
, nCurrentZoom
), mnMinZoom( nMinZoom
), mnMaxZoom( nMaxZoom
)
42 // -----------------------------------------------------------------------
44 SvxZoomSliderItem::SvxZoomSliderItem( const SvxZoomSliderItem
& rOrig
)
45 : SfxUInt16Item( rOrig
.Which(), rOrig
.GetValue() )
46 , maValues( rOrig
.maValues
)
47 , mnMinZoom( rOrig
.mnMinZoom
)
48 , mnMaxZoom( rOrig
.mnMaxZoom
)
52 // -----------------------------------------------------------------------
54 SvxZoomSliderItem::~SvxZoomSliderItem()
58 // -----------------------------------------------------------------------
60 SfxPoolItem
* SvxZoomSliderItem::Clone( SfxItemPool
* /*pPool*/ ) const
62 return new SvxZoomSliderItem( *this );
65 // -----------------------------------------------------------------------
67 SfxPoolItem
* SvxZoomSliderItem::Create( SvStream
& /*rStrm*/, sal_uInt16
/*nVersion*/ ) const
72 // -----------------------------------------------------------------------
74 SvStream
& SvxZoomSliderItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
79 // -----------------------------------------------------------------------
81 int SvxZoomSliderItem::operator==( const SfxPoolItem
& rAttr
) const
83 DBG_ASSERT( SfxPoolItem::operator==(rAttr
), "unequal types" );
85 SvxZoomSliderItem
& rItem
= (SvxZoomSliderItem
&)rAttr
;
87 return ( GetValue() == rItem
.GetValue() && maValues
== rItem
.maValues
&&
88 mnMinZoom
== rItem
.mnMinZoom
&& mnMaxZoom
== rItem
.mnMaxZoom
);
91 bool SvxZoomSliderItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
93 nMemberId
&= ~CONVERT_TWIPS
;
98 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq( ZOOMSLIDER_PARAMS
);
99 aSeq
[0].Name
= OUString( ZOOMSLIDER_PARAM_CURRENTZOOM
);
100 aSeq
[0].Value
<<= sal_Int32( GetValue() );
101 aSeq
[1].Name
= OUString( ZOOMSLIDER_PARAM_SNAPPINGPOINTS
);
102 aSeq
[1].Value
<<= maValues
;
103 aSeq
[2].Name
= OUString( ZOOMSLIDER_PARAM_MINZOOM
);
104 aSeq
[2].Value
<<= mnMinZoom
;
105 aSeq
[3].Name
= OUString( ZOOMSLIDER_PARAM_MAXZOOM
);
106 aSeq
[3].Value
<<= mnMaxZoom
;
111 case MID_ZOOMSLIDER_CURRENTZOOM
:
113 rVal
<<= (sal_Int32
) GetValue();
116 case MID_ZOOMSLIDER_SNAPPINGPOINTS
:
121 case MID_ZOOMSLIDER_MINZOOM
:
126 case MID_ZOOMSLIDER_MAXZOOM
:
132 OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
139 bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
141 nMemberId
&= ~CONVERT_TWIPS
;
146 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aSeq
;
147 if (( rVal
>>= aSeq
) && ( aSeq
.getLength() == ZOOMSLIDER_PARAMS
))
149 sal_Int32
nCurrentZoom( 0 );
150 com::sun::star::uno::Sequence
< sal_Int32
> aValues
;
152 sal_Bool
bAllConverted( sal_True
);
153 sal_Int16
nConvertedCount( 0 );
154 sal_Int32
nMinZoom( 0 ), nMaxZoom( 0 );
156 for ( sal_Int32 i
= 0; i
< aSeq
.getLength(); i
++ )
158 if ( aSeq
[i
].Name
.equalsAscii( ZOOMSLIDER_PARAM_CURRENTZOOM
))
160 bAllConverted
&= ( aSeq
[i
].Value
>>= nCurrentZoom
);
163 else if ( aSeq
[i
].Name
.equalsAscii( ZOOMSLIDER_PARAM_SNAPPINGPOINTS
))
165 bAllConverted
&= ( aSeq
[i
].Value
>>= aValues
);
168 else if( aSeq
[i
].Name
.equalsAscii( ZOOMSLIDER_PARAM_MINZOOM
) )
170 bAllConverted
&= ( aSeq
[i
].Value
>>= nMinZoom
);
173 else if( aSeq
[i
].Name
.equalsAscii( ZOOMSLIDER_PARAM_MAXZOOM
) )
175 bAllConverted
&= ( aSeq
[i
].Value
>>= nMaxZoom
);
180 if ( bAllConverted
&& nConvertedCount
== ZOOMSLIDER_PARAMS
)
182 SetValue( (sal_uInt16
)nCurrentZoom
);
184 mnMinZoom
= sal::static_int_cast
< sal_uInt16
>( nMinZoom
);
185 mnMaxZoom
= sal::static_int_cast
< sal_uInt16
>( nMaxZoom
);
194 case MID_ZOOMSLIDER_CURRENTZOOM
:
199 SetValue( (sal_uInt16
)nVal
);
206 case MID_ZOOMSLIDER_SNAPPINGPOINTS
:
208 com::sun::star::uno::Sequence
< sal_Int32
> aValues
;
209 if ( rVal
>>= aValues
)
217 case MID_ZOOMSLIDER_MINZOOM
:
222 mnMinZoom
= (sal_uInt16
)nVal
;
228 case MID_ZOOMSLIDER_MAXZOOM
:
233 mnMaxZoom
= (sal_uInt16
)nVal
;
240 OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
245 void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew
)
247 const sal_Int32 nValues
= maValues
.getLength();
248 maValues
.realloc( nValues
+ 1 );
249 sal_Int32
* pValues
= maValues
.getArray();
250 pValues
[ nValues
] = nNew
;
253 const com::sun::star::uno::Sequence
< sal_Int32
>& SvxZoomSliderItem::GetSnappingPoints() const
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */