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