LibreOffice Module starmath (master) 1
element.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10#pragma once
11
12#include "attribute.hxx"
13#include <rect.hxx>
14
15#include <editeng/editdata.hxx>
16
17class SmMlElement final : public SmRect
18{
19 /* Technical stuff */
20
21public:
24 , m_aText(u"")
25 , m_aESelection(0, 0, 0, 0)
29 , m_aParentElement(nullptr)
31 {
33 };
34 /* Mathml stuff */
35
36public:
38 : m_aElementType(aElementType)
39 , m_aText(u"\u00B6")
40 , m_aESelection(0, 0, 0, 0)
42 , m_aParentElement(nullptr)
44 {
46 };
47
48public:
49 SmMlElement(const SmMlElement& aElement)
50 : SmRect(static_cast<SmRect>(aElement))
52 , m_aText(aElement.getText())
55 , m_aParentElement(nullptr)
57 {
58 m_aAttributePosList = std::vector<SmMlAttributePos>(aElement.getAttributeCount());
59 for (size_t i = 0; i < aElement.getAttributeCount(); ++i)
61 };
62
63private:
64 // Type of element
66
67 // Element text
68 OUString m_aText;
69
70 // Location in source code
72
73 // Attribute list
74 std::vector<SmMlAttribute> m_aAttributeList;
75
76 // Attribute position list
77 std::vector<SmMlAttributePos> m_aAttributePosList;
78
79 // Sub elements
80 std::vector<SmMlElement*> m_aSubElements;
81
82 // Parent element
84
85 // Child id, so it is possible to iterate
87
88private:
90
91public: // Element type
97
103 bool isMlElementType(SmMlElementType aElementType) const
104 {
105 return m_aElementType == aElementType;
106 };
107
108public: // location in the source
113 const ESelection& getESelection() const { return m_aESelection; };
114
120
125 void setESelection(ESelection aESelection) { m_aESelection = aESelection; };
126
132 sal_Int32 GetSourceCodeRow() const { return m_aESelection.nStartPara; }
133
139 sal_Int32 GetSourceCodeColumn() const { return m_aESelection.nStartPos; }
140
141public: // attributes
146 size_t getAttributeCount() const { return m_aAttributeList.size(); };
147
154 SmMlAttribute getAttribute(size_t nAttributePos) const
155 {
156 return nAttributePos < m_aAttributeList.size() ? m_aAttributeList[nAttributePos]
157 : SmMlAttribute();
158 }
159
167
174 void setAttribute(const SmMlAttribute* aAttribute);
175
182 void setAttribute(const SmMlAttribute& aAttribute) { setAttribute(&aAttribute); }
183
187 bool isAttributeSet(SmMlAttributeValueType aAttributeType) const;
188
189private: // attributes
196 const SmMlAttribute* getAttributePointer(size_t nAttributePos) const
197 {
198 return nAttributePos < m_aAttributeList.size() ? &m_aAttributeList[nAttributePos] : nullptr;
199 }
200
208 void setAttributeForce(size_t nAttributePos, const SmMlAttribute* aAttribute)
209 {
210 m_aAttributeList[nAttributePos].setMlAttributeValue(aAttribute);
211 }
212
213public: // sub elements
218 size_t getSubElementsCount() const { return m_aSubElements.size(); };
219
226 {
227 return nPos < m_aSubElements.size() ? m_aSubElements[nPos] : nullptr;
228 };
229
235 const SmMlElement* getSubElement(size_t nPos) const
236 {
237 return nPos < m_aSubElements.size() ? m_aSubElements[nPos] : nullptr;
238 };
239
245 void setSubElement(size_t nPos, SmMlElement* aElement);
246
250 size_t getSubElementId() const { return m_nSubElementId; }
251
256 void setSubElementId(size_t nSubElementId) { m_nSubElementId = nSubElementId; }
257
258public: // parent elements
264
270
276 void setParentElement(SmMlElement* aParentElement) { m_aParentElement = aParentElement; };
277
278public: // text elements
282 const OUString& getText() const { return m_aText; };
283
287 void setText(OUString aText) { m_aText = aText; };
288};
289
290namespace starmathdatabase
291{
297std::vector<SmMlAttribute> makeMlAttributeList(std::vector<SmMlAttributePos> aAttributePosList);
298}
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
SmMlElementType m_aElementType
Definition: element.hxx:61
void setAttributeForce(size_t nAttributePos, const SmMlAttribute *aAttribute)
Sets a given attribute.
Definition: element.hxx:208
size_t getAttributeCount() const
Returns the amount of available attributes.
Definition: element.hxx:146
bool isAttributeSet(SmMlAttributeValueType aAttributeType) const
Checks if an attribute has been manually set.
Definition: element.cxx:82
SmMlAttribute getAttribute(size_t nAttributePos) const
Gets a given attribute.
Definition: element.hxx:154
void setText(OUString aText)
Returns the element text.
Definition: element.hxx:287
SmMlElement * getParentElement()
Returns the parent element.
Definition: element.hxx:263
const ESelection & getESelectionReference() const
Returns the location in the source code of the node type.
Definition: element.hxx:119
sal_Int32 GetSourceCodeRow() const
Gets the line in the text where the node is located.
Definition: element.hxx:132
std::vector< SmMlAttribute > m_aAttributeList
Definition: element.hxx:74
SmMlElementType getMlElementType() const
Returns the mathml element type.
Definition: element.hxx:96
std::vector< SmMlAttributePos > m_aAttributePosList
Definition: element.hxx:77
const SmMlAttribute * getAttributePointer(size_t nAttributePos) const
Gets a given attribute.
Definition: element.hxx:196
const SmMlElement * getSubElement(size_t nPos) const
Returns a given sub element.
Definition: element.hxx:235
const OUString & getText() const
Returns the element text.
Definition: element.hxx:282
void setSubElement(size_t nPos, SmMlElement *aElement)
Sets a given sub element.
Definition: element.cxx:106
ESelection m_aESelection
Definition: element.hxx:71
SmMlElement * getSubElement(size_t nPos)
Returns a given sub element.
Definition: element.hxx:225
SmMlElement(const SmMlElement &aElement)
Definition: element.hxx:49
size_t getSubElementId() const
Gets subelement id.
Definition: element.hxx:250
void setAttribute(const SmMlAttribute &aAttribute)
Set's a given attribute.
Definition: element.hxx:182
void setSubElementId(size_t nSubElementId)
Sets subelement id.
Definition: element.hxx:256
const ESelection & getESelection() const
Returns the location in the source code of the node type.
Definition: element.hxx:113
sal_Int32 GetSourceCodeColumn() const
Gets the column of the line in the text where the node is located.
Definition: element.hxx:139
void setAttribute(const SmMlAttribute *aAttribute)
Sets a given attribute.
Definition: element.cxx:93
SmMlElement(SmMlElementType aElementType)
Definition: element.hxx:37
size_t getSubElementsCount() const
Returns the sub elements count.
Definition: element.hxx:218
size_t m_nSubElementId
Definition: element.hxx:86
SmMlElement * m_aParentElement
Definition: element.hxx:83
bool isMlElementType(SmMlElementType aElementType) const
Check if the mathml element is of a given type.
Definition: element.hxx:103
std::vector< SmMlElement * > m_aSubElements
Definition: element.hxx:80
void setParentElement(SmMlElement *aParentElement)
Sets the parent element No allocation / free is done.
Definition: element.hxx:276
void SmImplAttributeType()
Definition: element.cxx:12
void setESelection(ESelection aESelection)
Sets the location in the source code of the node type.
Definition: element.hxx:125
const SmMlElement * getParentElement() const
Returns the parent element.
Definition: element.hxx:269
OUString m_aText
Definition: element.hxx:68
Definition: rect.hxx:84
SmMlElementType
Definition: def.hxx:52
SmMlAttributeValueType
Definition: def.hxx:73
float u
sal_uInt16 nPos
int i
Parses the starmath code and creates the nodes.
Definition: attribute.hxx:191
std::vector< SmMlAttribute > makeMlAttributeList(std::vector< SmMlAttributePos > aAttributePosList)
Generates an attribute vector of default values from an attribute position list.
Definition: element.cxx:126
sal_Int32 nStartPara
sal_Int32 nStartPos