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 SW_FMTMETA_HXX
21 #define SW_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>
34 namespace com
{ namespace sun
{ namespace star
{
42 * The classes that make up a meta entity are:
44 * <dt>SwTxtMeta</dt><dd>the text hint</dd>
45 * <dt>SwFmtMeta</dt><dd>the pool item</dd>
46 * <dt>sw::Meta</dt><dd>the metadatable entity itself</dd>
47 * <dt>SwXMeta</dt><dd>the UNO wrapper object</dd>
50 * The text hint contains the pool item (as usual) and has a pointer to the
51 * text node at which it is attached.
52 * The pool item has a shared pointer to the metadatable entity, and a reverse
53 * pointer to the text attribute at which it is attached.
54 * The pool item is non-poolable; it may only be attached to one text
56 * Of all the pool items that refer to a metadatable entity, only one may be
57 * in the document content at any time. Others may be in the undo array, or in
59 * The metadatable entity has a reverse pointer to the pool item that is
60 * currently in the document. It also registers as a client at the text node
61 * at which it is attached via this pool item and its text attribute.
62 * The UNO wrapper object registers as a client at the metadatable entity.
64 * Copying the metadatable entity proceeds in the following way:
66 * <li>The pool item is cloned (because it is non-poolable); the clone
67 * points to the same metadatable entity, but the metadatable entity's
68 * reverse pointer is unchanged.</li>
69 * <li>The DoCopy() method is called at the new pool item:
70 * it will clone the metadatable entity (using RegisterAsCopyOf).
71 * This is necessary, because first, a metadatable entity may
72 * only be inserted once into a document, and second, the copy may be
73 * inserted into a different document than the source document!</li>
74 * <li>A new text hint is created, taking over the new pool item.</li>
75 * <li>The text hint is inserted into the hints array of some text node.</li>
90 friend class SwTxtMeta
; ///< needs SetTxtAttr, DoCopy
91 friend class ::sw::Meta
; ///< needs m_pTxtAttr
93 ::boost::shared_ptr
< ::sw::Meta
> m_pMeta
;
94 SwTxtMeta
* m_pTxtAttr
;
96 SwTxtMeta
* GetTxtAttr() { return m_pTxtAttr
; }
97 void SetTxtAttr(SwTxtMeta
* const i_pTxtAttr
);
99 /// this method <em>must</em> be called when the hint is actually copied
100 void DoCopy(::sw::MetaFieldManager
& i_rTargetDocManager
,
101 SwTxtNode
& i_rTargetTxtNode
);
103 explicit SwFmtMeta( const sal_uInt16 i_nWhich
);
107 explicit SwFmtMeta( ::boost::shared_ptr
< ::sw::Meta
> const & i_pMeta
,
108 const sal_uInt16 i_nWhich
);
109 virtual ~SwFmtMeta();
112 virtual int operator==( const SfxPoolItem
& ) const;
113 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= 0 ) const;
115 /// notify clients registered at m_pMeta that this meta is being (re-)moved
116 void NotifyChangeTxtNode(SwTxtNode
*const pTxtNode
);
117 static SwFmtMeta
* CreatePoolDefault( const sal_uInt16 i_nWhich
);
118 ::sw::Meta
* GetMeta() { return m_pMeta
.get(); }
124 class MetaFieldManager
;
127 : public ::sfx2::Metadatable
131 friend class ::SwFmtMeta
; ///< SetFmtMeta, NotifyChangeTxtNode
132 friend class ::SwXMeta
; ///< GetTxtNode, GetTxtAttr, Get/SetXMeta
134 ::com::sun::star::uno::WeakReference
<
135 ::com::sun::star::rdf::XMetadatable
> m_wXMeta
;
138 SwTxtNode
* m_pTxtNode
;
140 SwTxtMeta
* GetTxtAttr() const;
141 SwTxtNode
* GetTxtNode() const; ///< @return 0 if not in document (undo)
143 SwFmtMeta
* GetFmtMeta() const { return m_pFmt
; }
144 void SetFmtMeta( SwFmtMeta
* const i_pFmt
) { m_pFmt
= i_pFmt
; };
146 void NotifyChangeTxtNodeImpl();
147 void NotifyChangeTxtNode(SwTxtNode
*const pTxtNode
);
149 ::com::sun::star::uno::WeakReference
<
150 ::com::sun::star::rdf::XMetadatable
> const& GetXMeta() const
152 void SetXMeta(::com::sun::star::uno::Reference
<
153 ::com::sun::star::rdf::XMetadatable
> const& xMeta
)
154 { m_wXMeta
= xMeta
; }
157 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
);
160 explicit Meta(SwFmtMeta
* const i_pFmt
= 0);
163 /// sfx2::Metadatable
164 virtual ::sfx2::IXmlIdRegistry
& GetRegistry();
165 virtual bool IsInClipboard() const;
166 virtual bool IsInUndo() const;
167 virtual bool IsInContent() const;
168 virtual ::com::sun::star::uno::Reference
<
169 ::com::sun::star::rdf::XMetadatable
> MakeUnoObject();
176 friend class ::SwFmtMeta
;
177 friend class ::SwXMetaField
;
178 friend class ::sw::MetaFieldManager
;
180 sal_uInt32 m_nNumberFormat
;
181 bool m_bIsFixedLanguage
;
183 sal_uInt32
GetNumberFormat(OUString
const & rContent
) const;
184 void SetNumberFormat(sal_uInt32 nNumberFormat
);
185 bool IsFixedLanguage() const { return m_bIsFixedLanguage
; }
186 void SetIsFixedLanguage(bool b
) { m_bIsFixedLanguage
= b
; }
188 explicit MetaField(SwFmtMeta
* const i_pFmt
= 0,
189 const sal_uInt32 nNumberFormat
= SAL_MAX_UINT32
,
190 const bool bIsFixedLanguage
= false );
193 /// get prefix/suffix from the RDF repository. @throws RuntimeException
194 void GetPrefixAndSuffix(
195 OUString
*const o_pPrefix
, OUString
*const o_pSuffix
);
198 /// knows all meta-fields in the document.
199 class MetaFieldManager
200 : private ::boost::noncopyable
203 typedef ::std::vector
< ::boost::weak_ptr
<MetaField
> > MetaFieldList_t
;
204 MetaFieldList_t m_MetaFields
;
208 ::boost::shared_ptr
<MetaField
> makeMetaField(
209 SwFmtMeta
* const i_pFmt
= 0,
210 const sal_uInt32 nNumberFormat
= SAL_MAX_UINT32
,
211 const bool bIsFixedLanguage
= false );
212 /// get all meta fields
213 ::std::vector
< ::com::sun::star::uno::Reference
<
214 ::com::sun::star::text::XTextField
> > getMetaFields();
219 #endif // SW_FMTMETA_HXX
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */