1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <ElementsDockingWindow.hxx>
22 #include <starmath.hrc>
23 #include <strings.hrc>
25 #include <cfgitem.hxx>
29 #include <visitors.hxx>
30 #include <document.hxx>
31 #include <strings.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/sfxmodelfactory.hxx>
35 #include <svl/stritem.hxx>
36 #include <vcl/event.hxx>
37 #include <vcl/settings.hxx>
38 #include <vcl/uitest/eventdescription.hxx>
39 #include <vcl/uitest/logger.hxx>
40 #include <vcl/virdev.hxx>
42 #include <unordered_map>
46 // element, element help, element visual, element visual's translatable
47 typedef std::tuple
<std::string_view
, TranslateId
, std::u16string_view
, TranslateId
> SmElementDescr
;
49 // SmParser 5 elements
51 const SmElementDescr s_a5UnaryBinaryOperatorsList
[] =
53 {RID_PLUSX
, RID_PLUSX_HELP
, {}, {}},
54 {RID_MINUSX
, RID_MINUSX_HELP
, {}, {}},
55 {RID_PLUSMINUSX
, RID_PLUSMINUSX_HELP
, {}, {}},
56 {RID_MINUSPLUSX
, RID_MINUSPLUSX_HELP
, {}, {}},
58 {RID_XPLUSY
, RID_XPLUSY_HELP
, {}, {}},
59 {RID_XMINUSY
, RID_XMINUSY_HELP
, {}, {}},
60 {RID_XCDOTY
, RID_XCDOTY_HELP
, {}, {}},
61 {RID_XTIMESY
, RID_XTIMESY_HELP
, {}, {}},
62 {RID_XSYMTIMESY
, RID_XSYMTIMESY_HELP
, {}, {}},
63 {RID_XOVERY
, RID_XOVERY_HELP
, {}, {}},
64 {RID_FRACXY
, RID_FRACXY_HELP
, {}, {}},
65 {RID_XDIVY
, RID_XDIVY_HELP
, {}, {}},
66 {RID_XSYMDIVIDEY
, RID_XSYMDIVIDEY_HELP
, {}, {}},
67 {RID_XOPLUSY
, RID_XOPLUSY_HELP
, {}, {}},
68 {RID_XOMINUSY
, RID_XOMINUSY_HELP
, {}, {}},
69 {RID_XODOTY
, RID_XODOTY_HELP
, {}, {}},
70 {RID_XOTIMESY
, RID_XOTIMESY_HELP
, {}, {}},
71 {RID_XODIVIDEY
, RID_XODIVIDEY_HELP
, {}, {}},
72 {RID_XCIRCY
, RID_XCIRCY_HELP
, {}, {}},
73 {RID_XWIDESLASHY
, RID_XWIDESLASHY_HELP
, {}, {}},
74 {RID_XWIDEBSLASHY
, RID_XWIDEBSLASHY_HELP
, {}, {}},
76 {RID_NEGX
, RID_NEGX_HELP
, {}, {}},
77 {RID_XANDY
, RID_XANDY_HELP
, {}, {}},
78 {RID_XORY
, RID_XORY_HELP
, {}, {}}
81 const SmElementDescr s_a5RelationsList
[] =
83 {RID_XEQY
, RID_XEQY_HELP
, {}, {}},
84 {RID_XNEQY
, RID_XNEQY_HELP
, {}, {}},
85 {RID_XLTY
, RID_XLTY_HELP
, {}, {}},
86 {RID_XLEY
, RID_XLEY_HELP
, {}, {}},
87 {RID_XLESLANTY
, RID_XLESLANTY_HELP
, {}, {}},
88 {RID_XGTY
, RID_XGTY_HELP
, {}, {}},
89 {RID_XGEY
, RID_XGEY_HELP
, {}, {}},
90 {RID_XGESLANTY
, RID_XGESLANTY_HELP
, {}, {}},
91 {RID_XLLY
, RID_XLLY_HELP
, {}, {}},
92 {RID_XGGY
, RID_XGGY_HELP
, {}, {}},
94 {RID_XAPPROXY
, RID_XAPPROXY_HELP
, {}, {}},
95 {RID_XSIMY
, RID_XSIMY_HELP
, {}, {}},
96 {RID_XSIMEQY
, RID_XSIMEQY_HELP
, {}, {}},
97 {RID_XEQUIVY
, RID_XEQUIVY_HELP
, {}, {}},
98 {RID_XPROPY
, RID_XPROPY_HELP
, {}, {}},
99 {RID_XPARALLELY
, RID_XPARALLELY_HELP
, {}, {}},
100 {RID_XORTHOY
, RID_XORTHOY_HELP
, {}, {}},
101 {RID_XDIVIDESY
, RID_XDIVIDESY_HELP
, {}, {}},
102 {RID_XNDIVIDESY
, RID_XNDIVIDESY_HELP
, {}, {}},
103 {RID_XTOWARDY
, RID_XTOWARDY_HELP
, {}, {}},
104 {RID_XTRANSLY
, RID_XTRANSLY_HELP
, {}, {}},
105 {RID_XTRANSRY
, RID_XTRANSRY_HELP
, {}, {}},
106 {RID_XDEFY
, RID_XDEFY_HELP
, {}, {}},
108 {RID_DLARROW
, RID_DLARROW_HELP
, {}, {}},
109 {RID_DLRARROW
, RID_DLRARROW_HELP
, {}, {}},
110 {RID_DRARROW
, RID_DRARROW_HELP
, {}, {}},
112 {RID_XPRECEDESY
, RID_XPRECEDESY_HELP
, {}, {}},
113 {RID_XSUCCEEDSY
, RID_XSUCCEEDSY_HELP
, {}, {}},
114 {RID_XPRECEDESEQUALY
, RID_XPRECEDESEQUALY_HELP
, {}, {}},
115 {RID_XSUCCEEDSEQUALY
, RID_XSUCCEEDSEQUALY_HELP
, {}, {}},
116 {RID_XPRECEDESEQUIVY
, RID_XPRECEDESEQUIVY_HELP
, {}, {}},
117 {RID_XSUCCEEDSEQUIVY
, RID_XSUCCEEDSEQUIVY_HELP
, {}, {}},
118 {RID_XNOTPRECEDESY
, RID_XNOTPRECEDESY_HELP
, {}, {}},
119 {RID_XNOTSUCCEEDSY
, RID_XNOTSUCCEEDSY_HELP
, {}, {}},
122 const SmElementDescr s_a5SetOperationsList
[] =
124 {RID_XINY
, RID_XINY_HELP
, {}, {}},
125 {RID_XNOTINY
, RID_XNOTINY_HELP
, {}, {}},
126 {RID_XOWNSY
, RID_XOWNSY_HELP
, {}, {}},
128 {RID_XINTERSECTIONY
, RID_XINTERSECTIONY_HELP
, {}, {}},
129 {RID_XUNIONY
, RID_XUNIONY_HELP
, {}, {}},
130 {RID_XSETMINUSY
, RID_XSETMINUSY_HELP
, {}, {}},
131 {RID_XSETQUOTIENTY
, RID_XSETQUOTIENTY_HELP
, {}, {}},
132 {RID_XSUBSETY
, RID_XSUBSETY_HELP
, {}, {}},
133 {RID_XSUBSETEQY
, RID_XSUBSETEQY_HELP
, {}, {}},
134 {RID_XSUPSETY
, RID_XSUPSETY_HELP
, {}, {}},
135 {RID_XSUPSETEQY
, RID_XSUPSETEQY_HELP
, {}, {}},
136 {RID_XNSUBSETY
, RID_XNSUBSETY_HELP
, {}, {}},
137 {RID_XNSUBSETEQY
, RID_XNSUBSETEQY_HELP
, {}, {}},
138 {RID_XNSUPSETY
, RID_XNSUPSETY_HELP
, {}, {}},
139 {RID_XNSUPSETEQY
, RID_XNSUPSETEQY_HELP
, {}, {}},
141 {RID_EMPTYSET
, RID_EMPTYSET_HELP
, {}, {}},
142 {RID_ALEPH
, RID_ALEPH_HELP
, {}, {}},
143 {RID_SETN
, RID_SETN_HELP
, {}, {}},
144 {RID_SETZ
, RID_SETZ_HELP
, {}, {}},
145 {RID_SETQ
, RID_SETQ_HELP
, {}, {}},
146 {RID_SETR
, RID_SETR_HELP
, {}, {}},
147 {RID_SETC
, RID_SETC_HELP
, {}, {}}
150 const SmElementDescr s_a5FunctionsList
[] =
152 {RID_ABSX
, RID_ABSX_HELP
, {}, {}},
153 {RID_FACTX
, RID_FACTX_HELP
, {}, {}},
154 {RID_SQRTX
, RID_SQRTX_HELP
, {}, {}},
155 {RID_NROOTXY
, RID_NROOTXY_HELP
, {}, {}},
156 {RID_RSUPX
, RID_RSUPX_HELP
, {}, {}},
157 {RID_EX
, RID_EX_HELP
, {}, {}},
158 {RID_LNX
, RID_LNX_HELP
, {}, {}},
159 {RID_EXPX
, RID_EXPX_HELP
, {}, {}},
160 {RID_LOGX
, RID_LOGX_HELP
, {}, {}},
162 {RID_SINX
, RID_SINX_HELP
, {}, {}},
163 {RID_COSX
, RID_COSX_HELP
, {}, {}},
164 {RID_TANX
, RID_TANX_HELP
, {}, {}},
165 {RID_COTX
, RID_COTX_HELP
, {}, {}},
166 {RID_SINHX
, RID_SINHX_HELP
, {}, {}},
167 {RID_COSHX
, RID_COSHX_HELP
, {}, {}},
168 {RID_TANHX
, RID_TANHX_HELP
, {}, {}},
169 {RID_COTHX
, RID_COTHX_HELP
, {}, {}},
171 {RID_ARCSINX
, RID_ARCSINX_HELP
, {}, {}},
172 {RID_ARCCOSX
, RID_ARCCOSX_HELP
, {}, {}},
173 {RID_ARCTANX
, RID_ARCTANX_HELP
, {}, {}},
174 {RID_ARCCOTX
, RID_ARCCOTX_HELP
, {}, {}},
175 {RID_ARSINHX
, RID_ARSINHX_HELP
, {}, {}},
176 {RID_ARCOSHX
, RID_ARCOSHX_HELP
, {}, {}},
177 {RID_ARTANHX
, RID_ARTANHX_HELP
, {}, {}},
178 {RID_ARCOTHX
, RID_ARCOTHX_HELP
, {}, {}},
180 {RID_FUNCX
, RID_FUNCX_HELP
, {}, {}},
183 const SmElementDescr s_a5OperatorsList
[] =
185 {RID_LIMX
, RID_LIMX_HELP
, {}, {}},
186 {RID_LIM_FROMX
, RID_LIM_FROMX_HELP
, {}, {}},
187 {RID_LIM_TOX
, RID_LIM_TOX_HELP
, {}, {}},
188 {RID_LIM_FROMTOX
, RID_LIM_FROMTOX_HELP
, {}, {}},
190 {RID_LIMINFX
, RID_LIMINFX_HELP
, {}, {}},
191 {RID_LIMINF_FROMX
, RID_LIMINF_FROMX_HELP
, {}, {}},
192 {RID_LIMINF_TOX
, RID_LIMINF_TOX_HELP
, {}, {}},
193 {RID_LIMINF_FROMTOX
, RID_LIMINF_FROMTOX_HELP
, {}, {}},
195 {RID_LIMSUPX
, RID_LIMSUPX_HELP
, {}, {}},
196 {RID_LIMSUP_FROMX
, RID_LIMSUP_FROMX_HELP
, {}, {}},
197 {RID_LIMSUP_TOX
, RID_LIMSUP_TOX_HELP
, {}, {}},
198 {RID_LIMSUP_FROMTOX
, RID_LIMSUP_FROMTOX_HELP
, {}, {}},
200 {RID_SUMX
, RID_SUMX_HELP
, {}, {}},
201 {RID_SUM_FROMX
, RID_SUM_FROMX_HELP
, {}, {}},
202 {RID_SUM_TOX
, RID_SUM_TOX_HELP
, {}, {}},
203 {RID_SUM_FROMTOX
, RID_SUM_FROMTOX_HELP
, {}, {}},
205 {RID_PRODX
, RID_PRODX_HELP
, {}, {}},
206 {RID_PROD_FROMX
, RID_PROD_FROMX_HELP
, {}, {}},
207 {RID_PROD_TOX
, RID_PROD_TOX_HELP
, {}, {}},
208 {RID_PROD_FROMTOX
, RID_PROD_FROMTOX_HELP
, {}, {}},
210 {RID_COPRODX
, RID_COPRODX_HELP
, {}, {}},
211 {RID_COPROD_FROMX
, RID_COPROD_FROMX_HELP
, {}, {}},
212 {RID_COPROD_TOX
, RID_COPROD_TOX_HELP
, {}, {}},
213 {RID_COPROD_FROMTOX
, RID_COPROD_FROMTOX_HELP
, {}, {}},
215 {RID_INTX
, RID_INTX_HELP
, {}, {}},
216 {RID_INT_FROMX
, RID_INT_FROMX_HELP
, {}, {}},
217 {RID_INT_TOX
, RID_INT_TOX_HELP
, {}, {}},
218 {RID_INT_FROMTOX
, RID_INT_FROMTOX_HELP
, {}, {}},
220 {RID_IINTX
, RID_IINTX_HELP
, {}, {}},
221 {RID_IINT_FROMX
, RID_IINT_FROMX_HELP
, {}, {}},
222 {RID_IINT_TOX
, RID_IINT_TOX_HELP
, {}, {}},
223 {RID_IINT_FROMTOX
, RID_IINT_FROMTOX_HELP
, {}, {}},
225 {RID_IIINTX
, RID_IIINTX_HELP
, {}, {}},
226 {RID_IIINT_FROMX
, RID_IIINT_FROMX_HELP
, {}, {}},
227 {RID_IIINT_TOX
, RID_IIINT_TOX_HELP
, {}, {}},
228 {RID_IIINT_FROMTOX
, RID_IIINT_FROMTOX_HELP
, {}, {}},
230 {RID_LINTX
, RID_LINTX_HELP
, {}, {}},
231 {RID_LINT_FROMX
, RID_LINT_FROMX_HELP
, {}, {}},
232 {RID_LINT_TOX
, RID_LINT_TOX_HELP
, {}, {}},
233 {RID_LINT_FROMTOX
, RID_LINT_FROMTOX_HELP
, {}, {}},
235 {RID_LLINTX
, RID_LLINTX_HELP
, {}, {}},
236 {RID_LLINT_FROMX
, RID_LLINT_FROMX_HELP
, {}, {}},
237 {RID_LLINT_TOX
, RID_LLINT_TOX_HELP
, {}, {}},
238 {RID_LLINT_FROMTOX
, RID_LLINT_FROMTOX_HELP
, {}, {}},
240 {RID_LLLINTX
, RID_LLLINTX_HELP
, {}, {}},
241 {RID_LLLINT_FROMX
, RID_LLLINT_FROMX_HELP
, {}, {}},
242 {RID_LLLINT_TOX
, RID_LLLINT_TOX_HELP
, {}, {}},
243 {RID_LLLINT_FROMTOX
, RID_LLLINT_FROMTOX_HELP
, {}, {}},
245 {RID_OPERX
, RID_OPERX_HELP
, u
"oper \xE22B <?>", {}},
246 {RID_OPER_FROMX
, RID_OPER_FROMX_HELP
, u
"oper \xE22B from <?> <?>", {}},
247 {RID_OPER_TOX
, RID_OPER_TOX_HELP
, u
"oper \xE22B to <?> <?>", {}},
248 {RID_OPER_FROMTOX
, RID_OPER_FROMTOX_HELP
, u
"oper \xE22B from <?> to <?> <?>", {}},
251 const SmElementDescr s_a5AttributesList
[] =
253 {RID_ACUTEX
, RID_ACUTEX_HELP
, {}, {}},
254 {RID_GRAVEX
, RID_GRAVEX_HELP
, {}, {}},
255 {RID_BREVEX
, RID_BREVEX_HELP
, {}, {}},
256 {RID_CIRCLEX
, RID_CIRCLEX_HELP
, {}, {}},
257 {RID_DOTX
, RID_DOTX_HELP
, {}, {}},
258 {RID_DDOTX
, RID_DDOTX_HELP
, {}, {}},
259 {RID_DDDOTX
, RID_DDDOTX_HELP
, {}, {}},
260 {RID_BARX
, RID_BARX_HELP
, {}, {}},
261 {RID_VECX
, RID_VECX_HELP
, {}, {}},
262 {RID_HARPOONX
, RID_HARPOONX_HELP
, {}, {}},
263 {RID_TILDEX
, RID_TILDEX_HELP
, {}, {}},
264 {RID_HATX
, RID_HATX_HELP
, {}, {}},
265 {RID_CHECKX
, RID_CHECKX_HELP
, {}, {}},
267 {RID_WIDEVECX
, RID_WIDEVECX_HELP
, {}, {}},
268 {RID_WIDEHARPOONX
, RID_WIDEHARPOONX_HELP
, {}, {}},
269 {RID_WIDETILDEX
, RID_WIDETILDEX_HELP
, {}, {}},
270 {RID_WIDEHATX
, RID_WIDEHATX_HELP
, {}, {}},
271 {RID_OVERLINEX
, RID_OVERLINEX_HELP
, {}, {}},
272 {RID_UNDERLINEX
, RID_UNDERLINEX_HELP
, {}, {}},
273 {RID_OVERSTRIKEX
, RID_OVERSTRIKEX_HELP
, {}, {}},
275 {RID_PHANTOMX
, RID_PHANTOMX_HELP
, u
"\"$1\"", STR_HIDE
},
276 {RID_BOLDX
, RID_BOLDX_HELP
, u
"bold B", {}},
277 {RID_ITALX
, RID_ITALX_HELP
, u
"ital I", {}},
278 {RID_SIZEXY
, RID_SIZEXY_HELP
, u
"\"$1\"", STR_SIZE
},
279 {RID_FONTXY
, RID_FONTXY_HELP
, u
"\"$1\"", STR_FONT
},
281 {RID_COLORX_BLACK
, RID_COLORX_BLACK_HELP
, u
"color black { \"$1\" }", STR_BLACK
},
282 {RID_COLORX_BLUE
, RID_COLORX_BLUE_HELP
, u
"color blue { \"$1\" }", STR_BLUE
},
283 {RID_COLORX_GREEN
, RID_COLORX_GREEN_HELP
, u
"color green { \"$1\" }", STR_GREEN
},
284 {RID_COLORX_RED
, RID_COLORX_RED_HELP
, u
"color red { \"$1\" }", STR_RED
},
285 {RID_COLORX_AQUA
, RID_COLORX_AQUA_HELP
, u
"color aqua { \"$1\" }", STR_AQUA
},
286 {RID_COLORX_FUCHSIA
, RID_COLORX_FUCHSIA_HELP
, u
"color fuchsia { \"$1\" }", STR_FUCHSIA
},
287 {RID_COLORX_YELLOW
, RID_COLORX_YELLOW_HELP
, u
"color yellow { \"$1\" }", STR_YELLOW
},
288 {RID_COLORX_GRAY
, RID_COLORX_GRAY_HELP
, u
"color gray { \"$1\" }", STR_GRAY
},
289 {RID_COLORX_LIME
, RID_COLORX_LIME_HELP
, u
"color lime { \"$1\" }", STR_LIME
},
290 {RID_COLORX_MAROON
, RID_COLORX_MAROON_HELP
, u
"color maroon { \"$1\" }", STR_MAROON
},
291 {RID_COLORX_NAVY
, RID_COLORX_NAVY_HELP
, u
"color navy { \"$1\" }", STR_NAVY
},
292 {RID_COLORX_OLIVE
, RID_COLORX_OLIVE_HELP
, u
"color olive { \"$1\" }", STR_OLIVE
},
293 {RID_COLORX_PURPLE
, RID_COLORX_PURPLE_HELP
, u
"color purple { \"$1\" }", STR_PURPLE
},
294 {RID_COLORX_SILVER
, RID_COLORX_SILVER_HELP
, u
"color silver { \"$1\" }", STR_SILVER
},
295 {RID_COLORX_TEAL
, RID_COLORX_TEAL_HELP
, u
"color teal { \"$1\" }", STR_TEAL
},
296 {RID_COLORX_RGB
, RID_COLORX_RGB_HELP
, u
"color rgb 0 0 0 { \"$1\" }", STR_RGB
},
297 //{RID_COLORX_RGBA, RID_COLORX_RGBA_HELP, u"color rgba 0 0 0 0 { \"$1\" }", STR_RGBA},
298 {RID_COLORX_HEX
, RID_COLORX_HEX_HELP
, u
"color hex 000000 { \"$1\" }", STR_HEX
},
300 {RID_COLORX_CORAL
, RID_COLORX_CORAL_HELP
, u
"color coral { \"$1\" }", STR_CORAL
},
301 {RID_COLORX_MIDNIGHT
, RID_COLORX_MIDNIGHT_HELP
, u
"color midnightblue { \"$1\" }", STR_MIDNIGHT
},
302 {RID_COLORX_CRIMSON
, RID_COLORX_CRIMSON_HELP
, u
"color crimson { \"$1\" }", STR_CRIMSON
},
303 {RID_COLORX_VIOLET
, RID_COLORX_VIOLET_HELP
, u
"color violet { \"$1\" }", STR_VIOLET
},
304 {RID_COLORX_ORANGE
, RID_COLORX_ORANGE_HELP
, u
"color orange { \"$1\" }", STR_ORANGE
},
305 {RID_COLORX_ORANGERED
, RID_COLORX_ORANGERED_HELP
, u
"color orangered { \"$1\" }", STR_ORANGERED
},
306 {RID_COLORX_SEAGREEN
, RID_COLORX_SEAGREEN_HELP
, u
"color seagreen { \"$1\" }", STR_SEAGREEN
},
307 {RID_COLORX_INDIGO
, RID_COLORX_INDIGO_HELP
, u
"color indigo { \"$1\" }", STR_INDIGO
},
308 {RID_COLORX_HOTPINK
, RID_COLORX_HOTPINK_HELP
, u
"color hotpink { \"$1\" }", STR_HOTPINK
},
309 {RID_COLORX_LAVENDER
, RID_COLORX_LAVENDER_HELP
, u
"color lavender { \"$1\" }", STR_LAVENDER
},
310 {RID_COLORX_SNOW
, RID_COLORX_SNOW_HELP
, u
"color snow { \"$1\" }", STR_SNOW
},
313 const SmElementDescr s_a5BracketsList
[] =
315 {RID_LRGROUPX
, RID_LRGROUPX_HELP
, {}, {}},
317 {RID_LRPARENTX
, RID_LRPARENTX_HELP
, {}, {}},
318 {RID_LRBRACKETX
, RID_LRBRACKETX_HELP
, {}, {}},
319 {RID_LRDBRACKETX
, RID_LRDBRACKETX_HELP
, {}, {}},
320 {RID_LRBRACEX
, RID_LRBRACEX_HELP
, {}, {}},
321 {RID_LRANGLEX
, RID_LRANGLEX_HELP
, {}, {}},
322 {RID_LMRANGLEXY
, RID_LMRANGLEXY_HELP
, {}, {}},
323 {RID_LRCEILX
, RID_LRCEILX_HELP
, {}, {}},
324 {RID_LRFLOORX
, RID_LRFLOORX_HELP
, {}, {}},
325 {RID_LRLINEX
, RID_LRLINEX_HELP
, {}, {}},
326 {RID_LRDLINEX
, RID_LRDLINEX_HELP
, {}, {}},
328 {RID_SLRPARENTX
, RID_SLRPARENTX_HELP
, u
"left ( binom{<?>}{<?>} right )", {}},
329 {RID_SLRBRACKETX
, RID_SLRBRACKETX_HELP
, u
"left [ binom{<?>}{<?>} right ]", {}},
330 {RID_SLRDBRACKETX
, RID_SLRDBRACKETX_HELP
, u
"left ldbracket binom{<?>}{<?>} right rdbracket", {}},
331 {RID_SLRBRACEX
, RID_SLRBRACEX_HELP
, u
"left lbrace binom{<?>}{<?>} right rbrace", {}},
332 {RID_SLRANGLEX
, RID_SLRANGLEX_HELP
, u
"left langle binom{<?>}{<?>} right rangle", {}},
333 {RID_SLMRANGLEXY
, RID_SLMRANGLEXY_HELP
, u
"left langle binom{<?>}{<?>} mline binom{<?>}{<?>} right rangle", {}},
334 {RID_SLRCEILX
, RID_SLRCEILX_HELP
, u
"left lceil binom{<?>}{<?>} right rceil", {}},
335 {RID_SLRFLOORX
, RID_SLRFLOORX_HELP
, u
"left lfloor binom{<?>}{<?>} right rfloor", {}},
336 {RID_SLRLINEX
, RID_SLRLINEX_HELP
, u
"left lline binom{<?>}{<?>} right rline", {}},
337 {RID_SLRDLINEX
, RID_SLRDLINEX_HELP
, u
"left ldline binom{<?>}{<?>} right rdline", {}},
339 {RID_XOVERBRACEY
, RID_XOVERBRACEY_HELP
, u
"{<?><?><?>} overbrace {<?>}", {}},
340 {RID_XUNDERBRACEY
, RID_XUNDERBRACEY_HELP
, u
"{<?><?><?>} underbrace {<?>} ", {}},
342 {RID_EVALX
, RID_EVALUATEX_HELP
, {}, {}},
343 {RID_EVAL_FROMX
, RID_EVALUATE_FROMX_HELP
, {}, {}},
344 {RID_EVAL_TOX
, RID_EVALUATE_TOX_HELP
, {}, {}},
345 {RID_EVAL_FROMTOX
, RID_EVALUATE_FROMTOX_HELP
, {}, {}},
348 const SmElementDescr s_a5FormatsList
[] =
350 {RID_RSUPX
, RID_RSUPX_HELP
, {}, {}},
351 {RID_RSUBX
, RID_RSUBX_HELP
, {}, {}},
352 {RID_LSUPX
, RID_LSUPX_HELP
, {}, {}},
353 {RID_LSUBX
, RID_LSUBX_HELP
, {}, {}},
354 {RID_CSUPX
, RID_CSUPX_HELP
, {}, {}},
355 {RID_CSUBX
, RID_CSUBX_HELP
, {}, {}},
357 {RID_NEWLINE
, RID_NEWLINE_HELP
, u
"\u21B5", {}},
358 {RID_SBLANK
, RID_SBLANK_HELP
, u
"\"`\"", {}},
359 {RID_BLANK
, RID_BLANK_HELP
, u
"\"~\"", {}},
360 {RID_NOSPACE
, RID_NOSPACE_HELP
, {}, {}},
361 {RID_ALIGNLX
, RID_ALIGNLX_HELP
, u
"\"$1\"", STR_ALIGN_LEFT
},
362 {RID_ALIGNCX
, RID_ALIGNCX_HELP
, u
"\"$1\"", STR_ALIGN_CENTER
},
363 {RID_ALIGNRX
, RID_ALIGNRX_HELP
, u
"\"$1\"", STR_ALIGN_RIGHT
},
365 {RID_BINOMXY
, RID_BINOMXY_HELP
, {}, {}},
366 {RID_STACK
, RID_STACK_HELP
, {}, {}},
367 {RID_MATRIX
, RID_MATRIX_HELP
, {}, {}},
370 const SmElementDescr s_a5OthersList
[] =
372 {RID_INFINITY
, RID_INFINITY_HELP
, {}, {}},
373 {RID_PARTIAL
, RID_PARTIAL_HELP
, {}, {}},
374 {RID_NABLA
, RID_NABLA_HELP
, {}, {}},
375 {RID_EXISTS
, RID_EXISTS_HELP
, {}, {}},
376 {RID_NOTEXISTS
, RID_NOTEXISTS_HELP
, {}, {}},
377 {RID_FORALL
, RID_FORALL_HELP
, {}, {}},
378 {RID_HBAR
, RID_HBAR_HELP
, {}, {}},
379 {RID_LAMBDABAR
, RID_LAMBDABAR_HELP
, {}, {}},
380 {RID_RE
, RID_RE_HELP
, {}, {}},
381 {RID_IM
, RID_IM_HELP
, {}, {}},
382 {RID_WP
, RID_WP_HELP
, {}, {}},
383 {RID_LAPLACE
, RID_LAPLACE_HELP
, {}, {}},
384 {RID_FOURIER
, RID_FOURIER_HELP
, {}, {}},
385 {RID_BACKEPSILON
, RID_BACKEPSILON_HELP
, {}, {}},
387 {RID_LEFTARROW
, RID_LEFTARROW_HELP
, {}, {}},
388 {RID_RIGHTARROW
, RID_RIGHTARROW_HELP
, {}, {}},
389 {RID_UPARROW
, RID_UPARROW_HELP
, {}, {}},
390 {RID_DOWNARROW
, RID_DOWNARROW_HELP
, {}, {}},
392 {RID_DOTSLOW
, RID_DOTSLOW_HELP
, {}, {}},
393 {RID_DOTSAXIS
, RID_DOTSAXIS_HELP
, {}, {}},
394 {RID_DOTSVERT
, RID_DOTSVERT_HELP
, {}, {}},
395 {RID_DOTSUP
, RID_DOTSUP_HELP
, {}, {}},
396 {RID_DOTSDOWN
, RID_DOTSDOWN_HELP
, {}, {}},
399 const SmElementDescr s_a5ExamplesList
[] =
401 {"{func e}^{i %pi} + 1 = 0", RID_EXAMPLE_EULER_IDENTITY_HELP
, {}, {}},
402 {"C = %pi cdot d = 2 cdot %pi cdot r", RID_EXAMPLE_CIRCUMFERENCE_HELP
, {}, {}},
403 {"c = sqrt{ a^2 + b^2 }", RID_EXAMPLE_PYTHAGOREAN_THEO_HELP
, {}, {}},
404 {"vec F = m times vec a", RID_EXAMPLE_2NEWTON
, {}, {}},
405 {"E = m c^2", RID_EXAMPLE_MASS_ENERGY_EQUIV_HELP
, {}, {}},
406 {"G_{%mu %nu} + %LAMBDA g_{%mu %nu}= frac{8 %pi G}{c^4} T_{%mu %nu}", RID_EXAMPLE_GENERAL_RELATIVITY_HELP
, {}, {}},
407 {"%DELTA t' = { %DELTA t } over sqrt{ 1 - v^2 over c^2 }", RID_EXAMPLE_SPECIAL_RELATIVITY_HELP
, {}, {}},
408 {"d over dt left( {partial L}over{partial dot q} right) = {partial L}over{partial q}", RID_EXAMPLE_EULER_LAGRANGE_HELP
, {}, {}},
409 {"int from a to b f'(x) dx = f(b) - f(a)", RID_EXAMPLE_FTC_HELP
, {}, {}},
410 {"ldline %delta bold{r}(t) rdline approx e^{%lambda t} ldline %delta { bold{r} }_0 rdline", RID_EXAMPLE_CHAOS_HELP
, {}, {}},
411 {"f(x) = sum from { n=0 } to { infinity } { {f^{(n)}(x_0) } over { fact{n} } (x-x_0)^n }", RID_EXAMPLE_A_TAYLOR_SERIES_HELP
, {}, {}},
412 {"f(x) = {1} over { %sigma sqrt{2 %pi} } func e^-{ {(x-%mu)^2} over {2 %sigma^2} }", RID_EXAMPLE_GAUSS_DISTRIBUTION_HELP
, {}, {}},
415 const std::vector
<TranslateId
> s_a5Categories
{
416 RID_CATEGORY_UNARY_BINARY_OPERATORS
,
417 RID_CATEGORY_RELATIONS
,
418 RID_CATEGORY_SET_OPERATIONS
,
419 RID_CATEGORY_FUNCTIONS
,
420 RID_CATEGORY_OPERATORS
,
421 RID_CATEGORY_ATTRIBUTES
,
422 RID_CATEGORY_BRACKETS
,
423 RID_CATEGORY_FORMATS
,
425 RID_CATEGORY_EXAMPLES
,
429 constexpr std::pair
<const SmElementDescr
*, size_t> asPair(const SmElementDescr (&category
)[N
])
431 return { category
, N
};
434 const std::vector
<std::pair
<const SmElementDescr
*, size_t>> s_a5CategoryDescriptions
{
435 { asPair(s_a5UnaryBinaryOperatorsList
) },
436 { asPair(s_a5RelationsList
) },
437 { asPair(s_a5SetOperationsList
) },
438 { asPair(s_a5FunctionsList
) },
439 { asPair(s_a5OperatorsList
) },
440 { asPair(s_a5AttributesList
) },
441 { asPair(s_a5BracketsList
) },
442 { asPair(s_a5FormatsList
) },
443 { asPair(s_a5OthersList
) },
444 { asPair(s_a5ExamplesList
) },
450 const std::vector
<TranslateId
>& SmElementsControl::categories()
452 return s_a5Categories
;
457 OUString maElementSource
;
459 ElementData(const OUString
& aElementSource
, const OUString
& aHelpText
)
460 : maElementSource(aElementSource
)
461 , maHelpText(aHelpText
)
466 SmElementsControl::SmElementsControl(std::unique_ptr
<weld::IconView
> pIconView
)
467 : mpDocShell(new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT
))
468 , mnCurrentSetIndex(-1)
469 , m_nSmSyntaxVersion(SM_MOD()->GetConfig()->GetDefaultSmSyntaxVersion())
470 , mpIconView(std::move(pIconView
))
472 maParser
.reset(starmathdatabase::GetVersionSmParser(m_nSmSyntaxVersion
));
473 maParser
->SetImportSymbolNames(true);
475 mpIconView
->connect_query_tooltip(LINK(this, SmElementsControl
, QueryTooltipHandler
));
476 mpIconView
->connect_item_activated(LINK(this, SmElementsControl
, ElementActivatedHandler
));
479 SmElementsControl::~SmElementsControl()
481 mpDocShell
->DoClose();
484 Color
SmElementsControl::GetTextColor()
486 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
487 return rStyleSettings
.GetFieldTextColor();
490 Color
SmElementsControl::GetControlBackground()
492 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
493 return rStyleSettings
.GetFieldColor();
498 // SmTmpDevice::GetTextColor assumes a fg/bg of svtools::FONTCOLOR/svtools::DOCCOLOR
499 // here replace COL_AUTO with the desired fg color, alternatively could add something
500 // to SmTmpDevice to override its defaults
501 class AutoColorVisitor
: public SmDefaultingVisitor
506 AutoColorVisitor(SmNode
* pNode
, Color aAutoColor
)
507 : m_aAutoColor(aAutoColor
)
511 virtual void DefaultVisit(SmNode
* pNode
) override
513 if (pNode
->GetFont().GetColor() == COL_AUTO
)
514 pNode
->GetFont().SetColor(m_aAutoColor
);
515 size_t nNodes
= pNode
->GetNumSubNodes();
516 for (size_t i
= 0; i
< nNodes
; ++i
)
518 SmNode
* pChild
= pNode
->GetSubNode(i
);
521 DefaultVisit(pChild
);
527 void SmElementsControl::addElement(const OUString
& aElementVisual
, const OUString
& aElementSource
, const OUString
& aHelpText
)
529 std::unique_ptr
<SmNode
> pNode
= maParser
->ParseExpression(aElementVisual
);
530 ScopedVclPtr
<VirtualDevice
> pDevice(mpIconView
->create_virtual_device());
531 pDevice
->SetMapMode(MapMode(SmMapUnit()));
532 pDevice
->SetDrawMode(DrawModeFlags::Default
);
533 pDevice
->SetLayoutMode(vcl::text::ComplexTextLayoutFlags::Default
);
534 pDevice
->SetDigitLanguage(LANGUAGE_ENGLISH
);
535 pDevice
->EnableRTL(false);
537 pDevice
->SetBackground(GetControlBackground());
538 pDevice
->SetTextColor(GetTextColor());
540 pNode
->Prepare(maFormat
, *mpDocShell
, 0);
541 pNode
->SetSize(Fraction(10,8));
542 pNode
->Arrange(*pDevice
, maFormat
);
544 AutoColorVisitor(pNode
.get(), GetTextColor());
546 Size aSize
= pDevice
->LogicToPixel(Size(pNode
->GetWidth(), pNode
->GetHeight()));
547 aSize
.extendBy(10, 0); // Add 5 pixels from both sides to accommodate extending parts of italics
548 pDevice
->SetOutputSizePixel(aSize
);
549 SmDrawingVisitor(*pDevice
, pDevice
->PixelToLogic(Point(5, 0)), pNode
.get());
551 maItemDatas
.push_back(std::make_unique
<ElementData
>(aElementSource
, aHelpText
));
552 const OUString
aId(weld::toId(maItemDatas
.back().get()));
553 mpIconView
->insert(-1, nullptr, &aId
, pDevice
, nullptr);
554 if (mpIconView
->get_item_width() < aSize
.Width())
555 mpIconView
->set_item_width(aSize
.Width());
558 OUString
SmElementsControl::GetElementSource(const OUString
& itemId
)
560 return weld::fromId
<ElementData
*>(itemId
)->maElementSource
;
563 OUString
SmElementsControl::GetElementHelpText(const OUString
& itemId
)
565 return weld::fromId
<ElementData
*>(itemId
)->maHelpText
;
568 void SmElementsControl::setElementSetIndex(int nSetIndex
)
570 if (mnCurrentSetIndex
== nSetIndex
)
572 mnCurrentSetIndex
= nSetIndex
;
576 void SmElementsControl::addElements(int nCategory
)
578 mpIconView
->freeze();
580 mpIconView
->set_item_width(0);
583 assert(nCategory
>= 0 && o3tl::make_unsigned(nCategory
) < s_a5CategoryDescriptions
.size());
585 const auto& [aElementsArray
, aElementsArraySize
] = s_a5CategoryDescriptions
[nCategory
];
587 for (size_t i
= 0; i
< aElementsArraySize
; i
++)
589 const auto& [element
, elementHelp
, elementVisual
, visualTranslatable
] = aElementsArray
[i
];
592 mpIconView
->append_separator({});
596 OUString
aElement(OUString::createFromAscii(element
));
597 OUString
aVisual(elementVisual
.empty() ? aElement
: OUString(elementVisual
));
598 if (visualTranslatable
)
599 aVisual
= aVisual
.replaceFirst("$1", SmResId(visualTranslatable
));
600 OUString
aHelp(elementHelp
? SmResId(elementHelp
) : OUString());
601 addElement(aVisual
, aElement
, aHelp
);
605 mpIconView
->set_size_request(0, 0);
609 void SmElementsControl::build()
611 switch(m_nSmSyntaxVersion
)
614 addElements(mnCurrentSetIndex
);
618 throw std::range_error("parser version limit");
622 void SmElementsControl::setSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion
)
624 if( m_nSmSyntaxVersion
!= nSmSyntaxVersion
)
626 m_nSmSyntaxVersion
= nSmSyntaxVersion
;
627 maParser
.reset(starmathdatabase::GetVersionSmParser(nSmSyntaxVersion
));
628 maParser
->SetImportSymbolNames(true);
629 // Be careful, we need the parser in order to build !!!
634 IMPL_LINK(SmElementsControl
, QueryTooltipHandler
, const weld::TreeIter
&, iter
, OUString
)
636 if (const OUString id
= mpIconView
->get_id(iter
); !id
.isEmpty())
637 return GetElementHelpText(id
);
641 IMPL_LINK_NOARG(SmElementsControl
, ElementActivatedHandler
, weld::IconView
&, bool)
643 if (const OUString id
= mpIconView
->get_selected_id(); !id
.isEmpty())
644 maSelectHdlLink
.Call(GetElementSource(id
));
646 mpIconView
->unselect_all();
650 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */