bump product version to 4.1.6.2
[LibreOffice.git] / sfx2 / source / doc / zoomitem.cxx
blobc6a40f94e2f61beb7dc0a4756ffa725fe888c81a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/stream.hxx>
21 #include <basic/sbxvar.hxx>
23 #include <sfx2/zoomitem.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include "sfx.hrc"
27 // -----------------------------------------------------------------------
29 TYPEINIT1_FACTORY(SvxZoomItem,SfxUInt16Item, new SvxZoomItem);
31 #define ZOOM_PARAM_VALUE "Value"
32 #define ZOOM_PARAM_VALUESET "ValueSet"
33 #define ZOOM_PARAM_TYPE "Type"
34 #define ZOOM_PARAMS 3
36 // -----------------------------------------------------------------------
38 SvxZoomItem::SvxZoomItem
40 SvxZoomType eZoomType,
41 sal_uInt16 nVal,
42 sal_uInt16 _nWhich
44 : SfxUInt16Item( _nWhich, nVal ),
45 nValueSet( SVX_ZOOM_ENABLE_ALL ),
46 eType( eZoomType )
50 // -----------------------------------------------------------------------
52 SvxZoomItem::SvxZoomItem( const SvxZoomItem& rOrig )
53 : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
54 nValueSet( rOrig.GetValueSet() ),
55 eType( rOrig.GetType() )
59 // -----------------------------------------------------------------------
61 SvxZoomItem::~SvxZoomItem()
65 // -----------------------------------------------------------------------
67 SfxPoolItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const
69 return new SvxZoomItem( *this );
72 // -----------------------------------------------------------------------
74 SfxPoolItem* SvxZoomItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
76 sal_uInt16 nValue;
77 sal_uInt16 nValSet;
78 sal_Int8 nType;
79 rStrm >> nValue >> nValSet >> nType;
80 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
81 pNew->SetValueSet( nValSet );
82 return pNew;
85 // -----------------------------------------------------------------------
87 SvStream& SvxZoomItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
89 rStrm << (sal_uInt16)GetValue()
90 << nValueSet
91 << (sal_Int8)eType;
92 return rStrm;
95 // -----------------------------------------------------------------------
97 int SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
99 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
101 SvxZoomItem& rItem = (SvxZoomItem&)rAttr;
103 return ( GetValue() == rItem.GetValue() &&
104 nValueSet == rItem.GetValueSet() &&
105 eType == rItem.GetType() );
108 bool SvxZoomItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
110 nMemberId &= ~CONVERT_TWIPS;
111 switch( nMemberId )
113 case 0:
115 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOM_PARAMS );
116 aSeq[0].Name = OUString( ZOOM_PARAM_VALUE );
117 aSeq[0].Value <<= sal_Int32( GetValue() );
118 aSeq[1].Name = OUString( ZOOM_PARAM_VALUESET );
119 aSeq[1].Value <<= sal_Int16( nValueSet );
120 aSeq[2].Name = OUString( ZOOM_PARAM_TYPE );
121 aSeq[2].Value <<= sal_Int16( eType );
122 rVal <<= aSeq;
123 break;
126 case MID_VALUE: rVal <<= (sal_Int32) GetValue(); break;
127 case MID_VALUESET: rVal <<= (sal_Int16) nValueSet; break;
128 case MID_TYPE: rVal <<= (sal_Int16) eType; break;
129 default:
130 OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
131 return false;
134 return true;
137 bool SvxZoomItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
139 nMemberId &= ~CONVERT_TWIPS;
140 switch( nMemberId )
142 case 0:
144 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
145 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
147 sal_Int32 nValueTmp( 0 );
148 sal_Int16 nValueSetTmp( 0 );
149 sal_Int16 nTypeTmp( 0 );
150 sal_Bool bAllConverted( sal_True );
151 sal_Int16 nConvertedCount( 0 );
152 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
154 if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUE ))
156 bAllConverted &= ( aSeq[i].Value >>= nValueTmp );
157 ++nConvertedCount;
159 else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUESET ))
161 bAllConverted &= ( aSeq[i].Value >>= nValueSetTmp );
162 ++nConvertedCount;
164 else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_TYPE ))
166 bAllConverted &= ( aSeq[i].Value >>= nTypeTmp );
167 ++nConvertedCount;
171 if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
173 SetValue( (sal_uInt16)nValueTmp );
174 nValueSet = nValueSetTmp;
175 eType = SvxZoomType( nTypeTmp );
176 return true;
179 return false;
181 case MID_VALUE:
183 sal_Int32 nVal = 0;
184 if ( rVal >>= nVal )
186 SetValue( (sal_uInt16)nVal );
187 return true;
189 else
190 return false;
193 case MID_VALUESET:
194 case MID_TYPE:
196 sal_Int16 nVal = sal_Int16();
197 if ( rVal >>= nVal )
199 if ( nMemberId == MID_VALUESET )
200 nValueSet = (sal_Int16) nVal;
201 else if ( nMemberId == MID_TYPE )
202 eType = SvxZoomType( (sal_Int16) nVal );
203 return true;
205 else
206 return false;
209 default:
210 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
211 return false;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */