LibreOffice Module sw (master) 1
unolinebreak.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 <unolinebreak.hxx>
21
23#include <sal/log.hxx>
24#include <svl/listener.hxx>
25#include <svl/itemprop.hxx>
26
28#include <doc.hxx>
29#include <formatlinebreak.hxx>
30#include <unotextrange.hxx>
31#include <ndtxt.hxx>
32#include <textlinebreak.hxx>
33#include <unomap.hxx>
34#include <unoprnms.hxx>
35
36using namespace com::sun::star;
37
40{
41public:
45
46 Impl(SwFormatLineBreak* const pLineBreak)
47 : m_bIsDescriptor(pLineBreak == nullptr)
48 , m_pFormatLineBreak(pLineBreak)
50 {
52 {
53 StartListening(m_pFormatLineBreak->GetNotifier());
54 }
55 }
56
58
60
61 void Invalidate();
62
63protected:
64 void Notify(const SfxHint& rHint) override;
65};
66
68{
69 return m_pFormatLineBreak;
70}
71
73{
74 const SwFormatLineBreak* pLineBreak(GetLineBreakFormat());
75 if (!pLineBreak)
76 {
77 throw uno::RuntimeException("SwXLineBreak: disposed or invalid", nullptr);
78 }
79
80 return *pLineBreak;
81}
82
84{
85 EndListeningAll();
86 m_pFormatLineBreak = nullptr;
87}
88
90{
91 if (rHint.GetId() == SfxHintId::Dying)
92 {
93 Invalidate();
94 }
95}
96
98 : m_pImpl(new SwXLineBreak::Impl(&rFormat))
99{
100}
101
103 : m_pImpl(new SwXLineBreak::Impl(nullptr))
104{
105}
106
108
110{
112 if (pLineBreakFormat)
113 {
114 xLineBreak = pLineBreakFormat->GetXTextContent();
115 }
116 if (!xLineBreak.is())
117 {
118 xLineBreak = pLineBreakFormat ? new SwXLineBreak(*pLineBreakFormat) : new SwXLineBreak;
119 if (pLineBreakFormat)
120 {
121 pLineBreakFormat->SetXLineBreak(xLineBreak);
122 }
123 }
124 return xLineBreak;
125}
126
127OUString SAL_CALL SwXLineBreak::getImplementationName() { return "SwXLineBreak"; }
128
129sal_Bool SAL_CALL SwXLineBreak::supportsService(const OUString& rServiceName)
130{
131 return cppu::supportsService(this, rServiceName);
132}
133
134uno::Sequence<OUString> SAL_CALL SwXLineBreak::getSupportedServiceNames()
135{
136 return { "com.sun.star.text.LineBreak" };
137}
138
139void SAL_CALL SwXLineBreak::attach(const uno::Reference<text::XTextRange>& xTextRange)
140{
141 SolarMutexGuard aGuard;
142 if (!m_pImpl->m_bIsDescriptor)
143 {
144 throw uno::RuntimeException();
145 }
146
147 auto pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
148 if (!pRange)
149 {
150 throw lang::IllegalArgumentException();
151 }
152
153 SwDoc& rNewDoc = pRange->GetDoc();
154 SwUnoInternalPaM aPam(rNewDoc);
155 sw::XTextRangeToSwPaM(aPam, xTextRange);
156 UnoActionContext aContext(&rNewDoc);
157 SwFormatLineBreak aLineBreak(m_pImpl->m_eClear);
158 SetAttrMode nInsertFlags = SetAttrMode::DEFAULT;
159 rNewDoc.getIDocumentContentOperations().InsertPoolItem(aPam, aLineBreak, nInsertFlags);
160 auto pTextAttr
163 if (pTextAttr)
164 {
165 m_pImpl->EndListeningAll();
166 auto pLineBreak = const_cast<SwFormatLineBreak*>(&pTextAttr->GetLineBreak());
167 m_pImpl->m_pFormatLineBreak = pLineBreak;
168 m_pImpl->StartListening(pLineBreak->GetNotifier());
169 }
170 m_pImpl->m_bIsDescriptor = false;
171}
172
173uno::Reference<text::XTextRange> SAL_CALL SwXLineBreak::getAnchor()
174{
175 SolarMutexGuard aGuard;
176
177 return m_pImpl->GetLineBreakFormatOrThrow().GetAnchor();
178}
179
181{
182 SAL_WARN("sw.uno", "SwXLineBreak::dispose: not implemented");
183}
184
185void SAL_CALL
186SwXLineBreak::addEventListener(const uno::Reference<lang::XEventListener>& /*xListener*/)
187{
188}
189
190void SAL_CALL
191SwXLineBreak::removeEventListener(const uno::Reference<lang::XEventListener>& /*xListener*/)
192{
193}
194
195uno::Reference<beans::XPropertySetInfo> SAL_CALL SwXLineBreak::getPropertySetInfo()
196{
197 SolarMutexGuard aGuard;
198
199 static uno::Reference<beans::XPropertySetInfo> xRet
201 return xRet;
202}
203
204void SAL_CALL SwXLineBreak::setPropertyValue(const OUString& rPropertyName,
205 const css::uno::Any& rValue)
206{
207 SolarMutexGuard aGuard;
208
209 if (rPropertyName != UNO_NAME_CLEAR)
210 {
211 throw lang::IllegalArgumentException();
212 }
213
214 if (m_pImpl->m_bIsDescriptor)
215 {
216 sal_Int16 eValue{};
217 if (rValue >>= eValue)
218 {
219 m_pImpl->m_eClear = static_cast<SwLineBreakClear>(eValue);
220 }
221 }
222 else
223 {
224 m_pImpl->m_pFormatLineBreak->PutValue(rValue, 0);
225 }
226}
227
228uno::Any SAL_CALL SwXLineBreak::getPropertyValue(const OUString& rPropertyName)
229{
230 SolarMutexGuard aGuard;
231
232 uno::Any aRet;
233 if (sw::GetDefaultTextContentValue(aRet, rPropertyName))
234 {
235 return aRet;
236 }
237
238 if (rPropertyName != UNO_NAME_CLEAR)
239 {
240 beans::UnknownPropertyException aExcept;
241 aExcept.Message = rPropertyName;
242 throw aExcept;
243 }
244
245 if (m_pImpl->m_bIsDescriptor)
246 {
247 auto eValue = static_cast<sal_Int16>(m_pImpl->m_eClear);
248 aRet <<= eValue;
249 }
250 else
251 {
252 aRet <<= m_pImpl->m_pFormatLineBreak->GetEnumValue();
253 }
254 return aRet;
255}
256
258 const OUString& /*rPropertyName*/,
259 const uno::Reference<beans::XPropertyChangeListener>& /*xListener*/)
260{
261 SAL_WARN("sw.uno", "SwXLineBreak::addPropertyChangeListener: not implemented");
262}
263
265 const OUString& /*rPropertyName*/,
266 const uno::Reference<beans::XPropertyChangeListener>& /*xListener*/)
267{
268 SAL_WARN("sw.uno", "SwXLineBreak::removePropertyChangeListener: not implemented");
269}
270
272 const OUString& /*rPropertyName*/,
273 const uno::Reference<beans::XVetoableChangeListener>& /*xListener*/)
274{
275 SAL_WARN("sw.uno", "SwXLineBreak::addVetoableChangeListener: not implemented");
276}
277
279 const OUString& /*rPropertyName*/,
280 const uno::Reference<beans::XVetoableChangeListener>& /*xListener*/)
281{
282 SAL_WARN("sw.uno", "SwXLineBreak::removeVetoableChangeListener: not implemented");
283}
284
285/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr, SwTextAttr **ppNewTextAttr=nullptr)=0
Insert an attribute.
SfxHintId GetId() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
bool StartListening(SvtBroadcaster &rBroadcaster)
Definition: doc.hxx:197
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:329
SfxPoolItem subclass that wraps an SwLineBreakClear.
void SetXLineBreak(rtl::Reference< SwXLineBreak > const &xLineBreak)
unotools::WeakReference< SwXLineBreak > const & GetXTextContent() const
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:901
SwNode & GetPointNode() const
Definition: pam.hxx:275
const SwPosition * GetPoint() const
Definition: pam.hxx:253
SwTextAttr subclass that tracks the location of the wrapped SwFormatLineBreak.
SwTextAttr * GetTextAttrForCharAt(const sal_Int32 nIndex, const sal_uInt16 nWhich=RES_TXTATR_END) const
get the text attribute at position nIndex which owns the dummy character CH_TXTATR_* at that position...
Definition: ndtxt.cxx:3155
const SfxItemPropertySet * GetPropertySet(sal_uInt16 PropertyId)
Definition: unomap1.cxx:1111
The inner part SwXLineBreak, which is deleted with a locked SolarMutex.
SwFormatLineBreak * m_pFormatLineBreak
Impl(SwFormatLineBreak *const pLineBreak)
void Notify(const SfxHint &rHint) override
SwLineBreakClear m_eClear
const SwFormatLineBreak & GetLineBreakFormatOrThrow() const
const SwFormatLineBreak * GetLineBreakFormat() const
UNO API wrapper around an SwFormatLineBreak, exposed as the com.sun.star.text.LineBreak service.
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
::sw::UnoImplPtr< Impl > m_pImpl
void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
~SwXLineBreak() override
static rtl::Reference< SwXLineBreak > CreateXLineBreak(SwFormatLineBreak *pLineBreakFormat)
void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
OUString SAL_CALL getImplementationName() override
void SAL_CALL dispose() override
SwLineBreakClear
Defines the location of a line break text wrapping restart.
constexpr TypedWhichId< SwFormatLineBreak > RES_TXTATR_LINEBREAK(61)
#define SAL_WARN(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
NONE
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)
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
SetAttrMode
Definition: swtypes.hxx:133
unsigned char sal_Bool
SwUnoPropertyMapProvider aSwMapProvider
Definition: unomap1.cxx:88
#define PROPERTY_MAP_LINEBREAK
Definition: unomap.hxx:129
constexpr OUStringLiteral UNO_NAME_CLEAR
Definition: unoprnms.hxx:915