34 #include <unoprnms.hxx>
47 uno::WeakReference<uno::XInterface>
m_wThis;
58 , m_pRegisteredBookmark(nullptr)
72 if(rHint.
GetId() == SfxHintId::Dying)
76 uno::Reference<uno::XInterface>
const xThis(
m_wThis);
81 lang::EventObject
const ev(xThis);
82 std::unique_lock aGuard(
m_Mutex);
90 const uno::Reference<text::XTextContent> xBookmark(&rThis);
96 OSL_ENSURE(pMarkBase,
"registerInMark: no MarkBase?");
99 pMarkBase->SetXBookmark(xBookmark);
104 else if (m_pRegisteredBookmark)
106 m_sMarkName = m_pRegisteredBookmark->GetName();
109 IBookmark* pBookmark =
dynamic_cast<IBookmark*
>(m_pRegisteredBookmark);
112 m_bHidden = pBookmark->IsHidden();
113 m_HideCondition = pBookmark->GetHideCondition();
117 m_pRegisteredBookmark = pBkmk;
125 m_pImpl->registerInMark( rThis, pBkmk );
130 return m_pImpl->m_pRegisteredBookmark;
135 return m_pImpl->m_pDoc->getIDocumentMarkAccess();
163 OSL_ENSURE(!pBookmark || pMarkBase,
"CreateXBookmark: no MarkBase?");
164 uno::Reference<text::XTextContent> xBookmark;
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.");
178 xBookmark.set(pXBookmark);
179 pXBookmark->
m_pImpl->registerInMark(*pXBookmark, pMarkBase);
185 const uno::Reference< lang::XUnoTunnel> & xUT)
188 comphelper::getFromUnoTunnel<SwXBookmark>(xUT));
189 if (pXBkm && (pDoc == pXBkm->
m_pImpl->m_pDoc))
191 return pXBkm->
m_pImpl->m_pRegisteredBookmark;
199 return theSwXBookmarkUnoTunnelId.
getSeq();
204 return comphelper::getSomethingImpl<SwXBookmark>(rId,
this);
208 const uno::Reference< text::XTextRange > & xTextRange,
211 if (
m_pImpl->m_pRegisteredBookmark)
213 throw uno::RuntimeException();
216 const uno::Reference<lang::XUnoTunnel> xRangeTunnel(
217 xTextRange, uno::UNO_QUERY);
218 SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
220 comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel);
223 pRange ? &pRange->
GetDoc() : (pCursor ? pCursor->GetDoc() :
nullptr);
226 throw lang::IllegalArgumentException();
233 if (
m_pImpl->m_sMarkName.isEmpty())
235 m_pImpl->m_sMarkName =
"Bookmark";
249 m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark(
255 if (!
m_pImpl->m_pRegisteredBookmark)
257 OSL_FAIL(
"<SwXBookmark::attachToRange(..)>"
258 " - could not create Mark.");
259 throw lang::IllegalArgumentException();
278 if (!
m_pImpl->m_pRegisteredBookmark)
280 throw uno::RuntimeException();
284 m_pImpl->m_pRegisteredBookmark->GetMarkPos(),
285 (
m_pImpl->m_pRegisteredBookmark->IsExpanded())
286 ? &
m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos() :
nullptr);
292 if (
m_pImpl->m_pRegisteredBookmark)
294 m_pImpl->m_pDoc->getIDocumentMarkAccess()->deleteMark(
m_pImpl->m_pRegisteredBookmark );
299 const uno::Reference< lang::XEventListener > & xListener)
302 std::unique_lock aGuard(
m_pImpl->m_Mutex);
303 m_pImpl->m_EventListeners.addInterface(aGuard, xListener);
307 const uno::Reference< lang::XEventListener > & xListener)
310 std::unique_lock aGuard(
m_pImpl->m_Mutex);
311 m_pImpl->m_EventListeners.removeInterface(aGuard, xListener);
318 return (
m_pImpl->m_pRegisteredBookmark)
319 ?
m_pImpl->m_pRegisteredBookmark->GetName()
327 if (!
m_pImpl->m_pRegisteredBookmark)
336 m_pImpl->m_pDoc->getIDocumentMarkAccess();
339 throw uno::RuntimeException(
"setName(): name already in use",
340 static_cast<::cppu::OWeakObject*>(
this));
343 SwPaM aPam(
m_pImpl->m_pRegisteredBookmark->GetMarkPos());
344 if (
m_pImpl->m_pRegisteredBookmark->IsExpanded())
347 *aPam.GetMark() =
m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos();
356 return "SwXBookmark";
364 uno::Sequence< OUString > SAL_CALL
368 "com.sun.star.text.TextContent",
369 "com.sun.star.text.Bookmark",
370 "com.sun.star.document.LinkTarget"
385 return pShell ? pShell->
GetModel() :
nullptr;
390 uno::Reference< beans::XPropertySetInfo > SAL_CALL
395 static uno::Reference< beans::XPropertySetInfo > xRef(
407 bool bNewValue =
false;
408 if (!(rValue >>= bNewValue))
409 throw lang::IllegalArgumentException(
"Property BookmarkHidden requires value of type boolean",
nullptr, 0);
411 IBookmark* pBookmark =
dynamic_cast<IBookmark*
>(
m_pImpl->m_pRegisteredBookmark);
414 pBookmark->Hide(bNewValue);
418 m_pImpl->m_bHidden = bNewValue;
425 if (!(rValue >>= newValue))
426 throw lang::IllegalArgumentException(
"Property BookmarkCondition requires value of type string",
nullptr, 0);
428 IBookmark* pBookmark =
dynamic_cast<IBookmark*
>(
m_pImpl->m_pRegisteredBookmark);
431 pBookmark->SetHideCondition(newValue);
435 m_pImpl->m_HideCondition = newValue;
441 throw lang::IllegalArgumentException(
"Property is read-only: "
442 + PropertyName, static_cast< cppu::OWeakObject * >(
this), 0 );
458 IBookmark* pBookmark =
dynamic_cast<IBookmark*
>(
m_pImpl->m_pRegisteredBookmark);
461 aRet <<= pBookmark->IsHidden();
470 IBookmark* pBookmark =
dynamic_cast<IBookmark*
>(
m_pImpl->m_pRegisteredBookmark);
473 aRet <<= pBookmark->GetHideCondition();
477 aRet <<=
m_pImpl->m_HideCondition;
487 const uno::Reference< beans::XPropertyChangeListener >& )
489 OSL_FAIL(
"SwXBookmark::addPropertyChangeListener(): not implemented");
495 const uno::Reference< beans::XPropertyChangeListener >& )
497 OSL_FAIL(
"SwXBookmark::removePropertyChangeListener(): not implemented");
503 const uno::Reference< beans::XVetoableChangeListener >& )
505 OSL_FAIL(
"SwXBookmark::addVetoableChangeListener(): not implemented");
511 const uno::Reference< beans::XVetoableChangeListener >& )
513 OSL_FAIL(
"SwXBookmark::removeVetoableChangeListener(): not implemented");
521 if(pParameters->find(aName) != pParameters->end())
522 throw container::ElementExistException();
523 (*pParameters)[aName] = aElement;
530 throw container::NoSuchElementException();
537 IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName);
538 if(pEntry == pParameters->end())
539 throw container::NoSuchElementException();
540 pEntry->second = aElement;
547 IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName);
548 if(pEntry == pParameters->end())
549 throw container::NoSuchElementException();
550 return pEntry->second;
564 return (pParameters->find(aName) != pParameters->end());
580 if(rHint.
GetId() == SfxHintId::Dying)
587 throw uno::RuntimeException();
593 , m_bReplacementObject(isReplacementObject)
600 return "SwXFieldmark";
603 uno::Sequence<OUString> SAL_CALL
609 return {
"com.sun.star.text.TextContent",
610 "com.sun.star.text.Bookmark",
611 "com.sun.star.text.FormFieldmark"};
615 return {
"com.sun.star.text.TextContent",
616 "com.sun.star.text.Bookmark",
617 "com.sun.star.text.Fieldmark"};
624 attachToRangeEx( xTextRange,
631 const IFieldmark *pBkm =
dynamic_cast<const IFieldmark*
>(GetBookmark());
633 throw uno::RuntimeException();
634 return pBkm->GetFieldname();
640 IFieldmark *pBkm =
dynamic_cast<IFieldmark*
>(GetBookmark());
642 throw uno::RuntimeException();
645 if (fieldType == oldFieldType)
651 ::sw::mark::IFieldmark* pNewFieldmark = GetIDocumentMarkAccess()->changeFormFieldmarkType(pBkm, fieldType);
654 registerInMark(*
this, pNewFieldmark);
665 pBkm->SetFieldname(fieldType);
669 throw uno::RuntimeException(
"changing to that type isn't implemented");
675 IFieldmark *pBkm =
dynamic_cast<IFieldmark*
>(GetBookmark());
677 throw uno::RuntimeException();
681 uno::Reference<text::XTextContent>
683 bool const isReplacementObject)
687 dynamic_cast< ::sw::mark::MarkBase * >(pMark));
688 assert(!pMark || pMarkBase);
689 uno::Reference<text::XTextContent> xMark;
698 if (dynamic_cast< ::sw::mark::TextFieldmark* >(pMark))
700 else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(pMark))
702 else if (dynamic_cast< ::sw::mark::DropDownFieldmark* >(pMark))
704 else if (dynamic_cast< ::sw::mark::DateFieldmark* >(pMark))
709 xMark.set(static_cast<::cppu::OWeakObject*>(pXBkmk.get()), uno::UNO_QUERY);
710 pXBkmk->registerInMark(*pXBkmk, pMarkBase);
722 assert( GetBookmark() ==
nullptr || pCheckboxFm !=
nullptr );
737 if ( PropertyName ==
"Checked" )
740 bool bChecked(
false );
741 if ( !(pCheckboxFm && ( rValue >>= bChecked )) )
742 throw uno::RuntimeException();
755 if ( rPropertyName ==
"Checked" )
759 throw uno::RuntimeException();
766 uno::Reference<beans::XPropertySetInfo> SAL_CALL
771 static uno::Reference<beans::XPropertySetInfo>
const xRef(
783 uno::Reference<lang::XEventListener>
const& xListener)
788 uno::Reference<lang::XEventListener>
const& xListener)
795 uno::Reference<text::XTextRange>
const& xTextRange)
805 uno::Reference<text::XTextRange>
814 uno::Reference<text::XTextRange>
829 IFieldmark
const*
const pMark(dynamic_cast<IFieldmark*>(GetBookmark()));
832 throw lang::DisposedException();
843 uno::Reference<text::XTextRange>
const xCommand(
GetCommand(*pMark));
844 return xCommand->getString();
857 uno::Reference<text::XTextRange>
const xResult(
GetResult(*pMark));
858 return xResult->getString();
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
static bool IsLegalName(std::u16string_view rName)
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Marks a position in the document model.
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
SwXFieldmark(bool isReplacementObject, SwDoc *pDoc)
virtual css::uno::Type SAL_CALL getElementType() override
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
IDocumentMarkAccess * GetIDocumentMarkAccess()
Provides access to the marks of a document.
css::uno::Reference< css::frame::XModel3 > GetModel() const
const SfxItemPropertySet * GetPropertySet(sal_uInt16 PropertyId)
#define PROPERTY_MAP_BOOKMARK
::sw::mark::IMark * m_pRegisteredBookmark
virtual const SwPosition & GetMarkPos() const =0
constexpr OUStringLiteral ODF_FORMDATE
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
virtual css::uno::Reference< css::frame::XModel > GetModel() override
OUString ExpandFieldmark(IFieldmark *pBM)
virtual ::sfx2::Metadatable * GetCoreObject() override
::sw::mark::IFieldmark::parameter_map_t * getCoreParameters()
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual void SAL_CALL dispose() override
css::uno::Reference< css::text::XTextRange > GetCommand(::sw::mark::IFieldmark const &rMark)
void registerInMark(SwXBookmark &rThis,::sw::mark::IMark *const pBkmk)
static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark(const SwPaM &rPaM)
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
virtual void SAL_CALL removeByName(const OUString &Name) override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
static css::uno::Reference< css::text::XTextContent > CreateXFieldmark(SwDoc &rDoc,::sw::mark::IMark *pMark, bool isReplacementObject=false)
virtual OUString SAL_CALL getPresentation(sal_Bool bShowCommand) override
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual parameter_map_t * GetParameters()=0
#define UNO_NAME_BOOKMARK_HIDDEN
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
const css::uno::Sequence< sal_Int8 > & getSeq() const
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
PaM is Point and Mark: a selection of the document model.
static css::uno::Reference< css::text::XTextContent > CreateXBookmark(SwDoc &rDoc,::sw::mark::IMark *pBookmark)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool GetDefaultTextContentValue(css::uno::Any &rAny, std::u16string_view rPropertyName, sal_uInt16 nWID=0)
virtual bool IsChecked() const =0
virtual const_iterator_t getAllMarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of marks.
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
constexpr OUStringLiteral ODF_FORMTEXT
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
::comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_EventListeners
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL setFieldType(const OUString &description) override
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
bool XTextRangeToSwPaM(SwUnoInternalPaM &rToFill, const uno::Reference< text::XTextRange > &xTextRange,::sw::TextRangeMode const eMode)
::sw::mark::IMark * GetBookmark() const
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
uno::WeakReference< uno::XInterface > m_wThis
css::uno::Reference< css::text::XTextRange > GetResult(::sw::mark::IFieldmark const &rMark)
SvtBroadcaster & GetNotifier()
UNO API wrapper around an internal sw::mark::IMark.
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
virtual void Notify(const SfxHint &rHint) override
virtual void SAL_CALL insertByName(const OUString &aName, const css::uno::Any &aElement) override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
virtual sal_Bool SAL_CALL hasElements() override
void registerInMark(SwXBookmark &rXMark,::sw::mark::IMark *const pMarkBase)
virtual OUString SAL_CALL getFieldType() override
virtual void SAL_CALL setName(const OUString &rName) override
virtual css::uno::Reference< css::container::XNameContainer > SAL_CALL getParameters() override
static bool IsLegalName(std::u16string_view rName)
SwDoc & GetDoc() const
Returns the document this position is in.
constexpr OUStringLiteral ODF_UNHANDLED
virtual ~SwXBookmark() override
::sw::mark::ICheckboxFieldmark * getCheckboxFieldmark()
SwUnoPropertyMapProvider aSwMapProvider
::sw::mark::IMark const * GetBookmarkInDoc(SwDoc const *const pDoc, const css::uno::Reference< css::lang::XUnoTunnel > &xUT)
#define UNO_LINK_DISPLAY_NAME
virtual OUString SAL_CALL getImplementationName() override
#define UNO_NAME_BOOKMARK_CONDITION
virtual void attachToRange(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
void attachToRangeEx(const css::uno::Reference< css::text::XTextRange > &xTextRange, IDocumentMarkAccess::MarkType eType)
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rIdentifier) override
virtual bool renameMark(::sw::mark::IMark *io_pMark, const OUString &rNewName)=0
Renames an existing Mark, if possible.
bool const m_bReplacementObject
constexpr OUStringLiteral ODF_FORMCHECKBOX
virtual OUString SAL_CALL getName() override
virtual void attachToRange(const css::uno::Reference< css::text::XTextRange > &xTextRange)
const css::uno::WeakReference< css::text::XTextContent > & GetXBookmark() const
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
virtual void SAL_CALL dispose() override
#define PROPERTY_MAP_FIELDMARK
virtual void SetChecked(bool checked)=0
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
::sw::UnoImplPtr< Impl > m_pImpl
constexpr OUStringLiteral ODF_FORMDROPDOWN
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
::sw::mark::IFieldmark * m_pFieldmark
cppu::ImplInheritanceHelper< SwXBookmark, css::text::XFormField, css::text::XTextField > SwXFieldmark_Base
virtual void Notify(const SfxHint &) override
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
bool m_bDetectedRangeSegmentation false