2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
15 #pragma implementation
19 #include "lyx_gui_misc.h"
20 #include "BufferView.h"
23 #include "credits_form.h"
26 #include "include_form.h"
28 #include "layout_forms.h"
32 #include "mathed/math_forms.h"
33 #include "minibuffer.h"
34 #include "print_form.h"
37 #include "bufferview_funcs.h"
38 #include "support/filetools.h"
45 extern BufferView * current_view;
47 extern FD_form_character * fd_form_character;
48 extern FD_form_credits * fd_form_credits;
49 extern FD_form_figure * fd_form_figure;
50 extern FD_form_preamble * fd_form_preamble;
51 extern FD_form_sendto * fd_form_sendto;
52 extern FD_form_spell_check * fd_form_spell_check;
53 extern FD_form_spell_options * fd_form_spell_options;
54 extern FD_LaTeXLog * fd_latex_log;
55 extern FD_panel * fd_panel;
56 extern FD_delim * fd_delim;
57 extern FD_deco * fd_deco;
58 extern FD_space * fd_space;
59 extern FD_matrix * fd_matrix;
60 extern FD_bibitem_form * bibitem_form;
61 extern FD_include * form;
63 extern void HideFiguresPopups();
65 // Prevents LyX from being killed when the close box is pressed in a popup.
66 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
70 // Redraw the form (on receipt of a Signal indicating, for example,
71 // that the xform colors have been re-mapped).
72 void RedrawAllBufferRelatedDialogs()
74 if (bibitem_form && bibitem_form->bibitem_form->visible) {
75 fl_redraw_form(bibitem_form->bibitem_form);
77 if (fd_deco && fd_deco->deco->visible) {
78 fl_redraw_form(fd_deco->deco);
80 if (fd_delim && fd_delim->delim->visible) {
81 fl_redraw_form(fd_delim->delim);
83 if (fd_form_character->form_character->visible) {
84 fl_redraw_form(fd_form_character->form_character);
86 if (fd_form_credits && fd_form_credits->form_credits->visible) {
87 fl_redraw_form(fd_form_credits->form_credits);
89 if (fd_form_figure->form_figure->visible) {
90 fl_redraw_form(fd_form_figure->form_figure);
92 if (fd_form_preamble->form_preamble->visible) {
93 fl_redraw_form(fd_form_preamble->form_preamble);
95 if (fd_form_sendto->form_sendto->visible) {
96 fl_redraw_form(fd_form_sendto->form_sendto);
98 if (fd_form_spell_check &&
99 fd_form_spell_check->form_spell_check->visible) {
100 fl_redraw_form(fd_form_spell_check->form_spell_check);
102 if (fd_form_spell_options &&
103 fd_form_spell_options->form_spell_options->visible) {
104 fl_redraw_form(fd_form_spell_options->form_spell_options);
106 if (fd_latex_log->LaTeXLog->visible) {
107 fl_redraw_form(fd_latex_log->LaTeXLog);
109 if (fd_matrix && fd_matrix->matrix->visible) {
110 fl_redraw_form(fd_matrix->matrix);
112 if (fd_panel && fd_panel->panel->visible) {
113 fl_redraw_form(fd_panel->panel);
115 if (fd_space && fd_space->space->visible) {
116 fl_redraw_form(fd_space->space);
118 if (form && form->include->visible) {
119 fl_redraw_form(form->include);
123 // Prevents LyX from crashing when no buffers available
124 // This is also one of the functions that we _really_ dont want
125 // we should try to finds way to help us with that.
126 // The signal/slot mechanism can probably help.
127 void CloseAllBufferRelatedDialogs()
129 // don't forget to check that dynamically created forms
130 // have been created otherwise hiding one could cause a crash
131 // need the visible check otherwise XForms prints a warning
132 // if hiding an invisible form
133 if (fd_form_character->form_character->visible) {
134 fl_hide_form(fd_form_character->form_character);
136 if (fd_form_preamble->form_preamble->visible) {
137 fl_hide_form(fd_form_preamble->form_preamble);
139 if (fd_form_figure->form_figure->visible) {
140 fl_hide_form(fd_form_figure->form_figure);
142 if (fd_form_sendto->form_sendto->visible) {
143 fl_hide_form(fd_form_sendto->form_sendto);
145 if (fd_latex_log->LaTeXLog->visible) {
146 fl_hide_form(fd_latex_log->LaTeXLog);
148 if (fd_form_spell_check) {
149 if (fd_form_spell_check->form_spell_check->visible) {
150 fl_trigger_object(fd_form_spell_check->done);
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 (bibitem_form->bibitem_form->visible) {
180 fl_hide_form(bibitem_form->bibitem_form);
184 if (form->include->visible) {
185 fl_hide_form(form->include);
191 // This is another function we really don't want.
192 // Again the Signal/Slot mechanism is tailor made for this task.
193 void updateAllVisibleBufferRelatedDialogs(bool)
195 if (fd_form_preamble->form_preamble->visible) {
196 UpdateLayoutPreamble(current_view);
198 if (fd_latex_log->LaTeXLog->visible) {
201 if (current_view->buffer() && current_view->buffer()->isReadonly()) {
202 // a little crude perhaps but it works. ARRae
203 if (fd_form_character->form_character->visible) {
204 fl_hide_form(fd_form_character->form_character);
206 #ifndef ALWAYS_CLOSE_MATH_PANELS
207 // The math popups should be closed only if we switch
208 // to a readonly buffer
210 if (fd_panel->panel->visible) {
211 fl_hide_form(fd_panel->panel);
215 if (fd_delim->delim->visible) {
216 fl_hide_form(fd_delim->delim);
220 if (fd_deco->deco->visible) {
221 fl_hide_form(fd_deco->deco);
225 if (fd_space->space->visible) {
226 fl_hide_form(fd_space->space);
230 if (fd_matrix->matrix->visible) {
231 fl_hide_form(fd_matrix->matrix);
237 // We have either changed buffers or changed the readonly status
238 // so the safest thing to do is hide all inset popups that
239 // are editting insets from the previous buffer or aren't
240 // allowed in readonly docs.
241 #ifdef ALWAYS_CLOSE_MATH_PANELS
243 if (fd_panel->panel->visible) {
244 fl_hide_form(fd_panel->panel);
248 if (fd_delim->delim->visible) {
249 fl_hide_form(fd_delim->delim);
253 if (fd_deco->deco->visible) {
254 fl_hide_form(fd_deco->deco);
258 if (fd_space->space->visible) {
259 fl_hide_form(fd_space->space);
263 if (fd_matrix->matrix->visible) {
264 fl_hide_form(fd_matrix->matrix);
269 if (bibitem_form->bibitem_form->visible) {
270 fl_hide_form(bibitem_form->bibitem_form);
274 if (form->include->visible) {
275 fl_hide_form(form->include);
281 // Extract shortcut from <ident>|<shortcut> string
282 char const * flyx_shortcut_extract(char const * sc)
284 // Find '|' in the sc and return the string after that.
285 register char const * sd = sc;
286 while(sd[0]!= 0 && sd[0] != '|') ++sd;
290 //lyxerr << sd << endl;
297 // Extract identifier from <ident>|<shortcut> string
298 char const * flyx_ident_extract(char const * sc)
300 register char const * se = sc;
301 while(se[0]!= 0 && se[0] != '|') ++se;
303 if (se[0] == 0) return sc;
305 char * sb = new char[se - sc + 1];
307 register char const * sd = sc;
317 void WriteStatus(MiniBuffer * minib, string const & s)
328 void WriteAlert(string const & s1, string const & s2, string const & s3)
330 MiniBuffer * minibuffer = 0;
331 if (current_view && current_view->owner())
332 minibuffer = current_view->owner()->getMiniBuffer();
334 /// Write to minibuffer
335 ProhibitInput(current_view);
336 minibuffer->Set(s1, s2, s3);
337 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
338 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
339 AllowInput(current_view);
342 lyxerr << "----------------------------------------" << endl
343 << s1 << endl << s2 << endl << s3 << endl
344 << "----------------------------------------" << endl;
349 // Alarms user of something related to files
350 void WriteFSAlert(string const & s1, string const & s2)
352 WriteAlert(s1, s2, strerror(errno));
356 bool AskQuestion(string const & s1, string const & s2, string const & s3,
359 if (!lyxrc.use_gui) {
360 lyxerr << "----------------------------------------" << endl
363 lyxerr << s2 << endl;
365 lyxerr << s3 << endl;
366 lyxerr << "Assuming answer is "
367 << (default_value ? "yes" : "no")
369 << "----------------------------------------" << endl;
370 return default_value;
373 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
374 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
375 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
379 // Returns 1 for yes, 2 for no, 3 for cancel.
380 int AskConfirmation(string const & s1, string const & s2, string const & s3,
383 if (!lyxrc.use_gui) {
384 lyxerr << "----------------------------------------" << endl
387 lyxerr << s2 << endl;
389 lyxerr << s3 << endl;
390 lyxerr << "Assuming answer is ";
391 if (default_value == 1)
393 else if (default_value == 2)
398 << "----------------------------------------" << endl;
399 return default_value;
402 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
404 scex(_("Cancel|^[")));
405 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
406 3, idex(_("Yes|Yy#y")),
408 idex(_("Cancel|^[")), 3);
413 pair<bool, string> const
414 askForText(string const & msg, string const & dflt)
416 if (!lyxrc.use_gui) {
417 lyxerr << "----------------------------------------" << endl
419 << "Assuming answer is " << dflt
420 << "----------------------------------------" << endl;
421 return make_pair<bool, string>(true, dflt);
424 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
425 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
426 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
427 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
429 return make_pair<bool, string>(true, string(tmp));
431 return make_pair<bool, string>(false, string());
435 // Inform the user that the buffer is read-only, and that changes in the
436 // dialog box that is to appear will be ignored.
437 void WarnReadonly(string const & file)
439 WriteAlert(_("Any changes will be ignored"),
440 _("The document is read-only:"),
441 MakeDisplayPath(file));
444 /// Get the dpi setting of the current screen
447 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
448 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
449 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;