]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Dialogs.C
Minipage is no more (long live the box inset)
[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
15 #include "Tooltips.h"
16
17 #include "ControlAboutlyx.h"
18 #include "ControlBibtex.h"
19 #include "ControlBox.h"
20 #include "ControlBranch.h"
21 #include "ControlChanges.h"
22 #include "ControlCitation.h"
23 #include "ControlErrorList.h"
24 #include "ControlERT.h"
25 #include "ControlExternal.h"
26 #include "ControlFloat.h"
27 #include "ControlGraphics.h"
28 #include "ControlInclude.h"
29 #include "ControlLog.h"
30 #include "ControlMath.h"
31 #include "ControlNote.h"
32 #include "ControlParagraph.h"
33 #include "ControlRef.h"
34 #include "ControlShowFile.h"
35 #include "ControlTabular.h"
36 #include "ControlTabularCreate.h"
37 #include "ControlToc.h"
38 #include "ControlVSpace.h"
39 #include "ControlWrap.h"
40
41 #include "FormAboutlyx.h"
42 #include "FormBibitem.h"
43 #include "FormBibtex.h"
44 #include "FormBox.h"
45 #include "FormBranch.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 "FormNote.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 "FormVSpace.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
99 using std::string;
100
101
102 namespace {
103
104 FormMathsBitmap * createFormBitmap(Dialog & parent, string const & title,
105                                    char const * const * data, int size)
106 {
107         char const * const * const end = data + size;
108         return new FormMathsBitmap(parent, title, std::vector<string>(data, end));
109 }
110
111
112 char const * const dialognames[] = {
113 "aboutlyx", "bibitem", "bibtex", "branch", "box", "changes",
114 "character", "citation", "error", "errorlist" , "ert", "external", "file",
115 "float", "graphics", "include", "index", "label", "log", "mathpanel",
116 "mathaccents", "matharrows", "mathoperators", "mathrelations", "mathgreek",
117 "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc",
118 "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators",
119 "mathdelimiter", "mathmatrix", "mathspace", "mathstyle",
120 "note", "paragraph", "ref", "tabular", "tabularcreate", "texinfo",
121
122 #ifdef HAVE_LIBAIKSAURUS
123 "thesaurus",
124 #endif
125
126 "toc", "url", "vspace", "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 == "box") {
171                 dialog->setController(new ControlBox(*dialog));
172                 dialog->setView(new FormBox(*dialog));
173                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
174         } else if (name == "branch") {
175                 dialog->setController(new ControlBranch(*dialog));
176                 dialog->setView(new FormBranch(*dialog));
177                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
178         } else if (name == "character") {
179                 dialog->setController(new ControlCharacter(*dialog));
180                 dialog->setView(new FormCharacter(*dialog));
181                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
182         } else if (name == "changes") {
183                 dialog->setController(new ControlChanges(*dialog));
184                 dialog->setView(new FormChanges(*dialog));
185                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
186         } else if (name == "citation") {
187                 dialog->setController(new ControlCitation(*dialog));
188                 dialog->setView(new FormCitation(*dialog));
189                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
190         } else if (name == "errorlist") {
191                 dialog->setController(new ControlErrorList(*dialog));
192                 dialog->setView(new FormErrorList(*dialog));
193                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
194         } else if (name == "ert") {
195                 dialog->setController(new ControlERT(*dialog));
196                 dialog->setView(new FormERT(*dialog));
197                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
198         } else if (name == "external") {
199                 dialog->setController(new ControlExternal(*dialog));
200                 dialog->setView(new FormExternal(*dialog));
201                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
202         } else if (name == "file") {
203                 dialog->setController(new ControlShowFile(*dialog));
204                 dialog->setView(new FormShowFile(*dialog));
205                 dialog->bc().bp(new OkCancelPolicy);
206         } else if (name == "float") {
207                 dialog->setController(new ControlFloat(*dialog));
208                 dialog->setView(new FormFloat(*dialog));
209                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
210         } else if (name == "graphics") {
211                 dialog->setController(new ControlGraphics(*dialog));
212                 dialog->setView(new FormGraphics(*dialog));
213                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
214         } else if (name == "include") {
215                 dialog->setController(new ControlInclude(*dialog));
216                 dialog->setView(new FormInclude(*dialog));
217                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
218         } else if (name == "index") {
219                 dialog->setController(new ControlCommand(*dialog, name));
220                 dialog->setView(new FormText(*dialog,
221                                              _("Index"), _("Keyword:|#K")));
222                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
223         } else if (name == "label") {
224                 dialog->setController(new ControlCommand(*dialog, name));
225                 dialog->setView(new FormText(*dialog,
226                                              _("Label"), _("Label:|#L")));
227                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
228         } else if (name == "log") {
229                 dialog->setController(new ControlLog(*dialog));
230                 dialog->setView(new FormLog(*dialog));
231                 dialog->bc().bp(new OkCancelPolicy);
232
233         } else if (name == "mathpanel") {
234                 dialog->setController(new ControlMath(*dialog));
235                 dialog->setView(new FormMathsPanel(*dialog));
236                 dialog->bc().bp(new IgnorantPolicy);
237
238         } else if (name == "mathaccents") {
239                 FormMathsBitmap * bitmap =
240                         createFormBitmap(*dialog, _("Maths Decorations & Accents"),
241                                          latex_deco, nr_latex_deco);
242                 bitmap->addBitmap(
243                         BitmapStore(12, 3, 4, deco1_width, deco1_height, deco1_bits, true));
244                 bitmap->addBitmap(
245                         BitmapStore(10, 4, 3, deco2_width, deco2_height, deco2_bits, true));
246
247                 dialog->setController(new ControlMath(*dialog));
248                 dialog->setView(bitmap);
249                 dialog->bc().bp(new IgnorantPolicy);
250
251         } else if (name == "matharrows") {
252                 FormMathsBitmap * bitmap =
253                         createFormBitmap(*dialog, _("Arrows"), latex_arrow, nr_latex_arrow);
254                 bitmap->addBitmap(
255                         BitmapStore(20, 5, 4, arrow_width,  arrow_height,  arrow_bits, true));
256                 bitmap->addBitmap(
257                         BitmapStore(7,  2, 4, larrow_width, larrow_height, larrow_bits, false));
258                 bitmap->addBitmap(
259                         BitmapStore(4,  2, 2, darrow_width,  darrow_height, darrow_bits, true));
260
261                 dialog->setController(new ControlMath(*dialog));
262                 dialog->setView(bitmap);
263                 dialog->bc().bp(new IgnorantPolicy);
264
265         } else if (name == "mathoperators") {
266                 FormMathsBitmap * bitmap =
267                         createFormBitmap(*dialog, _("Binary Ops"),
268                                          latex_bop, nr_latex_bop);
269                 bitmap->addBitmap(
270                         BitmapStore(31, 4, 8, bop_width, bop_height, bop_bits, true));
271
272                 dialog->setController(new ControlMath(*dialog));
273                 dialog->setView(bitmap);
274                 dialog->bc().bp(new IgnorantPolicy);
275
276         } else if (name == "mathrelations") {
277                 FormMathsBitmap * bitmap =
278                         createFormBitmap(*dialog, _("Binary Relations"),
279                                          latex_brel, nr_latex_brel);
280                 bitmap->addBitmap(
281                         BitmapStore(35, 4, 9, brel_width, brel_height, brel_bits, true));
282
283                 dialog->setController(new ControlMath(*dialog));
284                 dialog->setView(bitmap);
285                 dialog->bc().bp(new IgnorantPolicy);
286
287         } else if (name == "mathgreek") {
288                 FormMathsBitmap * bitmap =
289                         createFormBitmap(*dialog, _("Greek"),
290                                          latex_greek, nr_latex_greek);
291                 bitmap->addBitmap(
292                         BitmapStore(11, 6, 2, Greek_width, Greek_height, Greek_bits, true));
293                 bitmap->addBitmap(
294                         BitmapStore(28, 7, 4, greek_width, greek_height, greek_bits, true));
295
296                 dialog->setController(new ControlMath(*dialog));
297                 dialog->setView(bitmap);
298                 dialog->bc().bp(new IgnorantPolicy);
299
300         } else if (name == "mathmisc") {
301                 FormMathsBitmap * bitmap =
302                         createFormBitmap(*dialog, _("Misc"),
303                                          latex_misc, nr_latex_misc);
304                 bitmap->addBitmap(
305                         BitmapStore(29, 5, 6, misc_width, misc_height, misc_bits, true));
306                 bitmap->addBitmap(
307                         BitmapStore(5, 5, 1, misc4_width, misc4_height, misc4_bits, true));
308                 bitmap->addBitmap(
309                         BitmapStore(6, 3, 2, misc2_width, misc2_height, misc2_bits, false));
310                 bitmap->addBitmap(
311                         BitmapStore(4, 2, 2, misc3_width, misc3_height, misc3_bits, true));
312
313                 dialog->setController(new ControlMath(*dialog));
314                 dialog->setView(bitmap);
315                 dialog->bc().bp(new IgnorantPolicy);
316
317         } else if (name == "mathdots") {
318                 FormMathsBitmap * bitmap =
319                         createFormBitmap(*dialog, _("Dots"),
320                                          latex_dots, nr_latex_dots);
321                 bitmap->addBitmap(
322                         BitmapStore(4, 4, 1, dots_width, dots_height, dots_bits, true));
323
324                 dialog->setController(new ControlMath(*dialog));
325                 dialog->setView(bitmap);
326                 dialog->bc().bp(new IgnorantPolicy);
327
328         } else if (name == "mathbigoperators") {
329                 FormMathsBitmap * bitmap =
330                         createFormBitmap(*dialog, _("Big Operators"),
331                                          latex_varsz, nr_latex_varsz);
332                 bitmap->addBitmap(
333                         BitmapStore(14, 3, 5, varsz_width, varsz_height, varsz_bits, true));
334
335                 dialog->setController(new ControlMath(*dialog));
336                 dialog->setView(bitmap);
337                 dialog->bc().bp(new IgnorantPolicy);
338
339         } else if (name == "mathamsmisc") {
340                 FormMathsBitmap * bitmap =
341                         createFormBitmap(*dialog, _("AMS Misc"),
342                                          latex_ams_misc, nr_latex_ams_misc);
343                 bitmap->addBitmap(
344                         BitmapStore(9, 5, 2, ams1_width, ams1_height, ams1_bits, true));
345                 bitmap->addBitmap(
346                         BitmapStore(26, 3, 9, ams7_width, ams7_height, ams7_bits, true));
347
348                 dialog->setController(new ControlMath(*dialog));
349                 dialog->setView(bitmap);
350                 dialog->bc().bp(new IgnorantPolicy);
351
352         } else if (name == "mathamsarrows") {
353                 FormMathsBitmap * bitmap =
354                         createFormBitmap(*dialog, _("AMS Arrows"),
355                                          latex_ams_arrows, nr_latex_ams_arrows);
356                 bitmap->addBitmap(
357                         BitmapStore(32, 3, 11, ams2_width, ams2_height, ams2_bits, true));
358                 bitmap->addBitmap(
359                         BitmapStore(6, 3, 2, ams3_width, ams3_height, ams3_bits, true));
360
361                 dialog->setController(new ControlMath(*dialog));
362                 dialog->setView(bitmap);
363                 dialog->bc().bp(new IgnorantPolicy);
364
365         } else if (name == "mathamsrelations") {
366                 FormMathsBitmap * bitmap =
367                         createFormBitmap(*dialog, _("AMS Relations"),
368                                          latex_ams_rel, nr_latex_ams_rel);
369                 bitmap->addBitmap(
370                         BitmapStore(66, 6, 11, ams_rel_width, ams_rel_height, ams_rel_bits, true));
371
372                 dialog->setController(new ControlMath(*dialog));
373                 dialog->setView(bitmap);
374                 dialog->bc().bp(new IgnorantPolicy);
375
376         } else if (name == "mathamsnegatedrelations") {
377                 FormMathsBitmap * bitmap =
378                         createFormBitmap(*dialog, _("AMS Negated Rel"),
379                                          latex_ams_nrel, nr_latex_ams_nrel);
380                 bitmap->addBitmap(
381                         BitmapStore(51, 6, 9, ams_nrel_width, ams_nrel_height, ams_nrel_bits, true));
382
383                 dialog->setController(new ControlMath(*dialog));
384                 dialog->setView(bitmap);
385                 dialog->bc().bp(new IgnorantPolicy);
386
387         } else if (name == "mathamsoperators") {
388                 FormMathsBitmap * bitmap =
389                         createFormBitmap(*dialog, _("AMS Operators"),
390                                          latex_ams_ops, nr_latex_ams_ops);
391                 bitmap->addBitmap(
392                         BitmapStore(23, 3, 8, ams_ops_width, ams_ops_height, ams_ops_bits, true));
393
394                 dialog->setController(new ControlMath(*dialog));
395                 dialog->setView(bitmap);
396                 dialog->bc().bp(new IgnorantPolicy);
397
398         } else if (name == "mathdelimiter") {
399                 dialog->setController(new ControlMath(*dialog));
400                 dialog->setView(new FormMathsDelim(*dialog));
401                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
402         } else if (name == "mathmatrix") {
403                 dialog->setController(new ControlMath(*dialog));
404                 dialog->setView(new FormMathsMatrix(*dialog));
405                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
406         } else if (name == "mathspace") {
407                 dialog->setController(new ControlMath(*dialog));
408                 dialog->setView(new FormMathsSpace(*dialog));
409                 dialog->bc().bp(new IgnorantPolicy);
410         } else if (name == "mathstyle") {
411                 dialog->setController(new ControlMath(*dialog));
412                 dialog->setView(new FormMathsStyle(*dialog));
413                 dialog->bc().bp(new IgnorantPolicy);
414         } else if (name == "note") {
415                 dialog->setController(new ControlNote(*dialog));
416                 dialog->setView(new FormNote(*dialog));
417                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
418         } else if (name == "paragraph") {
419                 dialog->setController(new ControlParagraph(*dialog));
420                 dialog->setView(new FormParagraph(*dialog));
421                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
422         } else if (name == "ref") {
423                 dialog->setController(new ControlRef(*dialog));
424                 dialog->setView(new FormRef(*dialog));
425                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
426         } else if (name == "tabular") {
427                 dialog->setController(new ControlTabular(*dialog));
428                 dialog->setView(new FormTabular(*dialog));
429                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
430         } else if (name == "tabularcreate") {
431                 dialog->setController(new ControlTabularCreate(*dialog));
432                 dialog->setView(new FormTabularCreate(*dialog));
433                 dialog->bc().bp(new IgnorantPolicy);
434         } else if (name == "texinfo") {
435                 dialog->setController(new ControlTexinfo(*dialog));
436                 dialog->setView(new FormTexinfo(*dialog));
437                 dialog->bc().bp(new OkCancelPolicy);
438 #ifdef HAVE_LIBAIKSAURUS
439         } else if (name == "thesaurus") {
440                 dialog->setController(new ControlThesaurus(*dialog));
441                 dialog->setView(new FormThesaurus(*dialog));
442                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
443 #endif
444         } else if (name == "toc") {
445                 dialog->setController(new ControlToc(*dialog));
446                 dialog->setView(new FormToc(*dialog));
447                 dialog->bc().bp(new OkCancelPolicy);
448         } else if (name == "url") {
449                 dialog->setController(new ControlCommand(*dialog, name));
450                 dialog->setView(new FormUrl(*dialog));
451                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
452         } else if (name == "vspace") {
453                 dialog->setController(new ControlVSpace(*dialog));
454                 dialog->setView(new FormVSpace(*dialog));
455                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
456         } else if (name == "wrap") {
457                 dialog->setController(new ControlWrap(*dialog));
458                 dialog->setView(new FormWrap(*dialog));
459                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
460         }
461
462         return dialog;
463 }
464
465
466 void Dialogs::toggleTooltips()
467 {
468         Tooltips::toggleEnabled();
469 }
470
471
472 /// Are the tooltips on or off?
473 bool Dialogs::tooltipsEnabled()
474 {
475         return Tooltips::enabled();
476 }