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 // The math popups should be closed only if we switch
155 // to a readonly buffer
157 if (fd_panel->panel->visible) {
158 fl_hide_form(fd_panel->panel);
162 if (fd_delim->delim->visible) {
163 fl_hide_form(fd_delim->delim);
167 if (fd_deco->deco->visible) {
168 fl_hide_form(fd_deco->deco);
172 if (fd_space->space->visible) {
173 fl_hide_form(fd_space->space);
177 if (fd_matrix->matrix->visible) {
178 fl_hide_form(fd_matrix->matrix);
185 // Extract shortcut from <ident>|<shortcut> string
186 char const * flyx_shortcut_extract(char const * sc)
188 // Find '|' in the sc and return the string after that.
189 register char const * sd = sc;
190 while(sd[0]!= 0 && sd[0] != '|') ++sd;
194 //lyxerr << sd << endl;
201 // Extract identifier from <ident>|<shortcut> string
202 char const * flyx_ident_extract(char const * sc)
204 register char const * se = sc;
205 while(se[0]!= 0 && se[0] != '|') ++se;
207 if (se[0] == 0) return sc;
209 char * sb = new char[se - sc + 1];
211 register char const * sd = sc;
221 void WriteStatus(MiniBuffer * minib, string const & s)
232 void WriteAlert(string const & s1, string const & s2, string const & s3)
234 MiniBuffer * minibuffer = 0;
235 if (current_view && current_view->owner())
236 minibuffer = current_view->owner()->getMiniBuffer();
238 /// Write to minibuffer
239 ProhibitInput(current_view);
240 minibuffer->Set(s1, s2, s3);
241 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
242 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
243 AllowInput(current_view);
246 lyxerr << "----------------------------------------" << endl
247 << s1 << endl << s2 << endl << s3 << endl
248 << "----------------------------------------" << endl;
253 // Alarms user of something related to files
254 void WriteFSAlert(string const & s1, string const & s2)
256 WriteAlert(s1, s2, strerror(errno));
260 bool AskQuestion(string const & s1, string const & s2, string const & s3,
263 if (!lyxrc.use_gui) {
264 lyxerr << "----------------------------------------" << endl
267 lyxerr << s2 << endl;
269 lyxerr << s3 << endl;
270 lyxerr << "Assuming answer is "
271 << (default_value ? "yes" : "no")
273 << "----------------------------------------" << endl;
274 return default_value;
277 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
278 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
279 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
283 // Returns 1 for yes, 2 for no, 3 for cancel.
284 int AskConfirmation(string const & s1, string const & s2, string const & s3,
287 if (!lyxrc.use_gui) {
288 lyxerr << "----------------------------------------" << endl
291 lyxerr << s2 << endl;
293 lyxerr << s3 << endl;
294 lyxerr << "Assuming answer is ";
295 if (default_value == 1)
297 else if (default_value == 2)
302 << "----------------------------------------" << endl;
303 return default_value;
306 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
308 scex(_("Cancel|^[")));
309 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
310 3, idex(_("Yes|Yy#y")),
312 idex(_("Cancel|^[")), 3);
317 pair<bool, string> const
318 askForText(string const & msg, string const & dflt)
320 if (!lyxrc.use_gui) {
321 lyxerr << "----------------------------------------" << endl
323 << "Assuming answer is " << dflt
324 << "----------------------------------------" << endl;
325 return make_pair<bool, string>(true, dflt);
328 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
329 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
330 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
331 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
333 return make_pair<bool, string>(true, string(tmp));
335 return make_pair<bool, string>(false, string());
339 // Inform the user that the buffer is read-only, and that changes in the
340 // dialog box that is to appear will be ignored.
341 void WarnReadonly(string const & file)
343 WriteAlert(_("Any changes will be ignored"),
344 _("The document is read-only:"),
345 MakeDisplayPath(file));
348 /// Get the dpi setting of the current screen
351 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
352 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
353 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;