/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace com::sun::star; /// The inner part SwXLineBreak, which is deleted with a locked SolarMutex. class SwXLineBreak::Impl : public SvtListener { public: bool m_bIsDescriptor; SwFormatLineBreak* m_pFormatLineBreak; SwLineBreakClear m_eClear; Impl(SwFormatLineBreak* const pLineBreak) : m_bIsDescriptor(pLineBreak == nullptr) , m_pFormatLineBreak(pLineBreak) , m_eClear(SwLineBreakClear::NONE) { if (m_pFormatLineBreak) { StartListening(m_pFormatLineBreak->GetNotifier()); } } const SwFormatLineBreak* GetLineBreakFormat() const; const SwFormatLineBreak& GetLineBreakFormatOrThrow() const; void Invalidate(); protected: void Notify(const SfxHint& rHint) override; }; const SwFormatLineBreak* SwXLineBreak::Impl::GetLineBreakFormat() const { return m_pFormatLineBreak; } const SwFormatLineBreak& SwXLineBreak::Impl::GetLineBreakFormatOrThrow() const { const SwFormatLineBreak* pLineBreak(GetLineBreakFormat()); if (!pLineBreak) { throw uno::RuntimeException("SwXLineBreak: disposed or invalid", nullptr); } return *pLineBreak; } void SwXLineBreak::Impl::Invalidate() { EndListeningAll(); m_pFormatLineBreak = nullptr; } void SwXLineBreak::Impl::Notify(const SfxHint& rHint) { if (rHint.GetId() == SfxHintId::Dying) { Invalidate(); } } SwXLineBreak::SwXLineBreak(SwFormatLineBreak& rFormat) : m_pImpl(new SwXLineBreak::Impl(&rFormat)) { } SwXLineBreak::SwXLineBreak() : m_pImpl(new SwXLineBreak::Impl(nullptr)) { } SwXLineBreak::~SwXLineBreak() {} rtl::Reference SwXLineBreak::CreateXLineBreak(SwFormatLineBreak* pLineBreakFormat) { rtl::Reference xLineBreak; if (pLineBreakFormat) { xLineBreak = pLineBreakFormat->GetXTextContent(); } if (!xLineBreak.is()) { xLineBreak = pLineBreakFormat ? new SwXLineBreak(*pLineBreakFormat) : new SwXLineBreak; if (pLineBreakFormat) { pLineBreakFormat->SetXLineBreak(xLineBreak); } } return xLineBreak; } OUString SAL_CALL SwXLineBreak::getImplementationName() { return "SwXLineBreak"; } sal_Bool SAL_CALL SwXLineBreak::supportsService(const OUString& rServiceName) { return cppu::supportsService(this, rServiceName); } uno::Sequence SAL_CALL SwXLineBreak::getSupportedServiceNames() { return { "com.sun.star.text.LineBreak" }; } void SAL_CALL SwXLineBreak::attach(const uno::Reference& xTextRange) { SolarMutexGuard aGuard; if (!m_pImpl->m_bIsDescriptor) { throw uno::RuntimeException(); } auto pRange = dynamic_cast(xTextRange.get()); if (!pRange) { throw lang::IllegalArgumentException(); } SwDoc& rNewDoc = pRange->GetDoc(); SwUnoInternalPaM aPam(rNewDoc); sw::XTextRangeToSwPaM(aPam, xTextRange); UnoActionContext aContext(&rNewDoc); SwFormatLineBreak aLineBreak(m_pImpl->m_eClear); SetAttrMode nInsertFlags = SetAttrMode::DEFAULT; rNewDoc.getIDocumentContentOperations().InsertPoolItem(aPam, aLineBreak, nInsertFlags); auto pTextAttr = static_cast(aPam.GetPointNode().GetTextNode()->GetTextAttrForCharAt( aPam.GetPoint()->GetContentIndex() - 1, RES_TXTATR_LINEBREAK)); if (pTextAttr) { m_pImpl->EndListeningAll(); auto pLineBreak = const_cast(&pTextAttr->GetLineBreak()); m_pImpl->m_pFormatLineBreak = pLineBreak; m_pImpl->StartListening(pLineBreak->GetNotifier()); } m_pImpl->m_bIsDescriptor = false; } uno::Reference SAL_CALL SwXLineBreak::getAnchor() { SolarMutexGuard aGuard; return m_pImpl->GetLineBreakFormatOrThrow().GetAnchor(); } void SAL_CALL SwXLineBreak::dispose() { SAL_WARN("sw.uno", "SwXLineBreak::dispose: not implemented"); } void SAL_CALL SwXLineBreak::addEventListener(const uno::Reference& /*xListener*/) { } void SAL_CALL SwXLineBreak::removeEventListener(const uno::Reference& /*xListener*/) { } uno::Reference SAL_CALL SwXLineBreak::getPropertySetInfo() { SolarMutexGuard aGuard; static uno::Reference xRet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINEBREAK)->getPropertySetInfo(); return xRet; } void SAL_CALL SwXLineBreak::setPropertyValue(const OUString& rPropertyName, const css::uno::Any& rValue) { SolarMutexGuard aGuard; if (rPropertyName != UNO_NAME_CLEAR) { throw lang::IllegalArgumentException(); } if (m_pImpl->m_bIsDescriptor) { sal_Int16 eValue{}; if (rValue >>= eValue) { m_pImpl->m_eClear = static_cast(eValue); } } else { m_pImpl->m_pFormatLineBreak->PutValue(rValue, 0); } } uno::Any SAL_CALL SwXLineBreak::getPropertyValue(const OUString& rPropertyName) { SolarMutexGuard aGuard; uno::Any aRet; if (sw::GetDefaultTextContentValue(aRet, rPropertyName)) { return aRet; } if (rPropertyName != UNO_NAME_CLEAR) { throw beans::UnknownPropertyException(rPropertyName); } if (m_pImpl->m_bIsDescriptor) { auto eValue = static_cast(m_pImpl->m_eClear); aRet <<= eValue; } else { aRet <<= m_pImpl->m_pFormatLineBreak->GetEnumValue(); } return aRet; } void SAL_CALL SwXLineBreak::addPropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference& /*xListener*/) { SAL_WARN("sw.uno", "SwXLineBreak::addPropertyChangeListener: not implemented"); } void SAL_CALL SwXLineBreak::removePropertyChangeListener( const OUString& /*rPropertyName*/, const uno::Reference& /*xListener*/) { SAL_WARN("sw.uno", "SwXLineBreak::removePropertyChangeListener: not implemented"); } void SAL_CALL SwXLineBreak::addVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference& /*xListener*/) { SAL_WARN("sw.uno", "SwXLineBreak::addVetoableChangeListener: not implemented"); } void SAL_CALL SwXLineBreak::removeVetoableChangeListener( const OUString& /*rPropertyName*/, const uno::Reference& /*xListener*/) { SAL_WARN("sw.uno", "SwXLineBreak::removeVetoableChangeListener: not implemented"); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */