home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / lyx_gui_misc.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  9KB  |  328 lines

  1. // -*- C++ -*-
  2. /* This file is part of
  3. * ======================================================
  4. *           LyX, The Document Processor
  5. *        
  6. *           Copyright (C) 1995 Matthias Ettrich
  7. *           Copyright (C) 1995-1998 The LyX Team.
  8. *
  9. *======================================================*/
  10.  
  11. #include <config.h>
  12.  
  13. #include <errno.h>
  14. #include "lyx_gui_misc.h"
  15. #include "BufferView.h"
  16. #include "bibforms.h"
  17. #include "buffer.h"
  18. #include "bullet_forms.h"
  19. #include "form1.h"
  20. #include "gettext.h"
  21. #include "include_form.h"
  22. #include "latexoptions.h"
  23. #include "layout_forms.h"
  24. #include "lyx.h"
  25. #include "lyx_cb.h"
  26. #include "lyx_main.h"
  27. #include "math_forms.h"
  28. #include "minibuffer.h"
  29. #include "print_form.h"
  30. #include "sp_form.h"
  31.  
  32. extern MiniBuffer *minibuffer;
  33. extern BufferView *current_view;
  34. //     $Id: lyx_gui_misc.C,v 1.1.1.1 1998/04/23 16:02:53 larsbj Exp $    
  35.  
  36. #if !defined(lint) && !defined(WITH_WARNINGS)
  37. static char vcid[] = "$Id: lyx_gui_misc.C,v 1.1.1.1 1998/04/23 16:02:53 larsbj Exp $";
  38. #endif /* lint */
  39.  
  40.  
  41. extern FD_form_paragraph * fd_form_paragraph;
  42. extern FD_form_paragraph_extra * fd_form_paragraph_extra;
  43. extern FD_form_search * fd_form_search;
  44. extern FD_form_character * fd_form_character;
  45. extern FD_form_document * fd_form_document;
  46. extern FD_form_paper * fd_form_paper;
  47. extern FD_form_table_options * fd_form_table_options;
  48. extern FD_form_quotes * fd_form_quotes;
  49. extern FD_form_preamble * fd_form_preamble;
  50. extern FD_form_table * fd_form_table;
  51. extern FD_form_print * fd_form_print;
  52. extern FD_form_sendto * fd_form_sendto;
  53. extern FD_form_figure * fd_form_figure;
  54. extern FD_form_toc * fd_form_toc;
  55. extern FD_form_ref * fd_form_ref;
  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_citation_form * citation_form;
  66. extern FD_bibitem_form * bibitem_form;
  67. extern FD_include * form;
  68.  
  69. extern void TocUpdateCB();
  70.  
  71. // Prevents LyX from being killed when the close box is pressed in a popup.
  72. int CancelCloseBoxCB(FL_FORM *, void *)
  73. {
  74.     return FL_CANCEL;
  75. }
  76.  
  77.  
  78. // Prevents LyX from being killed when the close box is pressed in a popup.
  79. int IgnoreCloseBoxCB(FL_FORM *, void *)
  80. {
  81.     return FL_IGNORE;
  82. }
  83.  
  84.  
  85. // Prevents LyX from crashing when no buffers available
  86. // This is also one of the functions that we _really_ dont want
  87. // we should try to finds way to help us with that.
  88. // The signal/slot mechanism can probably help. 
  89. void CloseAllBufferRelatedPopups()
  90. {
  91.     // don't forget to check that dynamically created forms
  92.     // have been created otherwise hiding one could cause a crash
  93.     // need the visible check otherwise XForms prints a warning
  94.     // if hiding an invisible form
  95.     if (fd_form_paragraph->form_paragraph->visible) {
  96.         fl_hide_form(fd_form_paragraph->form_paragraph);
  97.     }
  98.     if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
  99.         fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
  100.     }
  101.     if (fd_form_search->form_search->visible) {
  102.         fl_hide_form(fd_form_search->form_search);
  103.     }
  104.     if (fd_form_character->form_character->visible) {
  105.         fl_hide_form(fd_form_character->form_character);
  106.     }
  107.     if (fd_form_document->form_document->visible) {
  108.         fl_hide_form(fd_form_document->form_document);
  109.     }
  110.     if (fd_form_quotes->form_quotes->visible) {
  111.         fl_hide_form(fd_form_quotes->form_quotes);
  112.     }
  113.     if (fd_form_preamble->form_preamble->visible) {
  114.         fl_hide_form(fd_form_preamble->form_preamble);
  115.     }
  116.     if (fd_form_table->form_table->visible) {
  117.         fl_hide_form(fd_form_table->form_table);
  118.     }
  119.     if (fd_form_print->form_print->visible) {
  120.         fl_hide_form(fd_form_print->form_print);
  121.     }
  122.     if (fd_form_figure->form_figure->visible) {
  123.         fl_hide_form(fd_form_figure->form_figure);
  124.     }
  125.     if (fd_form_toc->form_toc->visible) {
  126.         fl_hide_form(fd_form_toc->form_toc);
  127.     }
  128.     if (fd_form_ref->form_ref->visible) {
  129.         fl_hide_form(fd_form_ref->form_ref);
  130.     }
  131.     if (fd_form_paper->form_paper->visible) {
  132.         fl_hide_form(fd_form_paper->form_paper);
  133.     }
  134.     if (fd_form_table_options->form_table_options->visible) {
  135.         fl_hide_form(fd_form_table_options->form_table_options);
  136.     }
  137.     if (fd_form_sendto->form_sendto->visible) {
  138.         fl_hide_form(fd_form_sendto->form_sendto);
  139.     }
  140.     if (fd_latex_log->LaTeXLog->visible) {
  141.         fl_hide_form(fd_latex_log->LaTeXLog);
  142.     }
  143.     if (fd_form_spell_check) {
  144.         if (fd_form_spell_check->form_spell_check->visible) {
  145.             fl_trigger_object(fd_form_spell_check->done);
  146.         }
  147.     }
  148.     if (fd_form_bullet) {
  149.         if (fd_form_bullet->form_bullet->visible) {
  150.             fl_hide_form(fd_form_bullet->form_bullet);
  151.         }
  152.     }
  153.     if (fd_panel) {
  154.         if (fd_panel->panel->visible) {
  155.             fl_hide_form(fd_panel->panel);
  156.         }
  157.     }
  158.     if (fd_delim) {
  159.         if (fd_delim->delim->visible) {
  160.             fl_hide_form(fd_delim->delim);
  161.         }
  162.     }
  163.     if (fd_deco) {
  164.         if (fd_deco->deco->visible) {
  165.             fl_hide_form(fd_deco->deco);
  166.         }
  167.     }
  168.     if (fd_space) {
  169.         if (fd_space->space->visible) {
  170.             fl_hide_form(fd_space->space);
  171.         }
  172.     }
  173.     if (fd_matrix) {
  174.         if (fd_matrix->matrix->visible) {
  175.             fl_hide_form(fd_matrix->matrix);
  176.         }
  177.     }
  178.     if (citation_form) {
  179.         if (citation_form->citation_form->visible) {
  180.             fl_hide_form(citation_form->citation_form);
  181.         }
  182.     }
  183.     if (bibitem_form) {
  184.         if (bibitem_form->bibitem_form->visible) {
  185.             fl_hide_form(bibitem_form->bibitem_form);
  186.         }
  187.     }
  188.     if (form) {
  189.         if (form->include->visible) {
  190.             fl_hide_form(form->include);
  191.         }
  192.     }
  193. }
  194.  
  195. // This is another function we really don't want.
  196. // Again the Signal/Slot mechanism is tailor made for this task.
  197. void updateAllVisibleBufferRelatedPopups()
  198. {
  199.     if (fd_form_document->form_document->visible) {
  200.         UpdateLayoutDocument();
  201.     }
  202.     if (fd_form_preamble->form_preamble->visible) {
  203.         UpdateLayoutPreamble();
  204.     }
  205.     if (fd_form_quotes->form_quotes->visible) {
  206.         UpdateLayoutQuotes();
  207.     }
  208.     if (fd_form_paragraph->form_paragraph->visible) {
  209.         UpdateLayoutParagraph();
  210.     }
  211.     if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
  212.         UpdateParagraphExtra();
  213.     }
  214.     if (fd_form_paper->form_paper->visible) {
  215.         UpdateLayoutPaper();
  216.     }
  217.     if (fd_form_table_options->form_table_options->visible) {
  218.         UpdateLayoutTable(1); // just like a right mouse click
  219.     }
  220.     if (fd_form_bullet) {
  221.         if (fd_form_bullet->form_bullet->visible) {
  222.             updateBulletForm();
  223.         }
  224.     }
  225.     if (fd_form_toc->browser_toc->visible) {
  226.         TocUpdateCB(0,0);
  227.     }
  228. }
  229.  
  230. // Extract shortcut from <ident>|<shortcut> string
  231. const char* flyx_shortcut_extract(char const *sc)
  232. {
  233.     // Find '|' in the sc and return the string after that.
  234.  
  235.     register const char *sd = sc;
  236.     while(sd[0]!=0 && sd[0] != '|') sd++;
  237.  
  238.     if (sd[0]=='|') {
  239.         sd++;
  240.         //fprintf(stderr, "%s\n", sd);
  241.         return sd;
  242.     }
  243.     return "";
  244. }
  245.  
  246. // Extract identifier from <ident>|<shortcut> string
  247. const char* flyx_ident_extract(char const *sc)
  248. {
  249.     register const char *se = sc;
  250.     while(se[0]!=0 && se[0] != '|') se++;
  251.  
  252.     if (se[0]==0) return sc;
  253.     
  254.     char * sb = new char[se-sc + 1];
  255.     int index = 0;
  256.     register const char *sd = sc;
  257.     while (sd != se) {
  258.         sb[index] = sd[0];
  259.         index++; sd++;
  260.     }
  261.     sb[index]=0;
  262.     return sb;
  263. }
  264.  
  265.  
  266. //
  267. void WriteAlert(LString const & s1, LString const & s2, LString const & s3)
  268. {
  269.     if (minibuffer) {
  270.         ProhibitInput();
  271.         minibuffer->Set(s1, s2, s3);
  272.     }
  273.  
  274.     fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
  275.     fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
  276.     if (minibuffer) {
  277.         AllowInput();
  278.     }
  279. }
  280.  
  281.  
  282. // Alarms user of something related to files
  283. void WriteFSAlert(LString const & s1, LString const & s2)
  284. {
  285.     WriteAlert (s1, s2, strerror(errno));
  286. }
  287.  
  288.  
  289. bool AskQuestion(LString const & s1, LString const & s2, LString const & s3)
  290. {
  291.     fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
  292.     fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
  293.  
  294.     return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
  295. }
  296.  
  297. // Returns 1 for yes, 2 for no, 3 for cancel.
  298. int AskConfirmation(LString const & s1, LString const & s2, LString const & s3)
  299. {
  300.     fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
  301.                 scex(_("No|Nn#n")),
  302.                 scex(_("Cancel|^[")));
  303.         return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(), 
  304.                   3, idex(_("Yes|Yy#y")),
  305.                   idex(_("No|Nn#n")),
  306.                               idex(_("Cancel|^[")), 3);
  307. }
  308.  
  309.  
  310. // Asks for a text
  311. LString askForText(LString const & msg, LString const & dflt)
  312. {
  313.     LString tmp;
  314.     tmp = fl_show_input(msg.c_str(), dflt.c_str());
  315.     return tmp;
  316. }
  317.  
  318. // Inform the user that the buffer is read-only, and that changes in the
  319. // dialog box that is to appear will be ignored.
  320. void WarnReadonly()
  321. {
  322.     WriteAlert(_("Any changes will be ignored"),
  323.            _("The document is read-only:"),
  324.            current_view->currentBuffer()->getFileName());
  325. }
  326.  
  327.