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  GetAttrSet().dumpAsXml(pWriter);
31  (void)xmlTextWriterEndElement(pWriter);
32 }
33 
35 {
36  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwCharFormats"));
37  for (size_t i = 0; i < size(); ++i)
38  GetFormat(i)->dumpAsXml(pWriter);
39  (void)xmlTextWriterEndElement(pWriter);
40 }
41 
43  : m_PosIndex(m_Array.get<0>())
44  , m_NameIndex(m_Array.get<1>())
45 {
46 }
47 
49 {
50  // default char format is owned by SwDoc
51  DeleteAndDestroyAll(true);
52 }
53 
55 {
56  ByName::iterator it
57  = m_NameIndex.find(std::make_tuple(x->GetName(), const_cast<SwCharFormat*>(x)));
58  return m_Array.project<0>(it);
59 }
60 
61 SwCharFormats::ByName::const_iterator SwCharFormats::findByName(const OUString& name) const
62 {
63  return m_NameIndex.find(std::make_tuple(name));
64 }
65 
66 SwCharFormat* SwCharFormats::FindFormatByName(const OUString& rName) const
67 {
68  auto it = findByName(rName);
69  if (it != m_NameIndex.end())
70  return *it;
71  return nullptr;
72 }
73 
74 void SwCharFormats::DeleteAndDestroyAll(bool keepDefault)
75 {
76  if (empty())
77  return;
78  const int _offset = keepDefault ? 1 : 0;
79  for (const_iterator it = begin() + _offset; it != end(); ++it)
80  {
81  assert(!(*it)->HasName(u"Character style"));
82  delete *it;
83  }
84  if (_offset)
85  m_PosIndex.erase(begin() + _offset, end());
86  else
87  m_Array.clear();
88 }
89 
91 {
92  assert(!ContainsFormat(x));
93  m_PosIndex.push_back(x);
94 }
95 
96 void SwCharFormats::erase(const_iterator const& position) { m_PosIndex.erase(position); }
97 
98 bool SwCharFormats::ContainsFormat(const SwCharFormat* x) const { return find(x) != end(); }
99 
101 void SwCharFormats::SetFormatNameAndReindex(SwCharFormat* v, const OUString& sNewName)
102 {
103  auto it = find(v);
104  erase(it);
105  v->SetName(sNewName);
106  insert(v);
107 }
108 
109 size_t SwCharFormats::GetPos(const SwCharFormat* p) const
110 {
111  auto it = find(p);
112  return it == end() ? SIZE_MAX : it - begin();
113 }
114 
115 /* 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:74
ByPos::const_iterator const_iterator
Definition: charformats.hxx:62
void dumpAsXml(xmlTextWriterPtr pWriter) const
ByName::const_iterator findByName(const OUString &name) const
Definition: chrfmt.cxx:61
bool ContainsFormat(const SwCharFormat *pFormat) const
fast check if given format is contained here pFormat must not have been deleted
Definition: chrfmt.cxx:98
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:54
virtual ~SwCharFormats() override
Definition: chrfmt.cxx:48
struct _xmlTextWriter * xmlTextWriterPtr
int i
const_iterator end() const
Definition: charformats.hxx:90
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
size_t size() const
Definition: charformats.hxx:71
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: chrfmt.cxx:34
void SetFormatNameAndReindex(SwCharFormat *v, const OUString &sNewName)
Need to call this when the format name changes.
Definition: chrfmt.cxx:101
virtual SwCharFormat * FindFormatByName(const OUString &rName) const override
Definition: chrfmt.cxx:66
size_t GetPos(const SwCharFormat *p) const
Definition: chrfmt.cxx:109
void erase(const_iterator const &position)
Definition: chrfmt.cxx:96
ByName & m_NameIndex
Definition: charformats.hxx:59
void insert(SwCharFormat *x)
Definition: chrfmt.cxx:90
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