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"
36 extern BufferView * current_view;
38 extern FD_form_figure * fd_form_figure;
39 extern FD_form_sendto * fd_form_sendto;
41 extern void HideFiguresPopups();
44 // Prevents LyX from being killed when the close box is pressed in a popup.
46 int CancelCloseBoxCB(FL_FORM *, void *)
52 // Redraw the form (on receipt of a Signal indicating, for example,
53 // that the xform colors have been re-mapped).
54 void RedrawAllBufferRelatedDialogs()
56 if (fd_form_figure->form_figure->visible) {
57 fl_redraw_form(fd_form_figure->form_figure);
59 if (fd_form_sendto->form_sendto->visible) {
60 fl_redraw_form(fd_form_sendto->form_sendto);
64 // Prevents LyX from crashing when no buffers available
65 // This is also one of the functions that we _really_ dont want
66 // we should try to finds way to help us with that.
67 // The signal/slot mechanism can probably help.
68 void CloseAllBufferRelatedDialogs()
70 // don't forget to check that dynamically created forms
71 // have been created otherwise hiding one could cause a crash
72 // need the visible check otherwise XForms prints a warning
73 // if hiding an invisible form
74 if (fd_form_figure->form_figure->visible) {
75 fl_hide_form(fd_form_figure->form_figure);
77 if (fd_form_sendto->form_sendto->visible) {
78 fl_hide_form(fd_form_sendto->form_sendto);
83 // This is another function we really don't want.
84 // Again the Signal/Slot mechanism is tailor made for this task.
85 void updateAllVisibleBufferRelatedDialogs(bool)
90 // Extract shortcut from <ident>|<shortcut> string
91 char const * flyx_shortcut_extract(char const * sc)
93 // Find '|' in the sc and return the string after that.
94 register char const * sd = sc;
95 while(sd[0]!= 0 && sd[0] != '|') ++sd;
99 //lyxerr << sd << endl;
106 // Extract identifier from <ident>|<shortcut> string
107 char const * flyx_ident_extract(char const * sc)
109 register char const * se = sc;
110 while(se[0]!= 0 && se[0] != '|') ++se;
112 if (se[0] == 0) return sc;
114 char * sb = new char[se - sc + 1];
116 register char const * sd = sc;
127 void WriteAlert(string const & s1, string const & s2, string const & s3)
130 if (current_view && current_view->owner())
131 lview = current_view->owner();
133 /// Write to minibuffer
134 lview->prohibitInput();
135 string const msg = s1 + ' ' + s2 + ' ' + s3;
137 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
138 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
142 lyxerr << "----------------------------------------" << endl
143 << s1 << endl << s2 << endl << s3 << endl
144 << "----------------------------------------" << endl;
149 // Alarms user of something related to files
150 void WriteFSAlert(string const & s1, string const & s2)
152 WriteAlert(s1, s2, strerror(errno));
156 bool AskQuestion(string const & s1, string const & s2, string const & s3,
159 if (!lyxrc.use_gui) {
160 lyxerr << "----------------------------------------" << endl
163 lyxerr << s2 << endl;
165 lyxerr << s3 << endl;
166 lyxerr << "Assuming answer is "
167 << (default_value ? "yes" : "no")
169 << "----------------------------------------" << endl;
170 return default_value;
173 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
174 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
175 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
179 // Returns 1 for yes, 2 for no, 3 for cancel.
180 int AskConfirmation(string const & s1, string const & s2, string const & s3,
183 if (!lyxrc.use_gui) {
184 lyxerr << "----------------------------------------" << endl
187 lyxerr << s2 << endl;
189 lyxerr << s3 << endl;
190 lyxerr << "Assuming answer is ";
191 if (default_value == 1)
193 else if (default_value == 2)
198 << "----------------------------------------" << endl;
199 return default_value;
202 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
204 scex(_("Cancel|^[")));
205 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
206 3, idex(_("Yes|Yy#y")),
208 idex(_("Cancel|^[")), 3);
213 pair<bool, string> const
214 askForText(string const & msg, string const & dflt)
216 if (!lyxrc.use_gui) {
217 lyxerr << "----------------------------------------" << endl
219 << "Assuming answer is " << dflt
220 << "----------------------------------------" << endl;
221 return make_pair<bool, string>(true, dflt);
224 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
225 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
226 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
227 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
229 return make_pair<bool, string>(true, string(tmp));
231 return make_pair<bool, string>(false, string());
235 // Inform the user that the buffer is read-only, and that changes in the
236 // dialog box that is to appear will be ignored.
237 void WarnReadonly(string const & file)
239 WriteAlert(_("Any changes will be ignored"),
240 _("The document is read-only:"),
241 MakeDisplayPath(file));
244 /// Get the dpi setting of the current screen
247 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
248 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
249 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;