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 :
27 : // -----------------------------------------------------------------------
28 :
29 44 : 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 4 : 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 4 : eType( eZoomType )
47 : {
48 4 : }
49 :
50 : // -----------------------------------------------------------------------
51 :
52 12 : SvxZoomItem::SvxZoomItem( const SvxZoomItem& rOrig )
53 24 : : SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
54 12 : nValueSet( rOrig.GetValueSet() ),
55 36 : eType( rOrig.GetType() )
56 : {
57 12 : }
58 :
59 : // -----------------------------------------------------------------------
60 :
61 28 : SvxZoomItem::~SvxZoomItem()
62 : {
63 28 : }
64 :
65 : // -----------------------------------------------------------------------
66 :
67 12 : SfxPoolItem* SvxZoomItem::Clone( SfxItemPool * /*pPool*/ ) const
68 : {
69 12 : 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 >> nValue >> nValSet >> 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 << (sal_uInt16)GetValue()
90 0 : << nValueSet
91 0 : << (sal_Int8)eType;
92 0 : return rStrm;
93 : }
94 :
95 : // -----------------------------------------------------------------------
96 :
97 0 : int SvxZoomItem::operator==( const SfxPoolItem& rAttr ) const
98 : {
99 : DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
100 :
101 0 : SvxZoomItem& rItem = (SvxZoomItem&)rAttr;
102 :
103 0 : return ( GetValue() == rItem.GetValue() &&
104 0 : nValueSet == rItem.GetValueSet() &&
105 0 : eType == rItem.GetType() );
106 : }
107 :
108 0 : bool SvxZoomItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
109 : {
110 : // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
111 0 : nMemberId &= ~CONVERT_TWIPS;
112 :
113 : assert(nMemberId == 0);
114 :
115 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( ZOOM_PARAMS );
116 0 : aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUE ));
117 0 : aSeq[0].Value <<= sal_Int32( GetValue() );
118 0 : aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_VALUESET ));
119 0 : aSeq[1].Value <<= sal_Int16( nValueSet );
120 0 : aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ZOOM_PARAM_TYPE ));
121 0 : aSeq[2].Value <<= sal_Int16( eType );
122 0 : rVal <<= aSeq;
123 :
124 0 : return true;
125 : }
126 :
127 0 : bool SvxZoomItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
128 : {
129 0 : nMemberId &= ~CONVERT_TWIPS;
130 : assert(nMemberId == 0);
131 :
132 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
133 0 : if (( rVal >>= aSeq ) && ( aSeq.getLength() == ZOOM_PARAMS ))
134 : {
135 0 : sal_Int32 nValueTmp( 0 );
136 0 : sal_Int16 nValueSetTmp( 0 );
137 0 : sal_Int16 nTypeTmp( 0 );
138 0 : sal_Bool bAllConverted( sal_True );
139 0 : sal_Int16 nConvertedCount( 0 );
140 0 : for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
141 : {
142 0 : if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUE ))
143 : {
144 0 : bAllConverted &= ( aSeq[i].Value >>= nValueTmp );
145 0 : ++nConvertedCount;
146 : }
147 0 : else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_VALUESET ))
148 : {
149 0 : bAllConverted &= ( aSeq[i].Value >>= nValueSetTmp );
150 0 : ++nConvertedCount;
151 : }
152 0 : else if ( aSeq[i].Name.equalsAscii( ZOOM_PARAM_TYPE ))
153 : {
154 0 : bAllConverted &= ( aSeq[i].Value >>= nTypeTmp );
155 0 : ++nConvertedCount;
156 : }
157 : }
158 :
159 0 : if ( bAllConverted && nConvertedCount == ZOOM_PARAMS )
160 : {
161 0 : SetValue( (sal_uInt16)nValueTmp );
162 0 : nValueSet = nValueSetTmp;
163 0 : eType = SvxZoomType( nTypeTmp );
164 0 : return true;
165 : }
166 : }
167 :
168 0 : return false;
169 : }
170 :
171 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|