xref: /aoo41x/main/sw/source/core/fields/fldbas.cxx (revision 69a74367)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <float.h>
28cdf0e10cSrcweir #include <rtl/math.hxx>
29cdf0e10cSrcweir #include <svl/zforlist.hxx>
30cdf0e10cSrcweir #include <svl/zformat.hxx>
31cdf0e10cSrcweir #include <editeng/unolingu.hxx>
32cdf0e10cSrcweir #include <unofldmid.h>
33cdf0e10cSrcweir #include <doc.hxx>
34cdf0e10cSrcweir #include <editsh.hxx>
35cdf0e10cSrcweir #include <frame.hxx>
36cdf0e10cSrcweir #include <fldbas.hxx>
37cdf0e10cSrcweir #include <flddat.hxx>
38cdf0e10cSrcweir #include <ndtxt.hxx>
39cdf0e10cSrcweir #include <fmtfld.hxx>
40cdf0e10cSrcweir #include <txtfld.hxx>
41cdf0e10cSrcweir #include <pam.hxx>
42cdf0e10cSrcweir #include <docfld.hxx>
43cdf0e10cSrcweir #include <swtable.hxx>
44cdf0e10cSrcweir #include <docufld.hxx>
45cdf0e10cSrcweir #include <expfld.hxx>
46cdf0e10cSrcweir #include <shellres.hxx>
47cdf0e10cSrcweir #include <calc.hxx>
48cdf0e10cSrcweir #include <comcore.hrc>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include <math.h>
51cdf0e10cSrcweir #include <float.h>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir using namespace ::com::sun::star;
54cdf0e10cSrcweir using namespace nsSwDocInfoSubType;
55cdf0e10cSrcweir 
lcl_GetLanguageOfFormat(sal_uInt16 nLng,sal_uLong nFmt,const SvNumberFormatter & rFormatter)56cdf0e10cSrcweir sal_uInt16 lcl_GetLanguageOfFormat( sal_uInt16 nLng, sal_uLong nFmt,
57cdf0e10cSrcweir 								const SvNumberFormatter& rFormatter )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	if( nLng == LANGUAGE_NONE )	// wegen Bug #60010
60cdf0e10cSrcweir 		nLng = LANGUAGE_SYSTEM;
61cdf0e10cSrcweir 	else if( nLng == ::GetAppLanguage() )
62cdf0e10cSrcweir 		switch( rFormatter.GetIndexTableOffset( nFmt ))
63cdf0e10cSrcweir 		{
64cdf0e10cSrcweir 		case NF_NUMBER_SYSTEM:
65cdf0e10cSrcweir 		case NF_DATE_SYSTEM_SHORT:
66cdf0e10cSrcweir 		case NF_DATE_SYSTEM_LONG:
67cdf0e10cSrcweir 		case NF_DATETIME_SYSTEM_SHORT_HHMM:
68cdf0e10cSrcweir 			nLng = LANGUAGE_SYSTEM;
69cdf0e10cSrcweir 			break;
70cdf0e10cSrcweir         default: break;
71cdf0e10cSrcweir 		}
72cdf0e10cSrcweir 	return nLng;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir /*--------------------------------------------------------------------
76cdf0e10cSrcweir 	Beschreibung: Globals
77cdf0e10cSrcweir  --------------------------------------------------------------------*/
78cdf0e10cSrcweir // Array der Feldname
79cdf0e10cSrcweir 
80cdf0e10cSrcweir SvStringsDtor* SwFieldType::pFldNames = 0;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir DBG_NAME(SwFieldType)
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	sal_uInt16 __FAR_DATA aTypeTab[] = {
85cdf0e10cSrcweir 	/* RES_DBFLD			*/		TYP_DBFLD,
86cdf0e10cSrcweir 	/* RES_USERFLD			*/		TYP_USERFLD,
87cdf0e10cSrcweir 	/* RES_FILENAMEFLD		*/		TYP_FILENAMEFLD,
88cdf0e10cSrcweir 	/* RES_DBNAMEFLD		*/		TYP_DBNAMEFLD,
89cdf0e10cSrcweir 	/* RES_DATEFLD	   		*/		TYP_DATEFLD,
90cdf0e10cSrcweir 	/* RES_TIMEFLD			*/		TYP_TIMEFLD,
91cdf0e10cSrcweir 	/* RES_PAGENUMBERFLD	*/		TYP_PAGENUMBERFLD,	// dynamisch
92cdf0e10cSrcweir 	/* RES_AUTHORFLD		*/		TYP_AUTHORFLD,
93cdf0e10cSrcweir 	/* RES_CHAPTERFLD		*/		TYP_CHAPTERFLD,
94cdf0e10cSrcweir 	/* RES_DOCSTATFLD		*/		TYP_DOCSTATFLD,
95cdf0e10cSrcweir 	/* RES_GETEXPFLD		*/		TYP_GETFLD,			// dynamisch
96cdf0e10cSrcweir 	/* RES_SETEXPFLD		*/		TYP_SETFLD,			// dynamisch
97cdf0e10cSrcweir 	/* RES_GETREFFLD		*/		TYP_GETREFFLD,
98cdf0e10cSrcweir 	/* RES_HIDDENTXTFLD		*/		TYP_HIDDENTXTFLD,
99cdf0e10cSrcweir 	/* RES_POSTITFLD		*/		TYP_POSTITFLD,
100cdf0e10cSrcweir 	/* RES_FIXDATEFLD		*/		TYP_FIXDATEFLD,
101cdf0e10cSrcweir 	/* RES_FIXTIMEFLD		*/		TYP_FIXTIMEFLD,
102cdf0e10cSrcweir 	/* RES_REGFLD			*/		0,					// alt
103cdf0e10cSrcweir 	/* RES_VARREGFLD		*/		0,					// alt
104cdf0e10cSrcweir 	/* RES_SETREFFLD		*/		TYP_SETREFFLD,
105cdf0e10cSrcweir 	/* RES_INPUTFLD			*/		TYP_INPUTFLD,
106cdf0e10cSrcweir 	/* RES_MACROFLD			*/		TYP_MACROFLD,
107cdf0e10cSrcweir 	/* RES_DDEFLD			*/		TYP_DDEFLD,
108cdf0e10cSrcweir 	/* RES_TABLEFLD			*/		TYP_FORMELFLD,
109cdf0e10cSrcweir 	/* RES_HIDDENPARAFLD	*/		TYP_HIDDENPARAFLD,
110cdf0e10cSrcweir 	/* RES_DOCINFOFLD		*/		TYP_DOCINFOFLD,
111cdf0e10cSrcweir 	/* RES_TEMPLNAMEFLD		*/		TYP_TEMPLNAMEFLD,
112cdf0e10cSrcweir 	/* RES_DBNEXTSETFLD		*/		TYP_DBNEXTSETFLD,
113cdf0e10cSrcweir 	/* RES_DBNUMSETFLD		*/		TYP_DBNUMSETFLD,
114cdf0e10cSrcweir 	/* RES_DBSETNUMBERFLD	*/		TYP_DBSETNUMBERFLD,
115cdf0e10cSrcweir 	/* RES_EXTUSERFLD		*/		TYP_EXTUSERFLD,
116cdf0e10cSrcweir 	/* RES_REFPAGESETFLD	*/		TYP_SETREFPAGEFLD,
117cdf0e10cSrcweir 	/* RES_REFPAGEGETFLD    */		TYP_GETREFPAGEFLD,
118cdf0e10cSrcweir 	/* RES_INTERNETFLD		*/ 		TYP_INTERNETFLD,
119cdf0e10cSrcweir 	/* RES_JUMPEDITFLD		*/		TYP_JUMPEDITFLD,
120cdf0e10cSrcweir 	/* RES_SCRIPTFLD		*/		TYP_SCRIPTFLD,
121cdf0e10cSrcweir 	/* RES_DATETIMEFLD		*/		0,					// dynamisch
122cdf0e10cSrcweir 	/* RES_AUTHORITY		*/		TYP_AUTHORITY,
123cdf0e10cSrcweir 	/* RES_COMBINED_CHARS	*/		TYP_COMBINED_CHARS,
124cdf0e10cSrcweir     /* RES_DROPDOWN         */      TYP_DROPDOWN
125cdf0e10cSrcweir 	};
126cdf0e10cSrcweir 		// ????? TYP_USRINPFLD,
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
GetTypeStr(sal_uInt16 nTypeId)130cdf0e10cSrcweir const String& SwFieldType::GetTypeStr(sal_uInt16 nTypeId)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	if( !pFldNames )
133cdf0e10cSrcweir 		_GetFldName();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	if( nTypeId < SwFieldType::pFldNames->Count() )
136cdf0e10cSrcweir 		return *SwFieldType::pFldNames->GetObject( nTypeId );
137cdf0e10cSrcweir 	else
138cdf0e10cSrcweir 		return aEmptyStr;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 
142cdf0e10cSrcweir /*---------------------------------------------------
143cdf0e10cSrcweir  Jedes Feld referenziert einen Feldtypen, der fuer
144cdf0e10cSrcweir  jedes Dokument einmalig ist.
145cdf0e10cSrcweir  --------------------------------------------------*/
146cdf0e10cSrcweir 
SwFieldType(sal_uInt16 nWhichId)147cdf0e10cSrcweir SwFieldType::SwFieldType( sal_uInt16 nWhichId )
148cdf0e10cSrcweir 	: SwModify(0),
149cdf0e10cSrcweir 	nWhich( nWhichId )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 	DBG_CTOR( SwFieldType, 0 );
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir #ifdef DBG_UTIL
155cdf0e10cSrcweir 
~SwFieldType()156cdf0e10cSrcweir SwFieldType::~SwFieldType()
157cdf0e10cSrcweir {
158cdf0e10cSrcweir 	DBG_DTOR( SwFieldType, 0 );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir #endif
162cdf0e10cSrcweir 
GetName() const163cdf0e10cSrcweir const String& SwFieldType::GetName() const
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 	return aEmptyStr;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
QueryValue(uno::Any &,sal_uInt16) const168cdf0e10cSrcweir sal_Bool SwFieldType::QueryValue( uno::Any&, sal_uInt16 ) const
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	return sal_False;
171cdf0e10cSrcweir }
PutValue(const uno::Any &,sal_uInt16)172cdf0e10cSrcweir sal_Bool SwFieldType::PutValue( const uno::Any& , sal_uInt16 )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	return sal_False;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir /*--------------------------------------------------------------------
178cdf0e10cSrcweir 	Beschreibung:	Basisklasse aller Felder
179cdf0e10cSrcweir 					Felder referenzieren einen Feldtyp
180cdf0e10cSrcweir 					Felder sind n-mal vorhanden, Feldtypen nur einmal
181cdf0e10cSrcweir  --------------------------------------------------------------------*/
182cdf0e10cSrcweir 
SwField(SwFieldType * pTyp,sal_uInt32 nFmt,sal_uInt16 nLng,bool bUseFieldValueCache)183*69a74367SOliver-Rainer Wittmann SwField::SwField(
184*69a74367SOliver-Rainer Wittmann     SwFieldType* pTyp,
185*69a74367SOliver-Rainer Wittmann     sal_uInt32 nFmt,
186*69a74367SOliver-Rainer Wittmann     sal_uInt16 nLng,
187*69a74367SOliver-Rainer Wittmann     bool bUseFieldValueCache )
188*69a74367SOliver-Rainer Wittmann     : m_Cache()
189*69a74367SOliver-Rainer Wittmann     , m_bUseFieldValueCache( bUseFieldValueCache )
190*69a74367SOliver-Rainer Wittmann     , nLang( nLng )
191*69a74367SOliver-Rainer Wittmann     , bIsAutomaticLanguage( sal_True )
192*69a74367SOliver-Rainer Wittmann     , nFormat( nFmt )
193*69a74367SOliver-Rainer Wittmann     , pType( pTyp )
194cdf0e10cSrcweir {
195*69a74367SOliver-Rainer Wittmann     ASSERT( pTyp, "SwField: ungueltiger SwFieldType" );
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
~SwField()198cdf0e10cSrcweir SwField::~SwField()
199cdf0e10cSrcweir {
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir /*--------------------------------------------------------------------
203cdf0e10cSrcweir 	Beschreibung: Statt Umweg ueber den Typ
204cdf0e10cSrcweir  --------------------------------------------------------------------*/
205cdf0e10cSrcweir 
206cdf0e10cSrcweir #ifdef DBG_UTIL
Which() const207cdf0e10cSrcweir sal_uInt16 SwField::Which() const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	ASSERT(pType, "Kein Typ vorhanden");
210cdf0e10cSrcweir 	return pType->Which();
211cdf0e10cSrcweir }
212cdf0e10cSrcweir #endif
213cdf0e10cSrcweir 
214cdf0e10cSrcweir /*--------------------------------------------------------------------
215cdf0e10cSrcweir 	Beschreibung:
216cdf0e10cSrcweir  --------------------------------------------------------------------*/
217cdf0e10cSrcweir 
GetTypeId() const218cdf0e10cSrcweir sal_uInt16 SwField::GetTypeId() const
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	sal_uInt16 nRet;
222cdf0e10cSrcweir 	switch( pType->Which() )
223cdf0e10cSrcweir 	{
224cdf0e10cSrcweir 	case RES_DATETIMEFLD:
225cdf0e10cSrcweir 		if (GetSubType() & FIXEDFLD)
226cdf0e10cSrcweir 			nRet = static_cast<sal_uInt16>(GetSubType() & DATEFLD ? TYP_FIXDATEFLD : TYP_FIXTIMEFLD);
227cdf0e10cSrcweir 		else
228cdf0e10cSrcweir 			nRet = static_cast<sal_uInt16>(GetSubType() & DATEFLD ? TYP_DATEFLD : TYP_TIMEFLD);
229cdf0e10cSrcweir 		break;
230cdf0e10cSrcweir 	case RES_GETEXPFLD:
231cdf0e10cSrcweir 		nRet = static_cast<sal_uInt16>(nsSwGetSetExpType::GSE_FORMULA & GetSubType() ? TYP_FORMELFLD : TYP_GETFLD);
232cdf0e10cSrcweir 		break;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	case RES_HIDDENTXTFLD:
235cdf0e10cSrcweir 		nRet = GetSubType();
236cdf0e10cSrcweir 		break;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	case RES_SETEXPFLD:
239cdf0e10cSrcweir 		if( nsSwGetSetExpType::GSE_SEQ & GetSubType() )
240cdf0e10cSrcweir 			nRet = TYP_SEQFLD;
241cdf0e10cSrcweir 		else if( ((SwSetExpField*)this)->GetInputFlag() )
242cdf0e10cSrcweir 			nRet = TYP_SETINPFLD;
243cdf0e10cSrcweir 		else
244cdf0e10cSrcweir 			nRet = TYP_SETFLD;
245cdf0e10cSrcweir 		break;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	case RES_PAGENUMBERFLD:
248cdf0e10cSrcweir 		nRet = GetSubType();
249cdf0e10cSrcweir 		if( PG_NEXT == nRet )
250cdf0e10cSrcweir 			nRet = TYP_NEXTPAGEFLD;
251cdf0e10cSrcweir 		else if( PG_PREV == nRet )
252cdf0e10cSrcweir 			nRet = TYP_PREVPAGEFLD;
253cdf0e10cSrcweir 		else
254cdf0e10cSrcweir 			nRet = TYP_PAGENUMBERFLD;
255cdf0e10cSrcweir 		break;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	default:
258cdf0e10cSrcweir 		nRet = aTypeTab[ pType->Which() ];
259cdf0e10cSrcweir 	}
260cdf0e10cSrcweir 	return nRet;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 
264cdf0e10cSrcweir /*--------------------------------------------------------------------
265cdf0e10cSrcweir 	Beschreibung: liefert den Namen oder den Inhalt
266cdf0e10cSrcweir  --------------------------------------------------------------------*/
267cdf0e10cSrcweir 
GetFieldName() const268cdf0e10cSrcweir String SwField::GetFieldName() const
269cdf0e10cSrcweir {
270cdf0e10cSrcweir     sal_uInt16 nTypeId = GetTypeId();
271cdf0e10cSrcweir     if (RES_DATETIMEFLD == GetTyp()->Which())
272cdf0e10cSrcweir     {
273cdf0e10cSrcweir         nTypeId = static_cast<sal_uInt16>(
274cdf0e10cSrcweir             ((GetSubType() & DATEFLD) != 0) ? TYP_DATEFLD : TYP_TIMEFLD);
275cdf0e10cSrcweir     }
276cdf0e10cSrcweir     String sRet = SwFieldType::GetTypeStr( nTypeId );
277cdf0e10cSrcweir     if (IsFixed())
278cdf0e10cSrcweir     {
279cdf0e10cSrcweir         sRet += ' ';
280cdf0e10cSrcweir         sRet += ViewShell::GetShellRes()->aFixedStr;
281cdf0e10cSrcweir     }
282cdf0e10cSrcweir 	return sRet;
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir /*--------------------------------------------------------------------
286cdf0e10cSrcweir 	Beschreibung: Parameter setzen auslesen
287cdf0e10cSrcweir  --------------------------------------------------------------------*/
288cdf0e10cSrcweir 
GetPar1() const289cdf0e10cSrcweir const String& SwField::GetPar1() const
290cdf0e10cSrcweir {
291cdf0e10cSrcweir 	return aEmptyStr;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
GetPar2() const294cdf0e10cSrcweir String SwField::GetPar2() const
295cdf0e10cSrcweir {
296cdf0e10cSrcweir 	return aEmptyStr;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
GetFormula() const299cdf0e10cSrcweir String SwField::GetFormula() const
300cdf0e10cSrcweir {
301cdf0e10cSrcweir 	return GetPar2();
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
SetPar1(const String &)304cdf0e10cSrcweir void SwField::SetPar1(const String& )
305cdf0e10cSrcweir {}
306cdf0e10cSrcweir 
SetPar2(const String &)307cdf0e10cSrcweir void SwField::SetPar2(const String& )
308cdf0e10cSrcweir {}
309cdf0e10cSrcweir 
GetSubType() const310cdf0e10cSrcweir sal_uInt16 SwField::GetSubType() const
311cdf0e10cSrcweir {
312cdf0e10cSrcweir //	ASSERT(0, "Sorry Not implemented");
313cdf0e10cSrcweir 	return 0;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
SetSubType(sal_uInt16)316cdf0e10cSrcweir void SwField::SetSubType(sal_uInt16 )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir //	ASSERT(0, "Sorry Not implemented");
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
QueryValue(uno::Any & rVal,sal_uInt16 nWhichId) const321cdf0e10cSrcweir sal_Bool  SwField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     switch( nWhichId )
324cdf0e10cSrcweir     {
325cdf0e10cSrcweir         case FIELD_PROP_BOOL4:
326cdf0e10cSrcweir         {
327cdf0e10cSrcweir             sal_Bool bFixed = !bIsAutomaticLanguage;
328cdf0e10cSrcweir             rVal.setValue(&bFixed, ::getCppuBooleanType());
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir         break;
331cdf0e10cSrcweir         default:
332cdf0e10cSrcweir             DBG_ERROR("illegal property");
333cdf0e10cSrcweir     }
334cdf0e10cSrcweir     return sal_True;
335cdf0e10cSrcweir }
PutValue(const uno::Any & rVal,sal_uInt16 nWhichId)336cdf0e10cSrcweir sal_Bool SwField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir     switch( nWhichId )
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         case FIELD_PROP_BOOL4:
341cdf0e10cSrcweir         {
342cdf0e10cSrcweir             sal_Bool bFixed = sal_False;
343cdf0e10cSrcweir             if(rVal >>= bFixed)
344cdf0e10cSrcweir                 bIsAutomaticLanguage = !bFixed;
345cdf0e10cSrcweir         }
346cdf0e10cSrcweir         break;
347cdf0e10cSrcweir         default:
348cdf0e10cSrcweir             DBG_ERROR("illegal property");
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir     return sal_True;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 
354cdf0e10cSrcweir /*--------------------------------------------------------------------
355cdf0e10cSrcweir 	Beschreibung: 	neuen Typ setzen
356cdf0e10cSrcweir 					(wird fuer das Kopieren zwischen Dokumenten benutzt)
357cdf0e10cSrcweir 					muss immer vom gleichen Typ sein.
358cdf0e10cSrcweir  --------------------------------------------------------------------*/
359cdf0e10cSrcweir 
ChgTyp(SwFieldType * pNewType)360cdf0e10cSrcweir SwFieldType* SwField::ChgTyp( SwFieldType* pNewType )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir 	ASSERT( pNewType && pNewType->Which() == pType->Which(),
363cdf0e10cSrcweir 			"kein Typ oder ungleiche Typen" );
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	SwFieldType* pOld = pType;
366cdf0e10cSrcweir 	pType = pNewType;
367cdf0e10cSrcweir 	return pOld;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	// hat das Feld eine Action auf dem ClickHandler ? (z.B. INetFelder,..)
HasClickHdl() const371cdf0e10cSrcweir sal_Bool SwField::HasClickHdl() const
372cdf0e10cSrcweir {
373cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
374cdf0e10cSrcweir 	switch( pType->Which() )
375cdf0e10cSrcweir 	{
376cdf0e10cSrcweir 	case RES_INTERNETFLD:
377cdf0e10cSrcweir 	case RES_JUMPEDITFLD:
378cdf0e10cSrcweir 	case RES_GETREFFLD:
379cdf0e10cSrcweir 	case RES_MACROFLD:
380cdf0e10cSrcweir 	case RES_INPUTFLD:
381cdf0e10cSrcweir     case RES_DROPDOWN :
382cdf0e10cSrcweir 		bRet = sal_True;
383cdf0e10cSrcweir 		break;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	case RES_SETEXPFLD:
386cdf0e10cSrcweir 		bRet = ((SwSetExpField*)this)->GetInputFlag();
387cdf0e10cSrcweir 		break;
388cdf0e10cSrcweir 	}
389cdf0e10cSrcweir 	return bRet;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
SetLanguage(sal_uInt16 nLng)392cdf0e10cSrcweir void SwField::SetLanguage(sal_uInt16 nLng)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir 	nLang = nLng;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
ChangeFormat(sal_uInt32 n)397cdf0e10cSrcweir void SwField::ChangeFormat(sal_uInt32 n)
398cdf0e10cSrcweir {
399cdf0e10cSrcweir 	nFormat = n;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
IsFixed() const402cdf0e10cSrcweir sal_Bool SwField::IsFixed() const
403cdf0e10cSrcweir {
404cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
405cdf0e10cSrcweir 	switch( pType->Which() )
406cdf0e10cSrcweir 	{
407cdf0e10cSrcweir 	case RES_FIXDATEFLD:
408cdf0e10cSrcweir 	case RES_FIXTIMEFLD:
409cdf0e10cSrcweir 		bRet = sal_True;
410cdf0e10cSrcweir 		break;
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 	case RES_DATETIMEFLD:
413cdf0e10cSrcweir 		bRet = 0 != (GetSubType() & FIXEDFLD);
414cdf0e10cSrcweir 		break;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 	case RES_EXTUSERFLD:
417cdf0e10cSrcweir 	case RES_AUTHORFLD:
418cdf0e10cSrcweir 		bRet = 0 != (GetFormat() & AF_FIXED);
419cdf0e10cSrcweir 		break;
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 	case RES_FILENAMEFLD:
422cdf0e10cSrcweir 		bRet = 0 != (GetFormat() & FF_FIXED);
423cdf0e10cSrcweir 		break;
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 	case RES_DOCINFOFLD:
426cdf0e10cSrcweir 		bRet = 0 != (GetSubType() & DI_SUB_FIXED);
427cdf0e10cSrcweir 		break;
428cdf0e10cSrcweir 	}
429cdf0e10cSrcweir 	return bRet;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
ExpandField(bool const bCached) const432cdf0e10cSrcweir String SwField::ExpandField(bool const bCached) const
433cdf0e10cSrcweir {
434*69a74367SOliver-Rainer Wittmann     if ( m_bUseFieldValueCache )
435cdf0e10cSrcweir     {
436*69a74367SOliver-Rainer Wittmann         if (!bCached) // #i85766# do not expand fields in clipboard documents
437*69a74367SOliver-Rainer Wittmann         {
438*69a74367SOliver-Rainer Wittmann             m_Cache = Expand();
439*69a74367SOliver-Rainer Wittmann         }
440*69a74367SOliver-Rainer Wittmann         return m_Cache;
441cdf0e10cSrcweir     }
442*69a74367SOliver-Rainer Wittmann 
443*69a74367SOliver-Rainer Wittmann     return Expand();
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
CopyField() const446cdf0e10cSrcweir SwField * SwField::CopyField() const
447cdf0e10cSrcweir {
448cdf0e10cSrcweir     SwField *const pNew = Copy();
449cdf0e10cSrcweir     // #i85766# cache expansion of source (for clipboard)
450cdf0e10cSrcweir     // use this->cache, not this->Expand(): only text formatting calls Expand()
451cdf0e10cSrcweir     pNew->m_Cache = m_Cache;
452*69a74367SOliver-Rainer Wittmann     pNew->m_bUseFieldValueCache = m_bUseFieldValueCache;
453*69a74367SOliver-Rainer Wittmann 
454cdf0e10cSrcweir     return pNew;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir /*--------------------------------------------------------------------
458cdf0e10cSrcweir 	Beschreibung: Numerierung expandieren
459cdf0e10cSrcweir  --------------------------------------------------------------------*/
460cdf0e10cSrcweir 
FormatNumber(sal_uInt16 nNum,sal_uInt32 nFormat)461cdf0e10cSrcweir String FormatNumber(sal_uInt16 nNum, sal_uInt32 nFormat)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     if(SVX_NUM_PAGEDESC == nFormat)
464cdf0e10cSrcweir         return  String::CreateFromInt32( nNum );
465cdf0e10cSrcweir     SvxNumberType aNumber;
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 	ASSERT(nFormat != SVX_NUM_NUMBER_NONE, "Falsches Nummern-Format" );
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	aNumber.SetNumberingType((sal_Int16)nFormat);
470cdf0e10cSrcweir 	return aNumber.GetNumStr(nNum);
471cdf0e10cSrcweir }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir /*--------------------------------------------------------------------
474cdf0e10cSrcweir 	Beschreibung: CTOR SwValueFieldType
475cdf0e10cSrcweir  --------------------------------------------------------------------*/
476cdf0e10cSrcweir 
SwValueFieldType(SwDoc * pDocPtr,sal_uInt16 nWhichId)477cdf0e10cSrcweir SwValueFieldType::SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId )
478cdf0e10cSrcweir 	: SwFieldType(nWhichId),
479cdf0e10cSrcweir 	pDoc(pDocPtr),
480cdf0e10cSrcweir 	bUseFormat(sal_True)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
SwValueFieldType(const SwValueFieldType & rTyp)484cdf0e10cSrcweir SwValueFieldType::SwValueFieldType( const SwValueFieldType& rTyp )
485cdf0e10cSrcweir 	: SwFieldType(rTyp.Which()),
486cdf0e10cSrcweir 	pDoc(rTyp.GetDoc()),
487cdf0e10cSrcweir 	bUseFormat(rTyp.UseFormat())
488cdf0e10cSrcweir {
489cdf0e10cSrcweir }
490cdf0e10cSrcweir 
491cdf0e10cSrcweir /*--------------------------------------------------------------------
492cdf0e10cSrcweir 	Beschreibung: Wert formatiert als String zurueckgeben
493cdf0e10cSrcweir  --------------------------------------------------------------------*/
494cdf0e10cSrcweir 
ExpandValue(const double & rVal,sal_uInt32 nFmt,sal_uInt16 nLng) const495cdf0e10cSrcweir String SwValueFieldType::ExpandValue( const double& rVal,
496cdf0e10cSrcweir 										sal_uInt32 nFmt, sal_uInt16 nLng) const
497cdf0e10cSrcweir {
498cdf0e10cSrcweir 	if (rVal >= DBL_MAX)		// FehlerString fuer Calculator
499cdf0e10cSrcweir 		return ViewShell::GetShellRes()->aCalc_Error;
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 	String sExpand;
502cdf0e10cSrcweir 	SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
503cdf0e10cSrcweir 	Color* pCol = 0;
504cdf0e10cSrcweir 
505cdf0e10cSrcweir 	// wegen Bug #60010
506cdf0e10cSrcweir 	sal_uInt16 nFmtLng = ::lcl_GetLanguageOfFormat( nLng, nFmt, *pFormatter );
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 	if( nFmt < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFmtLng )
509cdf0e10cSrcweir 	{
510cdf0e10cSrcweir 		short nType = NUMBERFORMAT_DEFINED;
511cdf0e10cSrcweir 		xub_StrLen nDummy;
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 		const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 		if (pEntry && nLng != pEntry->GetLanguage())
516cdf0e10cSrcweir 		{
517cdf0e10cSrcweir 			sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFmt,
518cdf0e10cSrcweir 													(LanguageType)nFmtLng);
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 			if (nNewFormat == nFmt)
521cdf0e10cSrcweir 			{
522cdf0e10cSrcweir 				// Warscheinlich benutzerdefiniertes Format
523cdf0e10cSrcweir 				String sFmt(pEntry->GetFormatstring());
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 				pFormatter->PutandConvertEntry(sFmt, nDummy, nType, nFmt,
526cdf0e10cSrcweir 										pEntry->GetLanguage(), nFmtLng );
527cdf0e10cSrcweir 			}
528cdf0e10cSrcweir 			else
529cdf0e10cSrcweir 				nFmt = nNewFormat;
530cdf0e10cSrcweir 		}
531cdf0e10cSrcweir 		ASSERT(pEntry, "Unbekanntes Zahlenformat!");
532cdf0e10cSrcweir 	}
533cdf0e10cSrcweir 
534cdf0e10cSrcweir 	if( pFormatter->IsTextFormat( nFmt ) )
535cdf0e10cSrcweir 	{
536cdf0e10cSrcweir 		String sValue;
537cdf0e10cSrcweir 		DoubleToString(sValue, rVal, nFmtLng);
538cdf0e10cSrcweir 		pFormatter->GetOutputString(sValue, nFmt, sExpand, &pCol);
539cdf0e10cSrcweir 	}
540cdf0e10cSrcweir 	else
541cdf0e10cSrcweir 		pFormatter->GetOutputString(rVal, nFmt, sExpand, &pCol);
542cdf0e10cSrcweir 
543cdf0e10cSrcweir 	return sExpand;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir /*--------------------------------------------------------------------
547cdf0e10cSrcweir 	Beschreibung:
548cdf0e10cSrcweir  --------------------------------------------------------------------*/
549cdf0e10cSrcweir 
DoubleToString(String & rValue,const double & rVal,sal_uInt32 nFmt) const550cdf0e10cSrcweir void SwValueFieldType::DoubleToString( String &rValue, const double &rVal,
551cdf0e10cSrcweir 										sal_uInt32 nFmt) const
552cdf0e10cSrcweir {
553cdf0e10cSrcweir 	SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
554cdf0e10cSrcweir 	const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 	if (pEntry)
557cdf0e10cSrcweir 		DoubleToString(rValue, rVal, pEntry->GetLanguage());
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir /*--------------------------------------------------------------------
561cdf0e10cSrcweir 	Beschreibung:
562cdf0e10cSrcweir  --------------------------------------------------------------------*/
563cdf0e10cSrcweir 
DoubleToString(String & rValue,const double & rVal,sal_uInt16 nLng) const564cdf0e10cSrcweir void SwValueFieldType::DoubleToString( String &rValue, const double &rVal,
565cdf0e10cSrcweir 										sal_uInt16 nLng ) const
566cdf0e10cSrcweir {
567cdf0e10cSrcweir 	SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 	// wegen Bug #60010
570cdf0e10cSrcweir 	if( nLng == LANGUAGE_NONE )	// wegen Bug #60010
571cdf0e10cSrcweir 		nLng = LANGUAGE_SYSTEM;
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 	pFormatter->ChangeIntl( nLng );	// Separator in der richtigen Sprache besorgen
574cdf0e10cSrcweir 	rValue = ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
575cdf0e10cSrcweir 									pFormatter->GetDecSep(), true );
576cdf0e10cSrcweir }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir /*--------------------------------------------------------------------
579cdf0e10cSrcweir 	Beschreibung: CTOR SwValueField
580cdf0e10cSrcweir  --------------------------------------------------------------------*/
581cdf0e10cSrcweir 
SwValueField(SwValueFieldType * pFldType,sal_uInt32 nFmt,sal_uInt16 nLng,const double fVal)582cdf0e10cSrcweir SwValueField::SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt,
583cdf0e10cSrcweir 							sal_uInt16 nLng, const double fVal )
584cdf0e10cSrcweir 	: SwField(pFldType, nFmt, nLng),
585cdf0e10cSrcweir 	fValue(fVal)
586cdf0e10cSrcweir {
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
SwValueField(const SwValueField & rFld)589cdf0e10cSrcweir SwValueField::SwValueField( const SwValueField& rFld )
590cdf0e10cSrcweir 	: SwField(rFld),
591cdf0e10cSrcweir 	fValue(rFld.GetValue())
592cdf0e10cSrcweir {
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
~SwValueField()595cdf0e10cSrcweir SwValueField::~SwValueField()
596cdf0e10cSrcweir {
597cdf0e10cSrcweir }
598cdf0e10cSrcweir /*--------------------------------------------------------------------
599cdf0e10cSrcweir 	Beschreibung: 	neuen Typ setzen
600cdf0e10cSrcweir 					(wird fuer das Kopieren zwischen Dokumenten benutzt)
601cdf0e10cSrcweir 					muss immer vom gleichen Typ sein.
602cdf0e10cSrcweir  --------------------------------------------------------------------*/
603cdf0e10cSrcweir 
ChgTyp(SwFieldType * pNewType)604cdf0e10cSrcweir SwFieldType* SwValueField::ChgTyp( SwFieldType* pNewType )
605cdf0e10cSrcweir {
606cdf0e10cSrcweir 	SwDoc* pNewDoc = ((SwValueFieldType *)pNewType)->GetDoc();
607cdf0e10cSrcweir 	SwDoc* pDoc    = GetDoc();
608cdf0e10cSrcweir 
609cdf0e10cSrcweir 	if( pNewDoc && pDoc && pDoc != pNewDoc)
610cdf0e10cSrcweir 	{
611cdf0e10cSrcweir 		SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 		if( pFormatter && pFormatter->HasMergeFmtTbl() &&
614cdf0e10cSrcweir 			((SwValueFieldType *)GetTyp())->UseFormat() )
615cdf0e10cSrcweir 			SetFormat(pFormatter->GetMergeFmtIndex( GetFormat() ));
616cdf0e10cSrcweir 	}
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 	return SwField::ChgTyp(pNewType);
619cdf0e10cSrcweir }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir /*--------------------------------------------------------------------
622cdf0e10cSrcweir 	Beschreibung: Format in Office-Sprache ermitteln
623cdf0e10cSrcweir  --------------------------------------------------------------------*/
624cdf0e10cSrcweir 
GetSystemFormat(SvNumberFormatter * pFormatter,sal_uInt32 nFmt)625cdf0e10cSrcweir sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt)
626cdf0e10cSrcweir {
627cdf0e10cSrcweir 	const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
628cdf0e10cSrcweir 	sal_uInt16 nLng = SvxLocaleToLanguage( SvtSysLocale().GetLocaleData().getLocale() );
629cdf0e10cSrcweir 
630cdf0e10cSrcweir 	if (pEntry && nLng != pEntry->GetLanguage())
631cdf0e10cSrcweir 	{
632cdf0e10cSrcweir 		sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFmt,
633cdf0e10cSrcweir 														(LanguageType)nLng);
634cdf0e10cSrcweir 
635cdf0e10cSrcweir 		if (nNewFormat == nFmt)
636cdf0e10cSrcweir 		{
637cdf0e10cSrcweir 			// Warscheinlich benutzerdefiniertes Format
638cdf0e10cSrcweir 			short nType = NUMBERFORMAT_DEFINED;
639cdf0e10cSrcweir 			xub_StrLen nDummy;
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 			String sFmt(pEntry->GetFormatstring());
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 			sal_uInt32 nFormat = nFmt;
644cdf0e10cSrcweir 			pFormatter->PutandConvertEntry(sFmt, nDummy, nType,
645cdf0e10cSrcweir 								nFormat, pEntry->GetLanguage(), nLng);
646cdf0e10cSrcweir 			nFmt = nFormat;
647cdf0e10cSrcweir 		}
648cdf0e10cSrcweir 		else
649cdf0e10cSrcweir 			nFmt = nNewFormat;
650cdf0e10cSrcweir 	}
651cdf0e10cSrcweir 
652cdf0e10cSrcweir 	return nFmt;
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir /*--------------------------------------------------------------------
656cdf0e10cSrcweir 	Beschreibung: Sprache im Format anpassen
657cdf0e10cSrcweir  --------------------------------------------------------------------*/
658cdf0e10cSrcweir 
SetLanguage(sal_uInt16 nLng)659cdf0e10cSrcweir void SwValueField::SetLanguage( sal_uInt16 nLng )
660cdf0e10cSrcweir {
661cdf0e10cSrcweir     if( IsAutomaticLanguage() &&
662cdf0e10cSrcweir             ((SwValueFieldType *)GetTyp())->UseFormat() &&
663cdf0e10cSrcweir 		GetFormat() != SAL_MAX_UINT32 )
664cdf0e10cSrcweir 	{
665cdf0e10cSrcweir 		// wegen Bug #60010
666cdf0e10cSrcweir 		SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
667cdf0e10cSrcweir 		sal_uInt16 nFmtLng = ::lcl_GetLanguageOfFormat( nLng, GetFormat(),
668cdf0e10cSrcweir 													*pFormatter );
669cdf0e10cSrcweir 
670cdf0e10cSrcweir 		if( (GetFormat() >= SV_COUNTRY_LANGUAGE_OFFSET ||
671cdf0e10cSrcweir 			 LANGUAGE_SYSTEM != nFmtLng ) &&
672cdf0e10cSrcweir 			!(Which() == RES_USERFLD && (GetSubType()&nsSwExtendedSubType::SUB_CMD) ) )
673cdf0e10cSrcweir 		{
674cdf0e10cSrcweir 			const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
675cdf0e10cSrcweir 
676cdf0e10cSrcweir 			if( pEntry && nFmtLng != pEntry->GetLanguage() )
677cdf0e10cSrcweir 			{
678cdf0e10cSrcweir 				sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
679cdf0e10cSrcweir 										GetFormat(), (LanguageType)nFmtLng );
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 				if( nNewFormat == GetFormat() )
682cdf0e10cSrcweir 				{
683cdf0e10cSrcweir 					// Warscheinlich benutzerdefiniertes Format
684cdf0e10cSrcweir 					short nType = NUMBERFORMAT_DEFINED;
685cdf0e10cSrcweir 					xub_StrLen nDummy;
686cdf0e10cSrcweir 					String sFmt( pEntry->GetFormatstring() );
687cdf0e10cSrcweir 					pFormatter->PutandConvertEntry( sFmt, nDummy, nType,
688cdf0e10cSrcweir 													nNewFormat,
689cdf0e10cSrcweir 													pEntry->GetLanguage(),
690cdf0e10cSrcweir 													nFmtLng );
691cdf0e10cSrcweir 				}
692cdf0e10cSrcweir 				SetFormat( nNewFormat );
693cdf0e10cSrcweir 			}
694cdf0e10cSrcweir 			ASSERT(pEntry, "Unbekanntes Zahlenformat!");
695cdf0e10cSrcweir 		}
696cdf0e10cSrcweir 	}
697cdf0e10cSrcweir 
698cdf0e10cSrcweir 	SwField::SetLanguage(nLng);
699cdf0e10cSrcweir }
700cdf0e10cSrcweir 
701cdf0e10cSrcweir /*--------------------------------------------------------------------
702cdf0e10cSrcweir 	Beschreibung:
703cdf0e10cSrcweir  --------------------------------------------------------------------*/
704cdf0e10cSrcweir 
GetValue() const705cdf0e10cSrcweir double SwValueField::GetValue() const
706cdf0e10cSrcweir {
707cdf0e10cSrcweir 	return fValue;
708cdf0e10cSrcweir }
709cdf0e10cSrcweir 
SetValue(const double & rVal)710cdf0e10cSrcweir void SwValueField::SetValue( const double& rVal )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir 	fValue = rVal;
713cdf0e10cSrcweir }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir /*--------------------------------------------------------------------
716cdf0e10cSrcweir 	Beschreibung: SwFormulaField
717cdf0e10cSrcweir  --------------------------------------------------------------------*/
718cdf0e10cSrcweir 
SwFormulaField(SwValueFieldType * pFldType,sal_uInt32 nFmt,const double fVal)719cdf0e10cSrcweir SwFormulaField::SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt, const double fVal)
720cdf0e10cSrcweir 	: SwValueField(pFldType, nFmt, LANGUAGE_SYSTEM, fVal)
721cdf0e10cSrcweir {
722cdf0e10cSrcweir }
723cdf0e10cSrcweir 
SwFormulaField(const SwFormulaField & rFld)724cdf0e10cSrcweir SwFormulaField::SwFormulaField( const SwFormulaField& rFld )
725cdf0e10cSrcweir 	: SwValueField((SwValueFieldType *)rFld.GetTyp(), rFld.GetFormat(),
726cdf0e10cSrcweir 					rFld.GetLanguage(), rFld.GetValue())
727cdf0e10cSrcweir {
728cdf0e10cSrcweir }
729cdf0e10cSrcweir 
730cdf0e10cSrcweir /*--------------------------------------------------------------------
731cdf0e10cSrcweir 	Beschreibung:
732cdf0e10cSrcweir  --------------------------------------------------------------------*/
733cdf0e10cSrcweir 
GetFormula() const734cdf0e10cSrcweir String SwFormulaField::GetFormula() const
735cdf0e10cSrcweir {
736cdf0e10cSrcweir 	return sFormula;
737cdf0e10cSrcweir }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir /*--------------------------------------------------------------------
740cdf0e10cSrcweir 	Beschreibung:
741cdf0e10cSrcweir  --------------------------------------------------------------------*/
742cdf0e10cSrcweir 
SetFormula(const String & rStr)743cdf0e10cSrcweir void SwFormulaField::SetFormula(const String& rStr)
744cdf0e10cSrcweir {
745cdf0e10cSrcweir 	sFormula = rStr;
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 	sal_uLong nFmt(GetFormat());
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 	if( nFmt && SAL_MAX_UINT32 != nFmt )
750cdf0e10cSrcweir 	{
751cdf0e10cSrcweir 		xub_StrLen nPos = 0;
752cdf0e10cSrcweir 		double fTmpValue;
753cdf0e10cSrcweir 		if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
754cdf0e10cSrcweir 			SwValueField::SetValue( fTmpValue );
755cdf0e10cSrcweir 	}
756cdf0e10cSrcweir }
757cdf0e10cSrcweir 
758cdf0e10cSrcweir /*--------------------------------------------------------------------
759cdf0e10cSrcweir 	Beschreibung:
760cdf0e10cSrcweir  --------------------------------------------------------------------*/
761cdf0e10cSrcweir 
SetExpandedFormula(const String & rStr)762cdf0e10cSrcweir void SwFormulaField::SetExpandedFormula( const String& rStr )
763cdf0e10cSrcweir {
764cdf0e10cSrcweir 	sal_uInt32 nFmt(GetFormat());
765cdf0e10cSrcweir 
766cdf0e10cSrcweir 	if (nFmt && nFmt != SAL_MAX_UINT32 && ((SwValueFieldType *)GetTyp())->UseFormat())
767cdf0e10cSrcweir 	{
768cdf0e10cSrcweir 		double fTmpValue;
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 		SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
771cdf0e10cSrcweir 
772cdf0e10cSrcweir 		if (pFormatter->IsNumberFormat(rStr, nFmt, fTmpValue))
773cdf0e10cSrcweir 		{
774cdf0e10cSrcweir 			SwValueField::SetValue(fTmpValue);
775cdf0e10cSrcweir 			sFormula.Erase();
776cdf0e10cSrcweir 
777cdf0e10cSrcweir 			((SwValueFieldType *)GetTyp())->DoubleToString(sFormula, fTmpValue, nFmt);
778cdf0e10cSrcweir 			return;
779cdf0e10cSrcweir 		}
780cdf0e10cSrcweir 	}
781cdf0e10cSrcweir 	sFormula = rStr;
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir /*--------------------------------------------------------------------
785cdf0e10cSrcweir 	Beschreibung:
786cdf0e10cSrcweir  --------------------------------------------------------------------*/
787cdf0e10cSrcweir 
GetExpandedFormula() const788cdf0e10cSrcweir String SwFormulaField::GetExpandedFormula() const
789cdf0e10cSrcweir {
790cdf0e10cSrcweir 	sal_uInt32 nFmt(GetFormat());
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 	if (nFmt && nFmt != SAL_MAX_UINT32 && ((SwValueFieldType *)GetTyp())->UseFormat())
793cdf0e10cSrcweir 	{
794cdf0e10cSrcweir 		String sFormattedValue;
795cdf0e10cSrcweir 		Color* pCol = 0;
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 		SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 		if (pFormatter->IsTextFormat(nFmt))
800cdf0e10cSrcweir 		{
801cdf0e10cSrcweir 			String sValue;
802cdf0e10cSrcweir 			((SwValueFieldType *)GetTyp())->DoubleToString(sValue, GetValue(), nFmt);
803cdf0e10cSrcweir 			pFormatter->GetOutputString(sValue, nFmt, sFormattedValue, &pCol);
804cdf0e10cSrcweir 		}
805cdf0e10cSrcweir 		else
806cdf0e10cSrcweir 			pFormatter->GetOutputString(GetValue(), nFmt, sFormattedValue, &pCol);
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 		return sFormattedValue;
809cdf0e10cSrcweir 	}
810cdf0e10cSrcweir 	else
811cdf0e10cSrcweir 		return GetFormula();
812cdf0e10cSrcweir }
813cdf0e10cSrcweir 
GetDescription() const814cdf0e10cSrcweir String SwField::GetDescription() const
815cdf0e10cSrcweir {
816cdf0e10cSrcweir     return SW_RES(STR_FIELD);
817cdf0e10cSrcweir }
818