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 <unobookmark.hxx>
31 : : #include <osl/mutex.hxx>
32 : : #include <vcl/svapp.hxx>
33 : :
34 : : #include <TextCursorHelper.hxx>
35 : : #include <unotextrange.hxx>
36 : : #include <unomap.hxx>
37 : : #include <unoprnms.hxx>
38 : : #include <unoevtlstnr.hxx>
39 : : #include <IMark.hxx>
40 : : #include <crossrefbookmark.hxx>
41 : : #include <doc.hxx>
42 : : #include <IDocumentUndoRedo.hxx>
43 : : #include <docary.hxx>
44 : : #include <swundo.hxx>
45 : : #include <comcore.hrc>
46 : : #include <SwRewriter.hxx>
47 : : #include <docsh.hxx>
48 : : #include <xmloff/odffields.hxx>
49 : : #include <comphelper/servicehelper.hxx>
50 : :
51 : : using namespace ::sw::mark;
52 : : using namespace ::com::sun::star;
53 : : using ::rtl::OUString;
54 : :
55 : :
56 : : namespace
57 : : {
58 : 8 : static OUString lcl_QuoteName(const OUString& rName)
59 : : {
60 [ + + ][ + - ]: 8 : static const OUString sStart = OUString(String(SW_RES(STR_START_QUOTE)));
[ + - ][ + - ]
[ + - ][ # # ]
61 [ + + ][ + - ]: 8 : static const OUString sEnd = OUString(String(SW_RES(STR_END_QUOTE)));
[ + - ][ + - ]
[ + - ][ # # ]
62 : 8 : ::rtl::OUStringBuffer sBuf(64);
63 [ + - ][ + - ]: 8 : return sBuf.append(sStart).append(rName).append(sEnd).makeStringAndClear();
[ + - ][ + - ]
64 : : }
65 : : }
66 : :
67 : : /******************************************************************
68 : : * SwXBookmark
69 : : ******************************************************************/
70 : :
71 [ + - ][ - + ]: 28818 : class SwXBookmark::Impl
72 : : : public SwClient
73 : : {
74 : :
75 : : public:
76 : : SwEventListenerContainer m_ListenerContainer;
77 : : SwDoc * m_pDoc;
78 : : ::sw::mark::IMark * m_pRegisteredBookmark;
79 : : ::rtl::OUString m_sMarkName;
80 : :
81 : :
82 : 14409 : Impl( SwXBookmark & rThis,
83 : : SwDoc *const pDoc, ::sw::mark::IMark *const /*pBookmark*/)
84 : : : SwClient()
85 : : , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
86 : : , m_pDoc(pDoc)
87 [ + - ]: 14409 : , m_pRegisteredBookmark(0)
88 : : {
89 : : // DO NOT regiserInMark here! (because SetXBookmark would delete rThis)
90 : 14409 : }
91 : :
92 : : void registerInMark(SwXBookmark & rThis, ::sw::mark::IMark *const pBkmk);
93 : : protected:
94 : : // SwClient
95 : : virtual void Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew);
96 : :
97 : : };
98 : :
99 : 444 : void SwXBookmark::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
100 : : {
101 : 444 : ClientModify(this, pOld, pNew);
102 [ + - ]: 444 : if (!GetRegisteredIn())
103 : : {
104 : 444 : m_pRegisteredBookmark = NULL;
105 : 444 : m_pDoc = NULL;
106 : 444 : m_ListenerContainer.Disposing();
107 : : }
108 : 444 : }
109 : :
110 : 14409 : void SwXBookmark::Impl::registerInMark(SwXBookmark & rThis,
111 : : ::sw::mark::IMark *const pBkmk)
112 : : {
113 [ + - ]: 14409 : if (pBkmk)
114 : : {
115 : 14409 : pBkmk->Add(this);
116 : : ::sw::mark::MarkBase *const pMarkBase(
117 [ - + ]: 14409 : dynamic_cast< ::sw::mark::MarkBase * >(pBkmk));
118 : : OSL_ENSURE(pMarkBase, "registerInMark: no MarkBase?");
119 [ + - ]: 14409 : if (pMarkBase)
120 : : {
121 [ + - ]: 14409 : const uno::Reference<text::XTextContent> xBookmark(& rThis);
122 [ + - ]: 14409 : pMarkBase->SetXBookmark(xBookmark);
123 : : }
124 : : }
125 [ # # ]: 0 : else if (m_pRegisteredBookmark)
126 : : {
127 : 0 : m_sMarkName = m_pRegisteredBookmark->GetName();
128 : 0 : m_pRegisteredBookmark->Remove(this);
129 : : }
130 : 14409 : m_pRegisteredBookmark = pBkmk;
131 : 14409 : }
132 : :
133 : 15 : void SwXBookmark::registerInMark(SwXBookmark & rThis,
134 : : ::sw::mark::IMark *const pBkmk)
135 : : {
136 : 15 : m_pImpl->registerInMark( rThis, pBkmk );
137 : 15 : }
138 : :
139 : 18 : const ::sw::mark::IMark* SwXBookmark::GetBookmark() const
140 : : {
141 : 18 : return m_pImpl->m_pRegisteredBookmark;
142 : : }
143 : :
144 : 10397 : SwXBookmark::SwXBookmark(::sw::mark::IMark *const pBkmk, SwDoc *const pDoc)
145 [ + - ][ + - ]: 10397 : : m_pImpl( new SwXBookmark::Impl(*this, pDoc, pBkmk) )
146 : : {
147 : 10397 : }
148 : :
149 : 4012 : SwXBookmark::SwXBookmark()
150 [ + - ][ + - ]: 4012 : : m_pImpl( new SwXBookmark::Impl(*this, 0, 0) )
151 : : {
152 : 4012 : }
153 : :
154 [ + - ]: 14409 : SwXBookmark::~SwXBookmark()
155 : : {
156 [ - + ]: 28800 : }
157 : :
158 : : uno::Reference<text::XTextContent>
159 : 13557 : SwXBookmark::CreateXBookmark(SwDoc & rDoc, ::sw::mark::IMark & rBookmark)
160 : : {
161 : : // #i105557#: do not iterate over the registered clients: race condition
162 : : ::sw::mark::MarkBase *const pMarkBase(
163 [ - + ]: 13557 : dynamic_cast< ::sw::mark::MarkBase * >(&rBookmark));
164 : : OSL_ENSURE(pMarkBase, "CreateXBookmark: no MarkBase?");
165 [ - + ][ # # ]: 13557 : if (!pMarkBase) { return 0; }
166 [ + - ]: 13557 : uno::Reference<text::XTextContent> xBookmark(pMarkBase->GetXBookmark());
167 [ + + ]: 13557 : if (!xBookmark.is())
168 : : {
169 : : // FIXME: These belong in XTextFieldsSupplier
170 : : //if (dynamic_cast< ::sw::mark::TextFieldmark* >(&rBkmk))
171 : : // pXBkmk = new SwXFieldmark(false, &rBkmk, pDoc);
172 : : //else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(&rBkmk))
173 : : // pXBkmk = new SwXFieldmark(true, &rBkmk, pDoc);
174 : : //else
175 : : OSL_ENSURE(
176 : : dynamic_cast< ::sw::mark::IBookmark* >(&rBookmark),
177 : : "<SwXBookmark::GetObject(..)>"
178 : : "SwXBookmark requested for non-bookmark mark.");
179 [ + - ]: 10379 : SwXBookmark *const pXBookmark = new SwXBookmark(&rBookmark, &rDoc);
180 [ + - ][ + - ]: 10379 : xBookmark.set(pXBookmark);
181 [ + - ][ + - ]: 10379 : pXBookmark->m_pImpl->registerInMark(*pXBookmark, pMarkBase);
182 : : }
183 : 13557 : return xBookmark;
184 : : }
185 : :
186 : 0 : ::sw::mark::IMark const* SwXBookmark::GetBookmarkInDoc(SwDoc const*const pDoc,
187 : : const uno::Reference< lang::XUnoTunnel> & xUT)
188 : : {
189 : : SwXBookmark *const pXBkm(
190 : 0 : ::sw::UnoTunnelGetImplementation<SwXBookmark>(xUT));
191 [ # # ][ # # ]: 0 : if (pXBkm && (pDoc == pXBkm->m_pImpl->m_pDoc))
[ # # ]
192 : : {
193 : 0 : return pXBkm->m_pImpl->m_pRegisteredBookmark;
194 : : }
195 : 0 : return 0;
196 : : }
197 : :
198 : : namespace
199 : : {
200 : : class theSwXBookmarkUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXBookmarkUnoTunnelId > {};
201 : : }
202 : :
203 : 28742 : const uno::Sequence< sal_Int8 > & SwXBookmark::getUnoTunnelId()
204 : : {
205 : 28742 : return theSwXBookmarkUnoTunnelId::get().getSeq();
206 : : }
207 : :
208 : : sal_Int64 SAL_CALL
209 : 23724 : SwXBookmark::getSomething(const uno::Sequence< sal_Int8 >& rId)
210 : : throw (uno::RuntimeException)
211 : : {
212 : 23724 : return ::sw::UnoTunnelImpl<SwXBookmark>(rId, this);
213 : : }
214 : :
215 : 4015 : void SwXBookmark::attachToRangeEx(
216 : : const uno::Reference< text::XTextRange > & xTextRange,
217 : : IDocumentMarkAccess::MarkType eType)
218 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
219 : : {
220 [ - + ]: 4015 : if (m_pImpl->m_pRegisteredBookmark)
221 : : {
222 [ # # ]: 0 : throw uno::RuntimeException();
223 : : }
224 : :
225 : : const uno::Reference<lang::XUnoTunnel> xRangeTunnel(
226 [ + - ]: 4015 : xTextRange, uno::UNO_QUERY);
227 : 4015 : SwXTextRange* pRange = 0;
228 : 4015 : OTextCursorHelper* pCursor = 0;
229 [ + - ]: 4015 : if(xRangeTunnel.is())
230 : : {
231 [ + - ]: 4015 : pRange = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
232 : : pCursor =
233 [ + - ]: 4015 : ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
234 : : }
235 : :
236 : : SwDoc *const pDoc =
237 [ + + ][ + - ]: 4015 : (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0);
[ + - ][ + - ]
238 [ - + ]: 4015 : if (!pDoc)
239 : : {
240 [ # # ]: 0 : throw lang::IllegalArgumentException();
241 : : }
242 : :
243 : 4015 : m_pImpl->m_pDoc = pDoc;
244 [ + - ]: 4015 : SwUnoInternalPaM aPam(*m_pImpl->m_pDoc);
245 [ + - ]: 4015 : ::sw::XTextRangeToSwPaM(aPam, xTextRange);
246 [ + - ]: 4015 : UnoActionContext aCont(m_pImpl->m_pDoc);
247 [ + + ]: 4015 : if (m_pImpl->m_sMarkName.isEmpty())
248 : : {
249 [ + - ]: 15 : m_pImpl->m_sMarkName = OUString(RTL_CONSTASCII_USTRINGPARAM("Bookmark"));
250 : : }
251 [ + + ][ + + ]: 8027 : if ((eType == IDocumentMarkAccess::BOOKMARK) &&
[ + + ]
252 [ + - ]: 4012 : ::sw::mark::CrossRefNumItemBookmark::IsLegalName(m_pImpl->m_sMarkName))
253 : : {
254 : 6 : eType = IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK;
255 : : }
256 [ + + ][ - + ]: 8015 : else if ((eType == IDocumentMarkAccess::BOOKMARK) &&
[ - + ]
257 [ + - ]: 4006 : ::sw::mark::CrossRefHeadingBookmark::IsLegalName(m_pImpl->m_sMarkName))
258 : : {
259 : 0 : eType = IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK;
260 : : }
261 : : m_pImpl->registerInMark(*this,
262 [ + - ]: 4015 : m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark(
263 [ + - ][ + - ]: 4015 : aPam, m_pImpl->m_sMarkName, eType));
264 : : // #i81002#
265 : : // Check, if bookmark has been created.
266 : : // E.g., the creation of a cross-reference bookmark is suppress,
267 : : // if the PaM isn't a valid one for cross-reference bookmarks.
268 [ - + ]: 4015 : if (!m_pImpl->m_pRegisteredBookmark)
269 : : {
270 : : OSL_FAIL("<SwXBookmark::attachToRange(..)>"
271 : : " - could not create Mark.");
272 [ # # ]: 0 : throw lang::IllegalArgumentException();
273 [ + - ][ + - ]: 4015 : }
274 : 4015 : }
275 : :
276 : 4012 : void SwXBookmark::attachToRange(
277 : : const uno::Reference< text::XTextRange > & xTextRange)
278 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
279 : : {
280 : 4012 : attachToRangeEx(xTextRange, IDocumentMarkAccess::BOOKMARK);
281 : 4012 : }
282 : :
283 : : void SAL_CALL
284 : 4015 : SwXBookmark::attach(const uno::Reference< text::XTextRange > & xTextRange)
285 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
286 : : {
287 [ + - ]: 4015 : SolarMutexGuard aGuard;
288 [ + - ][ + - ]: 4015 : attachToRange( xTextRange );
289 : 4015 : }
290 : :
291 : : uno::Reference< text::XTextRange > SAL_CALL
292 : 9668 : SwXBookmark::getAnchor() throw (uno::RuntimeException)
293 : : {
294 [ + - ]: 9668 : SolarMutexGuard aGuard;
295 : :
296 [ - + ]: 9668 : if (!m_pImpl->m_pRegisteredBookmark)
297 : : {
298 [ # # ]: 0 : throw uno::RuntimeException();
299 : : }
300 : : return SwXTextRange::CreateXTextRange(
301 : 9668 : *m_pImpl->m_pDoc,
302 [ + - ]: 9668 : m_pImpl->m_pRegisteredBookmark->GetMarkPos(),
303 [ + - ]: 9668 : (m_pImpl->m_pRegisteredBookmark->IsExpanded())
304 [ + + ][ + - ]: 19336 : ? &m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos() : NULL);
[ + - ][ + - ]
305 : : }
306 : :
307 : 2 : void SAL_CALL SwXBookmark::dispose() throw (uno::RuntimeException)
308 : : {
309 [ + - ]: 2 : SolarMutexGuard aGuard;
310 [ + - ]: 2 : if (m_pImpl->m_pRegisteredBookmark)
311 : : {
312 [ + - ]: 2 : m_pImpl->m_pDoc->getIDocumentMarkAccess()->deleteMark(
313 [ + - ]: 2 : m_pImpl->m_pRegisteredBookmark);
314 [ + - ]: 2 : }
315 : 2 : }
316 : :
317 : 4 : void SAL_CALL SwXBookmark::addEventListener(
318 : : const uno::Reference< lang::XEventListener > & xListener)
319 : : throw (uno::RuntimeException)
320 : : {
321 [ + - ]: 4 : SolarMutexGuard g;
322 : :
323 [ - + ]: 4 : if (!m_pImpl->m_pRegisteredBookmark)
324 : : {
325 [ # # ]: 0 : throw uno::RuntimeException();
326 : : }
327 [ + - ][ + - ]: 4 : m_pImpl->m_ListenerContainer.AddListener(xListener);
328 : 4 : }
329 : :
330 : 2 : void SAL_CALL SwXBookmark::removeEventListener(
331 : : const uno::Reference< lang::XEventListener > & xListener)
332 : : throw (uno::RuntimeException)
333 : : {
334 [ + - ]: 2 : SolarMutexGuard g;
335 : :
336 [ + - ][ - + ]: 4 : if (!m_pImpl->m_pRegisteredBookmark ||
[ - + ]
337 [ + - ]: 2 : !m_pImpl->m_ListenerContainer.RemoveListener(xListener))
338 : : {
339 [ # # ]: 0 : throw uno::RuntimeException();
340 [ + - ]: 2 : }
341 : 2 : }
342 : :
343 : 3885 : OUString SAL_CALL SwXBookmark::getName()
344 : : throw (uno::RuntimeException)
345 : : {
346 [ + - ]: 3885 : SolarMutexGuard aGuard;
347 : :
348 : 3885 : return (m_pImpl->m_pRegisteredBookmark)
349 : 3885 : ? m_pImpl->m_pRegisteredBookmark->GetName()
350 [ + - ]: 7770 : : m_pImpl->m_sMarkName;
[ + - + - ]
351 : : }
352 : :
353 : 4004 : void SAL_CALL SwXBookmark::setName(const OUString& rName)
354 : : throw (uno::RuntimeException)
355 : : {
356 [ + - ]: 4004 : SolarMutexGuard aGuard;
357 : :
358 [ + + ]: 4004 : if (!m_pImpl->m_pRegisteredBookmark)
359 : : {
360 : 4000 : m_pImpl->m_sMarkName = rName;
361 : : }
362 [ + + ][ + - ]: 4004 : if (!m_pImpl->m_pRegisteredBookmark || (getName() == rName))
[ - + ][ + + ]
[ + + ][ # # ]
363 : : {
364 : 4004 : return;
365 : : }
366 : : IDocumentMarkAccess *const pMarkAccess =
367 [ + - ]: 4 : m_pImpl->m_pDoc->getIDocumentMarkAccess();
368 [ + - ][ + - ]: 4 : if(pMarkAccess->findMark(rName) != pMarkAccess->getMarksEnd())
[ + - ][ - + ]
369 : : {
370 [ # # ]: 0 : throw uno::RuntimeException();
371 : : }
372 : :
373 [ + - ][ + - ]: 4 : SwPaM aPam(m_pImpl->m_pRegisteredBookmark->GetMarkPos());
374 [ + - ][ - + ]: 4 : if (m_pImpl->m_pRegisteredBookmark->IsExpanded())
375 : : {
376 [ # # ]: 0 : aPam.SetMark();
377 [ # # ][ # # ]: 0 : *aPam.GetMark() = m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos();
378 : : }
379 : :
380 [ + - ]: 4 : SwRewriter aRewriter;
381 [ + - ][ + - ]: 4 : aRewriter.AddRule(UndoArg1, lcl_QuoteName(getName()));
[ + - ][ + - ]
[ + - ]
382 [ + - ][ + - ]: 4 : aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
[ + - ]
383 [ + - ][ + - ]: 4 : aRewriter.AddRule(UndoArg3, lcl_QuoteName(rName));
[ + - ][ + - ]
384 : :
385 [ + - ]: 4 : m_pImpl->m_pDoc->GetIDocumentUndoRedo().StartUndo(
386 [ + - ]: 4 : UNDO_BOOKMARK_RENAME, &aRewriter);
387 [ + - ]: 4 : pMarkAccess->renameMark(m_pImpl->m_pRegisteredBookmark, rName);
388 [ + - ]: 4 : m_pImpl->m_pDoc->GetIDocumentUndoRedo().EndUndo(
389 [ + - ][ + - ]: 4004 : UNDO_BOOKMARK_RENAME, &aRewriter);
[ + - ][ + - ]
[ + + ]
390 : : }
391 : :
392 : : OUString SAL_CALL
393 : 0 : SwXBookmark::getImplementationName() throw (uno::RuntimeException)
394 : : {
395 : 0 : return OUString(RTL_CONSTASCII_USTRINGPARAM("SwXBookmark"));
396 : : }
397 : :
398 : : static char const*const g_ServicesBookmark[] =
399 : : {
400 : : "com.sun.star.text.TextContent",
401 : : "com.sun.star.text.Bookmark",
402 : : "com.sun.star.document.LinkTarget",
403 : : };
404 : : static const size_t g_nServicesBookmark(
405 : : sizeof(g_ServicesBookmark)/sizeof(g_ServicesBookmark[0]));
406 : :
407 : 34 : sal_Bool SAL_CALL SwXBookmark::supportsService(const OUString& rServiceName)
408 : : throw (uno::RuntimeException)
409 : : {
410 : : return ::sw::SupportsServiceImpl(
411 : 34 : g_nServicesBookmark, g_ServicesBookmark, rServiceName);
412 : : }
413 : :
414 : : uno::Sequence< OUString > SAL_CALL
415 : 0 : SwXBookmark::getSupportedServiceNames() throw (uno::RuntimeException)
416 : : {
417 : : return ::sw::GetSupportedServiceNamesImpl(
418 : 0 : g_nServicesBookmark, g_ServicesBookmark);
419 : : }
420 : :
421 : : // MetadatableMixin
422 : 3944 : ::sfx2::Metadatable* SwXBookmark::GetCoreObject()
423 : : {
424 [ + - ]: 3944 : return dynamic_cast< ::sfx2::Metadatable* >(m_pImpl->m_pRegisteredBookmark);
425 : : }
426 : :
427 : 0 : uno::Reference<frame::XModel> SwXBookmark::GetModel()
428 : : {
429 [ # # ]: 0 : if (m_pImpl->m_pDoc)
430 : : {
431 : 0 : SwDocShell const * const pShell( m_pImpl->m_pDoc->GetDocShell() );
432 [ # # ]: 0 : return (pShell) ? pShell->GetModel() : 0;
433 : : }
434 : 0 : return 0;
435 : : }
436 : :
437 : :
438 : : uno::Reference< beans::XPropertySetInfo > SAL_CALL
439 : 12 : SwXBookmark::getPropertySetInfo() throw (uno::RuntimeException)
440 : : {
441 [ + - ]: 12 : SolarMutexGuard g;
442 : :
443 : : static uno::Reference< beans::XPropertySetInfo > xRef(
444 : : aSwMapProvider.GetPropertySet(PROPERTY_MAP_BOOKMARK)
445 [ + + ][ + - ]: 12 : ->getPropertySetInfo() );
[ + - ][ + - ]
[ # # ]
446 [ + - ]: 12 : return xRef;
447 : : }
448 : :
449 : : void SAL_CALL
450 : 6 : SwXBookmark::setPropertyValue(const OUString& PropertyName,
451 : : const uno::Any& /*rValue*/)
452 : : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
453 : : lang::IllegalArgumentException, lang::WrappedTargetException,
454 : : uno::RuntimeException)
455 : : {
456 : : // nothing to set here
457 : : throw lang::IllegalArgumentException( ::rtl::OUString(
458 : : RTL_CONSTASCII_USTRINGPARAM("Property is read-only: "))
459 [ + - ][ + - ]: 6 : + PropertyName, static_cast< cppu::OWeakObject * >(this), 0 );
[ + - ]
460 : : }
461 : :
462 : 12 : uno::Any SAL_CALL SwXBookmark::getPropertyValue(const OUString& rPropertyName)
463 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
464 : : uno::RuntimeException)
465 : : {
466 [ + - ]: 12 : SolarMutexGuard g;
467 : :
468 : 12 : uno::Any aRet;
469 [ - + ][ + - ]: 12 : if (! ::sw::GetDefaultTextContentValue(aRet, rPropertyName))
470 : : {
471 [ # # ][ # # ]: 0 : if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
[ # # ]
472 : : {
473 [ # # ][ # # ]: 0 : aRet <<= getName();
474 : : }
475 : : }
476 [ + - ]: 12 : return aRet;
477 : : }
478 : :
479 : : void SAL_CALL
480 : 0 : SwXBookmark::addPropertyChangeListener(
481 : : const ::rtl::OUString& /*rPropertyName*/,
482 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
483 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
484 : : uno::RuntimeException)
485 : : {
486 : : OSL_FAIL("SwXBookmark::addPropertyChangeListener(): not implemented");
487 : 0 : }
488 : :
489 : : void SAL_CALL
490 : 0 : SwXBookmark::removePropertyChangeListener(
491 : : const ::rtl::OUString& /*rPropertyName*/,
492 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
493 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
494 : : uno::RuntimeException)
495 : : {
496 : : OSL_FAIL("SwXBookmark::removePropertyChangeListener(): not implemented");
497 : 0 : }
498 : :
499 : : void SAL_CALL
500 : 0 : SwXBookmark::addVetoableChangeListener(
501 : : const ::rtl::OUString& /*rPropertyName*/,
502 : : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
503 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
504 : : uno::RuntimeException)
505 : : {
506 : : OSL_FAIL("SwXBookmark::addVetoableChangeListener(): not implemented");
507 : 0 : }
508 : :
509 : : void SAL_CALL
510 : 0 : SwXBookmark::removeVetoableChangeListener(
511 : : const ::rtl::OUString& /*rPropertyName*/,
512 : : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
513 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
514 : : uno::RuntimeException)
515 : : {
516 : : OSL_FAIL("SwXBookmark::removeVetoableChangeListener(): not implemented");
517 : 0 : }
518 : :
519 : : /******************************************************************
520 : : * SwXFieldmark
521 : : ******************************************************************/
522 : :
523 : 18 : SwXFieldmark::SwXFieldmark(bool _isReplacementObject, ::sw::mark::IMark* pBkm, SwDoc* pDc)
524 : : : SwXFieldmark_Base(pBkm, pDc)
525 : 18 : , isReplacementObject(_isReplacementObject)
526 : 18 : { }
527 : :
528 : 0 : void SwXFieldmarkParameters::insertByName(const OUString& aName, const uno::Any& aElement)
529 : : throw (lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException)
530 : : {
531 [ # # ]: 0 : SolarMutexGuard aGuard;
532 [ # # ]: 0 : IFieldmark::parameter_map_t* pParameters = getCoreParameters();
533 [ # # ][ # # ]: 0 : if(pParameters->find(aName) != pParameters->end())
534 [ # # ]: 0 : throw container::ElementExistException();
535 [ # # ][ # # ]: 0 : (*pParameters)[aName] = aElement;
536 : 0 : }
537 : :
538 : 0 : void SwXFieldmarkParameters::removeByName(const OUString& aName)
539 : : throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
540 : : {
541 [ # # ]: 0 : SolarMutexGuard aGuard;
542 [ # # ][ # # ]: 0 : if(!getCoreParameters()->erase(aName))
[ # # ]
543 [ # # ][ # # ]: 0 : throw container::NoSuchElementException();
544 : 0 : }
545 : :
546 : 0 : void SwXFieldmarkParameters::replaceByName(const OUString& aName, const uno::Any& aElement)
547 : : throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
548 : : {
549 [ # # ]: 0 : SolarMutexGuard aGuard;
550 [ # # ]: 0 : IFieldmark::parameter_map_t* pParameters = getCoreParameters();
551 [ # # ]: 0 : IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName);
552 [ # # ]: 0 : if(pEntry == pParameters->end())
553 [ # # ]: 0 : throw container::NoSuchElementException();
554 [ # # ]: 0 : pEntry->second = aElement;
555 : 0 : }
556 : :
557 : 0 : uno::Any SwXFieldmarkParameters::getByName(const OUString& aName)
558 : : throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
559 : : {
560 [ # # ]: 0 : SolarMutexGuard aGuard;
561 [ # # ]: 0 : IFieldmark::parameter_map_t* pParameters = getCoreParameters();
562 [ # # ]: 0 : IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName);
563 [ # # ]: 0 : if(pEntry == pParameters->end())
564 [ # # ]: 0 : throw container::NoSuchElementException();
565 [ # # ]: 0 : return pEntry->second;
566 : : }
567 : :
568 : 3 : uno::Sequence<OUString> SwXFieldmarkParameters::getElementNames()
569 : : throw (uno::RuntimeException)
570 : : {
571 [ + - ]: 3 : SolarMutexGuard aGuard;
572 [ + - ]: 3 : IFieldmark::parameter_map_t* pParameters = getCoreParameters();
573 [ + - ]: 3 : uno::Sequence<OUString> vResult(pParameters->size());
574 [ + - ]: 3 : OUString* pOutEntry = vResult.getArray();
575 [ + + ]: 6 : for(IFieldmark::parameter_map_t::iterator pEntry = pParameters->begin(); pEntry!=pParameters->end(); ++pEntry, ++pOutEntry)
576 : 3 : *pOutEntry = pEntry->first;
577 [ + - ]: 3 : return vResult;
578 : : }
579 : :
580 : 0 : ::sal_Bool SwXFieldmarkParameters::hasByName(const OUString& aName)
581 : : throw (uno::RuntimeException)
582 : : {
583 [ # # ]: 0 : SolarMutexGuard aGuard;
584 [ # # ]: 0 : IFieldmark::parameter_map_t* pParameters = getCoreParameters();
585 [ # # ][ # # ]: 0 : return (pParameters->find(aName) != pParameters->end());
586 : : }
587 : :
588 : 0 : uno::Type SwXFieldmarkParameters::getElementType()
589 : : throw (uno::RuntimeException)
590 : : {
591 : 0 : return ::cppu::UnoType< ::cppu::UnoVoidType>::get();
592 : : }
593 : :
594 : 0 : ::sal_Bool SwXFieldmarkParameters::hasElements()
595 : : throw (uno::RuntimeException)
596 : : {
597 [ # # ]: 0 : SolarMutexGuard aGuard;
598 [ # # ][ # # ]: 0 : return !getCoreParameters()->empty();
599 : : }
600 : :
601 : 0 : void SwXFieldmarkParameters::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
602 : : {
603 : 0 : ClientModify(this, pOld, pNew);
604 : 0 : }
605 : :
606 : :
607 : 3 : IFieldmark::parameter_map_t* SwXFieldmarkParameters::getCoreParameters()
608 : : throw (uno::RuntimeException)
609 : : {
610 [ - + ]: 3 : const IFieldmark* pFieldmark = dynamic_cast< const IFieldmark* >(GetRegisteredIn());
611 [ - + ]: 3 : if(!pFieldmark)
612 [ # # ]: 0 : throw uno::RuntimeException();
613 : 3 : return const_cast< IFieldmark* >(pFieldmark)->GetParameters();
614 : : }
615 : :
616 : :
617 : 3 : void SwXFieldmark::attachToRange( const uno::Reference < text::XTextRange >& xTextRange )
618 : : throw(lang::IllegalArgumentException, uno::RuntimeException)
619 : : {
620 : :
621 : : attachToRangeEx( xTextRange,
622 [ + - ]: 3 : ( isReplacementObject ? IDocumentMarkAccess::CHECKBOX_FIELDMARK : IDocumentMarkAccess::TEXT_FIELDMARK ) );
623 : 3 : }
624 : :
625 : 6 : ::rtl::OUString SwXFieldmark::getFieldType(void)
626 : : throw(uno::RuntimeException)
627 : : {
628 [ + - ]: 6 : SolarMutexGuard aGuard;
629 [ + - ][ - + ]: 6 : const IFieldmark *pBkm = dynamic_cast<const IFieldmark*>(GetBookmark());
630 [ - + ]: 6 : if(!pBkm)
631 [ # # ]: 0 : throw uno::RuntimeException();
632 [ + - ][ + - ]: 6 : return pBkm->GetFieldname();
633 : : }
634 : :
635 : 3 : void SwXFieldmark::setFieldType(const::rtl::OUString & fieldType)
636 : : throw(uno::RuntimeException)
637 : : {
638 [ + - ]: 3 : SolarMutexGuard aGuard;
639 : : IFieldmark *pBkm = const_cast<IFieldmark*>(
640 [ + - ][ - + ]: 3 : dynamic_cast<const IFieldmark*>(GetBookmark()));
641 [ - + ]: 3 : if(!pBkm)
642 [ # # ]: 0 : throw uno::RuntimeException();
643 [ + - ][ + - ]: 3 : pBkm->SetFieldname(fieldType);
644 : 3 : }
645 : :
646 : 6 : uno::Reference<container::XNameContainer> SwXFieldmark::getParameters()
647 : : throw (uno::RuntimeException)
648 : : {
649 [ + - ]: 6 : SolarMutexGuard aGuard;
650 : : IFieldmark *pBkm = const_cast<IFieldmark*>(
651 [ + - ][ - + ]: 6 : dynamic_cast<const IFieldmark*>(GetBookmark()));
652 [ - + ]: 6 : if(!pBkm)
653 [ # # ]: 0 : throw uno::RuntimeException();
654 [ + - ][ + - ]: 6 : return uno::Reference<container::XNameContainer>(new SwXFieldmarkParameters(pBkm));
[ + - ][ + - ]
655 : : }
656 : :
657 : : uno::Reference<text::XTextContent>
658 : 27 : SwXFieldmark::CreateXFieldmark(SwDoc & rDoc, ::sw::mark::IMark & rMark)
659 : : {
660 : : // #i105557#: do not iterate over the registered clients: race condition
661 : : ::sw::mark::MarkBase *const pMarkBase(
662 [ - + ]: 27 : dynamic_cast< ::sw::mark::MarkBase * >(&rMark));
663 : : OSL_ENSURE(pMarkBase, "CreateXBookmark: no MarkBase?");
664 [ - + ][ # # ]: 27 : if (!pMarkBase) { return 0; }
665 [ + - ]: 27 : uno::Reference<text::XTextContent> xMark(pMarkBase->GetXBookmark());
666 [ + + ]: 27 : if (!xMark.is())
667 : : {
668 : : // FIXME: These belong in XTextFieldsSupplier
669 : 15 : SwXFieldmark* pXBkmk = NULL;
670 [ + - ][ + + ]: 15 : if (dynamic_cast< ::sw::mark::TextFieldmark* >(&rMark))
671 [ + - ]: 12 : pXBkmk = new SwXFieldmark(false, &rMark, &rDoc);
672 [ + - ][ + - ]: 3 : else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(&rMark))
673 [ + - ]: 3 : pXBkmk = new SwXFieldmark(true, &rMark, &rDoc);
674 : :
675 [ + - ][ + - ]: 15 : xMark.set(pXBkmk);
676 [ + - ][ + - ]: 15 : pXBkmk->registerInMark(*pXBkmk, pMarkBase);
677 : : }
678 : 27 : return xMark;
679 : : }
680 : :
681 : : ::sw::mark::ICheckboxFieldmark*
682 : 3 : SwXFieldmark::getCheckboxFieldmark()
683 : : {
684 : 3 : ::sw::mark::ICheckboxFieldmark* pCheckboxFm = NULL;
685 [ + - ][ + - ]: 3 : if ( getFieldType() == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(ODF_FORMCHECKBOX) ) )
686 : : {
687 : : // evil #TODO #FIXME casting away the const-ness
688 [ - + ]: 3 : pCheckboxFm = const_cast<sw::mark::ICheckboxFieldmark*>(dynamic_cast< const ::sw::mark::ICheckboxFieldmark* >( GetBookmark()));
689 : : OSL_ASSERT( GetBookmark() == 0 || pCheckboxFm != 0 );
690 : : // unclear to me whether GetBookmark() can be null here
691 : : }
692 : 3 : return pCheckboxFm;
693 : :
694 : : }
695 : :
696 : : // support 'hidden' "Checked" property ( note: this property is just for convenience to support
697 : : // docx import filter thus not published via PropertySet info )
698 : :
699 : : void SAL_CALL
700 : 3 : SwXFieldmark::setPropertyValue(const OUString& PropertyName,
701 : : const uno::Any& rValue)
702 : : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
703 : : lang::IllegalArgumentException, lang::WrappedTargetException,
704 : : uno::RuntimeException)
705 : : {
706 [ + - ]: 3 : SolarMutexGuard g;
707 [ + - ]: 3 : if ( PropertyName == "Checked" )
708 : : {
709 [ + - ]: 3 : ::sw::mark::ICheckboxFieldmark* pCheckboxFm = getCheckboxFieldmark();
710 : 3 : sal_Bool bChecked( sal_False );
711 [ + - ][ + - ]: 3 : if ( pCheckboxFm && ( rValue >>= bChecked ) )
[ + - ]
712 [ + - ]: 3 : pCheckboxFm->SetChecked( bChecked );
713 : : else
714 [ # # ]: 3 : throw uno::RuntimeException();
715 : :
716 : : }
717 : : else
718 [ # # ][ + - ]: 3 : SwXFieldmark_Base::setPropertyValue( PropertyName, rValue );
719 : 3 : }
720 : :
721 : : // support 'hidden' "Checked" property ( note: this property is just for convenience to support
722 : : // docx import filter thus not published via PropertySet info )
723 : :
724 : 0 : uno::Any SAL_CALL SwXFieldmark::getPropertyValue(const OUString& rPropertyName)
725 : : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
726 : : uno::RuntimeException)
727 : : {
728 [ # # ]: 0 : SolarMutexGuard g;
729 [ # # ]: 0 : if ( rPropertyName == "Checked" )
730 : : {
731 [ # # ]: 0 : ::sw::mark::ICheckboxFieldmark* pCheckboxFm = getCheckboxFieldmark();
732 [ # # ]: 0 : if ( pCheckboxFm )
733 [ # # ][ # # ]: 0 : return uno::makeAny( pCheckboxFm->IsChecked() );
734 : : else
735 [ # # ]: 0 : throw uno::RuntimeException();
736 : : }
737 [ # # ][ # # ]: 0 : return SwXFieldmark_Base::getPropertyValue( rPropertyName );
738 : : }
739 : :
740 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|