Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <osl/mutex.hxx>
31 : : #include <vcl/svapp.hxx>
32 : :
33 : : #include <unomid.h>
34 : : #include <unotextrange.hxx>
35 : : #include <unorefmark.hxx>
36 : : #include <unotextcursor.hxx>
37 : : #include <unomap.hxx>
38 : : #include <unocrsr.hxx>
39 : : #include <unoevtlstnr.hxx>
40 : : #include <unocrsrhelper.hxx>
41 : : #include <doc.hxx>
42 : : #include <ndtxt.hxx>
43 : : #include <fmtrfmrk.hxx>
44 : : #include <txtrfmrk.hxx>
45 : : #include <hints.hxx>
46 : : #include <comphelper/servicehelper.hxx>
47 : :
48 : :
49 : : using namespace ::com::sun::star;
50 : : using ::rtl::OUString;
51 : :
52 : : /******************************************************************
53 : : * SwXReferenceMark
54 : : ******************************************************************/
55 [ + - ][ - + ]: 352 : class SwXReferenceMark::Impl
56 : : : public SwClient
57 : : {
58 : :
59 : : public:
60 : : SwEventListenerContainer m_ListenerContainer;
61 : : bool m_bIsDescriptor;
62 : : SwDoc * m_pDoc;
63 : : const SwFmtRefMark * m_pMarkFmt;
64 : : ::rtl::OUString m_sMarkName;
65 : :
66 : 176 : Impl( SwXReferenceMark & rThis,
67 : : SwDoc *const pDoc, SwFmtRefMark const*const pRefMark)
68 : : : SwClient((pDoc) ? pDoc->GetUnoCallBack() : 0)
69 : : , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
70 : : // #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code
71 : : , m_bIsDescriptor((0 == pRefMark) ? true : false)
72 : : , m_pDoc(pDoc)
73 [ + + ][ + - ]: 176 : , m_pMarkFmt(pRefMark)
74 : : {
75 [ + + ]: 176 : if (pRefMark)
76 : : {
77 : 100 : m_sMarkName = pRefMark->GetRefName();
78 : : }
79 : 176 : }
80 : :
81 : 287 : bool IsValid() const { return 0 != GetRegisteredIn(); }
82 : : void InsertRefMark( SwPaM & rPam, SwXTextCursor const*const pCursor );
83 : : void Invalidate();
84 : : protected:
85 : : // SwClient
86 : : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
87 : :
88 : : };
89 : :
90 : 175 : void SwXReferenceMark::Impl::Invalidate()
91 : : {
92 [ + + ]: 175 : if (IsValid())
93 : : {
94 : 38 : const_cast<SwModify*>(GetRegisteredIn())->Remove(this);
95 : : }
96 : 175 : m_ListenerContainer.Disposing();
97 : 175 : m_pDoc = 0;
98 : 175 : m_pMarkFmt = 0;
99 : 175 : }
100 : :
101 : 193 : void SwXReferenceMark::Impl::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
102 : : {
103 : 193 : ClientModify(this, pOld, pNew);
104 : :
105 [ + + ]: 193 : if (!GetRegisteredIn()) // removed => dispose
106 : : {
107 : 137 : Invalidate();
108 : : }
109 [ + - ]: 56 : else if (pOld)
110 : : {
111 [ + - ]: 56 : switch (pOld->Which())
112 : : {
113 : : case RES_REFMARK_DELETED:
114 [ + + ]: 56 : if (static_cast<const void*>(m_pMarkFmt) ==
115 : : static_cast<const SwPtrMsgPoolItem *>(pOld)->pObject)
116 : : {
117 : 38 : Invalidate();
118 : : }
119 : 56 : break;
120 : : }
121 : : }
122 : 193 : }
123 : :
124 : 176 : SwXReferenceMark::SwXReferenceMark(
125 : : SwDoc *const pDoc, SwFmtRefMark const*const pRefMark)
126 [ + - ][ + - ]: 176 : : m_pImpl( new SwXReferenceMark::Impl(*this, pDoc, pRefMark) )
127 : : {
128 : 176 : }
129 : :
130 [ + - ]: 176 : SwXReferenceMark::~SwXReferenceMark()
131 : : {
132 [ - + ]: 352 : }
133 : :
134 : : SwXReferenceMark *
135 : 8 : SwXReferenceMark::GetReferenceMark(
136 : : SwModify const& /*rUnoCB*/, SwFmtRefMark const& /*rMarkFmt*/)
137 : : {
138 : : // #i105557#: do not iterate over the registered clients: race condition
139 : : // to do this properly requires the SwXReferenceMark to register at the
140 : : // SwFmtRefMark directly, not at the unocallback
141 : 8 : return 0;
142 : : }
143 : :
144 : : SwXReferenceMark *
145 : 8 : SwXReferenceMark::CreateXReferenceMark(
146 : : SwDoc & rDoc, SwFmtRefMark const& rMarkFmt)
147 : : {
148 : : SwXReferenceMark *const pXMark(
149 : 8 : GetReferenceMark(*rDoc.GetUnoCallBack(), rMarkFmt) );
150 : : return (pXMark)
151 : : ? pXMark
152 [ + - ][ + - ]: 8 : : new SwXReferenceMark(&rDoc, &rMarkFmt);
153 : : }
154 : :
155 : : namespace
156 : : {
157 : : class theSwXReferenceMarkUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXReferenceMarkUnoTunnelId > {};
158 : : }
159 : :
160 : 5150 : const uno::Sequence< sal_Int8 > & SwXReferenceMark::getUnoTunnelId()
161 : : {
162 : 5150 : return theSwXReferenceMarkUnoTunnelId::get().getSeq();
163 : : }
164 : :
165 : : sal_Int64 SAL_CALL
166 : 132 : SwXReferenceMark::getSomething(const uno::Sequence< sal_Int8 >& rId)
167 : : throw (uno::RuntimeException)
168 : : {
169 : 132 : return ::sw::UnoTunnelImpl<SwXReferenceMark>(rId, this);
170 : : }
171 : :
172 : 0 : OUString SAL_CALL SwXReferenceMark::getImplementationName()
173 : : throw (uno::RuntimeException)
174 : : {
175 : 0 : return C2U("SwXReferenceMark");
176 : : }
177 : :
178 : : static char const*const g_ServicesReferenceMark[] =
179 : : {
180 : : "com.sun.star.text.TextContent",
181 : : "com.sun.star.text.ReferenceMark",
182 : : };
183 : :
184 : : static const size_t g_nServicesReferenceMark(
185 : : sizeof(g_ServicesReferenceMark)/sizeof(g_ServicesReferenceMark[0]));
186 : :
187 : : sal_Bool SAL_CALL
188 : 0 : SwXReferenceMark::supportsService(const OUString& rServiceName)
189 : : throw (uno::RuntimeException)
190 : : {
191 : : return ::sw::SupportsServiceImpl(
192 : 0 : g_nServicesReferenceMark, g_ServicesReferenceMark, rServiceName);
193 : : }
194 : :
195 : : uno::Sequence< OUString > SAL_CALL
196 : 0 : SwXReferenceMark::getSupportedServiceNames()
197 : : throw (uno::RuntimeException)
198 : : {
199 : : return ::sw::GetSupportedServiceNamesImpl(
200 : 0 : g_nServicesReferenceMark, g_ServicesReferenceMark);
201 : : }
202 : :
203 : : template<typename T> struct NotContainedIn
204 : : {
205 : : ::std::vector<T> const& m_rVector;
206 : 0 : explicit NotContainedIn(::std::vector<T> const& rVector)
207 : 0 : : m_rVector(rVector) { }
208 : 0 : bool operator() (T const& rT) {
209 : : return ::std::find(m_rVector.begin(), m_rVector.end(), rT)
210 [ # # ][ # # ]: 0 : == m_rVector.end();
211 : : }
212 : : };
213 : :
214 : 80 : void SwXReferenceMark::Impl::InsertRefMark(SwPaM& rPam,
215 : : SwXTextCursor const*const pCursor)
216 : : {
217 : : //! in some cases when this function is called the pDoc pointer member may have become
218 : : //! invalid/deleted thus we obtain the document pointer from rPaM where it should always
219 : : //! be valid.
220 : 80 : SwDoc *pDoc2 = rPam.GetDoc();
221 : :
222 [ + - ]: 80 : UnoActionContext aCont(pDoc2);
223 [ + - ][ + - ]: 80 : SwFmtRefMark aRefMark(m_sMarkName);
[ + - ]
224 [ + - ]: 80 : sal_Bool bMark = *rPam.GetPoint() != *rPam.GetMark();
225 : :
226 : : const bool bForceExpandHints( (!bMark && pCursor)
227 [ + + ][ + + ]: 80 : ? pCursor->IsAtEndOfMeta() : false );
[ + - ]
228 : : const SetAttrMode nInsertFlags = (bForceExpandHints)
229 : : ? ( nsSetAttrMode::SETATTR_FORCEHINTEXPAND
230 : : | nsSetAttrMode::SETATTR_DONTEXPAND)
231 [ + + ]: 80 : : nsSetAttrMode::SETATTR_DONTEXPAND;
232 : :
233 [ + - ]: 80 : ::std::vector<SwTxtAttr *> oldMarks;
234 [ + + ]: 80 : if (bMark)
235 : : {
236 : : oldMarks = rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
237 [ + - ]: 28 : rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_REFMARK);
238 : : }
239 : :
240 [ + - ]: 80 : pDoc2->InsertPoolItem( rPam, aRefMark, nInsertFlags );
241 : :
242 [ + + ][ + - ]: 80 : if( bMark && *rPam.GetPoint() > *rPam.GetMark())
[ + - ][ + + ]
243 : : {
244 : 28 : rPam.Exchange();
245 : : }
246 : :
247 : : // aRefMark was copied into the document pool; now retrieve real format...
248 : 80 : SwTxtAttr * pTxtAttr(0);
249 [ + + ]: 80 : if (bMark)
250 : : {
251 : : // #i107672#
252 : : // ensure that we do not retrieve a different mark at the same position
253 : : ::std::vector<SwTxtAttr *> const newMarks(
254 : : rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
255 [ + - ]: 28 : rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_REFMARK));
256 : : ::std::vector<SwTxtAttr *>::const_iterator const iter(
257 : : ::std::find_if(newMarks.begin(), newMarks.end(),
258 [ + - ]: 28 : NotContainedIn<SwTxtAttr *>(oldMarks)));
259 : : OSL_ASSERT(newMarks.end() != iter);
260 [ + - ][ + - ]: 28 : if (newMarks.end() != iter)
261 : : {
262 : 28 : pTxtAttr = *iter;
263 : 28 : }
264 : : }
265 : : else
266 : : {
267 : 52 : SwTxtNode *pTxtNd = rPam.GetNode()->GetTxtNode();
268 : : OSL_ASSERT(pTxtNd);
269 : : pTxtAttr = pTxtNd ? rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt(
270 [ + - ][ + - ]: 52 : rPam.GetPoint()->nContent.GetIndex() - 1, RES_TXTATR_REFMARK) : NULL;
271 : : }
272 : :
273 [ - + ]: 80 : if (!pTxtAttr)
274 : : {
275 : : throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
276 [ # # ][ # # ]: 0 : "SwXReferenceMark::InsertRefMark(): cannot insert attribute")), 0);
[ # # ]
277 : : }
278 : :
279 : 80 : m_pMarkFmt = &pTxtAttr->GetRefMark();
280 : :
281 [ + - ][ + - ]: 80 : pDoc2->GetUnoCallBack()->Add(this);
[ + - ][ + - ]
282 : 80 : }
283 : :
284 : : void SAL_CALL
285 : 76 : SwXReferenceMark::attach(const uno::Reference< text::XTextRange > & xTextRange)
286 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
287 : : {
288 [ + - ]: 76 : SolarMutexGuard aGuard;
289 : :
290 [ - + ]: 76 : if (!m_pImpl->m_bIsDescriptor)
291 : : {
292 [ # # ]: 0 : throw uno::RuntimeException();
293 : : }
294 [ + - ]: 76 : uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
295 : 76 : SwXTextRange* pRange = 0;
296 : 76 : OTextCursorHelper* pCursor = 0;
297 [ + - ]: 76 : if(xRangeTunnel.is())
298 : : {
299 [ + - ]: 76 : pRange = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
300 : : pCursor =
301 [ + - ]: 76 : ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
302 : : }
303 : : SwDoc *const pDocument =
304 [ + + ][ + - ]: 76 : (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0);
[ + - ][ + - ]
305 [ - + ]: 76 : if (!pDocument)
306 : : {
307 [ # # ]: 0 : throw lang::IllegalArgumentException();
308 : : }
309 : :
310 [ + - ]: 76 : SwUnoInternalPaM aPam(*pDocument);
311 : : //das muss jetzt sal_True liefern
312 [ + - ]: 76 : ::sw::XTextRangeToSwPaM(aPam, xTextRange);
313 [ + + ][ + - ]: 76 : m_pImpl->InsertRefMark(aPam, dynamic_cast<SwXTextCursor*>(pCursor));
314 : 76 : m_pImpl->m_bIsDescriptor = sal_False;
315 [ + - ][ + - ]: 76 : m_pImpl->m_pDoc = pDocument;
316 : 76 : }
317 : :
318 : : uno::Reference< text::XTextRange > SAL_CALL
319 : 2 : SwXReferenceMark::getAnchor() throw (uno::RuntimeException)
320 : : {
321 [ + - ]: 2 : SolarMutexGuard aGuard;
322 : :
323 [ + - ]: 2 : if (m_pImpl->IsValid())
324 : : {
325 : : SwFmtRefMark const*const pNewMark =
326 [ + - ][ + - ]: 2 : m_pImpl->m_pDoc->GetRefMark(m_pImpl->m_sMarkName);
[ + - ]
327 [ + - ][ + - ]: 2 : if (pNewMark && (pNewMark == m_pImpl->m_pMarkFmt))
[ + - ]
328 : : {
329 : : SwTxtRefMark const*const pTxtMark =
330 : 2 : m_pImpl->m_pMarkFmt->GetTxtRefMark();
331 [ + - ][ + - ]: 4 : if (pTxtMark &&
[ + - ]
332 : 2 : (&pTxtMark->GetTxtNode().GetNodes() ==
333 [ + - ]: 2 : &m_pImpl->m_pDoc->GetNodes()))
334 : : {
335 : 2 : SwTxtNode const& rTxtNode = pTxtMark->GetTxtNode();
336 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
337 : 2 : const ::std::auto_ptr<SwPaM> pPam( (pTxtMark->GetEnd())
338 : 0 : ? new SwPaM( rTxtNode, *pTxtMark->GetEnd(),
339 [ # # ]: 0 : rTxtNode, *pTxtMark->GetStart())
340 [ + - ][ + - ]: 2 : : new SwPaM( rTxtNode, *pTxtMark->GetStart()) );
[ - + # # ]
341 : : SAL_WNODEPRECATED_DECLARATIONS_POP
342 : :
343 : : return SwXTextRange::CreateXTextRange(
344 [ + - ][ + - ]: 2 : *m_pImpl->m_pDoc, *pPam->Start(), pPam->End());
[ + - ][ + - ]
345 : : }
346 : : }
347 : : }
348 [ # # ][ + - ]: 2 : return 0;
349 : : }
350 : :
351 : 2 : void SAL_CALL SwXReferenceMark::dispose() throw (uno::RuntimeException)
352 : : {
353 [ + - ]: 2 : SolarMutexGuard aGuard;
354 [ + - ]: 2 : if (m_pImpl->IsValid())
355 : : {
356 : : SwFmtRefMark const*const pNewMark =
357 [ + - ][ + - ]: 2 : m_pImpl->m_pDoc->GetRefMark(m_pImpl->m_sMarkName);
[ + - ]
358 [ + - ][ + - ]: 2 : if (pNewMark && (pNewMark == m_pImpl->m_pMarkFmt))
[ + - ]
359 : : {
360 : : SwTxtRefMark const*const pTxtMark =
361 : 2 : m_pImpl->m_pMarkFmt->GetTxtRefMark();
362 [ + - ][ + - ]: 4 : if (pTxtMark &&
[ + - ]
363 : 2 : (&pTxtMark->GetTxtNode().GetNodes() ==
364 [ + - ]: 2 : &m_pImpl->m_pDoc->GetNodes()))
365 : : {
366 : 2 : SwTxtNode const& rTxtNode = pTxtMark->GetTxtNode();
367 : 2 : xub_StrLen nStt = *pTxtMark->GetStart(),
368 : 2 : nEnd = pTxtMark->GetEnd() ? *pTxtMark->GetEnd()
369 [ - + ]: 2 : : nStt + 1;
370 : :
371 [ + - ]: 2 : SwPaM aPam( rTxtNode, nStt, rTxtNode, nEnd );
372 [ + - ][ + - ]: 2 : m_pImpl->m_pDoc->DeleteAndJoin( aPam );
373 : : }
374 : : }
375 : : }
376 [ # # ]: 0 : else if (m_pImpl->m_bIsDescriptor)
377 : : {
378 [ # # ]: 0 : m_pImpl->Invalidate();
379 [ + - ]: 2 : }
380 : 2 : }
381 : :
382 : 4 : void SAL_CALL SwXReferenceMark::addEventListener(
383 : : const uno::Reference< lang::XEventListener > & xListener)
384 : : throw (uno::RuntimeException)
385 : : {
386 [ + - ]: 4 : SolarMutexGuard g;
387 : :
388 [ - + ]: 4 : if (!m_pImpl->IsValid())
389 : : {
390 [ # # ]: 0 : throw uno::RuntimeException();
391 : : }
392 [ + - ][ + - ]: 4 : m_pImpl->m_ListenerContainer.AddListener(xListener);
393 : 4 : }
394 : :
395 : 2 : void SAL_CALL SwXReferenceMark::removeEventListener(
396 : : const uno::Reference< lang::XEventListener > & xListener)
397 : : throw (uno::RuntimeException)
398 : : {
399 [ + - ]: 2 : SolarMutexGuard g;
400 : :
401 [ + - ][ - + ]: 4 : if (!m_pImpl->IsValid() ||
[ - + ]
402 [ + - ]: 2 : !m_pImpl->m_ListenerContainer.RemoveListener(xListener))
403 : : {
404 [ # # ]: 0 : throw uno::RuntimeException();
405 [ + - ]: 2 : }
406 : 2 : }
407 : :
408 : 98 : OUString SAL_CALL SwXReferenceMark::getName()
409 : : throw (uno::RuntimeException)
410 : : {
411 [ + - ]: 98 : SolarMutexGuard aGuard;
412 [ + - ][ - + ]: 294 : if (!m_pImpl->IsValid() ||
[ - + ]
413 [ + - ][ + - ]: 196 : !m_pImpl->m_pDoc->GetRefMark(m_pImpl->m_sMarkName))
[ + - ][ + - ]
[ # # ]
414 : : {
415 [ # # ]: 0 : throw uno::RuntimeException();
416 : : }
417 [ + - ]: 98 : return m_pImpl->m_sMarkName;
418 : : }
419 : :
420 : 78 : void SAL_CALL SwXReferenceMark::setName(const OUString& rName)
421 : : throw (uno::RuntimeException)
422 : : {
423 [ + - ]: 78 : SolarMutexGuard aGuard;
424 [ + + ]: 78 : if (m_pImpl->m_bIsDescriptor)
425 : : {
426 : 74 : m_pImpl->m_sMarkName = rName;
427 : : }
428 : : else
429 : : {
430 [ + - ][ + - ]: 16 : if (!m_pImpl->IsValid()
[ - + ][ - + ]
431 [ + - ][ + - ]: 8 : || !m_pImpl->m_pDoc->GetRefMark(m_pImpl->m_sMarkName)
[ + - ][ + - ]
[ # # ]
432 [ + - ][ + - ]: 8 : || m_pImpl->m_pDoc->GetRefMark(rName))
[ + - ][ + - ]
[ # # ]
433 : : {
434 [ # # ]: 0 : throw uno::RuntimeException();
435 : : }
436 : : SwFmtRefMark const*const pCurMark =
437 [ + - ][ + - ]: 4 : m_pImpl->m_pDoc->GetRefMark(m_pImpl->m_sMarkName);
[ + - ]
438 [ + - ]: 8 : if ((rName != m_pImpl->m_sMarkName)
[ + - + - ]
[ + - ]
439 : 4 : && pCurMark && (pCurMark == m_pImpl->m_pMarkFmt))
440 : : {
441 [ + - ]: 4 : const UnoActionContext aCont(m_pImpl->m_pDoc);
442 : : SwTxtRefMark const*const pTxtMark =
443 : 4 : m_pImpl->m_pMarkFmt->GetTxtRefMark();
444 [ + - ][ + - ]: 8 : if (pTxtMark &&
[ + - ]
445 : 4 : (&pTxtMark->GetTxtNode().GetNodes() ==
446 [ + - ]: 4 : &m_pImpl->m_pDoc->GetNodes()))
447 : : {
448 : 4 : SwTxtNode const& rTxtNode = pTxtMark->GetTxtNode();
449 : 4 : xub_StrLen nStt = *pTxtMark->GetStart(),
450 : 4 : nEnd = pTxtMark->GetEnd() ? *pTxtMark->GetEnd()
451 [ - + ]: 4 : : nStt + 1;
452 : :
453 [ + - ]: 4 : SwPaM aPam( rTxtNode, nStt, rTxtNode, nEnd );
454 : : // deletes the m_pImpl->m_pDoc member in the SwXReferenceMark!
455 [ + - ]: 4 : m_pImpl->m_pDoc->DeleteAndJoin( aPam );
456 : : // The aPam will keep the correct and functional doc though
457 : :
458 : 4 : m_pImpl->m_sMarkName = rName;
459 : : //create a new one
460 [ + - ]: 4 : m_pImpl->InsertRefMark( aPam, 0 );
461 [ + - ]: 4 : m_pImpl->m_pDoc = aPam.GetDoc();
462 [ + - ]: 4 : }
463 : : }
464 [ + - ]: 78 : }
465 : 78 : }
466 : :
467 : : uno::Reference< beans::XPropertySetInfo > SAL_CALL
468 : 0 : SwXReferenceMark::getPropertySetInfo() throw (uno::RuntimeException)
469 : : {
470 [ # # ]: 0 : SolarMutexGuard g;
471 : :
472 : : static uno::Reference< beans::XPropertySetInfo > xRef =
473 : : aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH_EXTENSIONS)
474 [ # # ][ # # ]: 0 : ->getPropertySetInfo();
[ # # ][ # # ]
[ # # ]
475 [ # # ]: 0 : return xRef;
476 : : }
477 : :
478 : 0 : void SAL_CALL SwXReferenceMark::setPropertyValue(
479 : : const OUString& /*rPropertyName*/, const uno::Any& /*rValue*/ )
480 : : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
481 : : lang::IllegalArgumentException, lang::WrappedTargetException,
482 : : uno::RuntimeException)
483 : : {
484 [ # # ]: 0 : throw lang::IllegalArgumentException();
485 : : }
486 : :
487 : : uno::Any SAL_CALL
488 : 0 : SwXReferenceMark::getPropertyValue(const OUString& rPropertyName)
489 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
490 : : uno::RuntimeException)
491 : : {
492 : : // does not seem to need SolarMutex
493 : 0 : uno::Any aRet;
494 [ # # ][ # # ]: 0 : if (! ::sw::GetDefaultTextContentValue(aRet, rPropertyName))
495 : : {
496 [ # # ]: 0 : throw beans::UnknownPropertyException();
497 : : }
498 : 0 : return aRet;
499 : : }
500 : :
501 : 0 : void SAL_CALL SwXReferenceMark::addPropertyChangeListener(
502 : : const OUString& /*rPropertyName*/,
503 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
504 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
505 : : uno::RuntimeException)
506 : : {
507 : : OSL_FAIL("SwXReferenceMark::addPropertyChangeListener(): not implemented");
508 : 0 : }
509 : :
510 : 0 : void SAL_CALL SwXReferenceMark::removePropertyChangeListener(
511 : : const OUString& /*rPropertyName*/,
512 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
513 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
514 : : uno::RuntimeException)
515 : : {
516 : : OSL_FAIL("SwXReferenceMark::removePropertyChangeListener(): not implemented");
517 : 0 : }
518 : :
519 : 0 : void SAL_CALL SwXReferenceMark::addVetoableChangeListener(
520 : : const OUString& /*rPropertyName*/,
521 : : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
522 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
523 : : uno::RuntimeException)
524 : : {
525 : : OSL_FAIL("SwXReferenceMark::addVetoableChangeListener(): not implemented");
526 : 0 : }
527 : :
528 : 0 : void SAL_CALL SwXReferenceMark::removeVetoableChangeListener(
529 : : const OUString& /*rPropertyName*/,
530 : : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
531 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
532 : : uno::RuntimeException)
533 : : {
534 : : OSL_FAIL("SwXReferenceMark::removeVetoableChangeListener(): not implemented");
535 : 0 : }
536 : :
537 : : #include <com/sun/star/lang/DisposedException.hpp>
538 : : #include <unometa.hxx>
539 : : #include <unotext.hxx>
540 : : #include <unoport.hxx>
541 : : #include <txtatr.hxx>
542 : : #include <fmtmeta.hxx>
543 : : #include <docsh.hxx>
544 : :
545 : : /******************************************************************
546 : : * SwXMetaText
547 : : ******************************************************************/
548 [ - + ]: 279 : class SwXMetaText
549 : : : public SwXText
550 : : {
551 : : private:
552 : : SwXMeta & m_rMeta;
553 : :
554 : : virtual void PrepareForAttach(uno::Reference< text::XTextRange > & xRange,
555 : : const SwPaM & rPam);
556 : :
557 : : virtual bool CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb)
558 : : throw (lang::IllegalArgumentException, uno::RuntimeException);
559 : :
560 : : protected:
561 : : virtual const SwStartNode *GetStartNode() const;
562 : : virtual uno::Reference< text::XTextCursor >
563 : : CreateCursor() throw (uno::RuntimeException);
564 : :
565 : : public:
566 : : SwXMetaText(SwDoc & rDoc, SwXMeta & rMeta);
567 : :
568 : : /// make available for SwXMeta
569 : 182 : void Invalidate() { SwXText::Invalidate(); };
570 : :
571 : : // XInterface
572 : 0 : virtual void SAL_CALL acquire() throw()
573 : 0 : { OSL_FAIL("ERROR: SwXMetaText::acquire"); }
574 : 0 : virtual void SAL_CALL release() throw()
575 : 0 : { OSL_FAIL("ERROR: SwXMetaText::release"); }
576 : :
577 : : // XTypeProvider
578 : : virtual uno::Sequence< sal_Int8 > SAL_CALL
579 : : getImplementationId() throw (uno::RuntimeException);
580 : :
581 : : // XText
582 : : virtual uno::Reference< text::XTextCursor > SAL_CALL
583 : : createTextCursor() throw (uno::RuntimeException);
584 : : virtual uno::Reference< text::XTextCursor > SAL_CALL
585 : : createTextCursorByRange(
586 : : const uno::Reference< text::XTextRange > & xTextPosition)
587 : : throw (uno::RuntimeException);
588 : :
589 : : SwXMeta & GetXMeta() { return m_rMeta; }
590 : :
591 : : };
592 : :
593 : 279 : SwXMetaText::SwXMetaText(SwDoc & rDoc, SwXMeta & rMeta)
594 : : : SwXText(&rDoc, CURSOR_META)
595 : 279 : , m_rMeta(rMeta)
596 : : {
597 : 279 : }
598 : :
599 : 142 : const SwStartNode *SwXMetaText::GetStartNode() const
600 : : {
601 : : SwXText const * const pParent(
602 [ + - ][ + - ]: 142 : dynamic_cast<SwXText*>(m_rMeta.GetParentText().get()));
603 [ + - ]: 142 : return (pParent) ? pParent->GetStartNode() : 0;
604 : : }
605 : :
606 : 40 : void SwXMetaText::PrepareForAttach( uno::Reference<text::XTextRange> & xRange,
607 : : const SwPaM & rPam)
608 : : {
609 : : // create a new cursor to prevent modifying SwXTextRange
610 : : xRange = static_cast<text::XWordCursor*>(
611 : 40 : new SwXTextCursor(*GetDoc(), &m_rMeta, CURSOR_META, *rPam.GetPoint(),
612 [ + + ][ + - ]: 40 : (rPam.HasMark()) ? rPam.GetMark() : 0));
[ + - ][ + - ]
613 : 40 : }
614 : :
615 : 94 : bool SwXMetaText::CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb)
616 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
617 : : {
618 : 94 : return m_rMeta.CheckForOwnMemberMeta(rPam, bAbsorb);
619 : : }
620 : :
621 : 300 : uno::Reference< text::XTextCursor > SwXMetaText::CreateCursor()
622 : : throw (uno::RuntimeException)
623 : : {
624 : 300 : uno::Reference< text::XTextCursor > xRet;
625 [ + + ][ + - ]: 300 : if (IsValid())
626 : : {
627 : : SwTxtNode * pTxtNode;
628 : : xub_StrLen nMetaStart;
629 : : xub_StrLen nMetaEnd;
630 : : const bool bSuccess(
631 [ + - ]: 298 : m_rMeta.SetContentRange(pTxtNode, nMetaStart, nMetaEnd) );
632 [ + - ]: 298 : if (bSuccess)
633 : : {
634 [ + - ]: 298 : SwPosition aPos(*pTxtNode, nMetaStart);
635 : : xRet = static_cast<text::XWordCursor*>(
636 [ + - ][ + - ]: 298 : new SwXTextCursor(*GetDoc(), &m_rMeta, CURSOR_META, aPos));
[ + - ][ + - ]
[ + - ][ + - ]
637 : : }
638 : : }
639 : 300 : return xRet;
640 : : }
641 : :
642 : : uno::Sequence<sal_Int8> SAL_CALL
643 : 0 : SwXMetaText::getImplementationId() throw (uno::RuntimeException)
644 : : {
645 : 0 : return m_rMeta.getImplementationId();
646 : : }
647 : :
648 : : // XText
649 : : uno::Reference< text::XTextCursor > SAL_CALL
650 : 30 : SwXMetaText::createTextCursor() throw (uno::RuntimeException)
651 : : {
652 : 30 : return CreateCursor();
653 : : }
654 : :
655 : : uno::Reference< text::XTextCursor > SAL_CALL
656 : 6 : SwXMetaText::createTextCursorByRange(
657 : : const uno::Reference<text::XTextRange> & xTextPosition)
658 : : throw (uno::RuntimeException)
659 : : {
660 : 6 : const uno::Reference<text::XTextCursor> xCursor( CreateCursor() );
661 [ + + ][ + - ]: 6 : xCursor->gotoRange(xTextPosition, sal_False);
662 : 6 : return xCursor;
663 : : }
664 : :
665 : : /******************************************************************
666 : : * SwXMeta
667 : : ******************************************************************/
668 : : // the Meta has a cached list of text portions for its contents
669 : : // this list is created by SwXTextPortionEnumeration
670 : : // the Meta listens at the SwTxtNode and throws away the cache when it changes
671 [ + - ][ + - ]: 558 : class SwXMeta::Impl
[ - + ]
672 : : : public SwClient
673 : : {
674 : :
675 : : public:
676 : :
677 : : SwEventListenerContainer m_ListenerContainer;
678 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
679 : : ::std::auto_ptr<const TextRangeList_t> m_pTextPortions;
680 : : SAL_WNODEPRECATED_DECLARATIONS_POP
681 : : // 3 possible states: not attached, attached, disposed
682 : : bool m_bIsDisposed;
683 : : bool m_bIsDescriptor;
684 : : uno::Reference<text::XText> m_xParentText;
685 : : SwXMetaText m_Text;
686 : :
687 : 279 : Impl( SwXMeta & rThis, SwDoc & rDoc,
688 : : ::sw::Meta * const pMeta,
689 : : uno::Reference<text::XText> const& xParentText,
690 : : TextRangeList_t const * const pPortions)
691 : : : SwClient(pMeta)
692 : : , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
693 : : , m_pTextPortions( pPortions )
694 : : , m_bIsDisposed( false )
695 : : // #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code
696 : : , m_bIsDescriptor((0 == pMeta) ? true : false)
697 : : , m_xParentText(xParentText)
698 [ + + ][ + - ]: 279 : , m_Text(rDoc, rThis)
[ + - ]
699 : : {
700 : 279 : }
701 : :
702 : : inline const ::sw::Meta * GetMeta() const;
703 : : // only for SwXMetaField!
704 : : inline const ::sw::MetaField * GetMetaField() const;
705 : : protected:
706 : : // SwClient
707 : : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew);
708 : :
709 : : };
710 : :
711 : 2738 : inline const ::sw::Meta * SwXMeta::Impl::GetMeta() const
712 : : {
713 [ + - ]: 2738 : return static_cast< const ::sw::Meta * >(GetRegisteredIn());
714 : : }
715 : :
716 : : // SwModify
717 : 1855 : void SwXMeta::Impl::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
718 : : {
719 : 1855 : m_pTextPortions.reset(); // throw away cache (SwTxtNode changed)
720 : :
721 : 1855 : ClientModify(this, pOld, pNew);
722 : :
723 [ + + ]: 1855 : if (!GetRegisteredIn()) // removed => dispose
724 : : {
725 : 182 : m_ListenerContainer.Disposing();
726 : 182 : m_bIsDisposed = true;
727 : 182 : m_Text.Invalidate();
728 : : }
729 : 1855 : }
730 : :
731 : 144 : uno::Reference<text::XText> SwXMeta::GetParentText() const
732 : : {
733 : 144 : return m_pImpl->m_xParentText;
734 : : }
735 : :
736 : 85 : SwXMeta::SwXMeta(SwDoc *const pDoc, ::sw::Meta *const pMeta,
737 : : uno::Reference<text::XText> const& xParentText,
738 : : TextRangeList_t const*const pPortions)
739 [ + - ][ + - ]: 85 : : m_pImpl( new SwXMeta::Impl(*this, *pDoc, pMeta, xParentText, pPortions) )
740 : : {
741 : 85 : }
742 : :
743 : 194 : SwXMeta::SwXMeta(SwDoc *const pDoc)
744 [ + - ][ + - ]: 194 : : m_pImpl( new SwXMeta::Impl(*this, *pDoc, 0, 0, 0) )
[ + - ]
745 : : {
746 : 194 : }
747 : :
748 [ + - ]: 279 : SwXMeta::~SwXMeta()
749 : : {
750 [ - + ]: 458 : }
751 : :
752 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
753 : : uno::Reference<rdf::XMetadatable>
754 : 482 : SwXMeta::CreateXMeta(::sw::Meta & rMeta,
755 : : uno::Reference<text::XText> const& i_xParent,
756 : : ::std::auto_ptr<TextRangeList_t const> pPortions)
757 : : {
758 : : // re-use existing SwXMeta
759 : : // #i105557#: do not iterate over the registered clients: race condition
760 [ + - ]: 482 : uno::Reference<rdf::XMetadatable> xMeta(rMeta.GetXMeta());
761 [ + + ]: 482 : if (xMeta.is())
762 : : {
763 [ + + ]: 397 : if (pPortions.get()) // set cache in the XMeta to the given portions
764 : : {
765 [ + - ]: 277 : const uno::Reference<lang::XUnoTunnel> xUT(xMeta, uno::UNO_QUERY);
766 : : SwXMeta *const pXMeta(
767 [ + - ]: 277 : ::sw::UnoTunnelGetImplementation<SwXMeta>(xUT));
768 : : OSL_ENSURE(pXMeta, "no pXMeta?");
769 : : // NB: the meta must always be created with the complete content
770 : : // if SwXTextPortionEnumeration is created for a selection,
771 : : // it must be checked that the Meta is contained in the selection!
772 : 277 : pXMeta->m_pImpl->m_pTextPortions = pPortions;
773 : : // ??? is this necessary?
774 [ + - ][ - + ]: 277 : if (pXMeta->m_pImpl->m_xParentText.get() != i_xParent.get())
[ + - ]
775 : : {
776 : : OSL_FAIL("SwXMeta with different parent?");
777 [ # # ]: 0 : pXMeta->m_pImpl->m_xParentText.set(i_xParent);
778 : 277 : }
779 : : }
780 : 397 : return xMeta;
781 : : }
782 : :
783 : : // create new SwXMeta
784 [ + - ]: 85 : SwTxtNode * const pTxtNode( rMeta.GetTxtNode() );
785 : : OSL_ENSURE(pTxtNode, "CreateXMeta: no text node?");
786 [ - + ][ # # ]: 85 : if (!pTxtNode) { return 0; }
787 : 85 : uno::Reference<text::XText> xParentText(i_xParent);
788 [ + + ]: 85 : if (!xParentText.is())
789 : : {
790 [ + - ]: 12 : SwTxtMeta * const pTxtAttr( rMeta.GetTxtAttr() );
791 : : OSL_ENSURE(pTxtAttr, "CreateXMeta: no text attr?");
792 [ - + ][ # # ]: 12 : if (!pTxtAttr) { return 0; }
793 [ + - ]: 12 : const SwPosition aPos(*pTxtNode, *pTxtAttr->GetStart());
794 [ + - ][ + - ]: 12 : xParentText.set( ::sw::CreateParentXText(*pTxtNode->GetDoc(), aPos) );
[ + - ]
795 : : }
796 [ - + ][ # # ]: 85 : if (!xParentText.is()) { return 0; }
797 : 85 : SwXMeta *const pXMeta( (RES_TXTATR_META == rMeta.GetFmtMeta()->Which())
798 : 37 : ? new SwXMeta (pTxtNode->GetDoc(), &rMeta, xParentText,
799 [ + - ]: 37 : pPortions.release()) // temporarily un-auto_ptr :-(
800 : 48 : : new SwXMetaField(pTxtNode->GetDoc(), &rMeta, xParentText,
801 [ + - ][ + + ]: 122 : pPortions.release()));
802 : : // this is why the constructor is private: need to acquire pXMeta here
803 [ + - ][ + - ]: 85 : xMeta.set(pXMeta);
804 : : // in order to initialize the weak pointer cache in the core object
805 [ + - ]: 85 : rMeta.SetXMeta(xMeta);
806 : 482 : return xMeta;
807 : : }
808 : : SAL_WNODEPRECATED_DECLARATIONS_POP
809 : :
810 : 1410 : bool SwXMeta::SetContentRange(
811 : : SwTxtNode *& rpNode, xub_StrLen & rStart, xub_StrLen & rEnd ) const
812 : : {
813 : 1410 : ::sw::Meta const * const pMeta( m_pImpl->GetMeta() );
814 [ + - ]: 1410 : if (pMeta)
815 : : {
816 : 1410 : SwTxtMeta const * const pTxtAttr( pMeta->GetTxtAttr() );
817 [ + - ]: 1410 : if (pTxtAttr)
818 : : {
819 : 1410 : rpNode = pMeta->GetTxtNode();
820 [ + - ]: 1410 : if (rpNode)
821 : : {
822 : : // rStart points at the first position _within_ the meta!
823 : 1410 : rStart = *pTxtAttr->GetStart() + 1;
824 : 1410 : rEnd = *pTxtAttr->GetEnd();
825 : 1410 : return true;
826 : : }
827 : : }
828 : : }
829 : 1410 : return false;
830 : : }
831 : :
832 : 156 : bool SwXMeta::CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb)
833 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
834 : : {
835 : : SwTxtNode * pTxtNode;
836 : : xub_StrLen nMetaStart;
837 : : xub_StrLen nMetaEnd;
838 [ + - ]: 156 : const bool bSuccess( SetContentRange(pTxtNode, nMetaStart, nMetaEnd) );
839 : : OSL_ENSURE(bSuccess, "no pam?");
840 [ - + ]: 156 : if (!bSuccess)
841 [ # # ]: 0 : throw lang::DisposedException();
842 : :
843 [ + - ]: 156 : SwPosition const * const pStartPos( rPam.Start() );
844 [ + - ][ + + ]: 156 : if (&pStartPos->nNode.GetNode() != pTxtNode)
845 : : {
846 : : throw lang::IllegalArgumentException(
847 : : C2U("trying to insert into a nesting text content, but start "
848 : : "of text range not in same paragraph as text content"),
849 [ + - ][ + - ]: 6 : 0, 0);
[ + - ]
850 : : }
851 : 150 : bool bForceExpandHints(false);
852 : 150 : const xub_StrLen nStartPos(pStartPos->nContent.GetIndex());
853 : : // not <= but < because nMetaStart is behind dummy char!
854 : : // not >= but > because == means insert at end!
855 [ - + ][ + - ]: 150 : if ((nStartPos < nMetaStart) || (nStartPos > nMetaEnd))
856 : : {
857 : : throw lang::IllegalArgumentException(
858 : : C2U("trying to insert into a nesting text content, but start "
859 : : "of text range not inside text content"),
860 [ # # ][ # # ]: 0 : 0, 0);
[ # # ]
861 : : }
862 [ + + ]: 150 : else if (nStartPos == nMetaEnd)
863 : : {
864 : 38 : bForceExpandHints = true;
865 : : }
866 [ + + ][ + - ]: 150 : if (rPam.HasMark() && bAbsorb)
[ + + ]
867 : : {
868 [ + - ]: 78 : SwPosition const * const pEndPos( rPam.End() );
869 [ + - ][ - + ]: 78 : if (&pEndPos->nNode.GetNode() != pTxtNode)
870 : : {
871 : : throw lang::IllegalArgumentException(
872 : : C2U("trying to insert into a nesting text content, but end "
873 : : "of text range not in same paragraph as text content"),
874 [ # # ][ # # ]: 0 : 0, 0);
[ # # ]
875 : : }
876 : 78 : const xub_StrLen nEndPos(pEndPos->nContent.GetIndex());
877 : : // not <= but < because nMetaStart is behind dummy char!
878 : : // not >= but > because == means insert at end!
879 [ - + ][ + - ]: 78 : if ((nEndPos < nMetaStart) || (nEndPos > nMetaEnd))
880 : : {
881 : : throw lang::IllegalArgumentException(
882 : : C2U("trying to insert into a nesting text content, but end "
883 : : "of text range not inside text content"),
884 [ # # ][ # # ]: 6 : 0, 0);
[ # # ]
885 : : }
886 [ + + ]: 78 : else if (nEndPos == nMetaEnd)
887 : : {
888 : 66 : bForceExpandHints = true;
889 : : }
890 : : }
891 : 150 : return bForceExpandHints;
892 : : }
893 : :
894 : : namespace
895 : : {
896 : : class theSwXMetaUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXMetaUnoTunnelId > {};
897 : : }
898 : :
899 : 6208 : const uno::Sequence< sal_Int8 > & SwXMeta::getUnoTunnelId()
900 : : {
901 : 6208 : return theSwXMetaUnoTunnelId::get().getSeq();
902 : : }
903 : :
904 : : // XUnoTunnel
905 : : sal_Int64 SAL_CALL
906 : 913 : SwXMeta::getSomething( const uno::Sequence< sal_Int8 > & i_rId )
907 : : throw (uno::RuntimeException)
908 : : {
909 : 913 : return ::sw::UnoTunnelImpl<SwXMeta>(i_rId, this);
910 : : }
911 : :
912 : : // XServiceInfo
913 : : ::rtl::OUString SAL_CALL
914 : 0 : SwXMeta::getImplementationName() throw (uno::RuntimeException)
915 : : {
916 : 0 : return C2U("SwXMeta");
917 : : }
918 : :
919 : : static char const*const g_ServicesMeta[] =
920 : : {
921 : : "com.sun.star.text.TextContent",
922 : : "com.sun.star.text.InContentMetadata",
923 : : };
924 : :
925 : : static const size_t g_nServicesMeta(
926 : : sizeof(g_ServicesMeta)/sizeof(g_ServicesMeta[0]));
927 : :
928 : : sal_Bool SAL_CALL
929 : 20 : SwXMeta::supportsService(const ::rtl::OUString& rServiceName)
930 : : throw (uno::RuntimeException)
931 : : {
932 : : return ::sw::SupportsServiceImpl(
933 : 20 : g_nServicesMeta, g_ServicesMeta, rServiceName);
934 : : }
935 : :
936 : : uno::Sequence< ::rtl::OUString > SAL_CALL
937 : 0 : SwXMeta::getSupportedServiceNames() throw (uno::RuntimeException)
938 : : {
939 : 0 : return ::sw::GetSupportedServiceNamesImpl(g_nServicesMeta, g_ServicesMeta);
940 : : }
941 : :
942 : : // XComponent
943 : : void SAL_CALL
944 : 0 : SwXMeta::addEventListener(
945 : : uno::Reference< lang::XEventListener> const & xListener )
946 : : throw (uno::RuntimeException)
947 : : {
948 [ # # ]: 0 : SolarMutexGuard g;
949 : :
950 [ # # ]: 0 : m_pImpl->m_ListenerContainer.AddListener(xListener);
951 [ # # ]: 0 : if (m_pImpl->m_bIsDisposed)
952 : : {
953 [ # # ]: 0 : m_pImpl->m_ListenerContainer.Disposing();
954 [ # # ]: 0 : }
955 : 0 : }
956 : :
957 : : void SAL_CALL
958 : 0 : SwXMeta::removeEventListener(
959 : : uno::Reference< lang::XEventListener> const & xListener )
960 : : throw (uno::RuntimeException)
961 : : {
962 [ # # ]: 0 : SolarMutexGuard g;
963 : :
964 [ # # ]: 0 : if (!m_pImpl->m_bIsDisposed)
965 : : {
966 [ # # ]: 0 : m_pImpl->m_ListenerContainer.RemoveListener(xListener);
967 [ # # ]: 0 : }
968 : 0 : }
969 : :
970 : : void SAL_CALL
971 : 2 : SwXMeta::dispose() throw (uno::RuntimeException)
972 : : {
973 [ + - ]: 2 : SolarMutexGuard g;
974 : :
975 [ - + ]: 2 : if (m_pImpl->m_bIsDescriptor)
976 : : {
977 : 0 : m_pImpl->m_pTextPortions.reset();
978 [ # # ]: 0 : m_pImpl->m_ListenerContainer.Disposing();
979 : 0 : m_pImpl->m_bIsDisposed = true;
980 [ # # ]: 0 : m_pImpl->m_Text.Invalidate();
981 : : }
982 [ + - ]: 2 : else if (!m_pImpl->m_bIsDisposed)
983 : : {
984 : : SwTxtNode * pTxtNode;
985 : : xub_StrLen nMetaStart;
986 : : xub_StrLen nMetaEnd;
987 [ + - ]: 2 : const bool bSuccess(SetContentRange(pTxtNode, nMetaStart, nMetaEnd));
988 : : OSL_ENSURE(bSuccess, "no pam?");
989 [ + - ]: 2 : if (bSuccess)
990 : : {
991 : : // -1 because of CH_TXTATR
992 [ + - ]: 2 : SwPaM aPam( *pTxtNode, nMetaStart - 1, *pTxtNode, nMetaEnd );
993 : 2 : SwDoc * const pDoc( pTxtNode->GetDoc() );
994 [ + - ]: 2 : pDoc->DeleteAndJoin( aPam );
995 : :
996 : : // removal should call Modify and do the dispose
997 [ + - ]: 2 : OSL_ENSURE(m_pImpl->m_bIsDisposed, "zombie meta");
998 : : }
999 [ + - ]: 2 : }
1000 : 2 : }
1001 : :
1002 : : void SAL_CALL
1003 : 194 : SwXMeta::AttachImpl(const uno::Reference< text::XTextRange > & i_xTextRange,
1004 : : const sal_uInt16 i_nWhich)
1005 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
1006 : : {
1007 [ + - ]: 194 : SolarMutexGuard g;
1008 : :
1009 [ - + ]: 194 : if (m_pImpl->m_bIsDisposed)
1010 : : {
1011 [ # # ]: 0 : throw lang::DisposedException();
1012 : : }
1013 [ - + ]: 194 : if (!m_pImpl->m_bIsDescriptor)
1014 : : {
1015 : : throw uno::RuntimeException(
1016 : : rtl::OUString("SwXMeta::attach(): already attached"),
1017 [ # # ][ # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this));
1018 : : }
1019 : :
1020 [ + - ]: 194 : uno::Reference<lang::XUnoTunnel> xRangeTunnel(i_xTextRange, uno::UNO_QUERY);
1021 [ - + ]: 194 : if (!xRangeTunnel.is())
1022 : : {
1023 : : throw lang::IllegalArgumentException(
1024 : : rtl::OUString("SwXMeta::attach(): argument is no XUnoTunnel"),
1025 [ # # ][ # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this), 0);
1026 : : }
1027 : : SwXTextRange *const pRange(
1028 [ + - ]: 194 : ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel));
1029 : : OTextCursorHelper *const pCursor( (pRange) ? 0 :
1030 [ + + ][ + - ]: 194 : ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel));
1031 [ + + ][ - + ]: 194 : if (!pRange && !pCursor)
1032 : : {
1033 : : throw lang::IllegalArgumentException(
1034 : : rtl::OUString("SwXMeta::attach(): argument not supported type"),
1035 [ # # ][ # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this), 0);
1036 : : }
1037 : :
1038 : : SwDoc * const pDoc(
1039 [ + + ][ + - ]: 194 : pRange ? pRange->GetDoc() : pCursor ? pCursor->GetDoc() : 0 );
[ + - ][ + - ]
1040 [ - + ]: 194 : if (!pDoc)
1041 : : {
1042 : : throw lang::IllegalArgumentException(
1043 : : rtl::OUString("SwXMeta::attach(): argument has no SwDoc"),
1044 [ # # ][ # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this), 0);
1045 : : }
1046 : :
1047 [ + - ]: 194 : SwUnoInternalPaM aPam(*pDoc);
1048 [ + - ]: 194 : ::sw::XTextRangeToSwPaM(aPam, i_xTextRange);
1049 : :
1050 [ + - ]: 194 : UnoActionContext aContext(pDoc);
1051 : :
1052 : : SwXTextCursor const*const pTextCursor(
1053 [ + + ]: 194 : dynamic_cast<SwXTextCursor*>(pCursor));
1054 : : const bool bForceExpandHints((pTextCursor)
1055 [ + + ][ + - ]: 194 : ? pTextCursor->IsAtEndOfMeta() : false);
1056 : : const SetAttrMode nInsertFlags( (bForceExpandHints)
1057 : : ? ( nsSetAttrMode::SETATTR_FORCEHINTEXPAND
1058 : : | nsSetAttrMode::SETATTR_DONTEXPAND)
1059 [ + + ]: 194 : : nsSetAttrMode::SETATTR_DONTEXPAND );
1060 : :
1061 : : const ::boost::shared_ptr< ::sw::Meta> pMeta( (RES_TXTATR_META == i_nWhich)
1062 : 0 : ? ::boost::shared_ptr< ::sw::Meta>( new ::sw::Meta() )
1063 : : : ::boost::shared_ptr< ::sw::Meta>(
1064 [ + + ][ + - ]: 194 : pDoc->GetMetaFieldManager().makeMetaField()) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + + ]
[ + - ][ + + ]
[ # # # # ]
1065 [ + - ]: 194 : SwFmtMeta meta(pMeta, i_nWhich); // this is cloned by Insert!
1066 [ + - ]: 194 : const bool bSuccess( pDoc->InsertPoolItem( aPam, meta, nInsertFlags ) );
1067 [ + - ]: 194 : SwTxtAttr * const pTxtAttr( pMeta->GetTxtAttr() );
1068 [ + + ]: 194 : if (!bSuccess)
1069 : : {
1070 : : throw lang::IllegalArgumentException(
1071 : : rtl::OUString("SwXMeta::attach(): cannot create meta: range invalid?"),
1072 [ + - ][ + - ]: 4 : static_cast< ::cppu::OWeakObject* >(this), 1);
1073 : : }
1074 [ - + ]: 190 : if (!pTxtAttr)
1075 : : {
1076 : : OSL_FAIL("meta inserted, but has no text attribute?");
1077 : : throw uno::RuntimeException(
1078 : : rtl::OUString("SwXMeta::attach(): cannot create meta"),
1079 [ # # ][ # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this));
1080 : : }
1081 : :
1082 [ + - ]: 190 : pMeta->Add(m_pImpl.get());
1083 [ + - ][ + - ]: 190 : pMeta->SetXMeta(uno::Reference<rdf::XMetadatable>(this));
1084 : :
1085 [ + - ][ + - ]: 190 : m_pImpl->m_xParentText = ::sw::CreateParentXText(*pDoc, *aPam.GetPoint());
1086 : :
1087 [ + - ][ + - ]: 194 : m_pImpl->m_bIsDescriptor = false;
[ + - ][ + - ]
[ + - ]
1088 : 190 : }
1089 : :
1090 : : // XTextContent
1091 : : void SAL_CALL
1092 : 142 : SwXMeta::attach(const uno::Reference< text::XTextRange > & i_xTextRange)
1093 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
1094 : : {
1095 : 142 : return SwXMeta::AttachImpl(i_xTextRange, RES_TXTATR_META);
1096 : : }
1097 : :
1098 : : uno::Reference< text::XTextRange > SAL_CALL
1099 : 46 : SwXMeta::getAnchor() throw (uno::RuntimeException)
1100 : : {
1101 [ + - ]: 46 : SolarMutexGuard g;
1102 : :
1103 [ - + ]: 46 : if (m_pImpl->m_bIsDisposed)
1104 : : {
1105 [ # # ]: 0 : throw lang::DisposedException();
1106 : : }
1107 [ - + ]: 46 : if (m_pImpl->m_bIsDescriptor)
1108 : : {
1109 : : throw uno::RuntimeException(
1110 : : rtl::OUString("SwXMeta::getAnchor(): not inserted"),
1111 [ # # ][ # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this));
1112 : : }
1113 : :
1114 : : SwTxtNode * pTxtNode;
1115 : : xub_StrLen nMetaStart;
1116 : : xub_StrLen nMetaEnd;
1117 [ + - ]: 46 : const bool bSuccess(SetContentRange(pTxtNode, nMetaStart, nMetaEnd));
1118 : : OSL_ENSURE(bSuccess, "no pam?");
1119 [ - + ]: 46 : if (!bSuccess)
1120 : : {
1121 : : throw lang::DisposedException(
1122 : : rtl::OUString("SwXMeta::getAnchor(): not attached"),
1123 [ # # ][ # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this));
1124 : : }
1125 : :
1126 [ + - ]: 46 : const SwPosition start(*pTxtNode, nMetaStart - 1); // -1 due to CH_TXTATR
1127 [ + - ]: 46 : const SwPosition end(*pTxtNode, nMetaEnd);
1128 [ + - ][ + - ]: 46 : return SwXTextRange::CreateXTextRange(*pTxtNode->GetDoc(), start, &end);
[ + - ][ + - ]
1129 : : }
1130 : :
1131 : : // XTextRange
1132 : : uno::Reference< text::XText > SAL_CALL
1133 : 2 : SwXMeta::getText() throw (uno::RuntimeException)
1134 : : {
1135 [ + - ]: 2 : SolarMutexGuard g;
1136 [ + - ][ + - ]: 2 : return this;
1137 : : }
1138 : :
1139 : : uno::Reference< text::XTextRange > SAL_CALL
1140 : 68 : SwXMeta::getStart() throw (uno::RuntimeException)
1141 : : {
1142 [ + - ]: 68 : SolarMutexGuard g;
1143 [ + - ][ + - ]: 68 : return m_pImpl->m_Text.getStart();
1144 : : }
1145 : :
1146 : : uno::Reference< text::XTextRange > SAL_CALL
1147 : 62 : SwXMeta::getEnd() throw (uno::RuntimeException)
1148 : : {
1149 [ + - ]: 62 : SolarMutexGuard g;
1150 [ + - ][ + - ]: 62 : return m_pImpl->m_Text.getEnd();
1151 : : }
1152 : :
1153 : : rtl::OUString SAL_CALL
1154 : 80 : SwXMeta::getString() throw (uno::RuntimeException)
1155 : : {
1156 [ + - ]: 80 : SolarMutexGuard g;
1157 [ + - ][ + - ]: 80 : return m_pImpl->m_Text.getString();
1158 : : }
1159 : :
1160 : : void SAL_CALL
1161 : 54 : SwXMeta::setString(const rtl::OUString& rString) throw (uno::RuntimeException)
1162 : : {
1163 [ + - ]: 54 : SolarMutexGuard g;
1164 [ + - ][ + - ]: 54 : return m_pImpl->m_Text.setString(rString);
1165 : : }
1166 : :
1167 : : // XSimpleText
1168 : : uno::Reference< text::XTextCursor > SAL_CALL
1169 : 30 : SwXMeta::createTextCursor() throw (uno::RuntimeException)
1170 : : {
1171 [ + - ]: 30 : SolarMutexGuard g;
1172 [ + - ][ + - ]: 30 : return m_pImpl->m_Text.createTextCursor();
1173 : : }
1174 : :
1175 : : uno::Reference< text::XTextCursor > SAL_CALL
1176 : 6 : SwXMeta::createTextCursorByRange(
1177 : : const uno::Reference<text::XTextRange> & xTextPosition)
1178 : : throw (uno::RuntimeException)
1179 : : {
1180 [ + - ]: 6 : SolarMutexGuard g;
1181 [ + + ][ + - ]: 6 : return m_pImpl->m_Text.createTextCursorByRange(xTextPosition);
1182 : : }
1183 : :
1184 : : void SAL_CALL
1185 : 8 : SwXMeta::insertString(const uno::Reference<text::XTextRange> & xRange,
1186 : : const rtl::OUString& rString, sal_Bool bAbsorb)
1187 : : throw (uno::RuntimeException)
1188 : : {
1189 [ + - ]: 8 : SolarMutexGuard g;
1190 [ + + ][ + - ]: 8 : return m_pImpl->m_Text.insertString(xRange, rString, bAbsorb);
1191 : : }
1192 : :
1193 : : void SAL_CALL
1194 : 8 : SwXMeta::insertControlCharacter(const uno::Reference<text::XTextRange> & xRange,
1195 : : sal_Int16 nControlCharacter, sal_Bool bAbsorb)
1196 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
1197 : : {
1198 [ + - ]: 8 : SolarMutexGuard g;
1199 : 8 : return m_pImpl->m_Text.insertControlCharacter(xRange, nControlCharacter,
1200 [ + - ][ + + ]: 8 : bAbsorb);
1201 : : }
1202 : :
1203 : : // XText
1204 : : void SAL_CALL
1205 : 86 : SwXMeta::insertTextContent( const uno::Reference<text::XTextRange> & xRange,
1206 : : const uno::Reference<text::XTextContent> & xContent, sal_Bool bAbsorb)
1207 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
1208 : : {
1209 [ + - ]: 86 : SolarMutexGuard g;
1210 [ + + ][ + - ]: 86 : return m_pImpl->m_Text.insertTextContent(xRange, xContent, bAbsorb);
1211 : : }
1212 : :
1213 : : void SAL_CALL
1214 : 4 : SwXMeta::removeTextContent(
1215 : : const uno::Reference< text::XTextContent > & xContent)
1216 : : throw (container::NoSuchElementException, uno::RuntimeException)
1217 : : {
1218 [ + - ]: 4 : SolarMutexGuard g;
1219 [ + + ][ + - ]: 4 : return m_pImpl->m_Text.removeTextContent(xContent);
1220 : : }
1221 : :
1222 : : // XChild
1223 : : uno::Reference< uno::XInterface > SAL_CALL
1224 : 12 : SwXMeta::getParent() throw (uno::RuntimeException)
1225 : : {
1226 [ + - ]: 12 : SolarMutexGuard g;
1227 : : SwTxtNode * pTxtNode;
1228 : : xub_StrLen nMetaStart;
1229 : : xub_StrLen nMetaEnd;
1230 [ + - ]: 12 : bool const bSuccess( SetContentRange(pTxtNode, nMetaStart, nMetaEnd) );
1231 : : OSL_ENSURE(bSuccess, "no pam?");
1232 [ - + ][ # # ]: 12 : if (!bSuccess) { throw lang::DisposedException(); }
1233 : : // in order to prevent getting this meta, subtract 1 from nMetaStart;
1234 : : // so we get the index of the dummy character, and we exclude it
1235 : : // by calling GetTxtAttrAt(_, _, PARENT) in GetNestedTextContent
1236 : : uno::Reference<text::XTextContent> const xRet(
1237 : : SwUnoCursorHelper::GetNestedTextContent(*pTxtNode, nMetaStart - 1,
1238 [ + - ]: 12 : true) );
1239 [ + - ]: 12 : return xRet;
1240 : : }
1241 : :
1242 : : void SAL_CALL
1243 : 2 : SwXMeta::setParent(uno::Reference< uno::XInterface > const& /*xParent*/)
1244 : : throw (uno::RuntimeException, lang::NoSupportException)
1245 : : {
1246 [ + - ][ + - ]: 2 : throw lang::NoSupportException(rtl::OUString("setting parent not supported"), *this);
1247 : : }
1248 : :
1249 : : // XElementAccess
1250 : : uno::Type SAL_CALL
1251 : 0 : SwXMeta::getElementType() throw (uno::RuntimeException)
1252 : : {
1253 : 0 : return text::XTextRange::static_type();
1254 : : }
1255 : :
1256 : : sal_Bool SAL_CALL
1257 : 0 : SwXMeta::hasElements() throw (uno::RuntimeException)
1258 : : {
1259 [ # # ]: 0 : SolarMutexGuard g;
1260 : :
1261 [ # # ][ # # ]: 0 : return m_pImpl->GetRegisteredIn() ? sal_True : sal_False;
1262 : : }
1263 : :
1264 : : // XEnumerationAccess
1265 : : uno::Reference< container::XEnumeration > SAL_CALL
1266 : 352 : SwXMeta::createEnumeration() throw (uno::RuntimeException)
1267 : : {
1268 [ + - ]: 352 : SolarMutexGuard g;
1269 : :
1270 [ - + ]: 352 : if (m_pImpl->m_bIsDisposed)
1271 : : {
1272 [ # # ]: 0 : throw lang::DisposedException();
1273 : : }
1274 [ - + ]: 352 : if (m_pImpl->m_bIsDescriptor)
1275 : : {
1276 : : throw uno::RuntimeException(
1277 : : rtl::OUString("createEnumeration(): not inserted"),
1278 [ # # ][ # # ]: 0 : static_cast< ::cppu::OWeakObject* >(this));
1279 : : }
1280 : :
1281 : : SwTxtNode * pTxtNode;
1282 : : xub_StrLen nMetaStart;
1283 : : xub_StrLen nMetaEnd;
1284 [ + - ]: 352 : const bool bSuccess(SetContentRange(pTxtNode, nMetaStart, nMetaEnd));
1285 : : OSL_ENSURE(bSuccess, "no pam?");
1286 [ - + ]: 352 : if (!bSuccess)
1287 [ # # ]: 0 : throw lang::DisposedException();
1288 : :
1289 [ + - ]: 352 : SwPaM aPam(*pTxtNode, nMetaStart);
1290 : :
1291 [ + + ]: 352 : if (!m_pImpl->m_pTextPortions.get())
1292 : : {
1293 : : return new SwXTextPortionEnumeration(
1294 [ + - ][ + - ]: 2 : aPam, GetParentText(), nMetaStart, nMetaEnd);
[ + - ][ + - ]
1295 : : }
1296 : : else // cached!
1297 : : {
1298 [ + - ][ + - ]: 350 : return new SwXTextPortionEnumeration(aPam, *m_pImpl->m_pTextPortions);
[ + - ]
1299 [ + - ][ + - ]: 352 : }
1300 : : }
1301 : :
1302 : : // MetadatableMixin
1303 : 1066 : ::sfx2::Metadatable* SwXMeta::GetCoreObject()
1304 : : {
1305 : 1066 : return const_cast< ::sw::Meta * >(m_pImpl->GetMeta());
1306 : : }
1307 : :
1308 : 262 : uno::Reference<frame::XModel> SwXMeta::GetModel()
1309 : : {
1310 : 262 : ::sw::Meta const * const pMeta( m_pImpl->GetMeta() );
1311 [ + - ]: 262 : if (pMeta)
1312 : : {
1313 : 262 : SwTxtNode const * const pTxtNode( pMeta->GetTxtNode() );
1314 [ + - ]: 262 : if (pTxtNode)
1315 : : {
1316 : 262 : SwDocShell const * const pShell(pTxtNode->GetDoc()->GetDocShell());
1317 [ + - ]: 262 : return (pShell) ? pShell->GetModel() : 0;
1318 : : }
1319 : : }
1320 : 262 : return 0;
1321 : : }
1322 : :
1323 : : /******************************************************************
1324 : : * SwXMetaField
1325 : : ******************************************************************/
1326 : 94 : inline const ::sw::MetaField * SwXMeta::Impl::GetMetaField() const
1327 : : {
1328 [ + - ]: 94 : return static_cast< const ::sw::MetaField * >(GetRegisteredIn());
1329 : : }
1330 : :
1331 : 48 : SwXMetaField::SwXMetaField(SwDoc *const pDoc, ::sw::Meta *const pMeta,
1332 : : uno::Reference<text::XText> const& xParentText,
1333 : : TextRangeList_t const*const pPortions)
1334 : 48 : : SwXMetaField_Base(pDoc, pMeta, xParentText, pPortions)
1335 : : {
1336 : : OSL_ENSURE(pMeta && dynamic_cast< ::sw::MetaField* >(pMeta),
1337 : : "SwXMetaField created for wrong hint!");
1338 : 48 : }
1339 : :
1340 : 52 : SwXMetaField::SwXMetaField(SwDoc *const pDoc)
1341 : 52 : : SwXMetaField_Base(pDoc)
1342 : : {
1343 : 52 : }
1344 : :
1345 : 100 : SwXMetaField::~SwXMetaField()
1346 : : {
1347 [ - + ]: 200 : }
1348 : :
1349 : : // XServiceInfo
1350 : : ::rtl::OUString SAL_CALL
1351 : 0 : SwXMetaField::getImplementationName() throw (uno::RuntimeException)
1352 : : {
1353 : 0 : return C2U("SwXMetaField");
1354 : : }
1355 : :
1356 : : static char const*const g_ServicesMetaField[] =
1357 : : {
1358 : : "com.sun.star.text.TextContent",
1359 : : "com.sun.star.text.TextField",
1360 : : "com.sun.star.text.textfield.MetadataField",
1361 : : };
1362 : :
1363 : : static const size_t g_nServicesMetaField(
1364 : : sizeof(g_ServicesMetaField)/sizeof(g_ServicesMetaField[0]));
1365 : :
1366 : : sal_Bool SAL_CALL
1367 : 40 : SwXMetaField::supportsService(const ::rtl::OUString& rServiceName)
1368 : : throw (uno::RuntimeException)
1369 : : {
1370 : : return ::sw::SupportsServiceImpl(
1371 : 40 : g_nServicesMetaField, g_ServicesMetaField, rServiceName);
1372 : : }
1373 : :
1374 : : uno::Sequence< ::rtl::OUString > SAL_CALL
1375 : 40 : SwXMetaField::getSupportedServiceNames() throw (uno::RuntimeException)
1376 : : {
1377 : : return ::sw::GetSupportedServiceNamesImpl(
1378 : 40 : g_nServicesMetaField, g_ServicesMetaField);
1379 : : }
1380 : :
1381 : : // XComponent
1382 : : void SAL_CALL
1383 : 0 : SwXMetaField::addEventListener(
1384 : : uno::Reference< lang::XEventListener> const & xListener )
1385 : : throw (uno::RuntimeException)
1386 : : {
1387 : 0 : return SwXMeta::addEventListener(xListener);
1388 : : }
1389 : :
1390 : : void SAL_CALL
1391 : 0 : SwXMetaField::removeEventListener(
1392 : : uno::Reference< lang::XEventListener> const & xListener )
1393 : : throw (uno::RuntimeException)
1394 : : {
1395 : 0 : return SwXMeta::removeEventListener(xListener);
1396 : : }
1397 : :
1398 : : void SAL_CALL
1399 : 0 : SwXMetaField::dispose() throw (uno::RuntimeException)
1400 : : {
1401 : 0 : return SwXMeta::dispose();
1402 : : }
1403 : :
1404 : : // XTextContent
1405 : : void SAL_CALL
1406 : 52 : SwXMetaField::attach(const uno::Reference< text::XTextRange > & i_xTextRange)
1407 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
1408 : : {
1409 : 52 : return SwXMeta::AttachImpl(i_xTextRange, RES_TXTATR_METAFIELD);
1410 : : }
1411 : :
1412 : : uno::Reference< text::XTextRange > SAL_CALL
1413 : 40 : SwXMetaField::getAnchor() throw (uno::RuntimeException)
1414 : : {
1415 : 40 : return SwXMeta::getAnchor();
1416 : : }
1417 : :
1418 : : // XPropertySet
1419 : : uno::Reference< beans::XPropertySetInfo > SAL_CALL
1420 : 34 : SwXMetaField::getPropertySetInfo() throw (uno::RuntimeException)
1421 : : {
1422 [ + - ]: 34 : SolarMutexGuard g;
1423 : :
1424 : : static uno::Reference< beans::XPropertySetInfo > xRef(
1425 : : aSwMapProvider.GetPropertySet(PROPERTY_MAP_METAFIELD)
1426 [ + + ][ + - ]: 34 : ->getPropertySetInfo() );
[ + - ][ + - ]
[ # # ]
1427 [ + - ]: 34 : return xRef;
1428 : : }
1429 : :
1430 : : void SAL_CALL
1431 : 20 : SwXMetaField::setPropertyValue(
1432 : : const ::rtl::OUString& rPropertyName, const uno::Any& rValue)
1433 : : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
1434 : : lang::IllegalArgumentException, lang::WrappedTargetException,
1435 : : uno::RuntimeException)
1436 : : {
1437 [ + - ]: 20 : SolarMutexGuard g;
1438 : :
1439 : : ::sw::MetaField * const pMeta(
1440 : 20 : const_cast< ::sw::MetaField * >(m_pImpl->GetMetaField()) );
1441 [ - + ]: 20 : if (!pMeta)
1442 [ # # ]: 0 : throw lang::DisposedException();
1443 : :
1444 [ + + ]: 20 : if ( rPropertyName == "NumberFormat" )
1445 : : {
1446 : 10 : sal_Int32 nNumberFormat(0);
1447 [ + - ]: 10 : if (rValue >>= nNumberFormat)
1448 : : {
1449 [ + - ]: 10 : pMeta->SetNumberFormat(static_cast<sal_uInt32>(nNumberFormat));
1450 : : }
1451 : : }
1452 [ + - ]: 10 : else if ( rPropertyName == "IsFixedLanguage" )
1453 : : {
1454 : 10 : bool b(false);
1455 [ + - ]: 10 : if (rValue >>= b)
1456 : : {
1457 : 10 : pMeta->SetIsFixedLanguage(b);
1458 : : }
1459 : : }
1460 : : else
1461 : : {
1462 [ # # ]: 0 : throw beans::UnknownPropertyException();
1463 [ + - ]: 20 : }
1464 : 20 : }
1465 : :
1466 : : uno::Any SAL_CALL
1467 : 74 : SwXMetaField::getPropertyValue(const ::rtl::OUString& rPropertyName)
1468 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1469 : : uno::RuntimeException)
1470 : : {
1471 [ + - ]: 74 : SolarMutexGuard g;
1472 : :
1473 : 74 : ::sw::MetaField const * const pMeta( m_pImpl->GetMetaField() );
1474 [ - + ]: 74 : if (!pMeta)
1475 [ # # ]: 0 : throw lang::DisposedException();
1476 : :
1477 : 74 : uno::Any any;
1478 : :
1479 [ + + ]: 74 : if ( rPropertyName == "NumberFormat" )
1480 : : {
1481 [ + - ]: 48 : const ::rtl::OUString text( getPresentation(sal_False) );
1482 [ + - ][ + - ]: 48 : any <<= static_cast<sal_Int32>(pMeta->GetNumberFormat(text));
1483 : : }
1484 [ + + ]: 26 : else if ( rPropertyName == "IsFixedLanguage" )
1485 : : {
1486 [ + - ]: 6 : any <<= pMeta->IsFixedLanguage();
1487 : : }
1488 : : else
1489 : : {
1490 [ + - ]: 20 : throw beans::UnknownPropertyException();
1491 : : }
1492 : :
1493 [ + - ]: 74 : return any;
1494 : : }
1495 : :
1496 : : void SAL_CALL
1497 : 0 : SwXMetaField::addPropertyChangeListener(
1498 : : const ::rtl::OUString& /*rPropertyName*/,
1499 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1500 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1501 : : uno::RuntimeException)
1502 : : {
1503 : : OSL_FAIL("SwXMetaField::addPropertyChangeListener(): not implemented");
1504 : 0 : }
1505 : :
1506 : : void SAL_CALL
1507 : 0 : SwXMetaField::removePropertyChangeListener(
1508 : : const ::rtl::OUString& /*rPropertyName*/,
1509 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1510 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1511 : : uno::RuntimeException)
1512 : : {
1513 : : OSL_FAIL("SwXMetaField::removePropertyChangeListener(): not implemented");
1514 : 0 : }
1515 : :
1516 : : void SAL_CALL
1517 : 0 : SwXMetaField::addVetoableChangeListener(
1518 : : const ::rtl::OUString& /*rPropertyName*/,
1519 : : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1520 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1521 : : uno::RuntimeException)
1522 : : {
1523 : : OSL_FAIL("SwXMetaField::addVetoableChangeListener(): not implemented");
1524 : 0 : }
1525 : :
1526 : : void SAL_CALL
1527 : 0 : SwXMetaField::removeVetoableChangeListener(
1528 : : const ::rtl::OUString& /*rPropertyName*/,
1529 : : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1530 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1531 : : uno::RuntimeException)
1532 : : {
1533 : : OSL_FAIL("SwXMetaField::removeVetoableChangeListener(): not implemented");
1534 : 0 : }
1535 : :
1536 : : #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
1537 : : #include <com/sun/star/rdf/Statement.hpp>
1538 : : #include <com/sun/star/rdf/URI.hpp>
1539 : : #include <com/sun/star/rdf/URIs.hpp>
1540 : : #include <com/sun/star/rdf/XLiteral.hpp>
1541 : : #include <com/sun/star/rdf/XRepositorySupplier.hpp>
1542 : : #include <comphelper/processfactory.hxx>
1543 : :
1544 : : static uno::Reference<rdf::XURI> const&
1545 : 220 : lcl_getURI(const bool bPrefix)
1546 : : {
1547 : : static uno::Reference< uno::XComponentContext > xContext(
1548 [ + + ][ + - ]: 220 : ::comphelper::getProcessComponentContext());
[ + - ][ # # ]
1549 : : static uno::Reference< rdf::XURI > xOdfPrefix(
1550 : : rdf::URI::createKnown(xContext, rdf::URIs::ODF_PREFIX),
1551 [ + + ][ + - ]: 220 : uno::UNO_SET_THROW);
[ + - ][ + - ]
[ # # ]
1552 : : static uno::Reference< rdf::XURI > xOdfSuffix(
1553 : : rdf::URI::createKnown(xContext, rdf::URIs::ODF_SUFFIX),
1554 [ + + ][ + - ]: 220 : uno::UNO_SET_THROW);
[ + - ][ + - ]
[ # # ]
1555 [ + + ]: 220 : return (bPrefix) ? xOdfPrefix : xOdfSuffix;
1556 : : }
1557 : :
1558 : : static ::rtl::OUString
1559 : 220 : lcl_getPrefixOrSuffix(
1560 : : uno::Reference<rdf::XRepository> const & xRepository,
1561 : : uno::Reference<rdf::XResource> const & xMetaField,
1562 : : uno::Reference<rdf::XURI> const & xPredicate)
1563 : : {
1564 : : const uno::Reference<container::XEnumeration> xEnum(
1565 [ + - ]: 220 : xRepository->getStatements(xMetaField, xPredicate, 0),
1566 [ + - ][ + - ]: 220 : uno::UNO_SET_THROW);
[ + - ]
1567 [ + - ][ + - ]: 220 : while (xEnum->hasMoreElements()) {
[ + + ]
1568 [ + - ]: 136 : rdf::Statement stmt;
1569 [ + - ][ + - ]: 136 : if (!(xEnum->nextElement() >>= stmt)) {
[ + - ][ - + ]
1570 [ # # ]: 0 : throw uno::RuntimeException();
1571 : : }
1572 : : const uno::Reference<rdf::XLiteral> xObject(stmt.Object,
1573 [ + - ]: 136 : uno::UNO_QUERY);
1574 [ - + ]: 136 : if (!xObject.is()) continue;
1575 [ + - ][ + - ]: 136 : if (xEnum->hasMoreElements()) {
1576 : : OSL_TRACE("ignoring other odf:Prefix/odf:Suffix statements");
1577 : : }
1578 [ + - ][ + - ]: 272 : return xObject->getValue();
[ - + ]
1579 [ + - ][ - + ]: 272 : }
1580 : 220 : return ::rtl::OUString();
1581 : : }
1582 : :
1583 : : void
1584 : 150 : getPrefixAndSuffix(
1585 : : const uno::Reference<frame::XModel>& xModel,
1586 : : const uno::Reference<rdf::XMetadatable>& xMetaField,
1587 : : ::rtl::OUString *const o_pPrefix, ::rtl::OUString *const o_pSuffix)
1588 : : {
1589 : : try {
1590 : : const uno::Reference<rdf::XRepositorySupplier> xRS(
1591 [ + - ]: 150 : xModel, uno::UNO_QUERY_THROW);
1592 : : const uno::Reference<rdf::XRepository> xRepo(
1593 [ + - ][ + - ]: 150 : xRS->getRDFRepository(), uno::UNO_SET_THROW);
[ + - ]
1594 : : const uno::Reference<rdf::XResource> xMeta(
1595 [ + - ]: 150 : xMetaField, uno::UNO_QUERY_THROW);
1596 [ + + ]: 150 : if (o_pPrefix)
1597 : : {
1598 [ + - ][ + - ]: 110 : *o_pPrefix = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(true));
1599 : : }
1600 [ + + ]: 150 : if (o_pSuffix)
1601 : : {
1602 [ + - ][ + - ]: 110 : *o_pSuffix = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(false));
1603 : 150 : }
1604 : 0 : } catch (uno::RuntimeException &) {
1605 : 0 : throw;
1606 [ # # # ]: 0 : } catch (const uno::Exception & e) {
1607 : : throw lang::WrappedTargetRuntimeException(
1608 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getPrefixAndSuffix: exception")),
1609 [ # # # # : 0 : 0, uno::makeAny(e));
# # # # ]
1610 : : }
1611 : 150 : }
1612 : :
1613 : : // XTextField
1614 : : ::rtl::OUString SAL_CALL
1615 : 70 : SwXMetaField::getPresentation(sal_Bool bShowCommand)
1616 : : throw (uno::RuntimeException)
1617 : : {
1618 [ + - ]: 70 : SolarMutexGuard g;
1619 : :
1620 [ - + ]: 70 : if (bShowCommand)
1621 : : {
1622 : : //FIXME ?
1623 : 0 : return ::rtl::OUString();
1624 : : }
1625 : : else
1626 : : {
1627 : : // getString should check if this is invalid
1628 [ + - ]: 70 : const ::rtl::OUString content( this->getString() );
1629 : 70 : ::rtl::OUString prefix;
1630 : 70 : ::rtl::OUString suffix;
1631 [ + - ][ + - ]: 70 : getPrefixAndSuffix(GetModel(), this, &prefix, &suffix);
[ + - ]
1632 : 70 : return prefix + content + suffix;
1633 [ + - ]: 70 : }
1634 : : }
1635 : :
1636 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|