Replace workaround of resize to invalidate with an explicit SfxHint
[LibreOffice.git] / sw / inc / fmtfld.hxx
blob3976152b5822fea6d19c399835c67aea5e7a3d72
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) : 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
101 : public SfxPoolItem
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;
117 public:
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();
136 SwField* GetField()
138 return mpField.get();
142 Sets current field.
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
152 return mpTextField;
154 SwTextField* GetTextField()
156 return mpTextField;
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
178 INSERTED = 1,
179 REMOVED = 2,
180 FOCUS = 3,
181 CHANGED = 4,
182 RESOLVED = 5,
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;
197 public:
198 SwFormatFieldHint( const SwFormatField* pField, SwFormatFieldHintWhich nWhich, const SwView* pView = nullptr)
199 : SfxHint(SfxHintId::SwFormatField)
200 , m_pField(pField)
201 , m_nWhich(nWhich)
202 , m_pView(pView)
205 const SwFormatField* GetField() const { return m_pField; }
206 SwFormatFieldHintWhich Which() const { return m_nWhich; }
207 const SwView* GetView() const { return m_pView; }
210 #endif
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */