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