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"
27 #include "bufferview_funcs.h"
28 #include "support/filetools.h"
35 extern BufferView * current_view;
37 extern FD_form_figure * fd_form_figure;
38 extern FD_form_sendto * fd_form_sendto;
40 extern void HideFiguresPopups();
42 // Prevents LyX from being killed when the close box is pressed in a popup.
43 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
47 // Redraw the form (on receipt of a Signal indicating, for example,
48 // that the xform colors have been re-mapped).
49 void RedrawAllBufferRelatedDialogs()
51 if (fd_form_figure->form_figure->visible) {
52 fl_redraw_form(fd_form_figure->form_figure);
54 if (fd_form_sendto->form_sendto->visible) {
55 fl_redraw_form(fd_form_sendto->form_sendto);
59 // Prevents LyX from crashing when no buffers available
60 // This is also one of the functions that we _really_ dont want
61 // we should try to finds way to help us with that.
62 // The signal/slot mechanism can probably help.
63 void CloseAllBufferRelatedDialogs()
65 // don't forget to check that dynamically created forms
66 // have been created otherwise hiding one could cause a crash
67 // need the visible check otherwise XForms prints a warning
68 // if hiding an invisible form
69 if (fd_form_figure->form_figure->visible) {
70 fl_hide_form(fd_form_figure->form_figure);
72 if (fd_form_sendto->form_sendto->visible) {
73 fl_hide_form(fd_form_sendto->form_sendto);
78 // This is another function we really don't want.
79 // Again the Signal/Slot mechanism is tailor made for this task.
80 void updateAllVisibleBufferRelatedDialogs(bool)
85 // Extract shortcut from <ident>|<shortcut> string
86 char const * flyx_shortcut_extract(char const * sc)
88 // Find '|' in the sc and return the string after that.
89 register char const * sd = sc;
90 while(sd[0]!= 0 && sd[0] != '|') ++sd;
94 //lyxerr << sd << endl;
101 // Extract identifier from <ident>|<shortcut> string
102 char const * flyx_ident_extract(char const * sc)
104 register char const * se = sc;
105 while(se[0]!= 0 && se[0] != '|') ++se;
107 if (se[0] == 0) return sc;
109 char * sb = new char[se - sc + 1];
111 register char const * sd = sc;
122 void WriteAlert(string const & s1, string const & s2, string const & s3)
125 if (current_view && current_view->owner())
126 lview = current_view->owner();
128 /// Write to minibuffer
129 lview->prohibitInput();
130 string const msg = s1 + ' ' + s2 + ' ' + s3;
132 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
133 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
137 lyxerr << "----------------------------------------" << endl
138 << s1 << endl << s2 << endl << s3 << endl
139 << "----------------------------------------" << endl;
144 // Alarms user of something related to files
145 void WriteFSAlert(string const & s1, string const & s2)
147 WriteAlert(s1, s2, strerror(errno));
151 bool AskQuestion(string const & s1, string const & s2, string const & s3,
154 if (!lyxrc.use_gui) {
155 lyxerr << "----------------------------------------" << endl
158 lyxerr << s2 << endl;
160 lyxerr << s3 << endl;
161 lyxerr << "Assuming answer is "
162 << (default_value ? "yes" : "no")
164 << "----------------------------------------" << endl;
165 return default_value;
168 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
169 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
170 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
174 // Returns 1 for yes, 2 for no, 3 for cancel.
175 int AskConfirmation(string const & s1, string const & s2, string const & s3,
178 if (!lyxrc.use_gui) {
179 lyxerr << "----------------------------------------" << endl
182 lyxerr << s2 << endl;
184 lyxerr << s3 << endl;
185 lyxerr << "Assuming answer is ";
186 if (default_value == 1)
188 else if (default_value == 2)
193 << "----------------------------------------" << endl;
194 return default_value;
197 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
199 scex(_("Cancel|^[")));
200 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
201 3, idex(_("Yes|Yy#y")),
203 idex(_("Cancel|^[")), 3);
208 pair<bool, string> const
209 askForText(string const & msg, string const & dflt)
211 if (!lyxrc.use_gui) {
212 lyxerr << "----------------------------------------" << endl
214 << "Assuming answer is " << dflt
215 << "----------------------------------------" << endl;
216 return make_pair<bool, string>(true, dflt);
219 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
220 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
221 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
222 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
224 return make_pair<bool, string>(true, string(tmp));
226 return make_pair<bool, string>(false, string());
230 // Inform the user that the buffer is read-only, and that changes in the
231 // dialog box that is to appear will be ignored.
232 void WarnReadonly(string const & file)
234 WriteAlert(_("Any changes will be ignored"),
235 _("The document is read-only:"),
236 MakeDisplayPath(file));
239 /// Get the dpi setting of the current screen
242 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
243 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
244 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;