Add a comment to clarify what kind of inputs the class handles
[LibreOffice.git] / sw / source / core / txtnode / attrlinebreak.cxx
blobaf9f94848656381ec03668ce488bbce03d58cde7
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 , m_pTextAttr(nullptr)
39 setNonShareable();
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 sal_uInt16 SwFormatLineBreak::GetValueCount() const
62 return static_cast<sal_uInt16>(SwLineBreakClear::LAST) + 1;
65 rtl::Reference<SwXTextRange> SwFormatLineBreak::GetAnchor() const
67 SolarMutexGuard aGuard;
69 if (!m_pTextAttr)
70 return {};
72 SwPaM aPam(m_pTextAttr->GetTextNode(), m_pTextAttr->GetStart());
73 aPam.SetMark();
74 aPam.GetMark()->AdjustContent(+1);
75 rtl::Reference<SwXTextRange> xRet
76 = SwXTextRange::CreateXTextRange(aPam.GetDoc(), *aPam.Start(), aPam.End());
77 return xRet;
80 void SwFormatLineBreak::dumpAsXml(xmlTextWriterPtr pWriter) const
82 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatLineBreak"));
83 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
84 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
85 BAD_CAST(OString::number(GetEnumValue()).getStr()));
86 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("m_pTextAttr"), "%p", m_pTextAttr);
88 SfxPoolItem::dumpAsXml(pWriter);
90 (void)xmlTextWriterEndElement(pWriter);
93 SwTextLineBreak::SwTextLineBreak(const SfxPoolItemHolder& rAttr, sal_Int32 nStartPos)
94 : SwTextAttr(rAttr, nStartPos)
95 , m_pTextNode(nullptr)
97 SwFormatLineBreak& rSwFormatLineBreak(static_cast<SwFormatLineBreak&>(GetAttr()));
98 rSwFormatLineBreak.SetTextLineBreak(this);
99 SetHasDummyChar(true);
102 SwTextLineBreak::~SwTextLineBreak() {}
104 void SwTextLineBreak::dumpAsXml(xmlTextWriterPtr pWriter) const
106 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextLineBreak"));
107 if (m_pTextNode)
109 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_pTextNode"));
110 (void)xmlTextWriterWriteAttribute(
111 pWriter, BAD_CAST("index"),
112 BAD_CAST(OString::number(sal_Int32(m_pTextNode->GetIndex())).getStr()));
113 (void)xmlTextWriterEndElement(pWriter);
116 SwTextAttr::dumpAsXml(pWriter);
117 (void)xmlTextWriterEndElement(pWriter);
120 void SwTextLineBreak::SetTextNode(SwTextNode* pNew) { m_pTextNode = pNew; }
122 const SwTextNode& SwTextLineBreak::GetTextNode() const
124 assert(m_pTextNode);
125 return *m_pTextNode;
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */