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;
42 extern void HideFiguresPopups();
44 // Prevents LyX from being killed when the close box is pressed in a popup.
45 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
49 // Redraw the form (on receipt of a Signal indicating, for example,
50 // that the xform colors have been re-mapped).
51 void RedrawAllBufferRelatedDialogs()
53 if (fd_form_figure->form_figure->visible) {
54 fl_redraw_form(fd_form_figure->form_figure);
56 if (fd_form_sendto->form_sendto->visible) {
57 fl_redraw_form(fd_form_sendto->form_sendto);
59 if (fd_form_spell_check &&
60 fd_form_spell_check->form_spell_check->visible) {
61 fl_redraw_form(fd_form_spell_check->form_spell_check);
65 // Prevents LyX from crashing when no buffers available
66 // This is also one of the functions that we _really_ dont want
67 // we should try to finds way to help us with that.
68 // The signal/slot mechanism can probably help.
69 void CloseAllBufferRelatedDialogs()
71 // don't forget to check that dynamically created forms
72 // have been created otherwise hiding one could cause a crash
73 // need the visible check otherwise XForms prints a warning
74 // if hiding an invisible form
75 if (fd_form_figure->form_figure->visible) {
76 fl_hide_form(fd_form_figure->form_figure);
78 if (fd_form_sendto->form_sendto->visible) {
79 fl_hide_form(fd_form_sendto->form_sendto);
81 if (fd_form_spell_check) {
82 if (fd_form_spell_check->form_spell_check->visible) {
83 fl_trigger_object(fd_form_spell_check->done);
89 // This is another function we really don't want.
90 // Again the Signal/Slot mechanism is tailor made for this task.
91 void updateAllVisibleBufferRelatedDialogs(bool)
96 // Extract shortcut from <ident>|<shortcut> string
97 char const * flyx_shortcut_extract(char const * sc)
99 // Find '|' in the sc and return the string after that.
100 register char const * sd = sc;
101 while(sd[0]!= 0 && sd[0] != '|') ++sd;
105 //lyxerr << sd << endl;
112 // Extract identifier from <ident>|<shortcut> string
113 char const * flyx_ident_extract(char const * sc)
115 register char const * se = sc;
116 while(se[0]!= 0 && se[0] != '|') ++se;
118 if (se[0] == 0) return sc;
120 char * sb = new char[se - sc + 1];
122 register char const * sd = sc;
133 void WriteAlert(string const & s1, string const & s2, string const & s3)
136 if (current_view && current_view->owner())
137 lview = current_view->owner();
139 /// Write to minibuffer
140 lview->prohibitInput();
141 string const msg = s1 + ' ' + s2 + ' ' + s3;
143 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
144 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
148 lyxerr << "----------------------------------------" << endl
149 << s1 << endl << s2 << endl << s3 << endl
150 << "----------------------------------------" << endl;
155 // Alarms user of something related to files
156 void WriteFSAlert(string const & s1, string const & s2)
158 WriteAlert(s1, s2, strerror(errno));
162 bool AskQuestion(string const & s1, string const & s2, string const & s3,
165 if (!lyxrc.use_gui) {
166 lyxerr << "----------------------------------------" << endl
169 lyxerr << s2 << endl;
171 lyxerr << s3 << endl;
172 lyxerr << "Assuming answer is "
173 << (default_value ? "yes" : "no")
175 << "----------------------------------------" << endl;
176 return default_value;
179 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
180 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
181 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
185 // Returns 1 for yes, 2 for no, 3 for cancel.
186 int AskConfirmation(string const & s1, string const & s2, string const & s3,
189 if (!lyxrc.use_gui) {
190 lyxerr << "----------------------------------------" << endl
193 lyxerr << s2 << endl;
195 lyxerr << s3 << endl;
196 lyxerr << "Assuming answer is ";
197 if (default_value == 1)
199 else if (default_value == 2)
204 << "----------------------------------------" << endl;
205 return default_value;
208 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
210 scex(_("Cancel|^[")));
211 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
212 3, idex(_("Yes|Yy#y")),
214 idex(_("Cancel|^[")), 3);
219 pair<bool, string> const
220 askForText(string const & msg, string const & dflt)
222 if (!lyxrc.use_gui) {
223 lyxerr << "----------------------------------------" << endl
225 << "Assuming answer is " << dflt
226 << "----------------------------------------" << endl;
227 return make_pair<bool, string>(true, dflt);
230 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
231 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
232 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
233 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
235 return make_pair<bool, string>(true, string(tmp));
237 return make_pair<bool, string>(false, string());
241 // Inform the user that the buffer is read-only, and that changes in the
242 // dialog box that is to appear will be ignored.
243 void WarnReadonly(string const & file)
245 WriteAlert(_("Any changes will be ignored"),
246 _("The document is read-only:"),
247 MakeDisplayPath(file));
250 /// Get the dpi setting of the current screen
253 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
254 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
255 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;