]> git.lyx.org Git - features.git/blob - src/frontends/xforms/Dialogs.C
The error boxes are no more! See also Bug: 192, Bug: 807, Bug: 899 and Bug: 973
[features.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 "ControlErrorList.h"
25 #include "ControlERT.h"
26 #include "ControlExternal.h"
27 #include "ControlFloat.h"
28 #include "ControlGraphics.h"
29 #include "ControlInclude.h"
30 #include "ControlLog.h"
31 #include "ControlMath.h"
32 #include "ControlMinipage.h"
33 #include "ControlParagraph.h"
34 #include "ControlRef.h"
35 #include "ControlShowFile.h"
36 #include "ControlTabular.h"
37 #include "ControlTabularCreate.h"
38 #include "ControlTexinfo.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 "FormErrorList.h"
50 #include "FormERT.h"
51 #include "FormExternal.h"
52 #include "FormFloat.h"
53 #include "FormGraphics.h"
54 #include "FormInclude.h"
55 #include "FormLog.h"
56 #include "FormMathsPanel.h"
57 #include "FormMathsBitmap.h"
58 #include "FormMathsDelim.h"
59 #include "FormMathsMatrix.h"
60 #include "FormMathsSpace.h"
61 #include "FormMathsStyle.h"
62 #include "FormMinipage.h"
63 #include "FormParagraph.h"
64 #include "FormRef.h"
65 #include "FormTabular.h"
66 #include "FormTexinfo.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[] = { "aboutlyx", "bibitem", "bibtex", "changes",
112 "character", "citation", "error", "errorlist" , "ert", "external", "file",
113 "float", "graphics", "include", "index", "label", "latexlog", "mathpanel",
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", "texinfo",
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 == "aboutlyx") {
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 == "errorlist") {
181                 dialog->setController(new ControlErrorList(*dialog));
182                 dialog->setView(new FormErrorList(*dialog));
183                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
184         } else if (name == "ert") {
185                 dialog->setController(new ControlERT(*dialog));
186                 dialog->setView(new FormERT(*dialog));
187                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
188         } else if (name == "external") {
189                 dialog->setController(new ControlExternal(*dialog));
190                 dialog->setView(new FormExternal(*dialog));
191                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
192         } else if (name == "file") {
193                 dialog->setController(new ControlShowFile(*dialog));
194                 dialog->setView(new FormShowFile(*dialog));
195                 dialog->bc().bp(new OkCancelPolicy);
196         } else if (name == "float") {
197                 dialog->setController(new ControlFloat(*dialog));
198                 dialog->setView(new FormFloat(*dialog));
199                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
200         } else if (name == "graphics") {
201                 dialog->setController(new ControlGraphics(*dialog));
202                 dialog->setView(new FormGraphics(*dialog));
203                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
204         } else if (name == "include") {
205                 dialog->setController(new ControlInclude(*dialog));
206                 dialog->setView(new FormInclude(*dialog));
207                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
208         } else if (name == "index") {
209                 dialog->setController(new ControlCommand(*dialog, name));
210                 dialog->setView(new FormText(*dialog,
211                                              _("Index"), _("Keyword:|#K")));
212                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
213         } else if (name == "label") {
214                 dialog->setController(new ControlCommand(*dialog, name));
215                 dialog->setView(new FormText(*dialog,
216                                              _("Label"), _("Label:|#L")));
217                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
218         } else if (name == "latexlog") {
219                 dialog->setController(new ControlLog(*dialog));
220                 dialog->setView(new FormLog(*dialog));
221                 dialog->bc().bp(new OkCancelPolicy);
222
223         } else if (name == "mathpanel") {
224                 dialog->setController(new ControlMath(*dialog));
225                 dialog->setView(new FormMathsPanel(*dialog));
226                 dialog->bc().bp(new IgnorantPolicy);
227
228         } else if (name == "mathaccents") {
229                 FormMathsBitmap * bitmap =
230                         createFormBitmap(*dialog, _("Maths Decorations & Accents"),
231                                          latex_deco, nr_latex_deco);
232                 bitmap->addBitmap(
233                         BitmapStore(12, 3, 4, deco1_width, deco1_height, deco1_bits, true));
234                 bitmap->addBitmap(
235                         BitmapStore(10, 4, 3, deco2_width, deco2_height, deco2_bits, true));
236
237                 dialog->setController(new ControlMath(*dialog));
238                 dialog->setView(bitmap);
239                 dialog->bc().bp(new IgnorantPolicy);
240
241         } else if (name == "matharrows") {
242                 FormMathsBitmap * bitmap =
243                         createFormBitmap(*dialog, _("Arrows"), latex_arrow, nr_latex_arrow);
244                 bitmap->addBitmap(
245                         BitmapStore(20, 5, 4, arrow_width,  arrow_height,  arrow_bits, true));
246                 bitmap->addBitmap(
247                         BitmapStore(7,  2, 4, larrow_width, larrow_height, larrow_bits, false));
248                 bitmap->addBitmap(
249                         BitmapStore(4,  2, 2, darrow_width,  darrow_height, darrow_bits, true));
250
251                 dialog->setController(new ControlMath(*dialog));
252                 dialog->setView(bitmap);
253                 dialog->bc().bp(new IgnorantPolicy);
254
255         } else if (name == "mathoperators") {
256                 FormMathsBitmap * bitmap =
257                         createFormBitmap(*dialog, _("Binary Ops"),
258                                          latex_bop, nr_latex_bop);
259                 bitmap->addBitmap(
260                         BitmapStore(31, 4, 8, bop_width, bop_height, bop_bits, true));
261
262                 dialog->setController(new ControlMath(*dialog));
263                 dialog->setView(bitmap);
264                 dialog->bc().bp(new IgnorantPolicy);
265
266         } else if (name == "mathrelations") {
267                 FormMathsBitmap * bitmap =
268                         createFormBitmap(*dialog, _("Binary Relations"),
269                                          latex_brel, nr_latex_brel);
270                 bitmap->addBitmap(
271                         BitmapStore(35, 4, 9, brel_width, brel_height, brel_bits, true));
272
273                 dialog->setController(new ControlMath(*dialog));
274                 dialog->setView(bitmap);
275                 dialog->bc().bp(new IgnorantPolicy);
276
277         } else if (name == "mathgreek") {
278                 FormMathsBitmap * bitmap =
279                         createFormBitmap(*dialog, _("Greek"),
280                                          latex_greek, nr_latex_greek);
281                 bitmap->addBitmap(
282                         BitmapStore(11, 6, 2, Greek_width, Greek_height, Greek_bits, true));
283                 bitmap->addBitmap(
284                         BitmapStore(28, 7, 4, greek_width, greek_height, greek_bits, true));
285
286                 dialog->setController(new ControlMath(*dialog));
287                 dialog->setView(bitmap);
288                 dialog->bc().bp(new IgnorantPolicy);
289
290         } else if (name == "mathmisc") {
291                 FormMathsBitmap * bitmap =
292                         createFormBitmap(*dialog, _("Misc"),
293                                          latex_misc, nr_latex_misc);
294                 bitmap->addBitmap(
295                         BitmapStore(29, 5, 6, misc_width, misc_height, misc_bits, true));
296                 bitmap->addBitmap(
297                         BitmapStore(5, 5, 1, misc4_width, misc4_height, misc4_bits, true));
298                 bitmap->addBitmap(
299                         BitmapStore(6, 3, 2, misc2_width, misc2_height, misc2_bits, false));
300                 bitmap->addBitmap(
301                         BitmapStore(4, 2, 2, misc3_width, misc3_height, misc3_bits, true));
302
303                 dialog->setController(new ControlMath(*dialog));
304                 dialog->setView(bitmap);
305                 dialog->bc().bp(new IgnorantPolicy);
306
307         } else if (name == "mathdots") {
308                 FormMathsBitmap * bitmap =
309                         createFormBitmap(*dialog, _("Dots"),
310                                          latex_dots, nr_latex_dots);
311                 bitmap->addBitmap(
312                         BitmapStore(4, 4, 1, dots_width, dots_height, dots_bits, true));
313
314                 dialog->setController(new ControlMath(*dialog));
315                 dialog->setView(bitmap);
316                 dialog->bc().bp(new IgnorantPolicy);
317
318         } else if (name == "mathbigoperators") {
319                 FormMathsBitmap * bitmap =
320                         createFormBitmap(*dialog, _("Big Operators"),
321                                          latex_varsz, nr_latex_varsz);
322                 bitmap->addBitmap(
323                         BitmapStore(14, 3, 5, varsz_width, varsz_height, varsz_bits, true));
324
325                 dialog->setController(new ControlMath(*dialog));
326                 dialog->setView(bitmap);
327                 dialog->bc().bp(new IgnorantPolicy);
328
329         } else if (name == "mathamsmisc") {
330                 FormMathsBitmap * bitmap =
331                         createFormBitmap(*dialog, _("AMS Misc"),
332                                          latex_ams_misc, nr_latex_ams_misc);
333                 bitmap->addBitmap(
334                         BitmapStore(9, 5, 2, ams1_width, ams1_height, ams1_bits, true));
335                 bitmap->addBitmap(
336                         BitmapStore(26, 3, 9, ams7_width, ams7_height, ams7_bits, true));
337
338                 dialog->setController(new ControlMath(*dialog));
339                 dialog->setView(bitmap);
340                 dialog->bc().bp(new IgnorantPolicy);
341
342         } else if (name == "mathamsarrows") {
343                 FormMathsBitmap * bitmap =
344                         createFormBitmap(*dialog, _("AMS Arrows"),
345                                          latex_ams_arrows, nr_latex_ams_arrows);
346                 bitmap->addBitmap(
347                         BitmapStore(32, 3, 11, ams2_width, ams2_height, ams2_bits, true));
348                 bitmap->addBitmap(
349                         BitmapStore(6, 3, 2, ams3_width, ams3_height, ams3_bits, true));
350
351                 dialog->setController(new ControlMath(*dialog));
352                 dialog->setView(bitmap);
353                 dialog->bc().bp(new IgnorantPolicy);
354
355         } else if (name == "mathamsrelations") {
356                 FormMathsBitmap * bitmap =
357                         createFormBitmap(*dialog, _("AMS Relations"),
358                                          latex_ams_rel, nr_latex_ams_rel);
359                 bitmap->addBitmap(
360                         BitmapStore(66, 6, 11, ams_rel_width, ams_rel_height, ams_rel_bits, true));
361
362                 dialog->setController(new ControlMath(*dialog));
363                 dialog->setView(bitmap);
364                 dialog->bc().bp(new IgnorantPolicy);
365
366         } else if (name == "mathamsnegatedrelations") {
367                 FormMathsBitmap * bitmap =
368                         createFormBitmap(*dialog, _("AMS Negated Rel"),
369                                          latex_ams_nrel, nr_latex_ams_nrel);
370                 bitmap->addBitmap(
371                         BitmapStore(51, 6, 9, ams_nrel_width, ams_nrel_height, ams_nrel_bits, true));
372
373                 dialog->setController(new ControlMath(*dialog));
374                 dialog->setView(bitmap);
375                 dialog->bc().bp(new IgnorantPolicy);
376
377         } else if (name == "mathamsoperators") {
378                 FormMathsBitmap * bitmap =
379                         createFormBitmap(*dialog, _("AMS Operators"),
380                                          latex_ams_ops, nr_latex_ams_ops);
381                 bitmap->addBitmap(
382                         BitmapStore(23, 3, 8, ams_ops_width, ams_ops_height, ams_ops_bits, true));
383
384                 dialog->setController(new ControlMath(*dialog));
385                 dialog->setView(bitmap);
386                 dialog->bc().bp(new IgnorantPolicy);
387
388         } else if (name == "mathdelimiter") {
389                 dialog->setController(new ControlMath(*dialog));
390                 dialog->setView(new FormMathsDelim(*dialog));
391                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
392         } else if (name == "mathmatrix") {
393                 dialog->setController(new ControlMath(*dialog));
394                 dialog->setView(new FormMathsMatrix(*dialog));
395                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
396         } else if (name == "mathspace") {
397                 dialog->setController(new ControlMath(*dialog));
398                 dialog->setView(new FormMathsSpace(*dialog));
399                 dialog->bc().bp(new IgnorantPolicy);
400         } else if (name == "mathstyle") {
401                 dialog->setController(new ControlMath(*dialog));
402                 dialog->setView(new FormMathsStyle(*dialog));
403                 dialog->bc().bp(new IgnorantPolicy);
404         } else if (name == "minipage") {
405                 dialog->setController(new ControlMinipage(*dialog));
406                 dialog->setView(new FormMinipage(*dialog));
407                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
408         } else if (name == "paragraph") {
409                 dialog->setController(new ControlParagraph(*dialog));
410                 dialog->setView(new FormParagraph(*dialog));
411                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
412         } else if (name == "ref") {
413                 dialog->setController(new ControlRef(*dialog));
414                 dialog->setView(new FormRef(*dialog));
415                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
416         } else if (name == "tabular") {
417                 dialog->setController(new ControlTabular(*dialog));
418                 dialog->setView(new FormTabular(*dialog));
419                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
420         } else if (name == "tabularcreate") {
421                 dialog->setController(new ControlTabularCreate(*dialog));
422                 dialog->setView(new FormTabularCreate(*dialog));
423                 dialog->bc().bp(new IgnorantPolicy);
424         } else if (name == "texinfo") {
425                 dialog->setController(new ControlTexinfo(*dialog));
426                 dialog->setView(new FormTexinfo(*dialog));
427                 dialog->bc().bp(new OkCancelPolicy);
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 }