diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-02-28 10:59:49 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-03-25 13:41:45 +0100 |
commit | 864e9258ce61842091d7b37ee0a7b1d54b906289 (patch) | |
tree | 61cd8827ac272bff032a14a54f25d4db4b1a3e07 | |
parent | 4d2d9cf9c3165e2460466cc75e5a8453346610c8 (diff) |
sw clearing breaks: add document model
This is meant to represent clearing breaks, as in HTML's <br
clear="..."> and DOCX's <w:br w:type="textWrapping" w:clear="...">.
The new pool item is in the RES_TXTATR_NOEND section as this property
can be only specified on a single document model position: linebreak
characters.
(cherry picked from commit 24732bb12bfe0124d49733701226a34044c001a8)
Change-Id: I6c86097a049e489e1292f42fc8446eb7282c816a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132105
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | sw/Library_sw.mk | 1 | ||||
-rw-r--r-- | sw/inc/formatlinebreak.hxx | 96 | ||||
-rw-r--r-- | sw/inc/hintids.hxx | 3 | ||||
-rw-r--r-- | sw/inc/textlinebreak.hxx | 45 | ||||
-rw-r--r-- | sw/inc/txatbase.hxx | 8 | ||||
-rw-r--r-- | sw/source/core/bastyp/init.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/doc/dbgoutsw.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/txtnode/attrlinebreak.cxx | 118 | ||||
-rw-r--r-- | sw/source/core/txtnode/thints.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/txtnode/txatbase.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/html/css1atr.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/html/htmlatr.cxx | 2 |
12 files changed, 284 insertions, 6 deletions
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 70385f964c9b..0f594e203f59 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -425,6 +425,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/core/txtnode/atrftn \ sw/source/core/txtnode/atrref \ sw/source/core/txtnode/atrtox \ + sw/source/core/txtnode/attrlinebreak \ sw/source/core/txtnode/chrfmt \ sw/source/core/txtnode/fmtatr2 \ sw/source/core/txtnode/fntcache \ diff --git a/sw/inc/formatlinebreak.hxx b/sw/inc/formatlinebreak.hxx new file mode 100644 index 000000000000..9e26ab11351f --- /dev/null +++ b/sw/inc/formatlinebreak.hxx @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_SW_INC_FORMATLINEBREAK_HXX +#define INCLUDED_SW_INC_FORMATLINEBREAK_HXX + +#include "swdllapi.h" +#include <svl/eitem.hxx> +#include "calbck.hxx" + +#include <rtl/ustring.hxx> +#include <cppuhelper/weakref.hxx> +#include <com/sun/star/text/XTextContent.hpp> + +class SwDoc; +class SwTextLineBreak; + +/// Defines the location of a line break text wrapping restart. +enum class SwLineBreakClear +{ + NONE, + LEFT, + RIGHT, + ALL, + LAST = ALL +}; + +/// SfxPoolItem subclass that wraps an SwLineBreakClear. +class SW_DLLPUBLIC SwFormatLineBreak final : public SfxEnumItem<SwLineBreakClear>, + public sw::BroadcastingModify +{ + /// The SwTextAttr that knows the position of the line break in the doc model. + SwTextLineBreak* m_pTextAttr; + + css::uno::WeakReference<css::text::XTextContent> m_wXLineBreak; + + SwFormatLineBreak& operator=(const SwFormatLineBreak& rLineBreak) = delete; + + SwFormatLineBreak(const SwFormatLineBreak&) = delete; + +public: + SwFormatLineBreak(SwLineBreakClear eClear); + virtual ~SwFormatLineBreak() override; + + /// See SfxPoolItem::operator ==(). + bool operator==(const SfxPoolItem&) const override; + + /// See SfxPoolItem::Clone(). + SwFormatLineBreak* Clone(SfxItemPool* pPool = nullptr) const override; + + /// See SwModify::SwClientNotify(). + void SwClientNotify(const SwModify&, const SfxHint&) override; + + sal_uInt16 GetValueCount() const override; + + void InvalidateLineBreak(); + + css::uno::Reference<css::text::XTextRange> getAnchor(SwDoc& rDoc) const; + + void SetTextLineBreak(SwTextLineBreak* pTextAttr) { m_pTextAttr = pTextAttr; } + + const SwTextLineBreak* GetTextLineBreak() const { return m_pTextAttr; } + + SwTextLineBreak* GetTextLineBreak() { return m_pTextAttr; } + + css::uno::WeakReference<css::text::XTextContent> const& GetXTextContent() const + { + return m_wXLineBreak; + } + + void SetXLineBreak(css::uno::Reference<css::text::XTextContent> const& xLineBreak) + { + m_wXLineBreak = xLineBreak; + } + + void dumpAsXml(xmlTextWriterPtr pWriter) const override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx index 1642c094ca27..f446d6ab306b 100644 --- a/sw/inc/hintids.hxx +++ b/sw/inc/hintids.hxx @@ -150,6 +150,7 @@ class SwDrawFrameFormat; class SwFlyFrameFormat; class SwFormatField; class SwFormatFootnote; +class SwFormatLineBreak; class SwFormatRefMark; class SwGrfFormatColl; class SwTextFormatColl; @@ -282,7 +283,7 @@ constexpr TypedWhichId<SwFormatField> RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN); constexpr TypedWhichId<SwFormatFlyCnt> RES_TXTATR_FLYCNT(57); constexpr TypedWhichId<SwFormatFootnote> RES_TXTATR_FTN(58); constexpr TypedWhichId<SwFormatField> RES_TXTATR_ANNOTATION(59); -constexpr TypedWhichId<SfxBoolItem> RES_TXTATR_DUMMY3(60); +constexpr TypedWhichId<SwFormatLineBreak> RES_TXTATR_LINEBREAK(60); constexpr TypedWhichId<SfxBoolItem> RES_TXTATR_DUMMY1(61); constexpr TypedWhichId<SfxBoolItem> RES_TXTATR_DUMMY2(62); constexpr sal_uInt16 RES_TXTATR_NOEND_END(63); diff --git a/sw/inc/textlinebreak.hxx b/sw/inc/textlinebreak.hxx new file mode 100644 index 000000000000..c0853aa2bd56 --- /dev/null +++ b/sw/inc/textlinebreak.hxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_SW_INC_TEXTLINEBREAK_HXX +#define INCLUDED_SW_INC_TEXTLINEBREAK_HXX + +#include "txatbase.hxx" + +#include "ndindex.hxx" + +class SwFormatLineBreak; + +/** + * SwTextAttr subclass that tracks the location of the wrapped SwFormatLineBreak. + * + * This text attribute doesn't have an end: it's specified on a new line character of an SwTextNode. + */ +class SW_DLLPUBLIC SwTextLineBreak final : public SwTextAttr +{ +public: + SwTextLineBreak(SwFormatLineBreak& rAttr, sal_Int32 nStart); + + ~SwTextLineBreak() override; + + void dumpAsXml(xmlTextWriterPtr pWriter) const override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/txatbase.hxx b/sw/inc/txatbase.hxx index 8018712eaa23..110e12064c9c 100644 --- a/sw/inc/txatbase.hxx +++ b/sw/inc/txatbase.hxx @@ -28,6 +28,7 @@ #include "fmtfld.hxx" #include "fmtflcnt.hxx" #include "fmtftn.hxx" +#include "formatlinebreak.hxx" #include "fchrfmt.hxx" #include "tox.hxx" #include "ndhints.hxx" @@ -119,6 +120,7 @@ public: inline const SwFormatAutoFormat &GetAutoFormat() const; inline const SwFormatField &GetFormatField() const; inline const SwFormatFootnote &GetFootnote() const; + inline const SwFormatLineBreak& GetLineBreak() const; inline const SwFormatFlyCnt &GetFlyCnt() const; inline const SwTOXMark &GetTOXMark() const; inline const SwFormatRefMark &GetRefMark() const; @@ -207,6 +209,12 @@ inline const SwFormatFootnote& SwTextAttr::GetFootnote() const return static_cast<const SwFormatFootnote&>(*m_pAttr); } +inline const SwFormatLineBreak& SwTextAttr::GetLineBreak() const +{ + assert(m_pAttr && m_pAttr->Which() == RES_TXTATR_LINEBREAK); + return static_cast<const SwFormatLineBreak&>(*m_pAttr); +} + inline const SwFormatFlyCnt& SwTextAttr::GetFlyCnt() const { assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT ); diff --git a/sw/source/core/bastyp/init.cxx b/sw/source/core/bastyp/init.cxx index 8a82d99fc4b2..b6703dcd1d0d 100644 --- a/sw/source/core/bastyp/init.cxx +++ b/sw/source/core/bastyp/init.cxx @@ -93,6 +93,7 @@ #include <fmtfsize.hxx> #include <fmtftn.hxx> #include <fmtftntx.hxx> +#include <formatlinebreak.hxx> #include <fmthdft.hxx> #include <fmtinfmt.hxx> #include <fmtline.hxx> @@ -318,7 +319,7 @@ SfxItemInfo aSlotTab[] = { 0, false }, // RES_TXTATR_FLYCNT { 0, false }, // RES_TXTATR_FTN { 0, false }, // RES_TXTATR_ANNOTATION - { 0, true }, // RES_TXTATR_DUMMY3 + { 0, true }, // RES_TXTATR_LINEBREAK { 0, true }, // RES_TXTATR_DUMMY1 { 0, true }, // RES_TXTATR_DUMMY2 @@ -516,11 +517,11 @@ void InitCore() aAttrTab[ RES_TXTATR_FLYCNT - POOLATTR_BEGIN ] = new SwFormatFlyCnt( nullptr ); aAttrTab[ RES_TXTATR_FTN - POOLATTR_BEGIN ] = new SwFormatFootnote; aAttrTab[ RES_TXTATR_ANNOTATION - POOLATTR_BEGIN ] = new SwFormatField( RES_TXTATR_ANNOTATION ); + aAttrTab[RES_TXTATR_LINEBREAK - POOLATTR_BEGIN] = new SwFormatLineBreak(SwLineBreakClear::NONE); // TextAttr - Dummies aAttrTab[ RES_TXTATR_DUMMY1 - POOLATTR_BEGIN ] = new SfxBoolItem( RES_TXTATR_DUMMY1 ); aAttrTab[ RES_TXTATR_DUMMY2 - POOLATTR_BEGIN ] = new SfxBoolItem( RES_TXTATR_DUMMY2 ); - aAttrTab[ RES_TXTATR_DUMMY3 - POOLATTR_BEGIN ] = new SfxBoolItem( RES_TXTATR_DUMMY3 ); aAttrTab[ RES_PARATR_LINESPACING- POOLATTR_BEGIN ] = new SvxLineSpacingItem( LINE_SPACE_DEFAULT_HEIGHT, RES_PARATR_LINESPACING ); aAttrTab[ RES_PARATR_ADJUST- POOLATTR_BEGIN ] = new SvxAdjustItem( SvxAdjust::Left, RES_PARATR_ADJUST ); diff --git a/sw/source/core/doc/dbgoutsw.cxx b/sw/source/core/doc/dbgoutsw.cxx index d86f7612184d..0d294863dbed 100644 --- a/sw/source/core/doc/dbgoutsw.cxx +++ b/sw/source/core/doc/dbgoutsw.cxx @@ -147,7 +147,7 @@ static std::map<sal_uInt16,OUString> & GetItemWhichMap() { RES_TXTATR_FLYCNT , "TXTATR_FLYCNT" }, { RES_TXTATR_FTN , "TXTATR_FTN" }, { RES_TXTATR_ANNOTATION , "TXTATR_ANNOTATION" }, - { RES_TXTATR_DUMMY3 , "TXTATR_DUMMY3" }, + { RES_TXTATR_LINEBREAK , "RES_TXTATR_LINEBREAK" }, { RES_TXTATR_DUMMY1 , "TXTATR_DUMMY1" }, { RES_TXTATR_DUMMY2 , "TXTATR_DUMMY2" }, { RES_PARATR_LINESPACING , "PARATR_LINESPACING" }, diff --git a/sw/source/core/txtnode/attrlinebreak.cxx b/sw/source/core/txtnode/attrlinebreak.cxx new file mode 100644 index 000000000000..64aedd9d2be1 --- /dev/null +++ b/sw/source/core/txtnode/attrlinebreak.cxx @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <formatlinebreak.hxx> + +#include <libxml/xmlwriter.h> + +#include <vcl/svapp.hxx> + +#include <hintids.hxx> +#include <hints.hxx> +#include <pam.hxx> +#include <textlinebreak.hxx> + +using namespace com::sun::star; + +SwFormatLineBreak::SwFormatLineBreak(SwLineBreakClear eClear) + : SfxEnumItem(RES_TXTATR_LINEBREAK, eClear) + , sw::BroadcastingModify() + , m_pTextAttr(nullptr) +{ +} + +SwFormatLineBreak::~SwFormatLineBreak() {} + +bool SwFormatLineBreak::operator==(const SfxPoolItem& rAttr) const +{ + assert(SfxPoolItem::operator==(rAttr)); + return GetValue() == static_cast<const SwFormatLineBreak&>(rAttr).GetValue(); +} + +SwFormatLineBreak* SwFormatLineBreak::Clone(SfxItemPool*) const +{ + return new SwFormatLineBreak(GetValue()); +} + +void SwFormatLineBreak::SwClientNotify(const SwModify&, const SfxHint& rHint) +{ + if (rHint.GetId() != SfxHintId::SwLegacyModify) + return; + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + CallSwClientNotify(rHint); + if (RES_REMOVE_UNO_OBJECT == pLegacy->GetWhich()) + { + SetXLineBreak(css::uno::Reference<css::text::XTextContent>(nullptr)); + } +} + +sal_uInt16 SwFormatLineBreak::GetValueCount() const +{ + return static_cast<sal_uInt16>(SwLineBreakClear::LAST) + 1; +} + +void SwFormatLineBreak::InvalidateLineBreak() +{ + SwPtrMsgPoolItem const aItem(RES_REMOVE_UNO_OBJECT, + &static_cast<sw::BroadcastingModify&>(*this)); + CallSwClientNotify(sw::LegacyModifyHint(&aItem, &aItem)); +} + +uno::Reference<text::XTextRange> SwFormatLineBreak::getAnchor(SwDoc& /*rDoc*/) const +{ + SolarMutexGuard aGuard; + + SAL_WARN("sw.core", "SwFormatLineBreak::getAnchor: not implemented"); + if (!m_pTextAttr) + { + return uno::Reference<text::XTextRange>(); + } + + return {}; +} + +void SwFormatLineBreak::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatLineBreak")); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), + BAD_CAST(OString::number(GetEnumValue()).getStr())); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("m_pTextAttr"), "%p", m_pTextAttr); + + SfxPoolItem::dumpAsXml(pWriter); + + (void)xmlTextWriterEndElement(pWriter); +} + +SwTextLineBreak::SwTextLineBreak(SwFormatLineBreak& rAttr, sal_Int32 nStartPos) + : SwTextAttr(rAttr, nStartPos) +{ + rAttr.SetTextLineBreak(this); +} + +SwTextLineBreak::~SwTextLineBreak() {} + +void SwTextLineBreak::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextLineBreak")); + SwTextAttr::dumpAsXml(pWriter); + (void)xmlTextWriterEndElement(pWriter); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index c7418514d31e..bdf954d27e40 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -43,6 +43,7 @@ #include <txttxmrk.hxx> #include <txtrfmrk.hxx> #include <txtftn.hxx> +#include <textlinebreak.hxx> #include <txtfld.hxx> #include <txtannotationfld.hxx> #include <unotools/fltrcfg.hxx> @@ -1140,6 +1141,9 @@ SwTextAttr* MakeTextAttr( pNew = SwTextMeta::CreateTextMeta( rDoc.GetMetaFieldManager(), pTextNode, static_cast<SwFormatMeta&>(rNew), nStt, nEnd, bIsCopy == CopyOrNewType::Copy ); break; + case RES_TXTATR_LINEBREAK: + pNew = new SwTextLineBreak(static_cast<SwFormatLineBreak&>(rNew), nStt); + break; default: assert(RES_TXTATR_AUTOFMT == rNew.Which()); pNew = new SwTextAttrEnd( rNew, nStt, nEnd ); diff --git a/sw/source/core/txtnode/txatbase.cxx b/sw/source/core/txtnode/txatbase.cxx index c5c0736306fd..2d9546059424 100644 --- a/sw/source/core/txtnode/txatbase.cxx +++ b/sw/source/core/txtnode/txatbase.cxx @@ -97,6 +97,7 @@ void SwTextAttr::dumpAsXml(xmlTextWriterPtr pWriter) const if (End()) (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr())); (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr())); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("m_pAttr"), "%p", m_pAttr); const char* pWhich = nullptr; std::optional<OString> oValue; switch (Which()) @@ -159,6 +160,9 @@ void SwTextAttr::dumpAsXml(xmlTextWriterPtr pWriter) const break; case RES_TXTATR_FTN: break; + case RES_TXTATR_LINEBREAK: + GetLineBreak().dumpAsXml(pWriter); + break; default: SAL_WARN("sw.core", "Unhandled TXTATR"); break; diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx index de952e8552d8..882d7678ef55 100644 --- a/sw/source/filter/html/css1atr.cxx +++ b/sw/source/filter/html/css1atr.cxx @@ -3478,7 +3478,7 @@ SwAttrFnTab const aCSS1AttrFnTab = { /* RES_TXTATR_FLYCNT */ nullptr, /* RES_TXTATR_FTN */ nullptr, /* RES_TXTATR_ANNOTATION */ nullptr, -/* RES_TXTATR_DUMMY3 */ nullptr, +/* RES_TXTATR_LINEBREAK */ nullptr, /* RES_TXTATR_DUMMY1 */ nullptr, // Dummy: /* RES_TXTATR_DUMMY2 */ nullptr, // Dummy: diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index a78c5e272d56..41e5fad5c193 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -3269,7 +3269,7 @@ SwAttrFnTab aHTMLAttrFnTab = { /* RES_TXTATR_FLYCNT */ OutHTML_SwFlyCnt, /* RES_TXTATR_FTN */ OutHTML_SwFormatFootnote, /* RES_TXTATR_ANNOTATION */ OutHTML_SwFormatField, -/* RES_TXTATR_DUMMY3 */ nullptr, +/* RES_TXTATR_LINEBREAK */ nullptr, /* RES_TXTATR_DUMMY1 */ nullptr, // Dummy: /* RES_TXTATR_DUMMY2 */ nullptr, // Dummy: |