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 
26 SwTextAttr::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 
44 SwTextAttr::~SwTextAttr() COVERITY_NOEXCEPT_FALSE
45 {
46 }
47 
48 const sal_Int32* SwTextAttr::GetEnd() const
49 {
50  return nullptr;
51 }
52 
53 void SwTextAttr::SetEnd(sal_Int32 )
54 {
55  assert(false);
56 }
57 
58 void 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 
66 bool 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 
77 const sal_Int32* SwTextAttrEnd::GetEnd() const
78 {
79  return & m_nEnd;
80 }
81 
82 void 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  {
107  case RES_TXTATR_AUTOFMT:
108  pWhich = "autofmt";
109  break;
111  pWhich = "annotation";
112  break;
113  case RES_TXTATR_FLYCNT:
114  pWhich = "fly content";
115  break;
116  case RES_TXTATR_CHARFMT:
117  {
118  pWhich = "character format";
119  if (SwCharFormat* pCharFormat = GetCharFormat().GetCharFormat())
120  oValue = OString("name: " + OUStringToOString(pCharFormat->GetName(), RTL_TEXTENCODING_UTF8));
121  break;
122  }
123  case RES_TXTATR_INETFMT:
124  {
125  pWhich = "inet format";
126  const SwFormatINetFormat& rFormat = GetINetFormat();
127  oValue = OString("url: " + rFormat.GetValue().toUtf8());
128  break;
129  }
130  case RES_TXTATR_CJK_RUBY:
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  {
156  case RES_TXTATR_AUTOFMT:
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: */
sal_Int32 m_nEnd
Definition: txatbase.hxx:138
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_META(48)
virtual const sal_Int32 * GetEnd() const
end position
Definition: txatbase.cxx:48
virtual void SetEnd(sal_Int32) override
Definition: txatbase.cxx:82
SwpHints * m_pHints
Definition: txatbase.hxx:67
bool m_bDontExpand
Definition: txatbase.hxx:49
SfxPoolItem *const m_pAttr
Definition: txatbase.hxx:47
sal_uInt16 Which() const
Definition: txatbase.hxx:116
virtual const sal_Int32 * GetEnd() const override
end position
Definition: txatbase.cxx:77
void Remove(const SfxPoolItem &)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fmtatr2.cxx:143
sal_Int32 m_nStart
Definition: txatbase.hxx:48
SwTextAttr(SwTextAttr const &)=delete
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(59)
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:43
constexpr TypedWhichId< SwFormatRuby > RES_TXTATR_CJK_RUBY(53)
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
const OUString & GetText() const
Definition: fmtruby.hxx:61
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
const SwFormatLineBreak & GetLineBreak() const
Definition: txatbase.hxx:214
virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE
Definition: txatbase.cxx:44
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(58)
const SwFormatContentControl & GetContentControl() const
Definition: txatbase.hxx:220
constexpr TypedWhichId< SwFormatLineBreak > RES_TXTATR_LINEBREAK(61)
Represents the style of a text portion.
Definition: charfmt.hxx:26
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
virtual void SetEnd(sal_Int32)
Definition: txatbase.cxx:53
constexpr TypedWhichId< SwFormatContentControl > RES_TXTATR_CONTENTCONTROL(56)
SwCharFormat * GetCharFormat() const
Definition: fchrfmt.hxx:70
void EndPosChanged() const
Definition: ndhints.hxx:213
SwTextAttrEnd(SfxPoolItem &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txatbase.cxx:71
void dumpAsXml(xmlTextWriterPtr pWriter) const override
static void Destroy(SwTextAttr *pToDestroy, SfxItemPool &rPool)
destroy instance
Definition: txatbase.cxx:58
const sal_Int32 * End() const
Definition: txatbase.hxx:156
bool operator==(const SwTextAttr &) const
Definition: txatbase.cxx:66
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: txatbase.cxx:89
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
#define SAL_WARN(area, stream)
struct _xmlTextWriter * xmlTextWriterPtr
const SwFormatAutoFormat & GetAutoFormat() const
Definition: txatbase.hxx:193
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:187
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:432
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:250
void dumpAsXml(xmlTextWriterPtr pWriter) const override
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:244
bool m_bDetectedRangeSegmentation false
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo