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