bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / items / zoomslideritem.cxx
blob2c980e02d5b5d1413e59f991e06824ac18b51bd8
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 <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
71 return 0;
76 SvStream& SvxZoomSliderItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
78 return rStrm;
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;
96 switch ( nMemberId )
98 case 0 :
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;
109 rVal <<= aSeq;
111 break;
113 case MID_ZOOMSLIDER_CURRENTZOOM :
115 rVal <<= (sal_Int32) GetValue();
117 break;
118 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
120 rVal <<= maValues;
122 break;
123 case MID_ZOOMSLIDER_MINZOOM:
125 rVal <<= mnMinZoom;
127 break;
128 case MID_ZOOMSLIDER_MAXZOOM:
130 rVal <<= mnMaxZoom;
132 break;
133 default:
134 OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
135 return false;
138 return true;
141 bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
143 nMemberId &= ~CONVERT_TWIPS;
144 switch ( nMemberId )
146 case 0 :
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 );
163 ++nConvertedCount;
165 else if ( aSeq[i].Name == ZOOMSLIDER_PARAM_SNAPPINGPOINTS )
167 bAllConverted &= ( aSeq[i].Value >>= aValues );
168 ++nConvertedCount;
170 else if( aSeq[i].Name == ZOOMSLIDER_PARAM_MINZOOM )
172 bAllConverted &= ( aSeq[i].Value >>= nMinZoom );
173 ++nConvertedCount;
175 else if( aSeq[i].Name == ZOOMSLIDER_PARAM_MAXZOOM )
177 bAllConverted &= ( aSeq[i].Value >>= nMaxZoom );
178 ++nConvertedCount;
182 if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
184 SetValue( (sal_uInt16)nCurrentZoom );
185 maValues = aValues;
186 mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
187 mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
189 return true;
193 return false;
196 case MID_ZOOMSLIDER_CURRENTZOOM:
198 sal_Int32 nVal = 0;
199 if ( rVal >>= nVal )
201 SetValue( (sal_uInt16)nVal );
202 return true;
204 else
205 return false;
208 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
210 com::sun::star::uno::Sequence < sal_Int32 > aValues;
211 if ( rVal >>= aValues )
213 maValues = aValues;
214 return true;
216 else
217 return false;
219 case MID_ZOOMSLIDER_MINZOOM:
221 sal_Int32 nVal = 0;
222 if( rVal >>= nVal )
224 mnMinZoom = (sal_uInt16)nVal;
225 return true;
227 else
228 return false;
230 case MID_ZOOMSLIDER_MAXZOOM:
232 sal_Int32 nVal = 0;
233 if( rVal >>= nVal )
235 mnMaxZoom = (sal_uInt16)nVal;
236 return true;
238 else
239 return false;
241 default:
242 OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
243 return false;
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: */