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 : #include <basic/sbxvar.hxx>
22 :
23 : #include <sfx2/zoomitem.hxx>
24 : #include <com/sun/star/uno/Sequence.hxx>
25 : #include <com/sun/star/beans/PropertyValue.hpp>
26 : #include <sfx2/sfx.hrc>
27 :
28 :
29 28423 : TYPEINIT1_FACTORY(SvxZoomItem,SfxUInt16Item, new SvxZoomItem);
30 :
31 : #define ZOOM_PARAM_VALUE "Value"
32 : #define ZOOM_PARAM_VALUESET "ValueSet"
33 : #define ZOOM_PARAM_TYPE "Type"
34 : #define ZOOM_PARAMS 3
35 :
36 :
37 :
38 4388 : SvxZoomItem::SvxZoomItem
39 : (
40 : SvxZoomType eZoomType,
41 : sal_uInt16 nVal,
42 : sal_uInt16 _nWhich
43 : )
44 : : SfxUInt16Item( _nWhich, nVal ),
45 : nValueSet( SVX_ZOOM_ENABLE_ALL ),
46 4388 : eType( eZoomType )
47 : {
48 4388 : }
49 :
50 :
51 :
52 5610 : SvxZoomItem::SvxZoomItem( const SvxZoomItem& rOrig )
53 11220 : : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
54 5610 : nValueSet( rOrig.GetValueSet() ),
55 16830 : eType( rOrig.GetType() )
56 : {
57 5610 : }
58 :
59 :
60 :
61 17499 : SvxZoomItem::~SvxZoomItem()
62 : {
63 17499 : }
64 :
65 :
66 :
67 5610 : SfxPoolItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const
68 : {
69 5610 : return new SvxZoomItem( *this );
70 : }
71 :
72 :
73 :
74 0 : SfxPoolItem* SvxZoomItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
75 : {
76 : sal_uInt16 nValue;
77 : sal_uInt16 nValSet;
78 : sal_Int8 nType;
79 0 : rStrm.ReadUInt16( nValue ).ReadUInt16( nValSet ).ReadSChar( nType );
80 0 : SvxZoomItem* pNew = new SvxZoomItem( (SvxZoomType)nType, nValue, Which() );
81 0 : pNew->SetValueSet( nValSet );
82 0 : return pNew;
83 : }
84 :
85 :
86 :
87 0 : SvStream& SvxZoomItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
88 : {
89 0 : rStrm.WriteUInt16( GetValue() )
90 0 : .WriteUInt16( nValueSet )
91 0 : .WriteSChar( eType );
92 0 : return rStrm;
93 : }
94 :
95 :
96 :
97 36 : bool SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
98 : {
99 : DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
100 :
101 36 : const SvxZoomItem& rItem = static_cast<const SvxZoomItem&>(rAttr);
102 :
103 64 : return ( GetValue() == rItem.GetValue() &&
104 64 : nValueSet == rItem.GetValueSet() &&
105 64 : eType == rItem.GetType() );
106 : }
107 :
108 2650 : bool SvxZoomItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
109 : {
110 2650 : nMemberId &= ~CONVERT_TWIPS;
111 2650 : switch( nMemberId )
112 : {
113 : case 0:
114 : {
115 2650 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOM_PARAMS );
116 2650 : aSeq[0].Name = OUString( ZOOM_PARAM_VALUE );
117 2650 : aSeq[0].Value <<= sal_Int32( GetValue() );
118 2650 : aSeq[1].Name = OUString( ZOOM_PARAM_VALUESET );
119 2650 : aSeq[1].Value <<= sal_Int16( nValueSet );
120 2650 : aSeq[2].Name = OUString( ZOOM_PARAM_TYPE );
121 2650 : aSeq[2].Value <<= sal_Int16( eType );
122 2650 : rVal <<= aSeq;
123 2650 : break;
124 : }
125 :
126 0 : case MID_VALUE: rVal <<= (sal_Int32) GetValue(); break;
127 0 : case MID_VALUESET: rVal <<= (sal_Int16) nValueSet; break;
128 0 : case MID_TYPE: rVal <<= (sal_Int16) eType; break;
129 : default:
130 : OSL_FAIL("sfx2::SvxZoomItem::QueryValue(), Wrong MemberId!");
131 0 : return false;
132 : }
133 :
134 2650 : return true;
135 : }
136 :
137 1684 : bool SvxZoomItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
138 : {
139 1684 : nMemberId &= ~CONVERT_TWIPS;
140 1684 : switch( nMemberId )
141 : {
142 : case 0:
143 : {
144 1684 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
145 1684 : if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
146 : {
147 1684 : sal_Int32 nValueTmp( 0 );
148 1684 : sal_Int16 nValueSetTmp( 0 );
149 1684 : sal_Int16 nTypeTmp( 0 );
150 1684 : bool bAllConverted( true );
151 1684 : sal_Int16 nConvertedCount( 0 );
152 6736 : for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
153 : {
154 5052 : if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUE ))
155 : {
156 1684 : bAllConverted &= ( aSeq[i].Value >>= nValueTmp );
157 1684 : ++nConvertedCount;
158 : }
159 3368 : else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUESET ))
160 : {
161 1684 : bAllConverted &= ( aSeq[i].Value >>= nValueSetTmp );
162 1684 : ++nConvertedCount;
163 : }
164 1684 : else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_TYPE ))
165 : {
166 1684 : bAllConverted &= ( aSeq[i].Value >>= nTypeTmp );
167 1684 : ++nConvertedCount;
168 : }
169 : }
170 :
171 1684 : if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
172 : {
173 1684 : SetValue( (sal_uInt16)nValueTmp );
174 1684 : nValueSet = nValueSetTmp;
175 1684 : eType = SvxZoomType( nTypeTmp );
176 1684 : return true;
177 : }
178 : }
179 0 : return false;
180 : }
181 : case MID_VALUE:
182 : {
183 0 : sal_Int32 nVal = 0;
184 0 : if ( rVal >>= nVal )
185 : {
186 0 : SetValue( (sal_uInt16)nVal );
187 0 : return true;
188 : }
189 : else
190 0 : return false;
191 : }
192 :
193 : case MID_VALUESET:
194 : case MID_TYPE:
195 : {
196 0 : sal_Int16 nVal = sal_Int16();
197 0 : if ( rVal >>= nVal )
198 : {
199 0 : if ( nMemberId == MID_VALUESET )
200 0 : nValueSet = (sal_Int16) nVal;
201 0 : else if ( nMemberId == MID_TYPE )
202 0 : eType = SvxZoomType( (sal_Int16) nVal );
203 0 : return true;
204 : }
205 : else
206 0 : return false;
207 : }
208 :
209 : default:
210 : OSL_FAIL("sfx2::SvxZoomItem::PutValue(), Wrong MemberId!");
211 0 : return false;
212 : }
213 : }
214 :
215 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|