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"
25 #include "layout_forms.h"
29 #include "mathed/math_forms.h"
30 #include "minibuffer.h"
31 #include "print_form.h"
34 #include "bufferview_funcs.h"
35 #include "support/filetools.h"
42 extern BufferView * current_view;
44 extern FD_form_character * fd_form_character;
45 extern FD_form_credits * fd_form_credits;
46 extern FD_form_figure * fd_form_figure;
47 extern FD_form_preamble * fd_form_preamble;
48 extern FD_form_sendto * fd_form_sendto;
49 extern FD_form_spell_check * fd_form_spell_check;
50 extern FD_form_spell_options * fd_form_spell_options;
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;
57 extern void HideFiguresPopups();
59 // Prevents LyX from being killed when the close box is pressed in a popup.
60 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
64 // Redraw the form (on receipt of a Signal indicating, for example,
65 // that the xform colors have been re-mapped).
66 void RedrawAllBufferRelatedDialogs()
68 if (fd_deco && fd_deco->deco->visible) {
69 fl_redraw_form(fd_deco->deco);
71 if (fd_delim && fd_delim->delim->visible) {
72 fl_redraw_form(fd_delim->delim);
74 if (fd_form_character->form_character->visible) {
75 fl_redraw_form(fd_form_character->form_character);
77 if (fd_form_credits && fd_form_credits->form_credits->visible) {
78 fl_redraw_form(fd_form_credits->form_credits);
80 if (fd_form_figure->form_figure->visible) {
81 fl_redraw_form(fd_form_figure->form_figure);
83 if (fd_form_preamble->form_preamble->visible) {
84 fl_redraw_form(fd_form_preamble->form_preamble);
86 if (fd_form_sendto->form_sendto->visible) {
87 fl_redraw_form(fd_form_sendto->form_sendto);
89 if (fd_form_spell_check &&
90 fd_form_spell_check->form_spell_check->visible) {
91 fl_redraw_form(fd_form_spell_check->form_spell_check);
93 if (fd_form_spell_options &&
94 fd_form_spell_options->form_spell_options->visible) {
95 fl_redraw_form(fd_form_spell_options->form_spell_options);
97 if (fd_matrix && fd_matrix->matrix->visible) {
98 fl_redraw_form(fd_matrix->matrix);
100 if (fd_panel && fd_panel->panel->visible) {
101 fl_redraw_form(fd_panel->panel);
103 if (fd_space && fd_space->space->visible) {
104 fl_redraw_form(fd_space->space);
108 // Prevents LyX from crashing when no buffers available
109 // This is also one of the functions that we _really_ dont want
110 // we should try to finds way to help us with that.
111 // The signal/slot mechanism can probably help.
112 void CloseAllBufferRelatedDialogs()
114 // don't forget to check that dynamically created forms
115 // have been created otherwise hiding one could cause a crash
116 // need the visible check otherwise XForms prints a warning
117 // if hiding an invisible form
118 if (fd_form_character->form_character->visible) {
119 fl_hide_form(fd_form_character->form_character);
121 if (fd_form_preamble->form_preamble->visible) {
122 fl_hide_form(fd_form_preamble->form_preamble);
124 if (fd_form_figure->form_figure->visible) {
125 fl_hide_form(fd_form_figure->form_figure);
127 if (fd_form_sendto->form_sendto->visible) {
128 fl_hide_form(fd_form_sendto->form_sendto);
130 if (fd_form_spell_check) {
131 if (fd_form_spell_check->form_spell_check->visible) {
132 fl_trigger_object(fd_form_spell_check->done);
136 if (fd_panel->panel->visible) {
137 fl_hide_form(fd_panel->panel);
141 if (fd_delim->delim->visible) {
142 fl_hide_form(fd_delim->delim);
146 if (fd_deco->deco->visible) {
147 fl_hide_form(fd_deco->deco);
151 if (fd_space->space->visible) {
152 fl_hide_form(fd_space->space);
156 if (fd_matrix->matrix->visible) {
157 fl_hide_form(fd_matrix->matrix);
163 // This is another function we really don't want.
164 // Again the Signal/Slot mechanism is tailor made for this task.
165 void updateAllVisibleBufferRelatedDialogs(bool)
167 if (fd_form_preamble->form_preamble->visible) {
168 UpdateLayoutPreamble(current_view);
170 if (current_view->buffer() && current_view->buffer()->isReadonly()) {
171 // a little crude perhaps but it works. ARRae
172 if (fd_form_character->form_character->visible) {
173 fl_hide_form(fd_form_character->form_character);
175 #ifndef ALWAYS_CLOSE_MATH_PANELS
176 // The math popups should be closed only if we switch
177 // to a readonly buffer
179 if (fd_panel->panel->visible) {
180 fl_hide_form(fd_panel->panel);
184 if (fd_delim->delim->visible) {
185 fl_hide_form(fd_delim->delim);
189 if (fd_deco->deco->visible) {
190 fl_hide_form(fd_deco->deco);
194 if (fd_space->space->visible) {
195 fl_hide_form(fd_space->space);
199 if (fd_matrix->matrix->visible) {
200 fl_hide_form(fd_matrix->matrix);
206 // We have either changed buffers or changed the readonly status
207 // so the safest thing to do is hide all inset popups that
208 // are editting insets from the previous buffer or aren't
209 // allowed in readonly docs.
210 #ifdef ALWAYS_CLOSE_MATH_PANELS
212 if (fd_panel->panel->visible) {
213 fl_hide_form(fd_panel->panel);
217 if (fd_delim->delim->visible) {
218 fl_hide_form(fd_delim->delim);
222 if (fd_deco->deco->visible) {
223 fl_hide_form(fd_deco->deco);
227 if (fd_space->space->visible) {
228 fl_hide_form(fd_space->space);
232 if (fd_matrix->matrix->visible) {
233 fl_hide_form(fd_matrix->matrix);
240 // Extract shortcut from <ident>|<shortcut> string
241 char const * flyx_shortcut_extract(char const * sc)
243 // Find '|' in the sc and return the string after that.
244 register char const * sd = sc;
245 while(sd[0]!= 0 && sd[0] != '|') ++sd;
249 //lyxerr << sd << endl;
256 // Extract identifier from <ident>|<shortcut> string
257 char const * flyx_ident_extract(char const * sc)
259 register char const * se = sc;
260 while(se[0]!= 0 && se[0] != '|') ++se;
262 if (se[0] == 0) return sc;
264 char * sb = new char[se - sc + 1];
266 register char const * sd = sc;
276 void WriteStatus(MiniBuffer * minib, string const & s)
287 void WriteAlert(string const & s1, string const & s2, string const & s3)
289 MiniBuffer * minibuffer = 0;
290 if (current_view && current_view->owner())
291 minibuffer = current_view->owner()->getMiniBuffer();
293 /// Write to minibuffer
294 ProhibitInput(current_view);
295 minibuffer->Set(s1, s2, s3);
296 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
297 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
298 AllowInput(current_view);
301 lyxerr << "----------------------------------------" << endl
302 << s1 << endl << s2 << endl << s3 << endl
303 << "----------------------------------------" << endl;
308 // Alarms user of something related to files
309 void WriteFSAlert(string const & s1, string const & s2)
311 WriteAlert(s1, s2, strerror(errno));
315 bool AskQuestion(string const & s1, string const & s2, string const & s3,
318 if (!lyxrc.use_gui) {
319 lyxerr << "----------------------------------------" << endl
322 lyxerr << s2 << endl;
324 lyxerr << s3 << endl;
325 lyxerr << "Assuming answer is "
326 << (default_value ? "yes" : "no")
328 << "----------------------------------------" << endl;
329 return default_value;
332 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
333 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
334 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
338 // Returns 1 for yes, 2 for no, 3 for cancel.
339 int AskConfirmation(string const & s1, string const & s2, string const & s3,
342 if (!lyxrc.use_gui) {
343 lyxerr << "----------------------------------------" << endl
346 lyxerr << s2 << endl;
348 lyxerr << s3 << endl;
349 lyxerr << "Assuming answer is ";
350 if (default_value == 1)
352 else if (default_value == 2)
357 << "----------------------------------------" << endl;
358 return default_value;
361 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
363 scex(_("Cancel|^[")));
364 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
365 3, idex(_("Yes|Yy#y")),
367 idex(_("Cancel|^[")), 3);
372 pair<bool, string> const
373 askForText(string const & msg, string const & dflt)
375 if (!lyxrc.use_gui) {
376 lyxerr << "----------------------------------------" << endl
378 << "Assuming answer is " << dflt
379 << "----------------------------------------" << endl;
380 return make_pair<bool, string>(true, dflt);
383 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
384 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
385 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
386 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
388 return make_pair<bool, string>(true, string(tmp));
390 return make_pair<bool, string>(false, string());
394 // Inform the user that the buffer is read-only, and that changes in the
395 // dialog box that is to appear will be ignored.
396 void WarnReadonly(string const & file)
398 WriteAlert(_("Any changes will be ignored"),
399 _("The document is read-only:"),
400 MakeDisplayPath(file));
403 /// Get the dpi setting of the current screen
406 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
407 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
408 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;