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 <cppuhelper/weakref.hxx>
25 #include <sal/log.hxx>
26 #include <svl/listener.hxx>
27 #include <svl/itemprop.hxx>
28 
30 #include <doc.hxx>
31 #include <formatlinebreak.hxx>
32 #include <unotextrange.hxx>
33 #include <ndtxt.hxx>
34 #include <textlinebreak.hxx>
35 #include <unomap.hxx>
36 #include <unoprnms.hxx>
37 
38 using namespace com::sun::star;
39 
42 {
43 public:
47 
48  Impl(SwFormatLineBreak* const pLineBreak)
49  : m_bIsDescriptor(pLineBreak == nullptr)
50  , m_pFormatLineBreak(pLineBreak)
51  , m_eClear(SwLineBreakClear::NONE)
52  {
53  if (m_pFormatLineBreak)
54  {
55  StartListening(m_pFormatLineBreak->GetNotifier());
56  }
57  }
58 
59  const SwFormatLineBreak* GetLineBreakFormat() const;
60 
61  const SwFormatLineBreak& GetLineBreakFormatOrThrow() const;
62 
63  void Invalidate();
64 
65 protected:
66  void Notify(const SfxHint& rHint) override;
67 };
68 
70 {
71  return m_pFormatLineBreak;
72 }
73 
75 {
76  const SwFormatLineBreak* pLineBreak(GetLineBreakFormat());
77  if (!pLineBreak)
78  {
79  throw uno::RuntimeException("SwXLineBreak: disposed or invalid", nullptr);
80  }
81 
82  return *pLineBreak;
83 }
84 
86 {
87  EndListeningAll();
88  m_pFormatLineBreak = nullptr;
89 }
90 
92 {
93  if (rHint.GetId() == SfxHintId::Dying)
94  {
95  Invalidate();
96  }
97 }
98 
100  : m_pImpl(new SwXLineBreak::Impl(&rFormat))
101 {
102 }
103 
105  : m_pImpl(new SwXLineBreak::Impl(nullptr))
106 {
107 }
108 
110 
111 uno::Reference<text::XTextContent>
113 {
114  uno::Reference<text::XTextContent> xLineBreak;
115  if (pLineBreakFormat)
116  {
117  xLineBreak = pLineBreakFormat->GetXTextContent();
118  }
119  if (!xLineBreak.is())
120  {
121  SwXLineBreak* const pLineBreak(pLineBreakFormat ? new SwXLineBreak(*pLineBreakFormat)
122  : new SwXLineBreak);
123  xLineBreak.set(pLineBreak);
124  if (pLineBreakFormat)
125  {
126  pLineBreakFormat->SetXLineBreak(xLineBreak);
127  }
128  }
129  return xLineBreak;
130 }
131 
132 OUString SAL_CALL SwXLineBreak::getImplementationName() { return "SwXLineBreak"; }
133 
134 sal_Bool SAL_CALL SwXLineBreak::supportsService(const OUString& rServiceName)
135 {
136  return cppu::supportsService(this, rServiceName);
137 }
138 
139 uno::Sequence<OUString> SAL_CALL SwXLineBreak::getSupportedServiceNames()
140 {
141  return { "com.sun.star.text.LineBreak" };
142 }
143 
144 void SAL_CALL SwXLineBreak::attach(const uno::Reference<text::XTextRange>& xTextRange)
145 {
146  SolarMutexGuard aGuard;
147  if (!m_pImpl->m_bIsDescriptor)
148  {
149  throw uno::RuntimeException();
150  }
151 
152  auto pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
153  if (!pRange)
154  {
155  throw lang::IllegalArgumentException();
156  }
157 
158  SwDoc& rNewDoc = pRange->GetDoc();
159  SwUnoInternalPaM aPam(rNewDoc);
160  sw::XTextRangeToSwPaM(aPam, xTextRange);
161  UnoActionContext aContext(&rNewDoc);
162  SwFormatLineBreak aLineBreak(m_pImpl->m_eClear);
163  SetAttrMode nInsertFlags = SetAttrMode::DEFAULT;
164  rNewDoc.getIDocumentContentOperations().InsertPoolItem(aPam, aLineBreak, nInsertFlags);
165  auto pTextAttr
166  = static_cast<SwTextLineBreak*>(aPam.GetNode().GetTextNode()->GetTextAttrForCharAt(
168  if (pTextAttr)
169  {
170  m_pImpl->EndListeningAll();
171  auto pLineBreak = const_cast<SwFormatLineBreak*>(&pTextAttr->GetLineBreak());
172  m_pImpl->m_pFormatLineBreak = pLineBreak;
173  m_pImpl->StartListening(pLineBreak->GetNotifier());
174  }
175  m_pImpl->m_bIsDescriptor = false;
176 }
177 
178 uno::Reference<text::XTextRange> SAL_CALL SwXLineBreak::getAnchor()
179 {
180  SolarMutexGuard aGuard;
181 
182  return m_pImpl->GetLineBreakFormatOrThrow().GetAnchor();
183 }
184 
185 void SAL_CALL SwXLineBreak::dispose()
186 {
187  SAL_WARN("sw.uno", "SwXLineBreak::dispose: not implemented");
188 }
189 
190 void SAL_CALL
191 SwXLineBreak::addEventListener(const uno::Reference<lang::XEventListener>& /*xListener*/)
192 {
193 }
194 
195 void SAL_CALL
196 SwXLineBreak::removeEventListener(const uno::Reference<lang::XEventListener>& /*xListener*/)
197 {
198 }
199 
200 uno::Reference<beans::XPropertySetInfo> SAL_CALL SwXLineBreak::getPropertySetInfo()
201 {
202  SolarMutexGuard aGuard;
203 
204  static uno::Reference<beans::XPropertySetInfo> xRet
206  return xRet;
207 }
208 
209 void SAL_CALL SwXLineBreak::setPropertyValue(const OUString& rPropertyName,
210  const css::uno::Any& rValue)
211 {
212  SolarMutexGuard aGuard;
213 
214  if (rPropertyName != UNO_NAME_CLEAR)
215  {
216  throw lang::IllegalArgumentException();
217  }
218 
219  if (m_pImpl->m_bIsDescriptor)
220  {
221  sal_Int16 eValue{};
222  if (rValue >>= eValue)
223  {
224  m_pImpl->m_eClear = static_cast<SwLineBreakClear>(eValue);
225  }
226  }
227  else
228  {
229  m_pImpl->m_pFormatLineBreak->PutValue(rValue, 0);
230  }
231 }
232 
233 uno::Any SAL_CALL SwXLineBreak::getPropertyValue(const OUString& rPropertyName)
234 {
235  SolarMutexGuard aGuard;
236 
237  uno::Any aRet;
238  if (sw::GetDefaultTextContentValue(aRet, rPropertyName))
239  {
240  return aRet;
241  }
242 
243  if (rPropertyName != UNO_NAME_CLEAR)
244  {
245  beans::UnknownPropertyException aExcept;
246  aExcept.Message = rPropertyName;
247  throw aExcept;
248  }
249 
250  if (m_pImpl->m_bIsDescriptor)
251  {
252  auto eValue = static_cast<sal_Int16>(m_pImpl->m_eClear);
253  aRet <<= eValue;
254  }
255  else
256  {
257  aRet <<= m_pImpl->m_pFormatLineBreak->GetEnumValue();
258  }
259  return aRet;
260 }
261 
263  const OUString& /*rPropertyName*/,
264  const uno::Reference<beans::XPropertyChangeListener>& /*xListener*/)
265 {
266  SAL_WARN("sw.uno", "SwXLineBreak::addPropertyChangeListener: not implemented");
267 }
268 
270  const OUString& /*rPropertyName*/,
271  const uno::Reference<beans::XPropertyChangeListener>& /*xListener*/)
272 {
273  SAL_WARN("sw.uno", "SwXLineBreak::removePropertyChangeListener: not implemented");
274 }
275 
277  const OUString& /*rPropertyName*/,
278  const uno::Reference<beans::XVetoableChangeListener>& /*xListener*/)
279 {
280  SAL_WARN("sw.uno", "SwXLineBreak::addVetoableChangeListener: not implemented");
281 }
282 
284  const OUString& /*rPropertyName*/,
285  const uno::Reference<beans::XVetoableChangeListener>& /*xListener*/)
286 {
287  SAL_WARN("sw.uno", "SwXLineBreak::removeVetoableChangeListener: not implemented");
288 }
289 
290 sal_Int64 SAL_CALL SwXLineBreak::getSomething(const css::uno::Sequence<sal_Int8>& rIdentifier)
291 {
292  return comphelper::getSomethingImpl<SwXLineBreak>(rIdentifier, this);
293 }
294 
295 const uno::Sequence<sal_Int8>& SwXLineBreak::getUnoTunnelId()
296 {
297  static const comphelper::UnoIdInit theSwXLineBreakUnoTunnelId;
298  return theSwXLineBreakUnoTunnelId.getSeq();
299 }
300 
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:224
css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
void Notify(SwFlyFrame *pFly, SwPageFrame *pOld, const SwRect &rOld, const SwRect *pOldRect=nullptr)
Notify the background based on the difference between old and new rectangle.
Definition: frmtool.cxx:3242
#define UNO_NAME_CLEAR
Definition: unoprnms.hxx:873
SwLineBreakClear
Defines the location of a line break text wrapping restart.
#define PROPERTY_MAP_LINEBREAK
Definition: unomap.hxx:128
The inner part SwXLineBreak, which is deleted with a locked SolarMutex.
css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
const SfxItemPropertySet * GetPropertySet(sal_uInt16 PropertyId)
Definition: unomap1.cxx:1099
Definition: doc.hxx:187
css::uno::WeakReference< css::text::XTextContent > const & GetXTextContent() const
~SwXLineBreak() override
virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr, SwTextAttr **ppNewTextAttr=nullptr)=0
Insert an attribute.
sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
SfxHintId GetId() const
::sw::UnoImplPtr< Impl > m_pImpl
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:3069
NONE
SwIndex nContent
Definition: pam.hxx:39
sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rIdentifier) override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const css::uno::Sequence< sal_Int8 > & getSeq() const
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
bool GetDefaultTextContentValue(css::uno::Any &rAny, std::u16string_view rPropertyName, sal_uInt16 nWID=0)
SfxPoolItem subclass that wraps an SwLineBreakClear.
const SwFormatLineBreak & GetLineBreakFormatOrThrow() const
const SwPosition * GetPoint() const
Definition: pam.hxx:208
void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
SetAttrMode
Definition: swtypes.hxx:132
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
constexpr TypedWhichId< SwFormatLineBreak > RES_TXTATR_LINEBREAK(61)
unsigned char sal_Bool
SwTextAttr subclass that tracks the location of the wrapped SwFormatLineBreak.
void SetXLineBreak(css::uno::Reference< css::text::XTextContent > const &xLineBreak)
void SAL_CALL dispose() override
bool XTextRangeToSwPaM(SwUnoInternalPaM &rToFill, const uno::Reference< text::XTextRange > &xTextRange,::sw::TextRangeMode const eMode)
Definition: unoobj2.cxx:1107
UNO API wrapper around an SwFormatLineBreak, exposed as the com.sun.star.text.LineBreak service...
SvtBroadcaster & GetNotifier()
Definition: calbck.hxx:101
SwFormatLineBreak * m_pFormatLineBreak
void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
sal_Int32 GetIndex() const
Definition: index.hxx:91
void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
SwUnoPropertyMapProvider aSwMapProvider
Definition: unomap1.cxx:87
static css::uno::Reference< css::text::XTextContent > CreateXLineBreak(SwFormatLineBreak *pLineBreakFormat)
void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
void Notify(const SfxHint &rHint) override
Impl(SwFormatLineBreak *const pLineBreak)
#define SAL_WARN(area, stream)
void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
OUString SAL_CALL getImplementationName() override
SwLineBreakClear m_eClear
const SwFormatLineBreak * GetLineBreakFormat() const
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:864