2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 The LyX Team.
10 * ====================================================== */
15 #include "lyx_gui_misc.h"
16 #include "BufferView.h"
19 #include "bullet_forms.h"
22 #include "include_form.h"
23 #include "latexoptions.h"
24 #include "layout_forms.h"
28 #include "mathed/math_forms.h"
29 #include "minibuffer.h"
30 #include "print_form.h"
32 #include "insets/insetindex.h"
37 extern BufferView * current_view;
39 extern FD_form_paragraph * fd_form_paragraph;
40 extern FD_form_paragraph_extra * fd_form_paragraph_extra;
41 extern FD_form_search * fd_form_search;
42 extern FD_form_character * fd_form_character;
43 extern FD_form_document * fd_form_document;
44 extern FD_form_paper * fd_form_paper;
45 extern FD_form_table_options * fd_form_table_options;
46 extern FD_form_quotes * fd_form_quotes;
47 extern FD_form_preamble * fd_form_preamble;
48 extern FD_form_table * fd_form_table;
49 extern FD_form_print * fd_form_print;
50 extern FD_form_sendto * fd_form_sendto;
51 extern FD_form_figure * fd_form_figure;
52 extern FD_form_toc * fd_form_toc;
53 extern FD_form_ref * fd_form_ref;
54 extern FD_form_paragraph_extra * fd_form_paragraph_extra;
55 extern FD_LaTeXLog * fd_latex_log;
56 extern FD_form_spell_check * fd_form_spell_check;
57 extern FD_form_bullet * fd_form_bullet;
58 extern FD_panel * fd_panel;
59 extern FD_delim * fd_delim;
60 extern FD_deco * fd_deco;
61 extern FD_space * fd_space;
62 extern FD_matrix * fd_matrix;
63 extern FD_citation_form * citation_form;
64 extern FD_bibitem_form * bibitem_form;
65 extern FD_include * form;
66 extern FD_index_form * index_form;
68 extern void TocUpdateCB();
69 extern void HideFiguresPopups();
71 // Prevents LyX from being killed when the close box is pressed in a popup.
72 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
78 // Prevents LyX from being killed when the close box is pressed in a popup.
79 extern "C" int IgnoreCloseBoxCB(FL_FORM *, void *)
85 // Prevents LyX from crashing when no buffers available
86 // This is also one of the functions that we _really_ dont want
87 // we should try to finds way to help us with that.
88 // The signal/slot mechanism can probably help.
89 void CloseAllBufferRelatedPopups()
91 // don't forget to check that dynamically created forms
92 // have been created otherwise hiding one could cause a crash
93 // need the visible check otherwise XForms prints a warning
94 // if hiding an invisible form
95 if (fd_form_paragraph->form_paragraph->visible) {
96 fl_hide_form(fd_form_paragraph->form_paragraph);
98 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
99 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
101 if (fd_form_search->form_search->visible) {
102 fl_hide_form(fd_form_search->form_search);
104 if (fd_form_character->form_character->visible) {
105 fl_hide_form(fd_form_character->form_character);
107 if (fd_form_document->form_document->visible) {
108 fl_hide_form(fd_form_document->form_document);
110 if (fd_form_quotes->form_quotes->visible) {
111 fl_hide_form(fd_form_quotes->form_quotes);
113 if (fd_form_preamble->form_preamble->visible) {
114 fl_hide_form(fd_form_preamble->form_preamble);
116 if (fd_form_table->form_table->visible) {
117 fl_hide_form(fd_form_table->form_table);
119 if (fd_form_print->form_print->visible) {
120 fl_hide_form(fd_form_print->form_print);
122 if (fd_form_figure->form_figure->visible) {
123 fl_hide_form(fd_form_figure->form_figure);
125 if (fd_form_toc->form_toc->visible) {
126 fl_hide_form(fd_form_toc->form_toc);
128 if (fd_form_ref->form_ref->visible) {
129 fl_hide_form(fd_form_ref->form_ref);
131 if (fd_form_paper->form_paper->visible) {
132 fl_hide_form(fd_form_paper->form_paper);
134 if (fd_form_table_options->form_table_options->visible) {
135 fl_hide_form(fd_form_table_options->form_table_options);
137 if (fd_form_sendto->form_sendto->visible) {
138 fl_hide_form(fd_form_sendto->form_sendto);
140 if (fd_latex_log->LaTeXLog->visible) {
141 fl_hide_form(fd_latex_log->LaTeXLog);
143 if (fd_form_spell_check) {
144 if (fd_form_spell_check->form_spell_check->visible) {
145 fl_trigger_object(fd_form_spell_check->done);
148 if (fd_form_bullet) {
149 if (fd_form_bullet->form_bullet->visible) {
150 fl_hide_form(fd_form_bullet->form_bullet);
154 if (fd_panel->panel->visible) {
155 fl_hide_form(fd_panel->panel);
159 if (fd_delim->delim->visible) {
160 fl_hide_form(fd_delim->delim);
164 if (fd_deco->deco->visible) {
165 fl_hide_form(fd_deco->deco);
169 if (fd_space->space->visible) {
170 fl_hide_form(fd_space->space);
174 if (fd_matrix->matrix->visible) {
175 fl_hide_form(fd_matrix->matrix);
179 if (citation_form->citation_form->visible) {
180 fl_hide_form(citation_form->citation_form);
184 if (bibitem_form->bibitem_form->visible) {
185 fl_hide_form(bibitem_form->bibitem_form);
189 if (form->include->visible) {
190 fl_hide_form(form->include);
194 if (index_form->index_form->visible) {
195 fl_hide_form(index_form->index_form);
201 // This is another function we really don't want.
202 // Again the Signal/Slot mechanism is tailor made for this task.
203 void updateAllVisibleBufferRelatedPopups()
205 if (fd_form_document->form_document->visible) {
206 UpdateLayoutDocument();
208 if (fd_form_preamble->form_preamble->visible) {
209 UpdateLayoutPreamble();
211 if (fd_form_quotes->form_quotes->visible) {
212 UpdateLayoutQuotes();
214 if (fd_form_paragraph->form_paragraph->visible) {
215 UpdateLayoutParagraph();
217 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
218 UpdateParagraphExtra();
220 if (fd_form_paper->form_paper->visible) {
223 if (fd_form_table_options->form_table_options->visible) {
224 UpdateLayoutTable(1); // just like a right mouse click
226 if (fd_form_bullet) {
227 if (fd_form_bullet->form_bullet->visible) {
231 if (fd_form_toc->browser_toc->visible) {
234 #ifdef ALWAYS_UPDATE_REF
235 // Ideally, the RefUpdateCB should be modified so that if the
236 // current document is a subdocument the reference list should come
237 // from master document (or even be a merger of references from all
238 // its sibling documents). For now this has effectively been
239 // commented out to ensure that users of multipart documents can
240 // access the reference list of a different document. This is
241 // of course a compromise and an annoyance for users switching
242 // between separate documents. ARRae 241198
243 if (fd_form_ref->form_ref->visible) {
247 if (current_view->buffer()->isReadonly()) {
248 // a little crude perhaps but it works. ARRae
249 if (fd_form_character->form_character->visible) {
250 fl_hide_form(fd_form_character->form_character);
252 if (fd_form_table->form_table->visible) {
253 fl_hide_form(fd_form_table->form_table);
257 // We have either changed buffers or changed the readonly status
258 // so the safest thing to do is hide all inset popups that
259 // are editting insets from the previous buffer or aren't
260 // allowed in readonly docs.
262 if (fd_panel->panel->visible) {
263 fl_hide_form(fd_panel->panel);
267 if (fd_delim->delim->visible) {
268 fl_hide_form(fd_delim->delim);
272 if (fd_deco->deco->visible) {
273 fl_hide_form(fd_deco->deco);
277 if (fd_space->space->visible) {
278 fl_hide_form(fd_space->space);
282 if (fd_matrix->matrix->visible) {
283 fl_hide_form(fd_matrix->matrix);
287 if (citation_form->citation_form->visible) {
288 fl_hide_form(citation_form->citation_form);
292 if (bibitem_form->bibitem_form->visible) {
293 fl_hide_form(bibitem_form->bibitem_form);
297 if (form->include->visible) {
298 fl_hide_form(form->include);
302 if (index_form->index_form->visible) {
303 fl_hide_form(index_form->index_form);
309 // Extract shortcut from <ident>|<shortcut> string
310 char const * flyx_shortcut_extract(char const * sc)
312 // Find '|' in the sc and return the string after that.
313 register char const * sd = sc;
314 while(sd[0]!= 0 && sd[0] != '|') ++sd;
318 //lyxerr << sd << endl;
325 // Extract identifier from <ident>|<shortcut> string
326 char const * flyx_ident_extract(char const * sc)
328 register char const * se = sc;
329 while(se[0]!= 0 && se[0] != '|') ++se;
331 if (se[0] == 0) return sc;
333 char * sb = new char[se - sc + 1];
335 register char const * sd = sc;
346 void WriteAlert(string const & s1, string const & s2, string const & s3)
348 MiniBuffer * minibuffer = 0;
349 if (current_view && current_view->owner())
350 minibuffer = current_view->owner()->getMiniBuffer();
353 minibuffer->Set(s1, s2, s3);
356 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
357 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
364 // Alarms user of something related to files
365 void WriteFSAlert(string const & s1, string const & s2)
367 WriteAlert (s1, s2, strerror(errno));
371 bool AskQuestion(string const & s1, string const & s2, string const & s3)
373 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
374 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
376 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
378 return fl_show_question(s1.c_str(), s2.c_str(), s3.c_str());
383 // Returns 1 for yes, 2 for no, 3 for cancel.
384 int AskConfirmation(string const & s1, string const & s2, string const & s3)
386 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
388 scex(_("Cancel|^[")));
390 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
391 3, idex(_("Yes|Yy#y")),
393 idex(_("Cancel|^[")));
396 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
397 3, idex(_("Yes|Yy#y")),
399 idex(_("Cancel|^[")), 3);
405 pair<bool, string> askForText(string const & msg, string const & dflt)
408 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
409 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
410 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
411 tmp = fl_show_input(msg.c_str(), dflt.c_str());
413 return make_pair<bool, string>(true, tmp);
415 return make_pair<bool, string>(false, string());
419 // Inform the user that the buffer is read-only, and that changes in the
420 // dialog box that is to appear will be ignored.
421 void WarnReadonly(string const & file)
423 WriteAlert(_("Any changes will be ignored"),
424 _("The document is read-only:"),