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::u16string_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
, {}, {}},
161 {RID_ARALOGX
, RID_SINX_HELP
, {}, {}},
163 {RID_SINX
, RID_SINX_HELP
, {}, {}},
164 {RID_COSX
, RID_COSX_HELP
, {}, {}},
165 {RID_TANX
, RID_TANX_HELP
, {}, {}},
166 {RID_COTX
, RID_COTX_HELP
, {}, {}},
167 {RID_SINHX
, RID_SINHX_HELP
, {}, {}},
168 {RID_COSHX
, RID_COSHX_HELP
, {}, {}},
169 {RID_TANHX
, RID_TANHX_HELP
, {}, {}},
170 {RID_COTHX
, RID_COTHX_HELP
, {}, {}},
172 {RID_ARASINX
, RID_SINX_HELP
, {}, {}},
173 {RID_ARACOSX
, RID_COSX_HELP
, {}, {}},
174 {RID_ARATANX
, RID_TANX_HELP
, {}, {}},
175 {RID_ARACOTX
, RID_COTX_HELP
, {}, {}},
176 {RID_ARASECX
, RID_COTX_HELP
, {}, {}},
177 {RID_ARACSCX
, RID_COTX_HELP
, {}, {}},
178 {RID_ARASINHX
, RID_SINHX_HELP
, {}, {}},
179 {RID_ARACOSHX
, RID_COSHX_HELP
, {}, {}},
180 {RID_ARATANHX
, RID_TANHX_HELP
, {}, {}},
181 {RID_ARACOTHX
, RID_COTHX_HELP
, {}, {}},
182 {RID_ARASECHX
, RID_COTX_HELP
, {}, {}},
183 {RID_ARACSCHX
, RID_COTX_HELP
, {}, {}},
185 {RID_ARASIN2X
, RID_SINX_HELP
, {}, {}},
186 {RID_ARACOS2X
, RID_COSX_HELP
, {}, {}},
187 {RID_ARATAN2X
, RID_TANX_HELP
, {}, {}},
188 {RID_ARACOT2X
, RID_COTX_HELP
, {}, {}},
189 {RID_ARASEC2X
, RID_COTX_HELP
, {}, {}},
190 {RID_ARACSC2X
, RID_COTX_HELP
, {}, {}},
191 {RID_ARASINH2X
, RID_SINHX_HELP
, {}, {}},
192 {RID_ARACOSH2X
, RID_COSHX_HELP
, {}, {}},
193 {RID_ARATANH2X
, RID_TANHX_HELP
, {}, {}},
194 {RID_ARACOTH2X
, RID_COTHX_HELP
, {}, {}},
195 {RID_ARASECH2X
, RID_COTX_HELP
, {}, {}},
196 {RID_ARACSCH2X
, RID_COTX_HELP
, {}, {}},
198 {RID_ARCSINX
, RID_ARCSINX_HELP
, {}, {}},
199 {RID_ARCCOSX
, RID_ARCCOSX_HELP
, {}, {}},
200 {RID_ARCTANX
, RID_ARCTANX_HELP
, {}, {}},
201 {RID_ARCCOTX
, RID_ARCCOTX_HELP
, {}, {}},
202 {RID_ARSINHX
, RID_ARSINHX_HELP
, {}, {}},
203 {RID_ARCOSHX
, RID_ARCOSHX_HELP
, {}, {}},
204 {RID_ARTANHX
, RID_ARTANHX_HELP
, {}, {}},
205 {RID_ARCOTHX
, RID_ARCOTHX_HELP
, {}, {}},
207 {RID_FUNCX
, RID_FUNCX_HELP
, {}, {}},
210 const SmElementDescr s_a5OperatorsList
[] =
212 {RID_LIMX
, RID_LIMX_HELP
, {}, {}},
213 {RID_LIM_FROMX
, RID_LIM_FROMX_HELP
, {}, {}},
214 {RID_LIM_TOX
, RID_LIM_TOX_HELP
, {}, {}},
215 {RID_LIM_FROMTOX
, RID_LIM_FROMTOX_HELP
, {}, {}},
217 {RID_LIMINFX
, RID_LIMINFX_HELP
, {}, {}},
218 {RID_LIMINF_FROMX
, RID_LIMINF_FROMX_HELP
, {}, {}},
219 {RID_LIMINF_TOX
, RID_LIMINF_TOX_HELP
, {}, {}},
220 {RID_LIMINF_FROMTOX
, RID_LIMINF_FROMTOX_HELP
, {}, {}},
222 {RID_LIMSUPX
, RID_LIMSUPX_HELP
, {}, {}},
223 {RID_LIMSUP_FROMX
, RID_LIMSUP_FROMX_HELP
, {}, {}},
224 {RID_LIMSUP_TOX
, RID_LIMSUP_TOX_HELP
, {}, {}},
225 {RID_LIMSUP_FROMTOX
, RID_LIMSUP_FROMTOX_HELP
, {}, {}},
227 {RID_HADDX
, RID_HADDX_HELP
, {}, {}},
228 {RID_HADD_FROMX
, RID_HADD_FROMX_HELP
, {}, {}},
229 {RID_HADD_TOX
, RID_HADD_TOX_HELP
, {}, {}},
230 {RID_HADD_FROMTOX
, RID_HADD_FROMTOX_HELP
, {}, {}},
232 {RID_SUMX
, RID_SUMX_HELP
, {}, {}},
233 {RID_SUM_FROMX
, RID_SUM_FROMX_HELP
, {}, {}},
234 {RID_SUM_TOX
, RID_SUM_TOX_HELP
, {}, {}},
235 {RID_SUM_FROMTOX
, RID_SUM_FROMTOX_HELP
, {}, {}},
237 {RID_MAJX
, RID_MAJX_HELP
, {}, {}},
238 {RID_MAJ_FROMX
, RID_MAJ_FROMX_HELP
, {}, {}},
239 {RID_MAJ_TOX
, RID_MAJ_TOX_HELP
, {}, {}},
240 {RID_MAJ_FROMTOX
, RID_MAJ_FROMTOX_HELP
, {}, {}},
242 {RID_PRODX
, RID_PRODX_HELP
, {}, {}},
243 {RID_PROD_FROMX
, RID_PROD_FROMX_HELP
, {}, {}},
244 {RID_PROD_TOX
, RID_PROD_TOX_HELP
, {}, {}},
245 {RID_PROD_FROMTOX
, RID_PROD_FROMTOX_HELP
, {}, {}},
247 {RID_COPRODX
, RID_COPRODX_HELP
, {}, {}},
248 {RID_COPROD_FROMX
, RID_COPROD_FROMX_HELP
, {}, {}},
249 {RID_COPROD_TOX
, RID_COPROD_TOX_HELP
, {}, {}},
250 {RID_COPROD_FROMTOX
, RID_COPROD_FROMTOX_HELP
, {}, {}},
252 {RID_INTX
, RID_INTX_HELP
, {}, {}},
253 {RID_INT_FROMX
, RID_INT_FROMX_HELP
, {}, {}},
254 {RID_INT_TOX
, RID_INT_TOX_HELP
, {}, {}},
255 {RID_INT_FROMTOX
, RID_INT_FROMTOX_HELP
, {}, {}},
257 {RID_IINTX
, RID_IINTX_HELP
, {}, {}},
258 {RID_IINT_FROMX
, RID_IINT_FROMX_HELP
, {}, {}},
259 {RID_IINT_TOX
, RID_IINT_TOX_HELP
, {}, {}},
260 {RID_IINT_FROMTOX
, RID_IINT_FROMTOX_HELP
, {}, {}},
262 {RID_IIINTX
, RID_IIINTX_HELP
, {}, {}},
263 {RID_IIINT_FROMX
, RID_IIINT_FROMX_HELP
, {}, {}},
264 {RID_IIINT_TOX
, RID_IIINT_TOX_HELP
, {}, {}},
265 {RID_IIINT_FROMTOX
, RID_IIINT_FROMTOX_HELP
, {}, {}},
267 {RID_LINTX
, RID_LINTX_HELP
, {}, {}},
268 {RID_LINT_FROMX
, RID_LINT_FROMX_HELP
, {}, {}},
269 {RID_LINT_TOX
, RID_LINT_TOX_HELP
, {}, {}},
270 {RID_LINT_FROMTOX
, RID_LINT_FROMTOX_HELP
, {}, {}},
272 {RID_LLINTX
, RID_LLINTX_HELP
, {}, {}},
273 {RID_LLINT_FROMX
, RID_LLINT_FROMX_HELP
, {}, {}},
274 {RID_LLINT_TOX
, RID_LLINT_TOX_HELP
, {}, {}},
275 {RID_LLINT_FROMTOX
, RID_LLINT_FROMTOX_HELP
, {}, {}},
277 {RID_LLLINTX
, RID_LLLINTX_HELP
, {}, {}},
278 {RID_LLLINT_FROMX
, RID_LLLINT_FROMX_HELP
, {}, {}},
279 {RID_LLLINT_TOX
, RID_LLLINT_TOX_HELP
, {}, {}},
280 {RID_LLLINT_FROMTOX
, RID_LLLINT_FROMTOX_HELP
, {}, {}},
282 {RID_OPERX
, RID_OPERX_HELP
, u
"oper \xE22B <?>", {}},
283 {RID_OPER_FROMX
, RID_OPER_FROMX_HELP
, u
"oper \xE22B from <?> <?>", {}},
284 {RID_OPER_TOX
, RID_OPER_TOX_HELP
, u
"oper \xE22B to <?> <?>", {}},
285 {RID_OPER_FROMTOX
, RID_OPER_FROMTOX_HELP
, u
"oper \xE22B from <?> to <?> <?>", {}},
288 const SmElementDescr s_a5AttributesList
[] =
290 {RID_ACUTEX
, RID_ACUTEX_HELP
, {}, {}},
291 {RID_GRAVEX
, RID_GRAVEX_HELP
, {}, {}},
292 {RID_BREVEX
, RID_BREVEX_HELP
, {}, {}},
293 {RID_CIRCLEX
, RID_CIRCLEX_HELP
, {}, {}},
294 {RID_DOTX
, RID_DOTX_HELP
, {}, {}},
295 {RID_DDOTX
, RID_DDOTX_HELP
, {}, {}},
296 {RID_DDDOTX
, RID_DDDOTX_HELP
, {}, {}},
297 {RID_BARX
, RID_BARX_HELP
, {}, {}},
298 {RID_VECX
, RID_VECX_HELP
, {}, {}},
299 {RID_HARPOONX
, RID_HARPOONX_HELP
, {}, {}},
300 {RID_TILDEX
, RID_TILDEX_HELP
, {}, {}},
301 {RID_HATX
, RID_HATX_HELP
, {}, {}},
302 {RID_CHECKX
, RID_CHECKX_HELP
, {}, {}},
304 {RID_WIDEVECX
, RID_WIDEVECX_HELP
, {}, {}},
305 {RID_WIDEHARPOONX
, RID_WIDEHARPOONX_HELP
, {}, {}},
306 {RID_WIDETILDEX
, RID_WIDETILDEX_HELP
, {}, {}},
307 {RID_WIDEHATX
, RID_WIDEHATX_HELP
, {}, {}},
308 {RID_OVERLINEX
, RID_OVERLINEX_HELP
, {}, {}},
309 {RID_UNDERLINEX
, RID_UNDERLINEX_HELP
, {}, {}},
310 {RID_OVERSTRIKEX
, RID_OVERSTRIKEX_HELP
, {}, {}},
312 {RID_PHANTOMX
, RID_PHANTOMX_HELP
, u
"\"$1\"", STR_HIDE
},
313 {RID_BOLDX
, RID_BOLDX_HELP
, u
"bold B", {}},
314 {RID_ITALX
, RID_ITALX_HELP
, u
"ital I", {}},
315 {RID_SIZEXY
, RID_SIZEXY_HELP
, u
"\"$1\"", STR_SIZE
},
316 {RID_FONTXY
, RID_FONTXY_HELP
, u
"\"$1\"", STR_FONT
},
318 {RID_COLORX_BLACK
, RID_COLORX_BLACK_HELP
, u
"color black { \"$1\" }", STR_BLACK
},
319 {RID_COLORX_BLUE
, RID_COLORX_BLUE_HELP
, u
"color blue { \"$1\" }", STR_BLUE
},
320 {RID_COLORX_GREEN
, RID_COLORX_GREEN_HELP
, u
"color green { \"$1\" }", STR_GREEN
},
321 {RID_COLORX_RED
, RID_COLORX_RED_HELP
, u
"color red { \"$1\" }", STR_RED
},
322 {RID_COLORX_AQUA
, RID_COLORX_AQUA_HELP
, u
"color aqua { \"$1\" }", STR_AQUA
},
323 {RID_COLORX_FUCHSIA
, RID_COLORX_FUCHSIA_HELP
, u
"color fuchsia { \"$1\" }", STR_FUCHSIA
},
324 {RID_COLORX_YELLOW
, RID_COLORX_YELLOW_HELP
, u
"color yellow { \"$1\" }", STR_YELLOW
},
325 {RID_COLORX_GRAY
, RID_COLORX_GRAY_HELP
, u
"color gray { \"$1\" }", STR_GRAY
},
326 {RID_COLORX_LIME
, RID_COLORX_LIME_HELP
, u
"color lime { \"$1\" }", STR_LIME
},
327 {RID_COLORX_MAROON
, RID_COLORX_MAROON_HELP
, u
"color maroon { \"$1\" }", STR_MAROON
},
328 {RID_COLORX_NAVY
, RID_COLORX_NAVY_HELP
, u
"color navy { \"$1\" }", STR_NAVY
},
329 {RID_COLORX_OLIVE
, RID_COLORX_OLIVE_HELP
, u
"color olive { \"$1\" }", STR_OLIVE
},
330 {RID_COLORX_PURPLE
, RID_COLORX_PURPLE_HELP
, u
"color purple { \"$1\" }", STR_PURPLE
},
331 {RID_COLORX_SILVER
, RID_COLORX_SILVER_HELP
, u
"color silver { \"$1\" }", STR_SILVER
},
332 {RID_COLORX_TEAL
, RID_COLORX_TEAL_HELP
, u
"color teal { \"$1\" }", STR_TEAL
},
333 {RID_COLORX_RGB
, RID_COLORX_RGB_HELP
, u
"color rgb 0 0 0 { \"$1\" }", STR_RGB
},
334 //{RID_COLORX_RGBA, RID_COLORX_RGBA_HELP, u"color rgba 0 0 0 0 { \"$1\" }", STR_RGBA},
335 {RID_COLORX_HEX
, RID_COLORX_HEX_HELP
, u
"color hex 000000 { \"$1\" }", STR_HEX
},
337 {RID_COLORX_CORAL
, RID_COLORX_CORAL_HELP
, u
"color coral { \"$1\" }", STR_CORAL
},
338 {RID_COLORX_MIDNIGHT
, RID_COLORX_MIDNIGHT_HELP
, u
"color midnightblue { \"$1\" }", STR_MIDNIGHT
},
339 {RID_COLORX_CRIMSON
, RID_COLORX_CRIMSON_HELP
, u
"color crimson { \"$1\" }", STR_CRIMSON
},
340 {RID_COLORX_VIOLET
, RID_COLORX_VIOLET_HELP
, u
"color violet { \"$1\" }", STR_VIOLET
},
341 {RID_COLORX_ORANGE
, RID_COLORX_ORANGE_HELP
, u
"color orange { \"$1\" }", STR_ORANGE
},
342 {RID_COLORX_ORANGERED
, RID_COLORX_ORANGERED_HELP
, u
"color orangered { \"$1\" }", STR_ORANGERED
},
343 {RID_COLORX_SEAGREEN
, RID_COLORX_SEAGREEN_HELP
, u
"color seagreen { \"$1\" }", STR_SEAGREEN
},
344 {RID_COLORX_INDIGO
, RID_COLORX_INDIGO_HELP
, u
"color indigo { \"$1\" }", STR_INDIGO
},
345 {RID_COLORX_HOTPINK
, RID_COLORX_HOTPINK_HELP
, u
"color hotpink { \"$1\" }", STR_HOTPINK
},
346 {RID_COLORX_LAVENDER
, RID_COLORX_LAVENDER_HELP
, u
"color lavender { \"$1\" }", STR_LAVENDER
},
347 {RID_COLORX_SNOW
, RID_COLORX_SNOW_HELP
, u
"color snow { \"$1\" }", STR_SNOW
},
350 const SmElementDescr s_a5BracketsList
[] =
352 {RID_LRGROUPX
, RID_LRGROUPX_HELP
, {}, {}},
354 {RID_LRPARENTX
, RID_LRPARENTX_HELP
, {}, {}},
355 {RID_LRBRACKETX
, RID_LRBRACKETX_HELP
, {}, {}},
356 {RID_LRDBRACKETX
, RID_LRDBRACKETX_HELP
, {}, {}},
357 {RID_LRBRACEX
, RID_LRBRACEX_HELP
, {}, {}},
358 {RID_LRANGLEX
, RID_LRANGLEX_HELP
, {}, {}},
359 {RID_LMRANGLEXY
, RID_LMRANGLEXY_HELP
, {}, {}},
360 {RID_LRCEILX
, RID_LRCEILX_HELP
, {}, {}},
361 {RID_LRFLOORX
, RID_LRFLOORX_HELP
, {}, {}},
362 {RID_LRLINEX
, RID_LRLINEX_HELP
, {}, {}},
363 {RID_LRDLINEX
, RID_LRDLINEX_HELP
, {}, {}},
365 {RID_SLRPARENTX
, RID_SLRPARENTX_HELP
, u
"left ( binom{<?>}{<?>} right )", {}},
366 {RID_SLRBRACKETX
, RID_SLRBRACKETX_HELP
, u
"left [ binom{<?>}{<?>} right ]", {}},
367 {RID_SLRDBRACKETX
, RID_SLRDBRACKETX_HELP
, u
"left ldbracket binom{<?>}{<?>} right rdbracket", {}},
368 {RID_SLRBRACEX
, RID_SLRBRACEX_HELP
, u
"left lbrace binom{<?>}{<?>} right rbrace", {}},
369 {RID_SLRANGLEX
, RID_SLRANGLEX_HELP
, u
"left langle binom{<?>}{<?>} right rangle", {}},
370 {RID_SLMRANGLEXY
, RID_SLMRANGLEXY_HELP
, u
"left langle binom{<?>}{<?>} mline binom{<?>}{<?>} right rangle", {}},
371 {RID_SLRCEILX
, RID_SLRCEILX_HELP
, u
"left lceil binom{<?>}{<?>} right rceil", {}},
372 {RID_SLRFLOORX
, RID_SLRFLOORX_HELP
, u
"left lfloor binom{<?>}{<?>} right rfloor", {}},
373 {RID_SLRLINEX
, RID_SLRLINEX_HELP
, u
"left lline binom{<?>}{<?>} right rline", {}},
374 {RID_SLRDLINEX
, RID_SLRDLINEX_HELP
, u
"left ldline binom{<?>}{<?>} right rdline", {}},
376 {RID_XOVERBRACEY
, RID_XOVERBRACEY_HELP
, u
"{<?><?><?>} overbrace {<?>}", {}},
377 {RID_XUNDERBRACEY
, RID_XUNDERBRACEY_HELP
, u
"{<?><?><?>} underbrace {<?>} ", {}},
379 {RID_EVALX
, RID_EVALUATEX_HELP
, {}, {}},
380 {RID_EVAL_FROMX
, RID_EVALUATE_FROMX_HELP
, {}, {}},
381 {RID_EVAL_TOX
, RID_EVALUATE_TOX_HELP
, {}, {}},
382 {RID_EVAL_FROMTOX
, RID_EVALUATE_FROMTOX_HELP
, {}, {}},
385 const SmElementDescr s_a5FormatsList
[] =
387 {RID_RSUPX
, RID_RSUPX_HELP
, {}, {}},
388 {RID_RSUBX
, RID_RSUBX_HELP
, {}, {}},
389 {RID_LSUPX
, RID_LSUPX_HELP
, {}, {}},
390 {RID_LSUBX
, RID_LSUBX_HELP
, {}, {}},
391 {RID_CSUPX
, RID_CSUPX_HELP
, {}, {}},
392 {RID_CSUBX
, RID_CSUBX_HELP
, {}, {}},
394 {RID_NEWLINE
, RID_NEWLINE_HELP
, u
"\u21B5", {}},
395 {RID_SBLANK
, RID_SBLANK_HELP
, u
"\"`\"", {}},
396 {RID_BLANK
, RID_BLANK_HELP
, u
"\"~\"", {}},
397 {RID_NOSPACE
, RID_NOSPACE_HELP
, {}, {}},
398 {RID_ALIGNLX
, RID_ALIGNLX_HELP
, u
"\"$1\"", STR_ALIGN_LEFT
},
399 {RID_ALIGNCX
, RID_ALIGNCX_HELP
, u
"\"$1\"", STR_ALIGN_CENTER
},
400 {RID_ALIGNRX
, RID_ALIGNRX_HELP
, u
"\"$1\"", STR_ALIGN_RIGHT
},
402 {RID_BINOMXY
, RID_BINOMXY_HELP
, {}, {}},
403 {RID_STACK
, RID_STACK_HELP
, {}, {}},
404 {RID_MATRIX
, RID_MATRIX_HELP
, {}, {}},
407 const SmElementDescr s_a5OthersList
[] =
409 {RID_INFINITY
, RID_INFINITY_HELP
, {}, {}},
410 {RID_PARTIAL
, RID_PARTIAL_HELP
, {}, {}},
411 {RID_NABLA
, RID_NABLA_HELP
, {}, {}},
412 {RID_EXISTS
, RID_EXISTS_HELP
, {}, {}},
413 {RID_NOTEXISTS
, RID_NOTEXISTS_HELP
, {}, {}},
414 {RID_FORALL
, RID_FORALL_HELP
, {}, {}},
415 {RID_HBAR
, RID_HBAR_HELP
, {}, {}},
416 {RID_LAMBDABAR
, RID_LAMBDABAR_HELP
, {}, {}},
417 {RID_RE
, RID_RE_HELP
, {}, {}},
418 {RID_IM
, RID_IM_HELP
, {}, {}},
419 {RID_WP
, RID_WP_HELP
, {}, {}},
420 {RID_LAPLACE
, RID_LAPLACE_HELP
, {}, {}},
421 {RID_FOURIER
, RID_FOURIER_HELP
, {}, {}},
422 {RID_BACKEPSILON
, RID_BACKEPSILON_HELP
, {}, {}},
424 {RID_LEFTARROW
, RID_LEFTARROW_HELP
, {}, {}},
425 {RID_RIGHTARROW
, RID_RIGHTARROW_HELP
, {}, {}},
426 {RID_UPARROW
, RID_UPARROW_HELP
, {}, {}},
427 {RID_DOWNARROW
, RID_DOWNARROW_HELP
, {}, {}},
429 {RID_DOTSLOW
, RID_DOTSLOW_HELP
, {}, {}},
430 {RID_DOTSAXIS
, RID_DOTSAXIS_HELP
, {}, {}},
431 {RID_DOTSVERT
, RID_DOTSVERT_HELP
, {}, {}},
432 {RID_DOTSUP
, RID_DOTSUP_HELP
, {}, {}},
433 {RID_DOTSDOWN
, RID_DOTSDOWN_HELP
, {}, {}},
436 const SmElementDescr s_a5ExamplesList
[] =
438 {u
"{func e}^{i %pi} + 1 = 0", RID_EXAMPLE_EULER_IDENTITY_HELP
, {}, {}},
439 {u
"C = %pi cdot d = 2 cdot %pi cdot r", RID_EXAMPLE_CIRCUMFERENCE_HELP
, {}, {}},
440 {u
"c = sqrt{ a^2 + b^2 }", RID_EXAMPLE_PYTHAGOREAN_THEO_HELP
, {}, {}},
441 {u
"vec F = m times vec a", RID_EXAMPLE_2NEWTON
, {}, {}},
442 {u
"E = m c^2", RID_EXAMPLE_MASS_ENERGY_EQUIV_HELP
, {}, {}},
443 {u
"G_{%mu %nu} + %LAMBDA g_{%mu %nu}= frac{8 %pi G}{c^4} T_{%mu %nu}", RID_EXAMPLE_GENERAL_RELATIVITY_HELP
, {}, {}},
444 {u
"%DELTA t' = { %DELTA t } over sqrt{ 1 - v^2 over c^2 }", RID_EXAMPLE_SPECIAL_RELATIVITY_HELP
, {}, {}},
445 {u
"d over dt left( {partial L}over{partial dot q} right) = {partial L}over{partial q}", RID_EXAMPLE_EULER_LAGRANGE_HELP
, {}, {}},
446 {u
"int from a to b f'(x) dx = f(b) - f(a)", RID_EXAMPLE_FTC_HELP
, {}, {}},
447 {u
"ldline %delta bold{r}(t) rdline approx e^{%lambda t} ldline %delta { bold{r} }_0 rdline", RID_EXAMPLE_CHAOS_HELP
, {}, {}},
448 {u
"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
, {}, {}},
449 {u
"f(x) = {1} over { %sigma sqrt{2 %pi} } func e^-{ {(x-%mu)^2} over {2 %sigma^2} }", RID_EXAMPLE_GAUSS_DISTRIBUTION_HELP
, {}, {}},
452 const std::vector
<TranslateId
> s_a5Categories
{
453 RID_CATEGORY_UNARY_BINARY_OPERATORS
,
454 RID_CATEGORY_RELATIONS
,
455 RID_CATEGORY_SET_OPERATIONS
,
456 RID_CATEGORY_FUNCTIONS
,
457 RID_CATEGORY_OPERATORS
,
458 RID_CATEGORY_ATTRIBUTES
,
459 RID_CATEGORY_BRACKETS
,
460 RID_CATEGORY_FORMATS
,
462 RID_CATEGORY_EXAMPLES
,
463 RID_CATEGORY_USERDEFINED
,
467 constexpr std::pair
<const SmElementDescr
*, size_t> asPair(const SmElementDescr (&category
)[N
])
469 return { category
, N
};
472 const std::vector
<std::pair
<const SmElementDescr
*, size_t>> s_a5CategoryDescriptions
{
473 { asPair(s_a5UnaryBinaryOperatorsList
) },
474 { asPair(s_a5RelationsList
) },
475 { asPair(s_a5SetOperationsList
) },
476 { asPair(s_a5FunctionsList
) },
477 { asPair(s_a5OperatorsList
) },
478 { asPair(s_a5AttributesList
) },
479 { asPair(s_a5BracketsList
) },
480 { asPair(s_a5FormatsList
) },
481 { asPair(s_a5OthersList
) },
482 { asPair(s_a5ExamplesList
) },
488 const std::vector
<TranslateId
>& SmElementsControl::categories()
490 return s_a5Categories
;
495 OUString maElementSource
;
498 ElementData(const OUString
& aElementSource
, const OUString
& aHelpText
, const int& aPos
)
499 : maElementSource(aElementSource
)
500 , maHelpText(aHelpText
)
506 SmElementsControl::SmElementsControl(std::unique_ptr
<weld::IconView
> pIconView
,
507 std::unique_ptr
<weld::Menu
> pMenu
)
508 : mpDocShell(new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT
))
509 , mnCurrentSetIndex(-1)
510 , m_nSmSyntaxVersion(SmModule::get()->GetConfig()->GetDefaultSmSyntaxVersion())
511 , m_bAllowDelete(false)
512 , mpIconView(std::move(pIconView
))
513 , mxPopup(std::move(pMenu
))
515 maParser
.reset(starmathdatabase::GetVersionSmParser(m_nSmSyntaxVersion
));
516 maParser
->SetImportSymbolNames(true);
518 mpIconView
->connect_query_tooltip(LINK(this, SmElementsControl
, QueryTooltipHandler
));
519 mpIconView
->connect_item_activated(LINK(this, SmElementsControl
, ElementActivatedHandler
));
520 mpIconView
->connect_mouse_press(LINK(this, SmElementsControl
, MousePressHdl
));
523 SmElementsControl::~SmElementsControl()
525 mpDocShell
->DoClose();
528 Color
SmElementsControl::GetTextColor()
530 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
531 return rStyleSettings
.GetFieldTextColor();
534 Color
SmElementsControl::GetControlBackground()
536 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
537 return rStyleSettings
.GetFieldColor();
542 // SmTmpDevice::GetTextColor assumes a fg/bg of svtools::FONTCOLOR/svtools::DOCCOLOR
543 // here replace COL_AUTO with the desired fg color, alternatively could add something
544 // to SmTmpDevice to override its defaults
545 class AutoColorVisitor
: public SmDefaultingVisitor
550 AutoColorVisitor(SmNode
* pNode
, Color aAutoColor
)
551 : m_aAutoColor(aAutoColor
)
555 virtual void DefaultVisit(SmNode
* pNode
) override
557 if (pNode
->GetFont().GetColor() == COL_AUTO
)
558 pNode
->GetFont().SetColor(m_aAutoColor
);
559 size_t nNodes
= pNode
->GetNumSubNodes();
560 for (size_t i
= 0; i
< nNodes
; ++i
)
562 SmNode
* pChild
= pNode
->GetSubNode(i
);
565 DefaultVisit(pChild
);
571 void SmElementsControl::addElement(const OUString
& aElementVisual
, const OUString
& aElementSource
, const OUString
& aHelpText
)
573 std::unique_ptr
<SmNode
> pNode
= maParser
->ParseExpression(aElementVisual
);
574 ScopedVclPtr
<VirtualDevice
> pDevice(mpIconView
->create_virtual_device());
575 pDevice
->SetMapMode(MapMode(SmMapUnit()));
576 pDevice
->SetDrawMode(DrawModeFlags::Default
);
577 pDevice
->SetLayoutMode(vcl::text::ComplexTextLayoutFlags::Default
);
578 pDevice
->SetDigitLanguage(LANGUAGE_ENGLISH
);
579 pDevice
->EnableRTL(false);
581 pDevice
->SetBackground(GetControlBackground());
582 pDevice
->SetTextColor(GetTextColor());
584 pNode
->Prepare(maFormat
, *mpDocShell
, 0);
585 pNode
->SetSize(Fraction(10,8));
586 pNode
->Arrange(*pDevice
, maFormat
);
588 AutoColorVisitor(pNode
.get(), GetTextColor());
590 Size aSize
= pDevice
->LogicToPixel(Size(pNode
->GetWidth(), pNode
->GetHeight()));
591 aSize
.extendBy(10, 0); // Add 5 pixels from both sides to accommodate extending parts of italics
592 pDevice
->SetOutputSizePixel(aSize
);
593 SmDrawingVisitor(*pDevice
, pDevice
->PixelToLogic(Point(5, 0)), pNode
.get(), maFormat
);
595 maItemDatas
.push_back(std::make_unique
<ElementData
>(aElementSource
, aHelpText
, maItemDatas
.size()));
596 const OUString
aId(weld::toId(maItemDatas
.back().get()));
597 mpIconView
->insert(-1, nullptr, &aId
, pDevice
, nullptr);
598 if (mpIconView
->get_item_width() < aSize
.Width())
599 mpIconView
->set_item_width(aSize
.Width());
602 OUString
SmElementsControl::GetElementSource(const OUString
& itemId
)
604 return weld::fromId
<ElementData
*>(itemId
)->maElementSource
;
607 OUString
SmElementsControl::GetElementHelpText(const OUString
& itemId
)
609 return weld::fromId
<ElementData
*>(itemId
)->maHelpText
;
612 int SmElementsControl::GetElementPos(const OUString
& itemId
)
614 return weld::fromId
<ElementData
*>(itemId
)->maPos
;
617 void SmElementsControl::setElementSetIndex(int nSetIndex
, bool bForceBuild
)
619 if (!bForceBuild
&& mnCurrentSetIndex
== nSetIndex
)
621 mnCurrentSetIndex
= nSetIndex
;
625 void SmElementsControl::addElements(int nCategory
)
627 mpIconView
->freeze();
629 mpIconView
->set_item_width(0);
632 if (o3tl::make_unsigned(nCategory
) < s_a5CategoryDescriptions
.size())
634 const auto& [aElementsArray
, aElementsArraySize
] = s_a5CategoryDescriptions
[nCategory
];
636 for (size_t i
= 0; i
< aElementsArraySize
; i
++)
638 const auto& [element
, elementHelp
, elementVisual
, visualTranslatable
] = aElementsArray
[i
];
641 mpIconView
->append_separator({});
645 OUString
aElement(element
);
646 OUString
aVisual(elementVisual
.empty() ? aElement
: OUString(elementVisual
));
647 if (visualTranslatable
)
648 aVisual
= aVisual
.replaceFirst("$1", SmResId(visualTranslatable
));
649 OUString
aHelp(elementHelp
? SmResId(elementHelp
) : OUString());
650 addElement(aVisual
, aElement
, aHelp
);
656 css::uno::Sequence
<OUString
> sNames
= SmModule::get()->GetConfig()->LoadUserDefinedNames();
658 for (int i
= 0; i
< sNames
.getLength(); i
++)
660 SmModule::get()->GetConfig()->GetUserDefinedFormula(sNames
[i
], sFormula
);
661 addElement(sFormula
, sFormula
, sNames
[i
]);
665 mpIconView
->set_size_request(0, 0);
669 void SmElementsControl::build()
671 switch(m_nSmSyntaxVersion
)
674 addElements(mnCurrentSetIndex
);
675 m_sHoveredItem
= "nil"; // if list is empty we must not use the previously hovered item
679 throw std::range_error("parser version limit");
683 void SmElementsControl::setSmSyntaxVersion(sal_Int16 nSmSyntaxVersion
)
685 if( m_nSmSyntaxVersion
!= nSmSyntaxVersion
)
687 m_nSmSyntaxVersion
= nSmSyntaxVersion
;
688 maParser
.reset(starmathdatabase::GetVersionSmParser(nSmSyntaxVersion
));
689 maParser
->SetImportSymbolNames(true);
690 // Be careful, we need the parser in order to build !!!
695 IMPL_LINK(SmElementsControl
, QueryTooltipHandler
, const weld::TreeIter
&, iter
, OUString
)
697 if (const OUString id
= mpIconView
->get_id(iter
); !id
.isEmpty())
700 return GetElementHelpText(id
);
705 IMPL_LINK_NOARG(SmElementsControl
, ElementActivatedHandler
, weld::IconView
&, bool)
707 if (const OUString id
= mpIconView
->get_selected_id(); !id
.isEmpty())
708 maSelectHdlLink
.Call(GetElementSource(id
));
710 mpIconView
->unselect_all();
714 IMPL_LINK(SmElementsControl
, MousePressHdl
, const MouseEvent
&, rEvt
, bool)
716 if (rEvt
.IsRight() && m_bAllowDelete
&& (m_sHoveredItem
!= "nil"))
718 mpIconView
->select( GetElementPos(m_sHoveredItem
) );
719 OUString sElementId
= mpIconView
->get_selected_id();
720 if (!sElementId
.isEmpty())
722 OUString sResponse
= mxPopup
->popup_at_rect(
723 mpIconView
.get(), tools::Rectangle(rEvt
.GetPosPixel(), Size(1, 1)));
724 if (sResponse
== "delete")
726 SmModule::get()->GetConfig()->DeleteUserDefinedFormula( GetElementHelpText(m_sHoveredItem
) );
727 build(); //refresh view
729 mpIconView
->unselect_all();
734 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */