a11y: Simplify OCommonAccessibleComponent::getAccessibleIndexInParent
[LibreOffice.git] / sw / inc / fmtmeta.hxx
blobb7f9758484c4599345bc5b6d6fb3902eedab0598
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_FMTMETA_HXX
21 #define INCLUDED_SW_INC_FMTMETA_HXX
23 #include "calbck.hxx"
25 #include <unotools/weakref.hxx>
27 #include <svl/poolitem.hxx>
28 #include <sfx2/Metadatable.hxx>
30 #include <memory>
31 #include <vector>
33 namespace com::sun::star {
34 namespace document {
35 class XDocumentProperties;
37 namespace text {
38 class XTextField;
42 /**
43 * The classes that make up a meta entity are:
44 * <dl>
45 * <dt>SwTextMeta</dt><dd>the text hint</dd>
46 * <dt>SwFormatMeta</dt><dd>the pool item</dd>
47 * <dt>sw::Meta</dt><dd>the metadatable entity itself</dd>
48 * <dt>SwXMeta</dt><dd>the UNO wrapper object</dd>
49 * </dl>
51 * The text hint contains the pool item (as usual) and has a pointer to the
52 * text node at which it is attached.
53 * The pool item has a shared pointer to the metadatable entity, and a reverse
54 * pointer to the text attribute at which it is attached.
55 * The pool item is non-poolable; it may only be attached to one text
56 * attribute.
57 * Of all the pool items that refer to a metadatable entity, only one may be
58 * in the document content at any time. Others may be in the undo array, or in
59 * undo objects.
60 * The metadatable entity has a reverse pointer to the pool item that is
61 * currently in the document. It also registers as a client at the text node
62 * at which it is attached via this pool item and its text attribute.
63 * The UNO wrapper object registers as a client at the metadatable entity.
65 * Copying the metadatable entity proceeds in the following way:
66 * <ol>
67 * <li>The pool item is cloned (because it is non-poolable); the clone
68 * points to the same metadatable entity, but the metadatable entity's
69 * reverse pointer is unchanged.</li>
70 * <li>The DoCopy() method is called at the new pool item:
71 * it will clone the metadatable entity (using RegisterAsCopyOf).
72 * This is necessary, because first, a metadatable entity may
73 * only be inserted once into a document, and second, the copy may be
74 * inserted into a different document than the source document!</li>
75 * <li>A new text hint is created, taking over the new pool item.</li>
76 * <li>The text hint is inserted into the hints array of some text node.</li>
77 * </ol>
80 class SwTextMeta;
81 class SwXMeta;
82 class SwXMetaField;
83 class SwTextNode;
84 class SwDoc;
85 namespace sw {
86 class Meta;
87 class MetaFieldManager;
90 /// SwFormatMeta is a pool item subclass that owns a Meta.
91 class SwFormatMeta final
92 : public SfxPoolItem
94 private:
95 friend class SwTextMeta; ///< needs SetTextAttr, DoCopy
96 friend class ::sw::Meta; ///< needs m_pTextAttr
98 std::shared_ptr< ::sw::Meta > m_pMeta;
99 SwTextMeta * m_pTextAttr;
101 SwTextMeta * GetTextAttr() { return m_pTextAttr; }
102 void SetTextAttr(SwTextMeta * const i_pTextAttr);
104 /// this method <em>must</em> be called when the hint is actually copied
105 void DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
106 SwTextNode & i_rTargetTextNode);
108 explicit SwFormatMeta( const sal_uInt16 i_nWhich );
110 public:
111 /// takes ownership
112 explicit SwFormatMeta( std::shared_ptr< ::sw::Meta > i_pMeta,
113 const sal_uInt16 i_nWhich );
114 virtual ~SwFormatMeta() override;
116 /// SfxPoolItem
117 virtual bool operator==( const SfxPoolItem & ) const override;
118 virtual SwFormatMeta* Clone( SfxItemPool *pPool = nullptr ) const override;
120 /// notify clients registered at m_pMeta that this meta is being (re-)moved
121 void NotifyChangeTextNode(SwTextNode *const pTextNode);
122 static SwFormatMeta * CreatePoolDefault( const sal_uInt16 i_nWhich );
123 ::sw::Meta * GetMeta() { return m_pMeta.get(); }
126 namespace sw {
128 /// Meta is an annotation on a range of text. There is no UI to insert such annotations, but the UNO
129 /// API can do so.
131 /// See
132 /// <https://wiki.documentfoundation.org/Documentation/DevGuide/Office_Development#Annotated_text_range>
133 /// for more details.
134 class Meta
135 : public ::sfx2::Metadatable
136 , public sw::BroadcastingModify
138 friend class ::SwFormatMeta; ///< SetFormatMeta, NotifyChangeTextNode
139 friend class ::SwXMeta; ///< GetTextNode, GetTextAttr, Get/SetXMeta
141 unotools::WeakReference<SwXMeta> m_wXMeta;
143 SwFormatMeta * m_pFormat;
144 SwTextNode * m_pTextNode;
146 protected:
148 SwTextMeta * GetTextAttr() const;
149 SwTextNode * GetTextNode() const { return m_pTextNode;} ///< @return 0 if not in document (undo)
151 SwFormatMeta * GetFormatMeta() const { return m_pFormat; }
152 void SetFormatMeta( SwFormatMeta * const i_pFormat ) { m_pFormat = i_pFormat; };
154 void NotifyChangeTextNode(SwTextNode *const pTextNode);
156 unotools::WeakReference<SwXMeta> const& GetXMeta() const
157 { return m_wXMeta; }
158 void SetXMeta(rtl::Reference<SwXMeta> const& xMeta);
160 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
162 public:
163 explicit Meta(SwFormatMeta * const i_pFormat);
164 virtual ~Meta() override;
166 /// sfx2::Metadatable
167 virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
168 virtual bool IsInClipboard() const override;
169 virtual bool IsInUndo() const override;
170 virtual bool IsInContent() const override;
171 virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
174 class MetaField final
175 : public Meta
177 private:
178 friend class ::SwFormatMeta;
179 friend class ::SwXMetaField;
180 friend class ::sw::MetaFieldManager;
182 sal_uInt32 m_nNumberFormat;
183 bool m_bIsFixedLanguage;
185 sal_uInt32 GetNumberFormat(const OUString& aContent) const;
186 void SetNumberFormat(sal_uInt32 nNumberFormat);
187 bool IsFixedLanguage() const { return m_bIsFixedLanguage; }
188 void SetIsFixedLanguage(bool b) { m_bIsFixedLanguage = b; }
190 explicit MetaField(SwFormatMeta * const i_pFormat,
191 const sal_uInt32 nNumberFormat,
192 const bool bIsFixedLanguage );
194 public:
195 /// get prefix/suffix from the RDF repository. @throws RuntimeException
196 void GetPrefixAndSuffix(
197 OUString *const o_pPrefix, OUString *const o_pSuffix, OUString *const o_pShadingColor);
200 /// knows all meta-fields in the document.
201 class SW_DLLPUBLIC MetaFieldManager
203 private:
204 typedef std::vector< std::weak_ptr<MetaField> > MetaFieldList_t;
205 MetaFieldList_t m_MetaFields;
206 /// Document properties of a clipboard document, empty for non-clipboard documents.
207 css::uno::Reference<css::document::XDocumentProperties> m_xDocumentProperties;
209 MetaFieldManager(MetaFieldManager const&) = delete;
210 MetaFieldManager& operator=(MetaFieldManager const&) = delete;
212 public:
213 MetaFieldManager();
214 std::shared_ptr<MetaField> makeMetaField(
215 SwFormatMeta * const i_pFormat = nullptr,
216 const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
217 const bool bIsFixedLanguage = false );
218 /// get all meta fields
219 std::vector< css::uno::Reference<css::text::XTextField> > getMetaFields();
220 /// Copy document properties from rSource to m_xDocumentProperties.
221 void copyDocumentProperties(const SwDoc& rSource);
222 const css::uno::Reference<css::document::XDocumentProperties>& getDocumentProperties() const;
225 } // namespace sw
227 #endif // INCLUDED_SW_INC_FMTMETA_HXX
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */