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