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
24#include <sal/log.hxx>
25#include <svl/listener.hxx>
26#include <svl/itemprop.hxx>
27
29#include <doc.hxx>
30#include <formatlinebreak.hxx>
31#include <unotextrange.hxx>
32#include <ndtxt.hxx>
33#include <textlinebreak.hxx>
34#include <unomap.hxx>
35#include <unoprnms.hxx>
36
37using namespace com::sun::star;
38
41{
42public:
46
47 Impl(SwFormatLineBreak* const pLineBreak)
48 : m_bIsDescriptor(pLineBreak == nullptr)
49 , m_pFormatLineBreak(pLineBreak)
51 {
53 {
54 StartListening(m_pFormatLineBreak->GetNotifier());
55 }
56 }
57
59
61
62 void Invalidate();
63
64protected:
65 void Notify(const SfxHint& rHint) override;
66};
67
69{
70 return m_pFormatLineBreak;
71}
72
74{
75 const SwFormatLineBreak* pLineBreak(GetLineBreakFormat());
76 if (!pLineBreak)
77 {
78 throw uno::RuntimeException("SwXLineBreak: disposed or invalid", nullptr);
79 }
80
81 return *pLineBreak;
82}
83
85{
86 EndListeningAll();
87 m_pFormatLineBreak = nullptr;
88}
89
91{
92 if (rHint.GetId() == SfxHintId::Dying)
93 {
94 Invalidate();
95 }
96}
97
99 : m_pImpl(new SwXLineBreak::Impl(&rFormat))
100{
101}
102
104 : m_pImpl(new SwXLineBreak::Impl(nullptr))
105{
106}
107
109
111{
113 if (pLineBreakFormat)
114 {
115 xLineBreak = pLineBreakFormat->GetXTextContent();
116 }
117 if (!xLineBreak.is())
118 {
119 xLineBreak = pLineBreakFormat ? new SwXLineBreak(*pLineBreakFormat) : new SwXLineBreak;
120 if (pLineBreakFormat)
121 {
122 pLineBreakFormat->SetXLineBreak(xLineBreak);
123 }
124 }
125 return xLineBreak;
126}
127
128OUString SAL_CALL SwXLineBreak::getImplementationName() { return "SwXLineBreak"; }
129
130sal_Bool SAL_CALL SwXLineBreak::supportsService(const OUString& rServiceName)
131{
132 return cppu::supportsService(this, rServiceName);
133}
134
135uno::Sequence<OUString> SAL_CALL SwXLineBreak::getSupportedServiceNames()
136{
137 return { "com.sun.star.text.LineBreak" };
138}
139
140void SAL_CALL SwXLineBreak::attach(const uno::Reference<text::XTextRange>& xTextRange)
141{
142 SolarMutexGuard aGuard;
143 if (!m_pImpl->m_bIsDescriptor)
144 {
145 throw uno::RuntimeException();
146 }
147
148 auto pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
149 if (!pRange)
150 {
151 throw lang::IllegalArgumentException();
152 }
153
154 SwDoc& rNewDoc = pRange->GetDoc();
155 SwUnoInternalPaM aPam(rNewDoc);
156 sw::XTextRangeToSwPaM(aPam, xTextRange);
157 UnoActionContext aContext(&rNewDoc);
158 SwFormatLineBreak aLineBreak(m_pImpl->m_eClear);
159 SetAttrMode nInsertFlags = SetAttrMode::DEFAULT;
160 rNewDoc.getIDocumentContentOperations().InsertPoolItem(aPam, aLineBreak, nInsertFlags);
161 auto pTextAttr
164 if (pTextAttr)
165 {
166 m_pImpl->EndListeningAll();
167 auto pLineBreak = const_cast<SwFormatLineBreak*>(&pTextAttr->GetLineBreak());
168 m_pImpl->m_pFormatLineBreak = pLineBreak;
169 m_pImpl->StartListening(pLineBreak->GetNotifier());
170 }
171 m_pImpl->m_bIsDescriptor = false;
172}
173
174uno::Reference<text::XTextRange> SAL_CALL SwXLineBreak::getAnchor()
175{
176 SolarMutexGuard aGuard;
177
178 return m_pImpl->GetLineBreakFormatOrThrow().GetAnchor();
179}
180
182{
183 SAL_WARN("sw.uno", "SwXLineBreak::dispose: not implemented");
184}
185
186void SAL_CALL
187SwXLineBreak::addEventListener(const uno::Reference<lang::XEventListener>& /*xListener*/)
188{
189}
190
191void SAL_CALL
192SwXLineBreak::removeEventListener(const uno::Reference<lang::XEventListener>& /*xListener*/)
193{
194}
195
196uno::Reference<beans::XPropertySetInfo> SAL_CALL SwXLineBreak::getPropertySetInfo()
197{
198 SolarMutexGuard aGuard;
199
200 static uno::Reference<beans::XPropertySetInfo> xRet
202 return xRet;
203}
204
205void SAL_CALL SwXLineBreak::setPropertyValue(const OUString& rPropertyName,
206 const css::uno::Any& rValue)
207{
208 SolarMutexGuard aGuard;
209
210 if (rPropertyName != UNO_NAME_CLEAR)
211 {
212 throw lang::IllegalArgumentException();
213 }
214
215 if (m_pImpl->m_bIsDescriptor)
216 {
217 sal_Int16 eValue{};
218 if (rValue >>= eValue)
219 {
220 m_pImpl->m_eClear = static_cast<SwLineBreakClear>(eValue);
221 }
222 }
223 else
224 {
225 m_pImpl->m_pFormatLineBreak->PutValue(rValue, 0);
226 }
227}
228
229uno::Any SAL_CALL SwXLineBreak::getPropertyValue(const OUString& rPropertyName)
230{
231 SolarMutexGuard aGuard;
232
233 uno::Any aRet;
234 if (sw::GetDefaultTextContentValue(aRet, rPropertyName))
235 {
236 return aRet;
237 }
238
239 if (rPropertyName != UNO_NAME_CLEAR)
240 {
241 beans::UnknownPropertyException aExcept;
242 aExcept.Message = rPropertyName;
243 throw aExcept;
244 }
245
246 if (m_pImpl->m_bIsDescriptor)
247 {
248 auto eValue = static_cast<sal_Int16>(m_pImpl->m_eClear);
249 aRet <<= eValue;
250 }
251 else
252 {
253 aRet <<= m_pImpl->m_pFormatLineBreak->GetEnumValue();
254 }
255 return aRet;
256}
257
259 const OUString& /*rPropertyName*/,
260 const uno::Reference<beans::XPropertyChangeListener>& /*xListener*/)
261{
262 SAL_WARN("sw.uno", "SwXLineBreak::addPropertyChangeListener: not implemented");
263}
264
266 const OUString& /*rPropertyName*/,
267 const uno::Reference<beans::XPropertyChangeListener>& /*xListener*/)
268{
269 SAL_WARN("sw.uno", "SwXLineBreak::removePropertyChangeListener: not implemented");
270}
271
273 const OUString& /*rPropertyName*/,
274 const uno::Reference<beans::XVetoableChangeListener>& /*xListener*/)
275{
276 SAL_WARN("sw.uno", "SwXLineBreak::addVetoableChangeListener: not implemented");
277}
278
280 const OUString& /*rPropertyName*/,
281 const uno::Reference<beans::XVetoableChangeListener>& /*xListener*/)
282{
283 SAL_WARN("sw.uno", "SwXLineBreak::removeVetoableChangeListener: not implemented");
284}
285
286/* 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:195
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:323
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:897
SwNode & GetPointNode() const
Definition: pam.hxx:283
const SwPosition * GetPoint() const
Definition: pam.hxx:261
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:3153
const SfxItemPropertySet * GetPropertySet(sal_uInt16 PropertyId)
Definition: unomap1.cxx:1081
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:1090
bool GetDefaultTextContentValue(css::uno::Any &rAny, std::u16string_view rPropertyName, sal_uInt16 nWID=0)
sal_Int32 GetContentIndex() const
Definition: pam.hxx:84
SetAttrMode
Definition: swtypes.hxx:133
unsigned char sal_Bool
SwUnoPropertyMapProvider aSwMapProvider
Definition: unomap1.cxx:87
#define PROPERTY_MAP_LINEBREAK
Definition: unomap.hxx:129
constexpr OUStringLiteral UNO_NAME_CLEAR
Definition: unoprnms.hxx:898