LibreOffice Module sw (master) 1
attrlinebreak.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 <formatlinebreak.hxx>
21
22#include <libxml/xmlwriter.h>
23
24#include <vcl/svapp.hxx>
25
26#include <hintids.hxx>
27#include <pam.hxx>
28#include <textlinebreak.hxx>
29#include <ndtxt.hxx>
30#include <unotextrange.hxx>
31#include <unolinebreak.hxx>
32
33using namespace com::sun::star;
34
37 , sw::BroadcastingModify()
38 , m_pTextAttr(nullptr)
39{
40}
41
43
45{
46 m_wXLineBreak = xLineBreak.get();
47}
48
50{
51 assert(SfxPoolItem::operator==(rAttr));
52 return GetValue() == static_cast<const SwFormatLineBreak&>(rAttr).GetValue();
53}
54
56{
57 return new SwFormatLineBreak(GetValue());
58}
59
61{
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())
67 {
68 SetXLineBreak(nullptr);
69 }
70}
71
73{
74 return static_cast<sal_uInt16>(SwLineBreakClear::LAST) + 1;
75}
76
77uno::Reference<text::XTextRange> SwFormatLineBreak::GetAnchor() const
78{
79 SolarMutexGuard aGuard;
80
81 if (!m_pTextAttr)
82 {
83 return uno::Reference<text::XTextRange>();
84 }
85
87 aPam.SetMark();
88 ++aPam.GetMark()->nContent;
89 uno::Reference<text::XTextRange> xRet
90 = SwXTextRange::CreateXTextRange(aPam.GetDoc(), *aPam.Start(), aPam.End());
91 return xRet;
92}
93
95{
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);
101
102 SfxPoolItem::dumpAsXml(pWriter);
103
104 (void)xmlTextWriterEndElement(pWriter);
105}
106
108 : SwTextAttr(rAttr, nStartPos)
109 , m_pTextNode(nullptr)
110{
111 rAttr.SetTextLineBreak(this);
112 SetHasDummyChar(true);
113}
114
116
118{
119 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextLineBreak"));
120 if (m_pTextNode)
121 {
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);
127 }
128
129 SwTextAttr::dumpAsXml(pWriter);
130 (void)xmlTextWriterEndElement(pWriter);
131}
132
134
136{
137 assert(m_pTextNode);
138 return *m_pTextNode;
139}
140
141/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
virtual sal_uInt16 GetEnumValue() const override
SfxHintId GetId() const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
SfxPoolItem subclass that wraps an SwLineBreakClear.
bool operator==(const SfxPoolItem &) const override
See SfxPoolItem::operator ==().
void dumpAsXml(xmlTextWriterPtr pWriter) const override
SwFormatLineBreak(const SwFormatLineBreak &)=delete
void SetXLineBreak(rtl::Reference< SwXLineBreak > const &xLineBreak)
css::uno::Reference< css::text::XTextRange > GetAnchor() const
virtual ~SwFormatLineBreak() override
SwTextLineBreak * m_pTextAttr
The SwTextAttr that knows the position of the line break in the doc model.
void SwClientNotify(const SwModify &, const SfxHint &) override
See SwModify::SwClientNotify().
SwFormatLineBreak * Clone(SfxItemPool *pPool=nullptr) const override
See SfxPoolItem::Clone().
unotools::WeakReference< SwXLineBreak > m_wXLineBreak
void SetTextLineBreak(SwTextLineBreak *pTextAttr)
sal_uInt16 GetValueCount() const override
SwNodeOffset GetIndex() const
Definition: node.hxx:296
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:183
const SwPosition * GetMark() const
Definition: pam.hxx:259
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:595
const SwPosition * End() const
Definition: pam.hxx:267
SwDoc & GetDoc() const
Definition: pam.hxx:295
const SwPosition * Start() const
Definition: pam.hxx:262
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: txatbase.cxx:89
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:78
~SwTextLineBreak() override
SwTextNode * m_pTextNode
void SetTextNode(SwTextNode *pNew)
SwTextLineBreak(SwFormatLineBreak &rAttr, sal_Int32 nStart)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
const SwTextNode & GetTextNode() const
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:86
static css::uno::Reference< css::text::XTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1212
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:325
SwLineBreakClear
Defines the location of a line break text wrapping restart.
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(181)
constexpr TypedWhichId< SwFormatLineBreak > RES_TXTATR_LINEBREAK(61)
Dialog to specify the properties of date form field.
SwContentIndex nContent
Definition: pam.hxx:39