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