Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / inc / fmtfld.hxx
blob6f5811539b179f4ffe287da9cd13eaa11cab220c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 #include "swdllapi.h"
30 #include "swtypes.hxx"
31 #include "calbck.hxx"
32 #include "reffld.hxx"
33 #include "nodeoffset.hxx"
35 class SwField;
36 class SwTextField;
37 class SwView;
38 class SwFieldType;
39 class SwDDETable;
40 class SwFormatField;
41 class SwXTextField;
42 class IDocumentRedlineAccess;
44 namespace sw {
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) : m_rvTables(rvTables) {};
98 // ATT_FLD
99 class SW_DLLPUBLIC SwFormatField final
100 : public SfxPoolItem
101 , public sw::BroadcastingModify
102 , public SfxBroadcaster
104 friend void InitCore();
105 SwFormatField( sal_uInt16 nWhich ); // for default-Attribute
107 unotools::WeakReference<SwXTextField> m_wXTextField;
109 std::unique_ptr<SwField> mpField;
110 SwTextField* mpTextField; // the TextAttribute
112 virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) override;
114 public:
116 /// Single argument constructors shall be explicit.
117 explicit SwFormatField( const SwField &rField );
119 SwFormatField( const SwFormatField& rAttr );
121 virtual ~SwFormatField() override;
123 /// "Pure virtual methods" of SfxPoolItem.
124 virtual bool operator==( const SfxPoolItem& ) const override;
125 virtual SwFormatField* Clone( SfxItemPool* pPool = nullptr ) const override;
127 virtual bool GetInfo( SfxPoolItem& rInfo ) const override;
129 void InvalidateField();
131 const SwField* GetField() const
133 return mpField.get();
135 SwField* GetField()
137 return mpField.get();
141 Sets current field.
143 @param pField new field
145 @attention The current field will be destroyed before setting the new field.
147 void SetField( std::unique_ptr<SwField> pField );
149 const SwTextField* GetTextField() const
151 return mpTextField;
153 SwTextField* GetTextField()
155 return mpTextField;
157 void SetTextField( SwTextField& rTextField );
158 void ClearTextField();
160 void RegisterToFieldType( SwFieldType& );
161 bool IsFieldInDoc() const;
162 bool IsProtect() const;
164 SAL_DLLPRIVATE unotools::WeakReference<SwXTextField> const& GetXTextField() const
165 { return m_wXTextField; }
166 SAL_DLLPRIVATE void SetXTextField(rtl::Reference<SwXTextField> const& xTextField);
168 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
170 void ForceUpdateTextNode();
171 void UpdateTextNode(const SfxHint& rHint);
172 void UpdateDocPos(const SwTwips nDocPos);
175 enum class SwFormatFieldHintWhich
177 INSERTED = 1,
178 REMOVED = 2,
179 FOCUS = 3,
180 CHANGED = 4,
181 LANGUAGE = 5,
182 RESOLVED = 6
185 class SW_DLLPUBLIC SwFormatFieldHint final : public SfxHint
187 const SwFormatField* m_pField;
188 SwFormatFieldHintWhich m_nWhich;
189 const SwView* m_pView;
191 public:
192 SwFormatFieldHint( const SwFormatField* pField, SwFormatFieldHintWhich nWhich, const SwView* pView = nullptr)
193 : m_pField(pField)
194 , m_nWhich(nWhich)
195 , m_pView(pView)
198 const SwFormatField* GetField() const { return m_pField; }
199 SwFormatFieldHintWhich Which() const { return m_nWhich; }
200 const SwView* GetView() const { return m_pView; }
203 #endif
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */