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