Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <tools/stream.hxx>
21 :
22 : #include <osl/diagnose.h>
23 :
24 : #include <svx/zoomslideritem.hxx>
25 : #include <com/sun/star/beans/PropertyValue.hpp>
26 :
27 :
28 :
29 10597 : TYPEINIT1_FACTORY(SvxZoomSliderItem,SfxUInt16Item, new SvxZoomSliderItem);
30 :
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
36 :
37 :
38 :
39 2325 : SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, sal_uInt16 _nWhich )
40 2325 : : SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom )
41 : {
42 2325 : }
43 :
44 :
45 :
46 2738 : SvxZoomSliderItem::SvxZoomSliderItem( const SvxZoomSliderItem& rOrig )
47 5476 : : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() )
48 : , maValues( rOrig.maValues )
49 : , mnMinZoom( rOrig.mnMinZoom )
50 5476 : , mnMaxZoom( rOrig.mnMaxZoom )
51 : {
52 2738 : }
53 :
54 :
55 :
56 8810 : SvxZoomSliderItem::~SvxZoomSliderItem()
57 : {
58 8810 : }
59 :
60 :
61 :
62 2738 : SfxPoolItem* SvxZoomSliderItem::Clone( SfxItemPool * /*pPool*/ ) const
63 : {
64 2738 : return new SvxZoomSliderItem( *this );
65 : }
66 :
67 :
68 :
69 0 : SfxPoolItem* SvxZoomSliderItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const
70 : {
71 0 : return 0;
72 : }
73 :
74 :
75 :
76 0 : SvStream& SvxZoomSliderItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
77 : {
78 0 : return rStrm;
79 : }
80 :
81 :
82 :
83 317 : bool SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const
84 : {
85 : DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
86 :
87 317 : const SvxZoomSliderItem& rItem = static_cast<const SvxZoomSliderItem&>(rAttr);
88 :
89 933 : return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues &&
90 931 : mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom );
91 : }
92 :
93 1009 : bool SvxZoomSliderItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
94 : {
95 1009 : nMemberId &= ~CONVERT_TWIPS;
96 1009 : switch ( nMemberId )
97 : {
98 : case 0 :
99 : {
100 1009 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOMSLIDER_PARAMS );
101 1009 : aSeq[0].Name = ZOOMSLIDER_PARAM_CURRENTZOOM;
102 1009 : aSeq[0].Value <<= sal_Int32( GetValue() );
103 1009 : aSeq[1].Name = ZOOMSLIDER_PARAM_SNAPPINGPOINTS;
104 1009 : aSeq[1].Value <<= maValues;
105 1009 : aSeq[2].Name = ZOOMSLIDER_PARAM_MINZOOM;
106 1009 : aSeq[2].Value <<= mnMinZoom;
107 1009 : aSeq[3].Name = ZOOMSLIDER_PARAM_MAXZOOM;
108 1009 : aSeq[3].Value <<= mnMaxZoom;
109 1009 : rVal <<= aSeq;
110 : }
111 1009 : break;
112 :
113 : case MID_ZOOMSLIDER_CURRENTZOOM :
114 : {
115 0 : rVal <<= (sal_Int32) GetValue();
116 : }
117 0 : break;
118 : case MID_ZOOMSLIDER_SNAPPINGPOINTS:
119 : {
120 0 : rVal <<= maValues;
121 : }
122 0 : break;
123 : case MID_ZOOMSLIDER_MINZOOM:
124 : {
125 0 : rVal <<= mnMinZoom;
126 : }
127 0 : break;
128 : case MID_ZOOMSLIDER_MAXZOOM:
129 : {
130 0 : rVal <<= mnMaxZoom;
131 : }
132 0 : break;
133 : default:
134 : OSL_FAIL("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
135 0 : return false;
136 : }
137 :
138 1009 : return true;
139 : }
140 :
141 1009 : bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
142 : {
143 1009 : nMemberId &= ~CONVERT_TWIPS;
144 1009 : switch ( nMemberId )
145 : {
146 : case 0 :
147 : {
148 1009 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
149 1009 : if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS ))
150 : {
151 1009 : sal_Int32 nCurrentZoom( 0 );
152 1009 : com::sun::star::uno::Sequence < sal_Int32 > aValues;
153 :
154 1009 : bool bAllConverted( true );
155 1009 : sal_Int16 nConvertedCount( 0 );
156 1009 : sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 );
157 :
158 5045 : for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
159 : {
160 4036 : if ( aSeq[i].Name == ZOOMSLIDER_PARAM_CURRENTZOOM )
161 : {
162 1009 : bAllConverted &= ( aSeq[i].Value >>= nCurrentZoom );
163 1009 : ++nConvertedCount;
164 : }
165 3027 : else if ( aSeq[i].Name == ZOOMSLIDER_PARAM_SNAPPINGPOINTS )
166 : {
167 1009 : bAllConverted &= ( aSeq[i].Value >>= aValues );
168 1009 : ++nConvertedCount;
169 : }
170 2018 : else if( aSeq[i].Name == ZOOMSLIDER_PARAM_MINZOOM )
171 : {
172 1009 : bAllConverted &= ( aSeq[i].Value >>= nMinZoom );
173 1009 : ++nConvertedCount;
174 : }
175 1009 : else if( aSeq[i].Name == ZOOMSLIDER_PARAM_MAXZOOM )
176 : {
177 1009 : bAllConverted &= ( aSeq[i].Value >>= nMaxZoom );
178 1009 : ++nConvertedCount;
179 : }
180 : }
181 :
182 1009 : if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS )
183 : {
184 1009 : SetValue( (sal_uInt16)nCurrentZoom );
185 1009 : maValues = aValues;
186 1009 : mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom );
187 1009 : mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom );
188 :
189 1009 : return true;
190 0 : }
191 : }
192 :
193 0 : return false;
194 : }
195 :
196 : case MID_ZOOMSLIDER_CURRENTZOOM:
197 : {
198 0 : sal_Int32 nVal = 0;
199 0 : if ( rVal >>= nVal )
200 : {
201 0 : SetValue( (sal_uInt16)nVal );
202 0 : return true;
203 : }
204 : else
205 0 : return false;
206 : }
207 :
208 : case MID_ZOOMSLIDER_SNAPPINGPOINTS:
209 : {
210 0 : com::sun::star::uno::Sequence < sal_Int32 > aValues;
211 0 : if ( rVal >>= aValues )
212 : {
213 0 : maValues = aValues;
214 0 : return true;
215 : }
216 : else
217 0 : return false;
218 : }
219 : case MID_ZOOMSLIDER_MINZOOM:
220 : {
221 0 : sal_Int32 nVal = 0;
222 0 : if( rVal >>= nVal )
223 : {
224 0 : mnMinZoom = (sal_uInt16)nVal;
225 0 : return true;
226 : }
227 : else
228 0 : return false;
229 : }
230 : case MID_ZOOMSLIDER_MAXZOOM:
231 : {
232 0 : sal_Int32 nVal = 0;
233 0 : if( rVal >>= nVal )
234 : {
235 0 : mnMaxZoom = (sal_uInt16)nVal;
236 0 : return true;
237 : }
238 : else
239 0 : return false;
240 : }
241 : default:
242 : OSL_FAIL("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
243 0 : return false;
244 : }
245 : }
246 :
247 2323 : void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew )
248 : {
249 2323 : const sal_Int32 nValues = maValues.getLength();
250 2323 : maValues.realloc( nValues + 1 );
251 2323 : sal_Int32* pValues = maValues.getArray();
252 2323 : pValues[ nValues ] = nNew;
253 2323 : }
254 :
255 :
256 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|