android: Update app-specific/MIME type icons
[LibreOffice.git] / starmath / inc / mathml / element.hxx
blobce5d7073b60688454c2589edf5ea73d43d686f9f
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.
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 */
10 #pragma once
12 #include "attribute.hxx"
13 #include <rect.hxx>
15 #include <editeng/editdata.hxx>
17 class SmMlElement final : public SmRect
19 /* Technical stuff */
21 public:
22 SmMlElement()
23 : m_aElementType(SmMlElementType::NMlEmpty)
24 , m_aText(u"")
25 , m_aESelection(0, 0, 0, 0)
26 , m_aAttributeList(0)
27 , m_aAttributePosList(0)
28 , m_aSubElements(0)
29 , m_aParentElement(nullptr)
30 , m_nSubElementId(0)
32 SmImplAttributeType();
34 /* Mathml stuff */
36 public:
37 SmMlElement(SmMlElementType aElementType)
38 : m_aElementType(aElementType)
39 , m_aText(u"\u00B6")
40 , m_aESelection(0, 0, 0, 0)
41 , m_aSubElements(0)
42 , m_aParentElement(nullptr)
43 , m_nSubElementId(0)
45 SmImplAttributeType();
48 public:
49 SmMlElement(const SmMlElement& aElement)
50 : SmRect(static_cast<SmRect>(aElement))
51 , m_aElementType(aElement.getMlElementType())
52 , m_aText(aElement.getText())
53 , m_aESelection(aElement.getESelectionReference())
54 , m_aSubElements(0)
55 , m_aParentElement(nullptr)
56 , m_nSubElementId(aElement.getSubElementId())
58 m_aAttributePosList = std::vector<SmMlAttributePos>(aElement.getAttributeCount());
59 for (size_t i = 0; i < aElement.getAttributeCount(); ++i)
60 setAttributeForce(i, aElement.getAttributePointer(i));
63 private:
64 // Type of element
65 SmMlElementType m_aElementType;
67 // Element text
68 OUString m_aText;
70 // Location in source code
71 ESelection m_aESelection;
73 // Attribute list
74 std::vector<SmMlAttribute> m_aAttributeList;
76 // Attribute position list
77 std::vector<SmMlAttributePos> m_aAttributePosList;
79 // Sub elements
80 std::vector<SmMlElement*> m_aSubElements;
82 // Parent element
83 SmMlElement* m_aParentElement;
85 // Child id, so it is possible to iterate
86 size_t m_nSubElementId;
88 private:
89 void SmImplAttributeType();
91 public: // Element type
92 /**
93 * Returns the mathml element type
94 * @return mathml element type
96 SmMlElementType getMlElementType() const { return m_aElementType; };
98 /**
99 * Check if the mathml element is of a given type
100 * @param aElementType
101 * @return is mathml element type
103 bool isMlElementType(SmMlElementType aElementType) const
105 return m_aElementType == aElementType;
108 public: // location in the source
110 * Returns the location in the source code of the node type
111 * @return selection
113 const ESelection& getESelection() const { return m_aESelection; };
116 * Returns the location in the source code of the node type
117 * @return selection
119 const ESelection& getESelectionReference() const { return m_aESelection; };
122 * Sets the location in the source code of the node type
123 * @param aESelection
125 void setESelection(ESelection aESelection) { m_aESelection = aESelection; };
128 * Gets the line in the text where the node is located.
129 * It is used to do the visual <-> text correspondence.
130 * @return line
132 sal_Int32 GetSourceCodeRow() const { return m_aESelection.nStartPara; }
135 * Gets the column of the line in the text where the node is located.
136 * It is used to do the visual <-> text correspondence.
137 * @return column
139 sal_Int32 GetSourceCodeColumn() const { return m_aESelection.nStartPos; }
141 public: // attributes
143 * Returns the amount of available attributes
144 * @return attribute count
146 size_t getAttributeCount() const { return m_aAttributeList.size(); };
149 * Gets a given attribute.
150 * If no available returns empty attribute.
151 * @param nAttributePos
152 * @return given attribute.
154 SmMlAttribute getAttribute(size_t nAttributePos) const
156 return nAttributePos < m_aAttributeList.size() ? m_aAttributeList[nAttributePos]
157 : SmMlAttribute();
161 * Gets a given attribute.
162 * If no available returns empty attribute.
163 * @param nAttributePos
164 * @return given attribute.
166 SmMlAttribute getAttribute(SmMlAttributeValueType aAttributeType) const;
169 * Sets a given attribute.
170 * If no available does nothing.
171 * @param nAttributePos
172 * @return given attribute.
174 void setAttribute(const SmMlAttribute* aAttribute);
177 * Set's a given attribute.
178 * If no available does nothing.
179 * @param nAttributePos
180 * @return given attribute.
182 void setAttribute(const SmMlAttribute& aAttribute) { setAttribute(&aAttribute); }
184 /** Checks if an attribute has been manually set
185 * @param aElementType
187 bool isAttributeSet(SmMlAttributeValueType aAttributeType) const;
189 private: // attributes
191 * Gets a given attribute.
192 * If no available returns empty attribute.
193 * @param nAttributePos
194 * @return given attribute.
196 const SmMlAttribute* getAttributePointer(size_t nAttributePos) const
198 return nAttributePos < m_aAttributeList.size() ? &m_aAttributeList[nAttributePos] : nullptr;
202 * Sets a given attribute.
203 * If no available undefined behaviour.
204 * @param nAttributePos
205 * @param aAttribute
206 * @return given attribute.
208 void setAttributeForce(size_t nAttributePos, const SmMlAttribute* aAttribute)
210 m_aAttributeList[nAttributePos].setMlAttributeValue(aAttribute);
213 public: // sub elements
215 * Returns the sub elements count
216 * @return sub elements count
218 size_t getSubElementsCount() const { return m_aSubElements.size(); };
221 * Returns a given sub element
222 * @param nPos
223 * @return sub elements
225 SmMlElement* getSubElement(size_t nPos)
227 return nPos < m_aSubElements.size() ? m_aSubElements[nPos] : nullptr;
231 * Returns a given sub element
232 * @param nPos
233 * @return sub elements
235 const SmMlElement* getSubElement(size_t nPos) const
237 return nPos < m_aSubElements.size() ? m_aSubElements[nPos] : nullptr;
241 * Sets a given sub element
242 * @param nPos
243 * @param aElement
245 void setSubElement(size_t nPos, SmMlElement* aElement);
248 * Gets subelement id
250 size_t getSubElementId() const { return m_nSubElementId; }
253 * Sets subelement id
254 * @param nSubElementId
256 void setSubElementId(size_t nSubElementId) { m_nSubElementId = nSubElementId; }
258 public: // parent elements
260 * Returns the parent element
261 * @return parent element
263 SmMlElement* getParentElement() { return m_aParentElement; };
266 * Returns the parent element
267 * @return parent element
269 const SmMlElement* getParentElement() const { return m_aParentElement; };
272 * Sets the parent element
273 * No allocation / free is done.
274 * @param aParentElement
276 void setParentElement(SmMlElement* aParentElement) { m_aParentElement = aParentElement; };
278 public: // text elements
280 * Returns the element text
282 const OUString& getText() const { return m_aText; };
285 * Returns the element text
287 void setText(OUString aText) { m_aText = aText; };
290 namespace starmathdatabase
293 * Generates an attribute vector of default values from an attribute position list.
294 * @param aAttributePosList
295 * @return attribute vector
297 std::vector<SmMlAttribute> makeMlAttributeList(std::vector<SmMlAttributePos> aAttributePosList);
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */