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();
43 // Prevents LyX from being killed when the close box is pressed in a popup.
44 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
48 // Redraw the form (on receipt of a Signal indicating, for example,
49 // that the xform colors have been re-mapped).
50 void RedrawAllBufferRelatedDialogs()
52 if (fd_form_figure->form_figure->visible) {
53 fl_redraw_form(fd_form_figure->form_figure);
55 if (fd_form_sendto->form_sendto->visible) {
56 fl_redraw_form(fd_form_sendto->form_sendto);
60 // Prevents LyX from crashing when no buffers available
61 // This is also one of the functions that we _really_ dont want
62 // we should try to finds way to help us with that.
63 // The signal/slot mechanism can probably help.
64 void CloseAllBufferRelatedDialogs()
66 // don't forget to check that dynamically created forms
67 // have been created otherwise hiding one could cause a crash
68 // need the visible check otherwise XForms prints a warning
69 // if hiding an invisible form
70 if (fd_form_figure->form_figure->visible) {
71 fl_hide_form(fd_form_figure->form_figure);
73 if (fd_form_sendto->form_sendto->visible) {
74 fl_hide_form(fd_form_sendto->form_sendto);
79 // This is another function we really don't want.
80 // Again the Signal/Slot mechanism is tailor made for this task.
81 void updateAllVisibleBufferRelatedDialogs(bool)
86 // Extract shortcut from <ident>|<shortcut> string
87 char const * flyx_shortcut_extract(char const * sc)
89 // Find '|' in the sc and return the string after that.
90 register char const * sd = sc;
91 while(sd[0]!= 0 && sd[0] != '|') ++sd;
95 //lyxerr << sd << endl;
102 // Extract identifier from <ident>|<shortcut> string
103 char const * flyx_ident_extract(char const * sc)
105 register char const * se = sc;
106 while(se[0]!= 0 && se[0] != '|') ++se;
108 if (se[0] == 0) return sc;
110 char * sb = new char[se - sc + 1];
112 register char const * sd = sc;
123 void WriteAlert(string const & s1, string const & s2, string const & s3)
126 if (current_view && current_view->owner())
127 lview = current_view->owner();
129 /// Write to minibuffer
130 lview->prohibitInput();
131 string const msg = s1 + ' ' + s2 + ' ' + s3;
133 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
134 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
138 lyxerr << "----------------------------------------" << endl
139 << s1 << endl << s2 << endl << s3 << endl
140 << "----------------------------------------" << endl;
145 // Alarms user of something related to files
146 void WriteFSAlert(string const & s1, string const & s2)
148 WriteAlert(s1, s2, strerror(errno));
152 bool AskQuestion(string const & s1, string const & s2, string const & s3,
155 if (!lyxrc.use_gui) {
156 lyxerr << "----------------------------------------" << endl
159 lyxerr << s2 << endl;
161 lyxerr << s3 << endl;
162 lyxerr << "Assuming answer is "
163 << (default_value ? "yes" : "no")
165 << "----------------------------------------" << endl;
166 return default_value;
169 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
170 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
171 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
175 // Returns 1 for yes, 2 for no, 3 for cancel.
176 int AskConfirmation(string const & s1, string const & s2, string const & s3,
179 if (!lyxrc.use_gui) {
180 lyxerr << "----------------------------------------" << endl
183 lyxerr << s2 << endl;
185 lyxerr << s3 << endl;
186 lyxerr << "Assuming answer is ";
187 if (default_value == 1)
189 else if (default_value == 2)
194 << "----------------------------------------" << endl;
195 return default_value;
198 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
200 scex(_("Cancel|^[")));
201 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
202 3, idex(_("Yes|Yy#y")),
204 idex(_("Cancel|^[")), 3);
209 pair<bool, string> const
210 askForText(string const & msg, string const & dflt)
212 if (!lyxrc.use_gui) {
213 lyxerr << "----------------------------------------" << endl
215 << "Assuming answer is " << dflt
216 << "----------------------------------------" << endl;
217 return make_pair<bool, string>(true, dflt);
220 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
221 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
222 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
223 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
225 return make_pair<bool, string>(true, string(tmp));
227 return make_pair<bool, string>(false, string());
231 // Inform the user that the buffer is read-only, and that changes in the
232 // dialog box that is to appear will be ignored.
233 void WarnReadonly(string const & file)
235 WriteAlert(_("Any changes will be ignored"),
236 _("The document is read-only:"),
237 MakeDisplayPath(file));
240 /// Get the dpi setting of the current screen
243 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
244 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
245 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;