Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #ifndef SW_FMTMETA_HXX
21 : : #define SW_FMTMETA_HXX
22 : :
23 : : #include <cppuhelper/weakref.hxx>
24 : :
25 : : #include <svl/poolitem.hxx>
26 : : #include <sfx2/Metadatable.hxx>
27 : :
28 : : #include <boost/shared_ptr.hpp>
29 : : #include <boost/weak_ptr.hpp>
30 : :
31 : : #include <vector>
32 : :
33 : :
34 : : namespace com { namespace sun { namespace star {
35 : : namespace text {
36 : : class XTextField;
37 : : }
38 : : }}}
39 : :
40 : :
41 : : /**
42 : : * The classes that make up a meta entity are:
43 : : * <dl>
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>
48 : : * </dl>
49 : : *
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
55 : : * attribute.
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
58 : : * undo objects.
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.
63 : : *
64 : : * Copying the metadatable entity proceeds in the following way:
65 : : * <ol>
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>
76 : : * </ol>
77 : : */
78 : :
79 : : class SwTxtMeta;
80 : : class SwXMeta;
81 : : class SwXMetaField;
82 : : namespace sw {
83 : : class Meta;
84 : : }
85 : :
86 : : class SwFmtMeta
87 : : : public SfxPoolItem
88 : : {
89 : : private:
90 : : friend class SwTxtMeta; // needs SetTxtAttr, DoCopy
91 : : friend class ::sw::Meta; // needs m_pTxtAttr
92 : :
93 : : ::boost::shared_ptr< ::sw::Meta > m_pMeta;
94 : : SwTxtMeta * m_pTxtAttr;
95 : :
96 : 2194 : SwTxtMeta * GetTxtAttr() { return m_pTxtAttr; }
97 : : void SetTxtAttr(SwTxtMeta * const i_pTxtAttr);
98 : :
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);
102 : :
103 : : explicit SwFmtMeta( const sal_uInt16 i_nWhich );
104 : :
105 : : public:
106 : : // takes ownership
107 : : explicit SwFmtMeta( ::boost::shared_ptr< ::sw::Meta > const & i_pMeta,
108 : : const sal_uInt16 i_nWhich );
109 : : virtual ~SwFmtMeta();
110 : :
111 : : // SfxPoolItem
112 : : virtual int operator==( const SfxPoolItem & ) const;
113 : : virtual SfxPoolItem * Clone( SfxItemPool *pPool = 0 ) const;
114 : :
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 : 462 : ::sw::Meta * GetMeta() { return m_pMeta.get(); }
119 : : };
120 : :
121 : :
122 : : namespace sw {
123 : :
124 : : class MetaFieldManager;
125 : :
126 : : class Meta
127 : : : public ::sfx2::Metadatable
128 : : , public SwModify
129 : : {
130 : : protected:
131 : : friend class ::SwFmtMeta; // SetFmtMeta, NotifyChangeTxtNode
132 : : friend class ::SwXMeta; // GetTxtNode, GetTxtAttr, Get/SetXMeta
133 : :
134 : : ::com::sun::star::uno::WeakReference<
135 : : ::com::sun::star::rdf::XMetadatable> m_wXMeta;
136 : :
137 : : SwFmtMeta * m_pFmt;
138 : : SwTxtNode * m_pTxtNode;
139 : :
140 : : SwTxtMeta * GetTxtAttr() const;
141 : : SwTxtNode * GetTxtNode() const; // returns 0 if not in document (undo)
142 : :
143 : 2855 : SwFmtMeta * GetFmtMeta() const { return m_pFmt; }
144 : 388 : void SetFmtMeta( SwFmtMeta * const i_pFmt ) { m_pFmt = i_pFmt; };
145 : :
146 : : void NotifyChangeTxtNodeImpl();
147 : : void NotifyChangeTxtNode(SwTxtNode *const pTxtNode);
148 : :
149 : : ::com::sun::star::uno::WeakReference<
150 : 482 : ::com::sun::star::rdf::XMetadatable> const& GetXMeta() const
151 : 482 : { return m_wXMeta; }
152 : 663 : void SetXMeta(::com::sun::star::uno::Reference<
153 : : ::com::sun::star::rdf::XMetadatable> const& xMeta)
154 : 663 : { m_wXMeta = xMeta; }
155 : :
156 : : // SwClient
157 : : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
158 : :
159 : : public:
160 : : explicit Meta(SwFmtMeta * const i_pFmt = 0);
161 : : virtual ~Meta();
162 : :
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();
170 : : };
171 : :
172 [ - + ]: 104 : class MetaField
173 : : : public Meta
174 : : {
175 : : private:
176 : : friend class ::SwFmtMeta;
177 : : friend class ::SwXMetaField;
178 : : friend class ::sw::MetaFieldManager;
179 : :
180 : : sal_uInt32 m_nNumberFormat;
181 : : bool m_bIsFixedLanguage;
182 : :
183 : : sal_uInt32 GetNumberFormat(::rtl::OUString const & rContent) const;
184 : : void SetNumberFormat(sal_uInt32 nNumberFormat);
185 : 6 : bool IsFixedLanguage() const { return m_bIsFixedLanguage; }
186 : 10 : void SetIsFixedLanguage(bool b) { m_bIsFixedLanguage = b; }
187 : :
188 : : explicit MetaField(SwFmtMeta * const i_pFmt = 0,
189 : : const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
190 : : const bool bIsFixedLanguage = false );
191 : :
192 : : public:
193 : : /// get prefix/suffix from the RDF repository. @throws RuntimeException
194 : : void GetPrefixAndSuffix(
195 : : ::rtl::OUString *const o_pPrefix, ::rtl::OUString *const o_pSuffix);
196 : : };
197 : :
198 : : /** knows all meta-fields in the document. */
199 : 1458 : class MetaFieldManager
200 : : : private ::boost::noncopyable
201 : : {
202 : : private:
203 : : typedef ::std::vector< ::boost::weak_ptr<MetaField> > MetaFieldList_t;
204 : : MetaFieldList_t m_MetaFields;
205 : :
206 : : public:
207 : : MetaFieldManager();
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();
215 : : };
216 : :
217 : : } // namespace sw
218 : :
219 : : #endif // SW_FMTMETA_HXX
220 : :
221 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|