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 <o3tl/optional.hxx>
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  xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextAttr"));
92 
93  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("start"), BAD_CAST(OString::number(m_nStart).getStr()));
94  if (End())
95  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr()));
96  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
97  const char* pWhich = nullptr;
98  o3tl::optional<OString> oValue;
99  switch (Which())
100  {
101  case RES_TXTATR_AUTOFMT:
102  pWhich = "autofmt";
103  break;
105  pWhich = "annotation";
106  break;
107  case RES_TXTATR_FLYCNT:
108  pWhich = "fly content";
109  break;
110  case RES_TXTATR_CHARFMT:
111  {
112  pWhich = "character format";
113  if (SwCharFormat* pCharFormat = GetCharFormat().GetCharFormat())
114  oValue = OString("name: " + OUStringToOString(pCharFormat->GetName(), RTL_TEXTENCODING_UTF8));
115  break;
116  }
117  case RES_TXTATR_INETFMT:
118  {
119  pWhich = "inet format";
120  const SwFormatINetFormat& rFormat = GetINetFormat();
121  oValue = OString("url: " + rFormat.GetValue().toUtf8());
122  break;
123  }
124  case RES_TXTATR_CJK_RUBY:
125  {
126  pWhich = "ruby";
127  const SwFormatRuby& rFormat = GetRuby();
128  oValue = OString("rubytext: " + rFormat.GetText().toUtf8());
129  break;
130  }
131  case RES_TXTATR_META:
132  {
133  pWhich = "meta";
134  break;
135  }
136  case RES_TXTATR_FIELD:
137  {
138  pWhich = "field";
139  break;
140  }
141  default:
142  break;
143  }
144  if (pWhich)
145  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("which"), BAD_CAST(pWhich));
146  if (oValue)
147  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr()));
148  switch (Which())
149  {
150  case RES_TXTATR_AUTOFMT:
151  GetAutoFormat().dumpAsXml(pWriter);
152  break;
153  case RES_TXTATR_FIELD:
154  GetFormatField().dumpAsXml(pWriter);
155  break;
156  default:
157  break;
158  }
159 
160  xmlTextWriterEndElement(pWriter);
161 }
162 
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nEnd
Definition: txatbase.hxx:130
#define RES_TXTATR_CJK_RUBY
Definition: hintids.hxx:237
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:61
SfxPoolItem *const m_pAttr
Definition: txatbase.hxx:41
#define RES_TXTATR_CHARFMT
Definition: hintids.hxx:236
sal_uInt16 Which() const
Definition: txatbase.hxx:110
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:140
sal_Int32 m_nStart
Definition: txatbase.hxx:42
#define RES_TXTATR_META
Definition: hintids.hxx:232
SwTextAttr(SwTextAttr const &)=delete
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
const OUString & GetText() const
Definition: fmtruby.hxx:61
struct _xmlTextWriter * xmlTextWriterPtr
virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE
Definition: txatbase.cxx:44
#define RES_TXTATR_INETFMT
Definition: hintids.hxx:235
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
virtual void SetEnd(sal_Int32)
Definition: txatbase.cxx:53
#define RES_TXTATR_FIELD
Definition: hintids.hxx:244
#define RES_TXTATR_AUTOFMT
Definition: hintids.hxx:234
void EndPosChanged() const
Definition: ndhints.hxx:213
SwTextAttrEnd(SfxPoolItem &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txatbase.cxx:71
#define RES_TXTATR_ANNOTATION
Definition: hintids.hxx:247
static void Destroy(SwTextAttr *pToDestroy, SfxItemPool &rPool)
destroy instance
Definition: txatbase.cxx:58
const sal_Int32 * End() const
Definition: txatbase.hxx:148
bool operator==(const SwTextAttr &) const
Definition: txatbase.cxx:66
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: txatbase.cxx:89
#define RES_TXTATR_FLYCNT
Definition: hintids.hxx:245
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:159
const SwFormatAutoFormat & GetAutoFormat() const
Definition: txatbase.hxx:185
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:179
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:342
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:230
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:224