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"
27 #include "mathed/math_forms.h"
28 #include "minibuffer.h"
29 #include "print_form.h"
32 #include "bufferview_funcs.h"
33 #include "support/filetools.h"
40 extern BufferView * current_view;
42 extern FD_form_figure * fd_form_figure;
43 extern FD_form_sendto * fd_form_sendto;
44 extern FD_form_spell_check * fd_form_spell_check;
45 extern FD_form_spell_options * fd_form_spell_options;
46 extern FD_panel * fd_panel;
47 extern FD_delim * fd_delim;
48 extern FD_deco * fd_deco;
49 extern FD_space * fd_space;
50 extern FD_matrix * fd_matrix;
52 extern void HideFiguresPopups();
54 // Prevents LyX from being killed when the close box is pressed in a popup.
55 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
59 // Redraw the form (on receipt of a Signal indicating, for example,
60 // that the xform colors have been re-mapped).
61 void RedrawAllBufferRelatedDialogs()
63 if (fd_deco && fd_deco->deco->visible) {
64 fl_redraw_form(fd_deco->deco);
66 if (fd_delim && fd_delim->delim->visible) {
67 fl_redraw_form(fd_delim->delim);
69 if (fd_form_figure->form_figure->visible) {
70 fl_redraw_form(fd_form_figure->form_figure);
72 if (fd_form_sendto->form_sendto->visible) {
73 fl_redraw_form(fd_form_sendto->form_sendto);
75 if (fd_form_spell_check &&
76 fd_form_spell_check->form_spell_check->visible) {
77 fl_redraw_form(fd_form_spell_check->form_spell_check);
79 if (fd_form_spell_options &&
80 fd_form_spell_options->form_spell_options->visible) {
81 fl_redraw_form(fd_form_spell_options->form_spell_options);
83 if (fd_matrix && fd_matrix->matrix->visible) {
84 fl_redraw_form(fd_matrix->matrix);
86 if (fd_panel && fd_panel->panel->visible) {
87 fl_redraw_form(fd_panel->panel);
89 if (fd_space && fd_space->space->visible) {
90 fl_redraw_form(fd_space->space);
94 // Prevents LyX from crashing when no buffers available
95 // This is also one of the functions that we _really_ dont want
96 // we should try to finds way to help us with that.
97 // The signal/slot mechanism can probably help.
98 void CloseAllBufferRelatedDialogs()
100 // don't forget to check that dynamically created forms
101 // have been created otherwise hiding one could cause a crash
102 // need the visible check otherwise XForms prints a warning
103 // if hiding an invisible form
104 if (fd_form_figure->form_figure->visible) {
105 fl_hide_form(fd_form_figure->form_figure);
107 if (fd_form_sendto->form_sendto->visible) {
108 fl_hide_form(fd_form_sendto->form_sendto);
110 if (fd_form_spell_check) {
111 if (fd_form_spell_check->form_spell_check->visible) {
112 fl_trigger_object(fd_form_spell_check->done);
116 if (fd_panel->panel->visible) {
117 fl_hide_form(fd_panel->panel);
121 if (fd_delim->delim->visible) {
122 fl_hide_form(fd_delim->delim);
126 if (fd_deco->deco->visible) {
127 fl_hide_form(fd_deco->deco);
131 if (fd_space->space->visible) {
132 fl_hide_form(fd_space->space);
136 if (fd_matrix->matrix->visible) {
137 fl_hide_form(fd_matrix->matrix);
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(bool)
147 if (current_view->buffer() && current_view->buffer()->isReadonly()) {
148 // a little crude perhaps but it works. ARRae
149 // The math popups should be closed only if we switch
150 // to a readonly buffer
152 if (fd_panel->panel->visible) {
153 fl_hide_form(fd_panel->panel);
157 if (fd_delim->delim->visible) {
158 fl_hide_form(fd_delim->delim);
162 if (fd_deco->deco->visible) {
163 fl_hide_form(fd_deco->deco);
167 if (fd_space->space->visible) {
168 fl_hide_form(fd_space->space);
172 if (fd_matrix->matrix->visible) {
173 fl_hide_form(fd_matrix->matrix);
180 // Extract shortcut from <ident>|<shortcut> string
181 char const * flyx_shortcut_extract(char const * sc)
183 // Find '|' in the sc and return the string after that.
184 register char const * sd = sc;
185 while(sd[0]!= 0 && sd[0] != '|') ++sd;
189 //lyxerr << sd << endl;
196 // Extract identifier from <ident>|<shortcut> string
197 char const * flyx_ident_extract(char const * sc)
199 register char const * se = sc;
200 while(se[0]!= 0 && se[0] != '|') ++se;
202 if (se[0] == 0) return sc;
204 char * sb = new char[se - sc + 1];
206 register char const * sd = sc;
216 void WriteStatus(MiniBuffer * minib, string const & s)
227 void WriteAlert(string const & s1, string const & s2, string const & s3)
229 MiniBuffer * minibuffer = 0;
230 if (current_view && current_view->owner())
231 minibuffer = current_view->owner()->getMiniBuffer();
233 /// Write to minibuffer
234 ProhibitInput(current_view);
235 minibuffer->Set(s1, s2, s3);
236 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
237 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
238 AllowInput(current_view);
241 lyxerr << "----------------------------------------" << endl
242 << s1 << endl << s2 << endl << s3 << endl
243 << "----------------------------------------" << endl;
248 // Alarms user of something related to files
249 void WriteFSAlert(string const & s1, string const & s2)
251 WriteAlert(s1, s2, strerror(errno));
255 bool AskQuestion(string const & s1, string const & s2, string const & s3,
258 if (!lyxrc.use_gui) {
259 lyxerr << "----------------------------------------" << endl
262 lyxerr << s2 << endl;
264 lyxerr << s3 << endl;
265 lyxerr << "Assuming answer is "
266 << (default_value ? "yes" : "no")
268 << "----------------------------------------" << endl;
269 return default_value;
272 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
273 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
274 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
278 // Returns 1 for yes, 2 for no, 3 for cancel.
279 int AskConfirmation(string const & s1, string const & s2, string const & s3,
282 if (!lyxrc.use_gui) {
283 lyxerr << "----------------------------------------" << endl
286 lyxerr << s2 << endl;
288 lyxerr << s3 << endl;
289 lyxerr << "Assuming answer is ";
290 if (default_value == 1)
292 else if (default_value == 2)
297 << "----------------------------------------" << endl;
298 return default_value;
301 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
303 scex(_("Cancel|^[")));
304 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
305 3, idex(_("Yes|Yy#y")),
307 idex(_("Cancel|^[")), 3);
312 pair<bool, string> const
313 askForText(string const & msg, string const & dflt)
315 if (!lyxrc.use_gui) {
316 lyxerr << "----------------------------------------" << endl
318 << "Assuming answer is " << dflt
319 << "----------------------------------------" << endl;
320 return make_pair<bool, string>(true, dflt);
323 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
324 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
325 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
326 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
328 return make_pair<bool, string>(true, string(tmp));
330 return make_pair<bool, string>(false, string());
334 // Inform the user that the buffer is read-only, and that changes in the
335 // dialog box that is to appear will be ignored.
336 void WarnReadonly(string const & file)
338 WriteAlert(_("Any changes will be ignored"),
339 _("The document is read-only:"),
340 MakeDisplayPath(file));
343 /// Get the dpi setting of the current screen
346 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
347 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
348 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;