1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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
85 rStrm >> nValue >> nValSet >> nType;
86 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
87 pNew->SetValueSet( nValSet );
92 // -----------------------------------------------------------------------
94 SvStream
& SvxZoomSliderItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
96 /* rStrm << (sal_uInt16)GetValue()
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
;
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
;
134 case MID_ZOOMSLIDER_CURRENTZOOM
:
136 rVal
<<= (sal_Int32
) GetValue();
139 case MID_ZOOMSLIDER_SNAPPINGPOINTS
:
144 case MID_ZOOMSLIDER_MINZOOM
:
149 case MID_ZOOMSLIDER_MAXZOOM
:
155 DBG_ERROR("svx::SvxZoomSliderItem::QueryValue(), Wrong MemberId!");
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
;
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
);
187 else if ( aSeq
[i
].Name
.equalsAscii( ZOOMSLIDER_PARAM_SNAPPINGPOINTS
))
189 bAllConverted
&= ( aSeq
[i
].Value
>>= aValues
);
192 else if( aSeq
[i
].Name
.equalsAscii( ZOOMSLIDER_PARAM_MINZOOM
) )
194 bAllConverted
&= ( aSeq
[i
].Value
>>= nMinZoom
);
197 else if( aSeq
[i
].Name
.equalsAscii( ZOOMSLIDER_PARAM_MAXZOOM
) )
199 bAllConverted
&= ( aSeq
[i
].Value
>>= nMaxZoom
);
204 if ( bAllConverted
&& nConvertedCount
== ZOOMSLIDER_PARAMS
)
206 SetValue( (UINT16
)nCurrentZoom
);
208 mnMinZoom
= sal::static_int_cast
< USHORT
>( nMinZoom
);
209 mnMaxZoom
= sal::static_int_cast
< USHORT
>( nMaxZoom
);
218 case MID_ZOOMSLIDER_CURRENTZOOM
:
223 SetValue( (UINT16
)nVal
);
230 case MID_ZOOMSLIDER_SNAPPINGPOINTS
:
232 com::sun::star::uno::Sequence
< sal_Int32
> aValues
;
233 if ( rVal
>>= aValues
)
241 case MID_ZOOMSLIDER_MINZOOM
:
246 mnMinZoom
= (UINT16
)nVal
;
252 case MID_ZOOMSLIDER_MAXZOOM
:
257 mnMaxZoom
= (UINT16
)nVal
;
264 DBG_ERROR("svx::SvxZoomSliderItem::PutValue(), Wrong MemberId!");
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