xref: /aoo4110/main/svx/source/items/numinf.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #define _SVX_NUMINF_CXX
28 
29 #include <svx/numinf.hxx>
30 
31 // -----------------------------------------------------------------------
32 
33 TYPEINIT1(SvxNumberInfoItem, SfxPoolItem);
34 
35 // class SvxNumberInfoItem -----------------------------------------------
36 
37 #define INIT(pNum,eVal,nDouble,rStr)	\
38 	SfxPoolItem		( nId ),			\
39 										\
40 	pFormatter		( pNum ),			\
41 	eValueType		( eVal ),			\
42     aStringVal      ( rStr ),           \
43     nDoubleVal      ( nDouble ),        \
44     pDelFormatArr   ( NULL ),           \
45 	nDelCount		( 0 )
46 
SvxNumberInfoItem(const sal_uInt16 nId)47 SvxNumberInfoItem::SvxNumberInfoItem( const sal_uInt16 nId ) :
48 
49 	INIT( NULL, SVX_VALUE_TYPE_UNDEFINED, 0, String() )
50 
51 {
52 }
53 
54 // -----------------------------------------------------------------------
55 
SvxNumberInfoItem(SvNumberFormatter * pNumFormatter,const sal_uInt16 nId)56 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter* pNumFormatter,
57 									  const sal_uInt16 nId ) :
58 
59 	INIT( pNumFormatter, SVX_VALUE_TYPE_UNDEFINED, 0, String() )
60 
61 {
62 }
63 
64 // -----------------------------------------------------------------------
65 
SvxNumberInfoItem(SvNumberFormatter * pNumFormatter,const String & rVal,const sal_uInt16 nId)66 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter* pNumFormatter,
67 									  const String& rVal, const sal_uInt16 nId ) :
68 
69 	INIT( pNumFormatter, SVX_VALUE_TYPE_STRING, 0, rVal )
70 
71 {
72 }
73 
74 // -----------------------------------------------------------------------
75 
SvxNumberInfoItem(SvNumberFormatter * pNumFormatter,const double & rVal,const sal_uInt16 nId)76 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter* pNumFormatter,
77 									  const double& rVal, const sal_uInt16 nId ) :
78 
79 	INIT( pNumFormatter, SVX_VALUE_TYPE_NUMBER, rVal, String() )
80 
81 {
82 }
83 
84 // -----------------------------------------------------------------------
85 
SvxNumberInfoItem(SvNumberFormatter * pNumFormatter,const double & rVal,const String & rValueStr,const sal_uInt16 nId)86 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter* pNumFormatter,
87 									  const double& rVal, const String& rValueStr,
88 									  const sal_uInt16 nId ) :
89 
90 	INIT( pNumFormatter, SVX_VALUE_TYPE_NUMBER, rVal, rValueStr )
91 
92 {
93 }
94 
95 #undef INIT
96 
97 // -----------------------------------------------------------------------
98 
SvxNumberInfoItem(const SvxNumberInfoItem & rItem)99 SvxNumberInfoItem::SvxNumberInfoItem( const SvxNumberInfoItem& rItem ) :
100 
101 	SfxPoolItem( rItem.Which() ),
102 
103 	pFormatter	 ( rItem.pFormatter ),
104 	eValueType	 ( rItem.eValueType ),
105     aStringVal   ( rItem.aStringVal ),
106     nDoubleVal   ( rItem.nDoubleVal ),
107     pDelFormatArr( NULL ),
108 	nDelCount	 ( rItem.nDelCount )
109 
110 {
111 	if ( rItem.nDelCount > 0 )
112 	{
113 		pDelFormatArr = new sal_uInt32[ rItem.nDelCount ];
114 
115 		for ( sal_uInt16 i = 0; i < rItem.nDelCount; ++i )
116 			pDelFormatArr[i] = rItem.pDelFormatArr[i];
117 	}
118 }
119 
120 // -----------------------------------------------------------------------
121 
~SvxNumberInfoItem()122 SvxNumberInfoItem::~SvxNumberInfoItem()
123 {
124 	if ( pDelFormatArr )
125 		delete []pDelFormatArr;
126 }
127 
128 //------------------------------------------------------------------------
129 
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,String & rText,const IntlWrapper *) const130 SfxItemPresentation SvxNumberInfoItem::GetPresentation
131 (
132     SfxItemPresentation /*ePres*/,
133     SfxMapUnit          /*eCoreUnit*/,
134     SfxMapUnit          /*ePresUnit*/,
135     String&             rText, const IntlWrapper *
136 )	const
137 {
138 	rText.Erase();
139 	return SFX_ITEM_PRESENTATION_NONE;
140 }
141 
142 // -----------------------------------------------------------------------
143 
operator ==(const SfxPoolItem & rItem) const144 int SvxNumberInfoItem::operator==( const SfxPoolItem& rItem ) const
145 {
146 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal which or type" );
147 
148 	SvxNumberInfoItem& rOther = (SvxNumberInfoItem&)rItem;
149 
150 	sal_Bool bEqual = sal_False;
151 
152 	if ( nDelCount == rOther.nDelCount )
153 	{
154 		if ( nDelCount > 0 )
155 		{
156 			if ( pDelFormatArr != NULL && rOther.pDelFormatArr != NULL )
157 			{
158 				bEqual = sal_True;
159 
160 				for ( sal_uInt16 i = 0; i < nDelCount && bEqual; ++i )
161 					bEqual = ( pDelFormatArr[i] == rOther.pDelFormatArr[i] );
162 			}
163 		}
164 		else if ( nDelCount == 0 )
165 			bEqual = ( pDelFormatArr == NULL && rOther.pDelFormatArr == NULL );
166 
167 		bEqual = bEqual &&
168 				 pFormatter == rOther.pFormatter &&
169 				 eValueType == rOther.eValueType &&
170 				 nDoubleVal == rOther.nDoubleVal &&
171 				 aStringVal == rOther.aStringVal;
172 	}
173 	return bEqual;
174 }
175 
176 // -----------------------------------------------------------------------
177 
Clone(SfxItemPool *) const178 SfxPoolItem* SvxNumberInfoItem::Clone( SfxItemPool * ) const
179 {
180 	return new SvxNumberInfoItem( *this );
181 }
182 
183 // Laden/Speichern wird nicht gebraucht!
184 // -----------------------------------------------------------------------
185 
Create(SvStream &,sal_uInt16) const186 SfxPoolItem* SvxNumberInfoItem::Create( SvStream& /*rStream*/, sal_uInt16 ) const
187 {
188 	return new SvxNumberInfoItem( *this );
189 }
190 
191 // -----------------------------------------------------------------------
192 
Store(SvStream & rStream,sal_uInt16) const193 SvStream& SvxNumberInfoItem::Store( SvStream &rStream, sal_uInt16 /*nItemVersion*/ ) const
194 {
195 	return rStream;
196 }
197 
198 // -----------------------------------------------------------------------
199 
SetNumberFormatter(SvNumberFormatter * pNumFormatter)200 void SvxNumberInfoItem::SetNumberFormatter( SvNumberFormatter* pNumFormatter )
201 {
202 	pFormatter = pNumFormatter;
203 }
204 
205 // -----------------------------------------------------------------------
206 
SetStringValue(const String & rNewVal)207 void SvxNumberInfoItem::SetStringValue( const String& rNewVal )
208 {
209 	aStringVal = rNewVal;
210 	eValueType = SVX_VALUE_TYPE_STRING;
211 }
212 
213 // -----------------------------------------------------------------------
214 
SetDoubleValue(const double & rNewVal)215 void SvxNumberInfoItem::SetDoubleValue( const double& rNewVal )
216 {
217 	nDoubleVal = rNewVal;
218 	eValueType = SVX_VALUE_TYPE_NUMBER;
219 }
220 
221 // -----------------------------------------------------------------------
222 
SetDelFormatArray(const sal_uInt32 * pData,const sal_uInt32 nCount)223 void SvxNumberInfoItem::SetDelFormatArray( const sal_uInt32* pData,
224 										   const sal_uInt32 nCount )
225 {
226 	if ( pDelFormatArr )
227 	{
228 		delete []pDelFormatArr;
229 		pDelFormatArr = NULL;
230 	}
231 
232 	nDelCount = nCount;
233 
234 	if ( nCount > 0 )
235 	{
236 		pDelFormatArr = new sal_uInt32[ nCount ];
237 
238 		if ( pData != NULL )
239 		{
240 			for ( sal_uInt16 i = 0; i < nCount; ++i )
241 				pDelFormatArr[i] = pData[i];
242 		}
243 	}
244 }
245 
246 
247