1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <formatlinebreak.hxx>
22 #include <libxml/xmlwriter.h>
24 #include <vcl/svapp.hxx>
26 #include <hintids.hxx>
28 #include <textlinebreak.hxx>
30 #include <unotextrange.hxx>
31 #include <unolinebreak.hxx>
33 using namespace com::sun::star
;
35 SwFormatLineBreak::SwFormatLineBreak(SwLineBreakClear eClear
)
36 : SfxEnumItem(RES_TXTATR_LINEBREAK
, eClear
)
37 , sw::BroadcastingModify()
38 , m_pTextAttr(nullptr)
42 SwFormatLineBreak::~SwFormatLineBreak() {}
44 void SwFormatLineBreak::SetXLineBreak(rtl::Reference
<SwXLineBreak
> const& xLineBreak
)
46 m_wXLineBreak
= xLineBreak
.get();
49 bool SwFormatLineBreak::operator==(const SfxPoolItem
& rAttr
) const
51 assert(SfxPoolItem::operator==(rAttr
));
52 return GetValue() == static_cast<const SwFormatLineBreak
&>(rAttr
).GetValue();
55 SwFormatLineBreak
* SwFormatLineBreak::Clone(SfxItemPool
*) const
57 return new SwFormatLineBreak(GetValue());
60 void SwFormatLineBreak::SwClientNotify(const SwModify
&, const SfxHint
& rHint
)
62 if (rHint
.GetId() != SfxHintId::SwLegacyModify
)
64 auto pLegacy
= static_cast<const sw::LegacyModifyHint
*>(&rHint
);
65 CallSwClientNotify(rHint
);
66 if (RES_REMOVE_UNO_OBJECT
== pLegacy
->GetWhich())
68 SetXLineBreak(nullptr);
72 sal_uInt16
SwFormatLineBreak::GetValueCount() const
74 return static_cast<sal_uInt16
>(SwLineBreakClear::LAST
) + 1;
77 uno::Reference
<text::XTextRange
> SwFormatLineBreak::GetAnchor() const
79 SolarMutexGuard aGuard
;
83 return uno::Reference
<text::XTextRange
>();
86 SwPaM
aPam(m_pTextAttr
->GetTextNode(), m_pTextAttr
->GetStart());
88 aPam
.GetMark()->AdjustContent(+1);
89 uno::Reference
<text::XTextRange
> xRet
90 = SwXTextRange::CreateXTextRange(aPam
.GetDoc(), *aPam
.Start(), aPam
.End());
94 void SwFormatLineBreak::dumpAsXml(xmlTextWriterPtr pWriter
) const
96 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwFormatLineBreak"));
97 (void)xmlTextWriterWriteFormatAttribute(pWriter
, BAD_CAST("ptr"), "%p", this);
98 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("value"),
99 BAD_CAST(OString::number(GetEnumValue()).getStr()));
100 (void)xmlTextWriterWriteFormatAttribute(pWriter
, BAD_CAST("m_pTextAttr"), "%p", m_pTextAttr
);
102 SfxPoolItem::dumpAsXml(pWriter
);
104 (void)xmlTextWriterEndElement(pWriter
);
107 SwTextLineBreak::SwTextLineBreak(SwFormatLineBreak
& rAttr
, sal_Int32 nStartPos
)
108 : SwTextAttr(rAttr
, nStartPos
)
109 , m_pTextNode(nullptr)
111 rAttr
.SetTextLineBreak(this);
112 SetHasDummyChar(true);
115 SwTextLineBreak::~SwTextLineBreak() {}
117 void SwTextLineBreak::dumpAsXml(xmlTextWriterPtr pWriter
) const
119 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwTextLineBreak"));
122 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("m_pTextNode"));
123 (void)xmlTextWriterWriteAttribute(
124 pWriter
, BAD_CAST("index"),
125 BAD_CAST(OString::number(sal_Int32(m_pTextNode
->GetIndex())).getStr()));
126 (void)xmlTextWriterEndElement(pWriter
);
129 SwTextAttr::dumpAsXml(pWriter
);
130 (void)xmlTextWriterEndElement(pWriter
);
133 void SwTextLineBreak::SetTextNode(SwTextNode
* pNew
) { m_pTextNode
= pNew
; }
135 const SwTextNode
& SwTextLineBreak::GetTextNode() const
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */