1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: numinf.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define _SVX_NUMINF_CXX
36 #include <svx/numinf.hxx>
38 // -----------------------------------------------------------------------
40 TYPEINIT1(SvxNumberInfoItem
, SfxPoolItem
);
42 // class SvxNumberInfoItem -----------------------------------------------
44 #define INIT(pNum,eVal,nDouble,rStr) \
45 SfxPoolItem ( nId ), \
47 pFormatter ( pNum ), \
48 eValueType ( eVal ), \
49 aStringVal ( rStr ), \
50 nDoubleVal ( nDouble ), \
51 pDelFormatArr ( NULL ), \
54 SvxNumberInfoItem::SvxNumberInfoItem( const sal_uInt16 nId
) :
56 INIT( NULL
, SVX_VALUE_TYPE_UNDEFINED
, 0, String() )
61 // -----------------------------------------------------------------------
63 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter
* pNumFormatter
,
64 const sal_uInt16 nId
) :
66 INIT( pNumFormatter
, SVX_VALUE_TYPE_UNDEFINED
, 0, String() )
71 // -----------------------------------------------------------------------
73 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter
* pNumFormatter
,
74 const String
& rVal
, const sal_uInt16 nId
) :
76 INIT( pNumFormatter
, SVX_VALUE_TYPE_STRING
, 0, rVal
)
81 // -----------------------------------------------------------------------
83 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter
* pNumFormatter
,
84 const double& rVal
, const sal_uInt16 nId
) :
86 INIT( pNumFormatter
, SVX_VALUE_TYPE_NUMBER
, rVal
, String() )
91 // -----------------------------------------------------------------------
93 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter
* pNumFormatter
,
94 const double& rVal
, const String
& rValueStr
,
95 const sal_uInt16 nId
) :
97 INIT( pNumFormatter
, SVX_VALUE_TYPE_NUMBER
, rVal
, rValueStr
)
104 // -----------------------------------------------------------------------
106 SvxNumberInfoItem::SvxNumberInfoItem( const SvxNumberInfoItem
& rItem
) :
108 SfxPoolItem( rItem
.Which() ),
110 pFormatter ( rItem
.pFormatter
),
111 eValueType ( rItem
.eValueType
),
112 aStringVal ( rItem
.aStringVal
),
113 nDoubleVal ( rItem
.nDoubleVal
),
114 pDelFormatArr( NULL
),
115 nDelCount ( rItem
.nDelCount
)
118 if ( rItem
.nDelCount
> 0 )
120 pDelFormatArr
= new sal_uInt32
[ rItem
.nDelCount
];
122 for ( sal_uInt16 i
= 0; i
< rItem
.nDelCount
; ++i
)
123 pDelFormatArr
[i
] = rItem
.pDelFormatArr
[i
];
127 // -----------------------------------------------------------------------
129 SvxNumberInfoItem::~SvxNumberInfoItem()
132 delete []pDelFormatArr
;
135 //------------------------------------------------------------------------
137 SfxItemPresentation
SvxNumberInfoItem::GetPresentation
139 SfxItemPresentation
/*ePres*/,
140 SfxMapUnit
/*eCoreUnit*/,
141 SfxMapUnit
/*ePresUnit*/,
142 String
& rText
, const IntlWrapper
*
146 return SFX_ITEM_PRESENTATION_NONE
;
149 // -----------------------------------------------------------------------
151 int SvxNumberInfoItem::operator==( const SfxPoolItem
& rItem
) const
153 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal which or type" );
155 SvxNumberInfoItem
& rOther
= (SvxNumberInfoItem
&)rItem
;
157 sal_Bool bEqual
= sal_False
;
159 if ( nDelCount
== rOther
.nDelCount
)
163 if ( pDelFormatArr
!= NULL
&& rOther
.pDelFormatArr
!= NULL
)
167 for ( sal_uInt16 i
= 0; i
< nDelCount
&& bEqual
; ++i
)
168 bEqual
= ( pDelFormatArr
[i
] == rOther
.pDelFormatArr
[i
] );
171 else if ( nDelCount
== 0 )
172 bEqual
= ( pDelFormatArr
== NULL
&& rOther
.pDelFormatArr
== NULL
);
175 pFormatter
== rOther
.pFormatter
&&
176 eValueType
== rOther
.eValueType
&&
177 nDoubleVal
== rOther
.nDoubleVal
&&
178 aStringVal
== rOther
.aStringVal
;
183 // -----------------------------------------------------------------------
185 SfxPoolItem
* SvxNumberInfoItem::Clone( SfxItemPool
* ) const
187 return new SvxNumberInfoItem( *this );
190 // Laden/Speichern wird nicht gebraucht!
191 // -----------------------------------------------------------------------
193 SfxPoolItem
* SvxNumberInfoItem::Create( SvStream
& /*rStream*/, sal_uInt16
) const
195 return new SvxNumberInfoItem( *this );
198 // -----------------------------------------------------------------------
200 SvStream
& SvxNumberInfoItem::Store( SvStream
&rStream
, sal_uInt16
/*nItemVersion*/ ) const
205 // -----------------------------------------------------------------------
207 void SvxNumberInfoItem::SetNumberFormatter( SvNumberFormatter
* pNumFormatter
)
209 pFormatter
= pNumFormatter
;
212 // -----------------------------------------------------------------------
214 void SvxNumberInfoItem::SetStringValue( const String
& rNewVal
)
216 aStringVal
= rNewVal
;
217 eValueType
= SVX_VALUE_TYPE_STRING
;
220 // -----------------------------------------------------------------------
222 void SvxNumberInfoItem::SetDoubleValue( const double& rNewVal
)
224 nDoubleVal
= rNewVal
;
225 eValueType
= SVX_VALUE_TYPE_NUMBER
;
228 // -----------------------------------------------------------------------
230 void SvxNumberInfoItem::SetDelFormatArray( const sal_uInt32
* pData
,
231 const sal_uInt32 nCount
)
235 delete []pDelFormatArr
;
236 pDelFormatArr
= NULL
;
243 pDelFormatArr
= new sal_uInt32
[ nCount
];
247 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
248 pDelFormatArr
[i
] = pData
[i
];