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 const sal_Int32* SwTextAttr::GetEnd() const
50 {
51  return nullptr;
52 }
53 
54 void SwTextAttr::SetEnd(sal_Int32 )
55 {
56  assert(false);
57 }
58 
59 void SwTextAttr::Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool )
60 {
61  if (!pToDestroy) return;
62  SfxPoolItem * const pAttr = pToDestroy->m_pAttr;
63  delete pToDestroy;
64  rPool.Remove( *pAttr );
65 }
66 
67 bool SwTextAttr::operator==( const SwTextAttr& rAttr ) const
68 {
69  return GetAttr() == rAttr.GetAttr();
70 }
71 
73  sal_Int32 nStart, sal_Int32 nEnd ) :
74  SwTextAttr( rAttr, nStart ), m_nEnd( nEnd )
75 {
76 }
77 
78 const sal_Int32* SwTextAttrEnd::GetEnd() const
79 {
80  return & m_nEnd;
81 }
82 
83 void SwTextAttrEnd::SetEnd(sal_Int32 n)
84 {
85  m_nEnd = n;
86  if (m_pHints)
88 }
89 
91 {
92  xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextAttr"));
93 
94  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("start"), BAD_CAST(OString::number(m_nStart).getStr()));
95  if (End())
96  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr()));
97  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
98  const char* pWhich = nullptr;
100  switch (Which())
101  {
102  case RES_TXTATR_AUTOFMT:
103  pWhich = "autofmt";
104  break;
106  pWhich = "annotation";
107  break;
108  case RES_TXTATR_FLYCNT:
109  pWhich = "fly content";
110  break;
111  case RES_TXTATR_CHARFMT:
112  {
113  pWhich = "character format";
114  if (SwCharFormat* pCharFormat = GetCharFormat().GetCharFormat())
115  oValue = OString("name: " + OUStringToOString(pCharFormat->GetName(), RTL_TEXTENCODING_UTF8));
116  break;
117  }
118  case RES_TXTATR_INETFMT:
119  {
120  pWhich = "inet format";
121  const SwFormatINetFormat& rFormat = GetINetFormat();
122  oValue = OString("url: " + rFormat.GetValue().toUtf8());
123  break;
124  }
125  case RES_TXTATR_CJK_RUBY:
126  {
127  pWhich = "ruby";
128  const SwFormatRuby& rFormat = GetRuby();
129  oValue = OString("rubytext: " + rFormat.GetText().toUtf8());
130  break;
131  }
132  case RES_TXTATR_META:
133  {
134  pWhich = "meta";
135  break;
136  }
137  case RES_TXTATR_FIELD:
138  {
139  pWhich = "field";
140  break;
141  }
142  default:
143  break;
144  }
145  if (pWhich)
146  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("which"), BAD_CAST(pWhich));
147  if (oValue)
148  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr()));
149  switch (Which())
150  {
151  case RES_TXTATR_AUTOFMT:
152  GetAutoFormat().dumpAsXml(pWriter);
153  break;
154  case RES_TXTATR_FIELD:
155  GetFormatField().dumpAsXml(pWriter);
156  break;
157  default:
158  break;
159  }
160 
161  xmlTextWriterEndElement(pWriter);
162 }
163 
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nEnd
Definition: txatbase.hxx:130
#define RES_TXTATR_CJK_RUBY
Definition: hintids.hxx:144
virtual const sal_Int32 * GetEnd() const
end position
Definition: txatbase.cxx:49
virtual void SetEnd(sal_Int32) override
Definition: txatbase.cxx:83
SwpHints * m_pHints
Definition: txatbase.hxx:61
SfxPoolItem *const m_pAttr
Definition: txatbase.hxx:41
#define RES_TXTATR_CHARFMT
Definition: hintids.hxx:143
sal_uInt16 Which() const
Definition: txatbase.hxx:110
virtual const sal_Int32 * GetEnd() const override
end position
Definition: txatbase.cxx:78
void Remove(const SfxPoolItem &)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fmtatr2.cxx:145
sal_Int32 m_nStart
Definition: txatbase.hxx:42
#define RES_TXTATR_META
Definition: hintids.hxx:139
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:45
#define RES_TXTATR_INETFMT
Definition: hintids.hxx:142
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
virtual void SetEnd(sal_Int32)
Definition: txatbase.cxx:54
#define RES_TXTATR_FIELD
Definition: hintids.hxx:151
#define RES_TXTATR_AUTOFMT
Definition: hintids.hxx:141
void EndPosChanged() const
Definition: ndhints.hxx:213
SwTextAttrEnd(SfxPoolItem &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txatbase.cxx:72
#define RES_TXTATR_ANNOTATION
Definition: hintids.hxx:154
static void Destroy(SwTextAttr *pToDestroy, SfxItemPool &rPool)
destroy instance
Definition: txatbase.cxx:59
const sal_Int32 * End() const
Definition: txatbase.hxx:148
bool operator==(const SwTextAttr &) const
Definition: txatbase.cxx:67
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: txatbase.cxx:90
#define RES_TXTATR_FLYCNT
Definition: hintids.hxx:152
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