1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 #include <tools/stream.hxx> 31 32 #include <svx/zoomslideritem.hxx> 33 #include <com/sun/star/beans/PropertyValue.hpp> 34 35 // ----------------------------------------------------------------------- 36 37 TYPEINIT1_FACTORY(SvxZoomSliderItem,SfxUInt16Item, new SvxZoomSliderItem); 38 39 #define ZOOMSLIDER_PARAM_CURRENTZOOM "Columns" 40 #define ZOOMSLIDER_PARAM_SNAPPINGPOINTS "SnappingPoints" 41 #define ZOOMSLIDER_PARAM_MINZOOM "MinValue" 42 #define ZOOMSLIDER_PARAM_MAXZOOM "MaxValue" 43 #define ZOOMSLIDER_PARAMS 4 44 45 // ----------------------------------------------------------------------- 46 47 SvxZoomSliderItem::SvxZoomSliderItem( sal_uInt16 nCurrentZoom, sal_uInt16 nMinZoom, sal_uInt16 nMaxZoom, sal_uInt16 _nWhich ) 48 : SfxUInt16Item( _nWhich, nCurrentZoom ), mnMinZoom( nMinZoom ), mnMaxZoom( nMaxZoom ) 49 { 50 } 51 52 // ----------------------------------------------------------------------- 53 54 SvxZoomSliderItem::SvxZoomSliderItem( const SvxZoomSliderItem& rOrig ) 55 : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ) 56 , maValues( rOrig.maValues ) 57 , mnMinZoom( rOrig.mnMinZoom ) 58 , mnMaxZoom( rOrig.mnMaxZoom ) 59 { 60 } 61 62 // ----------------------------------------------------------------------- 63 64 SvxZoomSliderItem::~SvxZoomSliderItem() 65 { 66 } 67 68 // ----------------------------------------------------------------------- 69 70 SfxPoolItem* SvxZoomSliderItem::Clone( SfxItemPool * /*pPool*/ ) const 71 { 72 return new SvxZoomSliderItem( *this ); 73 } 74 75 // ----------------------------------------------------------------------- 76 77 SfxPoolItem* SvxZoomSliderItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const 78 { 79 /* sal_uInt16 nValue; 80 sal_uInt16 nValSet; 81 sal_Int8 nType; 82 rStrm >> nValue >> nValSet >> nType; 83 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() ); 84 pNew->SetValueSet( nValSet ); 85 return pNew;*/ 86 return 0; 87 } 88 89 // ----------------------------------------------------------------------- 90 91 SvStream& SvxZoomSliderItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const 92 { 93 /* rStrm << (sal_uInt16)GetValue() 94 << nValueSet 95 << (sal_Int8)eType;*/ 96 return rStrm; 97 } 98 99 // ----------------------------------------------------------------------- 100 101 int SvxZoomSliderItem::operator==( const SfxPoolItem& rAttr ) const 102 { 103 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" ); 104 105 SvxZoomSliderItem& rItem = (SvxZoomSliderItem&)rAttr; 106 107 return ( GetValue() == rItem.GetValue() && maValues == rItem.maValues && 108 mnMinZoom == rItem.mnMinZoom && mnMaxZoom == rItem.mnMaxZoom ); 109 } 110 111 sal_Bool SvxZoomSliderItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const 112 { 113 nMemberId &= ~CONVERT_TWIPS; 114 switch ( nMemberId ) 115 { 116 case 0 : 117 { 118 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOMSLIDER_PARAMS ); 119 aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_CURRENTZOOM )); 120 aSeq[0].Value <<= sal_Int32( GetValue() ); 121 aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_SNAPPINGPOINTS )); 122 aSeq[1].Value <<= maValues; 123 aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_MINZOOM ) ); 124 aSeq[2].Value <<= mnMinZoom; 125 aSeq[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOMSLIDER_PARAM_MAXZOOM ) ); 126 aSeq[3].Value <<= mnMaxZoom; 127 rVal <<= aSeq; 128 } 129 break; 130 131 case MID_ZOOMSLIDER_CURRENTZOOM : 132 { 133 rVal <<= (sal_Int32) GetValue(); 134 } 135 break; 136 case MID_ZOOMSLIDER_SNAPPINGPOINTS: 137 { 138 rVal <<= maValues; 139 } 140 break; 141 case MID_ZOOMSLIDER_MINZOOM: 142 { 143 rVal <<= mnMinZoom; 144 } 145 break; 146 case MID_ZOOMSLIDER_MAXZOOM: 147 { 148 rVal <<= mnMaxZoom; 149 } 150 break; 151 default: 152 DBG_ERROR("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!"); 153 return sal_False; 154 } 155 156 return sal_True; 157 } 158 159 sal_Bool SvxZoomSliderItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) 160 { 161 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); 162 nMemberId &= ~CONVERT_TWIPS; 163 switch ( nMemberId ) 164 { 165 case 0 : 166 { 167 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq; 168 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOMSLIDER_PARAMS )) 169 { 170 sal_Int32 nCurrentZoom( 0 ); 171 com::sun::star::uno::Sequence < sal_Int32 > aValues; 172 173 sal_Bool bAllConverted( sal_True ); 174 sal_Int16 nConvertedCount( 0 ); 175 sal_Int32 nMinZoom( 0 ), nMaxZoom( 0 ); 176 177 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ ) 178 { 179 if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_CURRENTZOOM )) 180 { 181 bAllConverted &= ( aSeq[i].Value >>= nCurrentZoom ); 182 ++nConvertedCount; 183 } 184 else if ( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_SNAPPINGPOINTS )) 185 { 186 bAllConverted &= ( aSeq[i].Value >>= aValues ); 187 ++nConvertedCount; 188 } 189 else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MINZOOM ) ) 190 { 191 bAllConverted &= ( aSeq[i].Value >>= nMinZoom ); 192 ++nConvertedCount; 193 } 194 else if( aSeq[i].Name.equalsAscii( ZOOMSLIDER_PARAM_MAXZOOM ) ) 195 { 196 bAllConverted &= ( aSeq[i].Value >>= nMaxZoom ); 197 ++nConvertedCount; 198 } 199 } 200 201 if ( bAllConverted && nConvertedCount == ZOOMSLIDER_PARAMS ) 202 { 203 SetValue( (sal_uInt16)nCurrentZoom ); 204 maValues = aValues; 205 mnMinZoom = sal::static_int_cast< sal_uInt16 >( nMinZoom ); 206 mnMaxZoom = sal::static_int_cast< sal_uInt16 >( nMaxZoom ); 207 208 return sal_True; 209 } 210 } 211 212 return sal_False; 213 } 214 215 case MID_ZOOMSLIDER_CURRENTZOOM: 216 { 217 sal_Int32 nVal = 0; 218 if ( rVal >>= nVal ) 219 { 220 SetValue( (sal_uInt16)nVal ); 221 return sal_True; 222 } 223 else 224 return sal_False; 225 } 226 227 case MID_ZOOMSLIDER_SNAPPINGPOINTS: 228 { 229 com::sun::star::uno::Sequence < sal_Int32 > aValues; 230 if ( rVal >>= aValues ) 231 { 232 maValues = aValues; 233 return sal_True; 234 } 235 else 236 return sal_False; 237 } 238 case MID_ZOOMSLIDER_MINZOOM: 239 { 240 sal_Int32 nVal = 0; 241 if( rVal >>= nVal ) 242 { 243 mnMinZoom = (sal_uInt16)nVal; 244 return sal_True; 245 } 246 else 247 return sal_False; 248 } 249 case MID_ZOOMSLIDER_MAXZOOM: 250 { 251 sal_Int32 nVal = 0; 252 if( rVal >>= nVal ) 253 { 254 mnMaxZoom = (sal_uInt16)nVal; 255 return sal_True; 256 } 257 else 258 return sal_False; 259 } 260 default: 261 DBG_ERROR("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!"); 262 return sal_False; 263 } 264 265 return sal_True; 266 } 267 268 void SvxZoomSliderItem::AddSnappingPoint( sal_Int32 nNew ) 269 { 270 const sal_Int32 nValues = maValues.getLength(); 271 maValues.realloc( nValues + 1 ); 272 sal_Int32* pValues = maValues.getArray(); 273 pValues[ nValues ] = nNew; 274 } 275 276 const com::sun::star::uno::Sequence < sal_Int32 >& SvxZoomSliderItem::GetSnappingPoints() const 277 { 278 return maValues; 279 } 280 281