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"
22 #include "credits_form.h"
28 #include "mathed/math_forms.h"
29 #include "minibuffer.h"
30 #include "print_form.h"
33 #include "bufferview_funcs.h"
34 #include "support/filetools.h"
41 extern BufferView * current_view;
43 extern FD_form_credits * fd_form_credits;
44 extern FD_form_figure * fd_form_figure;
45 extern FD_form_sendto * fd_form_sendto;
46 extern FD_form_spell_check * fd_form_spell_check;
47 extern FD_form_spell_options * fd_form_spell_options;
48 extern FD_panel * fd_panel;
49 extern FD_delim * fd_delim;
50 extern FD_deco * fd_deco;
51 extern FD_space * fd_space;
52 extern FD_matrix * fd_matrix;
54 extern void HideFiguresPopups();
56 // Prevents LyX from being killed when the close box is pressed in a popup.
57 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
61 // Redraw the form (on receipt of a Signal indicating, for example,
62 // that the xform colors have been re-mapped).
63 void RedrawAllBufferRelatedDialogs()
65 if (fd_deco && fd_deco->deco->visible) {
66 fl_redraw_form(fd_deco->deco);
68 if (fd_delim && fd_delim->delim->visible) {
69 fl_redraw_form(fd_delim->delim);
71 if (fd_form_credits && fd_form_credits->form_credits->visible) {
72 fl_redraw_form(fd_form_credits->form_credits);
74 if (fd_form_figure->form_figure->visible) {
75 fl_redraw_form(fd_form_figure->form_figure);
77 if (fd_form_sendto->form_sendto->visible) {
78 fl_redraw_form(fd_form_sendto->form_sendto);
80 if (fd_form_spell_check &&
81 fd_form_spell_check->form_spell_check->visible) {
82 fl_redraw_form(fd_form_spell_check->form_spell_check);
84 if (fd_form_spell_options &&
85 fd_form_spell_options->form_spell_options->visible) {
86 fl_redraw_form(fd_form_spell_options->form_spell_options);
88 if (fd_matrix && fd_matrix->matrix->visible) {
89 fl_redraw_form(fd_matrix->matrix);
91 if (fd_panel && fd_panel->panel->visible) {
92 fl_redraw_form(fd_panel->panel);
94 if (fd_space && fd_space->space->visible) {
95 fl_redraw_form(fd_space->space);
99 // Prevents LyX from crashing when no buffers available
100 // This is also one of the functions that we _really_ dont want
101 // we should try to finds way to help us with that.
102 // The signal/slot mechanism can probably help.
103 void CloseAllBufferRelatedDialogs()
105 // don't forget to check that dynamically created forms
106 // have been created otherwise hiding one could cause a crash
107 // need the visible check otherwise XForms prints a warning
108 // if hiding an invisible form
109 if (fd_form_figure->form_figure->visible) {
110 fl_hide_form(fd_form_figure->form_figure);
112 if (fd_form_sendto->form_sendto->visible) {
113 fl_hide_form(fd_form_sendto->form_sendto);
115 if (fd_form_spell_check) {
116 if (fd_form_spell_check->form_spell_check->visible) {
117 fl_trigger_object(fd_form_spell_check->done);
121 if (fd_panel->panel->visible) {
122 fl_hide_form(fd_panel->panel);
126 if (fd_delim->delim->visible) {
127 fl_hide_form(fd_delim->delim);
131 if (fd_deco->deco->visible) {
132 fl_hide_form(fd_deco->deco);
136 if (fd_space->space->visible) {
137 fl_hide_form(fd_space->space);
141 if (fd_matrix->matrix->visible) {
142 fl_hide_form(fd_matrix->matrix);
148 // This is another function we really don't want.
149 // Again the Signal/Slot mechanism is tailor made for this task.
150 void updateAllVisibleBufferRelatedDialogs(bool)
152 if (current_view->buffer() && current_view->buffer()->isReadonly()) {
153 // a little crude perhaps but it works. ARRae
154 #ifndef ALWAYS_CLOSE_MATH_PANELS
155 // The math popups should be closed only if we switch
156 // to a readonly buffer
158 if (fd_panel->panel->visible) {
159 fl_hide_form(fd_panel->panel);
163 if (fd_delim->delim->visible) {
164 fl_hide_form(fd_delim->delim);
168 if (fd_deco->deco->visible) {
169 fl_hide_form(fd_deco->deco);
173 if (fd_space->space->visible) {
174 fl_hide_form(fd_space->space);
178 if (fd_matrix->matrix->visible) {
179 fl_hide_form(fd_matrix->matrix);
185 // We have either changed buffers or changed the readonly status
186 // so the safest thing to do is hide all inset popups that
187 // are editting insets from the previous buffer or aren't
188 // allowed in readonly docs.
189 #ifdef ALWAYS_CLOSE_MATH_PANELS
191 if (fd_panel->panel->visible) {
192 fl_hide_form(fd_panel->panel);
196 if (fd_delim->delim->visible) {
197 fl_hide_form(fd_delim->delim);
201 if (fd_deco->deco->visible) {
202 fl_hide_form(fd_deco->deco);
206 if (fd_space->space->visible) {
207 fl_hide_form(fd_space->space);
211 if (fd_matrix->matrix->visible) {
212 fl_hide_form(fd_matrix->matrix);
219 // Extract shortcut from <ident>|<shortcut> string
220 char const * flyx_shortcut_extract(char const * sc)
222 // Find '|' in the sc and return the string after that.
223 register char const * sd = sc;
224 while(sd[0]!= 0 && sd[0] != '|') ++sd;
228 //lyxerr << sd << endl;
235 // Extract identifier from <ident>|<shortcut> string
236 char const * flyx_ident_extract(char const * sc)
238 register char const * se = sc;
239 while(se[0]!= 0 && se[0] != '|') ++se;
241 if (se[0] == 0) return sc;
243 char * sb = new char[se - sc + 1];
245 register char const * sd = sc;
255 void WriteStatus(MiniBuffer * minib, string const & s)
266 void WriteAlert(string const & s1, string const & s2, string const & s3)
268 MiniBuffer * minibuffer = 0;
269 if (current_view && current_view->owner())
270 minibuffer = current_view->owner()->getMiniBuffer();
272 /// Write to minibuffer
273 ProhibitInput(current_view);
274 minibuffer->Set(s1, s2, s3);
275 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
276 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
277 AllowInput(current_view);
280 lyxerr << "----------------------------------------" << endl
281 << s1 << endl << s2 << endl << s3 << endl
282 << "----------------------------------------" << endl;
287 // Alarms user of something related to files
288 void WriteFSAlert(string const & s1, string const & s2)
290 WriteAlert(s1, s2, strerror(errno));
294 bool AskQuestion(string const & s1, string const & s2, string const & s3,
297 if (!lyxrc.use_gui) {
298 lyxerr << "----------------------------------------" << endl
301 lyxerr << s2 << endl;
303 lyxerr << s3 << endl;
304 lyxerr << "Assuming answer is "
305 << (default_value ? "yes" : "no")
307 << "----------------------------------------" << endl;
308 return default_value;
311 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
312 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
313 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
317 // Returns 1 for yes, 2 for no, 3 for cancel.
318 int AskConfirmation(string const & s1, string const & s2, string const & s3,
321 if (!lyxrc.use_gui) {
322 lyxerr << "----------------------------------------" << endl
325 lyxerr << s2 << endl;
327 lyxerr << s3 << endl;
328 lyxerr << "Assuming answer is ";
329 if (default_value == 1)
331 else if (default_value == 2)
336 << "----------------------------------------" << endl;
337 return default_value;
340 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
342 scex(_("Cancel|^[")));
343 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
344 3, idex(_("Yes|Yy#y")),
346 idex(_("Cancel|^[")), 3);
351 pair<bool, string> const
352 askForText(string const & msg, string const & dflt)
354 if (!lyxrc.use_gui) {
355 lyxerr << "----------------------------------------" << endl
357 << "Assuming answer is " << dflt
358 << "----------------------------------------" << endl;
359 return make_pair<bool, string>(true, dflt);
362 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
363 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
364 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
365 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
367 return make_pair<bool, string>(true, string(tmp));
369 return make_pair<bool, string>(false, string());
373 // Inform the user that the buffer is read-only, and that changes in the
374 // dialog box that is to appear will be ignored.
375 void WarnReadonly(string const & file)
377 WriteAlert(_("Any changes will be ignored"),
378 _("The document is read-only:"),
379 MakeDisplayPath(file));
382 /// Get the dpi setting of the current screen
385 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
386 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
387 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;