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"
27 #include "layout_forms.h"
31 #include "mathed/math_forms.h"
32 #include "minibuffer.h"
33 #include "print_form.h"
36 #include "bufferview_funcs.h"
37 #include "support/filetools.h"
44 extern BufferView * current_view;
46 extern FD_form_character * fd_form_character;
47 extern FD_form_credits * fd_form_credits;
48 extern FD_form_figure * fd_form_figure;
49 extern FD_form_preamble * fd_form_preamble;
50 extern FD_form_sendto * fd_form_sendto;
51 extern FD_form_spell_check * fd_form_spell_check;
52 extern FD_form_spell_options * fd_form_spell_options;
53 extern FD_panel * fd_panel;
54 extern FD_delim * fd_delim;
55 extern FD_deco * fd_deco;
56 extern FD_space * fd_space;
57 extern FD_matrix * fd_matrix;
58 extern FD_bibitem_form * bibitem_form;
59 extern FD_include * form;
61 extern void HideFiguresPopups();
63 // Prevents LyX from being killed when the close box is pressed in a popup.
64 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
68 // Redraw the form (on receipt of a Signal indicating, for example,
69 // that the xform colors have been re-mapped).
70 void RedrawAllBufferRelatedDialogs()
72 if (bibitem_form && bibitem_form->bibitem_form->visible) {
73 fl_redraw_form(bibitem_form->bibitem_form);
75 if (fd_deco && fd_deco->deco->visible) {
76 fl_redraw_form(fd_deco->deco);
78 if (fd_delim && fd_delim->delim->visible) {
79 fl_redraw_form(fd_delim->delim);
81 if (fd_form_character->form_character->visible) {
82 fl_redraw_form(fd_form_character->form_character);
84 if (fd_form_credits && fd_form_credits->form_credits->visible) {
85 fl_redraw_form(fd_form_credits->form_credits);
87 if (fd_form_figure->form_figure->visible) {
88 fl_redraw_form(fd_form_figure->form_figure);
90 if (fd_form_preamble->form_preamble->visible) {
91 fl_redraw_form(fd_form_preamble->form_preamble);
93 if (fd_form_sendto->form_sendto->visible) {
94 fl_redraw_form(fd_form_sendto->form_sendto);
96 if (fd_form_spell_check &&
97 fd_form_spell_check->form_spell_check->visible) {
98 fl_redraw_form(fd_form_spell_check->form_spell_check);
100 if (fd_form_spell_options &&
101 fd_form_spell_options->form_spell_options->visible) {
102 fl_redraw_form(fd_form_spell_options->form_spell_options);
104 if (fd_matrix && fd_matrix->matrix->visible) {
105 fl_redraw_form(fd_matrix->matrix);
107 if (fd_panel && fd_panel->panel->visible) {
108 fl_redraw_form(fd_panel->panel);
110 if (fd_space && fd_space->space->visible) {
111 fl_redraw_form(fd_space->space);
113 if (form && form->include->visible) {
114 fl_redraw_form(form->include);
118 // Prevents LyX from crashing when no buffers available
119 // This is also one of the functions that we _really_ dont want
120 // we should try to finds way to help us with that.
121 // The signal/slot mechanism can probably help.
122 void CloseAllBufferRelatedDialogs()
124 // don't forget to check that dynamically created forms
125 // have been created otherwise hiding one could cause a crash
126 // need the visible check otherwise XForms prints a warning
127 // if hiding an invisible form
128 if (fd_form_character->form_character->visible) {
129 fl_hide_form(fd_form_character->form_character);
131 if (fd_form_preamble->form_preamble->visible) {
132 fl_hide_form(fd_form_preamble->form_preamble);
134 if (fd_form_figure->form_figure->visible) {
135 fl_hide_form(fd_form_figure->form_figure);
137 if (fd_form_sendto->form_sendto->visible) {
138 fl_hide_form(fd_form_sendto->form_sendto);
140 if (fd_form_spell_check) {
141 if (fd_form_spell_check->form_spell_check->visible) {
142 fl_trigger_object(fd_form_spell_check->done);
146 if (fd_panel->panel->visible) {
147 fl_hide_form(fd_panel->panel);
151 if (fd_delim->delim->visible) {
152 fl_hide_form(fd_delim->delim);
156 if (fd_deco->deco->visible) {
157 fl_hide_form(fd_deco->deco);
161 if (fd_space->space->visible) {
162 fl_hide_form(fd_space->space);
166 if (fd_matrix->matrix->visible) {
167 fl_hide_form(fd_matrix->matrix);
171 if (bibitem_form->bibitem_form->visible) {
172 fl_hide_form(bibitem_form->bibitem_form);
176 if (form->include->visible) {
177 fl_hide_form(form->include);
183 // This is another function we really don't want.
184 // Again the Signal/Slot mechanism is tailor made for this task.
185 void updateAllVisibleBufferRelatedDialogs(bool)
187 if (fd_form_preamble->form_preamble->visible) {
188 UpdateLayoutPreamble(current_view);
190 if (current_view->buffer() && current_view->buffer()->isReadonly()) {
191 // a little crude perhaps but it works. ARRae
192 if (fd_form_character->form_character->visible) {
193 fl_hide_form(fd_form_character->form_character);
195 #ifndef ALWAYS_CLOSE_MATH_PANELS
196 // The math popups should be closed only if we switch
197 // to a readonly buffer
199 if (fd_panel->panel->visible) {
200 fl_hide_form(fd_panel->panel);
204 if (fd_delim->delim->visible) {
205 fl_hide_form(fd_delim->delim);
209 if (fd_deco->deco->visible) {
210 fl_hide_form(fd_deco->deco);
214 if (fd_space->space->visible) {
215 fl_hide_form(fd_space->space);
219 if (fd_matrix->matrix->visible) {
220 fl_hide_form(fd_matrix->matrix);
226 // We have either changed buffers or changed the readonly status
227 // so the safest thing to do is hide all inset popups that
228 // are editting insets from the previous buffer or aren't
229 // allowed in readonly docs.
230 #ifdef ALWAYS_CLOSE_MATH_PANELS
232 if (fd_panel->panel->visible) {
233 fl_hide_form(fd_panel->panel);
237 if (fd_delim->delim->visible) {
238 fl_hide_form(fd_delim->delim);
242 if (fd_deco->deco->visible) {
243 fl_hide_form(fd_deco->deco);
247 if (fd_space->space->visible) {
248 fl_hide_form(fd_space->space);
252 if (fd_matrix->matrix->visible) {
253 fl_hide_form(fd_matrix->matrix);
258 if (bibitem_form->bibitem_form->visible) {
259 fl_hide_form(bibitem_form->bibitem_form);
263 if (form->include->visible) {
264 fl_hide_form(form->include);
270 // Extract shortcut from <ident>|<shortcut> string
271 char const * flyx_shortcut_extract(char const * sc)
273 // Find '|' in the sc and return the string after that.
274 register char const * sd = sc;
275 while(sd[0]!= 0 && sd[0] != '|') ++sd;
279 //lyxerr << sd << endl;
286 // Extract identifier from <ident>|<shortcut> string
287 char const * flyx_ident_extract(char const * sc)
289 register char const * se = sc;
290 while(se[0]!= 0 && se[0] != '|') ++se;
292 if (se[0] == 0) return sc;
294 char * sb = new char[se - sc + 1];
296 register char const * sd = sc;
306 void WriteStatus(MiniBuffer * minib, string const & s)
317 void WriteAlert(string const & s1, string const & s2, string const & s3)
319 MiniBuffer * minibuffer = 0;
320 if (current_view && current_view->owner())
321 minibuffer = current_view->owner()->getMiniBuffer();
323 /// Write to minibuffer
324 ProhibitInput(current_view);
325 minibuffer->Set(s1, s2, s3);
326 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
327 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
328 AllowInput(current_view);
331 lyxerr << "----------------------------------------" << endl
332 << s1 << endl << s2 << endl << s3 << endl
333 << "----------------------------------------" << endl;
338 // Alarms user of something related to files
339 void WriteFSAlert(string const & s1, string const & s2)
341 WriteAlert(s1, s2, strerror(errno));
345 bool AskQuestion(string const & s1, string const & s2, string const & s3,
348 if (!lyxrc.use_gui) {
349 lyxerr << "----------------------------------------" << endl
352 lyxerr << s2 << endl;
354 lyxerr << s3 << endl;
355 lyxerr << "Assuming answer is "
356 << (default_value ? "yes" : "no")
358 << "----------------------------------------" << endl;
359 return default_value;
362 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
363 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
364 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
368 // Returns 1 for yes, 2 for no, 3 for cancel.
369 int AskConfirmation(string const & s1, string const & s2, string const & s3,
372 if (!lyxrc.use_gui) {
373 lyxerr << "----------------------------------------" << endl
376 lyxerr << s2 << endl;
378 lyxerr << s3 << endl;
379 lyxerr << "Assuming answer is ";
380 if (default_value == 1)
382 else if (default_value == 2)
387 << "----------------------------------------" << endl;
388 return default_value;
391 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
393 scex(_("Cancel|^[")));
394 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
395 3, idex(_("Yes|Yy#y")),
397 idex(_("Cancel|^[")), 3);
402 pair<bool, string> const
403 askForText(string const & msg, string const & dflt)
405 if (!lyxrc.use_gui) {
406 lyxerr << "----------------------------------------" << endl
408 << "Assuming answer is " << dflt
409 << "----------------------------------------" << endl;
410 return make_pair<bool, string>(true, dflt);
413 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
414 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
415 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
416 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
418 return make_pair<bool, string>(true, string(tmp));
420 return make_pair<bool, string>(false, string());
424 // Inform the user that the buffer is read-only, and that changes in the
425 // dialog box that is to appear will be ignored.
426 void WarnReadonly(string const & file)
428 WriteAlert(_("Any changes will be ignored"),
429 _("The document is read-only:"),
430 MakeDisplayPath(file));
433 /// Get the dpi setting of the current screen
436 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
437 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
438 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;