Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / doc / zoomitem.cxx
blob69a24f376b005322e7753ecddbe0741d6a32329b
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 <osl/diagnose.h>
27 #include <sfx2/sfx.hrc>
30 TYPEINIT1_FACTORY(SvxZoomItem,SfxUInt16Item, new SvxZoomItem);
32 #define ZOOM_PARAM_VALUE "Value"
33 #define ZOOM_PARAM_VALUESET "ValueSet"
34 #define ZOOM_PARAM_TYPE "Type"
35 #define ZOOM_PARAMS 3
39 SvxZoomItem::SvxZoomItem
41 SvxZoomType eZoomType,
42 sal_uInt16 nVal,
43 sal_uInt16 _nWhich
45 : SfxUInt16Item( _nWhich, nVal ),
46 nValueSet( SvxZoomEnableFlags::ALL ),
47 eType( eZoomType )
53 SvxZoomItem::SvxZoomItem( const SvxZoomItem& rOrig )
54 : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
55 nValueSet( rOrig.GetValueSet() ),
56 eType( rOrig.GetType() )
62 SvxZoomItem::~SvxZoomItem()
68 SfxPoolItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const
70 return new SvxZoomItem( *this );
75 SfxPoolItem* SvxZoomItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
77 sal_uInt16 nValue;
78 sal_uInt16 nValSet;
79 sal_Int8 nType;
80 rStrm.ReadUInt16( nValue ).ReadUInt16( nValSet ).ReadSChar( nType );
81 SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
82 pNew->SetValueSet( static_cast<SvxZoomEnableFlags>(nValSet) );
83 return pNew;
88 SvStream& SvxZoomItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
90 rStrm.WriteUInt16( GetValue() )
91 .WriteUInt16( static_cast<sal_uInt16>(nValueSet) )
92 .WriteSChar( static_cast<int>(eType) );
93 return rStrm;
98 bool SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
100 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
102 const SvxZoomItem& rItem = static_cast<const SvxZoomItem&>(rAttr);
104 return ( GetValue() == rItem.GetValue() &&
105 nValueSet == rItem.GetValueSet() &&
106 eType == rItem.GetType() );
109 bool SvxZoomItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
111 nMemberId &= ~CONVERT_TWIPS;
112 switch( nMemberId )
114 case 0:
116 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOM_PARAMS );
117 aSeq[0].Name = ZOOM_PARAM_VALUE;
118 aSeq[0].Value <<= sal_Int32( GetValue() );
119 aSeq[1].Name = ZOOM_PARAM_VALUESET;
120 aSeq[1].Value <<= sal_Int16( nValueSet );
121 aSeq[2].Name = ZOOM_PARAM_TYPE;
122 aSeq[2].Value <<= sal_Int16( eType );
123 rVal <<= aSeq;
124 break;
127 case MID_VALUE: rVal <<= (sal_Int32) GetValue(); break;
128 case MID_VALUESET: rVal <<= (sal_Int16) nValueSet; break;
129 case MID_TYPE: rVal <<= (sal_Int16) eType; break;
130 default:
131 OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
132 return false;
135 return true;
138 bool SvxZoomItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
140 nMemberId &= ~CONVERT_TWIPS;
141 switch( nMemberId )
143 case 0:
145 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
146 if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
148 sal_Int32 nValueTmp( 0 );
149 sal_Int16 nValueSetTmp( 0 );
150 sal_Int16 nTypeTmp( 0 );
151 bool bAllConverted( true );
152 sal_Int16 nConvertedCount( 0 );
153 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
155 if ( aSeq[i].Name == ZOOM_PARAM_VALUE )
157 bAllConverted &= ( aSeq[i].Value >>= nValueTmp );
158 ++nConvertedCount;
160 else if ( aSeq[i].Name == ZOOM_PARAM_VALUESET )
162 bAllConverted &= ( aSeq[i].Value >>= nValueSetTmp );
163 ++nConvertedCount;
165 else if ( aSeq[i].Name == ZOOM_PARAM_TYPE )
167 bAllConverted &= ( aSeq[i].Value >>= nTypeTmp );
168 ++nConvertedCount;
172 if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
174 SetValue( (sal_uInt16)nValueTmp );
175 nValueSet = static_cast<SvxZoomEnableFlags>(nValueSetTmp);
176 eType = static_cast<SvxZoomType>(nTypeTmp);
177 return true;
180 return false;
182 case MID_VALUE:
184 sal_Int32 nVal = 0;
185 if ( rVal >>= nVal )
187 SetValue( (sal_uInt16)nVal );
188 return true;
190 else
191 return false;
194 case MID_VALUESET:
195 case MID_TYPE:
197 sal_Int16 nVal;
198 if ( rVal >>= nVal )
200 if ( nMemberId == MID_VALUESET )
201 nValueSet = static_cast<SvxZoomEnableFlags>(nVal);
202 else if ( nMemberId == MID_TYPE )
203 eType = static_cast<SvxZoomType>(nVal);
204 return true;
206 else
207 return false;
210 default:
211 OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
212 return false;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */