Resolves tdf#142513 - Order of ZoomIn and ZoomOut at Print Preview
[LibreOffice.git] / sw / inc / fmtmeta.hxx
blob441a7d5e6e6859845fb6900ec402ad02a7914715
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 <cppuhelper/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 class SwFormatMeta
91 : public SfxPoolItem
93 private:
94 friend class SwTextMeta; ///< needs SetTextAttr, DoCopy
95 friend class ::sw::Meta; ///< needs m_pTextAttr
97 std::shared_ptr< ::sw::Meta > m_pMeta;
98 SwTextMeta * m_pTextAttr;
100 SwTextMeta * GetTextAttr() { return m_pTextAttr; }
101 void SetTextAttr(SwTextMeta * const i_pTextAttr);
103 /// this method <em>must</em> be called when the hint is actually copied
104 void DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
105 SwTextNode & i_rTargetTextNode);
107 explicit SwFormatMeta( const sal_uInt16 i_nWhich );
109 public:
110 /// takes ownership
111 explicit SwFormatMeta( std::shared_ptr< ::sw::Meta > const & i_pMeta,
112 const sal_uInt16 i_nWhich );
113 virtual ~SwFormatMeta() override;
115 /// SfxPoolItem
116 virtual bool operator==( const SfxPoolItem & ) const override;
117 virtual SwFormatMeta* Clone( SfxItemPool *pPool = nullptr ) const override;
119 /// notify clients registered at m_pMeta that this meta is being (re-)moved
120 void NotifyChangeTextNode(SwTextNode *const pTextNode);
121 static SwFormatMeta * CreatePoolDefault( const sal_uInt16 i_nWhich );
122 ::sw::Meta * GetMeta() { return m_pMeta.get(); }
125 namespace sw {
127 class Meta
128 : public ::sfx2::Metadatable
129 , public sw::BroadcastingModify
131 friend class ::SwFormatMeta; ///< SetFormatMeta, NotifyChangeTextNode
132 friend class ::SwXMeta; ///< GetTextNode, GetTextAttr, Get/SetXMeta
134 css::uno::WeakReference<
135 css::rdf::XMetadatable> m_wXMeta;
137 SwFormatMeta * m_pFormat;
138 SwTextNode * m_pTextNode;
140 protected:
142 SwTextMeta * GetTextAttr() const;
143 SwTextNode * GetTextNode() const { return m_pTextNode;} ///< @return 0 if not in document (undo)
145 SwFormatMeta * GetFormatMeta() const { return m_pFormat; }
146 void SetFormatMeta( SwFormatMeta * const i_pFormat ) { m_pFormat = i_pFormat; };
148 void NotifyChangeTextNode(SwTextNode *const pTextNode);
150 css::uno::WeakReference<css::rdf::XMetadatable> const& GetXMeta() const
151 { return m_wXMeta; }
152 void SetXMeta(css::uno::Reference<css::rdf::XMetadatable> const& xMeta)
153 { m_wXMeta = xMeta; }
155 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
157 public:
158 explicit Meta(SwFormatMeta * const i_pFormat);
159 virtual ~Meta() override;
161 /// sfx2::Metadatable
162 virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
163 virtual bool IsInClipboard() const override;
164 virtual bool IsInUndo() const override;
165 virtual bool IsInContent() const override;
166 virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
169 class MetaField final
170 : public Meta
172 private:
173 friend class ::SwFormatMeta;
174 friend class ::SwXMetaField;
175 friend class ::sw::MetaFieldManager;
177 sal_uInt32 m_nNumberFormat;
178 bool m_bIsFixedLanguage;
180 sal_uInt32 GetNumberFormat(OUString const & rContent) const;
181 void SetNumberFormat(sal_uInt32 nNumberFormat);
182 bool IsFixedLanguage() const { return m_bIsFixedLanguage; }
183 void SetIsFixedLanguage(bool b) { m_bIsFixedLanguage = b; }
185 explicit MetaField(SwFormatMeta * const i_pFormat,
186 const sal_uInt32 nNumberFormat,
187 const bool bIsFixedLanguage );
189 public:
190 /// get prefix/suffix from the RDF repository. @throws RuntimeException
191 void GetPrefixAndSuffix(
192 OUString *const o_pPrefix, OUString *const o_pSuffix, OUString *const o_pShadingColor);
195 /// knows all meta-fields in the document.
196 class SW_DLLPUBLIC MetaFieldManager
198 private:
199 typedef std::vector< std::weak_ptr<MetaField> > MetaFieldList_t;
200 MetaFieldList_t m_MetaFields;
201 /// Document properties of a clipboard document, empty for non-clipboard documents.
202 css::uno::Reference<css::document::XDocumentProperties> m_xDocumentProperties;
204 MetaFieldManager(MetaFieldManager const&) = delete;
205 MetaFieldManager& operator=(MetaFieldManager const&) = delete;
207 public:
208 MetaFieldManager();
209 std::shared_ptr<MetaField> makeMetaField(
210 SwFormatMeta * const i_pFormat = nullptr,
211 const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
212 const bool bIsFixedLanguage = false );
213 /// get all meta fields
214 std::vector< css::uno::Reference<css::text::XTextField> > getMetaFields();
215 /// Copy document properties from rSource to m_xDocumentProperties.
216 void copyDocumentProperties(const SwDoc& rSource);
217 const css::uno::Reference<css::document::XDocumentProperties>& getDocumentProperties() const;
220 } // namespace sw
222 #endif // INCLUDED_SW_INC_FMTMETA_HXX
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */