1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
25 #include <cppuhelper/weakref.hxx>
27 #include <svl/poolitem.hxx>
28 #include <sfx2/Metadatable.hxx>
33 namespace com
{ namespace sun
{ namespace star
{
35 class XDocumentProperties
;
43 * The classes that make up a meta entity are:
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>
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
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
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:
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>
87 class MetaFieldManager
;
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
);
111 explicit SwFormatMeta( std::shared_ptr
< ::sw::Meta
> const & i_pMeta
,
112 const sal_uInt16 i_nWhich
);
113 virtual ~SwFormatMeta() override
;
116 virtual bool operator==( const SfxPoolItem
& ) const override
;
117 virtual SfxPoolItem
* 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(); }
128 : public ::sfx2::Metadatable
130 , public sw::BroadcasterMixin
132 friend class ::SwFormatMeta
; ///< SetFormatMeta, NotifyChangeTextNode
133 friend class ::SwXMeta
; ///< GetTextNode, GetTextAttr, Get/SetXMeta
135 css::uno::WeakReference
<
136 css::rdf::XMetadatable
> m_wXMeta
;
138 SwFormatMeta
* m_pFormat
;
139 SwTextNode
* m_pTextNode
;
143 SwTextMeta
* GetTextAttr() const;
144 SwTextNode
* GetTextNode() const { return m_pTextNode
;} ///< @return 0 if not in document (undo)
146 SwFormatMeta
* GetFormatMeta() const { return m_pFormat
; }
147 void SetFormatMeta( SwFormatMeta
* const i_pFormat
) { m_pFormat
= i_pFormat
; };
149 void NotifyChangeTextNode(SwTextNode
*const pTextNode
);
151 css::uno::WeakReference
<css::rdf::XMetadatable
> const& GetXMeta() const
153 void SetXMeta(css::uno::Reference
<css::rdf::XMetadatable
> const& xMeta
)
154 { m_wXMeta
= xMeta
; }
157 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
160 explicit Meta(SwFormatMeta
* const i_pFormat
);
161 virtual ~Meta() override
;
163 /// sfx2::Metadatable
164 virtual ::sfx2::IXmlIdRegistry
& GetRegistry() override
;
165 virtual bool IsInClipboard() const override
;
166 virtual bool IsInUndo() const override
;
167 virtual bool IsInContent() const override
;
168 virtual css::uno::Reference
< css::rdf::XMetadatable
> MakeUnoObject() override
;
171 class MetaField final
175 friend class ::SwFormatMeta
;
176 friend class ::SwXMetaField
;
177 friend class ::sw::MetaFieldManager
;
179 sal_uInt32 m_nNumberFormat
;
180 bool m_bIsFixedLanguage
;
182 sal_uInt32
GetNumberFormat(OUString
const & rContent
) const;
183 void SetNumberFormat(sal_uInt32 nNumberFormat
);
184 bool IsFixedLanguage() const { return m_bIsFixedLanguage
; }
185 void SetIsFixedLanguage(bool b
) { m_bIsFixedLanguage
= b
; }
187 explicit MetaField(SwFormatMeta
* const i_pFormat
,
188 const sal_uInt32 nNumberFormat
,
189 const bool bIsFixedLanguage
);
192 /// get prefix/suffix from the RDF repository. @throws RuntimeException
193 void GetPrefixAndSuffix(
194 OUString
*const o_pPrefix
, OUString
*const o_pSuffix
);
197 /// knows all meta-fields in the document.
198 class SW_DLLPUBLIC MetaFieldManager
201 typedef std::vector
< std::weak_ptr
<MetaField
> > MetaFieldList_t
;
202 MetaFieldList_t m_MetaFields
;
203 /// Document properties of a clipboard document, empty for non-clipboard documents.
204 css::uno::Reference
<css::document::XDocumentProperties
> m_xDocumentProperties
;
206 MetaFieldManager(MetaFieldManager
const&) = delete;
207 MetaFieldManager
& operator=(MetaFieldManager
const&) = delete;
211 std::shared_ptr
<MetaField
> makeMetaField(
212 SwFormatMeta
* const i_pFormat
= nullptr,
213 const sal_uInt32 nNumberFormat
= SAL_MAX_UINT32
,
214 const bool bIsFixedLanguage
= false );
215 /// get all meta fields
216 std::vector
< css::uno::Reference
<css::text::XTextField
> > getMetaFields();
217 /// Copy document properties from rSource to m_xDocumentProperties.
218 void copyDocumentProperties(const SwDoc
& rSource
);
219 const css::uno::Reference
<css::document::XDocumentProperties
>& getDocumentProperties() const;
224 #endif // INCLUDED_SW_INC_FMTMETA_HXX
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */