/src/libreoffice/starmath/inc/mathml/element.hxx
Line | Count | Source |
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 | | |
17 | | class SmMlElement final : public SmRect |
18 | | { |
19 | | /* Technical stuff */ |
20 | | |
21 | | public: |
22 | | SmMlElement() |
23 | 0 | : m_aElementType(SmMlElementType::NMlEmpty) |
24 | 0 | , m_aText(u""_ustr) |
25 | 0 | , m_aESelection(0, 0, 0, 0) |
26 | 0 | , m_aAttributeList(0) |
27 | 0 | , m_aAttributePosList(0) |
28 | 0 | , m_aSubElements(0) |
29 | 0 | , m_aParentElement(nullptr) |
30 | 0 | , m_nSubElementId(0) |
31 | 0 | { |
32 | 0 | SmImplAttributeType(); |
33 | 0 | }; |
34 | | /* Mathml stuff */ |
35 | | |
36 | | public: |
37 | | explicit SmMlElement(SmMlElementType aElementType) |
38 | | : m_aElementType(aElementType) |
39 | | , m_aText(u"\u00B6"_ustr) |
40 | | , m_aESelection(0, 0, 0, 0) |
41 | | , m_aSubElements(0) |
42 | | , m_aParentElement(nullptr) |
43 | | , m_nSubElementId(0) |
44 | 0 | { |
45 | 0 | SmImplAttributeType(); |
46 | 0 | }; |
47 | | |
48 | | public: |
49 | | SmMlElement(const SmMlElement& aElement) |
50 | 0 | : SmRect(static_cast<SmRect>(aElement)) |
51 | 0 | , m_aElementType(aElement.getMlElementType()) |
52 | 0 | , m_aText(aElement.getText()) |
53 | 0 | , m_aESelection(aElement.getESelectionReference()) |
54 | 0 | , m_aSubElements(0) |
55 | 0 | , m_aParentElement(nullptr) |
56 | 0 | , m_nSubElementId(aElement.getSubElementId()) |
57 | 0 | { |
58 | 0 | m_aAttributePosList = std::vector<SmMlAttributePos>(aElement.getAttributeCount()); |
59 | 0 | for (size_t i = 0; i < aElement.getAttributeCount(); ++i) |
60 | 0 | setAttributeForce(i, aElement.getAttributePointer(i)); |
61 | 0 | }; |
62 | | |
63 | | private: |
64 | | // Type of element |
65 | | SmMlElementType m_aElementType; |
66 | | |
67 | | // Element text |
68 | | OUString m_aText; |
69 | | |
70 | | // Location in source code |
71 | | ESelection m_aESelection; |
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 |
83 | | SmMlElement* m_aParentElement; |
84 | | |
85 | | // Child id, so it is possible to iterate |
86 | | size_t m_nSubElementId; |
87 | | |
88 | | private: |
89 | | void SmImplAttributeType(); |
90 | | |
91 | | public: // Element type |
92 | | /** |
93 | | * Returns the mathml element type |
94 | | * @return mathml element type |
95 | | */ |
96 | 0 | SmMlElementType getMlElementType() const { return m_aElementType; }; |
97 | | |
98 | | /** |
99 | | * Check if the mathml element is of a given type |
100 | | * @param aElementType |
101 | | * @return is mathml element type |
102 | | */ |
103 | | bool isMlElementType(SmMlElementType aElementType) const |
104 | 0 | { |
105 | 0 | return m_aElementType == aElementType; |
106 | 0 | }; |
107 | | |
108 | | public: // location in the source |
109 | | /** |
110 | | * Returns the location in the source code of the node type |
111 | | * @return selection |
112 | | */ |
113 | 0 | const ESelection& getESelection() const { return m_aESelection; }; |
114 | | |
115 | | /** |
116 | | * Returns the location in the source code of the node type |
117 | | * @return selection |
118 | | */ |
119 | 0 | const ESelection& getESelectionReference() const { return m_aESelection; }; |
120 | | |
121 | | /** |
122 | | * Sets the location in the source code of the node type |
123 | | * @param aESelection |
124 | | */ |
125 | 0 | void setESelection(ESelection aESelection) { m_aESelection = aESelection; }; |
126 | | |
127 | | /** |
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 |
131 | | */ |
132 | 0 | sal_Int32 GetSourceCodeRow() const { return m_aESelection.start.nPara; } |
133 | | |
134 | | /** |
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 |
138 | | */ |
139 | 0 | sal_Int32 GetSourceCodeColumn() const { return m_aESelection.start.nIndex; } |
140 | | |
141 | | public: // attributes |
142 | | /** |
143 | | * Returns the amount of available attributes |
144 | | * @return attribute count |
145 | | */ |
146 | 0 | size_t getAttributeCount() const { return m_aAttributeList.size(); }; |
147 | | |
148 | | /** |
149 | | * Gets a given attribute. |
150 | | * If no available returns empty attribute. |
151 | | * @param nAttributePos |
152 | | * @return given attribute. |
153 | | */ |
154 | | SmMlAttribute getAttribute(size_t nAttributePos) const |
155 | 0 | { |
156 | 0 | return nAttributePos < m_aAttributeList.size() ? m_aAttributeList[nAttributePos] |
157 | 0 | : SmMlAttribute(); |
158 | 0 | } |
159 | | |
160 | | /** |
161 | | * Gets a given attribute. |
162 | | * If no available returns empty attribute. |
163 | | * @param nAttributePos |
164 | | * @return given attribute. |
165 | | */ |
166 | | SmMlAttribute getAttribute(SmMlAttributeValueType aAttributeType) const; |
167 | | |
168 | | /** |
169 | | * Sets a given attribute. |
170 | | * If no available does nothing. |
171 | | * @param nAttributePos |
172 | | * @return given attribute. |
173 | | */ |
174 | | void setAttribute(const SmMlAttribute* aAttribute); |
175 | | |
176 | | /** |
177 | | * Set's a given attribute. |
178 | | * If no available does nothing. |
179 | | * @param nAttributePos |
180 | | * @return given attribute. |
181 | | */ |
182 | 0 | void setAttribute(const SmMlAttribute& aAttribute) { setAttribute(&aAttribute); } |
183 | | |
184 | | /** Checks if an attribute has been manually set |
185 | | * @param aElementType |
186 | | */ |
187 | | bool isAttributeSet(SmMlAttributeValueType aAttributeType) const; |
188 | | |
189 | | private: // attributes |
190 | | /** |
191 | | * Gets a given attribute. |
192 | | * If no available returns empty attribute. |
193 | | * @param nAttributePos |
194 | | * @return given attribute. |
195 | | */ |
196 | | const SmMlAttribute* getAttributePointer(size_t nAttributePos) const |
197 | 0 | { |
198 | 0 | return nAttributePos < m_aAttributeList.size() ? &m_aAttributeList[nAttributePos] : nullptr; |
199 | 0 | } |
200 | | |
201 | | /** |
202 | | * Sets a given attribute. |
203 | | * If no available undefined behaviour. |
204 | | * @param nAttributePos |
205 | | * @param aAttribute |
206 | | * @return given attribute. |
207 | | */ |
208 | | void setAttributeForce(size_t nAttributePos, const SmMlAttribute* aAttribute) |
209 | 0 | { |
210 | 0 | m_aAttributeList[nAttributePos].setMlAttributeValue(aAttribute); |
211 | 0 | } |
212 | | |
213 | | public: // sub elements |
214 | | /** |
215 | | * Returns the sub elements count |
216 | | * @return sub elements count |
217 | | */ |
218 | 0 | size_t getSubElementsCount() const { return m_aSubElements.size(); }; |
219 | | |
220 | | /** |
221 | | * Returns a given sub element |
222 | | * @param nPos |
223 | | * @return sub elements |
224 | | */ |
225 | | SmMlElement* getSubElement(size_t nPos) |
226 | 0 | { |
227 | 0 | return nPos < m_aSubElements.size() ? m_aSubElements[nPos] : nullptr; |
228 | 0 | }; |
229 | | |
230 | | /** |
231 | | * Returns a given sub element |
232 | | * @param nPos |
233 | | * @return sub elements |
234 | | */ |
235 | | const SmMlElement* getSubElement(size_t nPos) const |
236 | 0 | { |
237 | 0 | return nPos < m_aSubElements.size() ? m_aSubElements[nPos] : nullptr; |
238 | 0 | }; |
239 | | |
240 | | /** |
241 | | * Sets a given sub element |
242 | | * @param nPos |
243 | | * @param aElement |
244 | | */ |
245 | | void setSubElement(size_t nPos, SmMlElement* aElement); |
246 | | |
247 | | /** |
248 | | * Gets subelement id |
249 | | */ |
250 | 0 | size_t getSubElementId() const { return m_nSubElementId; } |
251 | | |
252 | | /** |
253 | | * Sets subelement id |
254 | | * @param nSubElementId |
255 | | */ |
256 | 0 | void setSubElementId(size_t nSubElementId) { m_nSubElementId = nSubElementId; } |
257 | | |
258 | | public: // parent elements |
259 | | /** |
260 | | * Returns the parent element |
261 | | * @return parent element |
262 | | */ |
263 | 0 | SmMlElement* getParentElement() { return m_aParentElement; }; |
264 | | |
265 | | /** |
266 | | * Returns the parent element |
267 | | * @return parent element |
268 | | */ |
269 | 0 | const SmMlElement* getParentElement() const { return m_aParentElement; }; |
270 | | |
271 | | /** |
272 | | * Sets the parent element |
273 | | * No allocation / free is done. |
274 | | * @param aParentElement |
275 | | */ |
276 | 0 | void setParentElement(SmMlElement* aParentElement) { m_aParentElement = aParentElement; }; |
277 | | |
278 | | public: // text elements |
279 | | /** |
280 | | * Returns the element text |
281 | | */ |
282 | 0 | const OUString& getText() const { return m_aText; }; |
283 | | |
284 | | /** |
285 | | * Returns the element text |
286 | | */ |
287 | 0 | void setText(const OUString& rText) { m_aText = rText; }; |
288 | | }; |
289 | | |
290 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |