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>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/weak_ptr.hpp>
33 namespace com
{ namespace sun
{ namespace star
{
40 * The classes that make up a meta entity are:
42 * <dt>SwTextMeta</dt><dd>the text hint</dd>
43 * <dt>SwFormatMeta</dt><dd>the pool item</dd>
44 * <dt>sw::Meta</dt><dd>the metadatable entity itself</dd>
45 * <dt>SwXMeta</dt><dd>the UNO wrapper object</dd>
48 * The text hint contains the pool item (as usual) and has a pointer to the
49 * text node at which it is attached.
50 * The pool item has a shared pointer to the metadatable entity, and a reverse
51 * pointer to the text attribute at which it is attached.
52 * The pool item is non-poolable; it may only be attached to one text
54 * Of all the pool items that refer to a metadatable entity, only one may be
55 * in the document content at any time. Others may be in the undo array, or in
57 * The metadatable entity has a reverse pointer to the pool item that is
58 * currently in the document. It also registers as a client at the text node
59 * at which it is attached via this pool item and its text attribute.
60 * The UNO wrapper object registers as a client at the metadatable entity.
62 * Copying the metadatable entity proceeds in the following way:
64 * <li>The pool item is cloned (because it is non-poolable); the clone
65 * points to the same metadatable entity, but the metadatable entity's
66 * reverse pointer is unchanged.</li>
67 * <li>The DoCopy() method is called at the new pool item:
68 * it will clone the metadatable entity (using RegisterAsCopyOf).
69 * This is necessary, because first, a metadatable entity may
70 * only be inserted once into a document, and second, the copy may be
71 * inserted into a different document than the source document!</li>
72 * <li>A new text hint is created, taking over the new pool item.</li>
73 * <li>The text hint is inserted into the hints array of some text node.</li>
83 class MetaFieldManager
;
90 friend class SwTextMeta
; ///< needs SetTextAttr, DoCopy
91 friend class ::sw::Meta
; ///< needs m_pTextAttr
93 ::boost::shared_ptr
< ::sw::Meta
> m_pMeta
;
94 SwTextMeta
* m_pTextAttr
;
96 SwTextMeta
* GetTextAttr() { return m_pTextAttr
; }
97 void SetTextAttr(SwTextMeta
* const i_pTextAttr
);
99 /// this method <em>must</em> be called when the hint is actually copied
100 void DoCopy(::sw::MetaFieldManager
& i_rTargetDocManager
,
101 SwTextNode
& i_rTargetTextNode
);
103 explicit SwFormatMeta( const sal_uInt16 i_nWhich
);
107 explicit SwFormatMeta( ::boost::shared_ptr
< ::sw::Meta
> const & i_pMeta
,
108 const sal_uInt16 i_nWhich
);
109 virtual ~SwFormatMeta();
112 virtual bool operator==( const SfxPoolItem
& ) const SAL_OVERRIDE
;
113 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= 0 ) const SAL_OVERRIDE
;
115 /// notify clients registered at m_pMeta that this meta is being (re-)moved
116 void NotifyChangeTextNode(SwTextNode
*const pTextNode
);
117 static SwFormatMeta
* CreatePoolDefault( const sal_uInt16 i_nWhich
);
118 ::sw::Meta
* GetMeta() { return m_pMeta
.get(); }
124 : public ::sfx2::Metadatable
128 friend class ::SwFormatMeta
; ///< SetFormatMeta, NotifyChangeTextNode
129 friend class ::SwXMeta
; ///< GetTextNode, GetTextAttr, Get/SetXMeta
131 ::com::sun::star::uno::WeakReference
<
132 ::com::sun::star::rdf::XMetadatable
> m_wXMeta
;
134 SwFormatMeta
* m_pFormat
;
135 SwTextNode
* m_pTextNode
;
137 SwTextMeta
* GetTextAttr() const;
138 SwTextNode
* GetTextNode() const { return m_pTextNode
;} ///< @return 0 if not in document (undo)
140 SwFormatMeta
* GetFormatMeta() const { return m_pFormat
; }
141 void SetFormatMeta( SwFormatMeta
* const i_pFormat
) { m_pFormat
= i_pFormat
; };
143 void NotifyChangeTextNodeImpl();
144 void NotifyChangeTextNode(SwTextNode
*const pTextNode
);
146 ::com::sun::star::uno::WeakReference
<
147 ::com::sun::star::rdf::XMetadatable
> const& GetXMeta() const
149 void SetXMeta(::com::sun::star::uno::Reference
<
150 ::com::sun::star::rdf::XMetadatable
> const& xMeta
)
151 { m_wXMeta
= xMeta
; }
154 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) SAL_OVERRIDE
;
157 explicit Meta(SwFormatMeta
* const i_pFormat
= 0);
160 /// sfx2::Metadatable
161 virtual ::sfx2::IXmlIdRegistry
& GetRegistry() SAL_OVERRIDE
;
162 virtual bool IsInClipboard() const SAL_OVERRIDE
;
163 virtual bool IsInUndo() const SAL_OVERRIDE
;
164 virtual bool IsInContent() const SAL_OVERRIDE
;
165 virtual ::com::sun::star::uno::Reference
<
166 ::com::sun::star::rdf::XMetadatable
> MakeUnoObject() SAL_OVERRIDE
;
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
= 0,
186 const sal_uInt32 nNumberFormat
= SAL_MAX_UINT32
,
187 const bool bIsFixedLanguage
= false );
190 /// get prefix/suffix from the RDF repository. @throws RuntimeException
191 void GetPrefixAndSuffix(
192 OUString
*const o_pPrefix
, OUString
*const o_pSuffix
);
195 /// knows all meta-fields in the document.
196 class MetaFieldManager
197 : private ::boost::noncopyable
200 typedef ::std::vector
< ::boost::weak_ptr
<MetaField
> > MetaFieldList_t
;
201 MetaFieldList_t m_MetaFields
;
205 ::boost::shared_ptr
<MetaField
> makeMetaField(
206 SwFormatMeta
* const i_pFormat
= 0,
207 const sal_uInt32 nNumberFormat
= SAL_MAX_UINT32
,
208 const bool bIsFixedLanguage
= false );
209 /// get all meta fields
210 ::std::vector
< ::com::sun::star::uno::Reference
<
211 ::com::sun::star::text::XTextField
> > getMetaFields();
216 #endif // INCLUDED_SW_INC_FMTMETA_HXX
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */