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"
43 extern BufferView * current_view;
45 extern FD_form_character * fd_form_character;
46 extern FD_form_preamble * fd_form_preamble;
47 extern FD_form_sendto * fd_form_sendto;
48 extern FD_form_figure * fd_form_figure;
49 extern FD_LaTeXLog * fd_latex_log;
50 extern FD_form_spell_check * fd_form_spell_check;
51 extern FD_panel * fd_panel;
52 extern FD_delim * fd_delim;
53 extern FD_deco * fd_deco;
54 extern FD_space * fd_space;
55 extern FD_matrix * fd_matrix;
56 extern FD_bibitem_form * bibitem_form;
57 extern FD_include * form;
59 extern void HideFiguresPopups();
61 // Prevents LyX from being killed when the close box is pressed in a popup.
62 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
68 // Prevents LyX from being killed when the close box is pressed in a popup.
69 extern "C" int IgnoreCloseBoxCB(FL_FORM *, void *)
75 // Prevents LyX from crashing when no buffers available
76 // This is also one of the functions that we _really_ dont want
77 // we should try to finds way to help us with that.
78 // The signal/slot mechanism can probably help.
79 void CloseAllBufferRelatedDialogs()
81 // don't forget to check that dynamically created forms
82 // have been created otherwise hiding one could cause a crash
83 // need the visible check otherwise XForms prints a warning
84 // if hiding an invisible form
85 if (fd_form_character->form_character->visible) {
86 fl_hide_form(fd_form_character->form_character);
88 if (fd_form_preamble->form_preamble->visible) {
89 fl_hide_form(fd_form_preamble->form_preamble);
91 if (fd_form_figure->form_figure->visible) {
92 fl_hide_form(fd_form_figure->form_figure);
94 if (fd_form_sendto->form_sendto->visible) {
95 fl_hide_form(fd_form_sendto->form_sendto);
97 if (fd_latex_log->LaTeXLog->visible) {
98 fl_hide_form(fd_latex_log->LaTeXLog);
100 if (fd_form_spell_check) {
101 if (fd_form_spell_check->form_spell_check->visible) {
102 fl_trigger_object(fd_form_spell_check->done);
106 if (fd_panel->panel->visible) {
107 fl_hide_form(fd_panel->panel);
111 if (fd_delim->delim->visible) {
112 fl_hide_form(fd_delim->delim);
116 if (fd_deco->deco->visible) {
117 fl_hide_form(fd_deco->deco);
121 if (fd_space->space->visible) {
122 fl_hide_form(fd_space->space);
126 if (fd_matrix->matrix->visible) {
127 fl_hide_form(fd_matrix->matrix);
131 if (bibitem_form->bibitem_form->visible) {
132 fl_hide_form(bibitem_form->bibitem_form);
136 if (form->include->visible) {
137 fl_hide_form(form->include);
143 // This is another function we really don't want.
144 // Again the Signal/Slot mechanism is tailor made for this task.
145 void updateAllVisibleBufferRelatedDialogs()
147 if (fd_form_preamble->form_preamble->visible) {
148 UpdateLayoutPreamble();
150 if (fd_latex_log->LaTeXLog->visible) {
153 if (current_view->buffer()->isReadonly()) {
154 // a little crude perhaps but it works. ARRae
155 if (fd_form_character->form_character->visible) {
156 fl_hide_form(fd_form_character->form_character);
158 #ifndef ALWAYS_CLOSE_MATH_PANELS
159 // The math popups should be closed only if we switch
160 // to a readonly buffer
162 if (fd_panel->panel->visible) {
163 fl_hide_form(fd_panel->panel);
167 if (fd_delim->delim->visible) {
168 fl_hide_form(fd_delim->delim);
172 if (fd_deco->deco->visible) {
173 fl_hide_form(fd_deco->deco);
177 if (fd_space->space->visible) {
178 fl_hide_form(fd_space->space);
182 if (fd_matrix->matrix->visible) {
183 fl_hide_form(fd_matrix->matrix);
189 // We have either changed buffers or changed the readonly status
190 // so the safest thing to do is hide all inset popups that
191 // are editting insets from the previous buffer or aren't
192 // allowed in readonly docs.
193 #ifdef ALWAYS_CLOSE_MATH_PANELS
195 if (fd_panel->panel->visible) {
196 fl_hide_form(fd_panel->panel);
200 if (fd_delim->delim->visible) {
201 fl_hide_form(fd_delim->delim);
205 if (fd_deco->deco->visible) {
206 fl_hide_form(fd_deco->deco);
210 if (fd_space->space->visible) {
211 fl_hide_form(fd_space->space);
215 if (fd_matrix->matrix->visible) {
216 fl_hide_form(fd_matrix->matrix);
221 if (bibitem_form->bibitem_form->visible) {
222 fl_hide_form(bibitem_form->bibitem_form);
226 if (form->include->visible) {
227 fl_hide_form(form->include);
233 // Extract shortcut from <ident>|<shortcut> string
234 char const * flyx_shortcut_extract(char const * sc)
236 // Find '|' in the sc and return the string after that.
237 register char const * sd = sc;
238 while(sd[0]!= 0 && sd[0] != '|') ++sd;
242 //lyxerr << sd << endl;
249 // Extract identifier from <ident>|<shortcut> string
250 char const * flyx_ident_extract(char const * sc)
252 register char const * se = sc;
253 while(se[0]!= 0 && se[0] != '|') ++se;
255 if (se[0] == 0) return sc;
257 char * sb = new char[se - sc + 1];
259 register char const * sd = sc;
269 void WriteStatus(MiniBuffer * minib, string const & s)
280 void WriteAlert(string const & s1, string const & s2, string const & s3)
282 MiniBuffer * minibuffer = 0;
283 if (current_view && current_view->owner())
284 minibuffer = current_view->owner()->getMiniBuffer();
286 /// Write to minibuffer
287 ProhibitInput(current_view);
288 minibuffer->Set(s1, s2, s3);
289 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
290 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
291 AllowInput(current_view);
294 lyxerr << "----------------------------------------" << endl
295 << s1 << endl << s2 << endl << s3 << endl
296 << "----------------------------------------" << endl;
301 // Alarms user of something related to files
302 void WriteFSAlert(string const & s1, string const & s2)
304 WriteAlert(s1, s2, strerror(errno));
308 bool AskQuestion(string const & s1, string const & s2, string const & s3)
310 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
311 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
312 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
316 // Returns 1 for yes, 2 for no, 3 for cancel.
317 int AskConfirmation(string const & s1, string const & s2, string const & s3)
319 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
321 scex(_("Cancel|^[")));
322 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
323 3, idex(_("Yes|Yy#y")),
325 idex(_("Cancel|^[")), 3);
330 pair<bool, string> const
331 askForText(string const & msg, string const & dflt)
333 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
334 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
335 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
336 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
338 return make_pair<bool, string>(true, string(tmp));
340 return make_pair<bool, string>(false, string());
344 // Inform the user that the buffer is read-only, and that changes in the
345 // dialog box that is to appear will be ignored.
346 void WarnReadonly(string const & file)
348 WriteAlert(_("Any changes will be ignored"),
349 _("The document is read-only:"),
350 MakeDisplayPath(file));
353 /// Get the dpi setting of the current screen
356 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
357 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
358 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;