]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Dialogs.C
Move xforms' Maths Panel to the new scheme.
[lyx.git] / src / frontends / xforms / Dialogs.C
1 /**
2  * \file xforms/Dialogs.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #include "Dialogs.h"
14 #include "Dialog.h"
15
16 #include "Tooltips.h"
17
18 #include "ControlAboutlyx.h"
19 #include "ControlBibtex.h"
20 #include "ControlChanges.h"
21 #include "ControlCharacter.h"
22 #include "ControlCitation.h"
23 #include "ControlCommand.h"
24 #include "ControlError.h"
25 #include "ControlErrorList.h"
26 #include "ControlERT.h"
27 #include "ControlExternal.h"
28 #include "ControlFloat.h"
29 #include "ControlGraphics.h"
30 #include "ControlInclude.h"
31 #include "ControlLog.h"
32 #include "ControlMath.h"
33 #include "ControlMinipage.h"
34 #include "ControlParagraph.h"
35 #include "ControlRef.h"
36 #include "ControlShowFile.h"
37 #include "ControlTabular.h"
38 #include "ControlTabularCreate.h"
39 #include "ControlToc.h"
40 #include "ControlVCLog.h"
41 #include "ControlWrap.h"
42
43 #include "FormAboutlyx.h"
44 #include "FormBibitem.h"
45 #include "FormBibtex.h"
46 #include "FormChanges.h"
47 #include "FormCharacter.h"
48 #include "FormCitation.h"
49 #include "FormError.h"
50 #include "FormErrorList.h"
51 #include "FormERT.h"
52 #include "FormExternal.h"
53 #include "FormFloat.h"
54 #include "FormGraphics.h"
55 #include "FormInclude.h"
56 #include "FormLog.h"
57 #include "FormMathsPanel.h"
58 #include "FormMathsBitmap.h"
59 #include "FormMathsDelim.h"
60 #include "FormMathsMatrix.h"
61 #include "FormMathsSpace.h"
62 #include "FormMathsStyle.h"
63 #include "FormMinipage.h"
64 #include "FormParagraph.h"
65 #include "FormRef.h"
66 #include "FormTabular.h"
67 #include "FormShowFile.h"
68 #include "FormTabularCreate.h"
69 #include "FormText.h"
70 #include "FormToc.h"
71 #include "FormUrl.h"
72 #include "FormVCLog.h"
73 #include "FormWrap.h"
74
75 #ifdef HAVE_LIBAIKSAURUS
76 #include "ControlThesaurus.h"
77 #include "FormThesaurus.h"
78 #endif
79
80 #include "xformsBC.h"
81 #include "ButtonController.h"
82
83 #include "arrows.xbm"
84 #include "bop.xbm"
85 #include "brel.xbm"
86 #include "deco.xbm"
87 #include "dots.xbm"
88 #include "greek.xbm"
89 #include "misc.xbm"
90 #include "varsz.xbm"
91
92 #include "ams_misc.xbm"
93 #include "ams_arrows.xbm"
94 #include "ams_rel.xbm"
95 #include "ams_nrel.xbm"
96 #include "ams_ops.xbm"
97
98 #include <vector>
99
100
101 namespace {
102
103 FormMathsBitmap * createFormBitmap(Dialog & parent, string const & title,
104                                    char const * const * data, int size)
105 {
106         char const * const * const end = data + size;
107         return new FormMathsBitmap(parent, title, std::vector<string>(data, end));
108 }
109
110
111 char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes",
112 "character", "citation", "error", "errorlist" , "ert", "external", "file",
113 "float", "graphics", "include", "index", "label", "log", "math",
114 "mathaccents", "matharrows", "mathoperators", "mathrelations", "mathgreek",
115 "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc",
116 "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators",
117 "mathdelimiter", "mathmatrix", "mathspace", "mathstyle",
118 "minipage", "paragraph", "ref", "tabular", "tabularcreate",
119
120 #ifdef HAVE_LIBAIKSAURUS
121 "thesaurus",
122 #endif
123
124 "toc", "url", "vclog", "wrap" };
125
126 char const * const * const end_dialognames =
127         dialognames + (sizeof(dialognames) / sizeof(char *));
128
129 struct cmpCStr {
130         cmpCStr(char const * name) : name_(name) {}
131         bool operator()(char const * other) {
132                 return strcmp(other, name_) == 0;
133         }
134 private:
135         char const * name_;
136 };
137
138 } // namespace anon
139
140
141 bool Dialogs::isValidName(string const & name) const
142 {
143         return std::find_if(dialognames, end_dialognames,
144                             cmpCStr(name.c_str())) != end_dialognames;
145 }
146
147
148 Dialog * Dialogs::build(string const & name)
149 {
150         if (!isValidName(name))
151                 return 0;
152
153         Dialog * dialog = new Dialog(lyxview_, name);
154         dialog->bc().view(new xformsBC(dialog->bc()));
155
156         if (name == "about") {
157                 dialog->setController(new ControlAboutlyx(*dialog));
158                 dialog->setView(new FormAboutlyx(*dialog));
159                 dialog->bc().bp(new OkCancelPolicy);
160         } else if (name == "bibitem") {
161                 dialog->setController(new ControlCommand(*dialog, name));
162                 dialog->setView(new FormBibitem(*dialog));
163                 dialog->bc().bp(new OkCancelReadOnlyPolicy);
164         } else if (name == "bibtex") {
165                 dialog->setController(new ControlBibtex(*dialog));
166                 dialog->setView(new FormBibtex(*dialog));
167                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
168         } else if (name == "character") {
169                 dialog->setController(new ControlCharacter(*dialog));
170                 dialog->setView(new FormCharacter(*dialog));
171                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
172         } else if (name == "changes") {
173                 dialog->setController(new ControlChanges(*dialog));
174                 dialog->setView(new FormChanges(*dialog));
175                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
176         } else if (name == "citation") {
177                 dialog->setController(new ControlCitation(*dialog));
178                 dialog->setView(new FormCitation(*dialog));
179                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
180         } else if (name == "error") {
181                 dialog->setController(new ControlError(*dialog));
182                 dialog->setView(new FormError(*dialog));
183                 dialog->bc().bp(new OkCancelPolicy);
184         } else if (name == "errorlist") {
185                 dialog->setController(new ControlErrorList(*dialog));
186                 dialog->setView(new FormErrorList(*dialog));
187                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
188         } else if (name == "ert") {
189                 dialog->setController(new ControlERT(*dialog));
190                 dialog->setView(new FormERT(*dialog));
191                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
192         } else if (name == "external") {
193                 dialog->setController(new ControlExternal(*dialog));
194                 dialog->setView(new FormExternal(*dialog));
195                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
196         } else if (name == "file") {
197                 dialog->setController(new ControlShowFile(*dialog));
198                 dialog->setView(new FormShowFile(*dialog));
199                 dialog->bc().bp(new OkCancelPolicy);
200         } else if (name == "float") {
201                 dialog->setController(new ControlFloat(*dialog));
202                 dialog->setView(new FormFloat(*dialog));
203                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
204         } else if (name == "graphics") {
205                 dialog->setController(new ControlGraphics(*dialog));
206                 dialog->setView(new FormGraphics(*dialog));
207                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
208         } else if (name == "include") {
209                 dialog->setController(new ControlInclude(*dialog));
210                 dialog->setView(new FormInclude(*dialog));
211                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
212         } else if (name == "index") {
213                 dialog->setController(new ControlCommand(*dialog, name));
214                 dialog->setView(new FormText(*dialog,
215                                              _("Index"), _("Keyword:|#K")));
216                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
217         } else if (name == "label") {
218                 dialog->setController(new ControlCommand(*dialog, name));
219                 dialog->setView(new FormText(*dialog,
220                                              _("Label"), _("Label:|#L")));
221                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
222         } else if (name == "log") {
223                 dialog->setController(new ControlLog(*dialog));
224                 dialog->setView(new FormLog(*dialog));
225                 dialog->bc().bp(new OkCancelPolicy);
226
227         } else if (name == "math") {
228                 dialog->setController(new ControlMath(*dialog));
229                 dialog->setView(new FormMathsPanel(*dialog));
230                 dialog->bc().bp(new IgnorantPolicy);
231
232         } else if (name == "mathaccents") {
233                 FormMathsBitmap * bitmap =
234                         createFormBitmap(*dialog, _("Maths Decorations & Accents"),
235                                          latex_deco, nr_latex_deco);
236                 bitmap->addBitmap(
237                         BitmapStore(12, 3, 4, deco1_width, deco1_height, deco1_bits, true));
238                 bitmap->addBitmap(
239                         BitmapStore(10, 4, 3, deco2_width, deco2_height, deco2_bits, true));
240
241                 dialog->setController(new ControlMath(*dialog));
242                 dialog->setView(bitmap);
243                 dialog->bc().bp(new IgnorantPolicy);
244
245         } else if (name == "matharrows") {
246                 FormMathsBitmap * bitmap =
247                         createFormBitmap(*dialog, _("Arrows"), latex_arrow, nr_latex_arrow);
248                 bitmap->addBitmap(
249                         BitmapStore(20, 5, 4, arrow_width,  arrow_height,  arrow_bits, true));
250                 bitmap->addBitmap(
251                         BitmapStore(7,  2, 4, larrow_width, larrow_height, larrow_bits, false));
252                 bitmap->addBitmap(
253                         BitmapStore(4,  2, 2, darrow_width,  darrow_height, darrow_bits, true));
254
255                 dialog->setController(new ControlMath(*dialog));
256                 dialog->setView(bitmap);
257                 dialog->bc().bp(new IgnorantPolicy);
258
259         } else if (name == "mathoperators") {
260                 FormMathsBitmap * bitmap =
261                         createFormBitmap(*dialog, _("Binary Ops"),
262                                          latex_bop, nr_latex_bop);
263                 bitmap->addBitmap(
264                         BitmapStore(31, 4, 8, bop_width, bop_height, bop_bits, true));
265
266                 dialog->setController(new ControlMath(*dialog));
267                 dialog->setView(bitmap);
268                 dialog->bc().bp(new IgnorantPolicy);
269
270         } else if (name == "mathrelations") {
271                 FormMathsBitmap * bitmap =
272                         createFormBitmap(*dialog, _("Binary Relations"),
273                                          latex_brel, nr_latex_brel);
274                 bitmap->addBitmap(
275                         BitmapStore(35, 4, 9, brel_width, brel_height, brel_bits, true));
276
277                 dialog->setController(new ControlMath(*dialog));
278                 dialog->setView(bitmap);
279                 dialog->bc().bp(new IgnorantPolicy);
280
281         } else if (name == "mathgreek") {
282                 FormMathsBitmap * bitmap =
283                         createFormBitmap(*dialog, _("Greek"),
284                                          latex_greek, nr_latex_greek);
285                 bitmap->addBitmap(
286                         BitmapStore(11, 6, 2, Greek_width, Greek_height, Greek_bits, true));
287                 bitmap->addBitmap(
288                         BitmapStore(28, 7, 4, greek_width, greek_height, greek_bits, true));
289
290                 dialog->setController(new ControlMath(*dialog));
291                 dialog->setView(bitmap);
292                 dialog->bc().bp(new IgnorantPolicy);
293
294         } else if (name == "mathmisc") {
295                 FormMathsBitmap * bitmap =
296                         createFormBitmap(*dialog, _("Misc"),
297                                          latex_misc, nr_latex_misc);
298                 bitmap->addBitmap(
299                         BitmapStore(29, 5, 6, misc_width, misc_height, misc_bits, true));
300                 bitmap->addBitmap(
301                         BitmapStore(5, 5, 1, misc4_width, misc4_height, misc4_bits, true));
302                 bitmap->addBitmap(
303                         BitmapStore(6, 3, 2, misc2_width, misc2_height, misc2_bits, false));
304                 bitmap->addBitmap(
305                         BitmapStore(4, 2, 2, misc3_width, misc3_height, misc3_bits, true));
306
307                 dialog->setController(new ControlMath(*dialog));
308                 dialog->setView(bitmap);
309                 dialog->bc().bp(new IgnorantPolicy);
310
311         } else if (name == "mathdots") {
312                 FormMathsBitmap * bitmap =
313                         createFormBitmap(*dialog, _("Dots"),
314                                          latex_dots, nr_latex_dots);
315                 bitmap->addBitmap(
316                         BitmapStore(4, 4, 1, dots_width, dots_height, dots_bits, true));
317
318                 dialog->setController(new ControlMath(*dialog));
319                 dialog->setView(bitmap);
320                 dialog->bc().bp(new IgnorantPolicy);
321
322         } else if (name == "mathbigoperators") {
323                 FormMathsBitmap * bitmap =
324                         createFormBitmap(*dialog, _("Big Operators"),
325                                          latex_varsz, nr_latex_varsz);
326                 bitmap->addBitmap(
327                         BitmapStore(14, 3, 5, varsz_width, varsz_height, varsz_bits, true));
328
329                 dialog->setController(new ControlMath(*dialog));
330                 dialog->setView(bitmap);
331                 dialog->bc().bp(new IgnorantPolicy);
332
333         } else if (name == "mathamsmisc") {
334                 FormMathsBitmap * bitmap =
335                         createFormBitmap(*dialog, _("AMS Misc"),
336                                          latex_ams_misc, nr_latex_ams_misc);
337                 bitmap->addBitmap(
338                         BitmapStore(9, 5, 2, ams1_width, ams1_height, ams1_bits, true));
339                 bitmap->addBitmap(
340                         BitmapStore(26, 3, 9, ams7_width, ams7_height, ams7_bits, true));
341
342                 dialog->setController(new ControlMath(*dialog));
343                 dialog->setView(bitmap);
344                 dialog->bc().bp(new IgnorantPolicy);
345
346         } else if (name == "mathamsarrows") {
347                 FormMathsBitmap * bitmap =
348                         createFormBitmap(*dialog, _("AMS Arrows"),
349                                          latex_ams_arrows, nr_latex_ams_arrows);
350                 bitmap->addBitmap(
351                         BitmapStore(32, 3, 11, ams2_width, ams2_height, ams2_bits, true));
352                 bitmap->addBitmap(
353                         BitmapStore(6, 3, 2, ams3_width, ams3_height, ams3_bits, true));
354
355                 dialog->setController(new ControlMath(*dialog));
356                 dialog->setView(bitmap);
357                 dialog->bc().bp(new IgnorantPolicy);
358
359         } else if (name == "mathamsrelations") {
360                 FormMathsBitmap * bitmap =
361                         createFormBitmap(*dialog, _("AMS Relations"),
362                                          latex_ams_rel, nr_latex_ams_rel);
363                 bitmap->addBitmap(
364                         BitmapStore(66, 6, 11, ams_rel_width, ams_rel_height, ams_rel_bits, true));
365
366                 dialog->setController(new ControlMath(*dialog));
367                 dialog->setView(bitmap);
368                 dialog->bc().bp(new IgnorantPolicy);
369
370         } else if (name == "mathamsnegatedrelations") {
371                 FormMathsBitmap * bitmap =
372                         createFormBitmap(*dialog, _("AMS Negated Rel"),
373                                          latex_ams_nrel, nr_latex_ams_nrel);
374                 bitmap->addBitmap(
375                         BitmapStore(51, 6, 9, ams_nrel_width, ams_nrel_height, ams_nrel_bits, true));
376
377                 dialog->setController(new ControlMath(*dialog));
378                 dialog->setView(bitmap);
379                 dialog->bc().bp(new IgnorantPolicy);
380
381         } else if (name == "mathamsoperators") {
382                 FormMathsBitmap * bitmap =
383                         createFormBitmap(*dialog, _("AMS Operators"),
384                                          latex_ams_ops, nr_latex_ams_ops);
385                 bitmap->addBitmap(
386                         BitmapStore(23, 3, 8, ams_ops_width, ams_ops_height, ams_ops_bits, true));
387
388                 dialog->setController(new ControlMath(*dialog));
389                 dialog->setView(bitmap);
390                 dialog->bc().bp(new IgnorantPolicy);
391
392         } else if (name == "mathdelimiter") {
393                 dialog->setController(new ControlMath(*dialog));
394                 dialog->setView(new FormMathsDelim(*dialog));
395                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
396         } else if (name == "mathmatrix") {
397                 dialog->setController(new ControlMath(*dialog));
398                 dialog->setView(new FormMathsMatrix(*dialog));
399                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
400         } else if (name == "mathspace") {
401                 dialog->setController(new ControlMath(*dialog));
402                 dialog->setView(new FormMathsSpace(*dialog));
403                 dialog->bc().bp(new IgnorantPolicy);
404         } else if (name == "mathstyle") {
405                 dialog->setController(new ControlMath(*dialog));
406                 dialog->setView(new FormMathsStyle(*dialog));
407                 dialog->bc().bp(new IgnorantPolicy);
408         } else if (name == "minipage") {
409                 dialog->setController(new ControlMinipage(*dialog));
410                 dialog->setView(new FormMinipage(*dialog));
411                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
412         } else if (name == "paragraph") {
413                 dialog->setController(new ControlParagraph(*dialog));
414                 dialog->setView(new FormParagraph(*dialog));
415                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
416         } else if (name == "ref") {
417                 dialog->setController(new ControlRef(*dialog));
418                 dialog->setView(new FormRef(*dialog));
419                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
420         } else if (name == "tabular") {
421                 dialog->setController(new ControlTabular(*dialog));
422                 dialog->setView(new FormTabular(*dialog));
423                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
424         } else if (name == "tabularcreate") {
425                 dialog->setController(new ControlTabularCreate(*dialog));
426                 dialog->setView(new FormTabularCreate(*dialog));
427                 dialog->bc().bp(new IgnorantPolicy);
428 #ifdef HAVE_LIBAIKSAURUS
429         } else if (name == "thesaurus") {
430                 dialog->setController(new ControlThesaurus(*dialog));
431                 dialog->setView(new FormThesaurus(*dialog));
432                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
433 #endif
434         } else if (name == "toc") {
435                 dialog->setController(new ControlToc(*dialog));
436                 dialog->setView(new FormToc(*dialog));
437                 dialog->bc().bp(new OkCancelPolicy);
438         } else if (name == "url") {
439                 dialog->setController(new ControlCommand(*dialog, name));
440                 dialog->setView(new FormUrl(*dialog));
441                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
442         } else if (name == "vclog") {
443                 dialog->setController(new ControlVCLog(*dialog));
444                 dialog->setView(new FormVCLog(*dialog));
445                 dialog->bc().bp(new OkCancelPolicy);
446         } else if (name == "wrap") {
447                 dialog->setController(new ControlWrap(*dialog));
448                 dialog->setView(new FormWrap(*dialog));
449                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
450         }
451
452         return dialog;
453 }
454
455
456 void Dialogs::toggleTooltips()
457 {
458         Tooltips::toggleEnabled();
459 }
460
461
462 /// Are the tooltips on or off?
463 bool Dialogs::tooltipsEnabled()
464 {
465         return Tooltips::enabled();
466 }