summaryrefslogtreecommitdiff
path: root/sw/inc
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-11-08 08:14:41 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-11-08 09:25:40 +0100
commitad950f10dc382ea169f94a0c301ca8c424e7103e (patch)
tree15b1145110a355dfc06c2d7fd865a976e13752e6 /sw/inc
parent6d6a143913603b040c10a5db83c2103557899011 (diff)
sw: introduce a manager for content controls
The VBA API for content controls can access e.g. the 3rd content control in the document, see <https://learn.microsoft.com/en-us/office/vba/api/word.contentcontrols>. To support something similar, first we need to track the content controls in the document, otherwise getting the Nth element of that list would require scanning the entire document, which would be slow. SwContentControlManager::m_aContentControls is a plain vector, because an o3tl::sorted_vector would require sorting at insert time, but our content controls are typically first created and only later inserted, and we want to use the insert position as the comparison key when sorting. This just keeps track of content controls (visible in the doc model XML dump), somewhat similar to sw::MetaFieldManager or SwFootnoteIdxs. UNO API to actually expose this is not yet added. Change-Id: I3f75334ffef684afc2c05a1bbdb7f247876d27ad Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142391 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/inc')
-rw-r--r--sw/inc/doc.hxx3
-rw-r--r--sw/inc/formatcontentcontrol.hxx1
-rw-r--r--sw/inc/textcontentcontrol.hxx23
3 files changed, 25 insertions, 2 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 62785cb8bce8..de5ec6112a00 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -133,6 +133,7 @@ class IDocumentExternalData;
class IDocumentMarkAccess;
class SetGetExpFields;
struct SwInsertTableOptions;
+class SwContentControlManager;
enum class SvMacroItemId : sal_uInt16;
enum class SvxFrameDirection;
enum class RndStdIds;
@@ -213,6 +214,7 @@ class SW_DLLPUBLIC SwDoc final
const std::unique_ptr< ::sw::mark::MarkManager> mpMarkManager;
const std::unique_ptr< ::sw::MetaFieldManager > m_pMetaFieldManager;
+ const std::unique_ptr< ::SwContentControlManager > m_pContentControlManager;
const std::unique_ptr< ::sw::DocumentDrawModelManager > m_pDocumentDrawModelManager;
const std::unique_ptr< ::sw::DocumentRedlineManager > m_pDocumentRedlineManager;
const std::unique_ptr< ::sw::DocumentStateManager > m_pDocumentStateManager;
@@ -1633,6 +1635,7 @@ public:
const css::uno::Reference< css::container::XNameContainer >& GetVBATemplateToProjectCache() const { return m_xTemplateToProjectCache; };
::sfx2::IXmlIdRegistry& GetXmlIdRegistry();
::sw::MetaFieldManager & GetMetaFieldManager();
+ ::SwContentControlManager& GetContentControlManager();
::sw::UndoManager & GetUndoManager();
::sw::UndoManager const& GetUndoManager() const;
diff --git a/sw/inc/formatcontentcontrol.hxx b/sw/inc/formatcontentcontrol.hxx
index 8cfa71dd04ba..adbc4c10a3e6 100644
--- a/sw/inc/formatcontentcontrol.hxx
+++ b/sw/inc/formatcontentcontrol.hxx
@@ -78,6 +78,7 @@ public:
* (re-)moved.
*/
void NotifyChangeTextNode(SwTextNode* pTextNode);
+ SwTextNode* GetTextNode() const;
static SwFormatContentControl* CreatePoolDefault(sal_uInt16 nWhich);
const std::shared_ptr<SwContentControl>& GetContentControl() const { return m_pContentControl; }
diff --git a/sw/inc/textcontentcontrol.hxx b/sw/inc/textcontentcontrol.hxx
index 1c445d812099..dc7d210f79a6 100644
--- a/sw/inc/textcontentcontrol.hxx
+++ b/sw/inc/textcontentcontrol.hxx
@@ -20,15 +20,19 @@
#include "txatbase.hxx"
+class SwContentControlManager;
class SwFormatContentControl;
/// SwTextAttr subclass that tracks the location of the wrapped SwFormatContentControl.
class SW_DLLPUBLIC SwTextContentControl final : public SwTextAttrNesting
{
- SwTextContentControl(SwFormatContentControl& rAttr, sal_Int32 nStart, sal_Int32 nEnd);
+ SwContentControlManager* m_pManager;
+
+ SwTextContentControl(SwContentControlManager* pManager, SwFormatContentControl& rAttr,
+ sal_Int32 nStart, sal_Int32 nEnd);
public:
- static SwTextContentControl* CreateTextContentControl(SwTextNode* pTargetTextNode,
+ static SwTextContentControl* CreateTextContentControl(SwDoc& rDoc, SwTextNode* pTargetTextNode,
SwFormatContentControl& rAttr,
sal_Int32 nStart, sal_Int32 nEnd,
bool bIsCopy);
@@ -37,7 +41,22 @@ public:
void ChgTextNode(SwTextNode* pNode);
+ SwTextNode* GetTextNode() const;
+
void dumpAsXml(xmlTextWriterPtr pWriter) const override;
};
+/// Knows all the text content controls in the document.
+class SW_DLLPUBLIC SwContentControlManager
+{
+ /// Non-owning reference to text content controls.
+ std::vector<SwTextContentControl*> m_aContentControls;
+
+public:
+ SwContentControlManager();
+ void Insert(SwTextContentControl* pTextContentControl);
+ void Erase(SwTextContentControl* pTextContentControl);
+ void dumpAsXml(xmlTextWriterPtr pWriter) const;
+};
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */