1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 31 #define _SVX_NUMINF_CXX 32 33 #include <svx/numinf.hxx> 34 35 // ----------------------------------------------------------------------- 36 37 TYPEINIT1(SvxNumberInfoItem, SfxPoolItem); 38 39 // class SvxNumberInfoItem ----------------------------------------------- 40 41 #define INIT(pNum,eVal,nDouble,rStr) \ 42 SfxPoolItem ( nId ), \ 43 \ 44 pFormatter ( pNum ), \ 45 eValueType ( eVal ), \ 46 aStringVal ( rStr ), \ 47 nDoubleVal ( nDouble ), \ 48 pDelFormatArr ( NULL ), \ 49 nDelCount ( 0 ) 50 51 SvxNumberInfoItem::SvxNumberInfoItem( const sal_uInt16 nId ) : 52 53 INIT( NULL, SVX_VALUE_TYPE_UNDEFINED, 0, String() ) 54 55 { 56 } 57 58 // ----------------------------------------------------------------------- 59 60 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter* pNumFormatter, 61 const sal_uInt16 nId ) : 62 63 INIT( pNumFormatter, SVX_VALUE_TYPE_UNDEFINED, 0, String() ) 64 65 { 66 } 67 68 // ----------------------------------------------------------------------- 69 70 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter* pNumFormatter, 71 const String& rVal, const sal_uInt16 nId ) : 72 73 INIT( pNumFormatter, SVX_VALUE_TYPE_STRING, 0, rVal ) 74 75 { 76 } 77 78 // ----------------------------------------------------------------------- 79 80 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter* pNumFormatter, 81 const double& rVal, const sal_uInt16 nId ) : 82 83 INIT( pNumFormatter, SVX_VALUE_TYPE_NUMBER, rVal, String() ) 84 85 { 86 } 87 88 // ----------------------------------------------------------------------- 89 90 SvxNumberInfoItem::SvxNumberInfoItem( SvNumberFormatter* pNumFormatter, 91 const double& rVal, const String& rValueStr, 92 const sal_uInt16 nId ) : 93 94 INIT( pNumFormatter, SVX_VALUE_TYPE_NUMBER, rVal, rValueStr ) 95 96 { 97 } 98 99 #undef INIT 100 101 // ----------------------------------------------------------------------- 102 103 SvxNumberInfoItem::SvxNumberInfoItem( const SvxNumberInfoItem& rItem ) : 104 105 SfxPoolItem( rItem.Which() ), 106 107 pFormatter ( rItem.pFormatter ), 108 eValueType ( rItem.eValueType ), 109 aStringVal ( rItem.aStringVal ), 110 nDoubleVal ( rItem.nDoubleVal ), 111 pDelFormatArr( NULL ), 112 nDelCount ( rItem.nDelCount ) 113 114 { 115 if ( rItem.nDelCount > 0 ) 116 { 117 pDelFormatArr = new sal_uInt32[ rItem.nDelCount ]; 118 119 for ( sal_uInt16 i = 0; i < rItem.nDelCount; ++i ) 120 pDelFormatArr[i] = rItem.pDelFormatArr[i]; 121 } 122 } 123 124 // ----------------------------------------------------------------------- 125 126 SvxNumberInfoItem::~SvxNumberInfoItem() 127 { 128 if ( pDelFormatArr ) 129 delete []pDelFormatArr; 130 } 131 132 //------------------------------------------------------------------------ 133 134 SfxItemPresentation SvxNumberInfoItem::GetPresentation 135 ( 136 SfxItemPresentation /*ePres*/, 137 SfxMapUnit /*eCoreUnit*/, 138 SfxMapUnit /*ePresUnit*/, 139 String& rText, const IntlWrapper * 140 ) const 141 { 142 rText.Erase(); 143 return SFX_ITEM_PRESENTATION_NONE; 144 } 145 146 // ----------------------------------------------------------------------- 147 148 int SvxNumberInfoItem::operator==( const SfxPoolItem& rItem ) const 149 { 150 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal which or type" ); 151 152 SvxNumberInfoItem& rOther = (SvxNumberInfoItem&)rItem; 153 154 sal_Bool bEqual = sal_False; 155 156 if ( nDelCount == rOther.nDelCount ) 157 { 158 if ( nDelCount > 0 ) 159 { 160 if ( pDelFormatArr != NULL && rOther.pDelFormatArr != NULL ) 161 { 162 bEqual = sal_True; 163 164 for ( sal_uInt16 i = 0; i < nDelCount && bEqual; ++i ) 165 bEqual = ( pDelFormatArr[i] == rOther.pDelFormatArr[i] ); 166 } 167 } 168 else if ( nDelCount == 0 ) 169 bEqual = ( pDelFormatArr == NULL && rOther.pDelFormatArr == NULL ); 170 171 bEqual = bEqual && 172 pFormatter == rOther.pFormatter && 173 eValueType == rOther.eValueType && 174 nDoubleVal == rOther.nDoubleVal && 175 aStringVal == rOther.aStringVal; 176 } 177 return bEqual; 178 } 179 180 // ----------------------------------------------------------------------- 181 182 SfxPoolItem* SvxNumberInfoItem::Clone( SfxItemPool * ) const 183 { 184 return new SvxNumberInfoItem( *this ); 185 } 186 187 // Laden/Speichern wird nicht gebraucht! 188 // ----------------------------------------------------------------------- 189 190 SfxPoolItem* SvxNumberInfoItem::Create( SvStream& /*rStream*/, sal_uInt16 ) const 191 { 192 return new SvxNumberInfoItem( *this ); 193 } 194 195 // ----------------------------------------------------------------------- 196 197 SvStream& SvxNumberInfoItem::Store( SvStream &rStream, sal_uInt16 /*nItemVersion*/ ) const 198 { 199 return rStream; 200 } 201 202 // ----------------------------------------------------------------------- 203 204 void SvxNumberInfoItem::SetNumberFormatter( SvNumberFormatter* pNumFormatter ) 205 { 206 pFormatter = pNumFormatter; 207 } 208 209 // ----------------------------------------------------------------------- 210 211 void SvxNumberInfoItem::SetStringValue( const String& rNewVal ) 212 { 213 aStringVal = rNewVal; 214 eValueType = SVX_VALUE_TYPE_STRING; 215 } 216 217 // ----------------------------------------------------------------------- 218 219 void SvxNumberInfoItem::SetDoubleValue( const double& rNewVal ) 220 { 221 nDoubleVal = rNewVal; 222 eValueType = SVX_VALUE_TYPE_NUMBER; 223 } 224 225 // ----------------------------------------------------------------------- 226 227 void SvxNumberInfoItem::SetDelFormatArray( const sal_uInt32* pData, 228 const sal_uInt32 nCount ) 229 { 230 if ( pDelFormatArr ) 231 { 232 delete []pDelFormatArr; 233 pDelFormatArr = NULL; 234 } 235 236 nDelCount = nCount; 237 238 if ( nCount > 0 ) 239 { 240 pDelFormatArr = new sal_uInt32[ nCount ]; 241 242 if ( pData != NULL ) 243 { 244 for ( sal_uInt16 i = 0; i < nCount; ++i ) 245 pDelFormatArr[i] = pData[i]; 246 } 247 } 248 } 249 250 251