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"
25 #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_preamble * fd_form_preamble;
48 extern FD_form_sendto * fd_form_sendto;
49 extern FD_form_figure * fd_form_figure;
50 extern FD_LaTeXLog * fd_latex_log;
51 extern FD_form_spell_check * fd_form_spell_check;
52 extern FD_panel * fd_panel;
53 extern FD_delim * fd_delim;
54 extern FD_deco * fd_deco;
55 extern FD_space * fd_space;
56 extern FD_matrix * fd_matrix;
57 extern FD_bibitem_form * bibitem_form;
58 extern FD_include * form;
60 extern void HideFiguresPopups();
62 // Prevents LyX from being killed when the close box is pressed in a popup.
63 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
69 // Prevents LyX from crashing when no buffers available
70 // This is also one of the functions that we _really_ dont want
71 // we should try to finds way to help us with that.
72 // The signal/slot mechanism can probably help.
73 void CloseAllBufferRelatedDialogs()
75 // don't forget to check that dynamically created forms
76 // have been created otherwise hiding one could cause a crash
77 // need the visible check otherwise XForms prints a warning
78 // if hiding an invisible form
79 if (fd_form_character->form_character->visible) {
80 fl_hide_form(fd_form_character->form_character);
82 if (fd_form_preamble->form_preamble->visible) {
83 fl_hide_form(fd_form_preamble->form_preamble);
85 if (fd_form_figure->form_figure->visible) {
86 fl_hide_form(fd_form_figure->form_figure);
88 if (fd_form_sendto->form_sendto->visible) {
89 fl_hide_form(fd_form_sendto->form_sendto);
91 if (fd_latex_log->LaTeXLog->visible) {
92 fl_hide_form(fd_latex_log->LaTeXLog);
94 if (fd_form_spell_check) {
95 if (fd_form_spell_check->form_spell_check->visible) {
96 fl_trigger_object(fd_form_spell_check->done);
100 if (fd_panel->panel->visible) {
101 fl_hide_form(fd_panel->panel);
105 if (fd_delim->delim->visible) {
106 fl_hide_form(fd_delim->delim);
110 if (fd_deco->deco->visible) {
111 fl_hide_form(fd_deco->deco);
115 if (fd_space->space->visible) {
116 fl_hide_form(fd_space->space);
120 if (fd_matrix->matrix->visible) {
121 fl_hide_form(fd_matrix->matrix);
125 if (bibitem_form->bibitem_form->visible) {
126 fl_hide_form(bibitem_form->bibitem_form);
130 if (form->include->visible) {
131 fl_hide_form(form->include);
137 // This is another function we really don't want.
138 // Again the Signal/Slot mechanism is tailor made for this task.
139 void updateAllVisibleBufferRelatedDialogs(bool)
141 if (fd_form_preamble->form_preamble->visible) {
142 UpdateLayoutPreamble(current_view);
144 if (fd_latex_log->LaTeXLog->visible) {
147 if (current_view->buffer() && current_view->buffer()->isReadonly()) {
148 // a little crude perhaps but it works. ARRae
149 if (fd_form_character->form_character->visible) {
150 fl_hide_form(fd_form_character->form_character);
152 #ifndef ALWAYS_CLOSE_MATH_PANELS
153 // The math popups should be closed only if we switch
154 // to a readonly buffer
156 if (fd_panel->panel->visible) {
157 fl_hide_form(fd_panel->panel);
161 if (fd_delim->delim->visible) {
162 fl_hide_form(fd_delim->delim);
166 if (fd_deco->deco->visible) {
167 fl_hide_form(fd_deco->deco);
171 if (fd_space->space->visible) {
172 fl_hide_form(fd_space->space);
176 if (fd_matrix->matrix->visible) {
177 fl_hide_form(fd_matrix->matrix);
183 // We have either changed buffers or changed the readonly status
184 // so the safest thing to do is hide all inset popups that
185 // are editting insets from the previous buffer or aren't
186 // allowed in readonly docs.
187 #ifdef ALWAYS_CLOSE_MATH_PANELS
189 if (fd_panel->panel->visible) {
190 fl_hide_form(fd_panel->panel);
194 if (fd_delim->delim->visible) {
195 fl_hide_form(fd_delim->delim);
199 if (fd_deco->deco->visible) {
200 fl_hide_form(fd_deco->deco);
204 if (fd_space->space->visible) {
205 fl_hide_form(fd_space->space);
209 if (fd_matrix->matrix->visible) {
210 fl_hide_form(fd_matrix->matrix);
215 if (bibitem_form->bibitem_form->visible) {
216 fl_hide_form(bibitem_form->bibitem_form);
220 if (form->include->visible) {
221 fl_hide_form(form->include);
227 // Extract shortcut from <ident>|<shortcut> string
228 char const * flyx_shortcut_extract(char const * sc)
230 // Find '|' in the sc and return the string after that.
231 register char const * sd = sc;
232 while(sd[0]!= 0 && sd[0] != '|') ++sd;
236 //lyxerr << sd << endl;
243 // Extract identifier from <ident>|<shortcut> string
244 char const * flyx_ident_extract(char const * sc)
246 register char const * se = sc;
247 while(se[0]!= 0 && se[0] != '|') ++se;
249 if (se[0] == 0) return sc;
251 char * sb = new char[se - sc + 1];
253 register char const * sd = sc;
263 void WriteStatus(MiniBuffer * minib, string const & s)
274 void WriteAlert(string const & s1, string const & s2, string const & s3)
276 MiniBuffer * minibuffer = 0;
277 if (current_view && current_view->owner())
278 minibuffer = current_view->owner()->getMiniBuffer();
280 /// Write to minibuffer
281 ProhibitInput(current_view);
282 minibuffer->Set(s1, s2, s3);
283 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
284 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
285 AllowInput(current_view);
288 lyxerr << "----------------------------------------" << endl
289 << s1 << endl << s2 << endl << s3 << endl
290 << "----------------------------------------" << endl;
295 // Alarms user of something related to files
296 void WriteFSAlert(string const & s1, string const & s2)
298 WriteAlert(s1, s2, strerror(errno));
302 bool AskQuestion(string const & s1, string const & s2, string const & s3,
305 if (!lyxrc.use_gui) {
306 lyxerr << "----------------------------------------" << endl
309 lyxerr << s2 << endl;
311 lyxerr << s3 << endl;
312 lyxerr << "Assuming answer is "
313 << (default_value ? "yes" : "no")
315 << "----------------------------------------" << endl;
316 return default_value;
319 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
320 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
321 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
325 // Returns 1 for yes, 2 for no, 3 for cancel.
326 int AskConfirmation(string const & s1, string const & s2, string const & s3,
329 if (!lyxrc.use_gui) {
330 lyxerr << "----------------------------------------" << endl
333 lyxerr << s2 << endl;
335 lyxerr << s3 << endl;
336 lyxerr << "Assuming answer is ";
337 if (default_value == 1)
339 else if (default_value == 2)
344 << "----------------------------------------" << endl;
345 return default_value;
348 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
350 scex(_("Cancel|^[")));
351 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
352 3, idex(_("Yes|Yy#y")),
354 idex(_("Cancel|^[")), 3);
359 pair<bool, string> const
360 askForText(string const & msg, string const & dflt)
362 if (!lyxrc.use_gui) {
363 lyxerr << "----------------------------------------" << endl
365 << "Assuming answer is " << dflt
366 << "----------------------------------------" << endl;
367 return make_pair<bool, string>(true, dflt);
370 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
371 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
372 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
373 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
375 return make_pair<bool, string>(true, string(tmp));
377 return make_pair<bool, string>(false, string());
381 // Inform the user that the buffer is read-only, and that changes in the
382 // dialog box that is to appear will be ignored.
383 void WarnReadonly(string const & file)
385 WriteAlert(_("Any changes will be ignored"),
386 _("The document is read-only:"),
387 MakeDisplayPath(file));
390 /// Get the dpi setting of the current screen
393 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
394 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
395 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;