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_sendto * fd_form_sendto;
48 extern FD_form_spell_check * fd_form_spell_check;
49 extern FD_form_spell_options * fd_form_spell_options;
50 extern FD_panel * fd_panel;
51 extern FD_delim * fd_delim;
52 extern FD_deco * fd_deco;
53 extern FD_space * fd_space;
54 extern FD_matrix * fd_matrix;
56 extern void HideFiguresPopups();
58 // Prevents LyX from being killed when the close box is pressed in a popup.
59 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
63 // Redraw the form (on receipt of a Signal indicating, for example,
64 // that the xform colors have been re-mapped).
65 void RedrawAllBufferRelatedDialogs()
67 if (fd_deco && fd_deco->deco->visible) {
68 fl_redraw_form(fd_deco->deco);
70 if (fd_delim && fd_delim->delim->visible) {
71 fl_redraw_form(fd_delim->delim);
73 if (fd_form_character->form_character->visible) {
74 fl_redraw_form(fd_form_character->form_character);
76 if (fd_form_credits && fd_form_credits->form_credits->visible) {
77 fl_redraw_form(fd_form_credits->form_credits);
79 if (fd_form_figure->form_figure->visible) {
80 fl_redraw_form(fd_form_figure->form_figure);
82 if (fd_form_sendto->form_sendto->visible) {
83 fl_redraw_form(fd_form_sendto->form_sendto);
85 if (fd_form_spell_check &&
86 fd_form_spell_check->form_spell_check->visible) {
87 fl_redraw_form(fd_form_spell_check->form_spell_check);
89 if (fd_form_spell_options &&
90 fd_form_spell_options->form_spell_options->visible) {
91 fl_redraw_form(fd_form_spell_options->form_spell_options);
93 if (fd_matrix && fd_matrix->matrix->visible) {
94 fl_redraw_form(fd_matrix->matrix);
96 if (fd_panel && fd_panel->panel->visible) {
97 fl_redraw_form(fd_panel->panel);
99 if (fd_space && fd_space->space->visible) {
100 fl_redraw_form(fd_space->space);
104 // Prevents LyX from crashing when no buffers available
105 // This is also one of the functions that we _really_ dont want
106 // we should try to finds way to help us with that.
107 // The signal/slot mechanism can probably help.
108 void CloseAllBufferRelatedDialogs()
110 // don't forget to check that dynamically created forms
111 // have been created otherwise hiding one could cause a crash
112 // need the visible check otherwise XForms prints a warning
113 // if hiding an invisible form
114 if (fd_form_character->form_character->visible) {
115 fl_hide_form(fd_form_character->form_character);
117 if (fd_form_figure->form_figure->visible) {
118 fl_hide_form(fd_form_figure->form_figure);
120 if (fd_form_sendto->form_sendto->visible) {
121 fl_hide_form(fd_form_sendto->form_sendto);
123 if (fd_form_spell_check) {
124 if (fd_form_spell_check->form_spell_check->visible) {
125 fl_trigger_object(fd_form_spell_check->done);
129 if (fd_panel->panel->visible) {
130 fl_hide_form(fd_panel->panel);
134 if (fd_delim->delim->visible) {
135 fl_hide_form(fd_delim->delim);
139 if (fd_deco->deco->visible) {
140 fl_hide_form(fd_deco->deco);
144 if (fd_space->space->visible) {
145 fl_hide_form(fd_space->space);
149 if (fd_matrix->matrix->visible) {
150 fl_hide_form(fd_matrix->matrix);
156 // This is another function we really don't want.
157 // Again the Signal/Slot mechanism is tailor made for this task.
158 void updateAllVisibleBufferRelatedDialogs(bool)
160 if (current_view->buffer() && current_view->buffer()->isReadonly()) {
161 // a little crude perhaps but it works. ARRae
162 if (fd_form_character->form_character->visible) {
163 fl_hide_form(fd_form_character->form_character);
165 #ifndef ALWAYS_CLOSE_MATH_PANELS
166 // The math popups should be closed only if we switch
167 // to a readonly buffer
169 if (fd_panel->panel->visible) {
170 fl_hide_form(fd_panel->panel);
174 if (fd_delim->delim->visible) {
175 fl_hide_form(fd_delim->delim);
179 if (fd_deco->deco->visible) {
180 fl_hide_form(fd_deco->deco);
184 if (fd_space->space->visible) {
185 fl_hide_form(fd_space->space);
189 if (fd_matrix->matrix->visible) {
190 fl_hide_form(fd_matrix->matrix);
196 // We have either changed buffers or changed the readonly status
197 // so the safest thing to do is hide all inset popups that
198 // are editting insets from the previous buffer or aren't
199 // allowed in readonly docs.
200 #ifdef ALWAYS_CLOSE_MATH_PANELS
202 if (fd_panel->panel->visible) {
203 fl_hide_form(fd_panel->panel);
207 if (fd_delim->delim->visible) {
208 fl_hide_form(fd_delim->delim);
212 if (fd_deco->deco->visible) {
213 fl_hide_form(fd_deco->deco);
217 if (fd_space->space->visible) {
218 fl_hide_form(fd_space->space);
222 if (fd_matrix->matrix->visible) {
223 fl_hide_form(fd_matrix->matrix);
230 // Extract shortcut from <ident>|<shortcut> string
231 char const * flyx_shortcut_extract(char const * sc)
233 // Find '|' in the sc and return the string after that.
234 register char const * sd = sc;
235 while(sd[0]!= 0 && sd[0] != '|') ++sd;
239 //lyxerr << sd << endl;
246 // Extract identifier from <ident>|<shortcut> string
247 char const * flyx_ident_extract(char const * sc)
249 register char const * se = sc;
250 while(se[0]!= 0 && se[0] != '|') ++se;
252 if (se[0] == 0) return sc;
254 char * sb = new char[se - sc + 1];
256 register char const * sd = sc;
266 void WriteStatus(MiniBuffer * minib, string const & s)
277 void WriteAlert(string const & s1, string const & s2, string const & s3)
279 MiniBuffer * minibuffer = 0;
280 if (current_view && current_view->owner())
281 minibuffer = current_view->owner()->getMiniBuffer();
283 /// Write to minibuffer
284 ProhibitInput(current_view);
285 minibuffer->Set(s1, s2, s3);
286 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
287 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
288 AllowInput(current_view);
291 lyxerr << "----------------------------------------" << endl
292 << s1 << endl << s2 << endl << s3 << endl
293 << "----------------------------------------" << endl;
298 // Alarms user of something related to files
299 void WriteFSAlert(string const & s1, string const & s2)
301 WriteAlert(s1, s2, strerror(errno));
305 bool AskQuestion(string const & s1, string const & s2, string const & s3,
308 if (!lyxrc.use_gui) {
309 lyxerr << "----------------------------------------" << endl
312 lyxerr << s2 << endl;
314 lyxerr << s3 << endl;
315 lyxerr << "Assuming answer is "
316 << (default_value ? "yes" : "no")
318 << "----------------------------------------" << endl;
319 return default_value;
322 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
323 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
324 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
328 // Returns 1 for yes, 2 for no, 3 for cancel.
329 int AskConfirmation(string const & s1, string const & s2, string const & s3,
332 if (!lyxrc.use_gui) {
333 lyxerr << "----------------------------------------" << endl
336 lyxerr << s2 << endl;
338 lyxerr << s3 << endl;
339 lyxerr << "Assuming answer is ";
340 if (default_value == 1)
342 else if (default_value == 2)
347 << "----------------------------------------" << endl;
348 return default_value;
351 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
353 scex(_("Cancel|^[")));
354 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
355 3, idex(_("Yes|Yy#y")),
357 idex(_("Cancel|^[")), 3);
362 pair<bool, string> const
363 askForText(string const & msg, string const & dflt)
365 if (!lyxrc.use_gui) {
366 lyxerr << "----------------------------------------" << endl
368 << "Assuming answer is " << dflt
369 << "----------------------------------------" << endl;
370 return make_pair<bool, string>(true, dflt);
373 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
374 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
375 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
376 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
378 return make_pair<bool, string>(true, string(tmp));
380 return make_pair<bool, string>(false, string());
384 // Inform the user that the buffer is read-only, and that changes in the
385 // dialog box that is to appear will be ignored.
386 void WarnReadonly(string const & file)
388 WriteAlert(_("Any changes will be ignored"),
389 _("The document is read-only:"),
390 MakeDisplayPath(file));
393 /// Get the dpi setting of the current screen
396 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
397 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
398 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;