]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/Dialogs.C
Minipage is no more (long live the box inset)
[lyx.git] / src / frontends / gtk / 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 "ControlBranch.h"
21 #include "ControlChanges.h"
22 #include "ControlCharacter.h"
23 #include "ControlCitation.h"
24 #include "ControlCommand.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 "ControlNote.h"
35 #include "ControlParagraph.h"
36 #include "ControlRef.h"
37 #include "ControlShowFile.h"
38 #include "ControlTabular.h"
39 #include "ControlTabularCreate.h"
40 #include "ControlTexinfo.h"
41 #include "ControlToc.h"
42 #include "ControlVCLog.h"
43 #include "ControlWrap.h"
44
45 #include "GAboutlyx.h"
46 #include "GText.h"
47 #include "FormBibitem.h"
48 #include "FormBibtex.h"
49 #include "FormBranch.h"
50 #include "FormChanges.h"
51 #include "FormCharacter.h"
52 #include "FormCitation.h"
53 #include "FormErrorList.h"
54 #include "FormERT.h"
55 #include "FormExternal.h"
56 #include "FormFloat.h"
57 #include "FormGraphics.h"
58 #include "FormInclude.h"
59 #include "FormLog.h"
60 #include "GMathPanel.h"
61 #include "FormMathsBitmap.h"
62 #include "FormMathsDelim.h"
63 #include "FormMathsMatrix.h"
64 #include "FormMathsSpace.h"
65 #include "FormMathsStyle.h"
66 #include "FormMinipage.h"
67 #include "FormNote.h"
68 #include "FormParagraph.h"
69 #include "FormRef.h"
70 #include "FormTabular.h"
71 #include "FormTexinfo.h"
72 #include "FormShowFile.h"
73 #include "GTableCreate.h"
74 #include "FormToc.h"
75 #include "GUrl.h"
76 #include "FormVCLog.h"
77 #include "FormWrap.h"
78
79 #ifdef HAVE_LIBAIKSAURUS
80 #include "ControlThesaurus.h"
81 #include "FormThesaurus.h"
82 #endif
83
84 #include "xformsBC.h"
85 #include "ButtonController.h"
86
87 #include "arrows.xbm"
88 #include "bop.xbm"
89 #include "brel.xbm"
90 #include "deco.xbm"
91 #include "dots.xbm"
92 #include "greek.xbm"
93 #include "misc.xbm"
94 #include "varsz.xbm"
95
96 #include "ams_misc.xbm"
97 #include "ams_arrows.xbm"
98 #include "ams_rel.xbm"
99 #include "ams_nrel.xbm"
100 #include "ams_ops.xbm"
101
102 #include <vector>
103
104 using std::string;
105
106
107 namespace {
108
109 FormMathsBitmap * createFormBitmap(Dialog & parent, string const & title,
110                                    char const * const * data, int size)
111 {
112         char const * const * const end = data + size;
113         return new FormMathsBitmap(parent, title, std::vector<string>(data, end));
114 }
115
116
117 char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", "changes",
118 "character", "citation", "error", "errorlist" , "ert", "external", "file",
119 "float", "graphics", "include", "index", "label", "latexlog", "mathpanel",
120 "mathaccents", "matharrows", "mathoperators", "mathrelations", "mathgreek",
121 "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc",
122 "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators",
123 "mathdelimiter", "mathmatrix", "mathspace", "mathstyle",
124 "minipage", "note", "paragraph", "ref", "tabular", "tabularcreate", "texinfo",
125
126 #ifdef HAVE_LIBAIKSAURUS
127 "thesaurus",
128 #endif
129
130 "toc", "url", "vclog", "wrap" };
131
132 char const * const * const end_dialognames =
133         dialognames + (sizeof(dialognames) / sizeof(char *));
134
135 struct cmpCStr {
136         cmpCStr(char const * name) : name_(name) {}
137         bool operator()(char const * other) {
138                 return strcmp(other, name_) == 0;
139         }
140 private:
141         char const * name_;
142 };
143
144 } // namespace anon
145
146
147 bool Dialogs::isValidName(string const & name) const
148 {
149         return std::find_if(dialognames, end_dialognames,
150                             cmpCStr(name.c_str())) != end_dialognames;
151 }
152
153
154 Dialog * Dialogs::build(string const & name)
155 {
156         if (!isValidName(name))
157                 return 0;
158
159         Dialog * dialog = new Dialog(lyxview_, name);
160         dialog->bc().view(new xformsBC(dialog->bc()));
161
162         if (name == "aboutlyx") {
163                 dialog->bc().view(new GBC(dialog->bc()));
164                 dialog->setController(new ControlAboutlyx(*dialog));
165                 dialog->setView(new GAboutlyx(*dialog));
166                 dialog->bc().bp(new OkCancelPolicy);
167         } else if (name == "bibitem") {
168                 dialog->setController(new ControlCommand(*dialog, name));
169                 dialog->setView(new FormBibitem(*dialog));
170                 dialog->bc().bp(new OkCancelReadOnlyPolicy);
171         } else if (name == "bibtex") {
172                 dialog->setController(new ControlBibtex(*dialog));
173                 dialog->setView(new FormBibtex(*dialog));
174                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
175         } else if (name == "character") {
176                 dialog->setController(new ControlCharacter(*dialog));
177                 dialog->setView(new FormCharacter(*dialog));
178                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
179         } else if (name == "changes") {
180                 dialog->setController(new ControlChanges(*dialog));
181                 dialog->setView(new FormChanges(*dialog));
182                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
183         } else if (name == "citation") {
184                 dialog->setController(new ControlCitation(*dialog));
185                 dialog->setView(new FormCitation(*dialog));
186                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
187         } else if (name == "errorlist") {
188                 dialog->setController(new ControlErrorList(*dialog));
189                 dialog->setView(new FormErrorList(*dialog));
190                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
191         } else if (name == "ert") {
192                 dialog->setController(new ControlERT(*dialog));
193                 dialog->setView(new FormERT(*dialog));
194                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
195         } else if (name == "external") {
196                 dialog->setController(new ControlExternal(*dialog));
197                 dialog->setView(new FormExternal(*dialog));
198                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
199         } else if (name == "file") {
200                 dialog->setController(new ControlShowFile(*dialog));
201                 dialog->setView(new FormShowFile(*dialog));
202                 dialog->bc().bp(new OkCancelPolicy);
203         } else if (name == "float") {
204                 dialog->setController(new ControlFloat(*dialog));
205                 dialog->setView(new FormFloat(*dialog));
206                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
207         } else if (name == "graphics") {
208                 dialog->setController(new ControlGraphics(*dialog));
209                 dialog->setView(new FormGraphics(*dialog));
210                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
211         } else if (name == "include") {
212                 dialog->setController(new ControlInclude(*dialog));
213                 dialog->setView(new FormInclude(*dialog));
214                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
215         } else if (name == "index") {
216                 dialog->bc().view(new GBC(dialog->bc()));
217                 dialog->setController(new ControlCommand(*dialog, name));
218                 dialog->setView(new GText(*dialog,
219                                           _("Index"), _("Keyword:|#K")));
220                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
221         } else if (name == "label") {
222                 dialog->bc().view(new GBC(dialog->bc()));
223                 dialog->setController(new ControlCommand(*dialog, name));
224                 dialog->setView(new GText(*dialog,
225                                           _("Label"), _("Label:|#L")));
226                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
227         } else if (name == "latexlog") {
228                 dialog->setController(new ControlLog(*dialog));
229                 dialog->setView(new FormLog(*dialog));
230                 dialog->bc().bp(new OkCancelPolicy);
231
232         } else if (name == "mathpanel") {
233                 dialog->bc().view(new GBC(dialog->bc()));
234                 dialog->setController(new ControlMath(*dialog));
235                 dialog->setView(new GMathPanel(*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 == "minipage") {
415                 dialog->setController(new ControlMinipage(*dialog));
416                 dialog->setView(new FormMinipage(*dialog));
417                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
418         } else if (name == "note") {
419                 dialog->setController(new ControlNote(*dialog));
420                 dialog->setView(new FormNote(*dialog));
421                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
422         } else if (name == "branch") {
423                 dialog->setController(new ControlBranch(*dialog));
424                 dialog->setView(new FormBranch(*dialog));
425                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
426         } else if (name == "paragraph") {
427                 dialog->setController(new ControlParagraph(*dialog));
428                 dialog->setView(new FormParagraph(*dialog));
429                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
430         } else if (name == "ref") {
431                 dialog->setController(new ControlRef(*dialog));
432                 dialog->setView(new FormRef(*dialog));
433                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
434         } else if (name == "tabular") {
435                 dialog->setController(new ControlTabular(*dialog));
436                 dialog->setView(new FormTabular(*dialog));
437                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
438         } else if (name == "tabularcreate") {
439                 dialog->bc().view(new GBC(dialog->bc()));
440                 dialog->setController(new ControlTabularCreate(*dialog));
441                 dialog->setView(new GTableCreate(*dialog));
442                 dialog->bc().bp(new IgnorantPolicy);
443         } else if (name == "texinfo") {
444                 dialog->setController(new ControlTexinfo(*dialog));
445                 dialog->setView(new FormTexinfo(*dialog));
446                 dialog->bc().bp(new OkCancelPolicy);
447 #ifdef HAVE_LIBAIKSAURUS
448         } else if (name == "thesaurus") {
449                 dialog->setController(new ControlThesaurus(*dialog));
450                 dialog->setView(new FormThesaurus(*dialog));
451                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
452 #endif
453         } else if (name == "toc") {
454                 dialog->setController(new ControlToc(*dialog));
455                 dialog->setView(new FormToc(*dialog));
456                 dialog->bc().bp(new OkCancelPolicy);
457         } else if (name == "url") {
458                 dialog->bc().view(new GBC(dialog->bc()));
459                 dialog->setController(new ControlCommand(*dialog, name));
460                 dialog->setView(new GUrl(*dialog));
461                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
462         } else if (name == "vclog") {
463                 dialog->setController(new ControlVCLog(*dialog));
464                 dialog->setView(new FormVCLog(*dialog));
465                 dialog->bc().bp(new OkCancelPolicy);
466         } else if (name == "wrap") {
467                 dialog->setController(new ControlWrap(*dialog));
468                 dialog->setView(new FormWrap(*dialog));
469                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
470         }
471
472         return dialog;
473 }
474
475
476 void Dialogs::toggleTooltips()
477 {
478         Tooltips::toggleEnabled();
479 }
480
481
482 /// Are the tooltips on or off?
483 bool Dialogs::tooltipsEnabled()
484 {
485         return Tooltips::enabled();
486 }