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
23 #include <cppuhelper/weakref.hxx>
25 #include <svl/poolitem.hxx>
26 #include <sfx2/Metadatable.hxx>
31 namespace com
{ namespace sun
{ namespace star
{
33 class XDocumentProperties
;
41 * The classes that make up a meta entity are:
43 * <dt>SwTextMeta</dt><dd>the text hint</dd>
44 * <dt>SwFormatMeta</dt><dd>the pool item</dd>
45 * <dt>sw::Meta</dt><dd>the metadatable entity itself</dd>
46 * <dt>SwXMeta</dt><dd>the UNO wrapper object</dd>
49 * The text hint contains the pool item (as usual) and has a pointer to the
50 * text node at which it is attached.
51 * The pool item has a shared pointer to the metadatable entity, and a reverse
52 * pointer to the text attribute at which it is attached.
53 * The pool item is non-poolable; it may only be attached to one text
55 * Of all the pool items that refer to a metadatable entity, only one may be
56 * in the document content at any time. Others may be in the undo array, or in
58 * The metadatable entity has a reverse pointer to the pool item that is
59 * currently in the document. It also registers as a client at the text node
60 * at which it is attached via this pool item and its text attribute.
61 * The UNO wrapper object registers as a client at the metadatable entity.
63 * Copying the metadatable entity proceeds in the following way:
65 * <li>The pool item is cloned (because it is non-poolable); the clone
66 * points to the same metadatable entity, but the metadatable entity's
67 * reverse pointer is unchanged.</li>
68 * <li>The DoCopy() method is called at the new pool item:
69 * it will clone the metadatable entity (using RegisterAsCopyOf).
70 * This is necessary, because first, a metadatable entity may
71 * only be inserted once into a document, and second, the copy may be
72 * inserted into a different document than the source document!</li>
73 * <li>A new text hint is created, taking over the new pool item.</li>
74 * <li>The text hint is inserted into the hints array of some text node.</li>
84 class MetaFieldManager
;
91 friend class SwTextMeta
; ///< needs SetTextAttr, DoCopy
92 friend class ::sw::Meta
; ///< needs m_pTextAttr
94 std::shared_ptr
< ::sw::Meta
> m_pMeta
;
95 SwTextMeta
* m_pTextAttr
;
97 SwTextMeta
* GetTextAttr() { return m_pTextAttr
; }
98 void SetTextAttr(SwTextMeta
* const i_pTextAttr
);
100 /// this method <em>must</em> be called when the hint is actually copied
101 void DoCopy(::sw::MetaFieldManager
& i_rTargetDocManager
,
102 SwTextNode
& i_rTargetTextNode
);
104 explicit SwFormatMeta( const sal_uInt16 i_nWhich
);
108 explicit SwFormatMeta( std::shared_ptr
< ::sw::Meta
> const & i_pMeta
,
109 const sal_uInt16 i_nWhich
);
110 virtual ~SwFormatMeta() override
;
113 virtual bool operator==( const SfxPoolItem
& ) const override
;
114 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
116 /// notify clients registered at m_pMeta that this meta is being (re-)moved
117 void NotifyChangeTextNode(SwTextNode
*const pTextNode
);
118 static SwFormatMeta
* CreatePoolDefault( const sal_uInt16 i_nWhich
);
119 ::sw::Meta
* GetMeta() { return m_pMeta
.get(); }
125 : public ::sfx2::Metadatable
129 friend class ::SwFormatMeta
; ///< SetFormatMeta, NotifyChangeTextNode
130 friend class ::SwXMeta
; ///< GetTextNode, GetTextAttr, Get/SetXMeta
132 css::uno::WeakReference
<
133 css::rdf::XMetadatable
> m_wXMeta
;
135 SwFormatMeta
* m_pFormat
;
136 SwTextNode
* m_pTextNode
;
138 SwTextMeta
* GetTextAttr() const;
139 SwTextNode
* GetTextNode() const { return m_pTextNode
;} ///< @return 0 if not in document (undo)
141 SwFormatMeta
* GetFormatMeta() const { return m_pFormat
; }
142 void SetFormatMeta( SwFormatMeta
* const i_pFormat
) { m_pFormat
= i_pFormat
; };
144 void NotifyChangeTextNode(SwTextNode
*const pTextNode
);
146 css::uno::WeakReference
<css::rdf::XMetadatable
> const& GetXMeta() const
148 void SetXMeta(css::uno::Reference
<css::rdf::XMetadatable
> const& xMeta
)
149 { m_wXMeta
= xMeta
; }
152 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
155 explicit Meta(SwFormatMeta
* const i_pFormat
= nullptr);
156 virtual ~Meta() override
;
158 /// sfx2::Metadatable
159 virtual ::sfx2::IXmlIdRegistry
& GetRegistry() override
;
160 virtual bool IsInClipboard() const override
;
161 virtual bool IsInUndo() const override
;
162 virtual bool IsInContent() const override
;
163 virtual css::uno::Reference
< css::rdf::XMetadatable
> MakeUnoObject() override
;
170 friend class ::SwFormatMeta
;
171 friend class ::SwXMetaField
;
172 friend class ::sw::MetaFieldManager
;
174 sal_uInt32 m_nNumberFormat
;
175 bool m_bIsFixedLanguage
;
177 sal_uInt32
GetNumberFormat(OUString
const & rContent
) const;
178 void SetNumberFormat(sal_uInt32 nNumberFormat
);
179 bool IsFixedLanguage() const { return m_bIsFixedLanguage
; }
180 void SetIsFixedLanguage(bool b
) { m_bIsFixedLanguage
= b
; }
182 explicit MetaField(SwFormatMeta
* const i_pFormat
= nullptr,
183 const sal_uInt32 nNumberFormat
= SAL_MAX_UINT32
,
184 const bool bIsFixedLanguage
= false );
187 /// get prefix/suffix from the RDF repository. @throws RuntimeException
188 void GetPrefixAndSuffix(
189 OUString
*const o_pPrefix
, OUString
*const o_pSuffix
);
192 /// knows all meta-fields in the document.
193 class SW_DLLPUBLIC MetaFieldManager
196 typedef std::vector
< std::weak_ptr
<MetaField
> > MetaFieldList_t
;
197 MetaFieldList_t m_MetaFields
;
198 /// Document properties of a clipboard document, empty for non-clipboard documents.
199 css::uno::Reference
<css::document::XDocumentProperties
> m_xDocumentProperties
;
201 MetaFieldManager(MetaFieldManager
const&) = delete;
202 MetaFieldManager
& operator=(MetaFieldManager
const&) = delete;
206 std::shared_ptr
<MetaField
> makeMetaField(
207 SwFormatMeta
* const i_pFormat
= nullptr,
208 const sal_uInt32 nNumberFormat
= SAL_MAX_UINT32
,
209 const bool bIsFixedLanguage
= false );
210 /// get all meta fields
211 std::vector
< css::uno::Reference
<css::text::XTextField
> > getMetaFields();
212 /// Copy document properties from rSource to m_xDocumentProperties.
213 void copyDocumentProperties(const SwDoc
& rSource
);
214 const css::uno::Reference
<css::document::XDocumentProperties
>& getDocumentProperties();
219 #endif // INCLUDED_SW_INC_FMTMETA_HXX
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */