xref: /trunk/main/sw/source/core/fields/docufld.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_sw.hxx"
30 
31 #include <textapi.hxx>
32 
33 #include <tools/pstm.hxx>
34 #include <hintids.hxx>
35 #include <com/sun/star/text/XText.hpp>
36 #include <com/sun/star/script/XTypeConverter.hpp>
37 #include <com/sun/star/text/SetVariableType.hpp>
38 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
39 #include <com/sun/star/text/UserDataPart.hpp>
40 #include <com/sun/star/text/ChapterFormat.hpp>
41 #include <com/sun/star/text/XTextField.hpp>
42 #include <com/sun/star/text/PlaceholderType.hpp>
43 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
44 #include <com/sun/star/text/UserFieldFormat.hpp>
45 #include <com/sun/star/text/PageNumberType.hpp>
46 #include <com/sun/star/text/ReferenceFieldPart.hpp>
47 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
48 #include <com/sun/star/text/XDependentTextField.hpp>
49 #include <com/sun/star/text/DocumentStatistic.hpp>
50 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
51 #include <com/sun/star/document/XDocumentProperties.hpp>
52 #include <com/sun/star/util/Date.hpp>
53 #include <com/sun/star/util/Duration.hpp>
54 #include <unotools/localedatawrapper.hxx>
55 #include <editeng/unolingu.hxx>
56 #include <comphelper/processfactory.hxx>
57 #include <comphelper/types.hxx>
58 #include <comphelper/string.hxx>
59 #include <tools/urlobj.hxx>
60 #include <vcl/svapp.hxx>
61 #include <svl/urihelper.hxx>
62 #include <unotools/useroptions.hxx>
63 #include <unotools/syslocale.hxx>
64 #include <svl/zforlist.hxx>
65 
66 #include <tools/time.hxx>
67 #include <tools/datetime.hxx>
68 
69 #include <com/sun/star/beans/PropertyAttribute.hpp>
70 #include <com/sun/star/util/Date.hpp>
71 #include <com/sun/star/util/DateTime.hpp>
72 #include <com/sun/star/util/Time.hpp>
73 
74 #include <tools/shl.hxx>
75 #include <swmodule.hxx>
76 #include <sfx2/app.hxx>
77 #include <sfx2/docfile.hxx>
78 #include <sfx2/doctempl.hxx>
79 #include <fmtfld.hxx>
80 #include <txtfld.hxx>
81 #include <charfmt.hxx>
82 #include <docstat.hxx>
83 #include <pagedesc.hxx>
84 #include <fmtpdsc.hxx>
85 #include <doc.hxx>
86 #include <rootfrm.hxx>      // AuthorField
87 #include <pagefrm.hxx>      //
88 #include <cntfrm.hxx>       //
89 #include <pam.hxx>
90 #include <viewsh.hxx>
91 #include <dbmgr.hxx>
92 #include <shellres.hxx>
93 #include <docufld.hxx>
94 #include <flddat.hxx>
95 #include <docfld.hxx>
96 #include <ndtxt.hxx>
97 #include <expfld.hxx>
98 #include <poolfmt.hxx>
99 #include <docsh.hxx>
100 #include <unofldmid.h>
101 #include <swunohelper.hxx>
102 #include <comcore.hrc>
103 
104 #include <editeng/outliner.hxx>
105 #include <editeng/outlobj.hxx>
106 #include <switerator.hxx>
107 
108 #define URL_DECODE  INetURLObject::DECODE_UNAMBIGUOUS
109 
110 using ::rtl::OUString;
111 using namespace ::com::sun::star;
112 using namespace ::com::sun::star::uno;
113 using namespace nsSwDocInfoSubType;
114 
115 /*--------------------------------------------------------------------
116     Beschreibung: SwPageNumberFieldType
117  --------------------------------------------------------------------*/
118 
119 SwPageNumberFieldType::SwPageNumberFieldType()
120     : SwFieldType( RES_PAGENUMBERFLD ),
121     nNumberingType( SVX_NUM_ARABIC ),
122     nNum( 0 ),
123     nMax( USHRT_MAX ),
124     bVirtuell( sal_False )
125 {
126 }
127 
128 String& SwPageNumberFieldType::Expand( sal_uInt32 nFmt, short nOff,
129                                 const String& rUserStr, String& rRet ) const
130 {
131     sal_uInt32 nTmpFmt = (SVX_NUM_PAGEDESC == nFmt) ? (sal_uInt32)nNumberingType : nFmt;
132     long nTmp = nNum + nOff;
133 
134     if( 0 >= nTmp || SVX_NUM_NUMBER_NONE == nTmpFmt || (!bVirtuell && nTmp > nMax) )
135         rRet = aEmptyStr;
136     else if( SVX_NUM_CHAR_SPECIAL == nTmpFmt )
137         rRet = rUserStr;
138     else
139         rRet = FormatNumber( (sal_uInt16)nTmp, nTmpFmt );
140     return rRet;
141 }
142 
143 SwFieldType* SwPageNumberFieldType::Copy() const
144 {
145     SwPageNumberFieldType *pTmp = new SwPageNumberFieldType();
146 
147     pTmp->nNum       = nNum;
148     pTmp->nMax       = nMax;
149     pTmp->nNumberingType = nNumberingType;
150     pTmp->bVirtuell  = bVirtuell;
151 
152     return pTmp;
153 }
154 
155 /*--------------------------------------------------------------------
156     Beschreibung: Verschiedene Expandierung
157  --------------------------------------------------------------------*/
158 
159 void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc, sal_uInt16 nPage,
160                                             sal_uInt16 nNumPages, sal_Bool bVirt,
161                                             const sal_Int16* pNumFmt )
162 {
163     nNum = nPage;
164     nMax = nNumPages;
165     if( pNumFmt )
166         nNumberingType = *pNumFmt;
167 
168     bVirtuell = sal_False;
169     if( bVirt )
170     {
171         // dann muss das Flag ueberprueft werden, denn das Layout setzt
172         // es NIE zurueck
173         const SfxItemPool &rPool = pDoc->GetAttrPool();
174         const SwFmtPageDesc *pDesc;
175         sal_uInt32 nMaxItems = rPool.GetItemCount2( RES_PAGEDESC );
176         for( sal_uInt32 n = 0; n < nMaxItems; ++n )
177             if( 0 != (pDesc = (SwFmtPageDesc*)rPool.GetItem2( RES_PAGEDESC, n ) )
178                 && pDesc->GetNumOffset() && pDesc->GetDefinedIn() )
179             {
180                 SwCntntNode* pNd = PTR_CAST( SwCntntNode, pDesc->GetDefinedIn() );
181                 if( pNd )
182                 {
183                     if ( SwIterator<SwFrm,SwCntntNode>::FirstElement(*pNd) )
184                         bVirtuell = sal_True;
185                 }
186                 else if( pDesc->GetDefinedIn()->ISA( SwFmt ))
187                 {
188                     SwAutoFmtGetDocNode aGetHt( &pDoc->GetNodes() );
189                     bVirtuell = !pDesc->GetDefinedIn()->GetInfo( aGetHt );
190                     break;
191                 }
192             }
193     }
194 }
195 
196 /*--------------------------------------------------------------------
197     Beschreibung: SwPageNumberField
198  --------------------------------------------------------------------*/
199 
200 SwPageNumberField::SwPageNumberField(SwPageNumberFieldType* pTyp,
201                                      sal_uInt16 nSub, sal_uInt32 nFmt, short nOff)
202     : SwField(pTyp, nFmt), nSubType(nSub), nOffset(nOff)
203 {
204 }
205 
206 String SwPageNumberField::Expand() const
207 {
208     String sRet;
209     SwPageNumberFieldType* pFldType = (SwPageNumberFieldType*)GetTyp();
210 
211     if( PG_NEXT == nSubType && 1 != nOffset )
212     {
213         if( pFldType->Expand( GetFormat(), 1, sUserStr, sRet ).Len() )
214             pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
215     }
216     else if( PG_PREV == nSubType && -1 != nOffset )
217     {
218         if( pFldType->Expand( GetFormat(), -1, sUserStr, sRet ).Len() )
219             pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
220     }
221     else
222         pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
223     return sRet;
224 }
225 
226 SwField* SwPageNumberField::Copy() const
227 {
228     SwPageNumberField *pTmp =
229         new SwPageNumberField((SwPageNumberFieldType*)GetTyp(), nSubType, GetFormat(), nOffset);
230     pTmp->SetLanguage( GetLanguage() );
231     pTmp->SetUserString( sUserStr );
232     return pTmp;
233 }
234 
235 String SwPageNumberField::GetPar2() const
236 {
237     return String::CreateFromInt32(nOffset);
238 }
239 
240 void SwPageNumberField::SetPar2(const String& rStr)
241 {
242     nOffset = (short)rStr.ToInt32();
243 }
244 
245 sal_uInt16 SwPageNumberField::GetSubType() const
246 {
247     return nSubType;
248 }
249 
250 sal_Bool SwPageNumberField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
251 {
252     switch( nWhichId )
253     {
254     case FIELD_PROP_FORMAT:
255         rAny <<= (sal_Int16)GetFormat();
256         break;
257     case FIELD_PROP_USHORT1:
258         rAny <<= nOffset;
259         break;
260     case FIELD_PROP_SUBTYPE:
261         {
262             text::PageNumberType eType;
263             eType = text::PageNumberType_CURRENT;
264             if(nSubType == PG_PREV)
265                 eType = text::PageNumberType_PREV;
266             else if(nSubType == PG_NEXT)
267                 eType = text::PageNumberType_NEXT;
268             rAny.setValue(&eType, ::getCppuType((const text::PageNumberType*)0));
269         }
270         break;
271     case FIELD_PROP_PAR1:
272         rAny <<= OUString(sUserStr);
273         break;
274 
275     default:
276         DBG_ERROR("illegal property");
277     }
278     return sal_True;
279 }
280 
281 sal_Bool SwPageNumberField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
282 {
283     sal_Bool bRet = sal_True;
284     sal_Int16 nSet = 0;
285     switch( nWhichId )
286     {
287     case FIELD_PROP_FORMAT:
288         rAny >>= nSet;
289 
290         // TODO: woher kommen die defines?
291         if(nSet <= SVX_NUM_PAGEDESC )
292             SetFormat(nSet);
293         else {
294             //exception(wrong_value)
295             ;
296         }
297         break;
298     case FIELD_PROP_USHORT1:
299         rAny >>= nSet;
300         nOffset = nSet;
301         break;
302     case FIELD_PROP_SUBTYPE:
303         switch( SWUnoHelper::GetEnumAsInt32( rAny ) )
304         {
305             case text::PageNumberType_CURRENT:
306                 nSubType = PG_RANDOM;
307             break;
308             case text::PageNumberType_PREV:
309                 nSubType = PG_PREV;
310             break;
311             case text::PageNumberType_NEXT:
312                 nSubType = PG_NEXT;
313             break;
314             default:
315                 bRet = sal_False;
316         }
317         break;
318     case FIELD_PROP_PAR1:
319         ::GetString( rAny, sUserStr );
320         break;
321 
322     default:
323         DBG_ERROR("illegal property");
324     }
325     return bRet;
326 }
327 /*--------------------------------------------------------------------
328     Beschreibung: SwAuthorFieldType
329  --------------------------------------------------------------------*/
330 
331 SwAuthorFieldType::SwAuthorFieldType()
332     : SwFieldType( RES_AUTHORFLD )
333 {
334 }
335 
336 String SwAuthorFieldType::Expand(sal_uLong nFmt) const
337 {
338     String sRet;
339     SvtUserOptions&  rOpt = SW_MOD()->GetUserOptions();
340     if((nFmt & 0xff) == AF_NAME)
341         sRet = rOpt.GetFullName();
342     else
343         sRet = rOpt.GetID();
344     return sRet;
345 }
346 
347 SwFieldType* SwAuthorFieldType::Copy() const
348 {
349     return new SwAuthorFieldType;
350 }
351 
352 /*--------------------------------------------------------------------
353     Beschreibung: SwAuthorField
354  --------------------------------------------------------------------*/
355 
356 SwAuthorField::SwAuthorField(SwAuthorFieldType* pTyp, sal_uInt32 nFmt)
357     : SwField(pTyp, nFmt)
358 {
359     aContent = ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
360 }
361 
362 String SwAuthorField::Expand() const
363 {
364     if (!IsFixed())
365         ((SwAuthorField*)this)->aContent =
366                     ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
367 
368     return aContent;
369 }
370 
371 SwField* SwAuthorField::Copy() const
372 {
373     SwAuthorField *pTmp = new SwAuthorField( (SwAuthorFieldType*)GetTyp(),
374                                                 GetFormat());
375     pTmp->SetExpansion(aContent);
376     return pTmp;
377 }
378 
379 sal_Bool SwAuthorField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
380 {
381     sal_Bool bVal;
382     switch( nWhichId )
383     {
384     case FIELD_PROP_BOOL1:
385         bVal = (GetFormat() & 0xff) == AF_NAME;
386         rAny.setValue(&bVal, ::getBooleanCppuType());
387         break;
388 
389     case FIELD_PROP_BOOL2:
390         bVal = IsFixed();
391         rAny.setValue(&bVal, ::getBooleanCppuType());
392         break;
393 
394     case FIELD_PROP_PAR1:
395         rAny <<= rtl::OUString(GetContent());
396         break;
397 
398     default:
399         DBG_ERROR("illegal property");
400     }
401     return sal_True;
402 }
403 
404 sal_Bool SwAuthorField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
405 {
406     switch( nWhichId )
407     {
408     case FIELD_PROP_BOOL1:
409         SetFormat( *(sal_Bool*)rAny.getValue() ? AF_NAME : AF_SHORTCUT );
410         break;
411 
412     case FIELD_PROP_BOOL2:
413         if( *(sal_Bool*)rAny.getValue() )
414             SetFormat( GetFormat() | AF_FIXED);
415         else
416             SetFormat( GetFormat() & ~AF_FIXED);
417         break;
418 
419     case FIELD_PROP_PAR1:
420         ::GetString( rAny, aContent );
421         break;
422 
423     default:
424         DBG_ERROR("illegal property");
425     }
426     return sal_True;
427 }
428 
429 /*--------------------------------------------------------------------
430     Beschreibung: SwFileNameFieldType
431  --------------------------------------------------------------------*/
432 
433 SwFileNameFieldType::SwFileNameFieldType(SwDoc *pDocument)
434     : SwFieldType( RES_FILENAMEFLD )
435 {
436     pDoc = pDocument;
437 }
438 
439 String SwFileNameFieldType::Expand(sal_uLong nFmt) const
440 {
441     String aRet;
442     const SwDocShell* pDShell = pDoc->GetDocShell();
443     if( pDShell && pDShell->HasName() )
444     {
445         const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
446         switch( nFmt & ~FF_FIXED )
447         {
448             case FF_PATH:
449                 {
450                     if( INET_PROT_FILE == rURLObj.GetProtocol() )
451                     {
452                         INetURLObject aTemp(rURLObj);
453                         aTemp.removeSegment();
454                         // #101947# last slash should belong to the pathname
455                         aRet = aTemp.PathToFileName();//GetFull();
456                     }
457                     else
458                     {
459                         aRet = URIHelper::removePassword(
460                                     rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
461                                     INetURLObject::WAS_ENCODED, URL_DECODE );
462                         aRet.Erase( aRet.Search( String(rURLObj.GetLastName(
463                                                     URL_DECODE )) ) );
464                     }
465                 }
466                 break;
467 
468             case FF_NAME:
469                 aRet = rURLObj.GetLastName( URL_DECODE );
470                 break;
471 
472             case FF_NAME_NOEXT:
473                 aRet = rURLObj.GetBase();
474                 break;
475 
476             default:
477                 if( INET_PROT_FILE == rURLObj.GetProtocol() )
478                     aRet = rURLObj.GetFull();
479                 else
480                     aRet = URIHelper::removePassword(
481                                     rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
482                                     INetURLObject::WAS_ENCODED, URL_DECODE );
483         }
484     }
485     return aRet;
486 }
487 
488 SwFieldType* SwFileNameFieldType::Copy() const
489 {
490     SwFieldType *pTmp = new SwFileNameFieldType(pDoc);
491     return pTmp;
492 }
493 /*--------------------------------------------------------------------
494     Beschreibung: SwFileNameField
495  --------------------------------------------------------------------*/
496 
497 SwFileNameField::SwFileNameField(SwFileNameFieldType* pTyp, sal_uInt32 nFmt)
498     : SwField(pTyp, nFmt)
499 {
500     aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
501 }
502 
503 String SwFileNameField::Expand() const
504 {
505     if (!IsFixed())
506         ((SwFileNameField*)this)->aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
507 
508     return aContent;
509 }
510 
511 SwField* SwFileNameField::Copy() const
512 {
513     SwFileNameField *pTmp =
514         new SwFileNameField((SwFileNameFieldType*)GetTyp(), GetFormat());
515     pTmp->SetExpansion(aContent);
516 
517     return pTmp;
518 }
519 
520 sal_Bool SwFileNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
521 {
522     switch( nWhichId )
523     {
524     case FIELD_PROP_FORMAT:
525         {
526             sal_Int16 nRet;
527             switch( GetFormat() &(~FF_FIXED) )
528             {
529                 case FF_PATH:
530                     nRet = text::FilenameDisplayFormat::PATH;
531                 break;
532                 case FF_NAME_NOEXT:
533                     nRet = text::FilenameDisplayFormat::NAME;
534                 break;
535                 case FF_NAME:
536                     nRet = text::FilenameDisplayFormat::NAME_AND_EXT;
537                 break;
538                 default:    nRet = text::FilenameDisplayFormat::FULL;
539             }
540             rAny <<= nRet;
541         }
542         break;
543 
544     case FIELD_PROP_BOOL2:
545         {
546             sal_Bool bVal = IsFixed();
547             rAny.setValue(&bVal, ::getBooleanCppuType());
548         }
549         break;
550 
551     case FIELD_PROP_PAR3:
552         rAny <<= OUString(GetContent());
553         break;
554     default:
555         DBG_ERROR("illegal property");
556     }
557     return sal_True;
558 }
559 
560 sal_Bool SwFileNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
561 {
562     switch( nWhichId )
563     {
564     case FIELD_PROP_FORMAT:
565         {
566             //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
567             //              called with a int32 value! But normally we need
568             //              here only a int16
569             sal_Int32 nType = 0;
570             rAny >>= nType;
571             sal_Bool bFixed = IsFixed();
572             switch( nType )
573             {
574                 case text::FilenameDisplayFormat::PATH:
575                     nType = FF_PATH;
576                 break;
577                 case text::FilenameDisplayFormat::NAME:
578                     nType = FF_NAME_NOEXT;
579                 break;
580                 case text::FilenameDisplayFormat::NAME_AND_EXT:
581                     nType = FF_NAME;
582                 break;
583                 default:    nType = FF_PATHNAME;
584             }
585             if(bFixed)
586                 nType |= FF_FIXED;
587             SetFormat(nType);
588         }
589         break;
590 
591     case FIELD_PROP_BOOL2:
592         if( *(sal_Bool*)rAny.getValue() )
593             SetFormat( GetFormat() | FF_FIXED);
594         else
595             SetFormat( GetFormat() & ~FF_FIXED);
596         break;
597 
598     case FIELD_PROP_PAR3:
599         ::GetString( rAny, aContent );
600         break;
601 
602     default:
603         DBG_ERROR("illegal property");
604     }
605     return sal_True;
606 }
607 /*--------------------------------------------------------------------
608     Beschreibung: SwTemplNameFieldType
609  --------------------------------------------------------------------*/
610 
611 SwTemplNameFieldType::SwTemplNameFieldType(SwDoc *pDocument)
612     : SwFieldType( RES_TEMPLNAMEFLD )
613 {
614     pDoc = pDocument;
615 }
616 
617 String SwTemplNameFieldType::Expand(sal_uLong nFmt) const
618 {
619     ASSERT( nFmt < FF_END, "Expand: kein guelt. Fmt!" );
620 
621     String aRet;
622     SwDocShell *pDocShell(pDoc->GetDocShell());
623     DBG_ASSERT(pDocShell, "no SwDocShell");
624     if (pDocShell) {
625         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
626             pDocShell->GetModel(), uno::UNO_QUERY_THROW);
627         uno::Reference<document::XDocumentProperties> xDocProps(
628             xDPS->getDocumentProperties());
629         DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
630 
631         if( FF_UI_NAME == nFmt )
632             aRet = xDocProps->getTemplateName();
633         else if( !xDocProps->getTemplateURL().equalsAscii("") )
634         {
635             if( FF_UI_RANGE == nFmt )
636             {
637                 // fuers besorgen vom RegionNamen !!
638                 SfxDocumentTemplates aFac;
639                 aFac.Construct();
640                 String sTmp;
641                 aFac.GetLogicNames( xDocProps->getTemplateURL(), aRet, sTmp );
642             }
643             else
644             {
645                 INetURLObject aPathName( xDocProps->getTemplateURL() );
646                 if( FF_NAME == nFmt )
647                     aRet = aPathName.GetName(URL_DECODE);
648                 else if( FF_NAME_NOEXT == nFmt )
649                     aRet = aPathName.GetBase();
650                 else
651                 {
652                     if( FF_PATH == nFmt )
653                     {
654                         aPathName.removeSegment();
655                         aRet = aPathName.GetFull();
656                     }
657                     else
658                         aRet = aPathName.GetFull();
659                 }
660             }
661         }
662     }
663     return aRet;
664 }
665 
666 SwFieldType* SwTemplNameFieldType::Copy() const
667 {
668     SwFieldType *pTmp = new SwTemplNameFieldType(pDoc);
669     return pTmp;
670 }
671 /*--------------------------------------------------------------------
672     Beschreibung: SwTemplNameField
673  --------------------------------------------------------------------*/
674 
675 SwTemplNameField::SwTemplNameField(SwTemplNameFieldType* pTyp, sal_uInt32 nFmt)
676     : SwField(pTyp, nFmt)
677 {}
678 
679 String SwTemplNameField::Expand() const
680 {
681     return((SwTemplNameFieldType*)GetTyp())->Expand(GetFormat());
682 }
683 
684 SwField* SwTemplNameField::Copy() const
685 {
686     SwTemplNameField *pTmp =
687         new SwTemplNameField((SwTemplNameFieldType*)GetTyp(), GetFormat());
688     return pTmp;
689 }
690 
691 sal_Bool SwTemplNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
692 {
693     switch ( nWhichId )
694     {
695     case FIELD_PROP_FORMAT:
696         {
697             sal_Int16 nRet;
698             switch( GetFormat() )
699             {
700                 case FF_PATH:       nRet = text::FilenameDisplayFormat::PATH; break;
701                 case FF_NAME_NOEXT: nRet = text::FilenameDisplayFormat::NAME; break;
702                 case FF_NAME:       nRet = text::FilenameDisplayFormat::NAME_AND_EXT; break;
703                 case FF_UI_RANGE:   nRet = text::TemplateDisplayFormat::AREA; break;
704                 case FF_UI_NAME:    nRet = text::TemplateDisplayFormat::TITLE;  break;
705                 default:    nRet = text::FilenameDisplayFormat::FULL;
706 
707             }
708             rAny <<= nRet;
709         }
710         break;
711     default:
712         DBG_ERROR("illegal property");
713     }
714     return sal_True;
715 }
716 
717 sal_Bool SwTemplNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
718 {
719     switch ( nWhichId )
720     {
721     case FIELD_PROP_FORMAT:
722         {
723             //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
724             //              called with a int32 value! But normally we need
725             //              here only a int16
726             sal_Int32 nType = 0;
727             rAny >>= nType;
728             switch( nType )
729             {
730             case text::FilenameDisplayFormat::PATH:
731                 SetFormat(FF_PATH);
732             break;
733             case text::FilenameDisplayFormat::NAME:
734                 SetFormat(FF_NAME_NOEXT);
735             break;
736             case text::FilenameDisplayFormat::NAME_AND_EXT:
737                 SetFormat(FF_NAME);
738             break;
739             case text::TemplateDisplayFormat::AREA  :
740                 SetFormat(FF_UI_RANGE);
741             break;
742             case text::TemplateDisplayFormat::TITLE  :
743                 SetFormat(FF_UI_NAME);
744             break;
745             default:    SetFormat(FF_PATHNAME);
746             }
747         }
748         break;
749     default:
750         DBG_ERROR("illegal property");
751     }
752     return sal_True;
753 }
754 /*--------------------------------------------------------------------
755     Beschreibung: SwDocStatFieldType
756  --------------------------------------------------------------------*/
757 
758 SwDocStatFieldType::SwDocStatFieldType(SwDoc* pDocument)
759     : SwFieldType( RES_DOCSTATFLD ), nNumberingType( SVX_NUM_ARABIC )
760 {
761     pDoc = pDocument;
762 }
763 
764 String SwDocStatFieldType::Expand(sal_uInt16 nSubType, sal_uInt32 nFmt) const
765 {
766     sal_uInt32 nVal = 0;
767     const SwDocStat& rDStat = pDoc->GetDocStat();
768     switch( nSubType )
769     {
770         case DS_TBL:  nVal = rDStat.nTbl;   break;
771         case DS_GRF:  nVal = rDStat.nGrf;   break;
772         case DS_OLE:  nVal = rDStat.nOLE;   break;
773         case DS_PARA: nVal = rDStat.nPara;  break;
774         case DS_WORD: nVal = rDStat.nWord;  break;
775         case DS_CHAR: nVal = rDStat.nChar;  break;
776         case DS_PAGE:
777             if( pDoc->GetCurrentLayout() )//swmod 080218
778                 ((SwDocStat &)rDStat).nPage = pDoc->GetCurrentLayout()->GetPageNum();   //swmod 080218
779             nVal = rDStat.nPage;
780             if( SVX_NUM_PAGEDESC == nFmt )
781                 nFmt = (sal_uInt32)nNumberingType;
782             break;
783         default:
784             ASSERT( sal_False, "SwDocStatFieldType::Expand: unbekannter SubType" );
785     }
786 
787     String sRet;
788     if( nVal <= SHRT_MAX )
789         sRet = FormatNumber( (sal_uInt16)nVal, nFmt );
790     else
791         sRet = String::CreateFromInt32( nVal );
792     return sRet;
793 }
794 
795 SwFieldType* SwDocStatFieldType::Copy() const
796 {
797     SwDocStatFieldType *pTmp = new SwDocStatFieldType(pDoc);
798     return pTmp;
799 }
800 
801 /*--------------------------------------------------------------------
802     Beschreibung: SwDocStatFieldType
803                   Aus historischen Gruenden steht in nFormat der
804                   SubType
805  --------------------------------------------------------------------*/
806 
807 SwDocStatField::SwDocStatField(SwDocStatFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFmt)
808     : SwField(pTyp, nFmt),
809     nSubType(nSub)
810 {}
811 
812 String SwDocStatField::Expand() const
813 {
814     return((SwDocStatFieldType*)GetTyp())->Expand(nSubType, GetFormat());
815 }
816 
817 SwField* SwDocStatField::Copy() const
818 {
819     SwDocStatField *pTmp = new SwDocStatField(
820                     (SwDocStatFieldType*)GetTyp(), nSubType, GetFormat() );
821     return pTmp;
822 }
823 
824 sal_uInt16 SwDocStatField::GetSubType() const
825 {
826     return nSubType;
827 }
828 
829 void SwDocStatField::SetSubType(sal_uInt16 nSub)
830 {
831     nSubType = nSub;
832 }
833 
834 void SwDocStatField::ChangeExpansion( const SwFrm* pFrm )
835 {
836     if( DS_PAGE == nSubType && SVX_NUM_PAGEDESC == GetFormat() )
837         ((SwDocStatFieldType*)GetTyp())->SetNumFormat(
838                 pFrm->FindPageFrm()->GetPageDesc()->GetNumType().GetNumberingType() );
839 }
840 
841 sal_Bool SwDocStatField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
842 {
843     switch ( nWhichId )
844     {
845     case FIELD_PROP_USHORT2:
846         rAny <<= (sal_Int16)GetFormat();
847         break;
848     default:
849         DBG_ERROR("illegal property");
850     }
851     return sal_True;
852 }
853 
854 sal_Bool SwDocStatField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
855 {
856     sal_Bool bRet = sal_False;
857     switch ( nWhichId )
858     {
859     case FIELD_PROP_USHORT2:
860         {
861             sal_Int16 nSet = 0;
862             rAny >>= nSet;
863             if(nSet <= SVX_NUM_CHARS_LOWER_LETTER_N &&
864                 nSet != SVX_NUM_CHAR_SPECIAL &&
865                     nSet != SVX_NUM_BITMAP)
866             {
867                 SetFormat(nSet);
868                 bRet = sal_True;
869             }
870         }
871         break;
872 
873     default:
874         DBG_ERROR("illegal property");
875     }
876     return bRet;
877 }
878 
879 /*--------------------------------------------------------------------
880     Beschreibung: DokumentinfoFields
881  --------------------------------------------------------------------*/
882 
883 SwDocInfoFieldType::SwDocInfoFieldType(SwDoc* pDc)
884     : SwValueFieldType( pDc, RES_DOCINFOFLD )
885 {
886 }
887 
888 // ---------------------------------------------------------------------------
889 SwFieldType* SwDocInfoFieldType::Copy() const
890 {
891     SwDocInfoFieldType* pTyp = new SwDocInfoFieldType(GetDoc());
892     return pTyp;
893 }
894 
895 void lcl_GetLocalDataWrapper( sal_uLong nLang,
896                               const LocaleDataWrapper **ppAppLocalData,
897                               const LocaleDataWrapper **ppLocalData )
898 {
899     SvtSysLocale aLocale;
900     *ppAppLocalData = &aLocale.GetLocaleData();
901     *ppLocalData = *ppAppLocalData;
902     if( nLang != SvxLocaleToLanguage( (*ppLocalData)->getLocale() ) )
903         *ppLocalData = new LocaleDataWrapper(
904                         ::comphelper::getProcessServiceFactory(),
905                         SvxCreateLocale( static_cast<LanguageType>(nLang) ) );
906 }
907 
908 // ---------------------------------------------------------------------------
909 String SwDocInfoFieldType::Expand( sal_uInt16 nSub, sal_uInt32 nFormat,
910                                     sal_uInt16 nLang, const String& rName ) const
911 {
912     String aStr;
913     const LocaleDataWrapper *pAppLocalData = 0, *pLocalData = 0;
914     SwDocShell *pDocShell(GetDoc()->GetDocShell());
915     DBG_ASSERT(pDocShell, "no SwDocShell");
916     if (!pDocShell) { return aStr; }
917 
918     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
919         pDocShell->GetModel(), uno::UNO_QUERY_THROW);
920     uno::Reference<document::XDocumentProperties> xDocProps(
921         xDPS->getDocumentProperties());
922     DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
923 
924     sal_uInt16 nExtSub = nSub & 0xff00;
925     nSub &= 0xff;   // ExtendedSubTypes nicht beachten
926 
927     switch(nSub)
928     {
929     case DI_TITEL:  aStr = xDocProps->getTitle();       break;
930     case DI_THEMA:  aStr = xDocProps->getSubject();     break;
931     case DI_KEYS:   aStr = ::comphelper::string::convertCommaSeparated(
932                                 xDocProps->getKeywords());
933                     break;
934     case DI_COMMENT:aStr = xDocProps->getDescription(); break;
935     case DI_DOCNO:  aStr = String::CreateFromInt32(
936                                         xDocProps->getEditingCycles() );
937                     break;
938     case DI_EDIT:
939         if ( !nFormat )
940         {
941             lcl_GetLocalDataWrapper( nLang, &pAppLocalData, &pLocalData );
942             sal_Int32 dur = xDocProps->getEditingDuration();
943             aStr = pLocalData->getTime( Time(dur/3600, (dur%3600)/60, dur%60),
944                                         sal_False, sal_False);
945         }
946         else
947         {
948             sal_Int32 dur = xDocProps->getEditingDuration();
949             double fVal = Time(dur/3600, (dur%3600)/60, dur%60).GetTimeInDays();
950             aStr = ExpandValue(fVal, nFormat, nLang);
951         }
952         break;
953     case DI_CUSTOM:
954         {
955             ::rtl::OUString sVal;
956             try
957             {
958                 uno::Any aAny;
959                 uno::Reference < beans::XPropertySet > xSet(
960                     xDocProps->getUserDefinedProperties(),
961                     uno::UNO_QUERY_THROW);
962                 aAny = xSet->getPropertyValue( rName );
963 
964                 uno::Reference < script::XTypeConverter > xConverter( comphelper::getProcessServiceFactory()
965                     ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), uno::UNO_QUERY );
966                 uno::Any aNew;
967                     aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING );
968                 aNew >>= sVal;
969             }
970             catch (uno::Exception&) {}
971             return sVal;
972         }
973 
974     default:
975         {
976             String aName( xDocProps->getAuthor() );
977             util::DateTime uDT( xDocProps->getCreationDate() );
978             Date aD(uDT.Day, uDT.Month, uDT.Year);
979             Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
980             DateTime aDate(aD,aT);
981             if( nSub == DI_CREATE )
982                 ;       // das wars schon!!
983             else if( nSub == DI_CHANGE )
984             {
985                 aName = xDocProps->getModifiedBy();
986                 uDT = xDocProps->getModificationDate();
987                 Date bD(uDT.Day, uDT.Month, uDT.Year);
988                 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
989                 DateTime bDate(bD,bT);
990                 aDate = bDate;
991             }
992             else if( nSub == DI_PRINT )
993             {
994                 aName = xDocProps->getPrintedBy();
995                 uDT = xDocProps->getPrintDate();
996                 Date bD(uDT.Day, uDT.Month, uDT.Year);
997                 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
998                 DateTime bDate(bD,bT);
999                 aDate = bDate;
1000             }
1001             else
1002                 break;
1003 
1004             if (aDate.IsValid())
1005             {
1006                 switch (nExtSub & ~DI_SUB_FIXED)
1007                 {
1008                 case DI_SUB_AUTHOR:
1009                     aStr = aName;
1010                     break;
1011 
1012                 case DI_SUB_TIME:
1013                     if (!nFormat)
1014                     {
1015                         lcl_GetLocalDataWrapper( nLang, &pAppLocalData,
1016                                                         &pLocalData );
1017                         aStr = pLocalData->getTime( aDate,
1018                                                     sal_False, sal_False);
1019                     }
1020                     else
1021                     {
1022                         // Numberformatter anwerfen!
1023                         double fVal = SwDateTimeField::GetDateTime( GetDoc(),
1024                                                     aDate);
1025                         aStr = ExpandValue(fVal, nFormat, nLang);
1026                     }
1027                     break;
1028 
1029                 case DI_SUB_DATE:
1030                     if (!nFormat)
1031                     {
1032                         lcl_GetLocalDataWrapper( nLang, &pAppLocalData,
1033                                                  &pLocalData );
1034                         aStr = pLocalData->getDate( aDate );
1035                     }
1036                     else
1037                     {
1038                         // Numberformatter anwerfen!
1039                         double fVal = SwDateTimeField::GetDateTime( GetDoc(),
1040                                                     aDate);
1041                         aStr = ExpandValue(fVal, nFormat, nLang);
1042                     }
1043                     break;
1044                 }
1045             }
1046         }
1047         break;
1048     }
1049 
1050     if( pAppLocalData != pLocalData )
1051         delete pLocalData;
1052 
1053     return aStr;
1054 }
1055 
1056 // ---------------------------------------------------------------------------
1057 SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, sal_uInt32 nFmt) :
1058     SwValueField(pTyp, nFmt), nSubType(nSub)
1059 {
1060     aName = rName;
1061     aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, nFmt, GetLanguage(), aName);
1062 }
1063 
1064 SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, const String& rValue, sal_uInt32 nFmt) :
1065     SwValueField(pTyp, nFmt), nSubType(nSub)
1066 {
1067     aName = rName;
1068     aContent = rValue;
1069 }
1070 
1071 // ---------------------------------------------------------------------------
1072 
1073 template<class T>
1074 double lcl_TimeToDouble( const T& rTime )
1075 {
1076     const double fMilliSecondsPerDay = 86400000.0;
1077     return ((rTime.Hours*3600000)+(rTime.Minutes*60000)+(rTime.Seconds*1000)+(rTime.HundredthSeconds*10)) / fMilliSecondsPerDay;
1078 }
1079 
1080 template<class D>
1081 double lcl_DateToDouble( const D& rDate, const Date& rNullDate )
1082 {
1083     long nDate = Date::DateToDays( rDate.Day, rDate.Month, rDate.Year );
1084     long nNullDate = Date::DateToDays( rNullDate.GetDay(), rNullDate.GetMonth(), rNullDate.GetYear() );
1085     return double( nDate - nNullDate );
1086 }
1087 
1088 String SwDocInfoField::Expand() const
1089 {
1090     if ( ( nSubType & 0xFF ) == DI_CUSTOM )
1091     {
1092          // custom properties currently need special treatment
1093          // we don't have a secure way to detect "real" custom properties in Word  Import of text fields
1094         // so we treat *every* unknown property as a custom property, even the "built-in" section in Word's document summary information stream
1095         // as these properties have not been inserted when the document summary information was imported, we do it here
1096         // this approach is still a lot better than the old one to import such fields as "user fields" and simple text
1097         SwDocShell* pDocShell = GetDoc()->GetDocShell();
1098         if( !pDocShell )
1099             return aContent;
1100         try
1101         {
1102             uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW);
1103             uno::Reference<document::XDocumentProperties> xDocProps( xDPS->getDocumentProperties());
1104             uno::Reference < beans::XPropertySet > xSet( xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
1105             uno::Reference < beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
1106 
1107             uno::Any aAny;
1108             if( xSetInfo->hasPropertyByName( aName ) )
1109                 aAny = xSet->getPropertyValue( aName );
1110             if ( aAny.getValueType() != ::getVoidCppuType() )
1111             {
1112                 // "void" type means that the property has not been inserted until now
1113                 if ( !IsFixed() )
1114                 {
1115                     // if the field is "fixed" we don't update it from the property
1116                     ::rtl::OUString sVal;
1117                     uno::Reference < script::XTypeConverter > xConverter( comphelper::getProcessServiceFactory()
1118                         ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), uno::UNO_QUERY );
1119                     util::Date aDate;
1120                     util::DateTime aDateTime;
1121                     util::Duration aDuration;
1122                     if( aAny >>= aDate)
1123                     {
1124                         SvNumberFormatter* pFormatter = pDocShell->GetDoc()->GetNumberFormatter();
1125                         Date* pNullDate = pFormatter->GetNullDate();
1126                         sVal = ExpandValue( lcl_DateToDouble<util::Date>( aDate, *pNullDate ), GetFormat(), GetLanguage());
1127                     }
1128                     else if( aAny >>= aDateTime )
1129                     {
1130                         double fDateTime = lcl_TimeToDouble<util::DateTime>( aDateTime );
1131                         SvNumberFormatter* pFormatter = pDocShell->GetDoc()->GetNumberFormatter();
1132                         Date* pNullDate = pFormatter->GetNullDate();
1133                         fDateTime += lcl_DateToDouble<util::DateTime>( aDateTime, *pNullDate );
1134                         sVal = ExpandValue( fDateTime, GetFormat(), GetLanguage());
1135                     }
1136                     else if( aAny >>= aDuration )
1137                     {
1138                         String sText(aDuration.Negative ? '-' : '+');
1139                         sText += ViewShell::GetShellRes()->sDurationFormat;
1140                         sText.SearchAndReplace(String::CreateFromAscii( "%1"), String::CreateFromInt32( aDuration.Years ) );
1141                         sText.SearchAndReplace(String::CreateFromAscii( "%2"), String::CreateFromInt32( aDuration.Months ) );
1142                         sText.SearchAndReplace(String::CreateFromAscii( "%3"), String::CreateFromInt32( aDuration.Days   ) );
1143                         sText.SearchAndReplace(String::CreateFromAscii( "%4"), String::CreateFromInt32( aDuration.Hours  ) );
1144                         sText.SearchAndReplace(String::CreateFromAscii( "%5"), String::CreateFromInt32( aDuration.Minutes) );
1145                         sText.SearchAndReplace(String::CreateFromAscii( "%6"), String::CreateFromInt32( aDuration.Seconds) );
1146                         sVal = sText;
1147                     }
1148                     else
1149                     {
1150                         uno::Any aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING );
1151                         aNew >>= sVal;
1152                     }
1153                     ((SwDocInfoField*)this)->aContent = sVal;
1154                 }
1155             }
1156         }
1157         catch (uno::Exception&) {}
1158     }
1159     else if ( !IsFixed() )
1160         ((SwDocInfoField*)this)->aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, GetFormat(), GetLanguage(), aName);
1161 
1162     return aContent;
1163 }
1164 /* ---------------------------------------------------------------------------
1165 
1166  ---------------------------------------------------------------------------*/
1167 String SwDocInfoField::GetFieldName() const
1168 {
1169     String aStr(SwFieldType::GetTypeStr(GetTypeId()));
1170     aStr += ':';
1171 
1172     sal_uInt16 const nSub = nSubType & 0xff;
1173 
1174     switch (nSub)
1175     {
1176         case DI_CUSTOM:
1177             aStr += aName;
1178             break;
1179 
1180         default:
1181             aStr += *ViewShell::GetShellRes()
1182                         ->aDocInfoLst[ nSub - DI_SUBTYPE_BEGIN ];
1183             break;
1184     }
1185     if (IsFixed())
1186     {
1187         aStr += ' ';
1188         aStr += ViewShell::GetShellRes()->aFixedStr;
1189     }
1190     return aStr;
1191 }
1192 /* ---------------------------------------------------------------------------
1193 
1194  ---------------------------------------------------------------------------*/
1195 SwField* SwDocInfoField::Copy() const
1196 {
1197     SwDocInfoField* pFld = new SwDocInfoField((SwDocInfoFieldType*)GetTyp(), nSubType, aName, GetFormat());
1198     pFld->SetAutomaticLanguage(IsAutomaticLanguage());
1199     pFld->aContent = aContent;
1200 
1201     return pFld;
1202 }
1203 /* ---------------------------------------------------------------------------
1204 
1205  ---------------------------------------------------------------------------*/
1206 sal_uInt16 SwDocInfoField::GetSubType() const
1207 {
1208     return nSubType;
1209 }
1210 /* ---------------------------------------------------------------------------
1211 
1212  ---------------------------------------------------------------------------*/
1213 void SwDocInfoField::SetSubType(sal_uInt16 nSub)
1214 {
1215     nSubType = nSub;
1216 }
1217 /* ---------------------------------------------------------------------------
1218 
1219  ---------------------------------------------------------------------------*/
1220 void SwDocInfoField::SetLanguage(sal_uInt16 nLng)
1221 {
1222     if (!GetFormat())
1223         SwField::SetLanguage(nLng);
1224     else
1225         SwValueField::SetLanguage(nLng);
1226 }
1227 /* ---------------------------------------------------------------------------
1228 
1229  ---------------------------------------------------------------------------*/
1230 sal_Bool SwDocInfoField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1231 {
1232     switch( nWhichId )
1233     {
1234     case FIELD_PROP_PAR1:
1235         rAny <<= OUString(aContent);
1236         break;
1237 
1238     case FIELD_PROP_PAR4:
1239         rAny <<= OUString(aName);
1240         break;
1241 
1242     case FIELD_PROP_USHORT1:
1243         rAny  <<= (sal_Int16)aContent.ToInt32();
1244         break;
1245 
1246     case FIELD_PROP_BOOL1:
1247         {
1248             sal_Bool bVal = 0 != (nSubType & DI_SUB_FIXED);
1249             rAny.setValue(&bVal, ::getBooleanCppuType());
1250         }
1251         break;
1252     case FIELD_PROP_FORMAT:
1253         rAny  <<= (sal_Int32)GetFormat();
1254         break;
1255 
1256     case FIELD_PROP_DOUBLE:
1257         {
1258             double fVal = GetValue();
1259             rAny.setValue(&fVal, ::getCppuType(&fVal));
1260         }
1261         break;
1262     case FIELD_PROP_PAR3:
1263         rAny <<= rtl::OUString(Expand());
1264         break;
1265     case FIELD_PROP_BOOL2:
1266         {
1267             sal_uInt16 nExtSub = (nSubType & 0xff00) & ~DI_SUB_FIXED;
1268             sal_Bool bVal = (nExtSub == DI_SUB_DATE);
1269             rAny.setValue(&bVal, ::getBooleanCppuType());
1270         }
1271         break;
1272     default:
1273         return SwField::QueryValue(rAny, nWhichId);
1274     }
1275     return sal_True;
1276 }
1277 /* ---------------------------------------------------------------------------
1278 
1279  ---------------------------------------------------------------------------*/
1280 sal_Bool SwDocInfoField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1281 {
1282     sal_Int32 nValue = 0;
1283     switch( nWhichId )
1284     {
1285     case FIELD_PROP_PAR1:
1286         if( nSubType & DI_SUB_FIXED )
1287             ::GetString( rAny, aContent );
1288         break;
1289 
1290     case FIELD_PROP_USHORT1:
1291         if( nSubType & DI_SUB_FIXED )
1292         {
1293             rAny >>= nValue;
1294             aContent = String::CreateFromInt32(nValue);
1295         }
1296         break;
1297 
1298     case FIELD_PROP_BOOL1:
1299         if(*(sal_Bool*)rAny.getValue())
1300             nSubType |= DI_SUB_FIXED;
1301         else
1302             nSubType &= ~DI_SUB_FIXED;
1303         break;
1304     case FIELD_PROP_FORMAT:
1305         {
1306             rAny >>= nValue;
1307             if( nValue >= 0)
1308                 SetFormat(nValue);
1309         }
1310         break;
1311 
1312     case FIELD_PROP_PAR3:
1313         ::GetString( rAny, aContent );
1314         break;
1315     case FIELD_PROP_BOOL2:
1316         nSubType &= 0xf0ff;
1317         if(*(sal_Bool*)rAny.getValue())
1318             nSubType |= DI_SUB_DATE;
1319         else
1320             nSubType |= DI_SUB_TIME;
1321         break;
1322     default:
1323         return SwField::PutValue(rAny, nWhichId);
1324     }
1325     return sal_True;
1326 }
1327 
1328 /*--------------------------------------------------------------------
1329     Beschreibung: SwHiddenTxtFieldType by JP
1330  --------------------------------------------------------------------*/
1331 
1332 SwHiddenTxtFieldType::SwHiddenTxtFieldType( sal_Bool bSetHidden )
1333     : SwFieldType( RES_HIDDENTXTFLD ), bHidden( bSetHidden )
1334 {
1335 }
1336 
1337 SwFieldType* SwHiddenTxtFieldType::Copy() const
1338 {
1339     return new SwHiddenTxtFieldType( bHidden );
1340 }
1341 /* ---------------------------------------------------------------------------
1342 
1343  ---------------------------------------------------------------------------*/
1344 void SwHiddenTxtFieldType::SetHiddenFlag( sal_Bool bSetHidden )
1345 {
1346     if( bHidden != bSetHidden )
1347     {
1348         bHidden = bSetHidden;
1349         UpdateFlds();       // alle HiddenText benachrichtigen
1350     }
1351 }
1352 /* ---------------------------------------------------------------------------
1353 
1354  ---------------------------------------------------------------------------*/
1355 SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType,
1356                                     sal_Bool    bConditional,
1357                                     const   String& rCond,
1358                                     const   String& rStr,
1359                                     sal_Bool    bHidden,
1360                                     sal_uInt16  nSub) :
1361     SwField( pFldType ), aCond(rCond), nSubType(nSub),
1362     bCanToggle(bConditional), bIsHidden(bHidden), bValid(sal_False)
1363 {
1364     if(nSubType == TYP_CONDTXTFLD)
1365     {
1366         sal_uInt16 nPos = 0;
1367         aTRUETxt = rStr.GetToken(0, '|', nPos);
1368 
1369         if(nPos != STRING_NOTFOUND)
1370         {
1371             aFALSETxt = rStr.GetToken(0, '|', nPos);
1372             if(nPos != STRING_NOTFOUND)
1373             {
1374                 aContent = rStr.GetToken(0, '|', nPos);
1375                 bValid = sal_True;
1376             }
1377         }
1378     }
1379     else
1380         aTRUETxt = rStr;
1381 }
1382 /* ---------------------------------------------------------------------------
1383 
1384  ---------------------------------------------------------------------------*/
1385 SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType,
1386                                     const String& rCond,
1387                                     const String& rTrue,
1388                                     const String& rFalse,
1389                                     sal_uInt16 nSub)
1390     : SwField( pFldType ), aTRUETxt(rTrue), aFALSETxt(rFalse), aCond(rCond), nSubType(nSub),
1391       bIsHidden(sal_True), bValid(sal_False)
1392 {
1393     bCanToggle  = aCond.Len() > 0;
1394 }
1395 /* ---------------------------------------------------------------------------
1396 
1397  ---------------------------------------------------------------------------*/
1398 String SwHiddenTxtField::Expand() const
1399 {
1400     // Type: !Hidden  -> immer anzeigen
1401     //        Hide    -> Werte die Bedingung aus
1402 
1403     if( TYP_CONDTXTFLD == nSubType )
1404     {
1405         if( bValid )
1406             return aContent;
1407 
1408         if( bCanToggle && !bIsHidden )
1409             return aTRUETxt;
1410     }
1411     else if( !((SwHiddenTxtFieldType*)GetTyp())->GetHiddenFlag() ||
1412         ( bCanToggle && bIsHidden ))
1413         return aTRUETxt;
1414 
1415     return aFALSETxt;
1416 }
1417 
1418 /*--------------------------------------------------------------------
1419     Beschreibung: Aktuellen Field-Value holen und cachen
1420  --------------------------------------------------------------------*/
1421 
1422 void SwHiddenTxtField::Evaluate(SwDoc* pDoc)
1423 {
1424     ASSERT(pDoc, Wo ist das Dokument Seniore);
1425 
1426     if( TYP_CONDTXTFLD == nSubType )
1427     {
1428         SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
1429 
1430         bValid = sal_False;
1431         String sTmpName;
1432 
1433         if (bCanToggle && !bIsHidden)
1434             sTmpName = aTRUETxt;
1435         else
1436             sTmpName = aFALSETxt;
1437 
1438 // OS 21.08.97: #42943# Datenbankausdruecke muessen sich von
1439 //              einfachem Text unterscheiden. also wird der einfache Text
1440 //              bevorzugt in Anfuehrungszeichen gesetzt.
1441 //              Sind diese vorhanden werden umschliessende entfernt.
1442 //              Wenn nicht, dann wird auf die Tauglichkeit als Datenbankname
1443 //              geprueft. Nur wenn zwei oder mehr Punkte vorhanden sind und kein
1444 //              Anfuehrungszeichen enthalten ist, gehen wir von einer DB aus.
1445         if(sTmpName.Len() > 1 && sTmpName.GetChar(0) == '\"' &&
1446             sTmpName.GetChar((sTmpName.Len() - 1))== '\"')
1447         {
1448             aContent = sTmpName.Copy(1, sTmpName.Len() - 2);
1449             bValid = sal_True;
1450         }
1451         else if(sTmpName.Search('\"') == STRING_NOTFOUND &&
1452             sTmpName.GetTokenCount('.') > 2)
1453         {
1454             ::ReplacePoint(sTmpName);
1455             if(sTmpName.GetChar(0) == '[' && sTmpName.GetChar(sTmpName.Len()-1) == ']')
1456             {   // Eckige Klammern entfernen
1457                 sTmpName.Erase(0, 1);
1458                 sTmpName.Erase(sTmpName.Len()-1, 1);
1459             }
1460 
1461             if( pMgr)
1462             {
1463                 String sDBName( GetDBName( sTmpName, pDoc ));
1464                 String sDataSource(sDBName.GetToken(0, DB_DELIM));
1465                 String sDataTableOrQuery(sDBName.GetToken(1, DB_DELIM));
1466                 if( pMgr->IsInMerge() && sDBName.Len() &&
1467                     pMgr->IsDataSourceOpen( sDataSource,
1468                                                 sDataTableOrQuery, sal_False))
1469                 {
1470                     double fNumber;
1471                     sal_uInt32 nTmpFormat;
1472                     pMgr->GetMergeColumnCnt(GetColumnName( sTmpName ),
1473                         GetLanguage(), aContent, &fNumber, &nTmpFormat );
1474                     bValid = sal_True;
1475                 }
1476                 else if( sDBName.Len() && sDataSource.Len() &&
1477                          sDataTableOrQuery.Len() )
1478                     bValid = sal_True;
1479             }
1480         }
1481     }
1482 }
1483 /* ---------------------------------------------------------------------------
1484 
1485  ---------------------------------------------------------------------------*/
1486 String SwHiddenTxtField::GetFieldName() const
1487 {
1488     String aStr(SwFieldType::GetTypeStr(nSubType));
1489     aStr += ' ';
1490     aStr += aCond;
1491     aStr += ' ';
1492     aStr += aTRUETxt;
1493 
1494     if (nSubType == TYP_CONDTXTFLD)
1495     {
1496         aStr.AppendAscii(" : ");
1497         aStr += aFALSETxt;
1498     }
1499     return aStr;
1500 }
1501 /* ---------------------------------------------------------------------------
1502 
1503  ---------------------------------------------------------------------------*/
1504 SwField* SwHiddenTxtField::Copy() const
1505 {
1506     SwHiddenTxtField* pFld =
1507         new SwHiddenTxtField((SwHiddenTxtFieldType*)GetTyp(), aCond,
1508                               aTRUETxt, aFALSETxt);
1509     pFld->bIsHidden = bIsHidden;
1510     pFld->bValid    = bValid;
1511     pFld->aContent  = aContent;
1512     pFld->SetFormat(GetFormat());
1513     pFld->nSubType  = nSubType;
1514     return pFld;
1515 }
1516 
1517 
1518 /*--------------------------------------------------------------------
1519     Beschreibung: Bedingung setzen
1520  --------------------------------------------------------------------*/
1521 
1522 void SwHiddenTxtField::SetPar1(const String& rStr)
1523 {
1524     aCond = rStr;
1525     bCanToggle = aCond.Len() > 0;
1526 }
1527 /* ---------------------------------------------------------------------------
1528 
1529  ---------------------------------------------------------------------------*/
1530 const String& SwHiddenTxtField::GetPar1() const
1531 {
1532     return aCond;
1533 }
1534 
1535 /*--------------------------------------------------------------------
1536     Beschreibung: True/False Text
1537  --------------------------------------------------------------------*/
1538 
1539 void SwHiddenTxtField::SetPar2(const String& rStr)
1540 {
1541     if(nSubType == TYP_CONDTXTFLD)
1542     {
1543         sal_uInt16 nPos = rStr.Search('|');
1544         aTRUETxt = rStr.Copy(0, nPos);
1545 
1546         if(nPos != STRING_NOTFOUND)
1547             aFALSETxt = rStr.Copy(nPos + 1);
1548     }
1549     else
1550         aTRUETxt = rStr;
1551 }
1552 /* ---------------------------------------------------------------------------
1553 
1554  ---------------------------------------------------------------------------*/
1555 String SwHiddenTxtField::GetPar2() const
1556 {
1557     String aRet(aTRUETxt);
1558     if(nSubType == TYP_CONDTXTFLD)
1559     {
1560         aRet += '|';
1561         aRet += aFALSETxt;
1562     }
1563     return aRet;
1564 }
1565 /* ---------------------------------------------------------------------------
1566 
1567  ---------------------------------------------------------------------------*/
1568 sal_uInt16 SwHiddenTxtField::GetSubType() const
1569 {
1570     return nSubType;
1571 }
1572 /* ---------------------------------------------------------------------------
1573 
1574  ---------------------------------------------------------------------------*/
1575 sal_Bool SwHiddenTxtField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1576 {
1577     const String* pOut = 0;
1578     switch( nWhichId )
1579     {
1580     case FIELD_PROP_PAR1:
1581         pOut = &aCond;
1582         break;
1583     case FIELD_PROP_PAR2:
1584         pOut = &aTRUETxt;
1585         break;
1586     case FIELD_PROP_PAR3:
1587         pOut = &aFALSETxt;
1588         break;
1589     case FIELD_PROP_PAR4 :
1590         pOut = &aContent;
1591     break;
1592     case FIELD_PROP_BOOL1:
1593         {
1594             sal_Bool bHidden = bIsHidden;
1595             rAny.setValue(&bHidden, ::getBooleanCppuType());
1596         }
1597         break;
1598     default:
1599         DBG_ERROR("illegal property");
1600     }
1601     if( pOut )
1602         rAny <<= OUString( *pOut );
1603     return sal_True;
1604 }
1605 /* ---------------------------------------------------------------------------
1606 
1607  ---------------------------------------------------------------------------*/
1608 sal_Bool SwHiddenTxtField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1609 {
1610     switch( nWhichId )
1611     {
1612     case FIELD_PROP_PAR1:
1613         {
1614             String sVal;
1615             SetPar1(::GetString( rAny, sVal ));
1616         }
1617         break;
1618     case FIELD_PROP_PAR2:
1619         ::GetString( rAny, aTRUETxt );
1620         break;
1621     case FIELD_PROP_PAR3:
1622         ::GetString( rAny, aFALSETxt );
1623         break;
1624     case FIELD_PROP_BOOL1:
1625         bIsHidden = *(sal_Bool*)rAny.getValue();
1626         break;
1627     case FIELD_PROP_PAR4:
1628         ::GetString( rAny, aContent);
1629         bValid = sal_True;
1630     break;
1631     default:
1632         DBG_ERROR("illegal property");
1633     }
1634     return sal_True;
1635 }
1636 
1637 //------------------------------------------------------------------------------
1638 
1639 String SwHiddenTxtField::GetColumnName(const String& rName)
1640 {
1641     sal_uInt16 nPos = rName.Search(DB_DELIM);
1642     if( STRING_NOTFOUND != nPos )
1643     {
1644         nPos = rName.Search(DB_DELIM, nPos + 1);
1645 
1646         if( STRING_NOTFOUND != nPos )
1647             return rName.Copy(nPos + 1);
1648     }
1649     return rName;
1650 }
1651 
1652 //------------------------------------------------------------------------------
1653 
1654 String SwHiddenTxtField::GetDBName(const String& rName, SwDoc *pDoc)
1655 {
1656     sal_uInt16 nPos = rName.Search(DB_DELIM);
1657     if( STRING_NOTFOUND != nPos )
1658     {
1659         nPos = rName.Search(DB_DELIM, nPos + 1);
1660 
1661         if( STRING_NOTFOUND != nPos )
1662             return rName.Copy( 0, nPos );
1663     }
1664     SwDBData aData = pDoc->GetDBData();
1665     String sRet = aData.sDataSource;
1666     sRet += DB_DELIM;
1667     sRet += String(aData.sCommand);
1668     return sRet;
1669 }
1670 
1671 /*--------------------------------------------------------------------
1672     Beschreibung: Der Feldtyp fuer Zeilenhoehe 0
1673  --------------------------------------------------------------------*/
1674 
1675 SwHiddenParaFieldType::SwHiddenParaFieldType()
1676     : SwFieldType( RES_HIDDENPARAFLD )
1677 {
1678 }
1679 
1680 SwFieldType* SwHiddenParaFieldType::Copy() const
1681 {
1682     SwHiddenParaFieldType* pTyp = new SwHiddenParaFieldType();
1683     return pTyp;
1684 }
1685 
1686 /*--------------------------------------------------------------------
1687     Beschreibung: Das Feld Zeilenhoehe 0
1688  --------------------------------------------------------------------*/
1689 
1690 SwHiddenParaField::SwHiddenParaField(SwHiddenParaFieldType* pTyp, const String& rStr)
1691     : SwField(pTyp), aCond(rStr)
1692 {
1693     bIsHidden = sal_False;
1694 }
1695 /* ---------------------------------------------------------------------------
1696 
1697  ---------------------------------------------------------------------------*/
1698 String SwHiddenParaField::Expand() const
1699 {
1700     return aEmptyStr;
1701 }
1702 /* ---------------------------------------------------------------------------
1703 
1704  ---------------------------------------------------------------------------*/
1705 SwField* SwHiddenParaField::Copy() const
1706 {
1707     SwHiddenParaField* pFld = new SwHiddenParaField((SwHiddenParaFieldType*)GetTyp(), aCond);
1708     pFld->bIsHidden = bIsHidden;
1709 
1710     return pFld;
1711 }
1712 
1713 sal_Bool SwHiddenParaField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1714 {
1715     switch ( nWhichId )
1716     {
1717     case FIELD_PROP_PAR1:
1718         rAny <<= OUString(aCond);
1719         break;
1720     case  FIELD_PROP_BOOL1:
1721         {
1722             sal_Bool bHidden = bIsHidden;
1723             rAny.setValue(&bHidden, ::getBooleanCppuType());
1724         }
1725         break;
1726 
1727     default:
1728         DBG_ERROR("illegal property");
1729     }
1730     return sal_True;
1731 }
1732 
1733 sal_Bool SwHiddenParaField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1734 {
1735     switch ( nWhichId )
1736     {
1737     case FIELD_PROP_PAR1:
1738         ::GetString( rAny, aCond );
1739         break;
1740     case FIELD_PROP_BOOL1:
1741         bIsHidden = *(sal_Bool*)rAny.getValue();
1742         break;
1743 
1744     default:
1745         DBG_ERROR("illegal property");
1746     }
1747     return sal_True;
1748 }
1749 
1750 /*--------------------------------------------------------------------
1751     Beschreibung: Bedingung setzen
1752  --------------------------------------------------------------------*/
1753 
1754 void SwHiddenParaField::SetPar1(const String& rStr)
1755 {
1756     aCond = rStr;
1757 }
1758 /* ---------------------------------------------------------------------------
1759 
1760  ---------------------------------------------------------------------------*/
1761 const String& SwHiddenParaField::GetPar1() const
1762 {
1763     return aCond;
1764 }
1765 
1766 /*--------------------------------------------------------------------
1767     Beschreibung: PostIt
1768  --------------------------------------------------------------------*/
1769 
1770 SwPostItFieldType::SwPostItFieldType(SwDoc *pDoc)
1771     : SwFieldType( RES_POSTITFLD ),mpDoc(pDoc)
1772 {}
1773 /* ---------------------------------------------------------------------------
1774 
1775  ---------------------------------------------------------------------------*/
1776 SwFieldType* SwPostItFieldType::Copy() const
1777 {
1778     return new SwPostItFieldType(mpDoc);
1779 }
1780 
1781 
1782 /*--------------------------------------------------------------------
1783     Beschreibung: SwPostItFieldType
1784  --------------------------------------------------------------------*/
1785 
1786 SwPostItField::SwPostItField( SwPostItFieldType* pT,
1787         const String& rAuthor, const String& rTxt, const DateTime& rDateTime )
1788     : SwField( pT ), sTxt( rTxt ), sAuthor( rAuthor ), aDateTime( rDateTime ), mpText(0), m_pTextObject(0)
1789 {
1790 }
1791 
1792 
1793 SwPostItField::~SwPostItField()
1794 {
1795     if ( m_pTextObject )
1796     {
1797         m_pTextObject->DisposeEditSource();
1798         m_pTextObject->release();
1799     }
1800 }
1801 
1802 /* ---------------------------------------------------------------------------
1803 
1804  ---------------------------------------------------------------------------*/
1805 String SwPostItField::Expand() const
1806 {
1807     return aEmptyStr;
1808 }
1809 
1810 
1811 String SwPostItField::GetDescription() const
1812 {
1813     return SW_RES(STR_NOTE);
1814 }
1815 
1816 /* ---------------------------------------------------------------------------
1817 
1818  ---------------------------------------------------------------------------*/
1819 SwField* SwPostItField::Copy() const
1820 {
1821     SwPostItField* pRet = new SwPostItField( (SwPostItFieldType*)GetTyp(), sAuthor,
1822                                 sTxt, aDateTime);
1823     if (mpText)
1824         pRet->SetTextObject( new OutlinerParaObject(*mpText) );
1825     return pRet;
1826 }
1827 /*--------------------------------------------------------------------
1828     Beschreibung: Author setzen
1829  --------------------------------------------------------------------*/
1830 
1831 void SwPostItField::SetPar1(const String& rStr)
1832 {
1833     sAuthor = rStr;
1834 }
1835 
1836 const String& SwPostItField::GetPar1() const
1837 {
1838     return sAuthor;
1839 }
1840 
1841 /*--------------------------------------------------------------------
1842     Beschreibung: Text fuers PostIt setzen
1843  --------------------------------------------------------------------*/
1844 
1845 void SwPostItField::SetPar2(const String& rStr)
1846 {
1847     sTxt = rStr;
1848 }
1849 /* ---------------------------------------------------------------------------
1850 
1851  ---------------------------------------------------------------------------*/
1852 String SwPostItField::GetPar2() const
1853 {
1854         return sTxt;
1855 }
1856 
1857 const OutlinerParaObject* SwPostItField::GetTextObject() const
1858 {
1859     return mpText;
1860 }
1861 
1862 void SwPostItField::SetTextObject( OutlinerParaObject* pText )
1863 {
1864     delete mpText;
1865     mpText = pText;
1866 }
1867 
1868 sal_uInt32 SwPostItField::GetNumberOfParagraphs() const
1869 {
1870     return (mpText) ? mpText->Count() : 1;
1871 }
1872 
1873 sal_Bool SwPostItField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1874 {
1875     switch( nWhichId )
1876     {
1877     case FIELD_PROP_PAR1:
1878         rAny <<= OUString(sAuthor);
1879         break;
1880     case FIELD_PROP_PAR2:
1881         {
1882         rAny <<= OUString(sTxt);
1883         break;
1884         }
1885     case FIELD_PROP_TEXT:
1886         {
1887             if ( !m_pTextObject )
1888             {
1889                 SwPostItFieldType* pGetType = (SwPostItFieldType*)GetTyp();
1890                 SwDoc* pDoc = pGetType->GetDoc();
1891                 SwTextAPIEditSource* pObj = new SwTextAPIEditSource( pDoc );
1892                 const_cast <SwPostItField*> (this)->m_pTextObject = new SwTextAPIObject( pObj );
1893                 m_pTextObject->acquire();
1894             }
1895 
1896             if ( mpText )
1897                 m_pTextObject->SetText( *mpText );
1898             else
1899                 m_pTextObject->SetString( sTxt );
1900 
1901             uno::Reference < text::XText > xText( m_pTextObject );
1902             rAny <<= xText;
1903             break;
1904         }
1905     case FIELD_PROP_DATE:
1906         {
1907             util::Date aSetDate;
1908             aSetDate.Day = aDateTime.GetDay();
1909             aSetDate.Month = aDateTime.GetMonth();
1910             aSetDate.Year = aDateTime.GetYear();
1911             rAny.setValue(&aSetDate, ::getCppuType((util::Date*)0));
1912         }
1913         break;
1914     case FIELD_PROP_DATE_TIME:
1915         {
1916                 util::DateTime DateTimeValue;
1917                 DateTimeValue.HundredthSeconds = aDateTime.Get100Sec();
1918                 DateTimeValue.Seconds = aDateTime.GetSec();
1919                 DateTimeValue.Minutes = aDateTime.GetMin();
1920                 DateTimeValue.Hours = aDateTime.GetHour();
1921                 DateTimeValue.Day = aDateTime.GetDay();
1922                 DateTimeValue.Month = aDateTime.GetMonth();
1923                 DateTimeValue.Year = aDateTime.GetYear();
1924                 rAny <<= DateTimeValue;
1925         }
1926         break;
1927     default:
1928         DBG_ERROR("illegal property");
1929     }
1930     return sal_True;
1931 }
1932 
1933 sal_Bool SwPostItField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1934 {
1935     switch( nWhichId )
1936     {
1937     case FIELD_PROP_PAR1:
1938         ::GetString( rAny, sAuthor );
1939         break;
1940     case FIELD_PROP_PAR2:
1941         ::GetString( rAny, sTxt );
1942         //#i100374# new string via api, delete complex text object so SwPostItNote picks up the new string
1943         if (mpText)
1944         {
1945             delete mpText;
1946             mpText = 0;
1947         }
1948         break;
1949     case FIELD_PROP_TEXT:
1950         DBG_ERROR("Not implemented!");
1951         // ::GetString( rAny, sTxt );
1952         break;
1953     case FIELD_PROP_DATE:
1954         if( rAny.getValueType() == ::getCppuType((util::Date*)0) )
1955         {
1956             util::Date aSetDate = *(util::Date*)rAny.getValue();
1957             aDateTime = Date(aSetDate.Day, aSetDate.Month, aSetDate.Year);
1958         }
1959         break;
1960     case FIELD_PROP_DATE_TIME:
1961     {
1962         util::DateTime aDateTimeValue;
1963         if(!(rAny >>= aDateTimeValue))
1964             return sal_False;
1965         aDateTime.Set100Sec(aDateTimeValue.HundredthSeconds);
1966         aDateTime.SetSec(aDateTimeValue.Seconds);
1967         aDateTime.SetMin(aDateTimeValue.Minutes);
1968         aDateTime.SetHour(aDateTimeValue.Hours);
1969         aDateTime.SetDay(aDateTimeValue.Day);
1970         aDateTime.SetMonth(aDateTimeValue.Month);
1971         aDateTime.SetYear(aDateTimeValue.Year);
1972     }
1973     break;
1974     default:
1975         DBG_ERROR("illegal property");
1976     }
1977     return sal_True;
1978 }
1979 /*--------------------------------------------------------------------
1980     Beschreibung: DokumentinfoFields
1981  --------------------------------------------------------------------*/
1982 
1983 SwExtUserFieldType::SwExtUserFieldType()
1984     : SwFieldType( RES_EXTUSERFLD )
1985 {
1986 }
1987 /* ---------------------------------------------------------------------------
1988 
1989  ---------------------------------------------------------------------------*/
1990 SwFieldType* SwExtUserFieldType::Copy() const
1991 {
1992     SwExtUserFieldType* pTyp = new SwExtUserFieldType;
1993     return pTyp;
1994 }
1995 /* ---------------------------------------------------------------------------
1996 
1997  ---------------------------------------------------------------------------*/
1998 String SwExtUserFieldType::Expand(sal_uInt16 nSub, sal_uInt32 ) const
1999 {
2000     String aRet;
2001     sal_uInt16 nRet = USHRT_MAX;
2002     switch(nSub)
2003     {
2004     case EU_FIRSTNAME:      nRet = USER_OPT_FIRSTNAME; break;
2005     case EU_NAME:           nRet = USER_OPT_LASTNAME;  break;
2006     case EU_SHORTCUT:       nRet = USER_OPT_ID; break;
2007 
2008     case EU_COMPANY:        nRet = USER_OPT_COMPANY;        break;
2009     case EU_STREET:         nRet = USER_OPT_STREET;         break;
2010     case EU_TITLE:          nRet = USER_OPT_TITLE;          break;
2011     case EU_POSITION:       nRet = USER_OPT_POSITION;       break;
2012     case EU_PHONE_PRIVATE:  nRet = USER_OPT_TELEPHONEHOME;    break;
2013     case EU_PHONE_COMPANY:  nRet = USER_OPT_TELEPHONEWORK;    break;
2014     case EU_FAX:            nRet = USER_OPT_FAX;            break;
2015     case EU_EMAIL:          nRet = USER_OPT_EMAIL;          break;
2016     case EU_COUNTRY:        nRet = USER_OPT_COUNTRY;        break;
2017     case EU_ZIP:            nRet = USER_OPT_ZIP;            break;
2018     case EU_CITY:           nRet = USER_OPT_CITY;           break;
2019     case EU_STATE:          nRet = USER_OPT_STATE;          break;
2020     case EU_FATHERSNAME:    nRet = USER_OPT_FATHERSNAME;    break;
2021     case EU_APARTMENT:      nRet = USER_OPT_APARTMENT;      break;
2022     default:                ASSERT( !this, "Field unknown");
2023     }
2024     if( USHRT_MAX != nRet )
2025     {
2026         SvtUserOptions&  rUserOpt = SW_MOD()->GetUserOptions();
2027         aRet = rUserOpt.GetToken( nRet );
2028     }
2029     return aRet;
2030 }
2031 /* ---------------------------------------------------------------------------
2032 
2033  ---------------------------------------------------------------------------*/
2034 SwExtUserField::SwExtUserField(SwExtUserFieldType* pTyp, sal_uInt16 nSubTyp, sal_uInt32 nFmt) :
2035     SwField(pTyp, nFmt), nType(nSubTyp)
2036 {
2037     aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
2038 }
2039 /* ---------------------------------------------------------------------------
2040 
2041  ---------------------------------------------------------------------------*/
2042 String SwExtUserField::Expand() const
2043 {
2044     if (!IsFixed())
2045         ((SwExtUserField*)this)->aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
2046 
2047     return aContent;
2048 }
2049 /* ---------------------------------------------------------------------------
2050 
2051  ---------------------------------------------------------------------------*/
2052 SwField* SwExtUserField::Copy() const
2053 {
2054     SwExtUserField* pFld = new SwExtUserField((SwExtUserFieldType*)GetTyp(), nType, GetFormat());
2055     pFld->SetExpansion(aContent);
2056 
2057     return pFld;
2058 }
2059 /* ---------------------------------------------------------------------------
2060 
2061  ---------------------------------------------------------------------------*/
2062 sal_uInt16 SwExtUserField::GetSubType() const
2063 {
2064     return nType;
2065 }
2066 /* ---------------------------------------------------------------------------
2067 
2068  ---------------------------------------------------------------------------*/
2069 void SwExtUserField::SetSubType(sal_uInt16 nSub)
2070 {
2071     nType = nSub;
2072 }
2073 
2074 sal_Bool SwExtUserField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2075 {
2076     switch( nWhichId )
2077     {
2078     case FIELD_PROP_PAR1:
2079         rAny <<= OUString(aContent);
2080         break;
2081 
2082     case FIELD_PROP_USHORT1:
2083         {
2084             sal_Int16 nTmp = nType;
2085             rAny <<= nTmp;
2086         }
2087         break;
2088     case FIELD_PROP_BOOL1:
2089         {
2090             sal_Bool bTmp = IsFixed();
2091             rAny.setValue(&bTmp, ::getBooleanCppuType());
2092         }
2093         break;
2094     default:
2095         DBG_ERROR("illegal property");
2096     }
2097     return sal_True;
2098 }
2099 
2100 sal_Bool SwExtUserField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2101 {
2102     switch( nWhichId )
2103     {
2104     case FIELD_PROP_PAR1:
2105         ::GetString( rAny, aContent );
2106         break;
2107 
2108     case FIELD_PROP_USHORT1:
2109         {
2110             sal_Int16 nTmp = 0;
2111             rAny >>= nTmp;
2112             nType = nTmp;
2113         }
2114         break;
2115     case FIELD_PROP_BOOL1:
2116         if( *(sal_Bool*)rAny.getValue() )
2117             SetFormat(GetFormat() | AF_FIXED);
2118         else
2119             SetFormat(GetFormat() & ~AF_FIXED);
2120         break;
2121     default:
2122         DBG_ERROR("illegal property");
2123     }
2124     return sal_True;
2125 }
2126 //-------------------------------------------------------------------------
2127 
2128 /*--------------------------------------------------------------------
2129     Beschreibung: Relatives Seitennummern - Feld
2130  --------------------------------------------------------------------*/
2131 
2132 SwRefPageSetFieldType::SwRefPageSetFieldType()
2133     : SwFieldType( RES_REFPAGESETFLD )
2134 {
2135 }
2136 /* ---------------------------------------------------------------------------
2137 
2138  ---------------------------------------------------------------------------*/
2139 SwFieldType* SwRefPageSetFieldType::Copy() const
2140 {
2141     return new SwRefPageSetFieldType;
2142 }
2143 /* ---------------------------------------------------------------------------
2144 
2145  ---------------------------------------------------------------------------*/
2146 // ueberlagert, weil es nichts zum Updaten gibt!
2147 void SwRefPageSetFieldType::Modify( const SfxPoolItem*, const SfxPoolItem * )
2148 {
2149 }
2150 
2151 /*--------------------------------------------------------------------
2152     Beschreibung: Relative Seitennummerierung
2153  --------------------------------------------------------------------*/
2154 
2155 SwRefPageSetField::SwRefPageSetField( SwRefPageSetFieldType* pTyp,
2156                     short nOff, sal_Bool bFlag )
2157     : SwField( pTyp ), nOffset( nOff ), bOn( bFlag )
2158 {
2159 }
2160 /* ---------------------------------------------------------------------------
2161 
2162  ---------------------------------------------------------------------------*/
2163 String SwRefPageSetField::Expand() const
2164 {
2165     return aEmptyStr;
2166 }
2167 /* ---------------------------------------------------------------------------
2168 
2169  ---------------------------------------------------------------------------*/
2170 SwField* SwRefPageSetField::Copy() const
2171 {
2172     return new SwRefPageSetField( (SwRefPageSetFieldType*)GetTyp(), nOffset, bOn );
2173 }
2174 /* ---------------------------------------------------------------------------
2175 
2176  ---------------------------------------------------------------------------*/
2177 String SwRefPageSetField::GetPar2() const
2178 {
2179     return String::CreateFromInt32( GetOffset() );
2180 }
2181 /* ---------------------------------------------------------------------------
2182 
2183  ---------------------------------------------------------------------------*/
2184 void SwRefPageSetField::SetPar2(const String& rStr)
2185 {
2186     SetOffset( (short) rStr.ToInt32() );
2187 }
2188 
2189 sal_Bool SwRefPageSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2190 {
2191     switch( nWhichId )
2192     {
2193     case FIELD_PROP_BOOL1:
2194         rAny.setValue(&bOn, ::getBooleanCppuType());
2195         break;
2196     case FIELD_PROP_USHORT1:
2197         rAny <<= (sal_Int16)nOffset;
2198         break;
2199     default:
2200         DBG_ERROR("illegal property");
2201     }
2202     return sal_True;
2203 }
2204 
2205 sal_Bool SwRefPageSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2206 {
2207     switch( nWhichId )
2208     {
2209     case FIELD_PROP_BOOL1:
2210         bOn = *(sal_Bool*)rAny.getValue();
2211         break;
2212     case FIELD_PROP_USHORT1:
2213         rAny >>=nOffset;
2214         break;
2215     default:
2216         DBG_ERROR("illegal property");
2217     }
2218     return sal_True;
2219 }
2220 /*--------------------------------------------------------------------
2221     Beschreibung: relatives Seitennummern - Abfrage Feld
2222  --------------------------------------------------------------------*/
2223 
2224 SwRefPageGetFieldType::SwRefPageGetFieldType( SwDoc* pDc )
2225     : SwFieldType( RES_REFPAGEGETFLD ), pDoc( pDc ), nNumberingType( SVX_NUM_ARABIC )
2226 {
2227 }
2228 /* ---------------------------------------------------------------------------
2229 
2230  ---------------------------------------------------------------------------*/
2231 SwFieldType* SwRefPageGetFieldType::Copy() const
2232 {
2233     SwRefPageGetFieldType* pNew = new SwRefPageGetFieldType( pDoc );
2234     pNew->nNumberingType = nNumberingType;
2235     return pNew;
2236 }
2237 /* ---------------------------------------------------------------------------
2238 
2239  ---------------------------------------------------------------------------*/
2240 void SwRefPageGetFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
2241 {
2242     // Update auf alle GetReferenz-Felder
2243     if( !pNew && !pOld && GetDepends() )
2244     {
2245         // sammel erstmal alle SetPageRefFelder ein.
2246         _SetGetExpFlds aTmpLst( 10, 5 );
2247         if( MakeSetList( aTmpLst ) )
2248         {
2249             SwIterator<SwFmtFld,SwFieldType> aIter( *this );
2250             for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
2251                     // nur die GetRef-Felder Updaten
2252                     if( pFmtFld->GetTxtFld() )
2253                         UpdateField( pFmtFld->GetTxtFld(), aTmpLst );
2254         }
2255     }
2256 
2257     // weiter an die Text-Felder, diese "Expandieren" den Text
2258     NotifyClients( pOld, pNew );
2259 }
2260 /* ---------------------------------------------------------------------------
2261 
2262  ---------------------------------------------------------------------------*/
2263 sal_uInt16 SwRefPageGetFieldType::MakeSetList( _SetGetExpFlds& rTmpLst )
2264 {
2265     SwIterator<SwFmtFld,SwFieldType> aIter(*pDoc->GetSysFldType( RES_REFPAGESETFLD));
2266     for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
2267     {
2268             // nur die GetRef-Felder Updaten
2269             const SwTxtFld* pTFld = pFmtFld->GetTxtFld();
2270             if( pTFld )
2271             {
2272                 const SwTxtNode& rTxtNd = pTFld->GetTxtNode();
2273 
2274                 // immer den ersten !! (in Tab-Headline, Kopf-/Fuss )
2275                 Point aPt;
2276                 const SwCntntFrm* pFrm = rTxtNd.getLayoutFrm( rTxtNd.GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2277 
2278                 _SetGetExpFld* pNew;
2279 
2280                 if( !pFrm ||
2281                      pFrm->IsInDocBody() ||
2282                     // --> FME 2004-07-27 #i31868#
2283                     // Check if pFrm is not yet connected to the layout.
2284                     !pFrm->FindPageFrm() )
2285                     // <--
2286                 {
2287                     // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2288                     SwNodeIndex aIdx( rTxtNd );
2289                     pNew = new _SetGetExpFld( aIdx, pTFld );
2290                 }
2291                 else
2292                 {
2293                     // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2294                     SwPosition aPos( pDoc->GetNodes().GetEndOfPostIts() );
2295 #ifdef DBG_UTIL
2296                     ASSERT( GetBodyTxtNode( *pDoc, aPos, *pFrm ),
2297                             "wo steht das Feld" );
2298 #else
2299                     GetBodyTxtNode( *pDoc, aPos, *pFrm );
2300 #endif
2301                     pNew = new _SetGetExpFld( aPos.nNode, pTFld,
2302                                                 &aPos.nContent );
2303                 }
2304 
2305                 if( !rTmpLst.Insert( pNew ))
2306                     delete pNew;
2307             }
2308     }
2309 
2310     return rTmpLst.Count();
2311 }
2312 /* ---------------------------------------------------------------------------
2313 
2314  ---------------------------------------------------------------------------*/
2315 void SwRefPageGetFieldType::UpdateField( SwTxtFld* pTxtFld,
2316                                         _SetGetExpFlds& rSetList )
2317 {
2318     SwRefPageGetField* pGetFld = (SwRefPageGetField*)pTxtFld->GetFld().GetFld();
2319     pGetFld->SetText( aEmptyStr );
2320 
2321     // dann suche mal das richtige RefPageSet-Field
2322     SwTxtNode* pTxtNode = (SwTxtNode*)&pTxtFld->GetTxtNode();
2323     if( pTxtNode->StartOfSectionIndex() >
2324         pDoc->GetNodes().GetEndOfExtras().GetIndex() )
2325     {
2326         SwNodeIndex aIdx( *pTxtNode );
2327         _SetGetExpFld aEndFld( aIdx, pTxtFld );
2328 
2329         sal_uInt16 nLast;
2330         rSetList.Seek_Entry( &aEndFld, &nLast );
2331 
2332         if( nLast-- )
2333         {
2334             const SwTxtFld* pRefTxtFld = rSetList[ nLast ]->GetFld();
2335             const SwRefPageSetField* pSetFld =
2336                         (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld();
2337             if( pSetFld->IsOn() )
2338             {
2339                 // dann bestimme mal den entsp. Offset
2340                 Point aPt;
2341                 const SwCntntFrm* pFrm = pTxtNode->getLayoutFrm( pTxtNode->GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2342                 const SwCntntFrm* pRefFrm = pRefTxtFld->GetTxtNode().getLayoutFrm( pRefTxtFld->GetTxtNode().GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2343                 const SwPageFrm* pPgFrm = 0;
2344                 sal_uInt16 nDiff = ( pFrm && pRefFrm )
2345                         ?   (pPgFrm = pFrm->FindPageFrm())->GetPhyPageNum() -
2346                             pRefFrm->FindPageFrm()->GetPhyPageNum() + 1
2347                         : 1;
2348 
2349                 sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
2350                         ? ( !pPgFrm
2351                                 ? (sal_uInt32)SVX_NUM_ARABIC
2352                                 : pPgFrm->GetPageDesc()->GetNumType().GetNumberingType() )
2353                         : pGetFld->GetFormat();
2354                 short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff));
2355                 pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
2356             }
2357         }
2358     }
2359     // dann die Formatierung anstossen
2360     ((SwFmtFld&)pTxtFld->GetFld()).ModifyNotification( 0, 0 );
2361 }
2362 
2363 /*--------------------------------------------------------------------
2364     Beschreibung: Relative Seitennummerierung Abfragen
2365  --------------------------------------------------------------------*/
2366 
2367 SwRefPageGetField::SwRefPageGetField( SwRefPageGetFieldType* pTyp,
2368                                     sal_uInt32 nFmt )
2369     : SwField( pTyp, nFmt )
2370 {
2371 }
2372 /* ---------------------------------------------------------------------------
2373 
2374  ---------------------------------------------------------------------------*/
2375 String SwRefPageGetField::Expand() const
2376 {
2377     return sTxt;
2378 }
2379 /* ---------------------------------------------------------------------------
2380 
2381  ---------------------------------------------------------------------------*/
2382 SwField* SwRefPageGetField::Copy() const
2383 {
2384     SwRefPageGetField* pCpy = new SwRefPageGetField(
2385                         (SwRefPageGetFieldType*)GetTyp(), GetFormat() );
2386     pCpy->SetText( sTxt );
2387     return pCpy;
2388 }
2389 /* ---------------------------------------------------------------------------
2390 
2391  ---------------------------------------------------------------------------*/
2392 void SwRefPageGetField::ChangeExpansion( const SwFrm* pFrm,
2393                                         const SwTxtFld* pFld )
2394 {
2395     // nur Felder in Footer, Header, FootNote, Flys
2396     SwTxtNode* pTxtNode = (SwTxtNode*)&pFld->GetTxtNode();
2397     SwRefPageGetFieldType* pGetType = (SwRefPageGetFieldType*)GetTyp();
2398     SwDoc* pDoc = pGetType->GetDoc();
2399     if( pFld->GetTxtNode().StartOfSectionIndex() >
2400         pDoc->GetNodes().GetEndOfExtras().GetIndex() )
2401         return;
2402 
2403     sTxt.Erase();
2404 
2405     ASSERT( !pFrm->IsInDocBody(), "Flag ist nicht richtig, Frame steht im DocBody" );
2406 
2407     // sammel erstmal alle SetPageRefFelder ein.
2408     _SetGetExpFlds aTmpLst( 10, 5 );
2409     if( !pGetType->MakeSetList( aTmpLst ) )
2410         return ;
2411 
2412     // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2413     SwPosition aPos( SwNodeIndex( pDoc->GetNodes() ) );
2414     pTxtNode = (SwTxtNode*) GetBodyTxtNode( *pDoc, aPos, *pFrm );
2415 
2416     // Wenn kein Layout vorhanden, kommt es in Kopf und Fusszeilen dazu
2417     // das ChangeExpansion uebers Layout-Formatieren aufgerufen wird
2418     // aber kein TxtNode vorhanden ist
2419     //
2420     if(!pTxtNode)
2421         return;
2422 
2423     _SetGetExpFld aEndFld( aPos.nNode, pFld, &aPos.nContent );
2424 
2425     sal_uInt16 nLast;
2426     aTmpLst.Seek_Entry( &aEndFld, &nLast );
2427 
2428     if( !nLast-- )
2429         return ;        // es gibt kein entsprechendes Set - Feld vor mir
2430 
2431     const SwTxtFld* pRefTxtFld = aTmpLst[ nLast ]->GetFld();
2432     const SwRefPageSetField* pSetFld =
2433                         (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld();
2434     Point aPt;
2435     const SwCntntFrm* pRefFrm = pRefTxtFld ? pRefTxtFld->GetTxtNode().getLayoutFrm( pFrm->getRootFrm(), &aPt, 0, sal_False ) : 0;
2436     if( pSetFld->IsOn() && pRefFrm )
2437     {
2438         // dann bestimme mal den entsp. Offset
2439         const SwPageFrm* pPgFrm = pFrm->FindPageFrm();
2440         sal_uInt16 nDiff = pPgFrm->GetPhyPageNum() -
2441                             pRefFrm->FindPageFrm()->GetPhyPageNum() + 1;
2442 
2443         SwRefPageGetField* pGetFld = (SwRefPageGetField*)pFld->GetFld().GetFld();
2444         sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
2445                             ? pPgFrm->GetPageDesc()->GetNumType().GetNumberingType()
2446                             : pGetFld->GetFormat();
2447         short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff ));
2448         pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
2449     }
2450 }
2451 
2452 sal_Bool SwRefPageGetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2453 {
2454     switch( nWhichId )
2455     {
2456         case FIELD_PROP_USHORT1:
2457             rAny <<= (sal_Int16)GetFormat();
2458         break;
2459         case FIELD_PROP_PAR1:
2460             rAny <<= OUString(sTxt);
2461         break;
2462         default:
2463             DBG_ERROR("illegal property");
2464     }
2465     return sal_True;
2466 }
2467 
2468 sal_Bool SwRefPageGetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2469 {
2470     switch( nWhichId )
2471     {
2472         case FIELD_PROP_USHORT1:
2473         {
2474             sal_Int16 nSet = 0;
2475             rAny >>= nSet;
2476             if(nSet <= SVX_NUM_PAGEDESC )
2477                 SetFormat(nSet);
2478             else {
2479                 //exception(wrong_value)
2480                 ;
2481             }
2482         }
2483         break;
2484         case FIELD_PROP_PAR1:
2485         {
2486             OUString sTmp;
2487             rAny >>= sTmp;
2488             sTxt = sTmp;
2489         }
2490         break;
2491     default:
2492         DBG_ERROR("illegal property");
2493     }
2494     return sal_True;
2495 }
2496 
2497 /*--------------------------------------------------------------------
2498     Beschreibung: Feld zum Anspringen und Editieren
2499  --------------------------------------------------------------------*/
2500 
2501 SwJumpEditFieldType::SwJumpEditFieldType( SwDoc* pD )
2502     : SwFieldType( RES_JUMPEDITFLD ), pDoc( pD ), aDep( this, 0 )
2503 {
2504 }
2505 /* ---------------------------------------------------------------------------
2506 
2507  ---------------------------------------------------------------------------*/
2508 SwFieldType* SwJumpEditFieldType::Copy() const
2509 {
2510     return new SwJumpEditFieldType( pDoc );
2511 }
2512 /* ---------------------------------------------------------------------------
2513 
2514  ---------------------------------------------------------------------------*/
2515 SwCharFmt* SwJumpEditFieldType::GetCharFmt()
2516 {
2517     SwCharFmt* pFmt = pDoc->GetCharFmtFromPool( RES_POOLCHR_JUMPEDIT );
2518 
2519     // noch nicht registriert ?
2520     if( !aDep.GetRegisteredIn() )
2521         pFmt->Add( &aDep );     // anmelden
2522 
2523     return pFmt;
2524 }
2525 /* ---------------------------------------------------------------------------
2526 
2527  ---------------------------------------------------------------------------*/
2528 SwJumpEditField::SwJumpEditField( SwJumpEditFieldType* pTyp, sal_uInt32 nForm,
2529                                 const String& rTxt, const String& rHelp )
2530     : SwField( pTyp, nForm ), sTxt( rTxt ), sHelp( rHelp )
2531 {
2532 }
2533 /* ---------------------------------------------------------------------------
2534 
2535  ---------------------------------------------------------------------------*/
2536 String SwJumpEditField::Expand() const
2537 {
2538     String sTmp( '<' );
2539     sTmp += sTxt;
2540     return sTmp += '>';
2541 }
2542 /* ---------------------------------------------------------------------------
2543 
2544  ---------------------------------------------------------------------------*/
2545 SwField* SwJumpEditField::Copy() const
2546 {
2547     return new SwJumpEditField( (SwJumpEditFieldType*)GetTyp(), GetFormat(),
2548                                 sTxt, sHelp );
2549 }
2550 /* ---------------------------------------------------------------------------
2551 
2552  ---------------------------------------------------------------------------*/
2553 // Platzhalter-Text
2554 
2555 const String& SwJumpEditField::GetPar1() const
2556 {
2557     return sTxt;
2558 }
2559 /* ---------------------------------------------------------------------------
2560 
2561  ---------------------------------------------------------------------------*/
2562 void SwJumpEditField::SetPar1(const String& rStr)
2563 {
2564     sTxt = rStr;
2565 }
2566 
2567 // HinweisText
2568 /* ---------------------------------------------------------------------------
2569 
2570  ---------------------------------------------------------------------------*/
2571 String SwJumpEditField::GetPar2() const
2572 {
2573     return sHelp;
2574 }
2575 /* ---------------------------------------------------------------------------
2576 
2577  ---------------------------------------------------------------------------*/
2578 void SwJumpEditField::SetPar2(const String& rStr)
2579 {
2580     sHelp = rStr;
2581 }
2582 
2583 sal_Bool SwJumpEditField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2584 {
2585     switch( nWhichId )
2586     {
2587     case FIELD_PROP_USHORT1:
2588         {
2589             sal_Int16 nRet;
2590             switch( GetFormat() )
2591             {
2592             case JE_FMT_TABLE:  nRet = text::PlaceholderType::TABLE; break;
2593             case JE_FMT_FRAME:  nRet = text::PlaceholderType::TEXTFRAME; break;
2594             case JE_FMT_GRAPHIC:nRet = text::PlaceholderType::GRAPHIC; break;
2595             case JE_FMT_OLE:    nRet = text::PlaceholderType::OBJECT; break;
2596 //          case JE_FMT_TEXT:
2597             default:
2598                 nRet = text::PlaceholderType::TEXT; break;
2599             }
2600             rAny <<= nRet;
2601         }
2602         break;
2603     case FIELD_PROP_PAR1 :
2604         rAny <<= OUString(sHelp);
2605         break;
2606     case FIELD_PROP_PAR2 :
2607          rAny <<= OUString(sTxt);
2608          break;
2609     default:
2610         DBG_ERROR("illegal property");
2611     }
2612     return sal_True;
2613 }
2614 
2615 sal_Bool SwJumpEditField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2616 {
2617     switch( nWhichId )
2618     {
2619     case FIELD_PROP_USHORT1:
2620         {
2621             //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
2622             //              called with a int32 value! But normally we need
2623             //              here only a int16
2624             sal_Int32 nSet = 0;
2625             rAny >>= nSet;
2626             switch( nSet )
2627             {
2628                 case text::PlaceholderType::TEXT     : SetFormat(JE_FMT_TEXT); break;
2629                 case text::PlaceholderType::TABLE    : SetFormat(JE_FMT_TABLE); break;
2630                 case text::PlaceholderType::TEXTFRAME: SetFormat(JE_FMT_FRAME); break;
2631                 case text::PlaceholderType::GRAPHIC  : SetFormat(JE_FMT_GRAPHIC); break;
2632                 case text::PlaceholderType::OBJECT   : SetFormat(JE_FMT_OLE); break;
2633             }
2634         }
2635         break;
2636     case FIELD_PROP_PAR1 :
2637         ::GetString( rAny, sHelp );
2638         break;
2639     case FIELD_PROP_PAR2 :
2640          ::GetString( rAny, sTxt);
2641          break;
2642     default:
2643         DBG_ERROR("illegal property");
2644     }
2645     return sal_True;
2646 }
2647 
2648 
2649 /*--------------------------------------------------------------------
2650     Beschreibung: Combined Character Fieldtype / Field
2651  --------------------------------------------------------------------*/
2652 
2653 SwCombinedCharFieldType::SwCombinedCharFieldType()
2654     : SwFieldType( RES_COMBINED_CHARS )
2655 {
2656 }
2657 
2658 SwFieldType* SwCombinedCharFieldType::Copy() const
2659 {
2660     return new SwCombinedCharFieldType;
2661 }
2662 
2663 /* --------------------------------------------------------------------*/
2664 
2665 SwCombinedCharField::SwCombinedCharField( SwCombinedCharFieldType* pFTyp,
2666                                             const String& rChars )
2667     : SwField( pFTyp, 0 ),
2668     sCharacters( rChars.Copy( 0, MAX_COMBINED_CHARACTERS ))
2669 {
2670 }
2671 
2672 String  SwCombinedCharField::Expand() const
2673 {
2674     return sCharacters;
2675 }
2676 
2677 SwField* SwCombinedCharField::Copy() const
2678 {
2679     return new SwCombinedCharField( (SwCombinedCharFieldType*)GetTyp(),
2680                                         sCharacters );
2681 }
2682 
2683 const String& SwCombinedCharField::GetPar1() const
2684 {
2685     return sCharacters;
2686 }
2687 
2688 void SwCombinedCharField::SetPar1(const String& rStr)
2689 {
2690     sCharacters = rStr.Copy( 0, MAX_COMBINED_CHARACTERS );
2691 }
2692 
2693 sal_Bool SwCombinedCharField::QueryValue( uno::Any& rAny,
2694                                         sal_uInt16 nWhichId ) const
2695 {
2696     switch( nWhichId )
2697     {
2698     case FIELD_PROP_PAR1:
2699         rAny <<= rtl::OUString( sCharacters );
2700         break;
2701     default:
2702         DBG_ERROR("illegal property");
2703     }
2704     return sal_True;
2705 }
2706 
2707 sal_Bool SwCombinedCharField::PutValue( const uno::Any& rAny,
2708                                         sal_uInt16 nWhichId )
2709 {
2710     switch( nWhichId )
2711     {
2712     case FIELD_PROP_PAR1:
2713         ::GetString( rAny, sCharacters ).Erase( MAX_COMBINED_CHARACTERS );
2714         break;
2715     default:
2716         DBG_ERROR("illegal property");
2717     }
2718     return sal_True;
2719 }
2720 
2721