1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SW_INC_DOCUFLD_HXX
20 #define INCLUDED_SW_INC_DOCUFLD_HXX
22 #include <tools/date.hxx>
23 #include <tools/datetime.hxx>
24 #include <rtl/ref.hxx>
25 #include <svl/macitem.hxx>
28 #include "numrule.hxx"
30 class SetGetExpFields
;
33 class OutlinerParaObject
;
34 class SwTextAPIObject
;
45 // Subtype of document statistics.
58 typedef sal_uInt16 SwDocInfoSubType
;
59 namespace nsSwDocInfoSubType
61 /** NB: these must denote consecutive integers!
62 NB2: these are extended by 4 DI_INFO values for backward compatibility
63 in filter/html/htmlfld.cxx, so make sure that DI_SUBTYPE_END
64 really is the end, and is at least 4 less than DI_SUB_*! */
65 const SwDocInfoSubType DI_SUBTYPE_BEGIN
= 0;
66 const SwDocInfoSubType DI_TITEL
= DI_SUBTYPE_BEGIN
;
67 const SwDocInfoSubType DI_THEMA
= 1;
68 const SwDocInfoSubType DI_KEYS
= 2;
69 const SwDocInfoSubType DI_COMMENT
= 3;
70 const SwDocInfoSubType DI_CREATE
= 4;
71 const SwDocInfoSubType DI_CHANGE
= 5;
72 const SwDocInfoSubType DI_PRINT
= 6;
73 const SwDocInfoSubType DI_DOCNO
= 7;
74 const SwDocInfoSubType DI_EDIT
= 8;
75 const SwDocInfoSubType DI_CUSTOM
= 9;
76 const SwDocInfoSubType DI_SUBTYPE_END
= 10;
78 const SwDocInfoSubType DI_SUB_AUTHOR
= 0x0100;
79 const SwDocInfoSubType DI_SUB_TIME
= 0x0200;
80 const SwDocInfoSubType DI_SUB_DATE
= 0x0300;
81 const SwDocInfoSubType DI_SUB_FIXED
= 0x1000;
82 const SwDocInfoSubType DI_SUB_MASK
= 0xff00;
92 // NOTE: Possibly the first 15 values in the below enum are required
93 // to exactly match the published constants in css::text::UserDataPart
94 // (see offapi/com/sun/star/text/UserDataPart.idl).
117 enum SwJumpEditFormat
126 class SwPageNumberFieldType
: public SwFieldType
128 SvxNumType nNumberingType
;
132 SwPageNumberFieldType();
134 OUString
Expand( SvxNumType nFormat
, short nOff
, sal_uInt16
const nPageNumber
,
135 sal_uInt16
const nMaxPage
, const OUString
& ) const;
136 void ChangeExpansion( SwDoc
* pDoc
,
137 bool bVirtPageNum
, const SvxNumType
* pNumFormat
);
138 virtual SwFieldType
* Copy() const override
;
142 class SW_DLLPUBLIC SwPageNumberField
: public SwField
147 // fdo#58074 store page number in SwField, not SwFieldType
148 sal_uInt16 m_nPageNumber
;
149 sal_uInt16 m_nMaxPage
;
152 SwPageNumberField(SwPageNumberFieldType
*, sal_uInt16 nSub
,
153 sal_uInt32 nFormat
= 0, short nOff
= 0,
154 sal_uInt16
const nPageNumber
= 0,
155 sal_uInt16
const nMaxPage
= 0);
157 void ChangeExpansion(sal_uInt16
const nPageNumber
,
158 sal_uInt16
const nMaxPage
);
160 virtual OUString
Expand() const override
;
161 virtual SwField
* Copy() const override
;
163 virtual OUString
GetPar2() const override
;
164 virtual void SetPar2(const OUString
& rStr
) override
;
166 virtual sal_uInt16
GetSubType() const override
;
167 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
168 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
170 const OUString
& GetUserString() const { return sUserStr
; }
171 void SetUserString( const OUString
& rS
) { sUserStr
= rS
; }
174 class SwAuthorFieldType
: public SwFieldType
179 static OUString
Expand(sal_uLong
);
180 virtual SwFieldType
* Copy() const override
;
183 class SwAuthorField
: public SwField
188 SwAuthorField(SwAuthorFieldType
*, sal_uInt32 nFormat
);
190 virtual OUString
Expand() const override
;
191 virtual SwField
* Copy() const override
;
193 void SetExpansion(const OUString
& rStr
) { aContent
= rStr
; }
195 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
196 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
199 class SwFileNameFieldType
: public SwFieldType
203 SwFileNameFieldType(SwDoc
*);
205 OUString
Expand(sal_uLong
) const;
206 virtual SwFieldType
* Copy() const override
;
209 class SW_DLLPUBLIC SwFileNameField
: public SwField
214 SwFileNameField(SwFileNameFieldType
*, sal_uInt32 nFormat
);
216 virtual OUString
Expand() const override
;
217 virtual SwField
* Copy() const override
;
219 void SetExpansion(const OUString
& rStr
) { aContent
= rStr
; }
221 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
222 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
225 class SwTemplNameFieldType
: public SwFieldType
229 SwTemplNameFieldType(SwDoc
*);
231 OUString
Expand(sal_uLong
) const;
232 virtual SwFieldType
* Copy() const override
;
235 class SW_DLLPUBLIC SwTemplNameField
: public SwField
238 SwTemplNameField(SwTemplNameFieldType
*, sal_uInt32 nFormat
);
240 virtual OUString
Expand() const override
;
241 virtual SwField
* Copy() const override
;
242 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
243 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
246 // Document statistics
247 class SwDocStatFieldType
: public SwFieldType
250 SvxNumType nNumberingType
;
253 SwDocStatFieldType(SwDoc
*);
254 OUString
Expand(sal_uInt16 nSubType
, SvxNumType nFormat
) const;
255 virtual SwFieldType
* Copy() const override
;
257 void SetNumFormat( SvxNumType eFormat
) { nNumberingType
= eFormat
; }
260 class SW_DLLPUBLIC SwDocStatField
: public SwField
265 SwDocStatField( SwDocStatFieldType
*,
266 sal_uInt16 nSubType
, sal_uInt32 nFormat
= 0);
268 void ChangeExpansion( const SwFrame
* pFrame
);
270 virtual OUString
Expand() const override
;
271 virtual SwField
* Copy() const override
;
273 virtual sal_uInt16
GetSubType() const override
;
274 virtual void SetSubType(sal_uInt16 nSub
) override
;
275 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
276 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
279 class SwHiddenTextFieldType
: public SwFieldType
283 SwHiddenTextFieldType(bool bSetHidden
= true);
285 virtual SwFieldType
* Copy() const override
;
287 void SetHiddenFlag( bool bSetHidden
);
288 bool GetHiddenFlag() const { return bHidden
; }
291 class SwHiddenTextField
: public SwField
293 OUString aTRUEText
; ///< Text if condition true.
294 OUString aFALSEText
; ///< If condition false.
295 OUString aContent
; ///< Evaluated DB-text.
297 OUString aCond
; ///< Condition.
300 bool bCanToggle
: 1; ///< Can field be toggled alone?
301 bool bIsHidden
: 1; ///< Is it not visible?
302 bool bValid
: 1; ///< Is DB-field evaluated?
304 virtual OUString
Expand() const override
;
305 virtual SwField
* Copy() const override
;
308 SwHiddenTextField( SwHiddenTextFieldType
*,
310 const OUString
& rCond
,
311 const OUString
& rText
,
312 bool bHidden
= false,
313 sal_uInt16 nSubType
= TYP_HIDDENTXTFLD
);
315 SwHiddenTextField( SwHiddenTextFieldType
*,
316 const OUString
& rCond
,
317 const OUString
& rTrue
,
318 const OUString
& rFalse
,
319 sal_uInt16 nSubType
= TYP_HIDDENTXTFLD
);
321 virtual OUString
GetFieldName() const override
;
323 void Evaluate(SwDoc
*);
325 void SetValue(bool bHidden
) { bIsHidden
= bHidden
; }
326 static OUString
GetColumnName(const OUString
& rName
);
327 static OUString
GetDBName(const OUString
& rName
, SwDoc
*pDoc
);
330 virtual void SetPar1(const OUString
& rStr
) override
;
331 virtual OUString
GetPar1() const override
;
333 /// True/False - String
334 virtual void SetPar2(const OUString
& rStr
) override
;
335 virtual OUString
GetPar2() const override
;
337 virtual sal_uInt16
GetSubType() const override
;
339 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
340 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
343 // Field that expands to an empty line (without height).
344 class SwHiddenParaFieldType
: public SwFieldType
347 SwHiddenParaFieldType();
349 virtual SwFieldType
* Copy() const override
;
352 class SwHiddenParaField
: public SwField
357 /// Direct input, delete old value.
358 SwHiddenParaField(SwHiddenParaFieldType
*, const OUString
& rCond
);
360 virtual OUString
Expand() const override
;
361 virtual SwField
* Copy() const override
;
363 void SetHidden(bool bHidden
) { bIsHidden
= bHidden
; }
364 bool IsHidden() const { return bIsHidden
; }
366 /// Query, set condition.
367 virtual OUString
GetPar1() const override
;
368 virtual void SetPar1(const OUString
& rStr
) override
;
369 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
370 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
373 class SwMacroFieldType
: public SwFieldType
378 SwMacroFieldType(SwDoc
*);
380 virtual SwFieldType
* Copy() const override
;
383 class SW_DLLPUBLIC SwMacroField
: public SwField
389 virtual OUString
Expand() const override
;
390 virtual SwField
* Copy() const override
;
393 /// Direct input, delete old value.
394 SwMacroField( SwMacroFieldType
*, const OUString
& rLibAndName
,
395 const OUString
& rText
);
397 const OUString
& GetMacro() const { return aMacro
; }
398 OUString
GetLibName() const;
399 OUString
GetMacroName() const;
400 SvxMacro
GetSvxMacro() const;
402 virtual OUString
GetFieldName() const override
;
404 /// Library and FileName
405 virtual OUString
GetPar1() const override
;
406 virtual void SetPar1(const OUString
& rStr
) override
;
409 virtual OUString
GetPar2() const override
;
410 virtual void SetPar2(const OUString
& rStr
) override
;
411 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
412 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
414 static void CreateMacroString( OUString
& rMacro
,
415 const OUString
& rMacroName
,
416 const OUString
& rLibraryName
);
418 static bool isScriptURL( const OUString
& str
);
421 class SwPostItFieldType
: public SwFieldType
426 SwPostItFieldType(SwDoc
* pDoc
);
428 virtual SwFieldType
* Copy() const override
;
430 SwDoc
* GetDoc() const
436 class SW_DLLPUBLIC SwPostItField
: public SwField
440 OUString sInitials
; ///< Initials of the author.
441 OUString sName
; ///< Name of the comment.
443 OutlinerParaObject
* mpText
;
444 rtl::Reference
<SwTextAPIObject
> m_xTextObject
;
445 sal_uInt32 m_nPostItId
;
448 static sal_uInt32 m_nLastPostItId
;
450 SwPostItField( SwPostItFieldType
*,
451 const OUString
& rAuthor
,
452 const OUString
& rText
,
453 const OUString
& rInitials
,
454 const OUString
& rName
,
455 const DateTime
& rDate
,
456 const sal_uInt32 nPostItId
= 0);
458 SwPostItField(const SwPostItField
&) = delete;
459 SwPostItField
* operator=(const SwPostItField
&) = delete;
461 virtual ~SwPostItField() override
;
463 virtual OUString
Expand() const override
;
464 virtual SwField
* Copy() const override
;
466 const DateTime
& GetDateTime() const { return aDateTime
; }
467 const Date
GetDate() const { return Date(aDateTime
.GetDate()); }
468 const tools::Time
GetTime() const { return aDateTime
.GetTime(); }
469 sal_uInt32
GetPostItId() const { return m_nPostItId
; }
472 virtual OUString
GetPar1() const override
;
473 virtual void SetPar1(const OUString
& rStr
) override
;
476 virtual OUString
GetPar2() const override
;
477 virtual void SetPar2(const OUString
& rStr
) override
;
478 const OUString
& GetText() const { return sText
; }
479 const OUString
& GetInitials() const { return sInitials
;}
480 void SetName(const OUString
& rStr
);
481 const OUString
& GetName() const { return sName
;}
483 const OutlinerParaObject
* GetTextObject() const { return mpText
;}
484 void SetTextObject( OutlinerParaObject
* pText
);
486 sal_Int32
GetNumberOfParagraphs() const;
488 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
489 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
490 virtual OUString
GetDescription() const override
;
491 virtual void dumpAsXml(struct _xmlTextWriter
* pWriter
) const override
;
494 class SwDocInfoFieldType
: public SwValueFieldType
497 SwDocInfoFieldType(SwDoc
* pDc
);
499 OUString
Expand(sal_uInt16 nSubType
, sal_uInt32 nFormat
, LanguageType nLang
, const OUString
& rName
) const;
500 virtual SwFieldType
* Copy() const override
;
503 class SW_DLLPUBLIC SwDocInfoField
: public SwValueField
509 virtual OUString
Expand() const override
;
510 virtual SwField
* Copy() const override
;
513 SwDocInfoField(SwDocInfoFieldType
*, sal_uInt16 nSub
, const OUString
& rName
, sal_uInt32 nFormat
=0);
514 SwDocInfoField(SwDocInfoFieldType
*, sal_uInt16 nSub
, const OUString
& rName
, const OUString
& rValue
, sal_uInt32 nFormat
=0);
516 virtual void SetSubType(sal_uInt16
) override
;
517 virtual sal_uInt16
GetSubType() const override
;
518 virtual void SetLanguage(LanguageType nLng
) override
;
519 virtual OUString
GetFieldName() const override
;
520 const OUString
& GetName() const { return aName
; }
521 void SetName( const OUString
& rName
) { aName
= rName
; }
522 void SetExpansion(const OUString
& rStr
) { aContent
= rStr
; }
523 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
524 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
527 // Extended User settings.
528 class SwExtUserFieldType
: public SwFieldType
531 SwExtUserFieldType();
533 static OUString
Expand(sal_uInt16 nSubType
, sal_uInt32 nFormat
);
534 virtual SwFieldType
* Copy() const override
;
537 class SwExtUserField
: public SwField
543 SwExtUserField(SwExtUserFieldType
*, sal_uInt16 nSub
, sal_uInt32 nFormat
);
545 virtual OUString
Expand() const override
;
546 virtual SwField
* Copy() const override
;
548 virtual sal_uInt16
GetSubType() const override
;
549 virtual void SetSubType(sal_uInt16 nSub
) override
;
551 void SetExpansion(const OUString
& rStr
) { aContent
= rStr
; }
553 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
554 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
557 // Relative page numbers - field.
558 class SwRefPageSetFieldType
: public SwFieldType
561 SwRefPageSetFieldType();
563 virtual SwFieldType
* Copy() const override
;
566 /// Overlay, because there is nothing to update!
567 virtual void Modify( const SfxPoolItem
*, const SfxPoolItem
* ) override
;
570 // Relative page numbering.
571 class SwRefPageSetField
: public SwField
577 SwRefPageSetField( SwRefPageSetFieldType
*, short nOff
,
580 virtual OUString
Expand() const override
;
581 virtual SwField
* Copy() const override
;
583 virtual OUString
GetPar2() const override
;
584 virtual void SetPar2(const OUString
& rStr
) override
;
586 bool IsOn() const { return bOn
; }
588 short GetOffset() const { return nOffset
; }
589 void SetOffset( short nOff
) { nOffset
= nOff
; }
590 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
591 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
594 // Relative page numbers - query field.
595 class SwRefPageGetFieldType
: public SwFieldType
598 sal_Int16 nNumberingType
;
600 void UpdateField( SwTextField
* pTextField
, SetGetExpFields
& rSetList
);
602 /// overwritten to update all RefPageGet fields
603 virtual void Modify( const SfxPoolItem
*, const SfxPoolItem
* ) override
;
605 SwRefPageGetFieldType( SwDoc
* pDoc
);
606 virtual SwFieldType
* Copy() const override
;
607 bool MakeSetList( SetGetExpFields
& rTmpLst
);
608 SwDoc
* GetDoc() const { return pDoc
; }
611 // Query relative page numbering.
612 class SwRefPageGetField
: public SwField
616 SwRefPageGetField( SwRefPageGetFieldType
*, sal_uInt32 nFormat
);
618 virtual OUString
Expand() const override
;
619 virtual SwField
* Copy() const override
;
621 void SetText( const OUString
& rText
) { sText
= rText
; }
623 void ChangeExpansion( const SwFrame
* pFrame
, const SwTextField
* pField
);
624 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
625 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
628 // Field to jump to and edit.
629 class SwJumpEditFieldType
: public SwFieldType
635 SwJumpEditFieldType( SwDoc
* pDoc
);
636 virtual SwFieldType
* Copy() const override
;
638 SwCharFormat
* GetCharFormat();
641 class SwJumpEditField
: public SwField
643 OUString sText
, sHelp
;
645 SwJumpEditField( SwJumpEditFieldType
*, sal_uInt32 nFormat
,
646 const OUString
& sText
, const OUString
& sHelp
);
648 virtual OUString
Expand() const override
;
649 virtual SwField
* Copy() const override
;
652 virtual OUString
GetPar1() const override
;
653 virtual void SetPar1(const OUString
& rStr
) override
;
656 virtual OUString
GetPar2() const override
;
657 virtual void SetPar2(const OUString
& rStr
) override
;
659 SwCharFormat
* GetCharFormat() const
660 { return static_cast<SwJumpEditFieldType
*>(GetTyp())->GetCharFormat(); }
661 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
662 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
665 class SwScriptFieldType
: public SwFieldType
669 SwScriptFieldType( SwDoc
* pDoc
);
671 virtual SwFieldType
* Copy() const override
;
674 class SwScriptField
: public SwField
676 OUString sType
; ///< Type of Code (Java/VBScript/...)
677 OUString sCode
; /**< Code as text.
678 Code as JavaCode ? */
680 bool bCodeURL
; ///< Code contains URL of a script.
683 SwScriptField( SwScriptFieldType
*, const OUString
& rType
,
684 const OUString
& rCode
, bool bURL
);
686 virtual OUString
GetDescription() const override
;
688 virtual OUString
Expand() const override
;
689 virtual SwField
* Copy() const override
;
692 virtual OUString
GetPar1() const override
;
693 virtual void SetPar1(const OUString
& rStr
) override
;
695 virtual OUString
GetPar2() const override
;
696 virtual void SetPar2(const OUString
& rStr
) override
;
698 bool IsCodeURL() const { return bCodeURL
; }
699 void SetCodeURL( bool bURL
) { bCodeURL
= bURL
; }
700 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
701 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
704 // Combined Character Fieldtype
705 class SwCombinedCharFieldType
: public SwFieldType
708 SwCombinedCharFieldType();
710 virtual SwFieldType
* Copy() const override
;
714 #define MAX_COMBINED_CHARACTERS 6
716 class SW_DLLPUBLIC SwCombinedCharField
: public SwField
718 OUString sCharacters
; ///< combine these characters
721 SwCombinedCharField( SwCombinedCharFieldType
*, const OUString
& rChars
);
723 virtual OUString
Expand() const override
;
724 virtual SwField
* Copy() const override
;
727 virtual OUString
GetPar1() const override
;
728 virtual void SetPar1(const OUString
& rStr
) override
;
730 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
731 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
734 #endif // INCLUDED_SW_INC_DOCUFLD_HXX
736 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */