LibreOffice Module sw (master) 1
unobkm.cxx
Go to the documentation of this file.
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#include <unobookmark.hxx>
21
26#include <svl/itemprop.hxx>
27#include <svl/listener.hxx>
28#include <vcl/svapp.hxx>
29#include <xmloff/odffields.hxx>
30
31#include <TextCursorHelper.hxx>
32#include <unotextrange.hxx>
33#include <unomap.hxx>
34#include <unoprnms.hxx>
35#include <IMark.hxx>
36#include <crossrefbookmark.hxx>
37#include <doc.hxx>
38#include <docsh.hxx>
39
40using namespace ::sw::mark;
41using namespace ::com::sun::star;
42
44 : public SvtListener
45{
46public:
48 std::mutex m_Mutex; // just for OInterfaceContainerHelper3
52 OUString m_sMarkName;
55
56 Impl( SwDoc *const pDoc )
57 : m_pDoc(pDoc)
58 , m_pRegisteredBookmark(nullptr)
59 , m_bHidden(false)
60 {
61 // DO NOT registerInMark here! (because SetXBookmark would delete rThis)
62 }
63
64 void registerInMark(SwXBookmark & rThis, ::sw::mark::IMark *const pBkmk);
65protected:
66 virtual void Notify(const SfxHint&) override;
67
68};
69
71{
72 if(rHint.GetId() == SfxHintId::Dying)
73 {
74 m_pRegisteredBookmark = nullptr;
75 m_pDoc = nullptr;
76 uno::Reference<uno::XInterface> const xThis(m_wThis);
77 if (!xThis.is())
78 { // fdo#72695: if UNO object is already dead, don't revive it with event
79 return;
80 }
81 lang::EventObject const ev(xThis);
82 std::unique_lock aGuard(m_Mutex);
84 }
85}
86
88 ::sw::mark::IMark* const pBkmk)
89{
90 const rtl::Reference<SwXBookmark> xBookmark(&rThis);
91 if (pBkmk)
92 {
93 EndListeningAll();
94 StartListening(pBkmk->GetNotifier());
95 ::sw::mark::MarkBase *const pMarkBase(dynamic_cast< ::sw::mark::MarkBase * >(pBkmk));
96 OSL_ENSURE(pMarkBase, "registerInMark: no MarkBase?");
97 if (pMarkBase)
98 {
99 pMarkBase->SetXBookmark(xBookmark);
100 }
101 assert(m_pDoc == nullptr || m_pDoc == &pBkmk->GetMarkPos().GetDoc());
102 m_pDoc = &pBkmk->GetMarkPos().GetDoc();
103 }
104 else if (m_pRegisteredBookmark)
105 {
106 m_sMarkName = m_pRegisteredBookmark->GetName();
107
108 // the following applies only to bookmarks (not to fieldmarks)
109 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pRegisteredBookmark);
110 if (pBookmark)
111 {
112 m_bHidden = pBookmark->IsHidden();
113 m_HideCondition = pBookmark->GetHideCondition();
114 }
115 EndListeningAll();
116 }
117 m_pRegisteredBookmark = pBkmk;
118 // need a permanent Reference to initialize m_wThis
119 m_wThis = xBookmark.get();
120}
121
123 ::sw::mark::IMark *const pBkmk)
124{
125 m_pImpl->registerInMark( rThis, pBkmk );
126}
127
129{
130 return m_pImpl->m_pRegisteredBookmark;
131}
132
134{
135 return m_pImpl->m_pDoc->getIDocumentMarkAccess();
136}
137
139{
140 return m_pImpl->m_pDoc;
141}
142
144 : m_pImpl( new SwXBookmark::Impl(pDoc) )
145{
146}
147
149 : m_pImpl( new SwXBookmark::Impl(nullptr) )
150{
151}
152
154{
155}
156
158 SwDoc & rDoc,
159 ::sw::mark::IMark *const pBookmark)
160{
161 // #i105557#: do not iterate over the registered clients: race condition
162 ::sw::mark::MarkBase *const pMarkBase(dynamic_cast< ::sw::mark::MarkBase * >(pBookmark));
163 OSL_ENSURE(!pBookmark || pMarkBase, "CreateXBookmark: no MarkBase?");
165 if (pMarkBase)
166 {
167 xBookmark = pMarkBase->GetXBookmark();
168 }
169 if (!xBookmark.is())
170 {
171 OSL_ENSURE(!pBookmark ||
172 dynamic_cast< ::sw::mark::IBookmark* >(pBookmark) ||
174 "<SwXBookmark::GetObject(..)>"
175 "SwXBookmark requested for non-bookmark mark and non-annotation mark.");
176 SwXBookmark *const pXBookmark =
177 pBookmark ? new SwXBookmark(&rDoc) : new SwXBookmark;
178 xBookmark.set(pXBookmark);
179 pXBookmark->m_pImpl->registerInMark(*pXBookmark, pMarkBase);
180 }
181 return xBookmark;
182}
183
185 const uno::Reference<uno::XInterface> & xUT)
186{
187 SwXBookmark *const pXBkm = dynamic_cast<SwXBookmark*>(xUT.get());
188 if (pXBkm && (pDoc == pXBkm->m_pImpl->m_pDoc))
189 {
190 return pXBkm->m_pImpl->m_pRegisteredBookmark;
191 }
192 return nullptr;
193}
194
196 const uno::Reference< text::XTextRange > & xTextRange,
198 bool const isFieldmarkSeparatorAtStart)
199{
200 if (m_pImpl->m_pRegisteredBookmark)
201 {
202 throw uno::RuntimeException();
203 }
204
205 SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
206 OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());
207
208 SwDoc *const pDoc =
209 pRange ? &pRange->GetDoc() : (pCursor ? pCursor->GetDoc() : nullptr);
210 if (!pDoc)
211 {
212 throw lang::IllegalArgumentException();
213 }
214
215 m_pImpl->m_pDoc = pDoc;
216 SwUnoInternalPaM aPam(*m_pImpl->m_pDoc);
217 ::sw::XTextRangeToSwPaM(aPam, xTextRange);
218 UnoActionContext aCont(m_pImpl->m_pDoc);
219 if (m_pImpl->m_sMarkName.isEmpty())
220 {
221 m_pImpl->m_sMarkName = "Bookmark";
222 }
225 {
227 }
231 {
233 }
234 m_pImpl->registerInMark(*this,
235 m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark(
236 aPam, m_pImpl->m_sMarkName, eType, ::sw::mark::InsertMode::New,
237 // note: aPam will be moved fwd by inserting start char, so sep
238 // will be directly following start
239 isFieldmarkSeparatorAtStart ? aPam.Start() : nullptr));
240 // #i81002#
241 // Check, if bookmark has been created.
242 // E.g., the creation of a cross-reference bookmark is suppress,
243 // if the PaM isn't a valid one for cross-reference bookmarks.
244 if (!m_pImpl->m_pRegisteredBookmark)
245 {
246 OSL_FAIL("<SwXBookmark::attachToRange(..)>"
247 " - could not create Mark.");
248 throw lang::IllegalArgumentException();
249 }
250}
251
252void SwXBookmark::attachToRange( const uno::Reference< text::XTextRange > & xTextRange )
253{
255}
256
257void SAL_CALL SwXBookmark::attach( const uno::Reference< text::XTextRange > & xTextRange )
258{
259 SolarMutexGuard aGuard;
260 attachToRange( xTextRange );
261}
262
263uno::Reference< text::XTextRange > SAL_CALL SwXBookmark::getAnchor()
264{
265 SolarMutexGuard aGuard;
266
267 if (!m_pImpl->m_pRegisteredBookmark)
268 {
269 throw uno::RuntimeException();
270 }
272 *m_pImpl->m_pDoc,
273 m_pImpl->m_pRegisteredBookmark->GetMarkPos(),
274 (m_pImpl->m_pRegisteredBookmark->IsExpanded())
275 ? &m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos() : nullptr);
276}
277
278void SAL_CALL SwXBookmark::dispose()
279{
280 SolarMutexGuard aGuard;
281 if (m_pImpl->m_pRegisteredBookmark)
282 {
283 m_pImpl->m_pDoc->getIDocumentMarkAccess()->deleteMark( m_pImpl->m_pRegisteredBookmark );
284 }
285}
286
288 const uno::Reference< lang::XEventListener > & xListener)
289{
290 // no need to lock here as m_pImpl is const and container threadsafe
291 std::unique_lock aGuard(m_pImpl->m_Mutex);
292 m_pImpl->m_EventListeners.addInterface(aGuard, xListener);
293}
294
296 const uno::Reference< lang::XEventListener > & xListener)
297{
298 // no need to lock here as m_pImpl is const and container threadsafe
299 std::unique_lock aGuard(m_pImpl->m_Mutex);
300 m_pImpl->m_EventListeners.removeInterface(aGuard, xListener);
301}
302
303OUString SAL_CALL SwXBookmark::getName()
304{
305 SolarMutexGuard aGuard;
306
307 return (m_pImpl->m_pRegisteredBookmark)
308 ? m_pImpl->m_pRegisteredBookmark->GetName()
309 : m_pImpl->m_sMarkName;
310}
311
312void SAL_CALL SwXBookmark::setName(const OUString& rName)
313{
314 SolarMutexGuard aGuard;
315
316 if (!m_pImpl->m_pRegisteredBookmark)
317 {
318 m_pImpl->m_sMarkName = rName;
319 }
320 if (!m_pImpl->m_pRegisteredBookmark || (getName() == rName))
321 {
322 return;
323 }
324 IDocumentMarkAccess *const pMarkAccess =
325 m_pImpl->m_pDoc->getIDocumentMarkAccess();
326 if(pMarkAccess->findMark(rName) != pMarkAccess->getAllMarksEnd())
327 {
328 throw uno::RuntimeException("setName(): name already in use",
329 static_cast<::cppu::OWeakObject*>(this));
330 }
331
332 SwPaM aPam(m_pImpl->m_pRegisteredBookmark->GetMarkPos());
333 if (m_pImpl->m_pRegisteredBookmark->IsExpanded())
334 {
335 aPam.SetMark();
336 *aPam.GetMark() = m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos();
337 }
338
339 pMarkAccess->renameMark(m_pImpl->m_pRegisteredBookmark, rName);
340}
341
342OUString SAL_CALL
344{
345 return "SwXBookmark";
346}
347
348sal_Bool SAL_CALL SwXBookmark::supportsService(const OUString& rServiceName)
349{
350 return cppu::supportsService(this, rServiceName);
351}
352
353uno::Sequence< OUString > SAL_CALL
355{
356 return {
357 "com.sun.star.text.TextContent",
358 "com.sun.star.text.Bookmark",
359 "com.sun.star.document.LinkTarget"
360 };
361}
362
363// MetadatableMixin
364::sfx2::Metadatable* SwXBookmark::GetCoreObject()
365{
366 return dynamic_cast< ::sfx2::Metadatable* >(m_pImpl->m_pRegisteredBookmark);
367}
368
369uno::Reference<frame::XModel> SwXBookmark::GetModel()
370{
371 if (m_pImpl->m_pDoc)
372 {
373 SwDocShell const * const pShell( m_pImpl->m_pDoc->GetDocShell() );
374 return pShell ? pShell->GetModel() : nullptr;
375 }
376 return nullptr;
377}
378
379uno::Reference< beans::XPropertySetInfo > SAL_CALL
381{
383
384 static uno::Reference< beans::XPropertySetInfo > xRef(
386 ->getPropertySetInfo() );
387 return xRef;
388}
389
390void SAL_CALL
391SwXBookmark::setPropertyValue(const OUString& PropertyName,
392 const uno::Any& rValue)
393{
395
396 if (PropertyName == UNO_NAME_BOOKMARK_HIDDEN)
397 {
398 bool bNewValue = false;
399 if (!(rValue >>= bNewValue))
400 throw lang::IllegalArgumentException("Property BookmarkHidden requires value of type boolean", nullptr, 0);
401
402 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pImpl->m_pRegisteredBookmark);
403 if (pBookmark)
404 {
405 pBookmark->Hide(bNewValue);
406 }
407 else
408 {
409 m_pImpl->m_bHidden = bNewValue;
410 }
411 return;
412 }
413 else if (PropertyName == UNO_NAME_BOOKMARK_CONDITION)
414 {
415 OUString newValue;
416 if (!(rValue >>= newValue))
417 throw lang::IllegalArgumentException("Property BookmarkCondition requires value of type string", nullptr, 0);
418
419 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pImpl->m_pRegisteredBookmark);
420 if (pBookmark)
421 {
422 pBookmark->SetHideCondition(newValue);
423 }
424 else
425 {
426 m_pImpl->m_HideCondition = newValue;
427 }
428 return;
429 }
430
431 // nothing to set here
432 throw lang::IllegalArgumentException("Property is read-only: "
433 + PropertyName, static_cast< cppu::OWeakObject * >(this), 0 );
434}
435
436uno::Any SAL_CALL SwXBookmark::getPropertyValue(const OUString& rPropertyName)
437{
439
440 uno::Any aRet;
441 if (! ::sw::GetDefaultTextContentValue(aRet, rPropertyName))
442 {
443 if(rPropertyName == UNO_LINK_DISPLAY_NAME)
444 {
445 aRet <<= getName();
446 }
447 else if (rPropertyName == UNO_NAME_BOOKMARK_HIDDEN)
448 {
449 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pImpl->m_pRegisteredBookmark);
450 if (pBookmark)
451 {
452 aRet <<= pBookmark->IsHidden();
453 }
454 else
455 {
456 aRet <<= m_pImpl->m_bHidden;
457 }
458 }
459 else if (rPropertyName == UNO_NAME_BOOKMARK_CONDITION)
460 {
461 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pImpl->m_pRegisteredBookmark);
462 if (pBookmark)
463 {
464 aRet <<= pBookmark->GetHideCondition();
465 }
466 else
467 {
468 aRet <<= m_pImpl->m_HideCondition;
469 }
470 }
471 }
472 return aRet;
473}
474
475void SAL_CALL
477 const OUString& /*rPropertyName*/,
478 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
479{
480 OSL_FAIL("SwXBookmark::addPropertyChangeListener(): not implemented");
481}
482
483void SAL_CALL
485 const OUString& /*rPropertyName*/,
486 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
487{
488 OSL_FAIL("SwXBookmark::removePropertyChangeListener(): not implemented");
489}
490
491void SAL_CALL
493 const OUString& /*rPropertyName*/,
494 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
495{
496 OSL_FAIL("SwXBookmark::addVetoableChangeListener(): not implemented");
497}
498
499void SAL_CALL
501 const OUString& /*rPropertyName*/,
502 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
503{
504 OSL_FAIL("SwXBookmark::removeVetoableChangeListener(): not implemented");
505}
506
507
508void SwXFieldmarkParameters::insertByName(const OUString& aName, const uno::Any& aElement)
509{
510 SolarMutexGuard aGuard;
511 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
512 if(pParameters->find(aName) != pParameters->end())
513 throw container::ElementExistException();
514 (*pParameters)[aName] = aElement;
515}
516
517void SwXFieldmarkParameters::removeByName(const OUString& aName)
518{
519 SolarMutexGuard aGuard;
520 if(!getCoreParameters()->erase(aName))
521 throw container::NoSuchElementException();
522}
523
524void SwXFieldmarkParameters::replaceByName(const OUString& aName, const uno::Any& aElement)
525{
526 SolarMutexGuard aGuard;
527 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
528 IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName);
529 if(pEntry == pParameters->end())
530 throw container::NoSuchElementException();
531 pEntry->second = aElement;
532}
533
535{
536 SolarMutexGuard aGuard;
537 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
538 IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName);
539 if(pEntry == pParameters->end())
540 throw container::NoSuchElementException();
541 return pEntry->second;
542}
543
545{
546 SolarMutexGuard aGuard;
547 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
548 return comphelper::mapKeysToSequence(*pParameters);
549}
550
552{
553 SolarMutexGuard aGuard;
554 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
555 return (pParameters->find(aName) != pParameters->end());
556}
557
559{
561}
562
564{
565 SolarMutexGuard aGuard;
566 return !getCoreParameters()->empty();
567}
568
570{
571 if(rHint.GetId() == SfxHintId::Dying)
572 m_pFieldmark = nullptr;
573}
574
575IFieldmark::parameter_map_t* SwXFieldmarkParameters::getCoreParameters()
576{
577 if(!m_pFieldmark)
578 throw uno::RuntimeException();
579 return m_pFieldmark->GetParameters();
580}
581
582SwXFieldmark::SwXFieldmark(bool const isReplacementObject, SwDoc *const pDoc)
583 : SwXFieldmark_Base(pDoc)
584 , m_bReplacementObject(isReplacementObject)
585{
586}
587
588OUString SAL_CALL
590{
591 return "SwXFieldmark";
592}
593
594uno::Sequence<OUString> SAL_CALL
596{
597 // is const, no lock needed
599 {
600 return {"com.sun.star.text.TextContent",
601 "com.sun.star.text.Bookmark",
602 "com.sun.star.text.FormFieldmark"};
603 }
604 else
605 {
606 return {"com.sun.star.text.TextContent",
607 "com.sun.star.text.Bookmark",
608 "com.sun.star.text.Fieldmark"};
609 }
610}
611
612void SwXFieldmark::attachToRange( const uno::Reference < text::XTextRange >& xTextRange )
613{
614
615 attachToRangeEx( xTextRange,
618}
619
621{
622 SolarMutexGuard aGuard;
623 const IFieldmark *pBkm = dynamic_cast<const IFieldmark*>(GetBookmark());
624 if(!pBkm)
625 throw uno::RuntimeException();
626 return pBkm->GetFieldname();
627}
628
629void SwXFieldmark::setFieldType(const OUString & fieldType)
630{
631 SolarMutexGuard aGuard;
632 IFieldmark *pBkm = dynamic_cast<IFieldmark*>(GetBookmark());
633 if(!pBkm)
634 throw uno::RuntimeException();
635
636 OUString const oldFieldType(getFieldType());
637 if (fieldType == oldFieldType)
638 return;
639
640 // note: this must not change between point-fieldmarks and range-fieldmarks
641 if(fieldType == ODF_FORMDROPDOWN || fieldType == ODF_FORMCHECKBOX || fieldType == ODF_FORMDATE)
642 {
643 ::sw::mark::IFieldmark* pNewFieldmark = GetIDocumentMarkAccess()->changeFormFieldmarkType(pBkm, fieldType);
644 if (pNewFieldmark)
645 {
646 registerInMark(*this, pNewFieldmark);
647 return;
648 }
649 }
650
651 if ((!m_bReplacementObject && (fieldType == ODF_UNHANDLED
652 || fieldType == ODF_FORMDATE
653 || fieldType == ODF_FORMTEXT))
654 || (m_bReplacementObject && (fieldType == ODF_FORMCHECKBOX
655 || fieldType == ODF_FORMDROPDOWN)))
656 {
657 pBkm->SetFieldname(fieldType);
658 return;
659 }
660
661 throw uno::RuntimeException("changing to that type isn't implemented");
662}
663
664uno::Reference<container::XNameContainer> SwXFieldmark::getParameters()
665{
666 SolarMutexGuard aGuard;
667 IFieldmark *pBkm = dynamic_cast<IFieldmark*>(GetBookmark());
668 if(!pBkm)
669 throw uno::RuntimeException();
670 return uno::Reference<container::XNameContainer>(new SwXFieldmarkParameters(pBkm));
671}
672
675 bool const isReplacementObject)
676{
677 // #i105557#: do not iterate over the registered clients: race condition
678 ::sw::mark::MarkBase *const pMarkBase(
679 dynamic_cast< ::sw::mark::MarkBase * >(pMark));
680 assert(!pMark || pMarkBase);
682 if (pMarkBase)
683 {
684 xMark = pMarkBase->GetXBookmark();
685 }
686 if (!xMark.is())
687 {
688 // FIXME: These belong in XTextFieldsSupplier
690 if (dynamic_cast< ::sw::mark::TextFieldmark* >(pMark))
691 pXBkmk = new SwXFieldmark(false, &rDoc);
692 else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(pMark))
693 pXBkmk = new SwXFieldmark(true, &rDoc);
694 else if (dynamic_cast< ::sw::mark::DropDownFieldmark* >(pMark))
695 pXBkmk = new SwXFieldmark(true, &rDoc);
696 else if (dynamic_cast< ::sw::mark::DateFieldmark* >(pMark))
697 pXBkmk = new SwXFieldmark(false, &rDoc);
698 else
699 pXBkmk = new SwXFieldmark(isReplacementObject, &rDoc);
700
701 xMark = pXBkmk.get();
702 pXBkmk->registerInMark(*pXBkmk, pMarkBase);
703 }
704 return xMark;
705}
706
709{
710 ::sw::mark::ICheckboxFieldmark* pCheckboxFm = nullptr;
712 {
713 pCheckboxFm = dynamic_cast< ::sw::mark::ICheckboxFieldmark* >( GetBookmark());
714 assert( GetBookmark() == nullptr || pCheckboxFm != nullptr );
715 // unclear to me whether GetBookmark() can be null here
716 }
717 return pCheckboxFm;
718
719}
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
724void SAL_CALL
725SwXFieldmark::setPropertyValue(const OUString& PropertyName,
726 const uno::Any& rValue)
727{
729 if ( PropertyName == "Checked" )
730 {
732 bool bChecked( false );
733 if ( !(pCheckboxFm && ( rValue >>= bChecked )) )
734 throw uno::RuntimeException();
735
736 pCheckboxFm->SetChecked( bChecked );
737 }
738 else if (PropertyName == "PrivateSeparatorAtStart")
739 {
740 bool isFieldmarkSeparatorAtStart{};
741 if (rValue >>= isFieldmarkSeparatorAtStart)
742 {
743 m_isFieldmarkSeparatorAtStart = isFieldmarkSeparatorAtStart;
744 }
745 }
746 // this doesn't support any SwXBookmark property
747}
748
749// support 'hidden' "Checked" property ( note: this property is just for convenience to support
750// docx import filter thus not published via PropertySet info )
751
752uno::Any SAL_CALL SwXFieldmark::getPropertyValue(const OUString& rPropertyName)
753{
755 if ( rPropertyName == "Checked" )
756 {
758 if ( !pCheckboxFm )
759 throw uno::RuntimeException();
760
761 return uno::Any( pCheckboxFm->IsChecked() );
762 }
763 return uno::Any(); // this doesn't support any SwXBookmark property
764}
765
766uno::Reference<beans::XPropertySetInfo> SAL_CALL
768{
770
771 static uno::Reference<beans::XPropertySetInfo> const xRef(
773 ->getPropertySetInfo() );
774 return xRef;
775}
776
777// XComponent
779{
780 return SwXBookmark::dispose();
781}
783 uno::Reference<lang::XEventListener> const& xListener)
784{
785 return SwXBookmark::addEventListener(xListener);
786}
788 uno::Reference<lang::XEventListener> const& xListener)
789{
790 return SwXBookmark::removeEventListener(xListener);
791}
792
793// XTextContent
795 uno::Reference<text::XTextRange> const& xTextRange)
796{
797 return SwXBookmark::attach(xTextRange);
798}
799
800uno::Reference<text::XTextRange> SAL_CALL SwXFieldmark::getAnchor()
801{
802 return SwXBookmark::getAnchor();
803}
804
806SwXFieldmark::GetCommand(IFieldmark const& rMark)
807{
808 SwPosition const sepPos(sw::mark::FindFieldSep(rMark));
809 SwPosition start(rMark.GetMarkStart());
810 start.AdjustContent(1);
811 return SwXTextRange::CreateXTextRange(*GetDoc(), start, &sepPos);
812}
813
815SwXFieldmark::GetResult(IFieldmark const& rMark)
816{
817 SwPosition sepPos(sw::mark::FindFieldSep(rMark));
818 sepPos.AdjustContent(1);
819 SwPosition const& rEnd(rMark.GetMarkEnd());
820 return SwXTextRange::CreateXTextRange(*GetDoc(), sepPos, &rEnd);
821}
822
823// XTextField
824OUString SAL_CALL
826{
828
829 IFieldmark const*const pMark(dynamic_cast<IFieldmark*>(GetBookmark()));
830 if (!pMark)
831 {
832 throw lang::DisposedException();
833 }
834
835 if (bShowCommand)
836 {
838 {
839 return OUString();
840 }
841 else
842 { // also for ODF_FORMDATE, which shouldn't be a fieldmark...
843 uno::Reference<text::XTextRange> const xCommand(GetCommand(*pMark));
844 return xCommand->getString();
845 }
846 }
847 else
848 {
849 OUString const type(getFieldType());
851 {
852 return sw::mark::ExpandFieldmark(const_cast<IFieldmark *>(pMark));
853 }
854 else
855 {
856 assert(!m_bReplacementObject);
857 uno::Reference<text::XTextRange> const xResult(GetResult(*pMark));
858 return xResult->getString();
859 }
860 }
861}
862
863/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
Provides access to the marks of a document.
virtual bool renameMark(::sw::mark::IMark *io_pMark, const OUString &rNewName)=0
Renames an existing Mark, if possible.
virtual const_iterator_t getAllMarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of marks.
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark(const SwPaM &rPaM)
Definition: docbm.cxx:541
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
Definition: docbm.cxx:502
SfxHintId GetId() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
Definition: doc.hxx:197
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
const SwPosition * GetMark() const
Definition: pam.hxx:255
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
const SwPosition * Start() const
Definition: pam.hxx:258
const SfxItemPropertySet * GetPropertySet(sal_uInt16 PropertyId)
Definition: unomap1.cxx:1111
::comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_EventListeners
Definition: unobkm.cxx:49
::sw::mark::IMark * m_pRegisteredBookmark
Definition: unobkm.cxx:51
virtual void Notify(const SfxHint &) override
Definition: unobkm.cxx:70
unotools::WeakReference< SwXBookmark > m_wThis
Definition: unobkm.cxx:47
OUString m_HideCondition
Definition: unobkm.cxx:54
void registerInMark(SwXBookmark &rThis, ::sw::mark::IMark *const pBkmk)
Definition: unobkm.cxx:87
Impl(SwDoc *const pDoc)
Definition: unobkm.cxx:56
SwDoc * m_pDoc
Definition: unobkm.cxx:50
std::mutex m_Mutex
Definition: unobkm.cxx:48
OUString m_sMarkName
Definition: unobkm.cxx:52
UNO API wrapper around an internal sw::mark::IMark.
Definition: unobookmark.hxx:51
void registerInMark(SwXBookmark &rXMark, ::sw::mark::IMark *const pMarkBase)
Definition: unobkm.cxx:122
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: unobkm.cxx:287
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: unobkm.cxx:391
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
Definition: unobkm.cxx:492
virtual ~SwXBookmark() override
Definition: unobkm.cxx:153
virtual css::uno::Reference< css::frame::XModel > GetModel() override
Definition: unobkm.cxx:369
virtual OUString SAL_CALL getName() override
Definition: unobkm.cxx:303
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unobkm.cxx:484
::sw::mark::IMark const * GetBookmarkInDoc(SwDoc const *const pDoc, const css::uno::Reference< css::uno::XInterface > &xUT)
Definition: unobkm.cxx:184
virtual void SAL_CALL setName(const OUString &rName) override
Definition: unobkm.cxx:312
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unobkm.cxx:476
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: unobkm.cxx:295
static rtl::Reference< SwXBookmark > CreateXBookmark(SwDoc &rDoc, ::sw::mark::IMark *pBookmark)
Definition: unobkm.cxx:157
virtual ::sfx2::Metadatable * GetCoreObject() override
Definition: unobkm.cxx:364
void attachToRangeEx(const css::uno::Reference< css::text::XTextRange > &xTextRange, IDocumentMarkAccess::MarkType eType, bool isFieldmarkSeparatorAtStart=false)
Definition: unobkm.cxx:195
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unobkm.cxx:380
virtual OUString SAL_CALL getImplementationName() override
Definition: unobkm.cxx:343
SwXBookmark()
descriptor
Definition: unobkm.cxx:148
SwDoc * GetDoc()
Definition: unobkm.cxx:138
virtual void attachToRange(const css::uno::Reference< css::text::XTextRange > &xTextRange)
Definition: unobkm.cxx:252
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unobkm.cxx:354
IDocumentMarkAccess * GetIDocumentMarkAccess()
Definition: unobkm.cxx:133
virtual void SAL_CALL dispose() override
Definition: unobkm.cxx:278
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
Definition: unobkm.cxx:263
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: unobkm.cxx:257
::sw::mark::IMark * GetBookmark() const
Definition: unobkm.cxx:128
::sw::UnoImplPtr< Impl > m_pImpl
Definition: unobookmark.hxx:55
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
Definition: unobkm.cxx:348
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: unobkm.cxx:436
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
Definition: unobkm.cxx:500
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unobkm.cxx:558
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: unobkm.cxx:534
virtual void Notify(const SfxHint &rHint) override
Definition: unobkm.cxx:569
virtual void SAL_CALL insertByName(const OUString &aName, const css::uno::Any &aElement) override
Definition: unobkm.cxx:508
virtual sal_Bool SAL_CALL hasElements() override
Definition: unobkm.cxx:563
virtual void SAL_CALL removeByName(const OUString &Name) override
Definition: unobkm.cxx:517
::sw::mark::IFieldmark::parameter_map_t * getCoreParameters()
Definition: unobkm.cxx:575
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
Definition: unobkm.cxx:524
::sw::mark::IFieldmark * m_pFieldmark
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unobkm.cxx:544
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: unobkm.cxx:551
::sw::mark::ICheckboxFieldmark * getCheckboxFieldmark()
Definition: unobkm.cxx:708
virtual OUString SAL_CALL getPresentation(sal_Bool bShowCommand) override
Definition: unobkm.cxx:825
rtl::Reference< SwXTextRange > GetResult(::sw::mark::IFieldmark const &rMark)
Definition: unobkm.cxx:815
virtual OUString SAL_CALL getImplementationName() override
Definition: unobkm.cxx:589
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: unobkm.cxx:782
rtl::Reference< SwXTextRange > GetCommand(::sw::mark::IFieldmark const &rMark)
Definition: unobkm.cxx:806
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
Definition: unobkm.cxx:800
bool m_isFieldmarkSeparatorAtStart
static rtl::Reference< SwXBookmark > CreateXFieldmark(SwDoc &rDoc, ::sw::mark::IMark *pMark, bool isReplacementObject=false)
Definition: unobkm.cxx:674
bool const m_bReplacementObject
SwXFieldmark(bool isReplacementObject, SwDoc *pDoc)
Definition: unobkm.cxx:582
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unobkm.cxx:595
virtual void attachToRange(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: unobkm.cxx:612
virtual css::uno::Reference< css::container::XNameContainer > SAL_CALL getParameters() override
Definition: unobkm.cxx:664
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: unobkm.cxx:752
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unobkm.cxx:767
virtual void SAL_CALL setFieldType(const OUString &description) override
Definition: unobkm.cxx:629
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: unobkm.cxx:725
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: unobkm.cxx:787
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: unobkm.cxx:794
virtual void SAL_CALL dispose() override
Definition: unobkm.cxx:778
virtual OUString SAL_CALL getFieldType() override
Definition: unobkm.cxx:620
const SwDoc & GetDoc() const
Definition: unoobj2.cxx:762
static rtl::Reference< SwXTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1221
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
Fieldmark representing a checkbox form field.
static bool IsLegalName(std::u16string_view rName)
static bool IsLegalName(std::u16string_view rName)
Fieldmark representing a date form field.
Fieldmark representing a drop-down form field.
virtual void SetChecked(bool checked)=0
virtual bool IsChecked() const =0
virtual const SwPosition & GetMarkPos() const =0
const unotools::WeakReference< SwXBookmark > & GetXBookmark() const
void SetXBookmark(rtl::Reference< SwXBookmark > const &xBkmk)
DocumentType eType
OUString aName
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
OUString ExpandFieldmark(IFieldmark *pBM)
Definition: itrform2.cxx:1120
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
bool XTextRangeToSwPaM(SwUnoInternalPaM &rToFill, const uno::Reference< text::XTextRange > &xTextRange, ::sw::TextRangeMode const eMode)
Definition: unoobj2.cxx:1108
bool GetDefaultTextContentValue(css::uno::Any &rAny, std::u16string_view rPropertyName, sal_uInt16 nWID=0)
constexpr OUStringLiteral ODF_FORMTEXT
constexpr OUStringLiteral ODF_FORMCHECKBOX
constexpr OUStringLiteral ODF_FORMDATE
constexpr OUStringLiteral ODF_UNHANDLED
constexpr OUStringLiteral ODF_FORMDROPDOWN
Marks a position in the document model.
Definition: pam.hxx:38
void AdjustContent(sal_Int32 nDelta)
Adjust content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:262
SwDoc & GetDoc() const
Returns the document this position is in.
Definition: pam.cxx:218
unsigned char sal_Bool
ResultType type
cppu::ImplInheritanceHelper< SwXBookmark, css::text::XFormField, css::text::XTextField > SwXFieldmark_Base
SwUnoPropertyMapProvider aSwMapProvider
Definition: unomap1.cxx:88
#define PROPERTY_MAP_FIELDMARK
Definition: unomap.hxx:128
#define PROPERTY_MAP_BOOKMARK
Definition: unomap.hxx:51
constexpr OUStringLiteral UNO_LINK_DISPLAY_NAME
Definition: unoprnms.hxx:488
constexpr OUStringLiteral UNO_NAME_BOOKMARK_CONDITION
Definition: unoprnms.hxx:366
constexpr OUStringLiteral UNO_NAME_BOOKMARK_HIDDEN
Definition: unoprnms.hxx:365