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"
42 extern BufferView * current_view;
44 extern FD_form_character * fd_form_character;
45 extern FD_form_preamble * fd_form_preamble;
46 extern FD_form_sendto * fd_form_sendto;
47 extern FD_form_figure * fd_form_figure;
48 extern FD_LaTeXLog * fd_latex_log;
49 extern FD_form_spell_check * fd_form_spell_check;
50 extern FD_panel * fd_panel;
51 extern FD_delim * fd_delim;
52 extern FD_deco * fd_deco;
53 extern FD_space * fd_space;
54 extern FD_matrix * fd_matrix;
55 extern FD_bibitem_form * bibitem_form;
56 extern FD_include * form;
58 extern void HideFiguresPopups();
60 // Prevents LyX from being killed when the close box is pressed in a popup.
61 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
67 // Prevents LyX from being killed when the close box is pressed in a popup.
68 extern "C" int IgnoreCloseBoxCB(FL_FORM *, void *)
74 // Prevents LyX from crashing when no buffers available
75 // This is also one of the functions that we _really_ dont want
76 // we should try to finds way to help us with that.
77 // The signal/slot mechanism can probably help.
78 void CloseAllBufferRelatedDialogs()
80 // don't forget to check that dynamically created forms
81 // have been created otherwise hiding one could cause a crash
82 // need the visible check otherwise XForms prints a warning
83 // if hiding an invisible form
84 if (fd_form_character->form_character->visible) {
85 fl_hide_form(fd_form_character->form_character);
87 if (fd_form_preamble->form_preamble->visible) {
88 fl_hide_form(fd_form_preamble->form_preamble);
90 if (fd_form_figure->form_figure->visible) {
91 fl_hide_form(fd_form_figure->form_figure);
93 if (fd_form_sendto->form_sendto->visible) {
94 fl_hide_form(fd_form_sendto->form_sendto);
96 if (fd_latex_log->LaTeXLog->visible) {
97 fl_hide_form(fd_latex_log->LaTeXLog);
99 if (fd_form_spell_check) {
100 if (fd_form_spell_check->form_spell_check->visible) {
101 fl_trigger_object(fd_form_spell_check->done);
105 if (fd_panel->panel->visible) {
106 fl_hide_form(fd_panel->panel);
110 if (fd_delim->delim->visible) {
111 fl_hide_form(fd_delim->delim);
115 if (fd_deco->deco->visible) {
116 fl_hide_form(fd_deco->deco);
120 if (fd_space->space->visible) {
121 fl_hide_form(fd_space->space);
125 if (fd_matrix->matrix->visible) {
126 fl_hide_form(fd_matrix->matrix);
130 if (bibitem_form->bibitem_form->visible) {
131 fl_hide_form(bibitem_form->bibitem_form);
135 if (form->include->visible) {
136 fl_hide_form(form->include);
142 // This is another function we really don't want.
143 // Again the Signal/Slot mechanism is tailor made for this task.
144 void updateAllVisibleBufferRelatedDialogs()
146 if (fd_form_preamble->form_preamble->visible) {
147 UpdateLayoutPreamble();
149 if (fd_latex_log->LaTeXLog->visible) {
152 if (current_view->buffer()->isReadonly()) {
153 // a little crude perhaps but it works. ARRae
154 if (fd_form_character->form_character->visible) {
155 fl_hide_form(fd_form_character->form_character);
157 #ifndef ALWAYS_CLOSE_MATH_PANELS
158 // The math popups should be closed only if we switch
159 // to a readonly buffer
161 if (fd_panel->panel->visible) {
162 fl_hide_form(fd_panel->panel);
166 if (fd_delim->delim->visible) {
167 fl_hide_form(fd_delim->delim);
171 if (fd_deco->deco->visible) {
172 fl_hide_form(fd_deco->deco);
176 if (fd_space->space->visible) {
177 fl_hide_form(fd_space->space);
181 if (fd_matrix->matrix->visible) {
182 fl_hide_form(fd_matrix->matrix);
188 // We have either changed buffers or changed the readonly status
189 // so the safest thing to do is hide all inset popups that
190 // are editting insets from the previous buffer or aren't
191 // allowed in readonly docs.
192 #ifdef ALWAYS_CLOSE_MATH_PANELS
194 if (fd_panel->panel->visible) {
195 fl_hide_form(fd_panel->panel);
199 if (fd_delim->delim->visible) {
200 fl_hide_form(fd_delim->delim);
204 if (fd_deco->deco->visible) {
205 fl_hide_form(fd_deco->deco);
209 if (fd_space->space->visible) {
210 fl_hide_form(fd_space->space);
214 if (fd_matrix->matrix->visible) {
215 fl_hide_form(fd_matrix->matrix);
220 if (bibitem_form->bibitem_form->visible) {
221 fl_hide_form(bibitem_form->bibitem_form);
225 if (form->include->visible) {
226 fl_hide_form(form->include);
232 // Extract shortcut from <ident>|<shortcut> string
233 char const * flyx_shortcut_extract(char const * sc)
235 // Find '|' in the sc and return the string after that.
236 register char const * sd = sc;
237 while(sd[0]!= 0 && sd[0] != '|') ++sd;
241 //lyxerr << sd << endl;
248 // Extract identifier from <ident>|<shortcut> string
249 char const * flyx_ident_extract(char const * sc)
251 register char const * se = sc;
252 while(se[0]!= 0 && se[0] != '|') ++se;
254 if (se[0] == 0) return sc;
256 char * sb = new char[se - sc + 1];
258 register char const * sd = sc;
268 void WriteStatus(MiniBuffer * minib, string const & s)
279 void WriteAlert(string const & s1, string const & s2, string const & s3)
281 MiniBuffer * minibuffer = 0;
282 if (current_view && current_view->owner())
283 minibuffer = current_view->owner()->getMiniBuffer();
285 /// Write to minibuffer
286 ProhibitInput(current_view);
287 minibuffer->Set(s1, s2, s3);
288 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
289 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
290 AllowInput(current_view);
293 lyxerr << "----------------------------------------" << endl
294 << s1 << endl << s2 << endl << s3 << endl
295 << "----------------------------------------" << endl;
300 // Alarms user of something related to files
301 void WriteFSAlert(string const & s1, string const & s2)
303 WriteAlert(s1, s2, strerror(errno));
307 bool AskQuestion(string const & s1, string const & s2, string const & s3)
309 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
310 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
311 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
315 // Returns 1 for yes, 2 for no, 3 for cancel.
316 int AskConfirmation(string const & s1, string const & s2, string const & s3)
318 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
320 scex(_("Cancel|^[")));
321 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
322 3, idex(_("Yes|Yy#y")),
324 idex(_("Cancel|^[")), 3);
329 pair<bool, string> const
330 askForText(string const & msg, string const & dflt)
332 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
333 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
334 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
335 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
337 return make_pair<bool, string>(true, string(tmp));
339 return make_pair<bool, string>(false, string());
343 // Inform the user that the buffer is read-only, and that changes in the
344 // dialog box that is to appear will be ignored.
345 void WarnReadonly(string const & file)
347 WriteAlert(_("Any changes will be ignored"),
348 _("The document is read-only:"),
349 MakeDisplayPath(file));
352 /// Get the dpi setting of the current screen
355 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
356 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
357 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;