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< lang::XUnoTunnel> & xUT)
186{
187 SwXBookmark *const pXBkm(
188 comphelper::getFromUnoTunnel<SwXBookmark>(xUT));
189 if (pXBkm && (pDoc == pXBkm->m_pImpl->m_pDoc))
190 {
191 return pXBkm->m_pImpl->m_pRegisteredBookmark;
192 }
193 return nullptr;
194}
195
196const uno::Sequence< sal_Int8 > & SwXBookmark::getUnoTunnelId()
197{
198 static const comphelper::UnoIdInit theSwXBookmarkUnoTunnelId;
199 return theSwXBookmarkUnoTunnelId.getSeq();
200}
201
202sal_Int64 SAL_CALL SwXBookmark::getSomething( const uno::Sequence< sal_Int8 >& rId )
203{
204 return comphelper::getSomethingImpl<SwXBookmark>(rId, this);
205}
206
208 const uno::Reference< text::XTextRange > & xTextRange,
210 bool const isFieldmarkSeparatorAtStart)
211{
212 if (m_pImpl->m_pRegisteredBookmark)
213 {
214 throw uno::RuntimeException();
215 }
216
217 const uno::Reference<lang::XUnoTunnel> xRangeTunnel(
218 xTextRange, uno::UNO_QUERY);
219 SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
220 OTextCursorHelper* pCursor =
221 comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel);
222
223 SwDoc *const pDoc =
224 pRange ? &pRange->GetDoc() : (pCursor ? pCursor->GetDoc() : nullptr);
225 if (!pDoc)
226 {
227 throw lang::IllegalArgumentException();
228 }
229
230 m_pImpl->m_pDoc = pDoc;
231 SwUnoInternalPaM aPam(*m_pImpl->m_pDoc);
232 ::sw::XTextRangeToSwPaM(aPam, xTextRange);
233 UnoActionContext aCont(m_pImpl->m_pDoc);
234 if (m_pImpl->m_sMarkName.isEmpty())
235 {
236 m_pImpl->m_sMarkName = "Bookmark";
237 }
240 {
242 }
246 {
248 }
249 m_pImpl->registerInMark(*this,
250 m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark(
251 aPam, m_pImpl->m_sMarkName, eType, ::sw::mark::InsertMode::New,
252 // note: aPam will be moved fwd by inserting start char, so sep
253 // will be directly following start
254 isFieldmarkSeparatorAtStart ? aPam.Start() : nullptr));
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 if (!m_pImpl->m_pRegisteredBookmark)
260 {
261 OSL_FAIL("<SwXBookmark::attachToRange(..)>"
262 " - could not create Mark.");
263 throw lang::IllegalArgumentException();
264 }
265}
266
267void SwXBookmark::attachToRange( const uno::Reference< text::XTextRange > & xTextRange )
268{
270}
271
272void SAL_CALL SwXBookmark::attach( const uno::Reference< text::XTextRange > & xTextRange )
273{
274 SolarMutexGuard aGuard;
275 attachToRange( xTextRange );
276}
277
278uno::Reference< text::XTextRange > SAL_CALL SwXBookmark::getAnchor()
279{
280 SolarMutexGuard aGuard;
281
282 if (!m_pImpl->m_pRegisteredBookmark)
283 {
284 throw uno::RuntimeException();
285 }
287 *m_pImpl->m_pDoc,
288 m_pImpl->m_pRegisteredBookmark->GetMarkPos(),
289 (m_pImpl->m_pRegisteredBookmark->IsExpanded())
290 ? &m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos() : nullptr);
291}
292
293void SAL_CALL SwXBookmark::dispose()
294{
295 SolarMutexGuard aGuard;
296 if (m_pImpl->m_pRegisteredBookmark)
297 {
298 m_pImpl->m_pDoc->getIDocumentMarkAccess()->deleteMark( m_pImpl->m_pRegisteredBookmark );
299 }
300}
301
303 const uno::Reference< lang::XEventListener > & xListener)
304{
305 // no need to lock here as m_pImpl is const and container threadsafe
306 std::unique_lock aGuard(m_pImpl->m_Mutex);
307 m_pImpl->m_EventListeners.addInterface(aGuard, xListener);
308}
309
311 const uno::Reference< lang::XEventListener > & xListener)
312{
313 // no need to lock here as m_pImpl is const and container threadsafe
314 std::unique_lock aGuard(m_pImpl->m_Mutex);
315 m_pImpl->m_EventListeners.removeInterface(aGuard, xListener);
316}
317
318OUString SAL_CALL SwXBookmark::getName()
319{
320 SolarMutexGuard aGuard;
321
322 return (m_pImpl->m_pRegisteredBookmark)
323 ? m_pImpl->m_pRegisteredBookmark->GetName()
324 : m_pImpl->m_sMarkName;
325}
326
327void SAL_CALL SwXBookmark::setName(const OUString& rName)
328{
329 SolarMutexGuard aGuard;
330
331 if (!m_pImpl->m_pRegisteredBookmark)
332 {
333 m_pImpl->m_sMarkName = rName;
334 }
335 if (!m_pImpl->m_pRegisteredBookmark || (getName() == rName))
336 {
337 return;
338 }
339 IDocumentMarkAccess *const pMarkAccess =
340 m_pImpl->m_pDoc->getIDocumentMarkAccess();
341 if(pMarkAccess->findMark(rName) != pMarkAccess->getAllMarksEnd())
342 {
343 throw uno::RuntimeException("setName(): name already in use",
344 static_cast<::cppu::OWeakObject*>(this));
345 }
346
347 SwPaM aPam(m_pImpl->m_pRegisteredBookmark->GetMarkPos());
348 if (m_pImpl->m_pRegisteredBookmark->IsExpanded())
349 {
350 aPam.SetMark();
351 *aPam.GetMark() = m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos();
352 }
353
354 pMarkAccess->renameMark(m_pImpl->m_pRegisteredBookmark, rName);
355}
356
357OUString SAL_CALL
359{
360 return "SwXBookmark";
361}
362
363sal_Bool SAL_CALL SwXBookmark::supportsService(const OUString& rServiceName)
364{
365 return cppu::supportsService(this, rServiceName);
366}
367
368uno::Sequence< OUString > SAL_CALL
370{
371 return {
372 "com.sun.star.text.TextContent",
373 "com.sun.star.text.Bookmark",
374 "com.sun.star.document.LinkTarget"
375 };
376}
377
378// MetadatableMixin
379::sfx2::Metadatable* SwXBookmark::GetCoreObject()
380{
381 return dynamic_cast< ::sfx2::Metadatable* >(m_pImpl->m_pRegisteredBookmark);
382}
383
384uno::Reference<frame::XModel> SwXBookmark::GetModel()
385{
386 if (m_pImpl->m_pDoc)
387 {
388 SwDocShell const * const pShell( m_pImpl->m_pDoc->GetDocShell() );
389 return pShell ? pShell->GetModel() : nullptr;
390 }
391 return nullptr;
392}
393
394uno::Reference< beans::XPropertySetInfo > SAL_CALL
396{
398
399 static uno::Reference< beans::XPropertySetInfo > xRef(
401 ->getPropertySetInfo() );
402 return xRef;
403}
404
405void SAL_CALL
406SwXBookmark::setPropertyValue(const OUString& PropertyName,
407 const uno::Any& rValue)
408{
410
411 if (PropertyName == UNO_NAME_BOOKMARK_HIDDEN)
412 {
413 bool bNewValue = false;
414 if (!(rValue >>= bNewValue))
415 throw lang::IllegalArgumentException("Property BookmarkHidden requires value of type boolean", nullptr, 0);
416
417 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pImpl->m_pRegisteredBookmark);
418 if (pBookmark)
419 {
420 pBookmark->Hide(bNewValue);
421 }
422 else
423 {
424 m_pImpl->m_bHidden = bNewValue;
425 }
426 return;
427 }
428 else if (PropertyName == UNO_NAME_BOOKMARK_CONDITION)
429 {
430 OUString newValue;
431 if (!(rValue >>= newValue))
432 throw lang::IllegalArgumentException("Property BookmarkCondition requires value of type string", nullptr, 0);
433
434 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pImpl->m_pRegisteredBookmark);
435 if (pBookmark)
436 {
437 pBookmark->SetHideCondition(newValue);
438 }
439 else
440 {
441 m_pImpl->m_HideCondition = newValue;
442 }
443 return;
444 }
445
446 // nothing to set here
447 throw lang::IllegalArgumentException("Property is read-only: "
448 + PropertyName, static_cast< cppu::OWeakObject * >(this), 0 );
449}
450
451uno::Any SAL_CALL SwXBookmark::getPropertyValue(const OUString& rPropertyName)
452{
454
455 uno::Any aRet;
456 if (! ::sw::GetDefaultTextContentValue(aRet, rPropertyName))
457 {
458 if(rPropertyName == UNO_LINK_DISPLAY_NAME)
459 {
460 aRet <<= getName();
461 }
462 else if (rPropertyName == UNO_NAME_BOOKMARK_HIDDEN)
463 {
464 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pImpl->m_pRegisteredBookmark);
465 if (pBookmark)
466 {
467 aRet <<= pBookmark->IsHidden();
468 }
469 else
470 {
471 aRet <<= m_pImpl->m_bHidden;
472 }
473 }
474 else if (rPropertyName == UNO_NAME_BOOKMARK_CONDITION)
475 {
476 IBookmark* pBookmark = dynamic_cast<IBookmark*>(m_pImpl->m_pRegisteredBookmark);
477 if (pBookmark)
478 {
479 aRet <<= pBookmark->GetHideCondition();
480 }
481 else
482 {
483 aRet <<= m_pImpl->m_HideCondition;
484 }
485 }
486 }
487 return aRet;
488}
489
490void SAL_CALL
492 const OUString& /*rPropertyName*/,
493 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
494{
495 OSL_FAIL("SwXBookmark::addPropertyChangeListener(): not implemented");
496}
497
498void SAL_CALL
500 const OUString& /*rPropertyName*/,
501 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
502{
503 OSL_FAIL("SwXBookmark::removePropertyChangeListener(): not implemented");
504}
505
506void SAL_CALL
508 const OUString& /*rPropertyName*/,
509 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
510{
511 OSL_FAIL("SwXBookmark::addVetoableChangeListener(): not implemented");
512}
513
514void SAL_CALL
516 const OUString& /*rPropertyName*/,
517 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
518{
519 OSL_FAIL("SwXBookmark::removeVetoableChangeListener(): not implemented");
520}
521
522
523void SwXFieldmarkParameters::insertByName(const OUString& aName, const uno::Any& aElement)
524{
525 SolarMutexGuard aGuard;
526 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
527 if(pParameters->find(aName) != pParameters->end())
528 throw container::ElementExistException();
529 (*pParameters)[aName] = aElement;
530}
531
532void SwXFieldmarkParameters::removeByName(const OUString& aName)
533{
534 SolarMutexGuard aGuard;
535 if(!getCoreParameters()->erase(aName))
536 throw container::NoSuchElementException();
537}
538
539void SwXFieldmarkParameters::replaceByName(const OUString& aName, const uno::Any& aElement)
540{
541 SolarMutexGuard aGuard;
542 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
543 IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName);
544 if(pEntry == pParameters->end())
545 throw container::NoSuchElementException();
546 pEntry->second = aElement;
547}
548
550{
551 SolarMutexGuard aGuard;
552 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
553 IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName);
554 if(pEntry == pParameters->end())
555 throw container::NoSuchElementException();
556 return pEntry->second;
557}
558
560{
561 SolarMutexGuard aGuard;
562 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
563 return comphelper::mapKeysToSequence(*pParameters);
564}
565
567{
568 SolarMutexGuard aGuard;
569 IFieldmark::parameter_map_t* pParameters = getCoreParameters();
570 return (pParameters->find(aName) != pParameters->end());
571}
572
574{
576}
577
579{
580 SolarMutexGuard aGuard;
581 return !getCoreParameters()->empty();
582}
583
585{
586 if(rHint.GetId() == SfxHintId::Dying)
587 m_pFieldmark = nullptr;
588}
589
590IFieldmark::parameter_map_t* SwXFieldmarkParameters::getCoreParameters()
591{
592 if(!m_pFieldmark)
593 throw uno::RuntimeException();
594 return m_pFieldmark->GetParameters();
595}
596
597SwXFieldmark::SwXFieldmark(bool const isReplacementObject, SwDoc *const pDoc)
598 : SwXFieldmark_Base(pDoc)
599 , m_bReplacementObject(isReplacementObject)
600{
601}
602
603OUString SAL_CALL
605{
606 return "SwXFieldmark";
607}
608
609uno::Sequence<OUString> SAL_CALL
611{
612 // is const, no lock needed
614 {
615 return {"com.sun.star.text.TextContent",
616 "com.sun.star.text.Bookmark",
617 "com.sun.star.text.FormFieldmark"};
618 }
619 else
620 {
621 return {"com.sun.star.text.TextContent",
622 "com.sun.star.text.Bookmark",
623 "com.sun.star.text.Fieldmark"};
624 }
625}
626
627void SwXFieldmark::attachToRange( const uno::Reference < text::XTextRange >& xTextRange )
628{
629
630 attachToRangeEx( xTextRange,
633}
634
636{
637 SolarMutexGuard aGuard;
638 const IFieldmark *pBkm = dynamic_cast<const IFieldmark*>(GetBookmark());
639 if(!pBkm)
640 throw uno::RuntimeException();
641 return pBkm->GetFieldname();
642}
643
644void SwXFieldmark::setFieldType(const OUString & fieldType)
645{
646 SolarMutexGuard aGuard;
647 IFieldmark *pBkm = dynamic_cast<IFieldmark*>(GetBookmark());
648 if(!pBkm)
649 throw uno::RuntimeException();
650
651 OUString const oldFieldType(getFieldType());
652 if (fieldType == oldFieldType)
653 return;
654
655 // note: this must not change between point-fieldmarks and range-fieldmarks
656 if(fieldType == ODF_FORMDROPDOWN || fieldType == ODF_FORMCHECKBOX || fieldType == ODF_FORMDATE)
657 {
658 ::sw::mark::IFieldmark* pNewFieldmark = GetIDocumentMarkAccess()->changeFormFieldmarkType(pBkm, fieldType);
659 if (pNewFieldmark)
660 {
661 registerInMark(*this, pNewFieldmark);
662 return;
663 }
664 }
665
666 if ((!m_bReplacementObject && (fieldType == ODF_UNHANDLED
667 || fieldType == ODF_FORMDATE
668 || fieldType == ODF_FORMTEXT))
669 || (m_bReplacementObject && (fieldType == ODF_FORMCHECKBOX
670 || fieldType == ODF_FORMDROPDOWN)))
671 {
672 pBkm->SetFieldname(fieldType);
673 return;
674 }
675
676 throw uno::RuntimeException("changing to that type isn't implemented");
677}
678
679uno::Reference<container::XNameContainer> SwXFieldmark::getParameters()
680{
681 SolarMutexGuard aGuard;
682 IFieldmark *pBkm = dynamic_cast<IFieldmark*>(GetBookmark());
683 if(!pBkm)
684 throw uno::RuntimeException();
685 return uno::Reference<container::XNameContainer>(new SwXFieldmarkParameters(pBkm));
686}
687
690 bool const isReplacementObject)
691{
692 // #i105557#: do not iterate over the registered clients: race condition
693 ::sw::mark::MarkBase *const pMarkBase(
694 dynamic_cast< ::sw::mark::MarkBase * >(pMark));
695 assert(!pMark || pMarkBase);
697 if (pMarkBase)
698 {
699 xMark = pMarkBase->GetXBookmark();
700 }
701 if (!xMark.is())
702 {
703 // FIXME: These belong in XTextFieldsSupplier
705 if (dynamic_cast< ::sw::mark::TextFieldmark* >(pMark))
706 pXBkmk = new SwXFieldmark(false, &rDoc);
707 else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(pMark))
708 pXBkmk = new SwXFieldmark(true, &rDoc);
709 else if (dynamic_cast< ::sw::mark::DropDownFieldmark* >(pMark))
710 pXBkmk = new SwXFieldmark(true, &rDoc);
711 else if (dynamic_cast< ::sw::mark::DateFieldmark* >(pMark))
712 pXBkmk = new SwXFieldmark(false, &rDoc);
713 else
714 pXBkmk = new SwXFieldmark(isReplacementObject, &rDoc);
715
716 xMark = pXBkmk.get();
717 pXBkmk->registerInMark(*pXBkmk, pMarkBase);
718 }
719 return xMark;
720}
721
724{
725 ::sw::mark::ICheckboxFieldmark* pCheckboxFm = nullptr;
727 {
728 pCheckboxFm = dynamic_cast< ::sw::mark::ICheckboxFieldmark* >( GetBookmark());
729 assert( GetBookmark() == nullptr || pCheckboxFm != nullptr );
730 // unclear to me whether GetBookmark() can be null here
731 }
732 return pCheckboxFm;
733
734}
735
736// support 'hidden' "Checked" property ( note: this property is just for convenience to support
737// docx import filter thus not published via PropertySet info )
738
739void SAL_CALL
740SwXFieldmark::setPropertyValue(const OUString& PropertyName,
741 const uno::Any& rValue)
742{
744 if ( PropertyName == "Checked" )
745 {
747 bool bChecked( false );
748 if ( !(pCheckboxFm && ( rValue >>= bChecked )) )
749 throw uno::RuntimeException();
750
751 pCheckboxFm->SetChecked( bChecked );
752 }
753 else if (PropertyName == "PrivateSeparatorAtStart")
754 {
755 bool isFieldmarkSeparatorAtStart{};
756 if (rValue >>= isFieldmarkSeparatorAtStart)
757 {
758 m_isFieldmarkSeparatorAtStart = isFieldmarkSeparatorAtStart;
759 }
760 }
761 // this doesn't support any SwXBookmark property
762}
763
764// support 'hidden' "Checked" property ( note: this property is just for convenience to support
765// docx import filter thus not published via PropertySet info )
766
767uno::Any SAL_CALL SwXFieldmark::getPropertyValue(const OUString& rPropertyName)
768{
770 if ( rPropertyName == "Checked" )
771 {
773 if ( !pCheckboxFm )
774 throw uno::RuntimeException();
775
776 return uno::Any( pCheckboxFm->IsChecked() );
777 }
778 return uno::Any(); // this doesn't support any SwXBookmark property
779}
780
781uno::Reference<beans::XPropertySetInfo> SAL_CALL
783{
785
786 static uno::Reference<beans::XPropertySetInfo> const xRef(
788 ->getPropertySetInfo() );
789 return xRef;
790}
791
792// XComponent
794{
795 return SwXBookmark::dispose();
796}
798 uno::Reference<lang::XEventListener> const& xListener)
799{
800 return SwXBookmark::addEventListener(xListener);
801}
803 uno::Reference<lang::XEventListener> const& xListener)
804{
805 return SwXBookmark::removeEventListener(xListener);
806}
807
808// XTextContent
810 uno::Reference<text::XTextRange> const& xTextRange)
811{
812 return SwXBookmark::attach(xTextRange);
813}
814
815uno::Reference<text::XTextRange> SAL_CALL SwXFieldmark::getAnchor()
816{
817 return SwXBookmark::getAnchor();
818}
819
821SwXFieldmark::GetCommand(IFieldmark const& rMark)
822{
823 SwPosition const sepPos(sw::mark::FindFieldSep(rMark));
824 SwPosition start(rMark.GetMarkStart());
825 start.AdjustContent(1);
826 return SwXTextRange::CreateXTextRange(*GetDoc(), start, &sepPos);
827}
828
830SwXFieldmark::GetResult(IFieldmark const& rMark)
831{
832 SwPosition sepPos(sw::mark::FindFieldSep(rMark));
833 sepPos.AdjustContent(1);
834 SwPosition const& rEnd(rMark.GetMarkEnd());
835 return SwXTextRange::CreateXTextRange(*GetDoc(), sepPos, &rEnd);
836}
837
838// XTextField
839OUString SAL_CALL
841{
843
844 IFieldmark const*const pMark(dynamic_cast<IFieldmark*>(GetBookmark()));
845 if (!pMark)
846 {
847 throw lang::DisposedException();
848 }
849
850 if (bShowCommand)
851 {
853 {
854 return OUString();
855 }
856 else
857 { // also for ODF_FORMDATE, which shouldn't be a fieldmark...
858 uno::Reference<text::XTextRange> const xCommand(GetCommand(*pMark));
859 return xCommand->getString();
860 }
861 }
862 else
863 {
864 OUString const type(getFieldType());
866 {
867 return sw::mark::ExpandFieldmark(const_cast<IFieldmark *>(pMark));
868 }
869 else
870 {
871 assert(!m_bReplacementObject);
872 uno::Reference<text::XTextRange> const xResult(GetResult(*pMark));
873 return xResult->getString();
874 }
875 }
876}
877
878/* 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:515
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
Definition: docbm.cxx:476
virtual const SwDoc * GetDoc() const =0
SfxHintId GetId() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
Definition: doc.hxx:194
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
const SwPosition * GetMark() const
Definition: pam.hxx:263
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:642
const SwPosition * Start() const
Definition: pam.hxx:266
const SfxItemPropertySet * GetPropertySet(sal_uInt16 PropertyId)
Definition: unomap1.cxx:1071
::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:53
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:302
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: unobkm.cxx:406
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
Definition: unobkm.cxx:507
virtual ~SwXBookmark() override
Definition: unobkm.cxx:153
virtual css::uno::Reference< css::frame::XModel > GetModel() override
Definition: unobkm.cxx:384
virtual OUString SAL_CALL getName() override
Definition: unobkm.cxx:318
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unobkm.cxx:196
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unobkm.cxx:499
virtual void SAL_CALL setName(const OUString &rName) override
Definition: unobkm.cxx:327
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rIdentifier) override
Definition: unobkm.cxx:202
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unobkm.cxx:491
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: unobkm.cxx:310
static rtl::Reference< SwXBookmark > CreateXBookmark(SwDoc &rDoc, ::sw::mark::IMark *pBookmark)
Definition: unobkm.cxx:157
virtual ::sfx2::Metadatable * GetCoreObject() override
Definition: unobkm.cxx:379
void attachToRangeEx(const css::uno::Reference< css::text::XTextRange > &xTextRange, IDocumentMarkAccess::MarkType eType, bool isFieldmarkSeparatorAtStart=false)
Definition: unobkm.cxx:207
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unobkm.cxx:395
virtual OUString SAL_CALL getImplementationName() override
Definition: unobkm.cxx:358
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:267
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unobkm.cxx:369
IDocumentMarkAccess * GetIDocumentMarkAccess()
Definition: unobkm.cxx:133
virtual void SAL_CALL dispose() override
Definition: unobkm.cxx:293
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
Definition: unobkm.cxx:278
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: unobkm.cxx:272
::sw::mark::IMark const * GetBookmarkInDoc(SwDoc const *const pDoc, const css::uno::Reference< css::lang::XUnoTunnel > &xUT)
Definition: unobkm.cxx:184
::sw::mark::IMark * GetBookmark() const
Definition: unobkm.cxx:128
::sw::UnoImplPtr< Impl > m_pImpl
Definition: unobookmark.hxx:57
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
Definition: unobkm.cxx:363
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: unobkm.cxx:451
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
Definition: unobkm.cxx:515
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unobkm.cxx:573
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: unobkm.cxx:549
virtual void Notify(const SfxHint &rHint) override
Definition: unobkm.cxx:584
virtual void SAL_CALL insertByName(const OUString &aName, const css::uno::Any &aElement) override
Definition: unobkm.cxx:523
virtual sal_Bool SAL_CALL hasElements() override
Definition: unobkm.cxx:578
virtual void SAL_CALL removeByName(const OUString &Name) override
Definition: unobkm.cxx:532
::sw::mark::IFieldmark::parameter_map_t * getCoreParameters()
Definition: unobkm.cxx:590
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
Definition: unobkm.cxx:539
::sw::mark::IFieldmark * m_pFieldmark
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unobkm.cxx:559
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: unobkm.cxx:566
::sw::mark::ICheckboxFieldmark * getCheckboxFieldmark()
Definition: unobkm.cxx:723
virtual OUString SAL_CALL getPresentation(sal_Bool bShowCommand) override
Definition: unobkm.cxx:840
rtl::Reference< SwXTextRange > GetResult(::sw::mark::IFieldmark const &rMark)
Definition: unobkm.cxx:830
virtual OUString SAL_CALL getImplementationName() override
Definition: unobkm.cxx:604
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: unobkm.cxx:797
rtl::Reference< SwXTextRange > GetCommand(::sw::mark::IFieldmark const &rMark)
Definition: unobkm.cxx:821
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
Definition: unobkm.cxx:815
bool m_isFieldmarkSeparatorAtStart
static rtl::Reference< SwXBookmark > CreateXFieldmark(SwDoc &rDoc, ::sw::mark::IMark *pMark, bool isReplacementObject=false)
Definition: unobkm.cxx:689
bool const m_bReplacementObject
SwXFieldmark(bool isReplacementObject, SwDoc *pDoc)
Definition: unobkm.cxx:597
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unobkm.cxx:610
virtual void attachToRange(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: unobkm.cxx:627
virtual css::uno::Reference< css::container::XNameContainer > SAL_CALL getParameters() override
Definition: unobkm.cxx:679
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: unobkm.cxx:767
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unobkm.cxx:782
virtual void SAL_CALL setFieldType(const OUString &description) override
Definition: unobkm.cxx:644
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: unobkm.cxx:740
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: unobkm.cxx:802
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: unobkm.cxx:809
virtual void SAL_CALL dispose() override
Definition: unobkm.cxx:793
virtual OUString SAL_CALL getFieldType() override
Definition: unobkm.cxx:635
const SwDoc & GetDoc() const
Definition: unoobj2.cxx:764
static rtl::Reference< SwXTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1210
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
const css::uno::Sequence< sal_Int8 > & getSeq() const
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:1100
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:1103
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:37
void AdjustContent(sal_Int32 nDelta)
Adjust content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:261
SwDoc & GetDoc() const
Returns the document this position is in.
Definition: pam.cxx:217
unsigned char sal_Bool
ResultType type
cppu::ImplInheritanceHelper< SwXBookmark, css::text::XFormField, css::text::XTextField > SwXFieldmark_Base
SwUnoPropertyMapProvider aSwMapProvider
Definition: unomap1.cxx:87
#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:477
constexpr OUStringLiteral UNO_NAME_BOOKMARK_CONDITION
Definition: unoprnms.hxx:361
constexpr OUStringLiteral UNO_NAME_BOOKMARK_HIDDEN
Definition: unoprnms.hxx:360