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