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"
23 #include "figure_form.h"
26 #include "minibuffer.h"
27 #include "print_form.h"
30 #include "bufferview_funcs.h"
31 #include "support/filetools.h"
38 extern BufferView * current_view;
40 extern FD_form_figure * fd_form_figure;
41 extern FD_form_sendto * fd_form_sendto;
42 extern FD_form_spell_check * fd_form_spell_check;
43 extern FD_form_spell_options * fd_form_spell_options;
45 extern void HideFiguresPopups();
47 // Prevents LyX from being killed when the close box is pressed in a popup.
48 extern "C" 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);
62 if (fd_form_spell_check &&
63 fd_form_spell_check->form_spell_check->visible) {
64 fl_redraw_form(fd_form_spell_check->form_spell_check);
66 if (fd_form_spell_options &&
67 fd_form_spell_options->form_spell_options->visible) {
68 fl_redraw_form(fd_form_spell_options->form_spell_options);
72 // Prevents LyX from crashing when no buffers available
73 // This is also one of the functions that we _really_ dont want
74 // we should try to finds way to help us with that.
75 // The signal/slot mechanism can probably help.
76 void CloseAllBufferRelatedDialogs()
78 // don't forget to check that dynamically created forms
79 // have been created otherwise hiding one could cause a crash
80 // need the visible check otherwise XForms prints a warning
81 // if hiding an invisible form
82 if (fd_form_figure->form_figure->visible) {
83 fl_hide_form(fd_form_figure->form_figure);
85 if (fd_form_sendto->form_sendto->visible) {
86 fl_hide_form(fd_form_sendto->form_sendto);
88 if (fd_form_spell_check) {
89 if (fd_form_spell_check->form_spell_check->visible) {
90 fl_trigger_object(fd_form_spell_check->done);
96 // This is another function we really don't want.
97 // Again the Signal/Slot mechanism is tailor made for this task.
98 void updateAllVisibleBufferRelatedDialogs(bool)
103 // Extract shortcut from <ident>|<shortcut> string
104 char const * flyx_shortcut_extract(char const * sc)
106 // Find '|' in the sc and return the string after that.
107 register char const * sd = sc;
108 while(sd[0]!= 0 && sd[0] != '|') ++sd;
112 //lyxerr << sd << endl;
119 // Extract identifier from <ident>|<shortcut> string
120 char const * flyx_ident_extract(char const * sc)
122 register char const * se = sc;
123 while(se[0]!= 0 && se[0] != '|') ++se;
125 if (se[0] == 0) return sc;
127 char * sb = new char[se - sc + 1];
129 register char const * sd = sc;
139 void WriteStatus(MiniBuffer * minib, string const & s)
150 void WriteAlert(string const & s1, string const & s2, string const & s3)
152 MiniBuffer * minibuffer = 0;
153 if (current_view && current_view->owner())
154 minibuffer = current_view->owner()->getMiniBuffer();
156 /// Write to minibuffer
157 ProhibitInput(current_view);
158 minibuffer->Set(s1, s2, s3);
159 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
160 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
161 AllowInput(current_view);
164 lyxerr << "----------------------------------------" << endl
165 << s1 << endl << s2 << endl << s3 << endl
166 << "----------------------------------------" << endl;
171 // Alarms user of something related to files
172 void WriteFSAlert(string const & s1, string const & s2)
174 WriteAlert(s1, s2, strerror(errno));
178 bool AskQuestion(string const & s1, string const & s2, string const & s3,
181 if (!lyxrc.use_gui) {
182 lyxerr << "----------------------------------------" << endl
185 lyxerr << s2 << endl;
187 lyxerr << s3 << endl;
188 lyxerr << "Assuming answer is "
189 << (default_value ? "yes" : "no")
191 << "----------------------------------------" << endl;
192 return default_value;
195 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
196 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
197 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
201 // Returns 1 for yes, 2 for no, 3 for cancel.
202 int AskConfirmation(string const & s1, string const & s2, string const & s3,
205 if (!lyxrc.use_gui) {
206 lyxerr << "----------------------------------------" << endl
209 lyxerr << s2 << endl;
211 lyxerr << s3 << endl;
212 lyxerr << "Assuming answer is ";
213 if (default_value == 1)
215 else if (default_value == 2)
220 << "----------------------------------------" << endl;
221 return default_value;
224 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
226 scex(_("Cancel|^[")));
227 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
228 3, idex(_("Yes|Yy#y")),
230 idex(_("Cancel|^[")), 3);
235 pair<bool, string> const
236 askForText(string const & msg, string const & dflt)
238 if (!lyxrc.use_gui) {
239 lyxerr << "----------------------------------------" << endl
241 << "Assuming answer is " << dflt
242 << "----------------------------------------" << endl;
243 return make_pair<bool, string>(true, dflt);
246 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
247 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
248 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
249 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
251 return make_pair<bool, string>(true, string(tmp));
253 return make_pair<bool, string>(false, string());
257 // Inform the user that the buffer is read-only, and that changes in the
258 // dialog box that is to appear will be ignored.
259 void WarnReadonly(string const & file)
261 WriteAlert(_("Any changes will be ignored"),
262 _("The document is read-only:"),
263 MakeDisplayPath(file));
266 /// Get the dpi setting of the current screen
269 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
270 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
271 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;