Update ooo320-m1
[ooovba.git] / sw / inc / fmtmeta.hxx
blob952181d0498ceb50263e0c1d321be89245daf50a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmtmeta.hxx,v $
10 * $Revision: 1.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SW_FMTMETA_HXX
32 #define SW_FMTMETA_HXX
34 #include <svtools/poolitem.hxx>
35 #include <sfx2/Metadatable.hxx>
37 #include <boost/shared_ptr.hpp>
38 #include <boost/weak_ptr.hpp>
40 #include <vector>
43 namespace com { namespace sun { namespace star {
44 namespace text {
45 class XTextField;
47 }}}
50 /**
51 * The classes that make up a meta entity are:
52 * <dl>
53 * <dt>SwTxtMeta</dt><dd>the text hint</dd>
54 * <dt>SwFmtMeta</dt><dd>the pool item</dd>
55 * <dt>sw::Meta</dt><dd>the metadatable entity itself</dd>
56 * <dt>SwXMeta</dt><dd>the UNO wrapper object</dd>
57 * </dl>
59 * The text hint contains the pool item (as usual) and has a pointer to the
60 * text node at which it is attached.
61 * The pool item has a shared pointer to the metadatable entity, and a reverse
62 * pointer to the text attribute at which it is attached.
63 * The pool item is non-poolable; it may only be attached to one text
64 * attribute.
65 * Of all the pool items that refer to a metadatable entity, only one may be
66 * in the document content at any time. Others may be in the undo array, or in
67 * undo objects.
68 * The metadatable entity has a reverse pointer to the pool item that is
69 * currently in the document. It also registers as a client at the text node
70 * at which it is attached via this pool item and its text attribute.
71 * The UNO wrapper object registers as a client at the metadatable entity.
73 * Copying the metadatable entity proceeds in the following way:
74 * <ol>
75 * <li>The pool item is cloned (because it is non-poolable); the clone
76 * points to the same metadatable entity, but the metadatable entity's
77 * reverse pointer is unchanged.</li>
78 * <li>A new text hint is created, taking over the new pool item.
79 * Unfortunately, this also makes the metadatable entity point at the
80 * cloned pool item.</li>
81 * <li>The text hint is inserted into the hints array of some text node.</li>
82 * <li>The DoCopy() method must be called at the new pool item:
83 * it will clone the metadatable entity (using RegisterAsCopyOf),
84 * and fix the reverse pointer of the original to point at the
85 * original pool item.
86 * This is necessary, because first, a metadatable entity may
87 * only be inserted once into a document, and second, the copy may be
88 * inserted into a different document than the source document!</li>
89 * </ol>
92 class SwTxtMeta;
93 class SwXMeta;
94 class SwXMetaField;
95 namespace sw {
96 class Meta;
99 class SwFmtMeta
100 : public SfxPoolItem
102 private:
103 friend class SwTxtMeta; // needs SetTxtAttr
104 friend class ::sw::Meta; // needs m_pTxtAttr
106 ::boost::shared_ptr< ::sw::Meta > m_pMeta;
107 SwTxtMeta * m_pTxtAttr;
109 SwTxtMeta * GetTxtAttr() { return m_pTxtAttr; }
110 void SetTxtAttr(SwTxtMeta * const i_pTxtAttr);
112 explicit SwFmtMeta( const USHORT i_nWhich );
114 public:
115 // takes ownership
116 explicit SwFmtMeta( ::boost::shared_ptr< ::sw::Meta > const & i_pMeta,
117 const USHORT i_nWhich );
118 virtual ~SwFmtMeta();
120 // SfxPoolItem
121 virtual int operator==( const SfxPoolItem & ) const;
122 virtual SfxPoolItem * Clone( SfxItemPool *pPool = 0 ) const;
123 // TYPEINFO();
125 // notify clients registered at m_pMeta that this meta is being removed
126 void NotifyRemoval();
127 static SwFmtMeta * CreatePoolDefault( const USHORT i_nWhich );
128 ::sw::Meta * GetMeta() { return m_pMeta.get(); }
129 /// this method <em>must</em> be called when the hint is actually copied
130 void DoCopy( SwFmtMeta & rOriginalMeta );
134 namespace sw {
136 class MetaFieldManager;
138 class Meta
139 : public ::sfx2::Metadatable
140 , public SwModify
142 protected:
143 friend class ::SwFmtMeta; // SetFmtMeta
144 friend class ::SwXMeta; // GetTxtNode, GetTxtAttr
146 SwFmtMeta * m_pFmt;
148 SwTxtMeta * GetTxtAttr() const;
149 SwTxtNode * GetTxtNode() const; // returns 0 if not in document (undo)
151 SwFmtMeta * GetFmtMeta() const { return m_pFmt; }
152 void SetFmtMeta( SwFmtMeta * const i_pFmt ) { m_pFmt = i_pFmt; };
154 public:
155 explicit Meta(SwFmtMeta * const i_pFmt = 0);
156 virtual ~Meta();
158 // SwClient
159 virtual void Modify( SfxPoolItem *pOld, SfxPoolItem *pNew );
161 // sfx2::Metadatable
162 virtual ::sfx2::IXmlIdRegistry& GetRegistry();
163 virtual bool IsInClipboard() const;
164 virtual bool IsInUndo() const;
165 virtual bool IsInContent() const;
166 virtual ::com::sun::star::uno::Reference<
167 ::com::sun::star::rdf::XMetadatable > MakeUnoObject();
170 class MetaField
171 : public Meta
173 private:
174 friend class ::SwFmtMeta;
175 friend class ::SwXMetaField;
176 friend class ::sw::MetaFieldManager;
178 sal_uInt32 m_nNumberFormat;
179 bool m_bIsFixedLanguage;
181 sal_uInt32 GetNumberFormat(::rtl::OUString const & rContent) const;
182 void SetNumberFormat(sal_uInt32 nNumberFormat);
183 bool IsFixedLanguage() const { return m_bIsFixedLanguage; }
184 void SetIsFixedLanguage(bool b) { m_bIsFixedLanguage = b; }
186 explicit MetaField(SwFmtMeta * const i_pFmt = 0,
187 const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
188 const bool bIsFixedLanguage = false );
190 public:
191 /// get prefix/suffix from the RDF repository. @throws RuntimeException
192 void GetPrefixAndSuffix(
193 ::rtl::OUString *const o_pPrefix, ::rtl::OUString *const o_pSuffix);
196 /** knows all meta-fields in the document. */
197 class MetaFieldManager
198 : private ::boost::noncopyable
200 private:
201 typedef ::std::vector< ::boost::weak_ptr<MetaField> > MetaFieldList_t;
202 MetaFieldList_t m_MetaFields;
204 public:
205 MetaFieldManager();
206 ::boost::shared_ptr<MetaField> makeMetaField(
207 SwFmtMeta * const i_pFmt = 0,
208 const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
209 const bool bIsFixedLanguage = false );
210 /// get all meta fields
211 ::std::vector< ::com::sun::star::uno::Reference<
212 ::com::sun::star::text::XTextField> > getMetaFields();
215 } // namespace sw
217 #endif // SW_FMTMETA_HXX