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