1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <tools/stream.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <svx/zoomslideritem.hxx>
29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // -----------------------------------------------------------------------
32cdf0e10cSrcweir 
33cdf0e10cSrcweir TYPEINIT1_FACTORY(SvxZoomSliderItem,SfxUInt16Item, new SvxZoomSliderItem);
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #define ZOOMSLIDER_PARAM_CURRENTZOOM    "Columns"
36cdf0e10cSrcweir #define ZOOMSLIDER_PARAM_SNAPPINGPOINTS "SnappingPoints"
37cdf0e10cSrcweir #define ZOOMSLIDER_PARAM_MINZOOM        "MinValue"
38cdf0e10cSrcweir #define ZOOMSLIDER_PARAM_MAXZOOM        "MaxValue"
39cdf0e10cSrcweir #define ZOOMSLIDER_PARAMS           4
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // -----------------------------------------------------------------------
42cdf0e10cSrcweir 
SvxZoomSliderItem(sal_uInt16 nCurrentZoom,sal_uInt16 nMinZoom,sal_uInt16 nMaxZoom,sal_uInt16 _nWhich)43cdf0e10cSrcweir SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, sal_uInt16 _nWhich )
44cdf0e10cSrcweir :   SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // -----------------------------------------------------------------------
49cdf0e10cSrcweir 
SvxZoomSliderItem(const SvxZoomSliderItem & rOrig)50cdf0e10cSrcweir SvxZoomSliderItem::SvxZoomSliderItem( const SvxZoomSliderItem& rOrig )
51cdf0e10cSrcweir : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() )
52cdf0e10cSrcweir , maValues( rOrig.maValues )
53cdf0e10cSrcweir , mnMinZoom( rOrig.mnMinZoom )
54cdf0e10cSrcweir , mnMaxZoom( rOrig.mnMaxZoom )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // -----------------------------------------------------------------------
59cdf0e10cSrcweir 
~SvxZoomSliderItem()60cdf0e10cSrcweir SvxZoomSliderItem::~SvxZoomSliderItem()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir // -----------------------------------------------------------------------
65cdf0e10cSrcweir 
Clone(SfxItemPool *) const66cdf0e10cSrcweir SfxPoolItem* SvxZoomSliderItem::Clone( SfxItemPool * /*pPool*/ ) const
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     return new SvxZoomSliderItem( *this );
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir // -----------------------------------------------------------------------
72cdf0e10cSrcweir 
Create(SvStream &,sal_uInt16) const73cdf0e10cSrcweir SfxPoolItem* SvxZoomSliderItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const
74cdf0e10cSrcweir {
75cdf0e10cSrcweir /*   sal_uInt16 nValue;
76cdf0e10cSrcweir 	sal_uInt16 nValSet;
77cdf0e10cSrcweir 	sal_Int8 nType;
78cdf0e10cSrcweir 	rStrm >> nValue >> nValSet >> nType;
79cdf0e10cSrcweir 	SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
80cdf0e10cSrcweir     pNew->SetValueSet( nValSet );
81cdf0e10cSrcweir     return pNew;*/
82cdf0e10cSrcweir     return 0;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // -----------------------------------------------------------------------
86cdf0e10cSrcweir 
Store(SvStream & rStrm,sal_uInt16) const87cdf0e10cSrcweir SvStream& SvxZoomSliderItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
88cdf0e10cSrcweir {
89cdf0e10cSrcweir /*   rStrm << (sal_uInt16)GetValue()
90cdf0e10cSrcweir 		  << nValueSet
91cdf0e10cSrcweir           << (sal_Int8)eType;*/
92cdf0e10cSrcweir 	return rStrm;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // -----------------------------------------------------------------------
96cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rAttr) const97cdf0e10cSrcweir int SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     SvxZoomSliderItem& rItem = (SvxZoomSliderItem&)rAttr;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
104cdf0e10cSrcweir              mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8 nMemberId) const107cdf0e10cSrcweir sal_Bool SvxZoomSliderItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
110cdf0e10cSrcweir     switch ( nMemberId )
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         case 0 :
113cdf0e10cSrcweir             {
114cdf0e10cSrcweir                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOMSLIDER_PARAMS );
115cdf0e10cSrcweir                 aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_CURRENTZOOM ));
116cdf0e10cSrcweir                 aSeq[0].Value <<= sal_Int32( GetValue() );
117cdf0e10cSrcweir                 aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_SNAPPINGPOINTS ));
118cdf0e10cSrcweir                 aSeq[1].Value <<= maValues;
119cdf0e10cSrcweir                 aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_MINZOOM ) );
120cdf0e10cSrcweir                 aSeq[2].Value <<= mnMinZoom;
121cdf0e10cSrcweir                 aSeq[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_MAXZOOM ) );
122cdf0e10cSrcweir                 aSeq[3].Value <<= mnMaxZoom;
123cdf0e10cSrcweir                 rVal <<= aSeq;
124cdf0e10cSrcweir             }
125cdf0e10cSrcweir             break;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         case MID_ZOOMSLIDER_CURRENTZOOM :
128cdf0e10cSrcweir             {
129cdf0e10cSrcweir                 rVal <<= (sal_Int32) GetValue();
130cdf0e10cSrcweir             }
131cdf0e10cSrcweir             break;
132cdf0e10cSrcweir         case MID_ZOOMSLIDER_SNAPPINGPOINTS:
133cdf0e10cSrcweir             {
134cdf0e10cSrcweir                  rVal <<= maValues;
135cdf0e10cSrcweir             }
136cdf0e10cSrcweir             break;
137cdf0e10cSrcweir         case MID_ZOOMSLIDER_MINZOOM:
138cdf0e10cSrcweir             {
139cdf0e10cSrcweir                 rVal <<= mnMinZoom;
140cdf0e10cSrcweir             }
141cdf0e10cSrcweir             break;
142cdf0e10cSrcweir         case MID_ZOOMSLIDER_MAXZOOM:
143cdf0e10cSrcweir             {
144cdf0e10cSrcweir                 rVal <<= mnMaxZoom;
145cdf0e10cSrcweir             }
146cdf0e10cSrcweir             break;
147cdf0e10cSrcweir         default:
148cdf0e10cSrcweir             DBG_ERROR("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
149cdf0e10cSrcweir             return sal_False;
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     return sal_True;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8 nMemberId)155cdf0e10cSrcweir sal_Bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir //  sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
158cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
159cdf0e10cSrcweir     switch ( nMemberId )
160cdf0e10cSrcweir     {
161cdf0e10cSrcweir         case 0 :
162cdf0e10cSrcweir             {
163cdf0e10cSrcweir                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
164cdf0e10cSrcweir                 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
165cdf0e10cSrcweir                 {
166cdf0e10cSrcweir                     sal_Int32 nCurrentZoom( 0 );
167cdf0e10cSrcweir                     com::sun::star::uno::Sequence < sal_Int32 > aValues;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir                     sal_Bool  bAllConverted( sal_True );
170cdf0e10cSrcweir                     sal_Int16 nConvertedCount( 0 );
171cdf0e10cSrcweir                     sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir                     for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
174cdf0e10cSrcweir                     {
175cdf0e10cSrcweir                         if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_CURRENTZOOM ))
176cdf0e10cSrcweir                         {
177cdf0e10cSrcweir                             bAllConverted &= ( aSeq[i].Value >>= nCurrentZoom );
178cdf0e10cSrcweir                             ++nConvertedCount;
179cdf0e10cSrcweir                         }
180cdf0e10cSrcweir                         else if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_SNAPPINGPOINTS ))
181cdf0e10cSrcweir                         {
182cdf0e10cSrcweir                             bAllConverted &= ( aSeq[i].Value >>= aValues );
183cdf0e10cSrcweir                             ++nConvertedCount;
184cdf0e10cSrcweir                         }
185cdf0e10cSrcweir                         else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MINZOOM ) )
186cdf0e10cSrcweir                         {
187cdf0e10cSrcweir                             bAllConverted &= ( aSeq[i].Value >>= nMinZoom );
188cdf0e10cSrcweir                             ++nConvertedCount;
189cdf0e10cSrcweir                         }
190cdf0e10cSrcweir                         else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MAXZOOM ) )
191cdf0e10cSrcweir                         {
192cdf0e10cSrcweir                             bAllConverted &= ( aSeq[i].Value >>= nMaxZoom );
193cdf0e10cSrcweir                             ++nConvertedCount;
194cdf0e10cSrcweir                         }
195cdf0e10cSrcweir                     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir                     if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
198cdf0e10cSrcweir                     {
199cdf0e10cSrcweir                         SetValue( (sal_uInt16)nCurrentZoom );
200cdf0e10cSrcweir                         maValues = aValues;
201cdf0e10cSrcweir                         mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
202cdf0e10cSrcweir                         mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
203cdf0e10cSrcweir 
204cdf0e10cSrcweir                         return sal_True;
205cdf0e10cSrcweir                     }
206cdf0e10cSrcweir                 }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir                 return sal_False;
209cdf0e10cSrcweir             }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         case MID_ZOOMSLIDER_CURRENTZOOM:
212cdf0e10cSrcweir             {
213cdf0e10cSrcweir                 sal_Int32 nVal = 0;
214cdf0e10cSrcweir                 if ( rVal >>= nVal )
215cdf0e10cSrcweir                 {
216cdf0e10cSrcweir                     SetValue( (sal_uInt16)nVal );
217cdf0e10cSrcweir                     return sal_True;
218cdf0e10cSrcweir                 }
219cdf0e10cSrcweir                 else
220cdf0e10cSrcweir                     return sal_False;
221cdf0e10cSrcweir             }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         case MID_ZOOMSLIDER_SNAPPINGPOINTS:
224cdf0e10cSrcweir             {
225cdf0e10cSrcweir                 com::sun::star::uno::Sequence < sal_Int32 > aValues;
226cdf0e10cSrcweir                 if ( rVal >>= aValues )
227cdf0e10cSrcweir                 {
228cdf0e10cSrcweir                     maValues = aValues;
229cdf0e10cSrcweir                     return sal_True;
230cdf0e10cSrcweir                 }
231cdf0e10cSrcweir                 else
232cdf0e10cSrcweir                     return sal_False;
233cdf0e10cSrcweir             }
234cdf0e10cSrcweir         case MID_ZOOMSLIDER_MINZOOM:
235cdf0e10cSrcweir             {
236cdf0e10cSrcweir                 sal_Int32 nVal = 0;
237cdf0e10cSrcweir                 if( rVal >>= nVal )
238cdf0e10cSrcweir                 {
239cdf0e10cSrcweir                     mnMinZoom = (sal_uInt16)nVal;
240cdf0e10cSrcweir                     return sal_True;
241cdf0e10cSrcweir                 }
242cdf0e10cSrcweir                 else
243cdf0e10cSrcweir                     return sal_False;
244cdf0e10cSrcweir             }
245cdf0e10cSrcweir         case MID_ZOOMSLIDER_MAXZOOM:
246cdf0e10cSrcweir             {
247cdf0e10cSrcweir                 sal_Int32 nVal = 0;
248cdf0e10cSrcweir                 if( rVal >>= nVal )
249cdf0e10cSrcweir                 {
250cdf0e10cSrcweir                     mnMaxZoom = (sal_uInt16)nVal;
251cdf0e10cSrcweir                     return sal_True;
252cdf0e10cSrcweir                 }
253cdf0e10cSrcweir                 else
254cdf0e10cSrcweir                     return sal_False;
255cdf0e10cSrcweir             }
256cdf0e10cSrcweir         default:
257cdf0e10cSrcweir             DBG_ERROR("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
258cdf0e10cSrcweir             return sal_False;
259cdf0e10cSrcweir     }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     return sal_True;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
AddSnappingPoint(sal_Int32 nNew)264cdf0e10cSrcweir void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew )
265cdf0e10cSrcweir {
266cdf0e10cSrcweir     const sal_Int32 nValues = maValues.getLength();
267cdf0e10cSrcweir     maValues.realloc(  nValues + 1 );
268cdf0e10cSrcweir     sal_Int32* pValues = maValues.getArray();
269cdf0e10cSrcweir     pValues[ nValues ] = nNew;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
GetSnappingPoints() const272cdf0e10cSrcweir const com::sun::star::uno::Sequence < sal_Int32 >& SvxZoomSliderItem::GetSnappingPoints() const
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     return maValues;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
277