1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
18 #include "lyx_gui_misc.h"
19 #include "BufferView.h"
22 #include "figure_form.h"
25 #include "print_form.h"
28 #include "bufferview_funcs.h"
29 #include "support/filetools.h"
36 extern BufferView * current_view;
38 extern FD_form_figure * fd_form_figure;
39 extern FD_form_sendto * fd_form_sendto;
40 extern FD_form_spell_check * fd_form_spell_check;
41 extern FD_form_spell_options * fd_form_spell_options;
43 extern void HideFiguresPopups();
45 // Prevents LyX from being killed when the close box is pressed in a popup.
46 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
50 // Redraw the form (on receipt of a Signal indicating, for example,
51 // that the xform colors have been re-mapped).
52 void RedrawAllBufferRelatedDialogs()
54 if (fd_form_figure->form_figure->visible) {
55 fl_redraw_form(fd_form_figure->form_figure);
57 if (fd_form_sendto->form_sendto->visible) {
58 fl_redraw_form(fd_form_sendto->form_sendto);
60 if (fd_form_spell_check &&
61 fd_form_spell_check->form_spell_check->visible) {
62 fl_redraw_form(fd_form_spell_check->form_spell_check);
64 if (fd_form_spell_options &&
65 fd_form_spell_options->form_spell_options->visible) {
66 fl_redraw_form(fd_form_spell_options->form_spell_options);
70 // Prevents LyX from crashing when no buffers available
71 // This is also one of the functions that we _really_ dont want
72 // we should try to finds way to help us with that.
73 // The signal/slot mechanism can probably help.
74 void CloseAllBufferRelatedDialogs()
76 // don't forget to check that dynamically created forms
77 // have been created otherwise hiding one could cause a crash
78 // need the visible check otherwise XForms prints a warning
79 // if hiding an invisible form
80 if (fd_form_figure->form_figure->visible) {
81 fl_hide_form(fd_form_figure->form_figure);
83 if (fd_form_sendto->form_sendto->visible) {
84 fl_hide_form(fd_form_sendto->form_sendto);
86 if (fd_form_spell_check) {
87 if (fd_form_spell_check->form_spell_check->visible) {
88 fl_trigger_object(fd_form_spell_check->done);
94 // This is another function we really don't want.
95 // Again the Signal/Slot mechanism is tailor made for this task.
96 void updateAllVisibleBufferRelatedDialogs(bool)
101 // Extract shortcut from <ident>|<shortcut> string
102 char const * flyx_shortcut_extract(char const * sc)
104 // Find '|' in the sc and return the string after that.
105 register char const * sd = sc;
106 while(sd[0]!= 0 && sd[0] != '|') ++sd;
110 //lyxerr << sd << endl;
117 // Extract identifier from <ident>|<shortcut> string
118 char const * flyx_ident_extract(char const * sc)
120 register char const * se = sc;
121 while(se[0]!= 0 && se[0] != '|') ++se;
123 if (se[0] == 0) return sc;
125 char * sb = new char[se - sc + 1];
127 register char const * sd = sc;
138 void WriteAlert(string const & s1, string const & s2, string const & s3)
141 if (current_view && current_view->owner())
142 lview = current_view->owner();
144 /// Write to minibuffer
145 ProhibitInput(current_view);
146 string const msg = s1 + ' ' + s2 + ' ' + s3;
148 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
149 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
150 AllowInput(current_view);
153 lyxerr << "----------------------------------------" << endl
154 << s1 << endl << s2 << endl << s3 << endl
155 << "----------------------------------------" << endl;
160 // Alarms user of something related to files
161 void WriteFSAlert(string const & s1, string const & s2)
163 WriteAlert(s1, s2, strerror(errno));
167 bool AskQuestion(string const & s1, string const & s2, string const & s3,
170 if (!lyxrc.use_gui) {
171 lyxerr << "----------------------------------------" << endl
174 lyxerr << s2 << endl;
176 lyxerr << s3 << endl;
177 lyxerr << "Assuming answer is "
178 << (default_value ? "yes" : "no")
180 << "----------------------------------------" << endl;
181 return default_value;
184 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
185 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
186 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
190 // Returns 1 for yes, 2 for no, 3 for cancel.
191 int AskConfirmation(string const & s1, string const & s2, string const & s3,
194 if (!lyxrc.use_gui) {
195 lyxerr << "----------------------------------------" << endl
198 lyxerr << s2 << endl;
200 lyxerr << s3 << endl;
201 lyxerr << "Assuming answer is ";
202 if (default_value == 1)
204 else if (default_value == 2)
209 << "----------------------------------------" << endl;
210 return default_value;
213 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
215 scex(_("Cancel|^[")));
216 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
217 3, idex(_("Yes|Yy#y")),
219 idex(_("Cancel|^[")), 3);
224 pair<bool, string> const
225 askForText(string const & msg, string const & dflt)
227 if (!lyxrc.use_gui) {
228 lyxerr << "----------------------------------------" << endl
230 << "Assuming answer is " << dflt
231 << "----------------------------------------" << endl;
232 return make_pair<bool, string>(true, dflt);
235 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
236 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
237 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
238 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
240 return make_pair<bool, string>(true, string(tmp));
242 return make_pair<bool, string>(false, string());
246 // Inform the user that the buffer is read-only, and that changes in the
247 // dialog box that is to appear will be ignored.
248 void WarnReadonly(string const & file)
250 WriteAlert(_("Any changes will be ignored"),
251 _("The document is read-only:"),
252 MakeDisplayPath(file));
255 /// Get the dpi setting of the current screen
258 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
259 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
260 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;