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