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 "bullet_forms.h"
26 #include "include_form.h"
28 #include "layout_forms.h"
32 #include "mathed/math_forms.h"
33 #include "minibuffer.h"
34 #include "print_form.h"
37 #include "bufferview_funcs.h"
38 #include "support/filetools.h"
43 extern BufferView * current_view;
45 extern FD_form_paragraph * fd_form_paragraph;
46 extern FD_form_paragraph_extra * fd_form_paragraph_extra;
47 extern FD_form_character * fd_form_character;
48 extern FD_form_document * fd_form_document;
49 extern FD_form_paper * fd_form_paper;
50 extern FD_form_table_options * fd_form_table_options;
51 extern FD_form_quotes * fd_form_quotes;
52 extern FD_form_preamble * fd_form_preamble;
53 extern FD_form_table * fd_form_table;
54 extern FD_form_sendto * fd_form_sendto;
55 extern FD_form_figure * fd_form_figure;
56 extern FD_form_paragraph_extra * fd_form_paragraph_extra;
57 extern FD_LaTeXLog * fd_latex_log;
58 extern FD_form_spell_check * fd_form_spell_check;
59 extern FD_form_bullet * fd_form_bullet;
60 extern FD_panel * fd_panel;
61 extern FD_delim * fd_delim;
62 extern FD_deco * fd_deco;
63 extern FD_space * fd_space;
64 extern FD_matrix * fd_matrix;
65 extern FD_bibitem_form * bibitem_form;
66 extern FD_include * form;
68 extern void HideFiguresPopups();
70 // Prevents LyX from being killed when the close box is pressed in a popup.
71 extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
77 // Prevents LyX from being killed when the close box is pressed in a popup.
78 extern "C" int IgnoreCloseBoxCB(FL_FORM *, void *)
84 // Prevents LyX from crashing when no buffers available
85 // This is also one of the functions that we _really_ dont want
86 // we should try to finds way to help us with that.
87 // The signal/slot mechanism can probably help.
88 void CloseAllBufferRelatedDialogs()
90 // don't forget to check that dynamically created forms
91 // have been created otherwise hiding one could cause a crash
92 // need the visible check otherwise XForms prints a warning
93 // if hiding an invisible form
94 if (fd_form_paragraph->form_paragraph->visible) {
95 fl_hide_form(fd_form_paragraph->form_paragraph);
97 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
98 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
100 if (fd_form_character->form_character->visible) {
101 fl_hide_form(fd_form_character->form_character);
103 #ifdef USE_OLD_DOCUMENT_LAYOUT
104 if (fd_form_document->form_document->visible) {
105 fl_hide_form(fd_form_document->form_document);
107 if (fd_form_quotes->form_quotes->visible) {
108 fl_hide_form(fd_form_quotes->form_quotes);
110 if (fd_form_paper->form_paper->visible) {
111 fl_hide_form(fd_form_paper->form_paper);
113 if (fd_form_bullet) {
114 if (fd_form_bullet->form_bullet->visible) {
115 fl_hide_form(fd_form_bullet->form_bullet);
119 if (fd_form_preamble->form_preamble->visible) {
120 fl_hide_form(fd_form_preamble->form_preamble);
122 if (fd_form_figure->form_figure->visible) {
123 fl_hide_form(fd_form_figure->form_figure);
125 if (fd_form_sendto->form_sendto->visible) {
126 fl_hide_form(fd_form_sendto->form_sendto);
128 if (fd_latex_log->LaTeXLog->visible) {
129 fl_hide_form(fd_latex_log->LaTeXLog);
131 if (fd_form_spell_check) {
132 if (fd_form_spell_check->form_spell_check->visible) {
133 fl_trigger_object(fd_form_spell_check->done);
137 if (fd_panel->panel->visible) {
138 fl_hide_form(fd_panel->panel);
142 if (fd_delim->delim->visible) {
143 fl_hide_form(fd_delim->delim);
147 if (fd_deco->deco->visible) {
148 fl_hide_form(fd_deco->deco);
152 if (fd_space->space->visible) {
153 fl_hide_form(fd_space->space);
157 if (fd_matrix->matrix->visible) {
158 fl_hide_form(fd_matrix->matrix);
162 if (bibitem_form->bibitem_form->visible) {
163 fl_hide_form(bibitem_form->bibitem_form);
167 if (form->include->visible) {
168 fl_hide_form(form->include);
174 // This is another function we really don't want.
175 // Again the Signal/Slot mechanism is tailor made for this task.
176 void updateAllVisibleBufferRelatedDialogs()
178 #ifdef USE_OLD_DOCUMENT_LAYOUT
179 if (fd_form_document->form_document->visible) {
180 UpdateLayoutDocument();
182 if (fd_form_quotes->form_quotes->visible) {
183 UpdateLayoutQuotes();
185 if (fd_form_paper->form_paper->visible) {
189 if (fd_form_preamble->form_preamble->visible) {
190 UpdateLayoutPreamble();
192 if (fd_form_paragraph->form_paragraph->visible) {
193 UpdateLayoutParagraph();
195 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
196 UpdateParagraphExtra();
198 if (fd_form_bullet) {
199 if (fd_form_bullet->form_bullet->visible) {
203 if (fd_latex_log->LaTeXLog->visible) {
206 if (current_view->buffer()->isReadonly()) {
207 // a little crude perhaps but it works. ARRae
208 if (fd_form_character->form_character->visible) {
209 fl_hide_form(fd_form_character->form_character);
211 #ifndef ALWAYS_CLOSE_MATH_PANELS
212 // The math popups should be closed only if we switch
213 // to a readonly buffer
215 if (fd_panel->panel->visible) {
216 fl_hide_form(fd_panel->panel);
220 if (fd_delim->delim->visible) {
221 fl_hide_form(fd_delim->delim);
225 if (fd_deco->deco->visible) {
226 fl_hide_form(fd_deco->deco);
230 if (fd_space->space->visible) {
231 fl_hide_form(fd_space->space);
235 if (fd_matrix->matrix->visible) {
236 fl_hide_form(fd_matrix->matrix);
242 // We have either changed buffers or changed the readonly status
243 // so the safest thing to do is hide all inset popups that
244 // are editting insets from the previous buffer or aren't
245 // allowed in readonly docs.
246 #ifdef ALWAYS_CLOSE_MATH_PANELS
248 if (fd_panel->panel->visible) {
249 fl_hide_form(fd_panel->panel);
253 if (fd_delim->delim->visible) {
254 fl_hide_form(fd_delim->delim);
258 if (fd_deco->deco->visible) {
259 fl_hide_form(fd_deco->deco);
263 if (fd_space->space->visible) {
264 fl_hide_form(fd_space->space);
268 if (fd_matrix->matrix->visible) {
269 fl_hide_form(fd_matrix->matrix);
274 if (bibitem_form->bibitem_form->visible) {
275 fl_hide_form(bibitem_form->bibitem_form);
279 if (form->include->visible) {
280 fl_hide_form(form->include);
286 // Extract shortcut from <ident>|<shortcut> string
287 char const * flyx_shortcut_extract(char const * sc)
289 // Find '|' in the sc and return the string after that.
290 register char const * sd = sc;
291 while(sd[0]!= 0 && sd[0] != '|') ++sd;
295 //lyxerr << sd << endl;
302 // Extract identifier from <ident>|<shortcut> string
303 char const * flyx_ident_extract(char const * sc)
305 register char const * se = sc;
306 while(se[0]!= 0 && se[0] != '|') ++se;
308 if (se[0] == 0) return sc;
310 char * sb = new char[se - sc + 1];
312 register char const * sd = sc;
323 void WriteAlert(string const & s1, string const & s2, string const & s3)
325 MiniBuffer * minibuffer = 0;
326 if (current_view && current_view->owner())
327 minibuffer = current_view->owner()->getMiniBuffer();
329 ProhibitInput(current_view);
330 minibuffer->Set(s1, s2, s3);
333 fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
334 fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
336 AllowInput(current_view);
341 // Alarms user of something related to files
342 void WriteFSAlert(string const & s1, string const & s2)
344 WriteAlert (s1, s2, strerror(errno));
348 bool AskQuestion(string const & s1, string const & s2, string const & s3)
350 fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
351 fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
352 return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
356 // Returns 1 for yes, 2 for no, 3 for cancel.
357 int AskConfirmation(string const & s1, string const & s2, string const & s3)
359 fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
361 scex(_("Cancel|^[")));
362 return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
363 3, idex(_("Yes|Yy#y")),
365 idex(_("Cancel|^[")), 3);
370 pair<bool, string> const
371 askForText(string const & msg, string const & dflt)
373 fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
374 fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
375 fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
376 char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
378 return make_pair<bool, string>(true, string(tmp));
380 return make_pair<bool, string>(false, string());
384 // Inform the user that the buffer is read-only, and that changes in the
385 // dialog box that is to appear will be ignored.
386 void WarnReadonly(string const & file)
388 WriteAlert(_("Any changes will be ignored"),
389 _("The document is read-only:"),
390 MakeDisplayPath(file));
393 /// Get the dpi setting of the current screen
396 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
397 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
398 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;