bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / items / zoomslideritem.cxx
blobeb04b54c04e0476d82d30f95cf7fb73a91b6d8f8
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 <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
69 return 0;
72 // -----------------------------------------------------------------------
74 SvStream& SvxZoomSliderItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
76 return rStrm;
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;
94 switch ( nMemberId )
96 case 0 :
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;
107 rVal <<= aSeq;
109 break;
111 case MID_ZOOMSLIDER_CURRENTZOOM :
113 rVal <<= (sal_Int32) GetValue();
115 break;
116 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
118 rVal <<= maValues;
120 break;
121 case MID_ZOOMSLIDER_MINZOOM:
123 rVal <<= mnMinZoom;
125 break;
126 case MID_ZOOMSLIDER_MAXZOOM:
128 rVal <<= mnMaxZoom;
130 break;
131 default:
132 OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
133 return false;
136 return true;
139 bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
141 nMemberId &= ~CONVERT_TWIPS;
142 switch ( nMemberId )
144 case 0 :
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 );
161 ++nConvertedCount;
163 else if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_SNAPPINGPOINTS ))
165 bAllConverted &= ( aSeq[i].Value >>= aValues );
166 ++nConvertedCount;
168 else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MINZOOM ) )
170 bAllConverted &= ( aSeq[i].Value >>= nMinZoom );
171 ++nConvertedCount;
173 else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MAXZOOM ) )
175 bAllConverted &= ( aSeq[i].Value >>= nMaxZoom );
176 ++nConvertedCount;
180 if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
182 SetValue( (sal_uInt16)nCurrentZoom );
183 maValues = aValues;
184 mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
185 mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
187 return true;
191 return false;
194 case MID_ZOOMSLIDER_CURRENTZOOM:
196 sal_Int32 nVal = 0;
197 if ( rVal >>= nVal )
199 SetValue( (sal_uInt16)nVal );
200 return true;
202 else
203 return false;
206 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
208 com::sun::star::uno::Sequence < sal_Int32 > aValues;
209 if ( rVal >>= aValues )
211 maValues = aValues;
212 return true;
214 else
215 return false;
217 case MID_ZOOMSLIDER_MINZOOM:
219 sal_Int32 nVal = 0;
220 if( rVal >>= nVal )
222 mnMinZoom = (sal_uInt16)nVal;
223 return true;
225 else
226 return false;
228 case MID_ZOOMSLIDER_MAXZOOM:
230 sal_Int32 nVal = 0;
231 if( rVal >>= nVal )
233 mnMaxZoom = (sal_uInt16)nVal;
234 return true;
236 else
237 return false;
239 default:
240 OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
241 return false;
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
255 return maValues;
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */