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 = "inet format";
119 const SwFormatINetFormat& rFormat = GetINetFormat();
120 oValue = OString("url: " + rFormat.GetValue().toUtf8());
121 break;
122 }
124 {
125 pWhich = "ruby";
126 const SwFormatRuby& rFormat = GetRuby();
127 oValue = OString("rubytext: " + rFormat.GetText().toUtf8());
128 break;
129 }
130 case RES_TXTATR_META:
131 {
132 pWhich = "meta";
133 break;
134 }
135 case RES_TXTATR_FIELD:
136 {
137 pWhich = "field";
138 break;
139 }
140 default:
141 break;
142 }
143 if (pWhich)
144 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("which"), BAD_CAST(pWhich));
145 if (oValue)
146 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr()));
147 switch (Which())
148 {
150 GetAutoFormat().dumpAsXml(pWriter);
151 break;
152 case RES_TXTATR_FIELD:
154 GetFormatField().dumpAsXml(pWriter);
155 break;
156 case RES_TXTATR_FTN:
157 GetFootnote().dumpAsXml(pWriter);
158 break;
160 GetLineBreak().dumpAsXml(pWriter);
161 break;
162 case RES_TXTATR_META:
163 break;
165 GetContentControl().dumpAsXml(pWriter);
166 break;
168 GetFlyCnt().dumpAsXml(pWriter);
169 break;
171 GetCharFormat().dumpAsXml(pWriter);
172 break;
174 GetRefMark().dumpAsXml(pWriter);
175 break;
176 default:
177 SAL_WARN("sw.core", "Unhandled TXTATR");
178 break;
179 }
180
181 (void)xmlTextWriterEndElement(pWriter);
182}
183
184/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Remove(const SfxPoolItem &)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fmtatr2.cxx:155
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fmtatr2.cxx:116
void dumpAsXml(xmlTextWriterPtr pWriter) const override
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:474
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrflyin.cxx:59
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrftn.cxx:282
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
void dumpAsXml(xmlTextWriterPtr pWriter) const override
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrref.cxx:90
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
const SwFormatRefMark & GetRefMark() const
Definition: txatbase.hxx:238
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 SwFormatFlyCnt & GetFlyCnt() const
Definition: txatbase.hxx:226
const SwFormatLineBreak & GetLineBreak() const
Definition: txatbase.hxx:214
const SwFormatFootnote & GetFootnote() const
Definition: txatbase.hxx:208
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
struct _xmlTextWriter * xmlTextWriterPtr
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< SwFormatRefMark > RES_TXTATR_REFMARK(RES_TXTATR_WITHEND_BEGIN)
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)