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 being killed when the close box is pressed in a popup.
70 extern "C" int IgnoreCloseBoxCB(FL_FORM *, void *)
76 // Prevents LyX from crashing when no buffers available
77 // This is also one of the functions that we _really_ dont want
78 // we should try to finds way to help us with that.
79 // The signal/slot mechanism can probably help.
80 void CloseAllBufferRelatedDialogs()
82 // don't forget to check that dynamically created forms
83 // have been created otherwise hiding one could cause a crash
84 // need the visible check otherwise XForms prints a warning
85 // if hiding an invisible form
86 if (fd_form_character->form_character->visible) {
87 fl_hide_form(fd_form_character->form_character);
89 if (fd_form_preamble->form_preamble->visible) {
90 fl_hide_form(fd_form_preamble->form_preamble);
92 if (fd_form_figure->form_figure->visible) {
93 fl_hide_form(fd_form_figure->form_figure);
95 if (fd_form_sendto->form_sendto->visible) {
96 fl_hide_form(fd_form_sendto->form_sendto);
98 if (fd_latex_log->LaTeXLog->visible) {
99 fl_hide_form(fd_latex_log->LaTeXLog);
101 if (fd_form_spell_check) {
102 if (fd_form_spell_check->form_spell_check->visible) {
103 fl_trigger_object(fd_form_spell_check->done);
107 if (fd_panel->panel->visible) {
108 fl_hide_form(fd_panel->panel);
112 if (fd_delim->delim->visible) {
113 fl_hide_form(fd_delim->delim);
117 if (fd_deco->deco->visible) {
118 fl_hide_form(fd_deco->deco);
122 if (fd_space->space->visible) {
123 fl_hide_form(fd_space->space);
127 if (fd_matrix->matrix->visible) {
128 fl_hide_form(fd_matrix->matrix);
132 if (bibitem_form->bibitem_form->visible) {
133 fl_hide_form(bibitem_form->bibitem_form);
137 if (form->include->visible) {
138 fl_hide_form(form->include);
144 // This is another function we really don't want.
145 // Again the Signal/Slot mechanism is tailor made for this task.
146 void updateAllVisibleBufferRelatedDialogs(bool)
148 if (fd_form_preamble->form_preamble->visible) {
149 UpdateLayoutPreamble();
151 if (fd_latex_log->LaTeXLog->visible) {
154 if (current_view->buffer() && current_view->buffer()->isReadonly()) {
155 // a little crude perhaps but it works. ARRae
156 if (fd_form_character->form_character->visible) {
157 fl_hide_form(fd_form_character->form_character);
159 #ifndef ALWAYS_CLOSE_MATH_PANELS
160 // The math popups should be closed only if we switch
161 // to a readonly buffer
163 if (fd_panel->panel->visible) {
164 fl_hide_form(fd_panel->panel);
168 if (fd_delim->delim->visible) {
169 fl_hide_form(fd_delim->delim);
173 if (fd_deco->deco->visible) {
174 fl_hide_form(fd_deco->deco);
178 if (fd_space->space->visible) {
179 fl_hide_form(fd_space->space);
183 if (fd_matrix->matrix->visible) {
184 fl_hide_form(fd_matrix->matrix);
190 // We have either changed buffers or changed the readonly status
191 // so the safest thing to do is hide all inset popups that
192 // are editting insets from the previous buffer or aren't
193 // allowed in readonly docs.
194 #ifdef ALWAYS_CLOSE_MATH_PANELS
196 if (fd_panel->panel->visible) {
197 fl_hide_form(fd_panel->panel);
201 if (fd_delim->delim->visible) {
202 fl_hide_form(fd_delim->delim);
206 if (fd_deco->deco->visible) {
207 fl_hide_form(fd_deco->deco);
211 if (fd_space->space->visible) {
212 fl_hide_form(fd_space->space);
216 if (fd_matrix->matrix->visible) {
217 fl_hide_form(fd_matrix->matrix);
222 if (bibitem_form->bibitem_form->visible) {
223 fl_hide_form(bibitem_form->bibitem_form);
227 if (form->include->visible) {
228 fl_hide_form(form->include);
234 // Extract shortcut from <ident>|<shortcut> string
235 char const * flyx_shortcut_extract(char const * sc)
237 // Find '|' in the sc and return the string after that.
238 register char const * sd = sc;
239 while(sd[0]!= 0 && sd[0] != '|') ++sd;
243 //lyxerr << sd << endl;
250 // Extract identifier from <ident>|<shortcut> string
251 char const * flyx_ident_extract(char const * sc)
253 register char const * se = sc;
254 while(se[0]!= 0 && se[0] != '|') ++se;
256 if (se[0] == 0) return sc;
258 char * sb = new char[se - sc + 1];
260 register char const * sd = sc;
270 void WriteStatus(MiniBuffer * minib, string const & s)
281 void WriteAlert(string const & s1, string const & s2, string const & s3)
283 MiniBuffer * minibuffer = 0;
284 if (current_view && current_view->owner())
285 minibuffer = current_view->owner()->getMiniBuffer();
287 /// Write to minibuffer
288 ProhibitInput(current_view);
289 minibuffer->Set(s1, s2, s3);
290 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
291 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
292 AllowInput(current_view);
295 lyxerr << "----------------------------------------" << endl
296 << s1 << endl << s2 << endl << s3 << endl
297 << "----------------------------------------" << endl;
302 // Alarms user of something related to files
303 void WriteFSAlert(string const & s1, string const & s2)
305 WriteAlert(s1, s2, strerror(errno));
309 bool AskQuestion(string const & s1, string const & s2, string const & s3,
312 if (!lyxrc.use_gui) {
313 lyxerr << "----------------------------------------" << endl
316 lyxerr << s2 << endl;
318 lyxerr << s3 << endl;
319 lyxerr << "Assuming answer is "
320 << (default_value ? "yes" : "no")
322 << "----------------------------------------" << endl;
323 return default_value;
326 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
327 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
328 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
332 // Returns 1 for yes, 2 for no, 3 for cancel.
333 int AskConfirmation(string const & s1, string const & s2, string const & s3,
336 if (!lyxrc.use_gui) {
337 lyxerr << "----------------------------------------" << endl
340 lyxerr << s2 << endl;
342 lyxerr << s3 << endl;
343 lyxerr << "Assuming answer is ";
344 if (default_value == 1)
346 else if (default_value == 2)
351 << "----------------------------------------" << endl;
352 return default_value;
355 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
357 scex(_("Cancel|^[")));
358 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
359 3, idex(_("Yes|Yy#y")),
361 idex(_("Cancel|^[")), 3);
366 pair<bool, string> const
367 askForText(string const & msg, string const & dflt)
369 if (!lyxrc.use_gui) {
370 lyxerr << "----------------------------------------" << endl
372 << "Assuming answer is " << dflt
373 << "----------------------------------------" << endl;
374 return make_pair<bool, string>(true, dflt);
377 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
378 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
379 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
380 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
382 return make_pair<bool, string>(true, string(tmp));
384 return make_pair<bool, string>(false, string());
388 // Inform the user that the buffer is read-only, and that changes in the
389 // dialog box that is to appear will be ignored.
390 void WarnReadonly(string const & file)
392 WriteAlert(_("Any changes will be ignored"),
393 _("The document is read-only:"),
394 MakeDisplayPath(file));
397 /// Get the dpi setting of the current screen
400 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
401 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
402 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;