LibreOffice Module sw (master)  1
chrfmt.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 <libxml/xmlwriter.h>
21 
22 #include <charfmt.hxx>
23 #include <charformats.hxx>
24 
26 {
27  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwCharFormat"));
28  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"),
29  BAD_CAST(GetName().toUtf8().getStr()));
30 
32  {
33  (void)xmlTextWriterWriteAttribute(
34  pWriter, BAD_CAST("linked"), BAD_CAST(mpLinkedParaFormat->GetName().toUtf8().getStr()));
35  }
36 
37  GetAttrSet().dumpAsXml(pWriter);
38  (void)xmlTextWriterEndElement(pWriter);
39 }
40 
42 
44 
46 {
47  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwCharFormats"));
48  for (size_t i = 0; i < size(); ++i)
49  GetFormat(i)->dumpAsXml(pWriter);
50  (void)xmlTextWriterEndElement(pWriter);
51 }
52 
54  : m_PosIndex(m_Array.get<0>())
55  , m_NameIndex(m_Array.get<1>())
56 {
57 }
58 
60 {
61  // default char format is owned by SwDoc
62  DeleteAndDestroyAll(true);
63 }
64 
66 {
67  ByName::iterator it
68  = m_NameIndex.find(std::make_tuple(x->GetName(), const_cast<SwCharFormat*>(x)));
69  return m_Array.project<0>(it);
70 }
71 
72 SwCharFormats::ByName::const_iterator SwCharFormats::findByName(const OUString& name) const
73 {
74  return m_NameIndex.find(std::make_tuple(name));
75 }
76 
77 SwCharFormat* SwCharFormats::FindFormatByName(const OUString& rName) const
78 {
79  auto it = findByName(rName);
80  if (it != m_NameIndex.end())
81  return *it;
82  return nullptr;
83 }
84 
85 void SwCharFormats::DeleteAndDestroyAll(bool keepDefault)
86 {
87  if (empty())
88  return;
89  const int _offset = keepDefault ? 1 : 0;
90  for (const_iterator it = begin() + _offset; it != end(); ++it)
91  {
92  assert(!(*it)->HasName(u"Character style"));
93  delete *it;
94  }
95  if (_offset)
96  m_PosIndex.erase(begin() + _offset, end());
97  else
98  m_Array.clear();
99 }
100 
102 {
103  assert(!ContainsFormat(x));
104  m_PosIndex.push_back(x);
105 }
106 
107 void SwCharFormats::erase(const_iterator const& position) { m_PosIndex.erase(position); }
108 
109 bool SwCharFormats::ContainsFormat(const SwCharFormat* x) const { return find(x) != end(); }
110 
112 void SwCharFormats::SetFormatNameAndReindex(SwCharFormat* v, const OUString& sNewName)
113 {
114  auto it = find(v);
115  erase(it);
116  v->SetName(sNewName);
117  insert(v);
118 }
119 
120 size_t SwCharFormats::GetPos(const SwCharFormat* p) const
121 {
122  auto it = find(p);
123  return it == end() ? SIZE_MAX : it - begin();
124 }
125 
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
ByPos & m_PosIndex
Definition: charformats.hxx:58
void DeleteAndDestroyAll(bool keepDefault=false)
Definition: chrfmt.cxx:85
ByPos::const_iterator const_iterator
Definition: charformats.hxx:62
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
void dumpAsXml(xmlTextWriterPtr pWriter) const
ByName::const_iterator findByName(const OUString &name) const
Definition: chrfmt.cxx:72
bool ContainsFormat(const SwCharFormat *pFormat) const
fast check if given format is contained here pFormat must not have been deleted
Definition: chrfmt.cxx:109
const OUString & GetName() const
Definition: format.hxx:115
virtual SwCharFormat * GetFormat(size_t idx) const override
Definition: charformats.hxx:95
const_iterator find(const SwCharFormat *x) const
Definition: chrfmt.cxx:65
virtual ~SwCharFormats() override
Definition: chrfmt.cxx:59
int i
const_iterator end() const
Definition: charformats.hxx:90
SwTextFormatColl * mpLinkedParaFormat
Definition: charfmt.hxx:31
virtual void SetName(const OUString &rNewName, bool bBroadcast=false)
Definition: format.cxx:146
SwCharFormatsBase m_Array
Definition: charformats.hxx:57
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: chrfmt.cxx:25
bool empty() const
Definition: charformats.hxx:70
float u
Represents the style of a text portion.
Definition: charfmt.hxx:26
size_t size() const
Definition: charformats.hxx:71
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: chrfmt.cxx:45
void SetFormatNameAndReindex(SwCharFormat *v, const OUString &sNewName)
Need to call this when the format name changes.
Definition: chrfmt.cxx:112
virtual SwCharFormat * FindFormatByName(const OUString &rName) const override
Definition: chrfmt.cxx:77
const SwTextFormatColl * GetLinkedParaFormat() const
Definition: chrfmt.cxx:43
size_t GetPos(const SwCharFormat *p) const
Definition: chrfmt.cxx:120
void erase(const_iterator const &position)
Definition: chrfmt.cxx:107
ByName & m_NameIndex
Definition: charformats.hxx:59
void SetLinkedParaFormat(SwTextFormatColl &rLink)
Definition: chrfmt.cxx:41
void insert(SwCharFormat *x)
Definition: chrfmt.cxx:101
struct _xmlTextWriter * xmlTextWriterPtr
const_iterator begin() const
Definition: charformats.hxx:89
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:120
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo