2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
15 #pragma implementation
19 #include "lyx_gui_misc.h"
20 #include "BufferView.h"
23 #include "figure_form.h"
26 #include "print_form.h"
29 #include "bufferview_funcs.h"
30 #include "support/filetools.h"
37 extern BufferView * current_view;
39 extern FD_form_figure * fd_form_figure;
40 extern FD_form_sendto * fd_form_sendto;
41 extern FD_form_spell_check * fd_form_spell_check;
42 extern FD_form_spell_options * fd_form_spell_options;
44 extern void HideFiguresPopups();
46 // Prevents LyX from being killed when the close box is pressed in a popup.
47 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
51 // Redraw the form (on receipt of a Signal indicating, for example,
52 // that the xform colors have been re-mapped).
53 void RedrawAllBufferRelatedDialogs()
55 if (fd_form_figure->form_figure->visible) {
56 fl_redraw_form(fd_form_figure->form_figure);
58 if (fd_form_sendto->form_sendto->visible) {
59 fl_redraw_form(fd_form_sendto->form_sendto);
61 if (fd_form_spell_check &&
62 fd_form_spell_check->form_spell_check->visible) {
63 fl_redraw_form(fd_form_spell_check->form_spell_check);
65 if (fd_form_spell_options &&
66 fd_form_spell_options->form_spell_options->visible) {
67 fl_redraw_form(fd_form_spell_options->form_spell_options);
71 // Prevents LyX from crashing when no buffers available
72 // This is also one of the functions that we _really_ dont want
73 // we should try to finds way to help us with that.
74 // The signal/slot mechanism can probably help.
75 void CloseAllBufferRelatedDialogs()
77 // don't forget to check that dynamically created forms
78 // have been created otherwise hiding one could cause a crash
79 // need the visible check otherwise XForms prints a warning
80 // if hiding an invisible form
81 if (fd_form_figure->form_figure->visible) {
82 fl_hide_form(fd_form_figure->form_figure);
84 if (fd_form_sendto->form_sendto->visible) {
85 fl_hide_form(fd_form_sendto->form_sendto);
87 if (fd_form_spell_check) {
88 if (fd_form_spell_check->form_spell_check->visible) {
89 fl_trigger_object(fd_form_spell_check->done);
95 // This is another function we really don't want.
96 // Again the Signal/Slot mechanism is tailor made for this task.
97 void updateAllVisibleBufferRelatedDialogs(bool)
102 // Extract shortcut from <ident>|<shortcut> string
103 char const * flyx_shortcut_extract(char const * sc)
105 // Find '|' in the sc and return the string after that.
106 register char const * sd = sc;
107 while(sd[0]!= 0 && sd[0] != '|') ++sd;
111 //lyxerr << sd << endl;
118 // Extract identifier from <ident>|<shortcut> string
119 char const * flyx_ident_extract(char const * sc)
121 register char const * se = sc;
122 while(se[0]!= 0 && se[0] != '|') ++se;
124 if (se[0] == 0) return sc;
126 char * sb = new char[se - sc + 1];
128 register char const * sd = sc;
139 void WriteAlert(string const & s1, string const & s2, string const & s3)
142 if (current_view && current_view->owner())
143 lview = current_view->owner();
145 /// Write to minibuffer
146 ProhibitInput(current_view);
147 string const msg = s1 + ' ' + s2 + ' ' + s3;
149 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
150 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
151 AllowInput(current_view);
154 lyxerr << "----------------------------------------" << endl
155 << s1 << endl << s2 << endl << s3 << endl
156 << "----------------------------------------" << endl;
161 // Alarms user of something related to files
162 void WriteFSAlert(string const & s1, string const & s2)
164 WriteAlert(s1, s2, strerror(errno));
168 bool AskQuestion(string const & s1, string const & s2, string const & s3,
171 if (!lyxrc.use_gui) {
172 lyxerr << "----------------------------------------" << endl
175 lyxerr << s2 << endl;
177 lyxerr << s3 << endl;
178 lyxerr << "Assuming answer is "
179 << (default_value ? "yes" : "no")
181 << "----------------------------------------" << endl;
182 return default_value;
185 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
186 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
187 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
191 // Returns 1 for yes, 2 for no, 3 for cancel.
192 int AskConfirmation(string const & s1, string const & s2, string const & s3,
195 if (!lyxrc.use_gui) {
196 lyxerr << "----------------------------------------" << endl
199 lyxerr << s2 << endl;
201 lyxerr << s3 << endl;
202 lyxerr << "Assuming answer is ";
203 if (default_value == 1)
205 else if (default_value == 2)
210 << "----------------------------------------" << endl;
211 return default_value;
214 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
216 scex(_("Cancel|^[")));
217 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
218 3, idex(_("Yes|Yy#y")),
220 idex(_("Cancel|^[")), 3);
225 pair<bool, string> const
226 askForText(string const & msg, string const & dflt)
228 if (!lyxrc.use_gui) {
229 lyxerr << "----------------------------------------" << endl
231 << "Assuming answer is " << dflt
232 << "----------------------------------------" << endl;
233 return make_pair<bool, string>(true, dflt);
236 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
237 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
238 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
239 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
241 return make_pair<bool, string>(true, string(tmp));
243 return make_pair<bool, string>(false, string());
247 // Inform the user that the buffer is read-only, and that changes in the
248 // dialog box that is to appear will be ignored.
249 void WarnReadonly(string const & file)
251 WriteAlert(_("Any changes will be ignored"),
252 _("The document is read-only:"),
253 MakeDisplayPath(file));
256 /// Get the dpi setting of the current screen
259 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
260 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
261 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;