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 <boost/optional.hpp>
21 #include <libxml/xmlwriter.h>
22 #include <svl/itempool.hxx>
23 #include <txatbase.hxx>
24 #include <fmtfld.hxx>
25 #include <docufld.hxx>
26 
27 SwTextAttr::SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart )
28  : m_pAttr( &rAttr )
29  , m_nStart( nStart )
30  , m_bDontExpand( false )
31  , m_bLockExpandFlag( false )
32  , m_bDontMoveAttr( false )
33  , m_bCharFormatAttr( false )
34  , m_bOverlapAllowedAttr( false )
35  , m_bPriorityAttr( false )
36  , m_bDontExpandStart( false )
37  , m_bNesting( false )
38  , m_bHasDummyChar( false )
39  , m_bFormatIgnoreStart(false)
40  , m_bFormatIgnoreEnd(false)
41  , m_bHasContent( false )
42 {
43 }
44 
45 SwTextAttr::~SwTextAttr() COVERITY_NOEXCEPT_FALSE
46 {
47 }
48 
49 sal_Int32* SwTextAttr::GetEnd()
50 {
51  return nullptr;
52 }
53 
54 void SwTextAttr::Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool )
55 {
56  if (!pToDestroy) return;
57  SfxPoolItem * const pAttr = pToDestroy->m_pAttr;
58  delete pToDestroy;
59  rPool.Remove( *pAttr );
60 }
61 
62 bool SwTextAttr::operator==( const SwTextAttr& rAttr ) const
63 {
64  return GetAttr() == rAttr.GetAttr();
65 }
66 
68  sal_Int32 nStart, sal_Int32 nEnd ) :
69  SwTextAttr( rAttr, nStart ), m_nEnd( nEnd )
70 {
71 }
72 
74 {
75  return & m_nEnd;
76 }
77 
79 {
80  xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextAttr"));
81 
82  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("start"), BAD_CAST(OString::number(m_nStart).getStr()));
83  if (End())
84  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr()));
85  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
86  const char* pWhich = nullptr;
88  switch (Which())
89  {
90  case RES_TXTATR_AUTOFMT:
91  pWhich = "autofmt";
92  break;
94  pWhich = "annotation";
95  break;
96  case RES_TXTATR_FLYCNT:
97  pWhich = "fly content";
98  break;
99  case RES_TXTATR_CHARFMT:
100  {
101  pWhich = "character format";
102  if (SwCharFormat* pCharFormat = GetCharFormat().GetCharFormat())
103  oValue = OString("name: " + OUStringToOString(pCharFormat->GetName(), RTL_TEXTENCODING_UTF8));
104  break;
105  }
106  case RES_TXTATR_INETFMT:
107  {
108  pWhich = "inet format";
109  const SwFormatINetFormat& rFormat = GetINetFormat();
110  oValue = OString("url: " + rFormat.GetValue().toUtf8());
111  break;
112  }
113  case RES_TXTATR_CJK_RUBY:
114  {
115  pWhich = "ruby";
116  const SwFormatRuby& rFormat = GetRuby();
117  oValue = OString("rubytext: " + rFormat.GetText().toUtf8());
118  break;
119  }
120  case RES_TXTATR_META:
121  {
122  pWhich = "meta";
123  break;
124  }
125  case RES_TXTATR_FIELD:
126  {
127  pWhich = "field";
128  break;
129  }
130  default:
131  break;
132  }
133  if (pWhich)
134  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("which"), BAD_CAST(pWhich));
135  if (oValue)
136  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr()));
137  switch (Which())
138  {
139  case RES_TXTATR_AUTOFMT:
140  GetAutoFormat().dumpAsXml(pWriter);
141  break;
142  case RES_TXTATR_FIELD:
143  GetFormatField().dumpAsXml(pWriter);
144  break;
145  default:
146  break;
147  }
148 
149  xmlTextWriterEndElement(pWriter);
150 }
151 
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nEnd
Definition: txatbase.hxx:125
#define RES_TXTATR_CJK_RUBY
Definition: hintids.hxx:143
SfxPoolItem *const m_pAttr
Definition: txatbase.hxx:39
#define RES_TXTATR_CHARFMT
Definition: hintids.hxx:142
sal_uInt16 Which() const
Definition: txatbase.hxx:105
void Remove(const SfxPoolItem &)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fmtatr2.cxx:145
sal_Int32 m_nStart
Definition: txatbase.hxx:40
#define RES_TXTATR_META
Definition: hintids.hxx:138
SwTextAttr(SwTextAttr const &)=delete
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
virtual sal_Int32 * GetEnd() override
end position
Definition: txatbase.cxx:73
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:185
const OUString & GetText() const
Definition: fmtruby.hxx:61
struct _xmlTextWriter * xmlTextWriterPtr
virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE
Definition: txatbase.cxx:45
virtual sal_Int32 * GetEnd()
end position
Definition: txatbase.cxx:49
#define RES_TXTATR_INETFMT
Definition: hintids.hxx:141
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
#define RES_TXTATR_FIELD
Definition: hintids.hxx:150
#define RES_TXTATR_AUTOFMT
Definition: hintids.hxx:140
SwTextAttrEnd(SfxPoolItem &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txatbase.cxx:67
#define RES_TXTATR_ANNOTATION
Definition: hintids.hxx:153
static void Destroy(SwTextAttr *pToDestroy, SfxItemPool &rPool)
destroy instance
Definition: txatbase.cxx:54
const sal_Int32 * End() const
Definition: txatbase.hxx:142
bool operator==(const SwTextAttr &) const
Definition: txatbase.cxx:62
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: txatbase.cxx:78
#define RES_TXTATR_FLYCNT
Definition: hintids.hxx:151
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:153
const SwFormatAutoFormat & GetAutoFormat() const
Definition: txatbase.hxx:179
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:173
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrfld.cxx:342
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:224
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:218