Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / txtnode / attrlinebreak.cxx
blob1c5c7882ee314610a17139154fb6356eec1ef50d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <pam.hxx>
28 #include <textlinebreak.hxx>
29 #include <ndtxt.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)
63 return;
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;
81 if (!m_pTextAttr)
83 return uno::Reference<text::XTextRange>();
86 SwPaM aPam(m_pTextAttr->GetTextNode(), m_pTextAttr->GetStart());
87 aPam.SetMark();
88 aPam.GetMark()->AdjustContent(+1);
89 uno::Reference<text::XTextRange> xRet
90 = SwXTextRange::CreateXTextRange(aPam.GetDoc(), *aPam.Start(), aPam.End());
91 return xRet;
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"));
120 if (m_pTextNode)
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
137 assert(m_pTextNode);
138 return *m_pTextNode;
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */