Update ooo320-m1
[ooovba.git] / svx / source / items / zoomslideritem.cxx
bloba4ed25e94279262e4ba213ebcd91e9ddb70d6314
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: zoomslideritem.cxx,v $
10 * $Revision: 1.3.138.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <tools/stream.hxx>
35 #include <svx/zoomslideritem.hxx>
36 #include <com/sun/star/beans/PropertyValue.hpp>
38 // -----------------------------------------------------------------------
40 TYPEINIT1_FACTORY(SvxZoomSliderItem,SfxUInt16Item, new SvxZoomSliderItem);
42 #define ZOOMSLIDER_PARAM_CURRENTZOOM "Columns"
43 #define ZOOMSLIDER_PARAM_SNAPPINGPOINTS "SnappingPoints"
44 #define ZOOMSLIDER_PARAM_MINZOOM "MinValue"
45 #define ZOOMSLIDER_PARAM_MAXZOOM "MaxValue"
46 #define ZOOMSLIDER_PARAMS 4
48 // -----------------------------------------------------------------------
50 SvxZoomSliderItem::SvxZoomSliderItem( USHORT nCurrentZoom, USHORT nMinZoom, USHORT nMaxZoom, USHORT _nWhich )
51 : SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
55 // -----------------------------------------------------------------------
57 SvxZoomSliderItem::SvxZoomSliderItem( const SvxZoomSliderItem& rOrig )
58 : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() )
59 , maValues( rOrig.maValues )
60 , mnMinZoom( rOrig.mnMinZoom )
61 , mnMaxZoom( rOrig.mnMaxZoom )
65 // -----------------------------------------------------------------------
67 SvxZoomSliderItem::~SvxZoomSliderItem()
71 // -----------------------------------------------------------------------
73 SfxPoolItem* SvxZoomSliderItem::Clone( SfxItemPool * /*pPool*/ ) const
75 return new SvxZoomSliderItem( *this );
78 // -----------------------------------------------------------------------
80 SfxPoolItem* SvxZoomSliderItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const
82 /* sal_uInt16 nValue;
83 sal_uInt16 nValSet;
84 sal_Int8 nType;
85 rStrm >> nValue >> nValSet >> nType;
86 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
87 pNew->SetValueSet( nValSet );
88 return pNew;*/
89 return 0;
92 // -----------------------------------------------------------------------
94 SvStream& SvxZoomSliderItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
96 /* rStrm << (sal_uInt16)GetValue()
97 << nValueSet
98 << (sal_Int8)eType;*/
99 return rStrm;
102 // -----------------------------------------------------------------------
104 int SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const
106 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
108 SvxZoomSliderItem& rItem = (SvxZoomSliderItem&)rAttr;
110 return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
111 mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
114 sal_Bool SvxZoomSliderItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId ) const
116 nMemberId &= ~CONVERT_TWIPS;
117 switch ( nMemberId )
119 case 0 :
121 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOMSLIDER_PARAMS );
122 aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_CURRENTZOOM ));
123 aSeq[0].Value <<= sal_Int32( GetValue() );
124 aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_SNAPPINGPOINTS ));
125 aSeq[1].Value <<= maValues;
126 aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_MINZOOM ) );
127 aSeq[2].Value <<= mnMinZoom;
128 aSeq[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_MAXZOOM ) );
129 aSeq[3].Value <<= mnMaxZoom;
130 rVal <<= aSeq;
132 break;
134 case MID_ZOOMSLIDER_CURRENTZOOM :
136 rVal <<= (sal_Int32) GetValue();
138 break;
139 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
141 rVal <<= maValues;
143 break;
144 case MID_ZOOMSLIDER_MINZOOM:
146 rVal <<= mnMinZoom;
148 break;
149 case MID_ZOOMSLIDER_MAXZOOM:
151 rVal <<= mnMaxZoom;
153 break;
154 default:
155 DBG_ERROR("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
156 return sal_False;
159 return sal_True;
162 sal_Bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId )
164 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
165 nMemberId &= ~CONVERT_TWIPS;
166 switch ( nMemberId )
168 case 0 :
170 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
171 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
173 sal_Int32 nCurrentZoom( 0 );
174 com::sun::star::uno::Sequence < sal_Int32 > aValues;
176 sal_Bool bAllConverted( sal_True );
177 sal_Int16 nConvertedCount( 0 );
178 sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
180 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
182 if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_CURRENTZOOM ))
184 bAllConverted &= ( aSeq[i].Value >>= nCurrentZoom );
185 ++nConvertedCount;
187 else if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_SNAPPINGPOINTS ))
189 bAllConverted &= ( aSeq[i].Value >>= aValues );
190 ++nConvertedCount;
192 else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MINZOOM ) )
194 bAllConverted &= ( aSeq[i].Value >>= nMinZoom );
195 ++nConvertedCount;
197 else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MAXZOOM ) )
199 bAllConverted &= ( aSeq[i].Value >>= nMaxZoom );
200 ++nConvertedCount;
204 if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
206 SetValue( (UINT16)nCurrentZoom );
207 maValues = aValues;
208 mnMinZoom = sal::static_int_cast< USHORT >( nMinZoom );
209 mnMaxZoom = sal::static_int_cast< USHORT >( nMaxZoom );
211 return sal_True;
215 return sal_False;
218 case MID_ZOOMSLIDER_CURRENTZOOM:
220 sal_Int32 nVal = 0;
221 if ( rVal >>= nVal )
223 SetValue( (UINT16)nVal );
224 return sal_True;
226 else
227 return sal_False;
230 case MID_ZOOMSLIDER_SNAPPINGPOINTS:
232 com::sun::star::uno::Sequence < sal_Int32 > aValues;
233 if ( rVal >>= aValues )
235 maValues = aValues;
236 return sal_True;
238 else
239 return sal_False;
241 case MID_ZOOMSLIDER_MINZOOM:
243 sal_Int32 nVal = 0;
244 if( rVal >>= nVal )
246 mnMinZoom = (UINT16)nVal;
247 return sal_True;
249 else
250 return sal_False;
252 case MID_ZOOMSLIDER_MAXZOOM:
254 sal_Int32 nVal = 0;
255 if( rVal >>= nVal )
257 mnMaxZoom = (UINT16)nVal;
258 return sal_True;
260 else
261 return sal_False;
263 default:
264 DBG_ERROR("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
265 return sal_False;
268 return sal_True;
271 void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew )
273 const sal_Int32 nValues = maValues.getLength();
274 maValues.realloc( nValues + 1 );
275 sal_Int32* pValues = maValues.getArray();
276 pValues[ nValues ] = nNew;
279 const com::sun::star::uno::Sequence < sal_Int32 >& SvxZoomSliderItem::GetSnappingPoints() const
281 return maValues;