LibreOffice Module sw (master) 1
txatbase.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 <optional>
21#include <libxml/xmlwriter.h>
22#include <svl/itempool.hxx>
23#include <txatbase.hxx>
24#include <fmtfld.hxx>
25
26SwTextAttr::SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart )
27 : m_pAttr( &rAttr )
28 , m_nStart( nStart )
29 , m_bDontExpand( false )
30 , m_bLockExpandFlag( false )
31 , m_bDontMoveAttr( false )
32 , m_bCharFormatAttr( false )
33 , m_bOverlapAllowedAttr( false )
34 , m_bPriorityAttr( false )
35 , m_bDontExpandStart( false )
36 , m_bNesting( false )
37 , m_bHasDummyChar( false )
38 , m_bFormatIgnoreStart(false)
39 , m_bFormatIgnoreEnd(false)
40 , m_bHasContent( false )
41{
42}
43
44SwTextAttr::~SwTextAttr() COVERITY_NOEXCEPT_FALSE
45{
46}
47
48const sal_Int32* SwTextAttr::GetEnd() const
49{
50 return nullptr;
51}
52
53void SwTextAttr::SetEnd(sal_Int32 )
54{
55 assert(false);
56}
57
58void SwTextAttr::Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool )
59{
60 if (!pToDestroy) return;
61 SfxPoolItem * const pAttr = pToDestroy->m_pAttr;
62 delete pToDestroy;
63 rPool.Remove( *pAttr );
64}
65
66bool SwTextAttr::operator==( const SwTextAttr& rAttr ) const
67{
68 return GetAttr() == rAttr.GetAttr();
69}
70
72 sal_Int32 nStart, sal_Int32 nEnd ) :
73 SwTextAttr( rAttr, nStart ), m_nEnd( nEnd )
74{
75}
76
77const sal_Int32* SwTextAttrEnd::GetEnd() const
78{
79 return & m_nEnd;
80}
81
82void SwTextAttrEnd::SetEnd(sal_Int32 n)
83{
84 m_nEnd = n;
85 if (m_pHints)
87}
88
90{
91 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextAttr"));
92 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
93 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s",
94 BAD_CAST(typeid(*this).name()));
95
96 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("start"), BAD_CAST(OString::number(m_nStart).getStr()));
97 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("dont-expand"),
98 BAD_CAST(OString::boolean(m_bDontExpand).getStr()));
99 if (End())
100 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr()));
101 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
102 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("m_pAttr"), "%p", m_pAttr);
103 const char* pWhich = nullptr;
104 std::optional<OString> oValue;
105 switch (Which())
106 {
108 pWhich = "autofmt";
109 break;
111 pWhich = "annotation";
112 break;
114 pWhich = "fly content";
115 break;
117 {
118 pWhich = "character format";
119 if (SwCharFormat* pCharFormat = GetCharFormat().GetCharFormat())
120 oValue = OString("name: " + OUStringToOString(pCharFormat->GetName(), RTL_TEXTENCODING_UTF8));
121 break;
122 }
124 {
125 pWhich = "inet format";
126 const SwFormatINetFormat& rFormat = GetINetFormat();
127 oValue = OString("url: " + rFormat.GetValue().toUtf8());
128 break;
129 }
131 {
132 pWhich = "ruby";
133 const SwFormatRuby& rFormat = GetRuby();
134 oValue = OString("rubytext: " + rFormat.GetText().toUtf8());
135 break;
136 }
137 case RES_TXTATR_META:
138 {
139 pWhich = "meta";
140 break;
141 }
142 case RES_TXTATR_FIELD:
143 {
144 pWhich = "field";
145 break;
146 }
147 default:
148 break;
149 }
150 if (pWhich)
151 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("which"), BAD_CAST(pWhich));
152 if (oValue)
153 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr()));
154 switch (Which())
155 {
157 GetAutoFormat().dumpAsXml(pWriter);
158 break;
159 case RES_TXTATR_FIELD:
161 GetFormatField().dumpAsXml(pWriter);
162 break;
163 case RES_TXTATR_FTN:
164 break;
166 GetLineBreak().dumpAsXml(pWriter);
167 break;
168 case RES_TXTATR_META:
169 break;
171 GetContentControl().dumpAsXml(pWriter);
172 break;
173 default:
174 SAL_WARN("sw.core", "Unhandled TXTATR");
175 break;
176 }
177
178 (void)xmlTextWriterEndElement(pWriter);
179}
180
181/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
void Remove(const SfxPoolItem &)
Represents the style of a text portion.
Definition: charfmt.hxx:27
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fmtatr2.cxx:144
SwCharFormat * GetCharFormat() const
Definition: fchrfmt.hxx:70
void dumpAsXml(xmlTextWriterPtr pWriter) const override
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:448
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
void dumpAsXml(xmlTextWriterPtr pWriter) const override
const OUString & GetText() const
Definition: fmtruby.hxx:61
SwTextAttrEnd(SfxPoolItem &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txatbase.cxx:71
virtual void SetEnd(sal_Int32) override
Definition: txatbase.cxx:82
virtual const sal_Int32 * GetEnd() const override
end position
Definition: txatbase.cxx:77
sal_Int32 m_nEnd
Definition: txatbase.hxx:138
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
static void Destroy(SwTextAttr *pToDestroy, SfxItemPool &rPool)
destroy instance
Definition: txatbase.cxx:58
sal_Int32 m_nStart
Definition: txatbase.hxx:48
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
virtual const sal_Int32 * GetEnd() const
end position
Definition: txatbase.cxx:48
SfxPoolItem *const m_pAttr
Definition: txatbase.hxx:47
const sal_Int32 * End() const
Definition: txatbase.hxx:156
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: txatbase.cxx:89
const SwFormatLineBreak & GetLineBreak() const
Definition: txatbase.hxx:214
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:244
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:187
virtual void SetEnd(sal_Int32)
Definition: txatbase.cxx:53
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:250
bool operator==(const SwTextAttr &) const
Definition: txatbase.cxx:66
SwTextAttr(SwTextAttr const &)=delete
virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE
Definition: txatbase.cxx:44
bool m_bDontExpand
Definition: txatbase.hxx:49
const SwFormatAutoFormat & GetAutoFormat() const
Definition: txatbase.hxx:193
const SwFormatContentControl & GetContentControl() const
Definition: txatbase.hxx:220
sal_uInt16 Which() const
Definition: txatbase.hxx:116
SwpHints * m_pHints
Definition: txatbase.hxx:67
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
void EndPosChanged() const
Definition: ndhints.hxx:213
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(59)
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
constexpr TypedWhichId< SwFormatContentControl > RES_TXTATR_CONTENTCONTROL(56)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(58)
constexpr TypedWhichId< SwFormatLineBreak > RES_TXTATR_LINEBREAK(61)
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_META(48)
constexpr TypedWhichId< SwFormatRuby > RES_TXTATR_CJK_RUBY(53)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
sal_Int64 n
#define SAL_WARN(area, stream)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)