xref: /trunk/main/sw/source/core/fields/expfld.cxx (revision 08357c13)
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_sw.hxx"
26 
27 #include <hintids.hxx>
28 #include <unotools/collatorwrapper.hxx>
29 #include <unotools/charclass.hxx>
30 #include <editeng/unolingu.hxx>
31 #include <svx/pageitem.hxx>
32 #include <editeng/langitem.hxx>
33 #include <editeng/fontitem.hxx>
34 #include <com/sun/star/text/SetVariableType.hpp>
35 #include <unofield.hxx>
36 #include <frmfmt.hxx>
37 #include <fmtfld.hxx>
38 #include <txtfld.hxx>
39 #include <fmtanchr.hxx>
40 #include <txtftn.hxx>
41 #include <doc.hxx>
42 #include <layfrm.hxx>
43 #include <pagefrm.hxx>
44 #include <cntfrm.hxx>
45 #include <rootfrm.hxx>
46 #include <tabfrm.hxx>
47 #include <flyfrm.hxx>
48 #include <ftnfrm.hxx>
49 #include <rowfrm.hxx>
50 #include <expfld.hxx>
51 #include <usrfld.hxx>
52 #include <ndtxt.hxx>
53 #include <calc.hxx>
54 #include <pam.hxx>
55 #include <docfld.hxx>
56 #include <swcache.hxx>
57 #include <swtable.hxx>
58 #include <breakit.hxx>
59 #include <SwStyleNameMapper.hxx>
60 #include <unofldmid.h>
61 #include <numrule.hxx>
62 #include <switerator.hxx>
63 
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::text;
66 using ::rtl::OUString;
67 
68 SV_IMPL_PTRARR( _SwSeqFldList, _SeqFldLstElem* )
69 
70 //-----------------------------------------------------------------------------
71 sal_Int16 lcl_SubTypeToAPI(sal_uInt16 nSubType)
72 {
73 		sal_Int16 nRet = 0;
74 		switch(nSubType)
75 		{
76 			case nsSwGetSetExpType::GSE_EXPR:
77                 nRet = SetVariableType::VAR;      // 0
78                 break;
79 			case nsSwGetSetExpType::GSE_SEQ:
80                 nRet = SetVariableType::SEQUENCE; // 1
81                 break;
82 			case nsSwGetSetExpType::GSE_FORMULA:
83                 nRet = SetVariableType::FORMULA;  // 2
84                 break;
85 			case nsSwGetSetExpType::GSE_STRING:
86                 nRet = SetVariableType::STRING;   // 3
87                 break;
88 		}
89 		return nRet;
90 }
91 //-----------------------------------------------------------------------------
92 sal_Int32 lcl_APIToSubType(const uno::Any& rAny)
93 {
94 		sal_Int16 nVal = 0;
95 		rAny >>= nVal;
96 		sal_Int32 nSet = 0;
97 		switch(nVal)
98 		{
99 			case SetVariableType::VAR:		nSet = nsSwGetSetExpType::GSE_EXPR;  break;
100 			case SetVariableType::SEQUENCE: nSet = nsSwGetSetExpType::GSE_SEQ;  break;
101 			case SetVariableType::FORMULA:  nSet = nsSwGetSetExpType::GSE_FORMULA; break;
102 			case SetVariableType::STRING:	nSet = nsSwGetSetExpType::GSE_STRING;	break;
103 			default:
104 				DBG_ERROR("wrong value");
105 				nSet = -1;
106 		}
107 		return nSet;
108 }
109 
110 //-----------------------------------------------------------------------------
111 
112 void ReplacePoint( String& rTmpName, sal_Bool bWithCommandType )
113 {
114     // replace first and last (if bWithCommandType: last two) dot Ersten und letzten Punkt ersetzen, da in Tabellennamen Punkte erlaubt sind
115     // since table names may contain dots
116 
117 	xub_StrLen nLen = rTmpName.Len();
118 	sal_Unicode *pStr = rTmpName.GetBufferAccess(), *pBackStr = pStr + nLen;
119 
120     long nBackCount = bWithCommandType ? 2 : 1;
121     xub_StrLen i;
122 
123     for( i = nLen; i; --i, pBackStr-- )
124 		if( '.' == *pBackStr )
125 		{
126 			*pBackStr = DB_DELIM;
127             if(!--nBackCount)
128                 break;
129 		}
130 	for( i = 0; i < nLen; ++i, ++pStr )
131 		if( '.' == *pStr )
132 		{
133 			*pStr = DB_DELIM;
134 			break;
135 		}
136 }
137 
138 SwTxtNode* GetFirstTxtNode( const SwDoc& rDoc, SwPosition& rPos,
139 							const SwCntntFrm *pCFrm, Point &rPt )
140 {
141 	SwTxtNode* pTxtNode = 0;
142 	if ( !pCFrm )
143 	{
144         const SwNodes& rNodes = rDoc.GetNodes();
145         rPos.nNode = *rNodes.GetEndOfContent().StartOfSectionNode();
146 		SwCntntNode* pCNd;
147         while( 0 != (pCNd = rNodes.GoNext( &rPos.nNode ) ) &&
148 				0 == ( pTxtNode = pCNd->GetTxtNode() ) )
149 						;
150 		ASSERT( pTxtNode, "wo ist der 1.TextNode" );
151 		rPos.nContent.Assign( pTxtNode, 0 );
152 	}
153 	else if ( !pCFrm->IsValid() )
154 	{
155 		pTxtNode = (SwTxtNode*)pCFrm->GetNode();
156 		rPos.nNode = *pTxtNode;
157 		rPos.nContent.Assign( pTxtNode, 0 );
158 	}
159 	else
160 	{
161 		pCFrm->GetCrsrOfst( &rPos, rPt );
162 		pTxtNode = rPos.nNode.GetNode().GetTxtNode();
163 	}
164 	return pTxtNode;
165 }
166 
167 const SwTxtNode* GetBodyTxtNode( const SwDoc& rDoc, SwPosition& rPos,
168 								const SwFrm& rFrm )
169 {
170 	const SwLayoutFrm* pLayout = (SwLayoutFrm*)rFrm.GetUpper();
171 	const SwTxtNode* pTxtNode = 0;
172 
173 	while( pLayout )
174 	{
175 		if( pLayout->IsFlyFrm() )
176 		{
177 			// hole das FlyFormat
178 			SwFrmFmt* pFlyFmt = ((SwFlyFrm*)pLayout)->GetFmt();
179 			ASSERT( pFlyFmt, "kein FlyFormat gefunden, wo steht das Feld" );
180 
181 			const SwFmtAnchor &rAnchor = pFlyFmt->GetAnchor();
182 
183 			if( FLY_AT_FLY == rAnchor.GetAnchorId() )
184 			{
185 				// und der Fly muss irgendwo angehaengt sein, also
186 				// den befragen
187                 pLayout = (SwLayoutFrm*)((SwFlyFrm*)pLayout)->GetAnchorFrm();
188 				continue;
189 			}
190             else if ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
191                      (FLY_AT_CHAR == rAnchor.GetAnchorId()) ||
192                      (FLY_AS_CHAR == rAnchor.GetAnchorId()))
193 			{
194 				ASSERT( rAnchor.GetCntntAnchor(), "keine gueltige Position" );
195 				rPos = *rAnchor.GetCntntAnchor();
196 				pTxtNode = rPos.nNode.GetNode().GetTxtNode();
197                 if ( FLY_AT_PARA == rAnchor.GetAnchorId() )
198                 {
199                     const_cast<SwTxtNode*>(pTxtNode)->MakeStartIndex(
200                             &rPos.nContent );
201 // oder doch besser das Ende vom (Anker-)TextNode nehmen ??
202 //					((SwTxtNode*)pTxtNode)->MakeEndIndex( &rPos.nContent );
203                 }
204 
205 				// noch nicht abbrechen, kann ja auch noch im
206 				// Header/Footer/Footnote/Fly stehen !!
207                 pLayout = ((SwFlyFrm*)pLayout)->GetAnchorFrm()
208                             ? ((SwFlyFrm*)pLayout)->GetAnchorFrm()->GetUpper() : 0;
209 				continue;
210 			}
211 			else
212 			{
213 				pLayout->FindPageFrm()->GetCntntPosition(
214 												pLayout->Frm().Pos(), rPos );
215 				pTxtNode = rPos.nNode.GetNode().GetTxtNode();
216 			}
217 		}
218 		else if( pLayout->IsFtnFrm() )
219 		{
220 			// hole den Node vom Anker
221 			const SwTxtFtn* pFtn = ((SwFtnFrm*)pLayout)->GetAttr();
222 			pTxtNode = &pFtn->GetTxtNode();
223 			rPos.nNode = *pTxtNode;
224 			rPos.nContent = *pFtn->GetStart();
225 		}
226 		else if( pLayout->IsHeaderFrm() || pLayout->IsFooterFrm() )
227 		{
228 			const SwCntntFrm* pCntFrm;
229 			const SwPageFrm* pPgFrm = pLayout->FindPageFrm();
230 			if( pLayout->IsHeaderFrm() )
231 			{
232 				const SwTabFrm *pTab;
233 				if( 0 != ( pCntFrm = pPgFrm->FindFirstBodyCntnt()) &&
234 					0 != (pTab = pCntFrm->FindTabFrm()) && pTab->IsFollow() &&
235                     pTab->GetTable()->GetRowsToRepeat() > 0 &&
236                     pTab->IsInHeadline( *pCntFrm ) )
237                 {
238 					// take the next line
239                     const SwLayoutFrm* pRow = pTab->GetFirstNonHeadlineRow();
240                     pCntFrm = pRow->ContainsCntnt();
241 				}
242 			}
243 			else
244 				pCntFrm = pPgFrm->FindLastBodyCntnt();
245 
246 			if( pCntFrm )
247 			{
248 				pTxtNode = pCntFrm->GetNode()->GetTxtNode();
249 				rPos.nNode = *pTxtNode;
250 				((SwTxtNode*)pTxtNode)->MakeEndIndex( &rPos.nContent );
251 			}
252 			else
253 			{
254 				Point aPt( pLayout->Frm().Pos() );
255 				aPt.Y()++;		// aus dem Header raus
256 				pCntFrm = pPgFrm->GetCntntPos( aPt, sal_False, sal_True, sal_False );
257 				pTxtNode = GetFirstTxtNode( rDoc, rPos, pCntFrm, aPt );
258 			}
259 		}
260 		else
261 		{
262 			pLayout = pLayout->GetUpper();
263 			continue;
264 		}
265 		break;		// gefunden und beende die Schleife
266 	}
267 	return pTxtNode;
268 }
269 
270 /*--------------------------------------------------------------------
271 	Beschreibung: SwSetExpFieldType by JP
272  --------------------------------------------------------------------*/
273 
274 SwGetExpFieldType::SwGetExpFieldType(SwDoc* pDc)
275 	: SwValueFieldType( pDc, RES_GETEXPFLD )
276 {
277 }
278 
279 SwFieldType* SwGetExpFieldType::Copy() const
280 {
281 	return new SwGetExpFieldType(GetDoc());
282 }
283 
284 void SwGetExpFieldType::Modify( const SfxPoolItem*, const SfxPoolItem* pNew )
285 {
286 	if( pNew && RES_DOCPOS_UPDATE == pNew->Which() )
287 		NotifyClients( 0, pNew );
288 	// sonst nichts weiter expandieren
289 }
290 
291 /*--------------------------------------------------------------------
292 	Beschreibung: SwGetExpField by JP
293  --------------------------------------------------------------------*/
294 
295 SwGetExpField::SwGetExpField(SwGetExpFieldType* pTyp, const String& rFormel,
296 							sal_uInt16 nSub, sal_uLong nFmt)
297 	: SwFormulaField( pTyp, nFmt, 0.0 ),
298 	bIsInBodyTxt( sal_True ),
299     nSubType(nSub),
300 	bLateInitialization( false )
301 {
302 	SetFormula( rFormel );
303 }
304 
305 String SwGetExpField::Expand() const
306 {
307 	if(nSubType & nsSwExtendedSubType::SUB_CMD)
308 		return GetFormula();
309 	else
310 		return sExpand;
311 }
312 
313 String SwGetExpField::GetFieldName() const
314 {
315     String aStr( SwFieldType::GetTypeStr(
316         static_cast<sal_uInt16>(((nsSwGetSetExpType::GSE_FORMULA & nSubType) != 0)
317                                             ? TYP_FORMELFLD
318                                             : TYP_GETFLD ) ));
319     aStr += ' ';
320     aStr += GetFormula();
321     return aStr;
322 }
323 
324 SwField* SwGetExpField::Copy() const
325 {
326 	SwGetExpField *pTmp = new SwGetExpField((SwGetExpFieldType*)GetTyp(),
327 											GetFormula(), nSubType, GetFormat());
328 	pTmp->SetLanguage(GetLanguage());
329 	pTmp->SwValueField::SetValue(GetValue());
330 	pTmp->sExpand 		= sExpand;
331 	pTmp->bIsInBodyTxt 	= bIsInBodyTxt;
332     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
333 	if( bLateInitialization )
334 		pTmp->SetLateInitialization();
335 
336 	return pTmp;
337 }
338 
339 void SwGetExpField::ChangeExpansion( const SwFrm& rFrm, const SwTxtFld& rFld )
340 {
341 	if( bIsInBodyTxt )		// nur Felder in Footer, Header, FootNote, Flys
342 		return;
343 
344 	ASSERT( !rFrm.IsInDocBody(), "Flag ist nicht richtig, Frame steht im DocBody" );
345 
346 	// bestimme mal das Dokument (oder geht es noch einfacher?)
347 	const SwTxtNode* pTxtNode = &rFld.GetTxtNode();
348 	SwDoc& rDoc = *(SwDoc*)pTxtNode->GetDoc();
349 
350 	// einen Index fuers bestimmen vom TextNode anlegen
351 	SwPosition aPos( SwNodeIndex( rDoc.GetNodes() ) );
352 	pTxtNode = GetBodyTxtNode( rDoc, aPos, rFrm );
353 
354 	// Wenn kein Layout vorhanden, kommt es in Kopf und Fusszeilen dazu
355 	// das ChnageExpansion uebers Layout-Formatieren aufgerufen wird
356 	// aber kein TxtNode vorhanden ist
357 	//
358 	if(!pTxtNode)
359 		return;
360 	// #i82544#
361     if( bLateInitialization )
362 	{
363 		SwFieldType* pSetExpFld = rDoc.GetFldType(RES_SETEXPFLD, GetFormula(), sal_False);
364 		if( pSetExpFld )
365 		{
366 			bLateInitialization = false;
367 			if( !(GetSubType() & nsSwGetSetExpType::GSE_STRING) &&
368 				static_cast< SwSetExpFieldType* >(pSetExpFld)->GetType() == nsSwGetSetExpType::GSE_STRING )
369 			SetSubType( nsSwGetSetExpType::GSE_STRING );
370 		}
371 	}
372 
373 	_SetGetExpFld aEndFld( aPos.nNode, &rFld, &aPos.nContent );
374 	if(GetSubType() & nsSwGetSetExpType::GSE_STRING)
375 	{
376 		SwHash** ppHashTbl;
377 		sal_uInt16 nSize;
378 		rDoc.FldsToExpand( ppHashTbl, nSize, aEndFld );
379 		LookString( ppHashTbl, nSize, GetFormula(), sExpand );
380 		::DeleteHashTable( ppHashTbl, nSize );		// HashTabelle loeschen
381 	}
382 	else
383 	{
384 		// fuelle den Calculator mit den Werten
385 		SwCalc aCalc( rDoc );
386 		rDoc.FldsToCalc(aCalc, aEndFld);
387 
388 		// Wert berechnen
389 		SetValue(aCalc.Calculate(GetFormula()).GetDouble());
390 
391 		// Auswertung nach Format
392 		sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue(
393 								GetValue(), GetFormat(), GetLanguage());
394 	}
395 }
396 
397 String SwGetExpField::GetPar2() const
398 {
399 	return GetFormula();
400 }
401 
402 void SwGetExpField::SetPar2(const String& rStr)
403 {
404 	SetFormula(rStr);
405 }
406 
407 sal_uInt16 SwGetExpField::GetSubType() const
408 {
409 	return nSubType;
410 }
411 
412 void SwGetExpField::SetSubType(sal_uInt16 nType)
413 {
414 	nSubType = nType;
415 }
416 
417 void SwGetExpField::SetLanguage(sal_uInt16 nLng)
418 {
419 	if (nSubType & nsSwExtendedSubType::SUB_CMD)
420 		SwField::SetLanguage(nLng);
421 	else
422 		SwValueField::SetLanguage(nLng);
423 }
424 
425 sal_Bool SwGetExpField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
426 {
427     switch( nWhichId )
428 	{
429 	case FIELD_PROP_DOUBLE:
430 		rAny <<= GetValue();
431 		break;
432 	case FIELD_PROP_FORMAT:
433 		rAny <<= (sal_Int32)GetFormat();
434 		break;
435 	case FIELD_PROP_USHORT1:
436 		 rAny <<= (sal_Int16)nSubType;
437 		break;
438 	case FIELD_PROP_PAR1:
439 	 	rAny <<= OUString( GetFormula() );
440 		break;
441 	case FIELD_PROP_SUBTYPE:
442 		{
443 			sal_Int16 nRet = lcl_SubTypeToAPI(GetSubType() & 0xff);
444 			rAny <<= nRet;
445 		}
446 		break;
447 	case FIELD_PROP_BOOL2:
448 		{
449 			sal_Bool bTmp = 0 != (nSubType & nsSwExtendedSubType::SUB_CMD);
450 			rAny.setValue(&bTmp, ::getBooleanCppuType());
451 		}
452 		break;
453 	case FIELD_PROP_PAR4:
454 		rAny <<= rtl::OUString(GetExpStr());
455 		break;
456 	default:
457         return SwField::QueryValue(rAny, nWhichId);
458     }
459 	return sal_True;
460 }
461 
462 sal_Bool SwGetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
463 {
464 	sal_Int32 nTmp = 0;
465 	String sTmp;
466     switch( nWhichId )
467 	{
468 	case FIELD_PROP_DOUBLE:
469 		SwValueField::SetValue(*(double*) rAny.getValue());
470 		break;
471 	case FIELD_PROP_FORMAT:
472 		rAny >>= nTmp;
473 		SetFormat(nTmp);
474 		break;
475 	case FIELD_PROP_USHORT1:
476 		 rAny >>= nTmp;
477 		 nSubType = static_cast<sal_uInt16>(nTmp);
478 		break;
479 	case FIELD_PROP_PAR1:
480 	 	SetFormula( ::GetString( rAny, sTmp ));
481 		break;
482 	case FIELD_PROP_SUBTYPE:
483 		nTmp = lcl_APIToSubType(rAny);
484 		if( nTmp >=0 )
485 			SetSubType( static_cast<sal_uInt16>((GetSubType() & 0xff00) | nTmp));
486 		break;
487 	case FIELD_PROP_BOOL2:
488 		if(*(sal_Bool*) rAny.getValue())
489 			nSubType |= nsSwExtendedSubType::SUB_CMD;
490 		else
491 			nSubType &= (~nsSwExtendedSubType::SUB_CMD);
492 		break;
493 	case FIELD_PROP_PAR4:
494 		ChgExpStr(::GetString( rAny, sTmp ));
495 		break;
496 	default:
497         return SwField::PutValue(rAny, nWhichId);
498     }
499 	return sal_True;
500 }
501 
502 SwSetExpFieldType::SwSetExpFieldType( SwDoc* pDc, const String& rName, sal_uInt16 nTyp )
503 	: SwValueFieldType( pDc, RES_SETEXPFLD ),
504 	sName( rName ),
505 	pOutlChgNd( 0 ),
506 	sDelim( String::CreateFromAscii( "." ) ),
507 	nType(nTyp), nLevel( UCHAR_MAX ),
508 	bDeleted( sal_False )
509 {
510 	if( ( nsSwGetSetExpType::GSE_SEQ | nsSwGetSetExpType::GSE_STRING ) & nType )
511 		EnableFormat(sal_False);	// Numberformatter nicht einsetzen
512 }
513 
514 SwFieldType* SwSetExpFieldType::Copy() const
515 {
516 	SwSetExpFieldType* pNew = new SwSetExpFieldType(GetDoc(), sName, nType);
517 	pNew->bDeleted = bDeleted;
518 	pNew->sDelim = sDelim;
519 	pNew->nLevel = nLevel;
520 
521 	return pNew;
522 }
523 
524 const String& SwSetExpFieldType::GetName() const
525 {
526 	return sName;
527 }
528 
529 void SwSetExpFieldType::Modify( const SfxPoolItem*, const SfxPoolItem* )
530 {
531 	return;		// nicht weiter expandieren
532 }
533 
534 void SwSetExpFieldType::SetSeqFormat(sal_uLong nFmt)
535 {
536 	SwIterator<SwFmtFld,SwFieldType> aIter(*this);
537 	for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
538 		pFmtFld->GetField()->ChangeFormat( nFmt );
539 }
540 
541 sal_uLong SwSetExpFieldType::GetSeqFormat()
542 {
543 	if( !GetDepends() )
544 		return SVX_NUM_ARABIC;
545 
546 	SwField *pFld = ((SwFmtFld*)GetDepends())->GetField();
547 	return pFld->GetFormat();
548 }
549 
550 sal_uInt16 SwSetExpFieldType::SetSeqRefNo( SwSetExpField& rFld )
551 {
552 	if( !GetDepends() || !(nsSwGetSetExpType::GSE_SEQ & nType) )
553 		return USHRT_MAX;
554 
555 extern void InsertSort( SvUShorts& rArr, sal_uInt16 nIdx, sal_uInt16* pInsPos = 0 );
556 	SvUShorts aArr( 64 );
557 
558 	sal_uInt16 n;
559 
560 	// dann testmal, ob die Nummer schon vergeben ist oder ob eine neue
561 	// bestimmt werden muss.
562 	SwIterator<SwFmtFld,SwFieldType> aIter( *this );
563 	const SwTxtNode* pNd;
564 	for( SwFmtFld* pF = aIter.First(); pF; pF = aIter.Next() )
565 		if( pF->GetField() != &rFld && pF->GetTxtFld() &&
566 			0 != ( pNd = pF->GetTxtFld()->GetpTxtNode() ) &&
567 			pNd->GetNodes().IsDocNodes() )
568 			InsertSort( aArr, ((SwSetExpField*)pF->GetField())->GetSeqNumber() );
569 
570 
571 	// teste erstmal ob die Nummer schon vorhanden ist:
572 	sal_uInt16 nNum = rFld.GetSeqNumber();
573 	if( USHRT_MAX != nNum )
574 	{
575 		for( n = 0; n < aArr.Count(); ++n )
576 			if( aArr[ n ] > nNum )
577 				return nNum;			// nicht vorhanden -> also benutzen
578 			else if( aArr[ n ] == nNum )
579 				break;					// schon vorhanden -> neue erzeugen
580 
581 		if( n == aArr.Count() )
582 			return nNum;			// nicht vorhanden -> also benutzen
583 	}
584 
585 	// alle Nummern entsprechend geflag, also bestimme die richtige Nummer
586 	for( n = 0; n < aArr.Count(); ++n )
587 		if( n != aArr[ n ] )
588 			break;
589 
590 	rFld.SetSeqNumber( n );
591 	return n;
592 }
593 
594 sal_uInt16 SwSetExpFieldType::GetSeqFldList( SwSeqFldList& rList )
595 {
596 	if( rList.Count() )
597 		rList.Remove( 0, rList.Count() );
598 
599 	SwIterator<SwFmtFld,SwFieldType> aIter( *this );
600 	const SwTxtNode* pNd;
601 	for( SwFmtFld* pF = aIter.First(); pF; pF = aIter.Next() )
602 		if( pF->GetTxtFld() &&
603 			0 != ( pNd = pF->GetTxtFld()->GetpTxtNode() ) &&
604 			pNd->GetNodes().IsDocNodes() )
605 		{
606             _SeqFldLstElem* pNew = new _SeqFldLstElem(
607                     pNd->GetExpandTxt( 0, (*pF->GetTxtFld()->GetStart()) + 1 ),
608                     ((SwSetExpField*)pF->GetField())->GetSeqNumber() );
609 			rList.InsertSort( pNew );
610 		}
611 
612 	return rList.Count();
613 }
614 
615 
616 void SwSetExpFieldType::SetChapter( SwSetExpField& rFld, const SwNode& rNd )
617 {
618 	const SwTxtNode* pTxtNd = rNd.FindOutlineNodeOfLevel( nLevel );
619 	if( pTxtNd )
620 	{
621         SwNumRule * pRule = pTxtNd->GetNumRule();
622 
623         if (pRule)
624         {
625             // --> OD 2005-11-02 #i51089 - TUNING#
626             if ( pTxtNd->GetNum() )
627             {
628                 const SwNodeNum & aNum = *(pTxtNd->GetNum());
629 
630                 // nur die Nummer besorgen, ohne Pre-/Post-fixstrings
631                 String sNumber( pRule->MakeNumString(aNum, sal_False ));
632 
633                 if( sNumber.Len() )
634                     rFld.ChgExpStr(  ( sNumber += sDelim ) += rFld.GetExpStr() );
635             }
636             else
637             {
638                 ASSERT( false,
639                         "<SwSetExpFieldType::SetChapter(..)> - text node with numbering rule, but without number. This is a serious defect -> inform OD" );
640             }
641         }
642 	}
643 }
644 
645 sal_Bool SwSetExpFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
646 {
647     switch( nWhichId )
648 	{
649 	case FIELD_PROP_SUBTYPE:
650 		{
651 			sal_Int16 nRet = lcl_SubTypeToAPI(GetType());
652 			rAny <<= nRet;
653 		}
654 		break;
655 	case FIELD_PROP_PAR2:
656 		rAny <<= OUString(GetDelimiter());
657 		break;
658 	case FIELD_PROP_SHORT1:
659 		{
660 			sal_Int8 nRet = nLevel < MAXLEVEL? nLevel : -1;
661 			rAny <<= nRet;
662 		}
663 		break;
664 	default:
665 		DBG_ERROR("illegal property");
666 	}
667 	return sal_True;
668 }
669 
670 sal_Bool SwSetExpFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
671 {
672     switch( nWhichId )
673 	{
674 	case FIELD_PROP_SUBTYPE:
675 		{
676 			sal_Int32 nSet = lcl_APIToSubType(rAny);
677 			if(nSet >=0)
678 				SetType(static_cast<sal_uInt16>(nSet));
679 		}
680 		break;
681 	case FIELD_PROP_PAR2:
682 		{
683 			String sTmp;
684 			if( ::GetString( rAny, sTmp ).Len() )
685 //				SetDelimiter( sTmp.GetChar( 0 ));
686 				SetDelimiter( sTmp );
687 			else
688 				SetDelimiter(String::CreateFromAscii( " "));
689 		}
690 		break;
691 	case FIELD_PROP_SHORT1:
692 		{
693 			sal_Int8 nLvl = 0;
694 			rAny >>= nLvl;
695 			if(nLvl < 0 || nLvl >= MAXLEVEL)
696 				SetOutlineLvl(UCHAR_MAX);
697 			else
698 				SetOutlineLvl(nLvl);
699 		}
700 		break;
701 	default:
702 		DBG_ERROR("illegal property");
703 	}
704 	return sal_True;
705 }
706 
707 sal_Bool SwSeqFldList::InsertSort( _SeqFldLstElem* pNew )
708 {
709 	sal_Unicode* p = pNew->sDlgEntry.GetBufferAccess();
710 	while( *p )
711 	{
712 		if( *p < 0x20 )
713 			*p = 0x20;
714 		++p;
715 	}
716 
717 	sal_uInt16 nPos;
718 	sal_Bool bRet = SeekEntry( *pNew, &nPos );
719 	if( !bRet )
720 		C40_INSERT( _SeqFldLstElem, pNew, nPos );
721 	return bRet;
722 }
723 
724 sal_Bool SwSeqFldList::SeekEntry( const _SeqFldLstElem& rNew, sal_uInt16* pP )
725 {
726 	sal_uInt16 nO = Count(), nM, nU = 0;
727 	if( nO > 0 )
728 	{
729 		CollatorWrapper & rCaseColl = ::GetAppCaseCollator(),
730 						& rColl = ::GetAppCollator();
731 		const CharClass& rCC = GetAppCharClass();
732 
733 		//#59900# Die Sortierung soll die Nummer korrekt einordnen
734 		//also "10" nach "9" und nicht "10" nach "1"
735 		const String& rTmp2 = rNew.sDlgEntry;
736 		xub_StrLen nFndPos2 = 0;
737 		String sNum2( rTmp2.GetToken( 0, ' ', nFndPos2 ));
738 		sal_Bool bIsNum2IsNumeric = rCC.isAsciiNumeric( sNum2 );
739 		sal_Int32 nNum2 = bIsNum2IsNumeric ? sNum2.ToInt32() : 0;
740 
741 		nO--;
742 		while( nU <= nO )
743 		{
744 			nM = nU + ( nO - nU ) / 2;
745 
746 			//#59900# Die Sortierung soll die Nummer korrekt einordnen
747 			//also "10" nach "9" und nicht "10" nach "1"
748 			const String& rTmp1 = (*((_SeqFldLstElem**)pData + nM))->sDlgEntry;
749 			xub_StrLen nFndPos1 = 0;
750 			String sNum1( rTmp1.GetToken( 0, ' ', nFndPos1 ));
751 			sal_Int32 nCmp;
752 
753 			if( bIsNum2IsNumeric && rCC.isNumeric( sNum1 ) )
754 			{
755 				sal_Int32 nNum1 = sNum1.ToInt32();
756 				nCmp = nNum2 - nNum1;
757 				if( 0 == nCmp )
758 					nCmp = rCaseColl.compareString( rTmp2.Copy( nFndPos2 ),
759 										 			  rTmp1.Copy( nFndPos1 ));
760 			}
761 			else
762 				nCmp = rColl.compareString( rTmp2, rTmp1 );
763 
764 			if( 0 == nCmp )
765 			{
766 				if( pP ) *pP = nM;
767 				return sal_True;
768 			}
769 			else if( 0 < nCmp )
770 				nU = nM + 1;
771 			else if( nM == 0 )
772 				break;
773 			else
774 				nO = nM - 1;
775 		}
776 	}
777 	if( pP ) *pP = nU;
778 	return sal_False;
779 }
780 
781 /*--------------------------------------------------------------------
782 	Beschreibung: SwSetExpField by JP
783  --------------------------------------------------------------------*/
784 
785 SwSetExpField::SwSetExpField(SwSetExpFieldType* pTyp, const String& rFormel,
786 										sal_uLong nFmt)
787 	: SwFormulaField( pTyp, nFmt, 0.0 ), nSeqNo( USHRT_MAX ),
788 	nSubType(0)
789 {
790 	SetFormula(rFormel);
791 	// SubType ignorieren !!!
792 	bInput = sal_False;
793 	if( IsSequenceFld() )
794 	{
795 		SwValueField::SetValue(1.0);
796 		if( !rFormel.Len() )
797 		{
798 			String sFormel(rFormel);
799 			sFormel += pTyp->GetName();
800 			sFormel += '+';
801 			sFormel += '1';
802 			SetFormula(sFormel);
803 		}
804 	}
805 }
806 
807 String SwSetExpField::Expand() const
808 {
809 	String aStr;
810 	if (nSubType & nsSwExtendedSubType::SUB_CMD)
811 	{	// Der CommandString ist gefragt
812 		aStr = GetTyp()->GetName();
813 		aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " = " ));
814 		aStr += GetFormula();
815 	}
816 	else if(!(nSubType & nsSwExtendedSubType::SUB_INVISIBLE))
817 	{   // Der Wert ist sichtbar
818 		aStr = sExpand;
819 	}
820 	return aStr;
821 }
822 
823 /*--------------------------------------------------------------------
824 	@return the field name
825  --------------------------------------------------------------------*/
826 
827 String SwSetExpField::GetFieldName() const
828 {
829     SwFldTypesEnum const nStrType( (IsSequenceFld())
830                             ? TYP_SEQFLD
831                             : (bInput)
832                                 ? TYP_SETINPFLD
833                                 : TYP_SETFLD   );
834 
835     String aStr( SwFieldType::GetTypeStr( static_cast<sal_uInt16>(nStrType) ) );
836     aStr += ' ';
837     aStr += GetTyp()->GetName();
838 
839     // Sequence: without formula
840     if (TYP_SEQFLD != nStrType)
841     {
842         aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " = " ) );
843         aStr += GetFormula();
844     }
845     return aStr;
846 }
847 
848 SwField* SwSetExpField::Copy() const
849 {
850 	SwSetExpField *pTmp = new SwSetExpField((SwSetExpFieldType*)GetTyp(),
851 											GetFormula(), GetFormat());
852 	pTmp->SwValueField::SetValue(GetValue());
853 	pTmp->sExpand   	= sExpand;
854     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
855     pTmp->SetLanguage(GetLanguage());
856 	pTmp->aPText		= aPText;
857 	pTmp->bInput		= bInput;
858 	pTmp->nSeqNo		= nSeqNo;
859 	pTmp->SetSubType(GetSubType());
860 
861 	return pTmp;
862 }
863 
864 void SwSetExpField::SetSubType(sal_uInt16 nSub)
865 {
866 	((SwSetExpFieldType*)GetTyp())->SetType(nSub & 0xff);
867 	nSubType = nSub & 0xff00;
868 
869 	DBG_ASSERT( (nSub & 0xff) != 3, "SubType ist illegal!" );
870 }
871 
872 sal_uInt16 SwSetExpField::GetSubType() const
873 {
874 	return ((SwSetExpFieldType*)GetTyp())->GetType() | nSubType;
875 }
876 
877 void SwSetExpField::SetValue( const double& rAny )
878 {
879 	SwValueField::SetValue(rAny);
880 
881 	if( IsSequenceFld() )
882 		sExpand = FormatNumber( (sal_uInt16)GetValue(), GetFormat() );
883 	else
884 		sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue( rAny,
885 												GetFormat(), GetLanguage());
886 }
887 
888 void SwGetExpField::SetValue( const double& rAny )
889 {
890 	SwValueField::SetValue(rAny);
891 	sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue( rAny, GetFormat(),
892 															GetLanguage());
893 }
894 /* -------------------------------------------------
895 	Description: Find the index of the reference text
896 	following the current field
897  --------------------------------------------------*/
898 xub_StrLen SwGetExpField::GetReferenceTextPos( const SwFmtFld& rFmt, SwDoc& rDoc)
899 {
900 	//
901 	const SwTxtFld* pTxtFld = rFmt.GetTxtFld();
902 	const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
903 	//
904 	xub_StrLen nRet = *pTxtFld->GetStart() + 1;
905 	String sNodeText = rTxtNode.GetTxt();
906 	sNodeText.Erase(0, nRet);
907 	if(sNodeText.Len())
908 	{
909 		//now check if sNodeText starts with a non-alphanumeric character plus a blank
910 		sal_uInt16 nSrcpt = pBreakIt->GetRealScriptOfText( sNodeText, 0 );
911 
912 		static sal_uInt16 nIds[] =
913 		{
914 			RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
915 			RES_CHRATR_FONT, RES_CHRATR_FONT,
916 			RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
917 			RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
918 			RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
919 			RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT,
920 			0, 0
921 		};
922 		SwAttrSet aSet(rDoc.GetAttrPool(), nIds);
923 		rTxtNode.GetAttr(aSet, nRet, nRet+1);
924 
925 		if( RTL_TEXTENCODING_SYMBOL != ((SvxFontItem&)aSet.Get(
926 				GetWhichOfScript( RES_CHRATR_FONT, nSrcpt )) ).GetCharSet() )
927 		{
928 			LanguageType eLang = ((SvxLanguageItem&)aSet.Get(
929 				GetWhichOfScript( RES_CHRATR_LANGUAGE, nSrcpt )) ).GetLanguage();
930 			CharClass aCC( SvxCreateLocale( eLang ));
931 			sal_Unicode c0 = sNodeText.GetChar(0);
932 			sal_Bool bIsAlphaNum = aCC.isAlphaNumeric( sNodeText, 0 );
933 			if( !bIsAlphaNum ||
934 				(c0 == ' ' || c0 == '\t'))
935 			{
936 				nRet++;
937 				if( sNodeText.Len() > 1 &&
938 					(sNodeText.GetChar(1) == ' ' ||
939 					 sNodeText.GetChar(1) == '\t'))
940 					nRet++;
941 			}
942 		}
943 	}
944 	return nRet;
945 }
946 
947 
948 /*--------------------------------------------------------------------
949 	Beschreibung: Parameter setzen
950  --------------------------------------------------------------------*/
951 
952 const String& SwSetExpField::GetPar1() const
953 {
954 	return ((SwSetExpFieldType*)GetTyp())->GetName();
955 }
956 
957 String SwSetExpField::GetPar2() const
958 {
959 	sal_uInt16 nType = ((SwSetExpFieldType*)GetTyp())->GetType();
960 
961 	if (nType & nsSwGetSetExpType::GSE_STRING)
962 		return GetFormula();
963 	return GetExpandedFormula();
964 }
965 
966 void SwSetExpField::SetPar2(const String& rStr)
967 {
968 	sal_uInt16 nType = ((SwSetExpFieldType*)GetTyp())->GetType();
969 
970 	if( !(nType & nsSwGetSetExpType::GSE_SEQ) || rStr.Len() )
971 	{
972 		if (nType & nsSwGetSetExpType::GSE_STRING)
973 			SetFormula(rStr);
974 		else
975 			SetExpandedFormula(rStr);
976 	}
977 }
978 
979 
980 sal_Bool SwSetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
981 {
982 	sal_Int32 nTmp32 = 0;
983 	sal_Int16 nTmp16 = 0;
984 	String sTmp;
985     switch( nWhichId )
986 	{
987 	case FIELD_PROP_BOOL2:
988 		if(*(sal_Bool*)rAny.getValue())
989 			nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
990 		else
991 			nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
992 		break;
993 	case FIELD_PROP_FORMAT:
994 		rAny >>= nTmp32;
995 		SetFormat(nTmp32);
996 		break;
997 	case FIELD_PROP_USHORT2:
998 		{
999 			rAny >>= nTmp16;
1000 			if(nTmp16 <= SVX_NUMBER_NONE )
1001 				SetFormat(nTmp16);
1002 			else {
1003 				//exception(wrong_value)
1004 				;
1005             }
1006 		}
1007 		break;
1008 	case FIELD_PROP_USHORT1:
1009 		rAny >>= nTmp16;
1010 		nSeqNo = nTmp16;
1011 		break;
1012 	case FIELD_PROP_PAR1:
1013 		SetPar1( SwStyleNameMapper::GetUIName(
1014 							::GetString( rAny, sTmp ), nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ) );
1015 		break;
1016 	case FIELD_PROP_PAR2:
1017 		{
1018 			OUString uTmp;
1019 			rAny >>= uTmp;
1020 			//I18N - if the formula contains only "TypeName+1"
1021 			//and it's one of the initially created sequence fields
1022 			//then the localized names has to be replaced by a programmatic name
1023 			OUString sMyFormula = SwXFieldMaster::LocalizeFormula(*this, uTmp, sal_False);
1024 			SetFormula( sMyFormula );
1025 		}
1026 		break;
1027 	case FIELD_PROP_DOUBLE:
1028 		{
1029 			double fVal = 0.0;
1030 			rAny >>= fVal;
1031 			SetValue(fVal);
1032 		}
1033 		break;
1034 	case FIELD_PROP_SUBTYPE:
1035 		nTmp32 = lcl_APIToSubType(rAny);
1036 		if(nTmp32 >= 0)
1037 			SetSubType(static_cast<sal_uInt16>((GetSubType() & 0xff00) | nTmp32));
1038 		break;
1039 	case FIELD_PROP_PAR3:
1040 		::GetString( rAny, aPText );
1041 		break;
1042 	case FIELD_PROP_BOOL3:
1043 		if(*(sal_Bool*) rAny.getValue())
1044 			nSubType |= nsSwExtendedSubType::SUB_CMD;
1045 		else
1046 			nSubType &= (~nsSwExtendedSubType::SUB_CMD);
1047 		break;
1048 	case FIELD_PROP_BOOL1:
1049 		SetInputFlag(*(sal_Bool*) rAny.getValue());
1050 		break;
1051 	case FIELD_PROP_PAR4:
1052 		ChgExpStr( ::GetString( rAny, sTmp ));
1053 		break;
1054 	default:
1055         return SwField::PutValue(rAny, nWhichId);
1056     }
1057 	return sal_True;
1058 }
1059 
1060 
1061 sal_Bool SwSetExpField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1062 {
1063     switch( nWhichId )
1064 	{
1065 	case FIELD_PROP_BOOL2:
1066 		{
1067 			sal_Bool bVal = 0 == (nSubType & nsSwExtendedSubType::SUB_INVISIBLE);
1068 			rAny.setValue(&bVal, ::getBooleanCppuType());
1069 		}
1070 		break;
1071 	case FIELD_PROP_FORMAT:
1072 		rAny <<= (sal_Int32)GetFormat();
1073 		break;
1074 	case FIELD_PROP_USHORT2:
1075 		rAny <<= (sal_Int16)GetFormat();
1076 		break;
1077 	case FIELD_PROP_USHORT1:
1078 		rAny <<= (sal_Int16)nSeqNo;
1079 		break;
1080 	case FIELD_PROP_PAR1:
1081 		rAny <<= OUString ( SwStyleNameMapper::GetProgName(GetPar1(), nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ) );
1082 		break;
1083 	case FIELD_PROP_PAR2:
1084 		{
1085 			//I18N - if the formula contains only "TypeName+1"
1086 			//and it's one of the initially created sequence fields
1087 			//then the localized names has to be replaced by a programmatic name
1088 			OUString sMyFormula = SwXFieldMaster::LocalizeFormula(*this, GetFormula(), sal_True);
1089 			rAny <<= OUString( sMyFormula );
1090 		}
1091 		break;
1092 	case FIELD_PROP_DOUBLE:
1093 		rAny <<= (double)GetValue();
1094 		break;
1095 	case FIELD_PROP_SUBTYPE:
1096 		{
1097 			sal_Int16 nRet = 0;
1098 				nRet = lcl_SubTypeToAPI(GetSubType() & 0xff);
1099 			rAny <<= nRet;
1100 		}
1101 		break;
1102 	case FIELD_PROP_PAR3:
1103 		rAny <<= OUString( aPText );
1104 		break;
1105 	case FIELD_PROP_BOOL3:
1106 		{
1107 			sal_Bool bTmp = 0 != (nSubType & nsSwExtendedSubType::SUB_CMD);
1108 			rAny.setValue(&bTmp, ::getBooleanCppuType());
1109 		}
1110 		break;
1111 	case FIELD_PROP_BOOL1:
1112 		{
1113 			sal_Bool bTmp = GetInputFlag();
1114 			rAny.setValue(&bTmp, ::getBooleanCppuType());
1115 		}
1116 		break;
1117 	case FIELD_PROP_PAR4:
1118 		rAny <<= rtl::OUString(GetExpStr());
1119 		break;
1120 	default:
1121         return SwField::QueryValue(rAny, nWhichId);
1122     }
1123 	return sal_True;
1124 }
1125 
1126 
1127 
1128 /*--------------------------------------------------------------------
1129 	Beschreibung: Eingabefeld Type
1130  ---------------------------------------------------------------------*/
1131 
1132 SwInputFieldType::SwInputFieldType( SwDoc* pD )
1133     : SwFieldType( RES_INPUTFLD )
1134     , pDoc( pD )
1135 {
1136 }
1137 
1138 SwFieldType* SwInputFieldType::Copy() const
1139 {
1140     SwInputFieldType* pType = new SwInputFieldType( pDoc );
1141     return pType;
1142 }
1143 
1144 /*--------------------------------------------------------------------
1145 	Beschreibung: Eingabefeld
1146  --------------------------------------------------------------------*/
1147 
1148 SwInputField::SwInputField( SwInputFieldType* pFieldType,
1149                             const String& rContent,
1150                             const String& rPrompt,
1151                             sal_uInt16 nSub,
1152                             sal_uLong nFmt,
1153                             bool bIsFormField )
1154     : SwField( pFieldType, nFmt, LANGUAGE_SYSTEM, false )
1155     , aContent(rContent)
1156     , aPText(rPrompt)
1157     , nSubType(nSub)
1158     , mbIsFormField( bIsFormField )
1159     , mpFmtFld( NULL )
1160 {
1161 }
1162 
1163 SwInputField::~SwInputField()
1164 {
1165 }
1166 
1167 
1168 void SwInputField::SetFmtFld( SwFmtFld& rFmtFld )
1169 {
1170     mpFmtFld = &rFmtFld;
1171 }
1172 
1173 SwFmtFld* SwInputField::GetFmtFld()
1174 {
1175     return mpFmtFld;
1176 }
1177 
1178 
1179 const String& SwInputField::getContent() const
1180 {
1181     return aContent;
1182 }
1183 
1184 void SwInputField::applyFieldContent( const String& rNewFieldContent )
1185 {
1186     if ( (nSubType & 0x00ff) == INP_TXT )
1187     {
1188         aContent = rNewFieldContent;
1189     }
1190     else if( (nSubType & 0x00ff) == INP_USR )
1191     {
1192         SwUserFieldType* pUserTyp = static_cast<SwUserFieldType*>(
1193             static_cast<SwInputFieldType*>(GetTyp())->GetDoc()->GetFldType( RES_USERFLD, getContent(), false ) );
1194         if( pUserTyp )
1195         {
1196             pUserTyp->SetContent( rNewFieldContent );
1197         }
1198     }
1199 }
1200 
1201 String SwInputField::GetFieldName() const
1202 {
1203     String aStr(SwField::GetFieldName());
1204     if ((nSubType & 0x00ff) == INP_USR)
1205     {
1206         aStr += GetTyp()->GetName();
1207         aStr += ' ';
1208         aStr += getContent();
1209     }
1210     return aStr;
1211 }
1212 
1213 SwField* SwInputField::Copy() const
1214 {
1215     SwInputField* pFld =
1216         new SwInputField(
1217             static_cast<SwInputFieldType*>(GetTyp()),
1218             getContent(),
1219             aPText,
1220             GetSubType(),
1221             GetFormat(),
1222             mbIsFormField );
1223 
1224     pFld->SetHelp( aHelp );
1225     pFld->SetToolTip( aToolTip );
1226 
1227     pFld->SetAutomaticLanguage(IsAutomaticLanguage());
1228     return pFld;
1229 }
1230 
1231 String SwInputField::Expand() const
1232 {
1233     String sRet;
1234     if ( (nSubType & 0x00ff) == INP_TXT )
1235     {
1236         sRet = getContent();
1237     }
1238     else if( (nSubType & 0x00ff) == INP_USR )
1239     {
1240         SwUserFieldType* pUserTyp = static_cast<SwUserFieldType*>(
1241             static_cast<SwInputFieldType*>(GetTyp())->GetDoc()->GetFldType( RES_USERFLD, getContent(), false ) );
1242         if( pUserTyp )
1243             sRet = pUserTyp->GetContent();
1244     }
1245     return sRet;
1246 }
1247 
1248 
1249 bool SwInputField::isFormField() const
1250 {
1251     return mbIsFormField
1252            || aHelp.Len() > 0
1253            || aToolTip.Len() > 0;
1254 }
1255 
1256 
1257 sal_Bool SwInputField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1258 {
1259     switch( nWhichId )
1260     {
1261     case FIELD_PROP_PAR1:
1262         rAny <<= OUString( getContent() );
1263         break;
1264     case FIELD_PROP_PAR2:
1265         rAny <<= OUString( aPText );
1266         break;
1267     case FIELD_PROP_PAR3:
1268         rAny <<= OUString( aHelp );
1269         break;
1270     case FIELD_PROP_PAR4:
1271         rAny <<= OUString( aToolTip );
1272         break;
1273     default:
1274         DBG_ERROR("illegal property");
1275     }
1276     return sal_True;
1277 }
1278 
1279 sal_Bool SwInputField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1280 {
1281     switch( nWhichId )
1282     {
1283     case FIELD_PROP_PAR1:
1284         {
1285             ::GetString( rAny, aContent );
1286         }
1287         break;
1288     case FIELD_PROP_PAR2:
1289         ::GetString( rAny, aPText );
1290         break;
1291     case FIELD_PROP_PAR3:
1292         ::GetString( rAny, aHelp );
1293         break;
1294     case FIELD_PROP_PAR4:
1295         ::GetString( rAny, aToolTip );
1296         break;
1297     default:
1298         DBG_ERROR("illegal property");
1299     }
1300     return sal_True;
1301 }
1302 
1303 
1304 void SwInputField::SetPar1(const String& rStr)
1305 {
1306     aContent = rStr;
1307 }
1308 
1309 const String& SwInputField::GetPar1() const
1310 {
1311     return getContent();
1312 }
1313 
1314 
1315 void SwInputField::SetPar2(const String& rStr)
1316 {
1317 	aPText = rStr;
1318 }
1319 
1320 String SwInputField::GetPar2() const
1321 {
1322 	return aPText;
1323 }
1324 
1325 void SwInputField::SetHelp(const String & rStr)
1326 {
1327     aHelp = rStr;
1328 }
1329 
1330 String SwInputField::GetHelp() const
1331 {
1332     return aHelp;
1333 }
1334 
1335 void SwInputField::SetToolTip(const String & rStr)
1336 {
1337     aToolTip = rStr;
1338 }
1339 
1340 String SwInputField::GetToolTip() const
1341 {
1342     return aToolTip;
1343 }
1344 
1345 sal_uInt16 SwInputField::GetSubType() const
1346 {
1347 	return nSubType;
1348 }
1349 
1350 void SwInputField::SetSubType(sal_uInt16 nSub)
1351 {
1352 	nSubType = nSub;
1353 }
1354 
1355