xref: /aoo41x/main/sw/inc/fmtmeta.hxx (revision 67e470da)
1*1d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1d2dbeb0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1d2dbeb0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1d2dbeb0SAndrew Rist  * distributed with this work for additional information
6*1d2dbeb0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1d2dbeb0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1d2dbeb0SAndrew Rist  * "License"); you may not use this file except in compliance
9*1d2dbeb0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1d2dbeb0SAndrew Rist  *
11*1d2dbeb0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1d2dbeb0SAndrew Rist  *
13*1d2dbeb0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1d2dbeb0SAndrew Rist  * software distributed under the License is distributed on an
15*1d2dbeb0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1d2dbeb0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1d2dbeb0SAndrew Rist  * specific language governing permissions and limitations
18*1d2dbeb0SAndrew Rist  * under the License.
19*1d2dbeb0SAndrew Rist  *
20*1d2dbeb0SAndrew Rist  *************************************************************/
21*1d2dbeb0SAndrew Rist 
22*1d2dbeb0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SW_FMTMETA_HXX
25cdf0e10cSrcweir #define SW_FMTMETA_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svl/poolitem.hxx>
30cdf0e10cSrcweir #include <sfx2/Metadatable.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
33cdf0e10cSrcweir #include <boost/weak_ptr.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <vector>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace com { namespace sun { namespace star {
39cdf0e10cSrcweir     namespace text {
40cdf0e10cSrcweir         class XTextField;
41cdf0e10cSrcweir     }
42cdf0e10cSrcweir }}}
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /**
46cdf0e10cSrcweir  * The classes that make up a meta entity are:
47cdf0e10cSrcweir  * <dl>
48cdf0e10cSrcweir  *   <dt>SwTxtMeta</dt><dd>the text hint</dd>
49cdf0e10cSrcweir  *   <dt>SwFmtMeta</dt><dd>the pool item</dd>
50cdf0e10cSrcweir  *   <dt>sw::Meta</dt><dd>the metadatable entity itself</dd>
51cdf0e10cSrcweir  *   <dt>SwXMeta</dt><dd>the UNO wrapper object</dd>
52cdf0e10cSrcweir  * </dl>
53cdf0e10cSrcweir  *
54cdf0e10cSrcweir  * The text hint contains the pool item (as usual) and has a pointer to the
55cdf0e10cSrcweir  * text node at which it is attached.
56cdf0e10cSrcweir  * The pool item has a shared pointer to the metadatable entity, and a reverse
57cdf0e10cSrcweir  * pointer to the text attribute at which it is attached.
58cdf0e10cSrcweir  * The pool item is non-poolable; it may only be attached to one text
59cdf0e10cSrcweir  * attribute.
60cdf0e10cSrcweir  * Of all the pool items that refer to a metadatable entity, only one may be
61cdf0e10cSrcweir  * in the document content at any time. Others may be in the undo array, or in
62cdf0e10cSrcweir  * undo objects.
63cdf0e10cSrcweir  * The metadatable entity has a reverse pointer to the pool item that is
64cdf0e10cSrcweir  * currently in the document. It also registers as a client at the text node
65cdf0e10cSrcweir  * at which it is attached via this pool item and its text attribute.
66cdf0e10cSrcweir  * The UNO wrapper object registers as a client at the metadatable entity.
67cdf0e10cSrcweir  *
68cdf0e10cSrcweir  * Copying the metadatable entity proceeds in the following way:
69cdf0e10cSrcweir  * <ol>
70cdf0e10cSrcweir  *   <li>The pool item is cloned (because it is non-poolable); the clone
71cdf0e10cSrcweir  *       points to the same metadatable entity, but the metadatable entity's
72cdf0e10cSrcweir  *       reverse pointer is unchanged.</li>
73cdf0e10cSrcweir  *   <li>The DoCopy() method is called at the new pool item:
74cdf0e10cSrcweir  *       it will clone the metadatable entity (using RegisterAsCopyOf).
75cdf0e10cSrcweir  *       This is necessary, because first, a metadatable entity may
76cdf0e10cSrcweir  *       only be inserted once into a document, and second, the copy may be
77cdf0e10cSrcweir  *       inserted into a different document than the source document!</li>
78cdf0e10cSrcweir  *   <li>A new text hint is created, taking over the new pool item.</li>
79cdf0e10cSrcweir  *   <li>The text hint is inserted into the hints array of some text node.</li>
80cdf0e10cSrcweir  * </ol>
81cdf0e10cSrcweir  */
82cdf0e10cSrcweir 
83cdf0e10cSrcweir class SwTxtMeta;
84cdf0e10cSrcweir class SwXMeta;
85cdf0e10cSrcweir class SwXMetaField;
86cdf0e10cSrcweir namespace sw {
87cdf0e10cSrcweir     class Meta;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir class SwFmtMeta
91cdf0e10cSrcweir     : public SfxPoolItem
92cdf0e10cSrcweir {
93cdf0e10cSrcweir private:
94cdf0e10cSrcweir     friend class SwTxtMeta; // needs SetTxtAttr, DoCopy
95cdf0e10cSrcweir     friend class ::sw::Meta; // needs m_pTxtAttr
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     ::boost::shared_ptr< ::sw::Meta > m_pMeta;
98cdf0e10cSrcweir     SwTxtMeta * m_pTxtAttr;
99cdf0e10cSrcweir 
GetTxtAttr()100cdf0e10cSrcweir     SwTxtMeta * GetTxtAttr() { return m_pTxtAttr; }
101cdf0e10cSrcweir     void SetTxtAttr(SwTxtMeta * const i_pTxtAttr);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     /// this method <em>must</em> be called when the hint is actually copied
104cdf0e10cSrcweir     void DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
105cdf0e10cSrcweir         SwTxtNode & i_rTargetTxtNode);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     explicit SwFmtMeta( const sal_uInt16 i_nWhich );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir public:
110cdf0e10cSrcweir     // takes ownership
111cdf0e10cSrcweir     explicit SwFmtMeta( ::boost::shared_ptr< ::sw::Meta > const & i_pMeta,
112cdf0e10cSrcweir                         const sal_uInt16 i_nWhich );
113cdf0e10cSrcweir     virtual ~SwFmtMeta();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     // SfxPoolItem
116cdf0e10cSrcweir     virtual int              operator==( const SfxPoolItem & ) const;
117cdf0e10cSrcweir     virtual SfxPoolItem *    Clone( SfxItemPool *pPool = 0 ) const;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     /// notify clients registered at m_pMeta that this meta is being (re-)moved
120cdf0e10cSrcweir     void NotifyChangeTxtNode(SwTxtNode *const pTxtNode);
121cdf0e10cSrcweir     static SwFmtMeta * CreatePoolDefault( const sal_uInt16 i_nWhich );
GetMeta()122cdf0e10cSrcweir     ::sw::Meta * GetMeta() { return m_pMeta.get(); }
123cdf0e10cSrcweir };
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir namespace sw {
127cdf0e10cSrcweir 
128cdf0e10cSrcweir class MetaFieldManager;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir class Meta
131cdf0e10cSrcweir     : public ::sfx2::Metadatable
132cdf0e10cSrcweir     , public SwModify
133cdf0e10cSrcweir {
134cdf0e10cSrcweir protected:
135cdf0e10cSrcweir     friend class ::SwFmtMeta; // SetFmtMeta, NotifyChangeTxtNode
136cdf0e10cSrcweir     friend class ::SwXMeta; // GetTxtNode, GetTxtAttr, Get/SetXMeta
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     ::com::sun::star::uno::WeakReference<
139cdf0e10cSrcweir         ::com::sun::star::rdf::XMetadatable> m_wXMeta;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     SwFmtMeta * m_pFmt;
142cdf0e10cSrcweir     SwTxtNode * m_pTxtNode;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     SwTxtMeta * GetTxtAttr() const;
145cdf0e10cSrcweir     SwTxtNode * GetTxtNode() const; // returns 0 if not in document (undo)
146cdf0e10cSrcweir 
GetFmtMeta() const147cdf0e10cSrcweir     SwFmtMeta * GetFmtMeta() const { return m_pFmt; }
SetFmtMeta(SwFmtMeta * const i_pFmt)148cdf0e10cSrcweir     void SetFmtMeta( SwFmtMeta * const i_pFmt ) { m_pFmt = i_pFmt; };
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     void NotifyChangeTxtNodeImpl();
151cdf0e10cSrcweir     void NotifyChangeTxtNode(SwTxtNode *const pTxtNode);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     ::com::sun::star::uno::WeakReference<
GetXMeta() const154cdf0e10cSrcweir         ::com::sun::star::rdf::XMetadatable> const& GetXMeta() const
155cdf0e10cSrcweir             { return m_wXMeta; }
SetXMeta(::com::sun::star::uno::Reference<::com::sun::star::rdf::XMetadatable> const & xMeta)156cdf0e10cSrcweir     void SetXMeta(::com::sun::star::uno::Reference<
157cdf0e10cSrcweir                     ::com::sun::star::rdf::XMetadatable> const& xMeta)
158cdf0e10cSrcweir             { m_wXMeta = xMeta; }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     // SwClient
161cdf0e10cSrcweir     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir public:
164cdf0e10cSrcweir     explicit Meta(SwFmtMeta * const i_pFmt = 0);
165cdf0e10cSrcweir     virtual ~Meta();
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     // sfx2::Metadatable
168cdf0e10cSrcweir     virtual ::sfx2::IXmlIdRegistry& GetRegistry();
169cdf0e10cSrcweir     virtual bool IsInClipboard() const;
170cdf0e10cSrcweir     virtual bool IsInUndo() const;
171cdf0e10cSrcweir     virtual bool IsInContent() const;
172cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference<
173cdf0e10cSrcweir         ::com::sun::star::rdf::XMetadatable > MakeUnoObject();
174cdf0e10cSrcweir };
175cdf0e10cSrcweir 
176cdf0e10cSrcweir class MetaField
177cdf0e10cSrcweir     : public Meta
178cdf0e10cSrcweir {
179cdf0e10cSrcweir private:
180cdf0e10cSrcweir     friend class ::SwFmtMeta;
181cdf0e10cSrcweir     friend class ::SwXMetaField;
182cdf0e10cSrcweir     friend class ::sw::MetaFieldManager;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     sal_uInt32 m_nNumberFormat;
185cdf0e10cSrcweir     bool       m_bIsFixedLanguage;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     sal_uInt32 GetNumberFormat(::rtl::OUString const & rContent) const;
188cdf0e10cSrcweir     void SetNumberFormat(sal_uInt32 nNumberFormat);
IsFixedLanguage() const189cdf0e10cSrcweir     bool IsFixedLanguage() const    { return m_bIsFixedLanguage; }
SetIsFixedLanguage(bool b)190cdf0e10cSrcweir     void SetIsFixedLanguage(bool b) { m_bIsFixedLanguage = b; }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     explicit MetaField(SwFmtMeta * const i_pFmt = 0,
193cdf0e10cSrcweir             const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
194cdf0e10cSrcweir             const bool bIsFixedLanguage = false );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir public:
197cdf0e10cSrcweir     /// get prefix/suffix from the RDF repository. @throws RuntimeException
198cdf0e10cSrcweir     void GetPrefixAndSuffix(
199cdf0e10cSrcweir         ::rtl::OUString *const o_pPrefix, ::rtl::OUString *const o_pSuffix);
200cdf0e10cSrcweir };
201cdf0e10cSrcweir 
202cdf0e10cSrcweir /** knows all meta-fields in the document. */
203cdf0e10cSrcweir class MetaFieldManager
204cdf0e10cSrcweir     : private ::boost::noncopyable
205cdf0e10cSrcweir {
206cdf0e10cSrcweir private:
207cdf0e10cSrcweir     typedef ::std::vector< ::boost::weak_ptr<MetaField> > MetaFieldList_t;
208cdf0e10cSrcweir     MetaFieldList_t m_MetaFields;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir public:
211cdf0e10cSrcweir     MetaFieldManager();
212cdf0e10cSrcweir     ::boost::shared_ptr<MetaField> makeMetaField(
213cdf0e10cSrcweir                 SwFmtMeta * const i_pFmt = 0,
214cdf0e10cSrcweir                 const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
215cdf0e10cSrcweir                 const bool bIsFixedLanguage = false );
216cdf0e10cSrcweir     /// get all meta fields
217cdf0e10cSrcweir     ::std::vector< ::com::sun::star::uno::Reference<
218cdf0e10cSrcweir         ::com::sun::star::text::XTextField> > getMetaFields();
219cdf0e10cSrcweir };
220cdf0e10cSrcweir 
221cdf0e10cSrcweir } // namespace sw
222cdf0e10cSrcweir 
223cdf0e10cSrcweir #endif // SW_FMTMETA_HXX
224cdf0e10cSrcweir 
225