xref: /AOO41X/main/sw/source/core/fields/docufld.cxx (revision dec99bbd1eb6ae693d6ee672c1a69e3a32d917e7)
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 
SwPageNumberFieldType()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 
Expand(sal_uInt32 nFmt,short nOff,const String & rUserStr,String & rRet) const124 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 
Copy() const139 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 
ChangeExpansion(SwDoc * pDoc,sal_uInt16 nPage,sal_uInt16 nNumPages,sal_Bool bVirt,const sal_Int16 * pNumFmt)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 
SwPageNumberField(SwPageNumberFieldType * pTyp,sal_uInt16 nSub,sal_uInt32 nFmt,short nOff)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 
Expand() const202 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 
Copy() const222 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 
GetPar2() const231 String SwPageNumberField::GetPar2() const
232 {
233     return String::CreateFromInt32(nOffset);
234 }
235 
SetPar2(const String & rStr)236 void SwPageNumberField::SetPar2(const String& rStr)
237 {
238     nOffset = (short)rStr.ToInt32();
239 }
240 
GetSubType() const241 sal_uInt16 SwPageNumberField::GetSubType() const
242 {
243     return nSubType;
244 }
245 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const246 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 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)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 
SwAuthorFieldType()327 SwAuthorFieldType::SwAuthorFieldType()
328     : SwFieldType( RES_AUTHORFLD )
329 {
330 }
331 
Expand(sal_uLong nFmt) const332 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 
Copy() const343 SwFieldType* SwAuthorFieldType::Copy() const
344 {
345     return new SwAuthorFieldType;
346 }
347 
348 /*--------------------------------------------------------------------
349     Beschreibung: SwAuthorField
350  --------------------------------------------------------------------*/
351 
SwAuthorField(SwAuthorFieldType * pTyp,sal_uInt32 nFmt)352 SwAuthorField::SwAuthorField(SwAuthorFieldType* pTyp, sal_uInt32 nFmt)
353     : SwField(pTyp, nFmt)
354 {
355     aContent = ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
356 }
357 
Expand() const358 String SwAuthorField::Expand() const
359 {
360     if (!IsFixed())
361         ((SwAuthorField*)this)->aContent =
362                     ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
363 
364     return aContent;
365 }
366 
Copy() const367 SwField* SwAuthorField::Copy() const
368 {
369     SwAuthorField *pTmp = new SwAuthorField( (SwAuthorFieldType*)GetTyp(),
370                                                 GetFormat());
371     pTmp->SetExpansion(aContent);
372     return pTmp;
373 }
374 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const375 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 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)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 
SwFileNameFieldType(SwDoc * pDocument)429 SwFileNameFieldType::SwFileNameFieldType(SwDoc *pDocument)
430     : SwFieldType( RES_FILENAMEFLD )
431 {
432     pDoc = pDocument;
433 }
434 
Expand(sal_uLong nFmt) const435 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 
Copy() const484 SwFieldType* SwFileNameFieldType::Copy() const
485 {
486     SwFieldType *pTmp = new SwFileNameFieldType(pDoc);
487     return pTmp;
488 }
489 /*--------------------------------------------------------------------
490     Beschreibung: SwFileNameField
491  --------------------------------------------------------------------*/
492 
SwFileNameField(SwFileNameFieldType * pTyp,sal_uInt32 nFmt)493 SwFileNameField::SwFileNameField(SwFileNameFieldType* pTyp, sal_uInt32 nFmt)
494     : SwField(pTyp, nFmt)
495 {
496     aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
497 }
498 
Expand() const499 String SwFileNameField::Expand() const
500 {
501     if (!IsFixed())
502         ((SwFileNameField*)this)->aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
503 
504     return aContent;
505 }
506 
Copy() const507 SwField* SwFileNameField::Copy() const
508 {
509     SwFileNameField *pTmp =
510         new SwFileNameField((SwFileNameFieldType*)GetTyp(), GetFormat());
511     pTmp->SetExpansion(aContent);
512 
513     return pTmp;
514 }
515 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const516 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 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)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 
SwTemplNameFieldType(SwDoc * pDocument)607 SwTemplNameFieldType::SwTemplNameFieldType(SwDoc *pDocument)
608     : SwFieldType( RES_TEMPLNAMEFLD )
609 {
610     pDoc = pDocument;
611 }
612 
Expand(sal_uLong nFmt) const613 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 
Copy() const662 SwFieldType* SwTemplNameFieldType::Copy() const
663 {
664     SwFieldType *pTmp = new SwTemplNameFieldType(pDoc);
665     return pTmp;
666 }
667 /*--------------------------------------------------------------------
668     Beschreibung: SwTemplNameField
669  --------------------------------------------------------------------*/
670 
SwTemplNameField(SwTemplNameFieldType * pTyp,sal_uInt32 nFmt)671 SwTemplNameField::SwTemplNameField(SwTemplNameFieldType* pTyp, sal_uInt32 nFmt)
672     : SwField(pTyp, nFmt)
673 {}
674 
Expand() const675 String SwTemplNameField::Expand() const
676 {
677     return((SwTemplNameFieldType*)GetTyp())->Expand(GetFormat());
678 }
679 
Copy() const680 SwField* SwTemplNameField::Copy() const
681 {
682     SwTemplNameField *pTmp =
683         new SwTemplNameField((SwTemplNameFieldType*)GetTyp(), GetFormat());
684     return pTmp;
685 }
686 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const687 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 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)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 
SwDocStatFieldType(SwDoc * pDocument)754 SwDocStatFieldType::SwDocStatFieldType(SwDoc* pDocument)
755     : SwFieldType( RES_DOCSTATFLD ), nNumberingType( SVX_NUM_ARABIC )
756 {
757     pDoc = pDocument;
758 }
759 
Expand(sal_uInt16 nSubType,sal_uInt32 nFmt) const760 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 
Copy() const791 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 
SwDocStatField(SwDocStatFieldType * pTyp,sal_uInt16 nSub,sal_uInt32 nFmt)803 SwDocStatField::SwDocStatField(SwDocStatFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFmt)
804     : SwField(pTyp, nFmt),
805     nSubType(nSub)
806 {}
807 
Expand() const808 String SwDocStatField::Expand() const
809 {
810     return((SwDocStatFieldType*)GetTyp())->Expand(nSubType, GetFormat());
811 }
812 
Copy() const813 SwField* SwDocStatField::Copy() const
814 {
815     SwDocStatField *pTmp = new SwDocStatField(
816                     (SwDocStatFieldType*)GetTyp(), nSubType, GetFormat() );
817     return pTmp;
818 }
819 
GetSubType() const820 sal_uInt16 SwDocStatField::GetSubType() const
821 {
822     return nSubType;
823 }
824 
SetSubType(sal_uInt16 nSub)825 void SwDocStatField::SetSubType(sal_uInt16 nSub)
826 {
827     nSubType = nSub;
828 }
829 
ChangeExpansion(const SwFrm * pFrm)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 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const837 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 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)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 
SwDocInfoFieldType(SwDoc * pDc)879 SwDocInfoFieldType::SwDocInfoFieldType(SwDoc* pDc)
880     : SwValueFieldType( pDc, RES_DOCINFOFLD )
881 {
882 }
883 
884 // ---------------------------------------------------------------------------
Copy() const885 SwFieldType* SwDocInfoFieldType::Copy() const
886 {
887     SwDocInfoFieldType* pTyp = new SwDocInfoFieldType(GetDoc());
888     return pTyp;
889 }
890 
lcl_GetLocalDataWrapper(sal_uLong nLang,const LocaleDataWrapper ** ppAppLocalData,const LocaleDataWrapper ** ppLocalData)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 // ---------------------------------------------------------------------------
Expand(sal_uInt16 nSub,sal_uInt32 nFormat,sal_uInt16 nLang,const String & rName) const905 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 // ---------------------------------------------------------------------------
SwDocInfoField(SwDocInfoFieldType * pTyp,sal_uInt16 nSub,const String & rName,sal_uInt32 nFmt)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 
SwDocInfoField(SwDocInfoFieldType * pTyp,sal_uInt16 nSub,const String & rName,const String & rValue,sal_uInt32 nFmt)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>
lcl_TimeToDouble(const T & rTime)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>
lcl_DateToDouble(const D & rDate,const Date & rNullDate)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 
Expand() const1084 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  ---------------------------------------------------------------------------*/
GetFieldName() const1163 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  ---------------------------------------------------------------------------*/
Copy() const1191 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  ---------------------------------------------------------------------------*/
GetSubType() const1202 sal_uInt16 SwDocInfoField::GetSubType() const
1203 {
1204     return nSubType;
1205 }
1206 /* ---------------------------------------------------------------------------
1207 
1208  ---------------------------------------------------------------------------*/
SetSubType(sal_uInt16 nSub)1209 void SwDocInfoField::SetSubType(sal_uInt16 nSub)
1210 {
1211     nSubType = nSub;
1212 }
1213 /* ---------------------------------------------------------------------------
1214 
1215  ---------------------------------------------------------------------------*/
SetLanguage(sal_uInt16 nLng)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  ---------------------------------------------------------------------------*/
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const1226 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  ---------------------------------------------------------------------------*/
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)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 
SwHiddenTxtFieldType(sal_Bool bSetHidden)1328 SwHiddenTxtFieldType::SwHiddenTxtFieldType( sal_Bool bSetHidden )
1329     : SwFieldType( RES_HIDDENTXTFLD ), bHidden( bSetHidden )
1330 {
1331 }
1332 
Copy() const1333 SwFieldType* SwHiddenTxtFieldType::Copy() const
1334 {
1335     return new SwHiddenTxtFieldType( bHidden );
1336 }
1337 /* ---------------------------------------------------------------------------
1338 
1339  ---------------------------------------------------------------------------*/
SetHiddenFlag(sal_Bool bSetHidden)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  ---------------------------------------------------------------------------*/
SwHiddenTxtField(SwHiddenTxtFieldType * pFldType,sal_Bool bConditional,const String & rCond,const String & rStr,sal_Bool bHidden,sal_uInt16 nSub)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  ---------------------------------------------------------------------------*/
SwHiddenTxtField(SwHiddenTxtFieldType * pFldType,const String & rCond,const String & rTrue,const String & rFalse,sal_uInt16 nSub)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  ---------------------------------------------------------------------------*/
Expand() const1394 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 
Evaluate(SwDoc * pDoc)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  ---------------------------------------------------------------------------*/
GetFieldName() const1482 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  ---------------------------------------------------------------------------*/
Copy() const1500 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 
SetPar1(const String & rStr)1518 void SwHiddenTxtField::SetPar1(const String& rStr)
1519 {
1520     aCond = rStr;
1521     bCanToggle = aCond.Len() > 0;
1522 }
1523 /* ---------------------------------------------------------------------------
1524 
1525  ---------------------------------------------------------------------------*/
GetPar1() const1526 const String& SwHiddenTxtField::GetPar1() const
1527 {
1528     return aCond;
1529 }
1530 
1531 /*--------------------------------------------------------------------
1532     Beschreibung: True/False Text
1533  --------------------------------------------------------------------*/
1534 
SetPar2(const String & rStr)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  ---------------------------------------------------------------------------*/
GetPar2() const1551 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  ---------------------------------------------------------------------------*/
GetSubType() const1564 sal_uInt16 SwHiddenTxtField::GetSubType() const
1565 {
1566     return nSubType;
1567 }
1568 /* ---------------------------------------------------------------------------
1569 
1570  ---------------------------------------------------------------------------*/
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const1571 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  ---------------------------------------------------------------------------*/
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)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 
GetColumnName(const String & rName)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 
GetDBName(const String & rName,SwDoc * pDoc)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 
SwHiddenParaFieldType()1671 SwHiddenParaFieldType::SwHiddenParaFieldType()
1672     : SwFieldType( RES_HIDDENPARAFLD )
1673 {
1674 }
1675 
Copy() const1676 SwFieldType* SwHiddenParaFieldType::Copy() const
1677 {
1678     SwHiddenParaFieldType* pTyp = new SwHiddenParaFieldType();
1679     return pTyp;
1680 }
1681 
1682 /*--------------------------------------------------------------------
1683     Beschreibung: Das Feld Zeilenhoehe 0
1684  --------------------------------------------------------------------*/
1685 
SwHiddenParaField(SwHiddenParaFieldType * pTyp,const String & rStr)1686 SwHiddenParaField::SwHiddenParaField(SwHiddenParaFieldType* pTyp, const String& rStr)
1687     : SwField(pTyp), aCond(rStr)
1688 {
1689     bIsHidden = sal_False;
1690 }
1691 /* ---------------------------------------------------------------------------
1692 
1693  ---------------------------------------------------------------------------*/
Expand() const1694 String SwHiddenParaField::Expand() const
1695 {
1696     return aEmptyStr;
1697 }
1698 /* ---------------------------------------------------------------------------
1699 
1700  ---------------------------------------------------------------------------*/
Copy() const1701 SwField* SwHiddenParaField::Copy() const
1702 {
1703     SwHiddenParaField* pFld = new SwHiddenParaField((SwHiddenParaFieldType*)GetTyp(), aCond);
1704     pFld->bIsHidden = bIsHidden;
1705 
1706     return pFld;
1707 }
1708 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const1709 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 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)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 
SetPar1(const String & rStr)1750 void SwHiddenParaField::SetPar1(const String& rStr)
1751 {
1752     aCond = rStr;
1753 }
1754 /* ---------------------------------------------------------------------------
1755 
1756  ---------------------------------------------------------------------------*/
GetPar1() const1757 const String& SwHiddenParaField::GetPar1() const
1758 {
1759     return aCond;
1760 }
1761 
1762 /*--------------------------------------------------------------------
1763     Beschreibung: PostIt
1764  --------------------------------------------------------------------*/
1765 
SwPostItFieldType(SwDoc * pDoc)1766 SwPostItFieldType::SwPostItFieldType(SwDoc *pDoc)
1767     : SwFieldType( RES_POSTITFLD )
1768     , mpDoc(pDoc)
1769 {}
1770 /* ---------------------------------------------------------------------------
1771 
1772  ---------------------------------------------------------------------------*/
Copy() const1773 SwFieldType* SwPostItFieldType::Copy() const
1774 {
1775     return new SwPostItFieldType(mpDoc);
1776 }
1777 
1778 
1779 
1780 
SwPostItField(SwPostItFieldType * pT,const String & rCommentContent,const String & rAuthor,const String & rAuthorInitials,const String & rName,const DateTime & rDateTime)1781 SwPostItField::SwPostItField(
1782     SwPostItFieldType* pT,
1783     const String& rCommentContent,
1784     const String& rAuthor,
1785     const String& rAuthorInitials,
1786     const String& rName,
1787     const DateTime& rDateTime )
1788     : SwField( pT )
1789     , msCommentContent( rCommentContent )
1790     , msAuthor( rAuthor )
1791     , msAuthorInitials( rAuthorInitials )
1792     , msName( rName )
1793     , maDateTime( rDateTime )
1794     , mpText( NULL )
1795     , m_pTextObject( NULL )
1796 {
1797 }
1798 
1799 
~SwPostItField()1800 SwPostItField::~SwPostItField()
1801 {
1802     if ( m_pTextObject != NULL )
1803     {
1804         m_pTextObject->DisposeEditSource();
1805         m_pTextObject->release();
1806     }
1807 
1808     delete mpText;
1809 }
1810 
1811 
Expand() const1812 String SwPostItField::Expand() const
1813 {
1814     return aEmptyStr;
1815 }
1816 
1817 
GetDescription() const1818 String SwPostItField::GetDescription() const
1819 {
1820     return SW_RES(STR_NOTE);
1821 }
1822 
1823 
Copy() const1824 SwField* SwPostItField::Copy() const
1825 {
1826     SwPostItField* pRet =
1827         new SwPostItField(
1828             (SwPostItFieldType*)GetTyp(),
1829             msCommentContent,
1830             msAuthor,
1831             msAuthorInitials,
1832             msName,
1833             maDateTime);
1834     if ( mpText != NULL )
1835     {
1836         pRet->SetTextObject( new OutlinerParaObject(*mpText) );
1837     }
1838 
1839     // Note: member <m_pTextObject> not copied.
1840 
1841     return pRet;
1842 }
1843 
1844 
SetPar1(const String & rStr)1845 void SwPostItField::SetPar1(const String& rStr)
1846 {
1847     msAuthor = rStr;
1848 }
1849 
GetPar1() const1850 const String& SwPostItField::GetPar1() const
1851 {
1852     return msAuthor;
1853 }
1854 
1855 
SetPar2(const String & rStr)1856 void SwPostItField::SetPar2(const String& rStr)
1857 {
1858     msCommentContent = rStr;
1859 }
1860 
GetPar2() const1861 String SwPostItField::GetPar2() const
1862 {
1863     return msCommentContent;
1864 }
1865 
1866 
SetName(const String & rName)1867 void SwPostItField::SetName(const String& rName)
1868 {
1869     msName = rName;
1870 }
1871 
GetName() const1872 const String& SwPostItField::GetName() const
1873 {
1874     return msName;
1875 }
1876 
1877 
GetTextObject() const1878 const OutlinerParaObject* SwPostItField::GetTextObject() const
1879 {
1880     return mpText;
1881 }
1882 
SetTextObject(OutlinerParaObject * pText)1883 void SwPostItField::SetTextObject( OutlinerParaObject* pText )
1884 {
1885     delete mpText;
1886     mpText = pText;
1887 }
1888 
1889 
GetNumberOfParagraphs() const1890 sal_uInt32 SwPostItField::GetNumberOfParagraphs() const
1891 {
1892     return (mpText) ? mpText->Count() : 1;
1893 }
1894 
1895 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const1896 sal_Bool SwPostItField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1897 {
1898     switch( nWhichId )
1899     {
1900     case FIELD_PROP_PAR1:
1901         rAny <<= OUString(msAuthor);
1902         break;
1903     case FIELD_PROP_PAR2:
1904         {
1905             rAny <<= OUString(msCommentContent);
1906             break;
1907         }
1908     case FIELD_PROP_PAR3:
1909         rAny <<= OUString(msAuthorInitials);
1910         break;
1911     case FIELD_PROP_PAR4:
1912         rAny <<= OUString(msName);
1913         break;
1914     case FIELD_PROP_TEXT:
1915         {
1916             if ( !m_pTextObject )
1917             {
1918                 SwPostItFieldType* pGetType = (SwPostItFieldType*)GetTyp();
1919                 SwDoc* pDoc = pGetType->GetDoc();
1920                 SwTextAPIEditSource* pObj = new SwTextAPIEditSource( pDoc );
1921                 const_cast <SwPostItField*> (this)->m_pTextObject = new SwTextAPIObject( pObj );
1922                 m_pTextObject->acquire();
1923             }
1924 
1925             if ( mpText )
1926                 m_pTextObject->SetText( *mpText );
1927             else
1928                 m_pTextObject->SetString( msCommentContent );
1929 
1930             uno::Reference < text::XText > xText( m_pTextObject );
1931             rAny <<= xText;
1932             break;
1933         }
1934     case FIELD_PROP_DATE:
1935         {
1936             util::Date aSetDate;
1937             aSetDate.Day = maDateTime.GetDay();
1938             aSetDate.Month = maDateTime.GetMonth();
1939             aSetDate.Year = maDateTime.GetYear();
1940             rAny.setValue(&aSetDate, ::getCppuType((util::Date*)0));
1941         }
1942         break;
1943     case FIELD_PROP_DATE_TIME:
1944         {
1945             util::DateTime DateTimeValue;
1946             DateTimeValue.HundredthSeconds = maDateTime.Get100Sec();
1947             DateTimeValue.Seconds = maDateTime.GetSec();
1948             DateTimeValue.Minutes = maDateTime.GetMin();
1949             DateTimeValue.Hours = maDateTime.GetHour();
1950             DateTimeValue.Day = maDateTime.GetDay();
1951             DateTimeValue.Month = maDateTime.GetMonth();
1952             DateTimeValue.Year = maDateTime.GetYear();
1953             rAny <<= DateTimeValue;
1954         }
1955         break;
1956     default:
1957         DBG_ERROR("illegal property");
1958     }
1959     return sal_True;
1960 }
1961 
1962 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)1963 sal_Bool SwPostItField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1964 {
1965     switch( nWhichId )
1966     {
1967     case FIELD_PROP_PAR1:
1968         ::GetString( rAny, msAuthor );
1969         break;
1970     case FIELD_PROP_PAR2:
1971         ::GetString( rAny, msCommentContent );
1972         //#i100374# new string via api, delete complex text object so SwPostItNote picks up the new string
1973         if (mpText)
1974         {
1975             delete mpText;
1976             mpText = 0;
1977         }
1978         break;
1979     case FIELD_PROP_PAR3:
1980         ::GetString( rAny, msAuthorInitials );
1981         break;
1982     case FIELD_PROP_PAR4:
1983         ::GetString( rAny, msName );
1984         break;
1985     case FIELD_PROP_TEXT:
1986         DBG_ERROR("Not implemented!");
1987         // ::GetString( rAny, msCommentContent );
1988         break;
1989     case FIELD_PROP_DATE:
1990         if( rAny.getValueType() == ::getCppuType((util::Date*)0) )
1991         {
1992             util::Date aSetDate = *(util::Date*)rAny.getValue();
1993             maDateTime = Date(aSetDate.Day, aSetDate.Month, aSetDate.Year);
1994         }
1995         break;
1996     case FIELD_PROP_DATE_TIME:
1997         {
1998             util::DateTime aDateTimeValue;
1999             if(!(rAny >>= aDateTimeValue))
2000                 return sal_False;
2001             maDateTime.Set100Sec(aDateTimeValue.HundredthSeconds);
2002             maDateTime.SetSec(aDateTimeValue.Seconds);
2003             maDateTime.SetMin(aDateTimeValue.Minutes);
2004             maDateTime.SetHour(aDateTimeValue.Hours);
2005             maDateTime.SetDay(aDateTimeValue.Day);
2006             maDateTime.SetMonth(aDateTimeValue.Month);
2007             maDateTime.SetYear(aDateTimeValue.Year);
2008         }
2009         break;
2010     default:
2011         DBG_ERROR("illegal property");
2012     }
2013     return sal_True;
2014 }
2015 
2016 
2017 /*--------------------------------------------------------------------
2018     Beschreibung: DokumentinfoFields
2019  --------------------------------------------------------------------*/
2020 
SwExtUserFieldType()2021 SwExtUserFieldType::SwExtUserFieldType()
2022     : SwFieldType( RES_EXTUSERFLD )
2023 {
2024 }
2025 /* ---------------------------------------------------------------------------
2026 
2027  ---------------------------------------------------------------------------*/
Copy() const2028 SwFieldType* SwExtUserFieldType::Copy() const
2029 {
2030     SwExtUserFieldType* pTyp = new SwExtUserFieldType;
2031     return pTyp;
2032 }
2033 /* ---------------------------------------------------------------------------
2034 
2035  ---------------------------------------------------------------------------*/
Expand(sal_uInt16 nSub,sal_uInt32) const2036 String SwExtUserFieldType::Expand(sal_uInt16 nSub, sal_uInt32 ) const
2037 {
2038     String aRet;
2039     sal_uInt16 nRet = USHRT_MAX;
2040     switch(nSub)
2041     {
2042     case EU_FIRSTNAME:      nRet = USER_OPT_FIRSTNAME; break;
2043     case EU_NAME:           nRet = USER_OPT_LASTNAME;  break;
2044     case EU_SHORTCUT:       nRet = USER_OPT_ID; break;
2045 
2046     case EU_COMPANY:        nRet = USER_OPT_COMPANY;        break;
2047     case EU_STREET:         nRet = USER_OPT_STREET;         break;
2048     case EU_TITLE:          nRet = USER_OPT_TITLE;          break;
2049     case EU_POSITION:       nRet = USER_OPT_POSITION;       break;
2050     case EU_PHONE_PRIVATE:  nRet = USER_OPT_TELEPHONEHOME;    break;
2051     case EU_PHONE_COMPANY:  nRet = USER_OPT_TELEPHONEWORK;    break;
2052     case EU_FAX:            nRet = USER_OPT_FAX;            break;
2053     case EU_EMAIL:          nRet = USER_OPT_EMAIL;          break;
2054     case EU_COUNTRY:        nRet = USER_OPT_COUNTRY;        break;
2055     case EU_ZIP:            nRet = USER_OPT_ZIP;            break;
2056     case EU_CITY:           nRet = USER_OPT_CITY;           break;
2057     case EU_STATE:          nRet = USER_OPT_STATE;          break;
2058     case EU_FATHERSNAME:    nRet = USER_OPT_FATHERSNAME;    break;
2059     case EU_APARTMENT:      nRet = USER_OPT_APARTMENT;      break;
2060     default:                ASSERT( !this, "Field unknown");
2061     }
2062     if( USHRT_MAX != nRet )
2063     {
2064         SvtUserOptions&  rUserOpt = SW_MOD()->GetUserOptions();
2065         aRet = rUserOpt.GetToken( nRet );
2066     }
2067     return aRet;
2068 }
2069 /* ---------------------------------------------------------------------------
2070 
2071  ---------------------------------------------------------------------------*/
SwExtUserField(SwExtUserFieldType * pTyp,sal_uInt16 nSubTyp,sal_uInt32 nFmt)2072 SwExtUserField::SwExtUserField(SwExtUserFieldType* pTyp, sal_uInt16 nSubTyp, sal_uInt32 nFmt) :
2073     SwField(pTyp, nFmt), nType(nSubTyp)
2074 {
2075     aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
2076 }
2077 /* ---------------------------------------------------------------------------
2078 
2079  ---------------------------------------------------------------------------*/
Expand() const2080 String SwExtUserField::Expand() const
2081 {
2082     if (!IsFixed())
2083         ((SwExtUserField*)this)->aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
2084 
2085     return aContent;
2086 }
2087 /* ---------------------------------------------------------------------------
2088 
2089  ---------------------------------------------------------------------------*/
Copy() const2090 SwField* SwExtUserField::Copy() const
2091 {
2092     SwExtUserField* pFld = new SwExtUserField((SwExtUserFieldType*)GetTyp(), nType, GetFormat());
2093     pFld->SetExpansion(aContent);
2094 
2095     return pFld;
2096 }
2097 /* ---------------------------------------------------------------------------
2098 
2099  ---------------------------------------------------------------------------*/
GetSubType() const2100 sal_uInt16 SwExtUserField::GetSubType() const
2101 {
2102     return nType;
2103 }
2104 /* ---------------------------------------------------------------------------
2105 
2106  ---------------------------------------------------------------------------*/
SetSubType(sal_uInt16 nSub)2107 void SwExtUserField::SetSubType(sal_uInt16 nSub)
2108 {
2109     nType = nSub;
2110 }
2111 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2112 sal_Bool SwExtUserField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2113 {
2114     switch( nWhichId )
2115     {
2116     case FIELD_PROP_PAR1:
2117         rAny <<= OUString(aContent);
2118         break;
2119 
2120     case FIELD_PROP_USHORT1:
2121         {
2122             sal_Int16 nTmp = nType;
2123             rAny <<= nTmp;
2124         }
2125         break;
2126     case FIELD_PROP_BOOL1:
2127         {
2128             sal_Bool bTmp = IsFixed();
2129             rAny.setValue(&bTmp, ::getBooleanCppuType());
2130         }
2131         break;
2132     default:
2133         DBG_ERROR("illegal property");
2134     }
2135     return sal_True;
2136 }
2137 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2138 sal_Bool SwExtUserField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2139 {
2140     switch( nWhichId )
2141     {
2142     case FIELD_PROP_PAR1:
2143         ::GetString( rAny, aContent );
2144         break;
2145 
2146     case FIELD_PROP_USHORT1:
2147         {
2148             sal_Int16 nTmp = 0;
2149             rAny >>= nTmp;
2150             nType = nTmp;
2151         }
2152         break;
2153     case FIELD_PROP_BOOL1:
2154         if( *(sal_Bool*)rAny.getValue() )
2155             SetFormat(GetFormat() | AF_FIXED);
2156         else
2157             SetFormat(GetFormat() & ~AF_FIXED);
2158         break;
2159     default:
2160         DBG_ERROR("illegal property");
2161     }
2162     return sal_True;
2163 }
2164 //-------------------------------------------------------------------------
2165 
2166 /*--------------------------------------------------------------------
2167     Beschreibung: Relatives Seitennummern - Feld
2168  --------------------------------------------------------------------*/
2169 
SwRefPageSetFieldType()2170 SwRefPageSetFieldType::SwRefPageSetFieldType()
2171     : SwFieldType( RES_REFPAGESETFLD )
2172 {
2173 }
2174 /* ---------------------------------------------------------------------------
2175 
2176  ---------------------------------------------------------------------------*/
Copy() const2177 SwFieldType* SwRefPageSetFieldType::Copy() const
2178 {
2179     return new SwRefPageSetFieldType;
2180 }
2181 /* ---------------------------------------------------------------------------
2182 
2183  ---------------------------------------------------------------------------*/
2184 // ueberlagert, weil es nichts zum Updaten gibt!
Modify(const SfxPoolItem *,const SfxPoolItem *)2185 void SwRefPageSetFieldType::Modify( const SfxPoolItem*, const SfxPoolItem * )
2186 {
2187 }
2188 
2189 /*--------------------------------------------------------------------
2190     Beschreibung: Relative Seitennummerierung
2191  --------------------------------------------------------------------*/
2192 
SwRefPageSetField(SwRefPageSetFieldType * pTyp,short nOff,sal_Bool bFlag)2193 SwRefPageSetField::SwRefPageSetField( SwRefPageSetFieldType* pTyp,
2194                     short nOff, sal_Bool bFlag )
2195     : SwField( pTyp ), nOffset( nOff ), bOn( bFlag )
2196 {
2197 }
2198 /* ---------------------------------------------------------------------------
2199 
2200  ---------------------------------------------------------------------------*/
Expand() const2201 String SwRefPageSetField::Expand() const
2202 {
2203     return aEmptyStr;
2204 }
2205 /* ---------------------------------------------------------------------------
2206 
2207  ---------------------------------------------------------------------------*/
Copy() const2208 SwField* SwRefPageSetField::Copy() const
2209 {
2210     return new SwRefPageSetField( (SwRefPageSetFieldType*)GetTyp(), nOffset, bOn );
2211 }
2212 /* ---------------------------------------------------------------------------
2213 
2214  ---------------------------------------------------------------------------*/
GetPar2() const2215 String SwRefPageSetField::GetPar2() const
2216 {
2217     return String::CreateFromInt32( GetOffset() );
2218 }
2219 /* ---------------------------------------------------------------------------
2220 
2221  ---------------------------------------------------------------------------*/
SetPar2(const String & rStr)2222 void SwRefPageSetField::SetPar2(const String& rStr)
2223 {
2224     SetOffset( (short) rStr.ToInt32() );
2225 }
2226 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2227 sal_Bool SwRefPageSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2228 {
2229     switch( nWhichId )
2230     {
2231     case FIELD_PROP_BOOL1:
2232         rAny.setValue(&bOn, ::getBooleanCppuType());
2233         break;
2234     case FIELD_PROP_USHORT1:
2235         rAny <<= (sal_Int16)nOffset;
2236         break;
2237     default:
2238         DBG_ERROR("illegal property");
2239     }
2240     return sal_True;
2241 }
2242 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2243 sal_Bool SwRefPageSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2244 {
2245     switch( nWhichId )
2246     {
2247     case FIELD_PROP_BOOL1:
2248         bOn = *(sal_Bool*)rAny.getValue();
2249         break;
2250     case FIELD_PROP_USHORT1:
2251         rAny >>=nOffset;
2252         break;
2253     default:
2254         DBG_ERROR("illegal property");
2255     }
2256     return sal_True;
2257 }
2258 /*--------------------------------------------------------------------
2259     Beschreibung: relatives Seitennummern - Abfrage Feld
2260  --------------------------------------------------------------------*/
2261 
SwRefPageGetFieldType(SwDoc * pDc)2262 SwRefPageGetFieldType::SwRefPageGetFieldType( SwDoc* pDc )
2263     : SwFieldType( RES_REFPAGEGETFLD ), pDoc( pDc ), nNumberingType( SVX_NUM_ARABIC )
2264 {
2265 }
2266 /* ---------------------------------------------------------------------------
2267 
2268  ---------------------------------------------------------------------------*/
Copy() const2269 SwFieldType* SwRefPageGetFieldType::Copy() const
2270 {
2271     SwRefPageGetFieldType* pNew = new SwRefPageGetFieldType( pDoc );
2272     pNew->nNumberingType = nNumberingType;
2273     return pNew;
2274 }
2275 /* ---------------------------------------------------------------------------
2276 
2277  ---------------------------------------------------------------------------*/
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)2278 void SwRefPageGetFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
2279 {
2280     // Update auf alle GetReferenz-Felder
2281     if( !pNew && !pOld && GetDepends() )
2282     {
2283         // sammel erstmal alle SetPageRefFelder ein.
2284         _SetGetExpFlds aTmpLst( 10, 5 );
2285         if( MakeSetList( aTmpLst ) )
2286         {
2287             SwIterator<SwFmtFld,SwFieldType> aIter( *this );
2288             for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
2289                     // nur die GetRef-Felder Updaten
2290                     if( pFmtFld->GetTxtFld() )
2291                         UpdateField( pFmtFld->GetTxtFld(), aTmpLst );
2292         }
2293     }
2294 
2295     // weiter an die Text-Felder, diese "Expandieren" den Text
2296     NotifyClients( pOld, pNew );
2297 }
2298 /* ---------------------------------------------------------------------------
2299 
2300  ---------------------------------------------------------------------------*/
MakeSetList(_SetGetExpFlds & rTmpLst)2301 sal_uInt16 SwRefPageGetFieldType::MakeSetList( _SetGetExpFlds& rTmpLst )
2302 {
2303     SwIterator<SwFmtFld,SwFieldType> aIter(*pDoc->GetSysFldType( RES_REFPAGESETFLD));
2304     for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
2305     {
2306             // nur die GetRef-Felder Updaten
2307             const SwTxtFld* pTFld = pFmtFld->GetTxtFld();
2308             if( pTFld )
2309             {
2310                 const SwTxtNode& rTxtNd = pTFld->GetTxtNode();
2311 
2312                 // immer den ersten !! (in Tab-Headline, Kopf-/Fuss )
2313                 Point aPt;
2314                 const SwCntntFrm* pFrm = rTxtNd.getLayoutFrm( rTxtNd.GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2315 
2316                 _SetGetExpFld* pNew;
2317 
2318                 if( !pFrm ||
2319                      pFrm->IsInDocBody() ||
2320                     // --> FME 2004-07-27 #i31868#
2321                     // Check if pFrm is not yet connected to the layout.
2322                     !pFrm->FindPageFrm() )
2323                     // <--
2324                 {
2325                     // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2326                     SwNodeIndex aIdx( rTxtNd );
2327                     pNew = new _SetGetExpFld( aIdx, pTFld );
2328                 }
2329                 else
2330                 {
2331                     // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2332                     SwPosition aPos( pDoc->GetNodes().GetEndOfPostIts() );
2333 #ifdef DBG_UTIL
2334                     ASSERT( GetBodyTxtNode( *pDoc, aPos, *pFrm ),
2335                             "wo steht das Feld" );
2336 #else
2337                     GetBodyTxtNode( *pDoc, aPos, *pFrm );
2338 #endif
2339                     pNew = new _SetGetExpFld( aPos.nNode, pTFld,
2340                                                 &aPos.nContent );
2341                 }
2342 
2343                 if( !rTmpLst.Insert( pNew ))
2344                     delete pNew;
2345             }
2346     }
2347 
2348     return rTmpLst.Count();
2349 }
2350 /* ---------------------------------------------------------------------------
2351 
2352  ---------------------------------------------------------------------------*/
UpdateField(SwTxtFld * pTxtFld,_SetGetExpFlds & rSetList)2353 void SwRefPageGetFieldType::UpdateField( SwTxtFld* pTxtFld,
2354                                         _SetGetExpFlds& rSetList )
2355 {
2356     SwRefPageGetField* pGetFld = (SwRefPageGetField*)pTxtFld->GetFmtFld().GetField();
2357     pGetFld->SetText( aEmptyStr );
2358 
2359     // dann suche mal das richtige RefPageSet-Field
2360     SwTxtNode* pTxtNode = (SwTxtNode*)&pTxtFld->GetTxtNode();
2361     if( pTxtNode->StartOfSectionIndex() >
2362         pDoc->GetNodes().GetEndOfExtras().GetIndex() )
2363     {
2364         SwNodeIndex aIdx( *pTxtNode );
2365         _SetGetExpFld aEndFld( aIdx, pTxtFld );
2366 
2367         sal_uInt16 nLast;
2368         rSetList.Seek_Entry( &aEndFld, &nLast );
2369 
2370         if( nLast-- )
2371         {
2372             const SwTxtFld* pRefTxtFld = rSetList[ nLast ]->GetTxtFld();
2373             const SwRefPageSetField* pSetFld =
2374                         (SwRefPageSetField*)pRefTxtFld->GetFmtFld().GetField();
2375             if( pSetFld->IsOn() )
2376             {
2377                 // dann bestimme mal den entsp. Offset
2378                 Point aPt;
2379                 const SwCntntFrm* pFrm = pTxtNode->getLayoutFrm( pTxtNode->GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2380                 const SwCntntFrm* pRefFrm = pRefTxtFld->GetTxtNode().getLayoutFrm( pRefTxtFld->GetTxtNode().GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2381                 const SwPageFrm* pPgFrm = 0;
2382                 sal_uInt16 nDiff = ( pFrm && pRefFrm )
2383                         ?   (pPgFrm = pFrm->FindPageFrm())->GetPhyPageNum() -
2384                             pRefFrm->FindPageFrm()->GetPhyPageNum() + 1
2385                         : 1;
2386 
2387                 sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
2388                         ? ( !pPgFrm
2389                                 ? (sal_uInt32)SVX_NUM_ARABIC
2390                                 : pPgFrm->GetPageDesc()->GetNumType().GetNumberingType() )
2391                         : pGetFld->GetFormat();
2392                 short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff));
2393                 pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
2394             }
2395         }
2396     }
2397     // dann die Formatierung anstossen
2398     ((SwFmtFld&)pTxtFld->GetFmtFld()).ModifyNotification( 0, 0 );
2399 }
2400 
2401 /*--------------------------------------------------------------------
2402     Beschreibung: Relative Seitennummerierung Abfragen
2403  --------------------------------------------------------------------*/
2404 
SwRefPageGetField(SwRefPageGetFieldType * pTyp,sal_uInt32 nFmt)2405 SwRefPageGetField::SwRefPageGetField( SwRefPageGetFieldType* pTyp,
2406                                     sal_uInt32 nFmt )
2407     : SwField( pTyp, nFmt )
2408 {
2409 }
2410 /* ---------------------------------------------------------------------------
2411 
2412  ---------------------------------------------------------------------------*/
Expand() const2413 String SwRefPageGetField::Expand() const
2414 {
2415     return sTxt;
2416 }
2417 /* ---------------------------------------------------------------------------
2418 
2419  ---------------------------------------------------------------------------*/
Copy() const2420 SwField* SwRefPageGetField::Copy() const
2421 {
2422     SwRefPageGetField* pCpy = new SwRefPageGetField(
2423                         (SwRefPageGetFieldType*)GetTyp(), GetFormat() );
2424     pCpy->SetText( sTxt );
2425     return pCpy;
2426 }
2427 /* ---------------------------------------------------------------------------
2428 
2429  ---------------------------------------------------------------------------*/
ChangeExpansion(const SwFrm * pFrm,const SwTxtFld * pFld)2430 void SwRefPageGetField::ChangeExpansion( const SwFrm* pFrm,
2431                                         const SwTxtFld* pFld )
2432 {
2433     // nur Felder in Footer, Header, FootNote, Flys
2434     SwTxtNode* pTxtNode = (SwTxtNode*)&pFld->GetTxtNode();
2435     SwRefPageGetFieldType* pGetType = (SwRefPageGetFieldType*)GetTyp();
2436     SwDoc* pDoc = pGetType->GetDoc();
2437     if( pFld->GetTxtNode().StartOfSectionIndex() >
2438         pDoc->GetNodes().GetEndOfExtras().GetIndex() )
2439         return;
2440 
2441     sTxt.Erase();
2442 
2443     ASSERT( !pFrm->IsInDocBody(), "Flag ist nicht richtig, Frame steht im DocBody" );
2444 
2445     // sammel erstmal alle SetPageRefFelder ein.
2446     _SetGetExpFlds aTmpLst( 10, 5 );
2447     if( !pGetType->MakeSetList( aTmpLst ) )
2448         return ;
2449 
2450     // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2451     SwPosition aPos( SwNodeIndex( pDoc->GetNodes() ) );
2452     pTxtNode = (SwTxtNode*) GetBodyTxtNode( *pDoc, aPos, *pFrm );
2453 
2454     // Wenn kein Layout vorhanden, kommt es in Kopf und Fusszeilen dazu
2455     // das ChangeExpansion uebers Layout-Formatieren aufgerufen wird
2456     // aber kein TxtNode vorhanden ist
2457     //
2458     if(!pTxtNode)
2459         return;
2460 
2461     _SetGetExpFld aEndFld( aPos.nNode, pFld, &aPos.nContent );
2462 
2463     sal_uInt16 nLast;
2464     aTmpLst.Seek_Entry( &aEndFld, &nLast );
2465 
2466     if( !nLast-- )
2467         return ;        // es gibt kein entsprechendes Set - Feld vor mir
2468 
2469     const SwTxtFld* pRefTxtFld = aTmpLst[ nLast ]->GetTxtFld();
2470     const SwRefPageSetField* pSetFld =
2471                         (SwRefPageSetField*)pRefTxtFld->GetFmtFld().GetField();
2472     Point aPt;
2473     const SwCntntFrm* pRefFrm = pRefTxtFld ? pRefTxtFld->GetTxtNode().getLayoutFrm( pFrm->getRootFrm(), &aPt, 0, sal_False ) : 0;
2474     if( pSetFld->IsOn() && pRefFrm )
2475     {
2476         // dann bestimme mal den entsp. Offset
2477         const SwPageFrm* pPgFrm = pFrm->FindPageFrm();
2478         sal_uInt16 nDiff = pPgFrm->GetPhyPageNum() -
2479                             pRefFrm->FindPageFrm()->GetPhyPageNum() + 1;
2480 
2481         SwRefPageGetField* pGetFld = (SwRefPageGetField*)pFld->GetFmtFld().GetField();
2482         sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
2483                             ? pPgFrm->GetPageDesc()->GetNumType().GetNumberingType()
2484                             : pGetFld->GetFormat();
2485         short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff ));
2486         pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
2487     }
2488 }
2489 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2490 sal_Bool SwRefPageGetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2491 {
2492     switch( nWhichId )
2493     {
2494         case FIELD_PROP_USHORT1:
2495             rAny <<= (sal_Int16)GetFormat();
2496         break;
2497         case FIELD_PROP_PAR1:
2498             rAny <<= OUString(sTxt);
2499         break;
2500         default:
2501             DBG_ERROR("illegal property");
2502     }
2503     return sal_True;
2504 }
2505 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2506 sal_Bool SwRefPageGetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2507 {
2508     switch( nWhichId )
2509     {
2510         case FIELD_PROP_USHORT1:
2511         {
2512             sal_Int16 nSet = 0;
2513             rAny >>= nSet;
2514             if(nSet <= SVX_NUM_PAGEDESC )
2515                 SetFormat(nSet);
2516             else {
2517                 //exception(wrong_value)
2518                 ;
2519             }
2520         }
2521         break;
2522         case FIELD_PROP_PAR1:
2523         {
2524             OUString sTmp;
2525             rAny >>= sTmp;
2526             sTxt = sTmp;
2527         }
2528         break;
2529     default:
2530         DBG_ERROR("illegal property");
2531     }
2532     return sal_True;
2533 }
2534 
2535 /*--------------------------------------------------------------------
2536     Beschreibung: Feld zum Anspringen und Editieren
2537  --------------------------------------------------------------------*/
2538 
SwJumpEditFieldType(SwDoc * pD)2539 SwJumpEditFieldType::SwJumpEditFieldType( SwDoc* pD )
2540     : SwFieldType( RES_JUMPEDITFLD ), pDoc( pD ), aDep( this, 0 )
2541 {
2542 }
2543 /* ---------------------------------------------------------------------------
2544 
2545  ---------------------------------------------------------------------------*/
Copy() const2546 SwFieldType* SwJumpEditFieldType::Copy() const
2547 {
2548     return new SwJumpEditFieldType( pDoc );
2549 }
2550 /* ---------------------------------------------------------------------------
2551 
2552  ---------------------------------------------------------------------------*/
GetCharFmt()2553 SwCharFmt* SwJumpEditFieldType::GetCharFmt()
2554 {
2555     SwCharFmt* pFmt = pDoc->GetCharFmtFromPool( RES_POOLCHR_JUMPEDIT );
2556 
2557     // noch nicht registriert ?
2558     if( !aDep.GetRegisteredIn() )
2559         pFmt->Add( &aDep );     // anmelden
2560 
2561     return pFmt;
2562 }
2563 /* ---------------------------------------------------------------------------
2564 
2565  ---------------------------------------------------------------------------*/
SwJumpEditField(SwJumpEditFieldType * pTyp,sal_uInt32 nForm,const String & rTxt,const String & rHelp)2566 SwJumpEditField::SwJumpEditField( SwJumpEditFieldType* pTyp, sal_uInt32 nForm,
2567                                 const String& rTxt, const String& rHelp )
2568     : SwField( pTyp, nForm ), sTxt( rTxt ), sHelp( rHelp )
2569 {
2570 }
2571 /* ---------------------------------------------------------------------------
2572 
2573  ---------------------------------------------------------------------------*/
Expand() const2574 String SwJumpEditField::Expand() const
2575 {
2576     String sTmp( '<' );
2577     sTmp += sTxt;
2578     return sTmp += '>';
2579 }
2580 /* ---------------------------------------------------------------------------
2581 
2582  ---------------------------------------------------------------------------*/
Copy() const2583 SwField* SwJumpEditField::Copy() const
2584 {
2585     return new SwJumpEditField( (SwJumpEditFieldType*)GetTyp(), GetFormat(),
2586                                 sTxt, sHelp );
2587 }
2588 /* ---------------------------------------------------------------------------
2589 
2590  ---------------------------------------------------------------------------*/
2591 // Platzhalter-Text
2592 
GetPar1() const2593 const String& SwJumpEditField::GetPar1() const
2594 {
2595     return sTxt;
2596 }
2597 /* ---------------------------------------------------------------------------
2598 
2599  ---------------------------------------------------------------------------*/
SetPar1(const String & rStr)2600 void SwJumpEditField::SetPar1(const String& rStr)
2601 {
2602     sTxt = rStr;
2603 }
2604 
2605 // HinweisText
2606 /* ---------------------------------------------------------------------------
2607 
2608  ---------------------------------------------------------------------------*/
GetPar2() const2609 String SwJumpEditField::GetPar2() const
2610 {
2611     return sHelp;
2612 }
2613 /* ---------------------------------------------------------------------------
2614 
2615  ---------------------------------------------------------------------------*/
SetPar2(const String & rStr)2616 void SwJumpEditField::SetPar2(const String& rStr)
2617 {
2618     sHelp = rStr;
2619 }
2620 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2621 sal_Bool SwJumpEditField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2622 {
2623     switch( nWhichId )
2624     {
2625     case FIELD_PROP_USHORT1:
2626         {
2627             sal_Int16 nRet;
2628             switch( GetFormat() )
2629             {
2630             case JE_FMT_TABLE:  nRet = text::PlaceholderType::TABLE; break;
2631             case JE_FMT_FRAME:  nRet = text::PlaceholderType::TEXTFRAME; break;
2632             case JE_FMT_GRAPHIC:nRet = text::PlaceholderType::GRAPHIC; break;
2633             case JE_FMT_OLE:    nRet = text::PlaceholderType::OBJECT; break;
2634 //          case JE_FMT_TEXT:
2635             default:
2636                 nRet = text::PlaceholderType::TEXT; break;
2637             }
2638             rAny <<= nRet;
2639         }
2640         break;
2641     case FIELD_PROP_PAR1 :
2642         rAny <<= OUString(sHelp);
2643         break;
2644     case FIELD_PROP_PAR2 :
2645          rAny <<= OUString(sTxt);
2646          break;
2647     default:
2648         DBG_ERROR("illegal property");
2649     }
2650     return sal_True;
2651 }
2652 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2653 sal_Bool SwJumpEditField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2654 {
2655     switch( nWhichId )
2656     {
2657     case FIELD_PROP_USHORT1:
2658         {
2659             //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
2660             //              called with a int32 value! But normally we need
2661             //              here only a int16
2662             sal_Int32 nSet = 0;
2663             rAny >>= nSet;
2664             switch( nSet )
2665             {
2666                 case text::PlaceholderType::TEXT     : SetFormat(JE_FMT_TEXT); break;
2667                 case text::PlaceholderType::TABLE    : SetFormat(JE_FMT_TABLE); break;
2668                 case text::PlaceholderType::TEXTFRAME: SetFormat(JE_FMT_FRAME); break;
2669                 case text::PlaceholderType::GRAPHIC  : SetFormat(JE_FMT_GRAPHIC); break;
2670                 case text::PlaceholderType::OBJECT   : SetFormat(JE_FMT_OLE); break;
2671             }
2672         }
2673         break;
2674     case FIELD_PROP_PAR1 :
2675         ::GetString( rAny, sHelp );
2676         break;
2677     case FIELD_PROP_PAR2 :
2678          ::GetString( rAny, sTxt);
2679          break;
2680     default:
2681         DBG_ERROR("illegal property");
2682     }
2683     return sal_True;
2684 }
2685 
2686 
2687 /*--------------------------------------------------------------------
2688     Beschreibung: Combined Character Fieldtype / Field
2689  --------------------------------------------------------------------*/
2690 
SwCombinedCharFieldType()2691 SwCombinedCharFieldType::SwCombinedCharFieldType()
2692     : SwFieldType( RES_COMBINED_CHARS )
2693 {
2694 }
2695 
Copy() const2696 SwFieldType* SwCombinedCharFieldType::Copy() const
2697 {
2698     return new SwCombinedCharFieldType;
2699 }
2700 
2701 /* --------------------------------------------------------------------*/
2702 
SwCombinedCharField(SwCombinedCharFieldType * pFTyp,const String & rChars)2703 SwCombinedCharField::SwCombinedCharField( SwCombinedCharFieldType* pFTyp,
2704                                             const String& rChars )
2705     : SwField( pFTyp, 0 ),
2706     sCharacters( rChars.Copy( 0, MAX_COMBINED_CHARACTERS ))
2707 {
2708 }
2709 
Expand() const2710 String  SwCombinedCharField::Expand() const
2711 {
2712     return sCharacters;
2713 }
2714 
Copy() const2715 SwField* SwCombinedCharField::Copy() const
2716 {
2717     return new SwCombinedCharField( (SwCombinedCharFieldType*)GetTyp(),
2718                                         sCharacters );
2719 }
2720 
GetPar1() const2721 const String& SwCombinedCharField::GetPar1() const
2722 {
2723     return sCharacters;
2724 }
2725 
SetPar1(const String & rStr)2726 void SwCombinedCharField::SetPar1(const String& rStr)
2727 {
2728     sCharacters = rStr.Copy( 0, MAX_COMBINED_CHARACTERS );
2729 }
2730 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2731 sal_Bool SwCombinedCharField::QueryValue( uno::Any& rAny,
2732                                         sal_uInt16 nWhichId ) const
2733 {
2734     switch( nWhichId )
2735     {
2736     case FIELD_PROP_PAR1:
2737         rAny <<= rtl::OUString( sCharacters );
2738         break;
2739     default:
2740         DBG_ERROR("illegal property");
2741     }
2742     return sal_True;
2743 }
2744 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2745 sal_Bool SwCombinedCharField::PutValue( const uno::Any& rAny,
2746                                         sal_uInt16 nWhichId )
2747 {
2748     switch( nWhichId )
2749     {
2750     case FIELD_PROP_PAR1:
2751         ::GetString( rAny, sCharacters ).Erase( MAX_COMBINED_CHARACTERS );
2752         break;
2753     default:
2754         DBG_ERROR("illegal property");
2755     }
2756     return sal_True;
2757 }
2758 
2759