2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
15 #pragma implementation
19 #include "lyx_gui_misc.h"
20 #include "BufferView.h"
27 #include "minibuffer.h"
28 #include "print_form.h"
31 #include "bufferview_funcs.h"
32 #include "support/filetools.h"
39 extern BufferView * current_view;
41 extern FD_form_figure * fd_form_figure;
42 extern FD_form_sendto * fd_form_sendto;
43 extern FD_form_spell_check * fd_form_spell_check;
44 extern FD_form_spell_options * fd_form_spell_options;
46 extern void HideFiguresPopups();
48 // Prevents LyX from being killed when the close box is pressed in a popup.
49 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
53 // Redraw the form (on receipt of a Signal indicating, for example,
54 // that the xform colors have been re-mapped).
55 void RedrawAllBufferRelatedDialogs()
57 if (fd_form_figure->form_figure->visible) {
58 fl_redraw_form(fd_form_figure->form_figure);
60 if (fd_form_sendto->form_sendto->visible) {
61 fl_redraw_form(fd_form_sendto->form_sendto);
63 if (fd_form_spell_check &&
64 fd_form_spell_check->form_spell_check->visible) {
65 fl_redraw_form(fd_form_spell_check->form_spell_check);
67 if (fd_form_spell_options &&
68 fd_form_spell_options->form_spell_options->visible) {
69 fl_redraw_form(fd_form_spell_options->form_spell_options);
73 // Prevents LyX from crashing when no buffers available
74 // This is also one of the functions that we _really_ dont want
75 // we should try to finds way to help us with that.
76 // The signal/slot mechanism can probably help.
77 void CloseAllBufferRelatedDialogs()
79 // don't forget to check that dynamically created forms
80 // have been created otherwise hiding one could cause a crash
81 // need the visible check otherwise XForms prints a warning
82 // if hiding an invisible form
83 if (fd_form_figure->form_figure->visible) {
84 fl_hide_form(fd_form_figure->form_figure);
86 if (fd_form_sendto->form_sendto->visible) {
87 fl_hide_form(fd_form_sendto->form_sendto);
89 if (fd_form_spell_check) {
90 if (fd_form_spell_check->form_spell_check->visible) {
91 fl_trigger_object(fd_form_spell_check->done);
97 // This is another function we really don't want.
98 // Again the Signal/Slot mechanism is tailor made for this task.
99 void updateAllVisibleBufferRelatedDialogs(bool)
104 // Extract shortcut from <ident>|<shortcut> string
105 char const * flyx_shortcut_extract(char const * sc)
107 // Find '|' in the sc and return the string after that.
108 register char const * sd = sc;
109 while(sd[0]!= 0 && sd[0] != '|') ++sd;
113 //lyxerr << sd << endl;
120 // Extract identifier from <ident>|<shortcut> string
121 char const * flyx_ident_extract(char const * sc)
123 register char const * se = sc;
124 while(se[0]!= 0 && se[0] != '|') ++se;
126 if (se[0] == 0) return sc;
128 char * sb = new char[se - sc + 1];
130 register char const * sd = sc;
140 void WriteStatus(MiniBuffer * minib, string const & s)
151 void WriteAlert(string const & s1, string const & s2, string const & s3)
153 MiniBuffer * minibuffer = 0;
154 if (current_view && current_view->owner())
155 minibuffer = current_view->owner()->getMiniBuffer();
157 /// Write to minibuffer
158 ProhibitInput(current_view);
159 minibuffer->Set(s1, s2, s3);
160 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
161 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
162 AllowInput(current_view);
165 lyxerr << "----------------------------------------" << endl
166 << s1 << endl << s2 << endl << s3 << endl
167 << "----------------------------------------" << endl;
172 // Alarms user of something related to files
173 void WriteFSAlert(string const & s1, string const & s2)
175 WriteAlert(s1, s2, strerror(errno));
179 bool AskQuestion(string const & s1, string const & s2, string const & s3,
182 if (!lyxrc.use_gui) {
183 lyxerr << "----------------------------------------" << endl
186 lyxerr << s2 << endl;
188 lyxerr << s3 << endl;
189 lyxerr << "Assuming answer is "
190 << (default_value ? "yes" : "no")
192 << "----------------------------------------" << endl;
193 return default_value;
196 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
197 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
198 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
202 // Returns 1 for yes, 2 for no, 3 for cancel.
203 int AskConfirmation(string const & s1, string const & s2, string const & s3,
206 if (!lyxrc.use_gui) {
207 lyxerr << "----------------------------------------" << endl
210 lyxerr << s2 << endl;
212 lyxerr << s3 << endl;
213 lyxerr << "Assuming answer is ";
214 if (default_value == 1)
216 else if (default_value == 2)
221 << "----------------------------------------" << endl;
222 return default_value;
225 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
227 scex(_("Cancel|^[")));
228 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
229 3, idex(_("Yes|Yy#y")),
231 idex(_("Cancel|^[")), 3);
236 pair<bool, string> const
237 askForText(string const & msg, string const & dflt)
239 if (!lyxrc.use_gui) {
240 lyxerr << "----------------------------------------" << endl
242 << "Assuming answer is " << dflt
243 << "----------------------------------------" << endl;
244 return make_pair<bool, string>(true, dflt);
247 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
248 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
249 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
250 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
252 return make_pair<bool, string>(true, string(tmp));
254 return make_pair<bool, string>(false, string());
258 // Inform the user that the buffer is read-only, and that changes in the
259 // dialog box that is to appear will be ignored.
260 void WarnReadonly(string const & file)
262 WriteAlert(_("Any changes will be ignored"),
263 _("The document is read-only:"),
264 MakeDisplayPath(file));
267 /// Get the dpi setting of the current screen
270 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
271 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
272 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;