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 .
20 #ifndef INCLUDED_SW_INC_FMTFLD_HXX
21 #define INCLUDED_SW_INC_FMTFLD_HXX
23 #include <cppuhelper/weakref.hxx>
24 #include <svl/poolitem.hxx>
25 #include <svl/SfxBroadcaster.hxx>
26 #include <com/sun/star/text/XTextField.hpp>
27 #include <unotools/weakref.hxx>
30 #include "swtypes.hxx"
33 #include "nodeoffset.hxx"
42 class IDocumentRedlineAccess
;
45 struct FindFormatForFieldHint final
: SfxHint
{
46 const SwField
* m_pField
;
47 SwFormatField
*& m_rpFormat
;
48 FindFormatForFieldHint(const SwField
* pField
, SwFormatField
*& rpFormat
)
49 : SfxHint(SfxHintId::SwFindFormatForField
), m_pField(pField
), m_rpFormat(rpFormat
) {};
51 struct FindFormatForPostItIdHint final
: SfxHint
{
52 const sal_uInt32 m_nPostItId
;
53 SwFormatField
*& m_rpFormat
;
54 FindFormatForPostItIdHint(const sal_uInt32 nPostItId
, SwFormatField
*& rpFormat
)
55 : SfxHint(SfxHintId::SwFindFormatForPostItId
), m_nPostItId(nPostItId
), m_rpFormat(rpFormat
) {};
57 struct CollectPostItsHint final
: SfxHint
{
58 std::vector
<SwFormatField
*>& m_rvFormatFields
;
59 IDocumentRedlineAccess
const& m_rIDRA
;
60 const bool m_bHideRedlines
;
61 CollectPostItsHint(std::vector
<SwFormatField
*>& rvFormatFields
, IDocumentRedlineAccess
const& rIDRA
, bool bHideRedlines
)
62 : SfxHint(SfxHintId::SwCollectPostIts
),
63 m_rvFormatFields(rvFormatFields
), m_rIDRA(rIDRA
), m_bHideRedlines(bHideRedlines
) {};
65 struct HasHiddenInformationNotesHint final
: SfxHint
{
66 bool& m_rbHasHiddenInformationNotes
;
67 HasHiddenInformationNotesHint(bool& rbHasHiddenInformationNotes
)
68 : SfxHint(SfxHintId::SwHasHiddenInformationNotes
),
69 m_rbHasHiddenInformationNotes(rbHasHiddenInformationNotes
) {};
71 struct GatherNodeIndexHint final
: SfxHint
{
72 std::vector
<SwNodeOffset
>& m_rvNodeIndex
;
73 GatherNodeIndexHint(std::vector
<SwNodeOffset
>& rvNodeIndex
)
74 : SfxHint(SfxHintId::SwGatherNodeIndex
),
75 m_rvNodeIndex(rvNodeIndex
) {};
77 struct GatherRefFieldsHint final
: SfxHint
{
78 std::vector
<SwGetRefField
*>& m_rvRFields
;
79 const sal_uInt16 m_nType
;
80 GatherRefFieldsHint(std::vector
<SwGetRefField
*>& rvRFields
, const sal_uInt16 nType
)
81 : SfxHint(SfxHintId::SwGatherRefFields
),
82 m_rvRFields(rvRFields
), m_nType(nType
) {};
84 struct GatherFieldsHint final
: SfxHint
{
85 const bool m_bCollectOnlyInDocNodes
;
86 std::vector
<SwFormatField
*>& m_rvFields
;
87 GatherFieldsHint(std::vector
<SwFormatField
*>& rvFields
, bool bCollectOnlyInDocNodes
= true)
88 : SfxHint(SfxHintId::SwGatherFields
),
89 m_bCollectOnlyInDocNodes(bCollectOnlyInDocNodes
), m_rvFields(rvFields
) {};
91 struct GatherDdeTablesHint final
: SfxHint
{
92 std::vector
<SwDDETable
*>& m_rvTables
;
93 GatherDdeTablesHint(std::vector
<SwDDETable
*>& rvTables
) : SfxHint(SfxHintId::SwGatherDdeTables
), m_rvTables(rvTables
) {};
98 /// SfxPoolItem subclass that is a wrapper around an SwField, i.e. one inserted field into paragraph
99 /// text. Typically owned by an SwTextField.
100 class SW_DLLPUBLIC SwFormatField final
102 , public sw::BroadcastingModify
103 , public SfxBroadcaster
105 friend SwFormatField
* createSwFormatFieldForItemInfoPackage(sal_uInt16
);
106 // friend class ItemInfoPackageSwAttributes;
107 friend void InitCore();
108 SwFormatField( sal_uInt16 nWhich
); // for default-Attribute
110 unotools::WeakReference
<SwXTextField
> m_wXTextField
;
112 std::unique_ptr
<SwField
> mpField
;
113 SwTextField
* mpTextField
; // the TextAttribute
115 virtual void SwClientNotify( const SwModify
& rModify
, const SfxHint
& rHint
) override
;
119 /// Single argument constructors shall be explicit.
120 explicit SwFormatField( const SwField
&rField
);
122 SwFormatField( const SwFormatField
& rAttr
);
124 virtual ~SwFormatField() override
;
126 /// "Pure virtual methods" of SfxPoolItem.
127 virtual bool operator==( const SfxPoolItem
& ) const override
;
128 virtual SwFormatField
* Clone( SfxItemPool
* pPool
= nullptr ) const override
;
130 void InvalidateField();
132 const SwField
* GetField() const
134 return mpField
.get();
138 return mpField
.get();
144 @param pField new field
146 @attention The current field will be destroyed before setting the new field.
148 void SetField( std::unique_ptr
<SwField
> pField
);
150 const SwTextField
* GetTextField() const
154 SwTextField
* GetTextField()
158 void SetTextField( SwTextField
& rTextField
);
159 void ClearTextField();
161 void RegisterToFieldType( SwFieldType
& );
162 bool IsFieldInDoc() const;
163 bool IsProtect() const;
165 SAL_DLLPRIVATE
unotools::WeakReference
<SwXTextField
> const& GetXTextField() const
166 { return m_wXTextField
; }
167 SAL_DLLPRIVATE
void SetXTextField(rtl::Reference
<SwXTextField
> const& xTextField
);
169 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
171 void ForceUpdateTextNode();
172 void UpdateTextNode(const SfxHint
& rHint
);
173 void UpdateDocPos(const SwTwips nDocPos
);
176 enum class SwFormatFieldHintWhich
183 REDLINED_DELETION
= 6
186 /// This SfxHint subclass is produced by code that changes the doc model (e.g. SwNodes::ChgNode()),
187 /// the typical which id is SwFormatFieldHintWhich::INSERTED or SwFormatFieldHintWhich::REMOVED.
189 /// The consumer of this hint is SwPostItMgr::Notify(), i.e. the sidebar on the right hand side of
190 /// the Writer edit window that hosts the comments as post-its.
191 class SW_DLLPUBLIC SwFormatFieldHint final
: public SfxHint
193 const SwFormatField
* m_pField
;
194 SwFormatFieldHintWhich m_nWhich
;
195 const SwView
* m_pView
;
198 SwFormatFieldHint( const SwFormatField
* pField
, SwFormatFieldHintWhich nWhich
, const SwView
* pView
= nullptr)
199 : SfxHint(SfxHintId::SwFormatField
)
205 const SwFormatField
* GetField() const { return m_pField
; }
206 SwFormatFieldHintWhich
Which() const { return m_nWhich
; }
207 const SwView
* GetView() const { return m_pView
; }
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */