xref: /aoo42x/main/sw/source/core/inc/unometa.hxx (revision 67e470da)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SW_UNOMETA_HXX
25 #define SW_UNOMETA_HXX
26 
27 #include <deque>
28 
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/container/XChild.hpp>
33 #include <com/sun/star/container/XEnumerationAccess.hpp>
34 #include <com/sun/star/text/XTextContent.hpp>
35 #include <com/sun/star/text/XTextField.hpp>
36 
37 #include <cppuhelper/implbase2.hxx>
38 #include <cppuhelper/implbase6.hxx>
39 
40 #include <sfx2/Metadatable.hxx>
41 
42 #include <unobaseclass.hxx>
43 
44 
45 typedef ::std::deque<
46     ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > >
47     TextRangeList_t;
48 
49 class SwPaM;
50 class SwTxtNode;
51 
52 namespace sw {
53     class Meta;
54     class MetaField;
55 }
56 
57 typedef ::cppu::ImplInheritanceHelper6
58 <   ::sfx2::MetadatableMixin
59 ,   ::com::sun::star::lang::XUnoTunnel
60 ,   ::com::sun::star::lang::XServiceInfo
61 ,   ::com::sun::star::container::XChild
62 ,   ::com::sun::star::container::XEnumerationAccess
63 ,   ::com::sun::star::text::XTextContent
64 ,   ::com::sun::star::text::XText
65 > SwXMeta_Base;
66 
67 class SwXMeta
68     : public SwXMeta_Base
69     , private ::boost::noncopyable
70 {
71 
72 public:
73 
74     class Impl;
75 
76 protected:
77 
78     ::sw::UnoImplPtr<Impl> m_pImpl;
79 
80     virtual void SAL_CALL AttachImpl(
81             const ::com::sun::star::uno::Reference<
82                 ::com::sun::star::text::XTextRange > & xTextRange,
83             const sal_uInt16 nWhich)
84         throw (::com::sun::star::lang::IllegalArgumentException,
85                 ::com::sun::star::uno::RuntimeException);
86 
87     virtual ~SwXMeta();
88 
89     /// @param pDoc and pMeta != 0, but not & because of ImplInheritanceHelper
90     SwXMeta(SwDoc *const pDoc, ::sw::Meta *const pMeta,
91         ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> const&
92             xParentText,
93         TextRangeList_t const*const pPortions);
94 
95 public:
96 
97     SwXMeta(SwDoc *const pDoc);
98 
99     static ::com::sun::star::uno::Reference<
100             ::com::sun::star::rdf::XMetadatable >
101         CreateXMeta(
102             ::sw::Meta & rMeta,
103             ::com::sun::star::uno::Reference< ::com::sun::star::text::XText>
104                 const& xParentText = 0,
105             ::std::auto_ptr<TextRangeList_t const> pPortions =
106                 ::std::auto_ptr<TextRangeList_t const>(0));
107 
108     /// init params with position of the attribute content (w/out CH_TXTATR)
109     bool SetContentRange(
110             SwTxtNode *& rpNode, xub_StrLen & rStart, xub_StrLen & rEnd) const;
111     ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >
112         GetParentText() const;
113 
114     bool CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb)
115         throw (::com::sun::star::lang::IllegalArgumentException,
116                ::com::sun::star::uno::RuntimeException);
117 
118     // MetadatableMixin
119     virtual ::sfx2::Metadatable * GetCoreObject();
120     virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
121         GetModel();
122 
123     static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
124 
125     // XUnoTunnel
126     virtual sal_Int64 SAL_CALL getSomething(
127             const ::com::sun::star::uno::Sequence< sal_Int8 >& Identifier )
128         throw (::com::sun::star::uno::RuntimeException);
129 
130     // XServiceInfo
131     virtual ::rtl::OUString SAL_CALL getImplementationName()
132         throw (::com::sun::star::uno::RuntimeException);
133     virtual sal_Bool SAL_CALL supportsService(
134             const ::rtl::OUString& rServiceName)
135         throw (::com::sun::star::uno::RuntimeException);
136     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
137         getSupportedServiceNames()
138         throw (::com::sun::star::uno::RuntimeException);
139 
140     // XComponent
141     virtual void SAL_CALL dispose()
142         throw (::com::sun::star::uno::RuntimeException);
143     virtual void SAL_CALL addEventListener(
144             const ::com::sun::star::uno::Reference<
145                 ::com::sun::star::lang::XEventListener > & xListener)
146         throw (::com::sun::star::uno::RuntimeException);
147     virtual void SAL_CALL removeEventListener(
148             const ::com::sun::star::uno::Reference<
149                 ::com::sun::star::lang::XEventListener > & xListener)
150         throw (::com::sun::star::uno::RuntimeException);
151 
152     // XChild
153     virtual ::com::sun::star::uno::Reference<
154             ::com::sun::star::uno::XInterface > SAL_CALL
155         getParent()
156         throw (::com::sun::star::uno::RuntimeException);
157     virtual void SAL_CALL setParent(
158             ::com::sun::star::uno::Reference<
159                 ::com::sun::star::uno::XInterface> const& xParent)
160         throw (::com::sun::star::uno::RuntimeException,
161             ::com::sun::star::lang::NoSupportException);
162 
163     // XElementAccess
164     virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
165         throw (::com::sun::star::uno::RuntimeException);
166     virtual sal_Bool SAL_CALL hasElements()
167         throw (::com::sun::star::uno::RuntimeException);
168 
169     // XEnumerationAccess
170     virtual ::com::sun::star::uno::Reference<
171             ::com::sun::star::container::XEnumeration >  SAL_CALL
172         createEnumeration()
173         throw (::com::sun::star::uno::RuntimeException);
174 
175     // XTextContent
176     virtual void SAL_CALL attach(
177             const ::com::sun::star::uno::Reference<
178                 ::com::sun::star::text::XTextRange > & xTextRange)
179         throw (::com::sun::star::lang::IllegalArgumentException,
180             ::com::sun::star::uno::RuntimeException);
181     virtual ::com::sun::star::uno::Reference<
182                 ::com::sun::star::text::XTextRange > SAL_CALL getAnchor()
183         throw (::com::sun::star::uno::RuntimeException);
184 
185     // XTextRange
186     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >
187         SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException);
188     virtual ::com::sun::star::uno::Reference<
189                 ::com::sun::star::text::XTextRange > SAL_CALL getStart()
190         throw (::com::sun::star::uno::RuntimeException);
191     virtual ::com::sun::star::uno::Reference<
192                 ::com::sun::star::text::XTextRange > SAL_CALL getEnd()
193         throw (::com::sun::star::uno::RuntimeException);
194     virtual rtl::OUString SAL_CALL getString()
195         throw (::com::sun::star::uno::RuntimeException);
196     virtual void SAL_CALL setString(const rtl::OUString& rString)
197         throw (::com::sun::star::uno::RuntimeException);
198 
199     // XSimpleText
200     virtual ::com::sun::star::uno::Reference<
201                 ::com::sun::star::text::XTextCursor >  SAL_CALL
202         createTextCursor()
203         throw (::com::sun::star::uno::RuntimeException);
204     virtual ::com::sun::star::uno::Reference<
205                 ::com::sun::star::text::XTextCursor >  SAL_CALL
206         createTextCursorByRange(
207             const ::com::sun::star::uno::Reference<
208                 ::com::sun::star::text::XTextRange > & xTextPosition)
209         throw (::com::sun::star::uno::RuntimeException);
210     virtual void SAL_CALL insertString(
211             const ::com::sun::star::uno::Reference<
212                 ::com::sun::star::text::XTextRange > & xRange,
213             const rtl::OUString& aString, sal_Bool bAbsorb)
214         throw (::com::sun::star::uno::RuntimeException);
215     virtual void SAL_CALL insertControlCharacter(
216             const ::com::sun::star::uno::Reference<
217                 ::com::sun::star::text::XTextRange > & xRange,
218             sal_Int16 nControlCharacter, sal_Bool bAbsorb)
219         throw (::com::sun::star::lang::IllegalArgumentException,
220             ::com::sun::star::uno::RuntimeException);
221 
222     // XText
223     virtual void SAL_CALL insertTextContent(
224             const ::com::sun::star::uno::Reference<
225                 ::com::sun::star::text::XTextRange > & xRange,
226             const ::com::sun::star::uno::Reference<
227                 ::com::sun::star::text::XTextContent > & xContent,
228             sal_Bool bAbsorb)
229         throw (::com::sun::star::lang::IllegalArgumentException,
230             ::com::sun::star::uno::RuntimeException);
231     virtual void SAL_CALL removeTextContent(
232             const ::com::sun::star::uno::Reference<
233                 ::com::sun::star::text::XTextContent > & xContent)
234         throw (::com::sun::star::container::NoSuchElementException,
235             ::com::sun::star::uno::RuntimeException);
236 
237 };
238 
239 
240 typedef ::cppu::ImplInheritanceHelper2
241 <   SwXMeta
242 ,   ::com::sun::star::beans::XPropertySet
243 ,   ::com::sun::star::text::XTextField
244 > SwXMetaField_Base;
245 
246 class SwXMetaField
247     : public SwXMetaField_Base
248 {
249 
250 private:
251 
252     virtual ~SwXMetaField();
253 
254     friend ::com::sun::star::uno::Reference<
255             ::com::sun::star::rdf::XMetadatable >
256         SwXMeta::CreateXMeta(::sw::Meta &,
257             ::com::sun::star::uno::Reference< ::com::sun::star::text::XText>
258                 const&,
259             ::std::auto_ptr<TextRangeList_t const> pPortions);
260 
261     SwXMetaField(SwDoc *const pDoc, ::sw::Meta *const pMeta,
262         ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> const&
263             xParentText,
264         TextRangeList_t const*const pPortions);
265 
266 public:
267 
268     SwXMetaField(SwDoc *const pDoc);
269 
270     // XServiceInfo
271     virtual ::rtl::OUString SAL_CALL getImplementationName()
272         throw (::com::sun::star::uno::RuntimeException);
273     virtual sal_Bool SAL_CALL supportsService(
274             const ::rtl::OUString& ServiceName)
275         throw (::com::sun::star::uno::RuntimeException);
276     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
277         getSupportedServiceNames( )
278         throw (::com::sun::star::uno::RuntimeException);
279 
280     // XComponent
281     virtual void SAL_CALL dispose()
282         throw (::com::sun::star::uno::RuntimeException);
283     virtual void SAL_CALL addEventListener(
284             const ::com::sun::star::uno::Reference<
285                 ::com::sun::star::lang::XEventListener > & xListener)
286         throw (::com::sun::star::uno::RuntimeException);
287     virtual void SAL_CALL removeEventListener(
288             const ::com::sun::star::uno::Reference<
289                 ::com::sun::star::lang::XEventListener > & xListener)
290         throw (::com::sun::star::uno::RuntimeException);
291 
292     // XPropertySet
293     virtual ::com::sun::star::uno::Reference<
294             ::com::sun::star::beans::XPropertySetInfo > SAL_CALL
295         getPropertySetInfo()
296         throw (::com::sun::star::uno::RuntimeException);
297     virtual void SAL_CALL setPropertyValue(
298             const ::rtl::OUString& rPropertyName,
299             const ::com::sun::star::uno::Any& rValue)
300         throw (::com::sun::star::beans::UnknownPropertyException,
301             ::com::sun::star::beans::PropertyVetoException,
302             ::com::sun::star::lang::IllegalArgumentException,
303             ::com::sun::star::lang::WrappedTargetException,
304             ::com::sun::star::uno::RuntimeException);
305     virtual ::com::sun::star::uno::Any SAL_CALL
306         getPropertyValue(const ::rtl::OUString& rPropertyName)
307         throw (::com::sun::star::beans::UnknownPropertyException,
308             ::com::sun::star::lang::WrappedTargetException,
309             ::com::sun::star::uno::RuntimeException);
310     virtual void SAL_CALL addPropertyChangeListener(
311             const ::rtl::OUString& rPropertyName,
312             const ::com::sun::star::uno::Reference<
313                 ::com::sun::star::beans::XPropertyChangeListener >& xListener)
314         throw (::com::sun::star::beans::UnknownPropertyException,
315             ::com::sun::star::lang::WrappedTargetException,
316             ::com::sun::star::uno::RuntimeException);
317     virtual void SAL_CALL removePropertyChangeListener(
318             const ::rtl::OUString& rPropertyName,
319             const ::com::sun::star::uno::Reference<
320                 ::com::sun::star::beans::XPropertyChangeListener >& xListener)
321         throw (::com::sun::star::beans::UnknownPropertyException,
322             ::com::sun::star::lang::WrappedTargetException,
323             ::com::sun::star::uno::RuntimeException);
324     virtual void SAL_CALL addVetoableChangeListener(
325             const ::rtl::OUString& rPropertyName,
326             const ::com::sun::star::uno::Reference<
327                 ::com::sun::star::beans::XVetoableChangeListener >& xListener)
328         throw (::com::sun::star::beans::UnknownPropertyException,
329             ::com::sun::star::lang::WrappedTargetException,
330             ::com::sun::star::uno::RuntimeException);
331     virtual void SAL_CALL removeVetoableChangeListener(
332             const ::rtl::OUString& rPropertyName,
333             const ::com::sun::star::uno::Reference<
334                 ::com::sun::star::beans::XVetoableChangeListener >& xListener)
335         throw (::com::sun::star::beans::UnknownPropertyException,
336             ::com::sun::star::lang::WrappedTargetException,
337             ::com::sun::star::uno::RuntimeException);
338 
339     // XTextContent
340     virtual void SAL_CALL attach(
341             const ::com::sun::star::uno::Reference<
342                 ::com::sun::star::text::XTextRange > & xTextRange)
343         throw ( ::com::sun::star::lang::IllegalArgumentException,
344             ::com::sun::star::uno::RuntimeException );
345     virtual ::com::sun::star::uno::Reference<
346             ::com::sun::star::text::XTextRange > SAL_CALL getAnchor()
347         throw (::com::sun::star::uno::RuntimeException);
348 
349     // XTextField
350     virtual rtl::OUString SAL_CALL getPresentation(sal_Bool bShowCommand)
351         throw (::com::sun::star::uno::RuntimeException);
352 
353 };
354 
355 /// get prefix/suffix from the RDF repository. @throws RuntimeException
356 void getPrefixAndSuffix(
357         const ::com::sun::star::uno::Reference<
358             ::com::sun::star::frame::XModel>& xModel,
359         const ::com::sun::star::uno::Reference<
360             ::com::sun::star::rdf::XMetadatable>& xMetaField,
361         ::rtl::OUString *const o_pPrefix, ::rtl::OUString *const o_pSuffix);
362 
363 #endif // SW_UNOMETA_HXX
364 
365