Update ooo320-m1
[ooovba.git] / sw / source / core / fields / docufld.cxx
blobd5204f1c1d54a263d6d500ee05ebd9d79e3ac867
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docufld.cxx,v $
10 * $Revision: 1.51.16.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <textapi.hxx>
36 #include <tools/pstm.hxx>
37 #include <hintids.hxx>
38 #include <com/sun/star/text/XText.hpp>
39 #include <com/sun/star/script/XTypeConverter.hpp>
40 #include <com/sun/star/text/SetVariableType.hpp>
41 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
42 #include <com/sun/star/text/UserDataPart.hpp>
43 #include <com/sun/star/text/ChapterFormat.hpp>
44 #include <com/sun/star/text/XTextField.hpp>
45 #include <com/sun/star/text/PlaceholderType.hpp>
46 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
47 #include <com/sun/star/text/UserFieldFormat.hpp>
48 #include <com/sun/star/text/PageNumberType.hpp>
49 #include <com/sun/star/text/ReferenceFieldPart.hpp>
50 #ifndef _COM_SUN_STAR_TEXT_FilenameDisplayFormat_HPP_
51 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
52 #endif
53 #include <com/sun/star/text/XDependentTextField.hpp>
54 #include <com/sun/star/text/DocumentStatistic.hpp>
55 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
56 #include <com/sun/star/document/XDocumentProperties.hpp>
57 #include <com/sun/star/util/Date.hpp>
58 #include <unotools/localedatawrapper.hxx>
59 #include <svx/unolingu.hxx>
60 #include <comphelper/processfactory.hxx>
61 #include <comphelper/types.hxx>
62 #include <comphelper/string.hxx>
63 #include <tools/urlobj.hxx>
64 #ifndef _APP_HXX //autogen
65 #include <vcl/svapp.hxx>
66 #endif
67 #include <svtools/urihelper.hxx>
68 #include <svtools/useroptions.hxx>
69 #include <svtools/syslocale.hxx>
71 #include <tools/time.hxx>
72 #include <tools/datetime.hxx>
74 #include <com/sun/star/beans/PropertyAttribute.hpp>
76 #include <tools/shl.hxx>
77 #include <swmodule.hxx>
78 #include <sfx2/app.hxx>
79 #include <sfx2/docfile.hxx>
80 #include <sfx2/doctempl.hxx>
81 #include <fmtfld.hxx>
82 #include <txtfld.hxx>
83 #include <charfmt.hxx>
84 #include <docstat.hxx>
85 #include <pagedesc.hxx>
86 #include <fmtpdsc.hxx>
87 #include <doc.hxx>
88 #include <rootfrm.hxx> // AuthorField
89 #include <pagefrm.hxx> //
90 #include <cntfrm.hxx> //
91 #include <pam.hxx>
92 #include <viewsh.hxx>
93 #ifndef _DBMGR_HXX
94 #include <dbmgr.hxx>
95 #endif
96 #include <shellres.hxx>
97 #include <docufld.hxx>
98 #include <flddat.hxx>
99 #include <docfld.hxx>
100 #include <ndtxt.hxx>
101 #include <expfld.hxx>
102 #include <poolfmt.hxx>
103 #ifndef _DOCSH_HXX
104 #include <docsh.hxx>
105 #endif
106 #ifndef _UNOFLDMID_H
107 #include <unofldmid.h>
108 #endif
109 #include <swunohelper.hxx>
110 #ifndef _COMCORE_HRC
111 #include <comcore.hrc>
112 #endif
114 #include <svx/outliner.hxx>
115 #include <svx/outlobj.hxx>
117 #define URL_DECODE INetURLObject::DECODE_UNAMBIGUOUS
119 using ::rtl::OUString;
120 using namespace ::com::sun::star;
121 using namespace ::com::sun::star::uno;
122 using namespace nsSwDocInfoSubType;
124 /*--------------------------------------------------------------------
125 Beschreibung: SwPageNumberFieldType
126 --------------------------------------------------------------------*/
128 SwPageNumberFieldType::SwPageNumberFieldType()
129 : SwFieldType( RES_PAGENUMBERFLD ),
130 nNumberingType( SVX_NUM_ARABIC ),
131 nNum( 0 ),
132 nMax( USHRT_MAX ),
133 bVirtuell( sal_False )
137 String& SwPageNumberFieldType::Expand( sal_uInt32 nFmt, short nOff,
138 const String& rUserStr, String& rRet ) const
140 sal_uInt32 nTmpFmt = (SVX_NUM_PAGEDESC == nFmt) ? (sal_uInt32)nNumberingType : nFmt;
141 long nTmp = nNum + nOff;
143 if( 0 >= nTmp || SVX_NUM_NUMBER_NONE == nTmpFmt || (!bVirtuell && nTmp > nMax) )
144 rRet = aEmptyStr;
145 else if( SVX_NUM_CHAR_SPECIAL == nTmpFmt )
146 rRet = rUserStr;
147 else
148 rRet = FormatNumber( (sal_uInt16)nTmp, nTmpFmt );
149 return rRet;
152 SwFieldType* SwPageNumberFieldType::Copy() const
154 SwPageNumberFieldType *pTmp = new SwPageNumberFieldType();
156 pTmp->nNum = nNum;
157 pTmp->nMax = nMax;
158 pTmp->nNumberingType = nNumberingType;
159 pTmp->bVirtuell = bVirtuell;
161 return pTmp;
164 /*--------------------------------------------------------------------
165 Beschreibung: Verschiedene Expandierung
166 --------------------------------------------------------------------*/
168 void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc, sal_uInt16 nPage,
169 sal_uInt16 nNumPages, sal_Bool bVirt,
170 const sal_Int16* pNumFmt )
172 nNum = nPage;
173 nMax = nNumPages;
174 if( pNumFmt )
175 nNumberingType = *pNumFmt;
177 bVirtuell = sal_False;
178 if( bVirt )
180 // dann muss das Flag ueberprueft werden, denn das Layout setzt
181 // es NIE zurueck
182 const SfxItemPool &rPool = pDoc->GetAttrPool();
183 const SwFmtPageDesc *pDesc;
184 sal_uInt16 nMaxItems = rPool.GetItemCount( RES_PAGEDESC );
185 for( sal_uInt16 n = 0; n < nMaxItems; ++n )
186 if( 0 != (pDesc = (SwFmtPageDesc*)rPool.GetItem( RES_PAGEDESC, n ) )
187 && pDesc->GetNumOffset() && pDesc->GetDefinedIn() )
189 if( pDesc->GetDefinedIn()->ISA( SwCntntNode ))
191 SwClientIter aIter( *(SwModify*)pDesc->GetDefinedIn() );
192 if( aIter.First( TYPE( SwFrm ) ) )
194 bVirtuell = sal_True;
195 break;
198 else if( pDesc->GetDefinedIn()->ISA( SwFmt ))
200 SwAutoFmtGetDocNode aGetHt( &pDoc->GetNodes() );
201 bVirtuell = !pDesc->GetDefinedIn()->GetInfo( aGetHt );
202 break;
208 /*--------------------------------------------------------------------
209 Beschreibung: SwPageNumberField
210 --------------------------------------------------------------------*/
212 SwPageNumberField::SwPageNumberField(SwPageNumberFieldType* pTyp,
213 sal_uInt16 nSub, sal_uInt32 nFmt, short nOff)
214 : SwField(pTyp, nFmt), nSubType(nSub), nOffset(nOff)
218 String SwPageNumberField::Expand() const
220 String sRet;
221 SwPageNumberFieldType* pFldType = (SwPageNumberFieldType*)GetTyp();
223 if( PG_NEXT == nSubType && 1 != nOffset )
225 if( pFldType->Expand( GetFormat(), 1, sUserStr, sRet ).Len() )
226 pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
228 else if( PG_PREV == nSubType && -1 != nOffset )
230 if( pFldType->Expand( GetFormat(), -1, sUserStr, sRet ).Len() )
231 pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
233 else
234 pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
235 return sRet;
238 SwField* SwPageNumberField::Copy() const
240 SwPageNumberField *pTmp =
241 new SwPageNumberField((SwPageNumberFieldType*)GetTyp(), nSubType, GetFormat(), nOffset);
242 pTmp->SetLanguage( GetLanguage() );
243 pTmp->SetUserString( sUserStr );
244 return pTmp;
247 String SwPageNumberField::GetPar2() const
249 return String::CreateFromInt32(nOffset);
252 void SwPageNumberField::SetPar2(const String& rStr)
254 nOffset = (short)rStr.ToInt32();
257 sal_uInt16 SwPageNumberField::GetSubType() const
259 return nSubType;
262 /*-----------------05.03.98 10:25-------------------
264 --------------------------------------------------*/
265 BOOL SwPageNumberField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
267 switch( nWhichId )
269 case FIELD_PROP_FORMAT:
270 rAny <<= (sal_Int16)GetFormat();
271 break;
272 case FIELD_PROP_USHORT1:
273 rAny <<= nOffset;
274 break;
275 case FIELD_PROP_SUBTYPE:
277 text::PageNumberType eType;
278 eType = text::PageNumberType_CURRENT;
279 if(nSubType == PG_PREV)
280 eType = text::PageNumberType_PREV;
281 else if(nSubType == PG_NEXT)
282 eType = text::PageNumberType_NEXT;
283 rAny.setValue(&eType, ::getCppuType((const text::PageNumberType*)0));
285 break;
286 case FIELD_PROP_PAR1:
287 rAny <<= OUString(sUserStr);
288 break;
290 default:
291 DBG_ERROR("illegal property");
293 return sal_True;
295 /*-----------------05.03.98 10:25-------------------
297 --------------------------------------------------*/
298 BOOL SwPageNumberField::PutValue( const uno::Any& rAny, USHORT nWhichId )
300 BOOL bRet = TRUE;
301 sal_Int16 nSet = 0;
302 switch( nWhichId )
304 case FIELD_PROP_FORMAT:
305 rAny >>= nSet;
307 // TODO: woher kommen die defines?
308 if(nSet <= SVX_NUM_PAGEDESC )
309 SetFormat(nSet);
310 else {
311 //exception(wrong_value)
314 break;
315 case FIELD_PROP_USHORT1:
316 rAny >>= nSet;
317 nOffset = nSet;
318 break;
319 case FIELD_PROP_SUBTYPE:
320 switch( SWUnoHelper::GetEnumAsInt32( rAny ) )
322 case text::PageNumberType_CURRENT:
323 nSubType = PG_RANDOM;
324 break;
325 case text::PageNumberType_PREV:
326 nSubType = PG_PREV;
327 break;
328 case text::PageNumberType_NEXT:
329 nSubType = PG_NEXT;
330 break;
331 default:
332 bRet = FALSE;
334 break;
335 case FIELD_PROP_PAR1:
336 ::GetString( rAny, sUserStr );
337 break;
339 default:
340 DBG_ERROR("illegal property");
342 return bRet;
344 /*--------------------------------------------------------------------
345 Beschreibung: SwAuthorFieldType
346 --------------------------------------------------------------------*/
348 SwAuthorFieldType::SwAuthorFieldType()
349 : SwFieldType( RES_AUTHORFLD )
353 String SwAuthorFieldType::Expand(ULONG nFmt) const
355 String sRet;
356 SvtUserOptions& rOpt = SW_MOD()->GetUserOptions();
357 if((nFmt & 0xff) == AF_NAME)
358 sRet = rOpt.GetFullName();
359 else
360 sRet = rOpt.GetID();
361 return sRet;
364 SwFieldType* SwAuthorFieldType::Copy() const
366 return new SwAuthorFieldType;
369 /*--------------------------------------------------------------------
370 Beschreibung: SwAuthorField
371 --------------------------------------------------------------------*/
373 SwAuthorField::SwAuthorField(SwAuthorFieldType* pTyp, sal_uInt32 nFmt)
374 : SwField(pTyp, nFmt)
376 aContent = ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
379 String SwAuthorField::Expand() const
381 if (!IsFixed())
382 ((SwAuthorField*)this)->aContent =
383 ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
385 return aContent;
388 SwField* SwAuthorField::Copy() const
390 SwAuthorField *pTmp = new SwAuthorField( (SwAuthorFieldType*)GetTyp(),
391 GetFormat());
392 pTmp->SetExpansion(aContent);
393 return pTmp;
396 /*-----------------05.03.98 11:15-------------------
398 --------------------------------------------------*/
399 BOOL SwAuthorField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
401 sal_Bool bVal;
402 switch( nWhichId )
404 case FIELD_PROP_BOOL1:
405 bVal = (GetFormat() & 0xff) == AF_NAME;
406 rAny.setValue(&bVal, ::getBooleanCppuType());
407 break;
409 case FIELD_PROP_BOOL2:
410 bVal = IsFixed();
411 rAny.setValue(&bVal, ::getBooleanCppuType());
412 break;
414 case FIELD_PROP_PAR1:
415 rAny <<= rtl::OUString(GetContent());
416 break;
418 default:
419 DBG_ERROR("illegal property");
421 return sal_True;
423 /*-----------------05.03.98 11:15-------------------
425 --------------------------------------------------*/
426 BOOL SwAuthorField::PutValue( const uno::Any& rAny, USHORT nWhichId )
428 switch( nWhichId )
430 case FIELD_PROP_BOOL1:
431 SetFormat( *(sal_Bool*)rAny.getValue() ? AF_NAME : AF_SHORTCUT );
432 break;
434 case FIELD_PROP_BOOL2:
435 if( *(sal_Bool*)rAny.getValue() )
436 SetFormat( GetFormat() | AF_FIXED);
437 else
438 SetFormat( GetFormat() & ~AF_FIXED);
439 break;
441 case FIELD_PROP_PAR1:
442 ::GetString( rAny, aContent );
443 break;
445 default:
446 DBG_ERROR("illegal property");
448 return sal_True;
451 /*--------------------------------------------------------------------
452 Beschreibung: SwFileNameFieldType
453 --------------------------------------------------------------------*/
455 SwFileNameFieldType::SwFileNameFieldType(SwDoc *pDocument)
456 : SwFieldType( RES_FILENAMEFLD )
458 pDoc = pDocument;
461 String SwFileNameFieldType::Expand(ULONG nFmt) const
463 String aRet;
464 const SwDocShell* pDShell = pDoc->GetDocShell();
465 if( pDShell && pDShell->HasName() )
467 const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
468 switch( nFmt & ~FF_FIXED )
470 case FF_PATH:
472 if( INET_PROT_FILE == rURLObj.GetProtocol() )
474 INetURLObject aTemp(rURLObj);
475 aTemp.removeSegment();
476 // #101947# last slash should belong to the pathname
477 aRet = aTemp.PathToFileName();//GetFull();
479 else
481 aRet = URIHelper::removePassword(
482 rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
483 INetURLObject::WAS_ENCODED, URL_DECODE );
484 aRet.Erase( aRet.Search( String(rURLObj.GetLastName(
485 URL_DECODE )) ) );
488 break;
490 case FF_NAME:
491 aRet = rURLObj.GetLastName( URL_DECODE );
492 break;
494 case FF_NAME_NOEXT:
495 aRet = rURLObj.GetBase();
496 break;
498 default:
499 if( INET_PROT_FILE == rURLObj.GetProtocol() )
500 aRet = rURLObj.GetFull();
501 else
502 aRet = URIHelper::removePassword(
503 rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
504 INetURLObject::WAS_ENCODED, URL_DECODE );
507 return aRet;
510 SwFieldType* SwFileNameFieldType::Copy() const
512 SwFieldType *pTmp = new SwFileNameFieldType(pDoc);
513 return pTmp;
515 /*--------------------------------------------------------------------
516 Beschreibung: SwFileNameField
517 --------------------------------------------------------------------*/
519 SwFileNameField::SwFileNameField(SwFileNameFieldType* pTyp, sal_uInt32 nFmt)
520 : SwField(pTyp, nFmt)
522 aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
525 String SwFileNameField::Expand() const
527 if (!IsFixed())
528 ((SwFileNameField*)this)->aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
530 return aContent;
533 SwField* SwFileNameField::Copy() const
535 SwFileNameField *pTmp =
536 new SwFileNameField((SwFileNameFieldType*)GetTyp(), GetFormat());
537 pTmp->SetExpansion(aContent);
539 return pTmp;
542 /*-----------------05.03.98 08:59-------------------
544 --------------------------------------------------*/
545 BOOL SwFileNameField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
547 switch( nWhichId )
549 case FIELD_PROP_FORMAT:
551 sal_Int16 nRet;
552 switch( GetFormat() &(~FF_FIXED) )
554 case FF_PATH:
555 nRet = text::FilenameDisplayFormat::PATH;
556 break;
557 case FF_NAME_NOEXT:
558 nRet = text::FilenameDisplayFormat::NAME;
559 break;
560 case FF_NAME:
561 nRet = text::FilenameDisplayFormat::NAME_AND_EXT;
562 break;
563 default: nRet = text::FilenameDisplayFormat::FULL;
565 rAny <<= nRet;
567 break;
569 case FIELD_PROP_BOOL2:
571 BOOL bVal = IsFixed();
572 rAny.setValue(&bVal, ::getBooleanCppuType());
574 break;
576 case FIELD_PROP_PAR3:
577 rAny <<= OUString(GetContent());
578 break;
579 default:
580 DBG_ERROR("illegal property");
582 return sal_True;
584 /*-----------------05.03.98 09:01-------------------
586 --------------------------------------------------*/
587 BOOL SwFileNameField::PutValue( const uno::Any& rAny, USHORT nWhichId )
589 switch( nWhichId )
591 case FIELD_PROP_FORMAT:
593 //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
594 // called with a int32 value! But normally we need
595 // here only a int16
596 sal_Int32 nType = 0;
597 rAny >>= nType;
598 BOOL bFixed = IsFixed();
599 switch( nType )
601 case text::FilenameDisplayFormat::PATH:
602 nType = FF_PATH;
603 break;
604 case text::FilenameDisplayFormat::NAME:
605 nType = FF_NAME_NOEXT;
606 break;
607 case text::FilenameDisplayFormat::NAME_AND_EXT:
608 nType = FF_NAME;
609 break;
610 default: nType = FF_PATHNAME;
612 if(bFixed)
613 nType |= FF_FIXED;
614 SetFormat(nType);
616 break;
618 case FIELD_PROP_BOOL2:
619 if( *(sal_Bool*)rAny.getValue() )
620 SetFormat( GetFormat() | FF_FIXED);
621 else
622 SetFormat( GetFormat() & ~FF_FIXED);
623 break;
625 case FIELD_PROP_PAR3:
626 ::GetString( rAny, aContent );
627 break;
629 default:
630 DBG_ERROR("illegal property");
632 return sal_True;
634 /*--------------------------------------------------------------------
635 Beschreibung: SwTemplNameFieldType
636 --------------------------------------------------------------------*/
638 SwTemplNameFieldType::SwTemplNameFieldType(SwDoc *pDocument)
639 : SwFieldType( RES_TEMPLNAMEFLD )
641 pDoc = pDocument;
644 String SwTemplNameFieldType::Expand(ULONG nFmt) const
646 ASSERT( nFmt < FF_END, "Expand: kein guelt. Fmt!" );
648 String aRet;
649 SwDocShell *pDocShell(pDoc->GetDocShell());
650 DBG_ASSERT(pDocShell, "no SwDocShell");
651 if (pDocShell) {
652 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
653 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
654 uno::Reference<document::XDocumentProperties> xDocProps(
655 xDPS->getDocumentProperties());
656 DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
658 if( FF_UI_NAME == nFmt )
659 aRet = xDocProps->getTemplateName();
660 else if( !xDocProps->getTemplateURL().equalsAscii("") )
662 if( FF_UI_RANGE == nFmt )
664 // fuers besorgen vom RegionNamen !!
665 SfxDocumentTemplates aFac;
666 aFac.Construct();
667 String sTmp;
668 aFac.GetLogicNames( xDocProps->getTemplateURL(), aRet, sTmp );
670 else
672 INetURLObject aPathName( xDocProps->getTemplateURL() );
673 if( FF_NAME == nFmt )
674 aRet = aPathName.GetName(URL_DECODE);
675 else if( FF_NAME_NOEXT == nFmt )
676 aRet = aPathName.GetBase();
677 else
679 if( FF_PATH == nFmt )
681 aPathName.removeSegment();
682 aRet = aPathName.GetFull();
684 else
685 aRet = aPathName.GetFull();
690 return aRet;
693 SwFieldType* SwTemplNameFieldType::Copy() const
695 SwFieldType *pTmp = new SwTemplNameFieldType(pDoc);
696 return pTmp;
698 /*--------------------------------------------------------------------
699 Beschreibung: SwTemplNameField
700 --------------------------------------------------------------------*/
702 SwTemplNameField::SwTemplNameField(SwTemplNameFieldType* pTyp, sal_uInt32 nFmt)
703 : SwField(pTyp, nFmt)
706 String SwTemplNameField::Expand() const
708 return((SwTemplNameFieldType*)GetTyp())->Expand(GetFormat());
711 SwField* SwTemplNameField::Copy() const
713 SwTemplNameField *pTmp =
714 new SwTemplNameField((SwTemplNameFieldType*)GetTyp(), GetFormat());
715 return pTmp;
718 /*-----------------05.03.98 08:59-------------------
720 --------------------------------------------------*/
721 BOOL SwTemplNameField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
723 switch ( nWhichId )
725 case FIELD_PROP_FORMAT:
727 sal_Int16 nRet;
728 switch( GetFormat() )
730 case FF_PATH: nRet = text::FilenameDisplayFormat::PATH; break;
731 case FF_NAME_NOEXT: nRet = text::FilenameDisplayFormat::NAME; break;
732 case FF_NAME: nRet = text::FilenameDisplayFormat::NAME_AND_EXT; break;
733 case FF_UI_RANGE: nRet = text::TemplateDisplayFormat::AREA; break;
734 case FF_UI_NAME: nRet = text::TemplateDisplayFormat::TITLE; break;
735 default: nRet = text::FilenameDisplayFormat::FULL;
738 rAny <<= nRet;
740 break;
741 default:
742 DBG_ERROR("illegal property");
744 return sal_True;
746 /*-----------------05.03.98 09:01-------------------
748 --------------------------------------------------*/
749 BOOL SwTemplNameField::PutValue( const uno::Any& rAny, USHORT nWhichId )
751 switch ( nWhichId )
753 case FIELD_PROP_FORMAT:
755 //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
756 // called with a int32 value! But normally we need
757 // here only a int16
758 sal_Int32 nType = 0;
759 rAny >>= nType;
760 switch( nType )
762 case text::FilenameDisplayFormat::PATH:
763 SetFormat(FF_PATH);
764 break;
765 case text::FilenameDisplayFormat::NAME:
766 SetFormat(FF_NAME_NOEXT);
767 break;
768 case text::FilenameDisplayFormat::NAME_AND_EXT:
769 SetFormat(FF_NAME);
770 break;
771 case text::TemplateDisplayFormat::AREA :
772 SetFormat(FF_UI_RANGE);
773 break;
774 case text::TemplateDisplayFormat::TITLE :
775 SetFormat(FF_UI_NAME);
776 break;
777 default: SetFormat(FF_PATHNAME);
780 break;
781 default:
782 DBG_ERROR("illegal property");
784 return sal_True;
786 /*--------------------------------------------------------------------
787 Beschreibung: SwDocStatFieldType
788 --------------------------------------------------------------------*/
790 SwDocStatFieldType::SwDocStatFieldType(SwDoc* pDocument)
791 : SwFieldType( RES_DOCSTATFLD ), nNumberingType( SVX_NUM_ARABIC )
793 pDoc = pDocument;
796 String SwDocStatFieldType::Expand(sal_uInt16 nSubType, sal_uInt32 nFmt) const
798 sal_uInt32 nVal = 0;
799 const SwDocStat& rDStat = pDoc->GetDocStat();
800 switch( nSubType )
802 case DS_TBL: nVal = rDStat.nTbl; break;
803 case DS_GRF: nVal = rDStat.nGrf; break;
804 case DS_OLE: nVal = rDStat.nOLE; break;
805 case DS_PARA: nVal = rDStat.nPara; break;
806 case DS_WORD: nVal = rDStat.nWord; break;
807 case DS_CHAR: nVal = rDStat.nChar; break;
808 case DS_PAGE:
809 if( pDoc->GetRootFrm() )
810 ((SwDocStat &)rDStat).nPage = pDoc->GetRootFrm()->GetPageNum();
811 nVal = rDStat.nPage;
812 if( SVX_NUM_PAGEDESC == nFmt )
813 nFmt = (sal_uInt32)nNumberingType;
814 break;
815 default:
816 ASSERT( sal_False, "SwDocStatFieldType::Expand: unbekannter SubType" );
819 String sRet;
820 if( nVal <= SHRT_MAX )
821 sRet = FormatNumber( (sal_uInt16)nVal, nFmt );
822 else
823 sRet = String::CreateFromInt32( nVal );
824 return sRet;
827 SwFieldType* SwDocStatFieldType::Copy() const
829 SwDocStatFieldType *pTmp = new SwDocStatFieldType(pDoc);
830 return pTmp;
833 /*--------------------------------------------------------------------
834 Beschreibung: SwDocStatFieldType
835 Aus historischen Gruenden steht in nFormat der
836 SubType
837 --------------------------------------------------------------------*/
839 SwDocStatField::SwDocStatField(SwDocStatFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFmt)
840 : SwField(pTyp, nFmt),
841 nSubType(nSub)
844 String SwDocStatField::Expand() const
846 return((SwDocStatFieldType*)GetTyp())->Expand(nSubType, GetFormat());
849 SwField* SwDocStatField::Copy() const
851 SwDocStatField *pTmp = new SwDocStatField(
852 (SwDocStatFieldType*)GetTyp(), nSubType, GetFormat() );
853 return pTmp;
856 sal_uInt16 SwDocStatField::GetSubType() const
858 return nSubType;
861 void SwDocStatField::SetSubType(sal_uInt16 nSub)
863 nSubType = nSub;
866 void SwDocStatField::ChangeExpansion( const SwFrm* pFrm )
868 if( DS_PAGE == nSubType && SVX_NUM_PAGEDESC == GetFormat() )
869 ((SwDocStatFieldType*)GetTyp())->SetNumFormat(
870 pFrm->FindPageFrm()->GetPageDesc()->GetNumType().GetNumberingType() );
873 /*-----------------05.03.98 11:38-------------------
875 --------------------------------------------------*/
876 BOOL SwDocStatField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
878 switch ( nWhichId )
880 case FIELD_PROP_USHORT2:
881 rAny <<= (sal_Int16)GetFormat();
882 break;
883 default:
884 DBG_ERROR("illegal property");
886 return sal_True;
888 /*-----------------05.03.98 11:38-------------------
890 --------------------------------------------------*/
891 BOOL SwDocStatField::PutValue( const uno::Any& rAny, USHORT nWhichId )
893 BOOL bRet = FALSE;
894 switch ( nWhichId )
896 case FIELD_PROP_USHORT2:
898 sal_Int16 nSet = 0;
899 rAny >>= nSet;
900 if(nSet <= SVX_NUM_CHARS_LOWER_LETTER_N &&
901 nSet != SVX_NUM_CHAR_SPECIAL &&
902 nSet != SVX_NUM_BITMAP)
904 SetFormat(nSet);
905 bRet = TRUE;
908 break;
910 default:
911 DBG_ERROR("illegal property");
913 return bRet;
916 /*--------------------------------------------------------------------
917 Beschreibung: DokumentinfoFields
918 --------------------------------------------------------------------*/
920 SwDocInfoFieldType::SwDocInfoFieldType(SwDoc* pDc)
921 : SwValueFieldType( pDc, RES_DOCINFOFLD )
925 /* ---------------------------------------------------------------------------
927 ---------------------------------------------------------------------------*/
928 SwFieldType* SwDocInfoFieldType::Copy() const
930 SwDocInfoFieldType* pTyp = new SwDocInfoFieldType(GetDoc());
931 return pTyp;
934 void lcl_GetLocalDataWrapper( ULONG nLang,
935 const LocaleDataWrapper **ppAppLocalData,
936 const LocaleDataWrapper **ppLocalData )
938 SvtSysLocale aLocale;
939 *ppAppLocalData = &aLocale.GetLocaleData();
940 *ppLocalData = *ppAppLocalData;
941 if( nLang != SvxLocaleToLanguage( (*ppLocalData)->getLocale() ) )
942 *ppLocalData = new LocaleDataWrapper(
943 ::comphelper::getProcessServiceFactory(),
944 SvxCreateLocale( static_cast<LanguageType>(nLang) ) );
947 /* ---------------------------------------------------------------------------
949 ---------------------------------------------------------------------------*/
950 String SwDocInfoFieldType::Expand( sal_uInt16 nSub, sal_uInt32 nFormat,
951 sal_uInt16 nLang, const String& rName ) const
953 String aStr;
954 const LocaleDataWrapper *pAppLocalData = 0, *pLocalData = 0;
955 SwDocShell *pDocShell(GetDoc()->GetDocShell());
956 DBG_ASSERT(pDocShell, "no SwDocShell");
957 if (!pDocShell) { return aStr; }
959 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
960 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
961 uno::Reference<document::XDocumentProperties> xDocProps(
962 xDPS->getDocumentProperties());
963 DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
965 sal_uInt16 nExtSub = nSub & 0xff00;
966 nSub &= 0xff; // ExtendedSubTypes nicht beachten
968 switch(nSub)
970 case DI_TITEL: aStr = xDocProps->getTitle(); break;
971 case DI_THEMA: aStr = xDocProps->getSubject(); break;
972 case DI_KEYS: aStr = ::comphelper::string::convertCommaSeparated(
973 xDocProps->getKeywords());
974 break;
975 case DI_COMMENT:aStr = xDocProps->getDescription(); break;
976 case DI_DOCNO: aStr = String::CreateFromInt32(
977 xDocProps->getEditingCycles() );
978 break;
979 case DI_EDIT:
980 if ( !nFormat )
982 lcl_GetLocalDataWrapper( nLang, &pAppLocalData, &pLocalData );
983 sal_Int32 dur = xDocProps->getEditingDuration();
984 aStr = pLocalData->getTime( Time(dur/3600, (dur%3600)/60, dur%60),
985 sal_False, sal_False);
987 else
989 sal_Int32 dur = xDocProps->getEditingDuration();
990 double fVal = Time(dur/3600, (dur%3600)/60, dur%60).GetTimeInDays();
991 aStr = ExpandValue(fVal, nFormat, nLang);
993 break;
994 case DI_CUSTOM:
996 ::rtl::OUString sVal;
999 uno::Any aAny;
1000 uno::Reference < beans::XPropertySet > xSet(
1001 xDocProps->getUserDefinedProperties(),
1002 uno::UNO_QUERY_THROW);
1003 aAny = xSet->getPropertyValue( rName );
1005 uno::Reference < script::XTypeConverter > xConverter( comphelper::getProcessServiceFactory()
1006 ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), uno::UNO_QUERY );
1007 uno::Any aNew;
1008 aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING );
1009 aNew >>= sVal;
1011 catch (uno::Exception&) {}
1012 return sVal;
1015 default:
1017 String aName( xDocProps->getAuthor() );
1018 util::DateTime uDT( xDocProps->getCreationDate() );
1019 Date aD(uDT.Day, uDT.Month, uDT.Year);
1020 Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
1021 DateTime aDate(aD,aT);
1022 if( nSub == DI_CREATE )
1023 ; // das wars schon!!
1024 else if( nSub == DI_CHANGE )
1026 aName = xDocProps->getModifiedBy();
1027 uDT = xDocProps->getModificationDate();
1028 Date bD(uDT.Day, uDT.Month, uDT.Year);
1029 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
1030 DateTime bDate(bD,bT);
1031 aDate = bDate;
1033 else if( nSub == DI_PRINT )
1035 aName = xDocProps->getPrintedBy();
1036 uDT = xDocProps->getPrintDate();
1037 Date bD(uDT.Day, uDT.Month, uDT.Year);
1038 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
1039 DateTime bDate(bD,bT);
1040 aDate = bDate;
1042 else
1043 break;
1045 if (aDate.IsValid())
1047 switch (nExtSub & ~DI_SUB_FIXED)
1049 case DI_SUB_AUTHOR:
1050 aStr = aName;
1051 break;
1053 case DI_SUB_TIME:
1054 if (!nFormat)
1056 lcl_GetLocalDataWrapper( nLang, &pAppLocalData,
1057 &pLocalData );
1058 aStr = pLocalData->getTime( aDate,
1059 sal_False, sal_False);
1061 else
1063 // Numberformatter anwerfen!
1064 double fVal = SwDateTimeField::GetDateTime( GetDoc(),
1065 aDate);
1066 aStr = ExpandValue(fVal, nFormat, nLang);
1068 break;
1070 case DI_SUB_DATE:
1071 if (!nFormat)
1073 lcl_GetLocalDataWrapper( nLang, &pAppLocalData,
1074 &pLocalData );
1075 aStr = pLocalData->getDate( aDate );
1077 else
1079 // Numberformatter anwerfen!
1080 double fVal = SwDateTimeField::GetDateTime( GetDoc(),
1081 aDate);
1082 aStr = ExpandValue(fVal, nFormat, nLang);
1084 break;
1088 break;
1091 if( pAppLocalData != pLocalData )
1092 delete pLocalData;
1094 return aStr;
1097 /* ---------------------------------------------------------------------------
1099 ---------------------------------------------------------------------------*/
1100 SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, sal_uInt32 nFmt) :
1101 SwValueField(pTyp, nFmt), nSubType(nSub)
1103 aName = rName;
1104 aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, nFmt, GetLanguage(), aName);
1107 SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, const String& rValue, sal_uInt32 nFmt) :
1108 SwValueField(pTyp, nFmt), nSubType(nSub)
1110 aName = rName;
1111 aContent = rValue;
1114 /* ---------------------------------------------------------------------------
1116 ---------------------------------------------------------------------------*/
1117 String SwDocInfoField::Expand() const
1119 if ( ( nSubType & 0xFF ) == DI_CUSTOM )
1121 // custom properties currently need special treatment
1122 // we don't have a secure way to detect "real" custom properties in Word Import of text fields
1123 // so we treat *every* unknown property as a custom property, even the "built-in" section in Word's document summary information stream
1124 // as these properties have not been inserted when the document summary information was imported, we do it here
1125 // this approach is still a lot better than the old one to import such fields as "user fields" and simple text
1126 SwDocShell* pDocShell = GetDoc()->GetDocShell();
1127 if( !pDocShell )
1128 return aContent;
1131 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW);
1132 uno::Reference<document::XDocumentProperties> xDocProps( xDPS->getDocumentProperties());
1133 uno::Reference < beans::XPropertySet > xSet( xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
1134 uno::Reference < beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
1136 uno::Any aAny;
1137 if( xSetInfo->hasPropertyByName( aName ) )
1138 aAny = xSet->getPropertyValue( aName );
1139 if ( aAny.getValueType() != ::getVoidCppuType() )
1141 // "void" type means that the property has not been inserted until now
1142 if ( !IsFixed() )
1144 // if the field is "fixed" we don't update it from the property
1145 ::rtl::OUString sVal;
1146 uno::Reference < script::XTypeConverter > xConverter( comphelper::getProcessServiceFactory()
1147 ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), uno::UNO_QUERY );
1148 uno::Any aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING );
1149 aNew >>= sVal;
1150 ((SwDocInfoField*)this)->aContent = sVal;
1153 else
1155 // property is "void" - means it has not been added until now - do it!
1156 aAny <<= ::rtl::OUString(aContent);
1157 uno::Reference < beans::XPropertyContainer > xCont( xSet, uno::UNO_QUERY );
1158 xCont->addProperty( aName, ::com::sun::star::beans::PropertyAttribute::REMOVEABLE, aAny );
1161 catch (uno::Exception&) {}
1163 else if ( !IsFixed() )
1164 ((SwDocInfoField*)this)->aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, GetFormat(), GetLanguage(), aName);
1166 return aContent;
1168 /* ---------------------------------------------------------------------------
1170 ---------------------------------------------------------------------------*/
1171 String SwDocInfoField::GetCntnt(sal_Bool bName) const
1173 if ( bName )
1175 String aStr(SwFieldType::GetTypeStr(GetTypeId()));
1176 aStr += ':';
1178 sal_uInt16 nSub = nSubType & 0xff;
1180 switch(nSub)
1182 case DI_CUSTOM:
1183 aStr += aName;
1184 break;
1186 default:
1187 aStr += *ViewShell::GetShellRes()->aDocInfoLst[ nSub - DI_SUBTYPE_BEGIN ];
1188 break;
1190 if( IsFixed() )
1191 ( aStr += ' ' ) += ViewShell::GetShellRes()->aFixedStr;
1192 return aStr;
1194 return Expand();
1196 /* ---------------------------------------------------------------------------
1198 ---------------------------------------------------------------------------*/
1199 SwField* SwDocInfoField::Copy() const
1201 SwDocInfoField* pFld = new SwDocInfoField((SwDocInfoFieldType*)GetTyp(), nSubType, aName, GetFormat());
1202 pFld->SetAutomaticLanguage(IsAutomaticLanguage());
1203 pFld->aContent = aContent;
1205 return pFld;
1207 /* ---------------------------------------------------------------------------
1209 ---------------------------------------------------------------------------*/
1210 sal_uInt16 SwDocInfoField::GetSubType() const
1212 return nSubType;
1214 /* ---------------------------------------------------------------------------
1216 ---------------------------------------------------------------------------*/
1217 void SwDocInfoField::SetSubType(sal_uInt16 nSub)
1219 nSubType = nSub;
1221 /* ---------------------------------------------------------------------------
1223 ---------------------------------------------------------------------------*/
1224 void SwDocInfoField::SetLanguage(sal_uInt16 nLng)
1226 if (!GetFormat())
1227 SwField::SetLanguage(nLng);
1228 else
1229 SwValueField::SetLanguage(nLng);
1231 /* ---------------------------------------------------------------------------
1233 ---------------------------------------------------------------------------*/
1234 BOOL SwDocInfoField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
1236 switch( nWhichId )
1238 case FIELD_PROP_PAR1:
1239 rAny <<= OUString(aContent);
1240 break;
1242 case FIELD_PROP_PAR4:
1243 rAny <<= OUString(aName);
1244 break;
1246 case FIELD_PROP_USHORT1:
1247 rAny <<= (sal_Int16)aContent.ToInt32();
1248 break;
1250 case FIELD_PROP_BOOL1:
1252 sal_Bool bVal = 0 != (nSubType & DI_SUB_FIXED);
1253 rAny.setValue(&bVal, ::getBooleanCppuType());
1255 break;
1256 case FIELD_PROP_FORMAT:
1257 rAny <<= (sal_Int32)GetFormat();
1258 break;
1260 case FIELD_PROP_DOUBLE:
1262 double fVal = GetValue();
1263 rAny.setValue(&fVal, ::getCppuType(&fVal));
1265 break;
1266 case FIELD_PROP_PAR3:
1267 rAny <<= rtl::OUString(Expand());
1268 break;
1269 case FIELD_PROP_BOOL2:
1271 sal_uInt16 nExtSub = (nSubType & 0xff00) & ~DI_SUB_FIXED;
1272 sal_Bool bVal = (nExtSub == DI_SUB_DATE);
1273 rAny.setValue(&bVal, ::getBooleanCppuType());
1275 break;
1276 default:
1277 return SwField::QueryValue(rAny, nWhichId);
1279 return sal_True;
1281 /* ---------------------------------------------------------------------------
1283 ---------------------------------------------------------------------------*/
1284 BOOL SwDocInfoField::PutValue( const uno::Any& rAny, USHORT nWhichId )
1286 sal_Int32 nValue = 0;
1287 switch( nWhichId )
1289 case FIELD_PROP_PAR1:
1290 if( nSubType & DI_SUB_FIXED )
1291 ::GetString( rAny, aContent );
1292 break;
1294 case FIELD_PROP_USHORT1:
1295 if( nSubType & DI_SUB_FIXED )
1297 rAny >>= nValue;
1298 aContent = String::CreateFromInt32(nValue);
1300 break;
1302 case FIELD_PROP_BOOL1:
1303 if(*(sal_Bool*)rAny.getValue())
1304 nSubType |= DI_SUB_FIXED;
1305 else
1306 nSubType &= ~DI_SUB_FIXED;
1307 break;
1308 case FIELD_PROP_FORMAT:
1310 rAny >>= nValue;
1311 if( nValue >= 0)
1312 SetFormat(nValue);
1314 break;
1316 case FIELD_PROP_PAR3:
1317 ::GetString( rAny, aContent );
1318 break;
1319 case FIELD_PROP_BOOL2:
1320 nSubType &= 0xf0ff;
1321 if(*(sal_Bool*)rAny.getValue())
1322 nSubType |= DI_SUB_DATE;
1323 else
1324 nSubType |= DI_SUB_TIME;
1325 break;
1326 default:
1327 return SwField::PutValue(rAny, nWhichId);
1329 return sal_True;
1332 /*--------------------------------------------------------------------
1333 Beschreibung: SwHiddenTxtFieldType by JP
1334 --------------------------------------------------------------------*/
1336 SwHiddenTxtFieldType::SwHiddenTxtFieldType( sal_Bool bSetHidden )
1337 : SwFieldType( RES_HIDDENTXTFLD ), bHidden( bSetHidden )
1340 SwFieldType* SwHiddenTxtFieldType::Copy() const
1342 return new SwHiddenTxtFieldType( bHidden );
1344 /* ---------------------------------------------------------------------------
1346 ---------------------------------------------------------------------------*/
1347 void SwHiddenTxtFieldType::SetHiddenFlag( sal_Bool bSetHidden )
1349 if( bHidden != bSetHidden )
1351 bHidden = bSetHidden;
1352 UpdateFlds(); // alle HiddenText benachrichtigen
1355 /* ---------------------------------------------------------------------------
1357 ---------------------------------------------------------------------------*/
1358 SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType,
1359 sal_Bool bConditional,
1360 const String& rCond,
1361 const String& rStr,
1362 sal_Bool bHidden,
1363 sal_uInt16 nSub) :
1364 SwField( pFldType ), aCond(rCond), nSubType(nSub),
1365 bCanToggle(bConditional), bIsHidden(bHidden), bValid(sal_False)
1367 if(nSubType == TYP_CONDTXTFLD)
1369 sal_uInt16 nPos = 0;
1370 aTRUETxt = rStr.GetToken(0, '|', nPos);
1372 if(nPos != STRING_NOTFOUND)
1374 aFALSETxt = rStr.GetToken(0, '|', nPos);
1375 if(nPos != STRING_NOTFOUND)
1377 aContent = rStr.GetToken(0, '|', nPos);
1378 bValid = sal_True;
1382 else
1383 aTRUETxt = rStr;
1385 /* ---------------------------------------------------------------------------
1387 ---------------------------------------------------------------------------*/
1388 SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType,
1389 const String& rCond,
1390 const String& rTrue,
1391 const String& rFalse,
1392 sal_uInt16 nSub)
1393 : SwField( pFldType ), aTRUETxt(rTrue), aFALSETxt(rFalse), aCond(rCond), nSubType(nSub),
1394 bIsHidden(sal_True), bValid(sal_False)
1396 bCanToggle = aCond.Len() > 0;
1398 /* ---------------------------------------------------------------------------
1400 ---------------------------------------------------------------------------*/
1401 String SwHiddenTxtField::Expand() const
1403 // Type: !Hidden -> immer anzeigen
1404 // Hide -> Werte die Bedingung aus
1406 if( TYP_CONDTXTFLD == nSubType )
1408 if( bValid )
1409 return aContent;
1411 if( bCanToggle && !bIsHidden )
1412 return aTRUETxt;
1414 else if( !((SwHiddenTxtFieldType*)GetTyp())->GetHiddenFlag() ||
1415 ( bCanToggle && bIsHidden ))
1416 return aTRUETxt;
1418 return aFALSETxt;
1421 /*--------------------------------------------------------------------
1422 Beschreibung: Aktuellen Field-Value holen und cachen
1423 --------------------------------------------------------------------*/
1425 void SwHiddenTxtField::Evaluate(SwDoc* pDoc)
1427 ASSERT(pDoc, Wo ist das Dokument Seniore);
1429 if( TYP_CONDTXTFLD == nSubType )
1431 SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
1433 bValid = sal_False;
1434 String sTmpName;
1436 if (bCanToggle && !bIsHidden)
1437 sTmpName = aTRUETxt;
1438 else
1439 sTmpName = aFALSETxt;
1441 // OS 21.08.97: #42943# Datenbankausdruecke muessen sich von
1442 // einfachem Text unterscheiden. also wird der einfache Text
1443 // bevorzugt in Anfuehrungszeichen gesetzt.
1444 // Sind diese vorhanden werden umschliessende entfernt.
1445 // Wenn nicht, dann wird auf die Tauglichkeit als Datenbankname
1446 // geprueft. Nur wenn zwei oder mehr Punkte vorhanden sind und kein
1447 // Anfuehrungszeichen enthalten ist, gehen wir von einer DB aus.
1448 if(sTmpName.Len() > 1 && sTmpName.GetChar(0) == '\"' &&
1449 sTmpName.GetChar((sTmpName.Len() - 1))== '\"')
1451 aContent = sTmpName.Copy(1, sTmpName.Len() - 2);
1452 bValid = sal_True;
1454 else if(sTmpName.Search('\"') == STRING_NOTFOUND &&
1455 sTmpName.GetTokenCount('.') > 2)
1457 ::ReplacePoint(sTmpName);
1458 if(sTmpName.GetChar(0) == '[' && sTmpName.GetChar(sTmpName.Len()-1) == ']')
1459 { // Eckige Klammern entfernen
1460 sTmpName.Erase(0, 1);
1461 sTmpName.Erase(sTmpName.Len()-1, 1);
1464 if( pMgr)
1466 String sDBName( GetDBName( sTmpName, pDoc ));
1467 String sDataSource(sDBName.GetToken(0, DB_DELIM));
1468 String sDataTableOrQuery(sDBName.GetToken(1, DB_DELIM));
1469 if( pMgr->IsInMerge() && sDBName.Len() &&
1470 pMgr->IsDataSourceOpen( sDataSource,
1471 sDataTableOrQuery, sal_False))
1473 double fNumber;
1474 sal_uInt32 nTmpFormat;
1475 pMgr->GetMergeColumnCnt(GetColumnName( sTmpName ),
1476 GetLanguage(), aContent, &fNumber, &nTmpFormat );
1477 bValid = sal_True;
1479 else if( sDBName.Len() && sDataSource.Len() &&
1480 sDataTableOrQuery.Len() )
1481 bValid = sal_True;
1486 /* ---------------------------------------------------------------------------
1488 ---------------------------------------------------------------------------*/
1489 String SwHiddenTxtField::GetCntnt(sal_Bool bName) const
1491 if ( bName )
1493 String aStr(SwFieldType::GetTypeStr(nSubType));
1494 aStr += ' ';
1495 aStr += aCond;
1496 aStr += ' ';
1497 aStr += aTRUETxt;
1499 if(nSubType == TYP_CONDTXTFLD)
1501 static char __READONLY_DATA cTmp[] = " : ";
1502 aStr.AppendAscii(cTmp);
1503 aStr += aFALSETxt;
1505 return aStr;
1507 return Expand();
1509 /* ---------------------------------------------------------------------------
1511 ---------------------------------------------------------------------------*/
1512 SwField* SwHiddenTxtField::Copy() const
1514 SwHiddenTxtField* pFld =
1515 new SwHiddenTxtField((SwHiddenTxtFieldType*)GetTyp(), aCond,
1516 aTRUETxt, aFALSETxt);
1517 pFld->bIsHidden = bIsHidden;
1518 pFld->bValid = bValid;
1519 pFld->aContent = aContent;
1520 pFld->SetFormat(GetFormat());
1521 pFld->nSubType = nSubType;
1522 return pFld;
1526 /*--------------------------------------------------------------------
1527 Beschreibung: Bedingung setzen
1528 --------------------------------------------------------------------*/
1530 void SwHiddenTxtField::SetPar1(const String& rStr)
1532 aCond = rStr;
1533 bCanToggle = aCond.Len() > 0;
1535 /* ---------------------------------------------------------------------------
1537 ---------------------------------------------------------------------------*/
1538 const String& SwHiddenTxtField::GetPar1() const
1540 return aCond;
1543 /*--------------------------------------------------------------------
1544 Beschreibung: True/False Text
1545 --------------------------------------------------------------------*/
1547 void SwHiddenTxtField::SetPar2(const String& rStr)
1549 if(nSubType == TYP_CONDTXTFLD)
1551 sal_uInt16 nPos = rStr.Search('|');
1552 aTRUETxt = rStr.Copy(0, nPos);
1554 if(nPos != STRING_NOTFOUND)
1555 aFALSETxt = rStr.Copy(nPos + 1);
1557 else
1558 aTRUETxt = rStr;
1560 /* ---------------------------------------------------------------------------
1562 ---------------------------------------------------------------------------*/
1563 String SwHiddenTxtField::GetPar2() const
1565 String aRet(aTRUETxt);
1566 if(nSubType == TYP_CONDTXTFLD)
1568 aRet += '|';
1569 aRet += aFALSETxt;
1571 return aRet;
1573 /* ---------------------------------------------------------------------------
1575 ---------------------------------------------------------------------------*/
1576 sal_uInt16 SwHiddenTxtField::GetSubType() const
1578 return nSubType;
1580 /* ---------------------------------------------------------------------------
1582 ---------------------------------------------------------------------------*/
1583 BOOL SwHiddenTxtField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
1585 const String* pOut = 0;
1586 switch( nWhichId )
1588 case FIELD_PROP_PAR1:
1589 pOut = &aCond;
1590 break;
1591 case FIELD_PROP_PAR2:
1592 pOut = &aTRUETxt;
1593 break;
1594 case FIELD_PROP_PAR3:
1595 pOut = &aFALSETxt;
1596 break;
1597 case FIELD_PROP_PAR4 :
1598 pOut = &aContent;
1599 break;
1600 case FIELD_PROP_BOOL1:
1602 sal_Bool bHidden = bIsHidden;
1603 rAny.setValue(&bHidden, ::getBooleanCppuType());
1605 break;
1606 default:
1607 DBG_ERROR("illegal property");
1609 if( pOut )
1610 rAny <<= OUString( *pOut );
1611 return sal_True;
1613 /* ---------------------------------------------------------------------------
1615 ---------------------------------------------------------------------------*/
1616 BOOL SwHiddenTxtField::PutValue( const uno::Any& rAny, USHORT nWhichId )
1618 switch( nWhichId )
1620 case FIELD_PROP_PAR1:
1622 String sVal;
1623 SetPar1(::GetString( rAny, sVal ));
1625 break;
1626 case FIELD_PROP_PAR2:
1627 ::GetString( rAny, aTRUETxt );
1628 break;
1629 case FIELD_PROP_PAR3:
1630 ::GetString( rAny, aFALSETxt );
1631 break;
1632 case FIELD_PROP_BOOL1:
1633 bIsHidden = *(sal_Bool*)rAny.getValue();
1634 break;
1635 case FIELD_PROP_PAR4:
1636 ::GetString( rAny, aContent);
1637 bValid = TRUE;
1638 break;
1639 default:
1640 DBG_ERROR("illegal property");
1642 return sal_True;
1645 //------------------------------------------------------------------------------
1647 String SwHiddenTxtField::GetColumnName(const String& rName)
1649 sal_uInt16 nPos = rName.Search(DB_DELIM);
1650 if( STRING_NOTFOUND != nPos )
1652 nPos = rName.Search(DB_DELIM, nPos + 1);
1654 if( STRING_NOTFOUND != nPos )
1655 return rName.Copy(nPos + 1);
1657 return rName;
1660 //------------------------------------------------------------------------------
1662 String SwHiddenTxtField::GetDBName(const String& rName, SwDoc *pDoc)
1664 sal_uInt16 nPos = rName.Search(DB_DELIM);
1665 if( STRING_NOTFOUND != nPos )
1667 nPos = rName.Search(DB_DELIM, nPos + 1);
1669 if( STRING_NOTFOUND != nPos )
1670 return rName.Copy( 0, nPos );
1672 SwDBData aData = pDoc->GetDBData();
1673 String sRet = aData.sDataSource;
1674 sRet += DB_DELIM;
1675 sRet += String(aData.sCommand);
1676 return sRet;
1679 /*--------------------------------------------------------------------
1680 Beschreibung: Der Feldtyp fuer Zeilenhoehe 0
1681 --------------------------------------------------------------------*/
1683 SwHiddenParaFieldType::SwHiddenParaFieldType()
1684 : SwFieldType( RES_HIDDENPARAFLD )
1688 SwFieldType* SwHiddenParaFieldType::Copy() const
1690 SwHiddenParaFieldType* pTyp = new SwHiddenParaFieldType();
1691 return pTyp;
1694 /*--------------------------------------------------------------------
1695 Beschreibung: Das Feld Zeilenhoehe 0
1696 --------------------------------------------------------------------*/
1698 SwHiddenParaField::SwHiddenParaField(SwHiddenParaFieldType* pTyp, const String& rStr)
1699 : SwField(pTyp), aCond(rStr)
1701 bIsHidden = sal_False;
1703 /* ---------------------------------------------------------------------------
1705 ---------------------------------------------------------------------------*/
1706 String SwHiddenParaField::Expand() const
1708 return aEmptyStr;
1710 /* ---------------------------------------------------------------------------
1712 ---------------------------------------------------------------------------*/
1713 SwField* SwHiddenParaField::Copy() const
1715 SwHiddenParaField* pFld = new SwHiddenParaField((SwHiddenParaFieldType*)GetTyp(), aCond);
1716 pFld->bIsHidden = bIsHidden;
1718 return pFld;
1720 /*-----------------05.03.98 13:25-------------------
1722 --------------------------------------------------*/
1723 BOOL SwHiddenParaField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
1725 switch ( nWhichId )
1727 case FIELD_PROP_PAR1:
1728 rAny <<= OUString(aCond);
1729 break;
1730 case FIELD_PROP_BOOL1:
1732 sal_Bool bHidden = bIsHidden;
1733 rAny.setValue(&bHidden, ::getBooleanCppuType());
1735 break;
1737 default:
1738 DBG_ERROR("illegal property");
1740 return sal_True;
1742 /*-----------------05.03.98 13:25-------------------
1744 --------------------------------------------------*/
1745 BOOL SwHiddenParaField::PutValue( const uno::Any& rAny, USHORT nWhichId )
1747 switch ( nWhichId )
1749 case FIELD_PROP_PAR1:
1750 ::GetString( rAny, aCond );
1751 break;
1752 case FIELD_PROP_BOOL1:
1753 bIsHidden = *(sal_Bool*)rAny.getValue();
1754 break;
1756 default:
1757 DBG_ERROR("illegal property");
1759 return sal_True;
1762 /*--------------------------------------------------------------------
1763 Beschreibung: Bedingung setzen
1764 --------------------------------------------------------------------*/
1766 void SwHiddenParaField::SetPar1(const String& rStr)
1768 aCond = rStr;
1770 /* ---------------------------------------------------------------------------
1772 ---------------------------------------------------------------------------*/
1773 const String& SwHiddenParaField::GetPar1() const
1775 return aCond;
1778 /*--------------------------------------------------------------------
1779 Beschreibung: PostIt
1780 --------------------------------------------------------------------*/
1782 SwPostItFieldType::SwPostItFieldType(SwDoc *pDoc)
1783 : SwFieldType( RES_POSTITFLD ),mpDoc(pDoc)
1785 /* ---------------------------------------------------------------------------
1787 ---------------------------------------------------------------------------*/
1788 SwFieldType* SwPostItFieldType::Copy() const
1790 return new SwPostItFieldType(mpDoc);
1794 /*--------------------------------------------------------------------
1795 Beschreibung: SwPostItFieldType
1796 --------------------------------------------------------------------*/
1798 SwPostItField::SwPostItField( SwPostItFieldType* pT,
1799 const String& rAuthor, const String& rTxt, const DateTime& rDateTime )
1800 : SwField( pT ), sTxt( rTxt ), sAuthor( rAuthor ), aDateTime( rDateTime ), mpText(0), m_pTextObject(0)
1805 SwPostItField::~SwPostItField()
1807 if ( m_pTextObject )
1809 m_pTextObject->DisposeEditSource();
1810 m_pTextObject->release();
1814 /* ---------------------------------------------------------------------------
1816 ---------------------------------------------------------------------------*/
1817 String SwPostItField::Expand() const
1819 return aEmptyStr;
1823 String SwPostItField::GetDescription() const
1825 return SW_RES(STR_NOTE);
1828 /* ---------------------------------------------------------------------------
1830 ---------------------------------------------------------------------------*/
1831 SwField* SwPostItField::Copy() const
1833 SwPostItField* pRet = new SwPostItField( (SwPostItFieldType*)GetTyp(), sAuthor,
1834 sTxt, aDateTime);
1835 if (mpText)
1836 pRet->SetTextObject( new OutlinerParaObject(*mpText) );
1837 return pRet;
1839 /*--------------------------------------------------------------------
1840 Beschreibung: Author setzen
1841 --------------------------------------------------------------------*/
1843 void SwPostItField::SetPar1(const String& rStr)
1845 sAuthor = rStr;
1848 const String& SwPostItField::GetPar1() const
1850 return sAuthor;
1853 /*--------------------------------------------------------------------
1854 Beschreibung: Text fuers PostIt setzen
1855 --------------------------------------------------------------------*/
1857 void SwPostItField::SetPar2(const String& rStr)
1859 sTxt = rStr;
1861 /* ---------------------------------------------------------------------------
1863 ---------------------------------------------------------------------------*/
1864 String SwPostItField::GetPar2() const
1866 return sTxt;
1869 const OutlinerParaObject* SwPostItField::GetTextObject() const
1871 return mpText;
1874 void SwPostItField::SetTextObject( OutlinerParaObject* pText )
1876 delete mpText;
1877 mpText = pText;
1880 /*-----------------05.03.98 13:42-------------------
1882 --------------------------------------------------*/
1883 BOOL SwPostItField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
1885 switch( nWhichId )
1887 case FIELD_PROP_PAR1:
1888 rAny <<= OUString(sAuthor);
1889 break;
1890 case FIELD_PROP_PAR2:
1892 rAny <<= OUString(sTxt);
1893 break;
1895 case FIELD_PROP_TEXT:
1897 if ( !m_pTextObject )
1899 SwPostItFieldType* pGetType = (SwPostItFieldType*)GetTyp();
1900 SwDoc* pDoc = pGetType->GetDoc();
1901 SwTextAPIEditSource* pObj = new SwTextAPIEditSource( pDoc );
1902 const_cast <SwPostItField*> (this)->m_pTextObject = new SwTextAPIObject( pObj );
1903 m_pTextObject->acquire();
1906 if ( mpText )
1907 m_pTextObject->SetText( *mpText );
1908 else
1909 m_pTextObject->SetString( sTxt );
1911 uno::Reference < text::XText > xText( m_pTextObject );
1912 rAny <<= xText;
1913 break;
1915 case FIELD_PROP_DATE:
1917 util::Date aSetDate;
1918 aSetDate.Day = aDateTime.GetDay();
1919 aSetDate.Month = aDateTime.GetMonth();
1920 aSetDate.Year = aDateTime.GetYear();
1921 rAny.setValue(&aSetDate, ::getCppuType((util::Date*)0));
1923 break;
1924 case FIELD_PROP_DATE_TIME:
1926 util::DateTime DateTimeValue;
1927 DateTimeValue.HundredthSeconds = aDateTime.Get100Sec();
1928 DateTimeValue.Seconds = aDateTime.GetSec();
1929 DateTimeValue.Minutes = aDateTime.GetMin();
1930 DateTimeValue.Hours = aDateTime.GetHour();
1931 DateTimeValue.Day = aDateTime.GetDay();
1932 DateTimeValue.Month = aDateTime.GetMonth();
1933 DateTimeValue.Year = aDateTime.GetYear();
1934 rAny <<= DateTimeValue;
1936 break;
1937 default:
1938 DBG_ERROR("illegal property");
1940 return sal_True;
1944 /*-----------------05.03.98 13:42-------------------
1946 --------------------------------------------------*/
1947 BOOL SwPostItField::PutValue( const uno::Any& rAny, USHORT nWhichId )
1949 switch( nWhichId )
1951 case FIELD_PROP_PAR1:
1952 ::GetString( rAny, sAuthor );
1953 break;
1954 case FIELD_PROP_PAR2:
1955 ::GetString( rAny, sTxt );
1956 //#i100374# new string via api, delete complex text object so SwPostItNote picks up the new string
1957 if (mpText)
1959 delete mpText;
1960 mpText = 0;
1962 break;
1963 case FIELD_PROP_TEXT:
1964 DBG_ERROR("Not implemented!");
1965 // ::GetString( rAny, sTxt );
1966 break;
1967 case FIELD_PROP_DATE:
1968 if( rAny.getValueType() == ::getCppuType((util::Date*)0) )
1970 util::Date aSetDate = *(util::Date*)rAny.getValue();
1971 aDateTime = Date(aSetDate.Day, aSetDate.Month, aSetDate.Year);
1973 break;
1974 case FIELD_PROP_DATE_TIME:
1976 util::DateTime aDateTimeValue;
1977 if(!(rAny >>= aDateTimeValue))
1978 return FALSE;
1979 aDateTime.Set100Sec(aDateTimeValue.HundredthSeconds);
1980 aDateTime.SetSec(aDateTimeValue.Seconds);
1981 aDateTime.SetMin(aDateTimeValue.Minutes);
1982 aDateTime.SetHour(aDateTimeValue.Hours);
1983 aDateTime.SetDay(aDateTimeValue.Day);
1984 aDateTime.SetMonth(aDateTimeValue.Month);
1985 aDateTime.SetYear(aDateTimeValue.Year);
1987 break;
1988 default:
1989 DBG_ERROR("illegal property");
1991 return sal_True;
1993 /*--------------------------------------------------------------------
1994 Beschreibung: DokumentinfoFields
1995 --------------------------------------------------------------------*/
1997 SwExtUserFieldType::SwExtUserFieldType()
1998 : SwFieldType( RES_EXTUSERFLD )
2001 /* ---------------------------------------------------------------------------
2003 ---------------------------------------------------------------------------*/
2004 SwFieldType* SwExtUserFieldType::Copy() const
2006 SwExtUserFieldType* pTyp = new SwExtUserFieldType;
2007 return pTyp;
2009 /* ---------------------------------------------------------------------------
2011 ---------------------------------------------------------------------------*/
2012 String SwExtUserFieldType::Expand(sal_uInt16 nSub, sal_uInt32 ) const
2014 String aRet;
2015 sal_uInt16 nRet = USHRT_MAX;
2016 switch(nSub)
2018 case EU_FIRSTNAME: nRet = USER_OPT_FIRSTNAME; break;
2019 case EU_NAME: nRet = USER_OPT_LASTNAME; break;
2020 case EU_SHORTCUT: nRet = USER_OPT_ID; break;
2022 case EU_COMPANY: nRet = USER_OPT_COMPANY; break;
2023 case EU_STREET: nRet = USER_OPT_STREET; break;
2024 case EU_TITLE: nRet = USER_OPT_TITLE; break;
2025 case EU_POSITION: nRet = USER_OPT_POSITION; break;
2026 case EU_PHONE_PRIVATE: nRet = USER_OPT_TELEPHONEHOME; break;
2027 case EU_PHONE_COMPANY: nRet = USER_OPT_TELEPHONEWORK; break;
2028 case EU_FAX: nRet = USER_OPT_FAX; break;
2029 case EU_EMAIL: nRet = USER_OPT_EMAIL; break;
2030 case EU_COUNTRY: nRet = USER_OPT_COUNTRY; break;
2031 case EU_ZIP: nRet = USER_OPT_ZIP; break;
2032 case EU_CITY: nRet = USER_OPT_CITY; break;
2033 case EU_STATE: nRet = USER_OPT_STATE; break;
2034 case EU_FATHERSNAME: nRet = USER_OPT_FATHERSNAME; break;
2035 case EU_APARTMENT: nRet = USER_OPT_APARTMENT; break;
2036 default: ASSERT( !this, "Field unknown");
2038 if( USHRT_MAX != nRet )
2040 SvtUserOptions& rUserOpt = SW_MOD()->GetUserOptions();
2041 aRet = rUserOpt.GetToken( nRet );
2043 return aRet;
2045 /* ---------------------------------------------------------------------------
2047 ---------------------------------------------------------------------------*/
2048 SwExtUserField::SwExtUserField(SwExtUserFieldType* pTyp, sal_uInt16 nSubTyp, sal_uInt32 nFmt) :
2049 SwField(pTyp, nFmt), nType(nSubTyp)
2051 aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
2053 /* ---------------------------------------------------------------------------
2055 ---------------------------------------------------------------------------*/
2056 String SwExtUserField::Expand() const
2058 if (!IsFixed())
2059 ((SwExtUserField*)this)->aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
2061 return aContent;
2063 /* ---------------------------------------------------------------------------
2065 ---------------------------------------------------------------------------*/
2066 SwField* SwExtUserField::Copy() const
2068 SwExtUserField* pFld = new SwExtUserField((SwExtUserFieldType*)GetTyp(), nType, GetFormat());
2069 pFld->SetExpansion(aContent);
2071 return pFld;
2073 /* ---------------------------------------------------------------------------
2075 ---------------------------------------------------------------------------*/
2076 sal_uInt16 SwExtUserField::GetSubType() const
2078 return nType;
2080 /* ---------------------------------------------------------------------------
2082 ---------------------------------------------------------------------------*/
2083 void SwExtUserField::SetSubType(sal_uInt16 nSub)
2085 nType = nSub;
2088 /*-----------------05.03.98 14:14-------------------
2090 --------------------------------------------------*/
2091 BOOL SwExtUserField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
2093 switch( nWhichId )
2095 case FIELD_PROP_PAR1:
2096 rAny <<= OUString(aContent);
2097 break;
2099 case FIELD_PROP_USHORT1:
2101 sal_Int16 nTmp = nType;
2102 rAny <<= nTmp;
2104 break;
2105 case FIELD_PROP_BOOL1:
2107 sal_Bool bTmp = IsFixed();
2108 rAny.setValue(&bTmp, ::getBooleanCppuType());
2110 break;
2111 default:
2112 DBG_ERROR("illegal property");
2114 return sal_True;
2116 /*-----------------05.03.98 14:14-------------------
2118 --------------------------------------------------*/
2119 BOOL SwExtUserField::PutValue( const uno::Any& rAny, USHORT nWhichId )
2121 switch( nWhichId )
2123 case FIELD_PROP_PAR1:
2124 ::GetString( rAny, aContent );
2125 break;
2127 case FIELD_PROP_USHORT1:
2129 sal_Int16 nTmp = 0;
2130 rAny >>= nTmp;
2131 nType = nTmp;
2133 break;
2134 case FIELD_PROP_BOOL1:
2135 if( *(sal_Bool*)rAny.getValue() )
2136 SetFormat(GetFormat() | AF_FIXED);
2137 else
2138 SetFormat(GetFormat() & ~AF_FIXED);
2139 break;
2140 default:
2141 DBG_ERROR("illegal property");
2143 return sal_True;
2145 //-------------------------------------------------------------------------
2147 /*--------------------------------------------------------------------
2148 Beschreibung: Relatives Seitennummern - Feld
2149 --------------------------------------------------------------------*/
2151 SwRefPageSetFieldType::SwRefPageSetFieldType()
2152 : SwFieldType( RES_REFPAGESETFLD )
2155 /* ---------------------------------------------------------------------------
2157 ---------------------------------------------------------------------------*/
2158 SwFieldType* SwRefPageSetFieldType::Copy() const
2160 return new SwRefPageSetFieldType;
2162 /* ---------------------------------------------------------------------------
2164 ---------------------------------------------------------------------------*/
2165 // ueberlagert, weil es nichts zum Updaten gibt!
2166 void SwRefPageSetFieldType::Modify( SfxPoolItem *, SfxPoolItem * )
2170 /*--------------------------------------------------------------------
2171 Beschreibung: Relative Seitennummerierung
2172 --------------------------------------------------------------------*/
2174 SwRefPageSetField::SwRefPageSetField( SwRefPageSetFieldType* pTyp,
2175 short nOff, sal_Bool bFlag )
2176 : SwField( pTyp ), nOffset( nOff ), bOn( bFlag )
2179 /* ---------------------------------------------------------------------------
2181 ---------------------------------------------------------------------------*/
2182 String SwRefPageSetField::Expand() const
2184 return aEmptyStr;
2186 /* ---------------------------------------------------------------------------
2188 ---------------------------------------------------------------------------*/
2189 SwField* SwRefPageSetField::Copy() const
2191 return new SwRefPageSetField( (SwRefPageSetFieldType*)GetTyp(), nOffset, bOn );
2193 /* ---------------------------------------------------------------------------
2195 ---------------------------------------------------------------------------*/
2196 String SwRefPageSetField::GetPar2() const
2198 return String::CreateFromInt32( GetOffset() );
2200 /* ---------------------------------------------------------------------------
2202 ---------------------------------------------------------------------------*/
2203 void SwRefPageSetField::SetPar2(const String& rStr)
2205 SetOffset( (short) rStr.ToInt32() );
2208 /*-----------------05.03.98 14:52-------------------
2210 --------------------------------------------------*/
2211 BOOL SwRefPageSetField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
2213 switch( nWhichId )
2215 case FIELD_PROP_BOOL1:
2216 rAny.setValue(&bOn, ::getBooleanCppuType());
2217 break;
2218 case FIELD_PROP_USHORT1:
2219 rAny <<= (sal_Int16)nOffset;
2220 break;
2221 default:
2222 DBG_ERROR("illegal property");
2224 return sal_True;
2226 /*-----------------05.03.98 14:52-------------------
2228 --------------------------------------------------*/
2229 BOOL SwRefPageSetField::PutValue( const uno::Any& rAny, USHORT nWhichId )
2231 switch( nWhichId )
2233 case FIELD_PROP_BOOL1:
2234 bOn = *(sal_Bool*)rAny.getValue();
2235 break;
2236 case FIELD_PROP_USHORT1:
2237 rAny >>=nOffset;
2238 break;
2239 default:
2240 DBG_ERROR("illegal property");
2242 return sal_True;
2244 /*--------------------------------------------------------------------
2245 Beschreibung: relatives Seitennummern - Abfrage Feld
2246 --------------------------------------------------------------------*/
2248 SwRefPageGetFieldType::SwRefPageGetFieldType( SwDoc* pDc )
2249 : SwFieldType( RES_REFPAGEGETFLD ), pDoc( pDc ), nNumberingType( SVX_NUM_ARABIC )
2252 /* ---------------------------------------------------------------------------
2254 ---------------------------------------------------------------------------*/
2255 SwFieldType* SwRefPageGetFieldType::Copy() const
2257 SwRefPageGetFieldType* pNew = new SwRefPageGetFieldType( pDoc );
2258 pNew->nNumberingType = nNumberingType;
2259 return pNew;
2261 /* ---------------------------------------------------------------------------
2263 ---------------------------------------------------------------------------*/
2264 void SwRefPageGetFieldType::Modify( SfxPoolItem* pOld, SfxPoolItem* pNew )
2266 // Update auf alle GetReferenz-Felder
2267 if( !pNew && !pOld && GetDepends() )
2269 // sammel erstmal alle SetPageRefFelder ein.
2270 _SetGetExpFlds aTmpLst( 10, 5 );
2271 if( MakeSetList( aTmpLst ) )
2273 SwClientIter aIter( *this );
2274 if( aIter.GoStart() )
2275 do {
2276 // nur die GetRef-Felder Updaten
2277 SwFmtFld* pFmtFld = (SwFmtFld*)aIter();
2278 if( pFmtFld->GetTxtFld() )
2279 UpdateField( pFmtFld->GetTxtFld(), aTmpLst );
2280 } while( aIter++ );
2284 // weiter an die Text-Felder, diese "Expandieren" den Text
2285 SwModify::Modify( pOld, pNew );
2287 /* ---------------------------------------------------------------------------
2289 ---------------------------------------------------------------------------*/
2290 sal_uInt16 SwRefPageGetFieldType::MakeSetList( _SetGetExpFlds& rTmpLst )
2292 SwClientIter aIter( *pDoc->GetSysFldType( RES_REFPAGESETFLD));
2293 if( aIter.GoStart() )
2294 do {
2295 // nur die GetRef-Felder Updaten
2296 SwFmtFld* pFmtFld = (SwFmtFld*)aIter();
2297 const SwTxtFld* pTFld = pFmtFld->GetTxtFld();
2298 if( pTFld )
2300 const SwTxtNode& rTxtNd = pTFld->GetTxtNode();
2302 // immer den ersten !! (in Tab-Headline, Kopf-/Fuss )
2303 Point aPt;
2304 const SwCntntFrm* pFrm = rTxtNd.GetFrm( &aPt, 0, sal_False );
2306 _SetGetExpFld* pNew;
2308 if( !pFrm ||
2309 pFrm->IsInDocBody() ||
2310 // --> FME 2004-07-27 #i31868#
2311 // Check if pFrm is not yet connected to the layout.
2312 !pFrm->FindPageFrm() )
2313 // <--
2315 // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2316 SwNodeIndex aIdx( rTxtNd );
2317 pNew = new _SetGetExpFld( aIdx, pTFld );
2319 else
2321 // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2322 SwPosition aPos( pDoc->GetNodes().GetEndOfPostIts() );
2323 #ifndef PRODUCT
2324 ASSERT( GetBodyTxtNode( *pDoc, aPos, *pFrm ),
2325 "wo steht das Feld" );
2326 #else
2327 GetBodyTxtNode( *pDoc, aPos, *pFrm );
2328 #endif
2329 pNew = new _SetGetExpFld( aPos.nNode, pTFld,
2330 &aPos.nContent );
2333 if( !rTmpLst.Insert( pNew ))
2334 delete pNew;
2336 } while( aIter++ );
2338 return rTmpLst.Count();
2340 /* ---------------------------------------------------------------------------
2342 ---------------------------------------------------------------------------*/
2343 void SwRefPageGetFieldType::UpdateField( SwTxtFld* pTxtFld,
2344 _SetGetExpFlds& rSetList )
2346 SwRefPageGetField* pGetFld = (SwRefPageGetField*)pTxtFld->GetFld().GetFld();
2347 pGetFld->SetText( aEmptyStr );
2349 // dann suche mal das richtige RefPageSet-Field
2350 SwTxtNode* pTxtNode = (SwTxtNode*)&pTxtFld->GetTxtNode();
2351 if( pTxtNode->StartOfSectionIndex() >
2352 pDoc->GetNodes().GetEndOfExtras().GetIndex() )
2354 SwNodeIndex aIdx( *pTxtNode );
2355 _SetGetExpFld aEndFld( aIdx, pTxtFld );
2357 sal_uInt16 nLast;
2358 rSetList.Seek_Entry( &aEndFld, &nLast );
2360 if( nLast-- )
2362 const SwTxtFld* pRefTxtFld = rSetList[ nLast ]->GetFld();
2363 const SwRefPageSetField* pSetFld =
2364 (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld();
2365 if( pSetFld->IsOn() )
2367 // dann bestimme mal den entsp. Offset
2368 Point aPt;
2369 const SwCntntFrm* pFrm = pTxtNode->GetFrm( &aPt, 0, sal_False );
2370 const SwCntntFrm* pRefFrm = pRefTxtFld->GetTxtNode().GetFrm( &aPt, 0, sal_False );
2371 const SwPageFrm* pPgFrm = 0;
2372 sal_uInt16 nDiff = ( pFrm && pRefFrm )
2373 ? (pPgFrm = pFrm->FindPageFrm())->GetPhyPageNum() -
2374 pRefFrm->FindPageFrm()->GetPhyPageNum() + 1
2375 : 1;
2377 sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
2378 ? ( !pPgFrm
2379 ? (sal_uInt32)SVX_NUM_ARABIC
2380 : pPgFrm->GetPageDesc()->GetNumType().GetNumberingType() )
2381 : pGetFld->GetFormat();
2382 short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff));
2383 pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
2387 // dann die Formatierung anstossen
2388 ((SwFmtFld&)pTxtFld->GetFld()).Modify( 0, 0 );
2391 /*--------------------------------------------------------------------
2392 Beschreibung: Relative Seitennummerierung Abfragen
2393 --------------------------------------------------------------------*/
2395 SwRefPageGetField::SwRefPageGetField( SwRefPageGetFieldType* pTyp,
2396 sal_uInt32 nFmt )
2397 : SwField( pTyp, nFmt )
2400 /* ---------------------------------------------------------------------------
2402 ---------------------------------------------------------------------------*/
2403 String SwRefPageGetField::Expand() const
2405 return sTxt;
2407 /* ---------------------------------------------------------------------------
2409 ---------------------------------------------------------------------------*/
2410 SwField* SwRefPageGetField::Copy() const
2412 SwRefPageGetField* pCpy = new SwRefPageGetField(
2413 (SwRefPageGetFieldType*)GetTyp(), GetFormat() );
2414 pCpy->SetText( sTxt );
2415 return pCpy;
2417 /* ---------------------------------------------------------------------------
2419 ---------------------------------------------------------------------------*/
2420 void SwRefPageGetField::ChangeExpansion( const SwFrm* pFrm,
2421 const SwTxtFld* pFld )
2423 // nur Felder in Footer, Header, FootNote, Flys
2424 SwTxtNode* pTxtNode = (SwTxtNode*)&pFld->GetTxtNode();
2425 SwRefPageGetFieldType* pGetType = (SwRefPageGetFieldType*)GetTyp();
2426 SwDoc* pDoc = pGetType->GetDoc();
2427 if( pFld->GetTxtNode().StartOfSectionIndex() >
2428 pDoc->GetNodes().GetEndOfExtras().GetIndex() )
2429 return;
2431 sTxt.Erase();
2433 ASSERT( !pFrm->IsInDocBody(), "Flag ist nicht richtig, Frame steht im DocBody" );
2435 // sammel erstmal alle SetPageRefFelder ein.
2436 _SetGetExpFlds aTmpLst( 10, 5 );
2437 if( !pGetType->MakeSetList( aTmpLst ) )
2438 return ;
2440 // einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2441 SwPosition aPos( SwNodeIndex( pDoc->GetNodes() ) );
2442 pTxtNode = (SwTxtNode*) GetBodyTxtNode( *pDoc, aPos, *pFrm );
2444 // Wenn kein Layout vorhanden, kommt es in Kopf und Fusszeilen dazu
2445 // das ChangeExpansion uebers Layout-Formatieren aufgerufen wird
2446 // aber kein TxtNode vorhanden ist
2448 if(!pTxtNode)
2449 return;
2451 _SetGetExpFld aEndFld( aPos.nNode, pFld, &aPos.nContent );
2453 sal_uInt16 nLast;
2454 aTmpLst.Seek_Entry( &aEndFld, &nLast );
2456 if( !nLast-- )
2457 return ; // es gibt kein entsprechendes Set - Feld vor mir
2459 const SwTxtFld* pRefTxtFld = aTmpLst[ nLast ]->GetFld();
2460 const SwRefPageSetField* pSetFld =
2461 (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld();
2462 Point aPt;
2463 const SwCntntFrm* pRefFrm = pRefTxtFld ? pRefTxtFld->GetTxtNode().GetFrm( &aPt, 0, sal_False ) : 0;
2464 if( pSetFld->IsOn() && pRefFrm )
2466 // dann bestimme mal den entsp. Offset
2467 const SwPageFrm* pPgFrm = pFrm->FindPageFrm();
2468 sal_uInt16 nDiff = pPgFrm->GetPhyPageNum() -
2469 pRefFrm->FindPageFrm()->GetPhyPageNum() + 1;
2471 SwRefPageGetField* pGetFld = (SwRefPageGetField*)pFld->GetFld().GetFld();
2472 sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
2473 ? pPgFrm->GetPageDesc()->GetNumType().GetNumberingType()
2474 : pGetFld->GetFormat();
2475 short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff ));
2476 pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
2479 /*-----------------05.03.98 14:52-------------------
2481 --------------------------------------------------*/
2482 BOOL SwRefPageGetField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
2484 switch( nWhichId )
2486 case FIELD_PROP_USHORT1:
2487 rAny <<= (sal_Int16)GetFormat();
2488 break;
2489 case FIELD_PROP_PAR1:
2490 rAny <<= OUString(sTxt);
2491 break;
2492 default:
2493 DBG_ERROR("illegal property");
2495 return sal_True;
2497 /*-----------------05.03.98 14:52-------------------
2499 --------------------------------------------------*/
2500 BOOL SwRefPageGetField::PutValue( const uno::Any& rAny, USHORT nWhichId )
2502 switch( nWhichId )
2504 case FIELD_PROP_USHORT1:
2506 sal_Int16 nSet = 0;
2507 rAny >>= nSet;
2508 if(nSet <= SVX_NUM_PAGEDESC )
2509 SetFormat(nSet);
2510 else {
2511 //exception(wrong_value)
2515 break;
2516 case FIELD_PROP_PAR1:
2518 OUString sTmp;
2519 rAny >>= sTmp;
2520 sTxt = sTmp;
2522 break;
2523 default:
2524 DBG_ERROR("illegal property");
2526 return sal_True;
2529 /*--------------------------------------------------------------------
2530 Beschreibung: Feld zum Anspringen und Editieren
2531 --------------------------------------------------------------------*/
2533 SwJumpEditFieldType::SwJumpEditFieldType( SwDoc* pD )
2534 : SwFieldType( RES_JUMPEDITFLD ), pDoc( pD ), aDep( this, 0 )
2537 /* ---------------------------------------------------------------------------
2539 ---------------------------------------------------------------------------*/
2540 SwFieldType* SwJumpEditFieldType::Copy() const
2542 return new SwJumpEditFieldType( pDoc );
2544 /* ---------------------------------------------------------------------------
2546 ---------------------------------------------------------------------------*/
2547 SwCharFmt* SwJumpEditFieldType::GetCharFmt()
2549 SwCharFmt* pFmt = pDoc->GetCharFmtFromPool( RES_POOLCHR_JUMPEDIT );
2551 // noch nicht registriert ?
2552 if( !aDep.GetRegisteredIn() )
2553 pFmt->Add( &aDep ); // anmelden
2555 return pFmt;
2557 /* ---------------------------------------------------------------------------
2559 ---------------------------------------------------------------------------*/
2560 SwJumpEditField::SwJumpEditField( SwJumpEditFieldType* pTyp, sal_uInt32 nForm,
2561 const String& rTxt, const String& rHelp )
2562 : SwField( pTyp, nForm ), sTxt( rTxt ), sHelp( rHelp )
2565 /* ---------------------------------------------------------------------------
2567 ---------------------------------------------------------------------------*/
2568 String SwJumpEditField::Expand() const
2570 String sTmp( '<' );
2571 sTmp += sTxt;
2572 return sTmp += '>';
2574 /* ---------------------------------------------------------------------------
2576 ---------------------------------------------------------------------------*/
2577 SwField* SwJumpEditField::Copy() const
2579 return new SwJumpEditField( (SwJumpEditFieldType*)GetTyp(), GetFormat(),
2580 sTxt, sHelp );
2582 /* ---------------------------------------------------------------------------
2584 ---------------------------------------------------------------------------*/
2585 // Platzhalter-Text
2587 const String& SwJumpEditField::GetPar1() const
2589 return sTxt;
2591 /* ---------------------------------------------------------------------------
2593 ---------------------------------------------------------------------------*/
2594 void SwJumpEditField::SetPar1(const String& rStr)
2596 sTxt = rStr;
2599 // HinweisText
2600 /* ---------------------------------------------------------------------------
2602 ---------------------------------------------------------------------------*/
2603 String SwJumpEditField::GetPar2() const
2605 return sHelp;
2607 /* ---------------------------------------------------------------------------
2609 ---------------------------------------------------------------------------*/
2610 void SwJumpEditField::SetPar2(const String& rStr)
2612 sHelp = rStr;
2615 /*-----------------05.03.98 15:00-------------------
2617 --------------------------------------------------*/
2618 BOOL SwJumpEditField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
2620 switch( nWhichId )
2622 case FIELD_PROP_USHORT1:
2624 sal_Int16 nRet;
2625 switch( GetFormat() )
2627 case JE_FMT_TABLE: nRet = text::PlaceholderType::TABLE; break;
2628 case JE_FMT_FRAME: nRet = text::PlaceholderType::TEXTFRAME; break;
2629 case JE_FMT_GRAPHIC:nRet = text::PlaceholderType::GRAPHIC; break;
2630 case JE_FMT_OLE: nRet = text::PlaceholderType::OBJECT; break;
2631 // case JE_FMT_TEXT:
2632 default:
2633 nRet = text::PlaceholderType::TEXT; break;
2635 rAny <<= nRet;
2637 break;
2638 case FIELD_PROP_PAR1 :
2639 rAny <<= OUString(sHelp);
2640 break;
2641 case FIELD_PROP_PAR2 :
2642 rAny <<= OUString(sTxt);
2643 break;
2644 default:
2645 DBG_ERROR("illegal property");
2647 return sal_True;
2649 /*-----------------05.03.98 15:00-------------------
2651 --------------------------------------------------*/
2652 BOOL SwJumpEditField::PutValue( const uno::Any& rAny, USHORT nWhichId )
2654 switch( nWhichId )
2656 case FIELD_PROP_USHORT1:
2658 //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
2659 // called with a int32 value! But normally we need
2660 // here only a int16
2661 sal_Int32 nSet = 0;
2662 rAny >>= nSet;
2663 switch( nSet )
2665 case text::PlaceholderType::TEXT : SetFormat(JE_FMT_TEXT); break;
2666 case text::PlaceholderType::TABLE : SetFormat(JE_FMT_TABLE); break;
2667 case text::PlaceholderType::TEXTFRAME: SetFormat(JE_FMT_FRAME); break;
2668 case text::PlaceholderType::GRAPHIC : SetFormat(JE_FMT_GRAPHIC); break;
2669 case text::PlaceholderType::OBJECT : SetFormat(JE_FMT_OLE); break;
2672 break;
2673 case FIELD_PROP_PAR1 :
2674 ::GetString( rAny, sHelp );
2675 break;
2676 case FIELD_PROP_PAR2 :
2677 ::GetString( rAny, sTxt);
2678 break;
2679 default:
2680 DBG_ERROR("illegal property");
2682 return sal_True;
2686 /*--------------------------------------------------------------------
2687 Beschreibung: Combined Character Fieldtype / Field
2688 --------------------------------------------------------------------*/
2690 SwCombinedCharFieldType::SwCombinedCharFieldType()
2691 : SwFieldType( RES_COMBINED_CHARS )
2695 SwFieldType* SwCombinedCharFieldType::Copy() const
2697 return new SwCombinedCharFieldType;
2700 /* --------------------------------------------------------------------*/
2702 SwCombinedCharField::SwCombinedCharField( SwCombinedCharFieldType* pFTyp,
2703 const String& rChars )
2704 : SwField( pFTyp, 0 ),
2705 sCharacters( rChars.Copy( 0, MAX_COMBINED_CHARACTERS ))
2709 String SwCombinedCharField::Expand() const
2711 return sCharacters;
2714 SwField* SwCombinedCharField::Copy() const
2716 return new SwCombinedCharField( (SwCombinedCharFieldType*)GetTyp(),
2717 sCharacters );
2720 const String& SwCombinedCharField::GetPar1() const
2722 return sCharacters;
2725 void SwCombinedCharField::SetPar1(const String& rStr)
2727 sCharacters = rStr.Copy( 0, MAX_COMBINED_CHARACTERS );
2730 BOOL SwCombinedCharField::QueryValue( uno::Any& rAny,
2731 USHORT nWhichId ) const
2733 switch( nWhichId )
2735 case FIELD_PROP_PAR1:
2736 rAny <<= rtl::OUString( sCharacters );
2737 break;
2738 default:
2739 DBG_ERROR("illegal property");
2741 return sal_True;
2744 BOOL SwCombinedCharField::PutValue( const uno::Any& rAny,
2745 USHORT nWhichId )
2747 switch( nWhichId )
2749 case FIELD_PROP_PAR1:
2750 ::GetString( rAny, sCharacters ).Erase( MAX_COMBINED_CHARACTERS );
2751 break;
2752 default:
2753 DBG_ERROR("illegal property");
2755 return sal_True;