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_cb.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  98KB  |  3,675 lines

  1. /* This file is part of
  2. * ======================================================
  3. *           LyX, The Document Processor
  4. *      
  5. *        Copyright (C) 1995 Matthias Ettrich,
  6. *           Copyright (C) 1995-1998 The LyX Team.
  7. *
  8. *======================================================*/
  9.  
  10. #include <config.h>
  11.  
  12. #include <ctype.h>
  13. #include <unistd.h>
  14. #include <signal.h>
  15. #include <stdlib.h>
  16.  
  17. #include "LString.h"
  18. #include "lyx_main.h"
  19. #include FORMS_H_LOCATION
  20. #include "lyx.h"
  21. #include "layout_forms.h"
  22. #include "bullet_forms.h"
  23. #include "print_form.h"
  24. #include "form1.h"
  25. #include "spellchecker.h"
  26. #include "version.h"
  27. #include "lyx_cb.h"
  28. #include "credits.h"
  29. #include "insetref.h"
  30. #include "insetquotes.h"
  31. #include "insetlabel.h"
  32. #include "insetinfo.h"
  33. #include "insetspecialchar.h"
  34. #include "figinset.h"
  35. #include "lyxfunc.h"
  36. #include "latexoptions.h"
  37. #include "lyxfont.h"
  38. #include "minibuffer.h"
  39. #include "combox.h"
  40. #include "bufferlist.h"
  41. #include "filetools.h"
  42. #include "path.h"
  43. #include "filedlg.h"
  44. #include "lyx_gui_misc.h"
  45. #include "LyXView.h" // only because of form_main
  46. #include "lastfiles.h"
  47. #include "FileInfo.h"
  48. #include "lyxscreen.h"
  49. #include "error.h"
  50. #include "syscall.h"
  51. #include "lyxlib.h"
  52. #include "lyxserver.h"
  53. #include "FontLoader.h"
  54. #include "lyxrc.h"
  55. #include "lyxtext.h"
  56. #include "gettext.h"
  57. #include "insetfig.h"
  58.  
  59. //     $Id: lyx_cb.C,v 1.1.1.1 1998/04/23 16:02:52 larsbj Exp $    
  60.  
  61. #if !defined(lint) && !defined(WITH_WARNINGS)
  62. static char vcid[] = "$Id: lyx_cb.C,v 1.1.1.1 1998/04/23 16:02:52 larsbj Exp $";
  63. #endif /* lint */
  64.  
  65. extern MiniBuffer *minibuffer;
  66. extern Combox *combo_language;
  67. extern BufferList bufferlist;
  68. extern void show_symbols_form();
  69. extern FD_form_main *fd_form_main;
  70. extern FD_form_title *fd_form_title;
  71. extern FD_form_paragraph *fd_form_paragraph;
  72. extern FD_form_character *fd_form_character;
  73. extern FD_form_document *fd_form_document;
  74. extern FD_form_quotes *fd_form_quotes;
  75. extern FD_form_preamble *fd_form_preamble;
  76. extern FD_form_table *fd_form_table;
  77. extern FD_form_print *fd_form_print;
  78. extern FD_form_figure *fd_form_figure;
  79. extern FD_form_screen *fd_form_screen;
  80. extern FD_form_toc *fd_form_toc;
  81. extern FD_form_ref *fd_form_ref;
  82. extern FD_LaTeXOptions *fd_latex_options;
  83. extern FD_form_bullet *fd_form_bullet;
  84.  
  85. extern BufferView *current_view; // called too many times in this file...
  86.  
  87. extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
  88.  
  89. extern void sigchldhandler(int sig);
  90. extern int send_fax(LString const &fname, LString const &sendcmd);
  91.  
  92. extern LyXServer *lyxserver;
  93. extern FontLoader fontloader;
  94.  
  95. // this should be static, but I need it in buffer.C
  96. bool quitting;    // flag, that we are quitting the program
  97. extern bool finished; // all cleanup done just let it run through now.
  98.  
  99. char ascii_type; /* for selection notify callbacks */
  100.  
  101. bool scrolling = false;
  102.  
  103. char updatetimer = 0;
  104.  
  105. /* whether the work area should get callbacks */ 
  106. bool input_prohibited = false;
  107.  
  108. /* the selection possible is needed, that only motion events are 
  109. * used, where the bottom press event was on the drawing area too */
  110. bool selection_possible = false;
  111.  
  112. void InsertCorrectQuote();
  113.  
  114.  
  115. /* 
  116.    This is the inset locking stuff needed for mathed --------------------
  117.  
  118.    an inset can simple call LockInset in it's edit call and *ONLY* in it's
  119.    edit call.
  120.    Inset::Edit() can only be called by the main lyx module.
  121.  
  122.    Then the inset may modify the menu's and/or iconbars. 
  123.  
  124.    Unlocking is either done by LyX or the inset itself with a UnlockInset-call
  125.  
  126.    During the lock, all button and keyboard events will be modified
  127.    and send to the inset through the following inset-features. Note that
  128.    Inset::InsetUnlock will be called from inside UnlockInset. It is meant
  129.    to contain the code for restoring the menus and things like this.
  130.  
  131.    
  132.    virtual void InsetButtonPress(int x, int y, int button);
  133.    virtual void InsetButtonRelease(int x, int y, int button);
  134.    virtual void InsetKeyPress(XKeyEvent *ev);
  135.    virtual void InsetMotionNotify(int x, int y, int state);
  136.    virtual void InsetUnlock();
  137.  
  138.    If a inset wishes any redraw and/or update it just has to call
  139.    UpdateInset(this).
  140.    It's is completly irrelevant, where the inset is. UpdateInset will
  141.    find it in any paragraph in any buffer. 
  142.    Of course the_locking_inset and the insets in the current paragraph/buffer
  143.    are checked first, so no performance problem should occur.
  144.    
  145.    Hope that's ok for the beginning, Alejandro,
  146.    sorry that I needed so much time,
  147.  
  148.                   Matthias
  149.    */
  150.  
  151. void UpdateInset(Inset* inset, bool mark_dirty = true);
  152. /* these functions return 1 if an error occured, 
  153.    otherwise 0 */
  154. // Now they work only for updatable insets. [Alejandro 080596]
  155. bool LockInset(UpdatableInset* inset);
  156. void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
  157. void FitLockedInsetCursor(long x, long y, int asc, int desc);
  158. int UnlockInset(UpdatableInset* inset);
  159. void LockedInsetStoreUndo(Undo::undo_kind kind);
  160.  
  161. /* this is for asyncron updating. UpdateInsetUpdateList will be called
  162.    automatically from LyX. Just insert the Inset into the Updatelist */
  163. void UpdateInsetUpdateList();
  164. void PutInsetIntoInsetUpdateList(Inset* inset);
  165.  
  166. InsetUpdateStruct *InsetUpdateList = NULL;
  167.  
  168.  
  169. /*
  170.   -----------------------------------------------------------------------
  171.  */
  172.  
  173. /* some function prototypes */
  174.  
  175. void GotoNote();
  176. void OpenStuff();
  177. void ToggleFloat();
  178. void MenuUndo();
  179. void MenuRedo();
  180. void HyphenationPoint();
  181. void HFill();
  182. void Newline();
  183. void ProtectedBlank();
  184. void CopyCB();
  185. int RunLinuxDoc(int, LString const &);
  186. void MenuWrite(Buffer* buf);
  187. void MenuWriteAs(Buffer *buffer);
  188. void MenuReload(Buffer *buf);
  189. void MenuLayoutSave();
  190.  
  191. unsigned char GetCurrentTextClass()
  192. {
  193.     return current_view->currentBuffer()->params.textclass;
  194. }
  195.  
  196.  
  197. // How should this actually work? Should it prohibit input in all BufferViews,
  198. // or just in the current one? If "just the current one", then it should be
  199. // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
  200. // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
  201. // BufferViews. Or is it perhaps just the (input in) BufferViews in the
  202. // current LyxView that should be prohibited (Lgb) (This applies to
  203. // "AllowInput" as well.)
  204. void ProhibitInput()
  205. {
  206.     input_prohibited = true;
  207.     if (current_view->getScreen())
  208.         current_view->getScreen()->HideCursor();
  209.  
  210.     static Cursor cursor;
  211.     static bool cursor_undefined = true;
  212.    
  213.     if (cursor_undefined){
  214.         cursor = XCreateFontCursor(fl_display, XC_watch);
  215.         XFlush(fl_display);
  216.         cursor_undefined = false;
  217.     }
  218.    
  219.     /* set the cursor to the watch for all forms and the canvas */ 
  220.     XDefineCursor(fl_display, fd_form_main->form_main->window, cursor);
  221.     if (fd_form_paragraph->form_paragraph->visible)
  222.         XDefineCursor(fl_display,
  223.                   fd_form_paragraph->form_paragraph->window,
  224.                   cursor);
  225.     if (fd_form_character->form_character->visible)
  226.         XDefineCursor(fl_display,
  227.                   fd_form_character->form_character->window,
  228.                   cursor);
  229.  
  230.     XFlush(fl_display);
  231.     fl_deactivate_all_forms();
  232. }
  233.  
  234.  
  235. // Should find a way to move this into BufferView.C
  236. void SetXtermCursor(Window win)
  237. {
  238.     static Cursor cursor;
  239.     static char cursor_undefined = 1;
  240.     if (cursor_undefined){
  241.         cursor = XCreateFontCursor(fl_display, XC_xterm);
  242.         XFlush(fl_display);
  243.         cursor_undefined = 0;
  244.     }
  245.     XDefineCursor(fl_display, win, cursor);
  246.     XFlush(fl_display);
  247. }
  248.  
  249.  
  250. void AllowInput()
  251. {
  252.     input_prohibited = false;
  253.  
  254.     /* reset the cursor from the watch for all forms and the canvas */
  255.    
  256.     XUndefineCursor(fl_display, fd_form_main->form_main->window);
  257.     if (fd_form_paragraph->form_paragraph->visible)
  258.         XUndefineCursor(fl_display,
  259.                 fd_form_paragraph->form_paragraph->window);
  260.     if (fd_form_character->form_character->visible)
  261.         XUndefineCursor(fl_display,
  262.                 fd_form_character->form_character->window);
  263.     if (current_view->getWorkArea()->belowmouse)
  264.         SetXtermCursor(fd_form_main->form_main->window);
  265.  
  266.     XFlush(fl_display);
  267.     fl_activate_all_forms();
  268. }
  269.  
  270.  
  271. void FreeUpdateTimer()
  272. {
  273.     /* a real free timer would be better but I don't know 
  274.      * how to do this with xforms */
  275.     updatetimer = 0;
  276. }
  277.  
  278.  
  279. void SetUpdateTimer(float time)
  280. {
  281.     fl_set_timer(fd_form_main->timer_update, time);
  282.     updatetimer = 1;
  283. }
  284.  
  285.  
  286. void BeforeChange()
  287. {
  288.     current_view->getScreen()->ToggleSelection();
  289.     current_view->currentBuffer()->text->ClearSelection();
  290.     FreeUpdateTimer();
  291. }
  292.  
  293.  
  294. void SmallUpdate(signed char f)
  295. {
  296.     current_view->getScreen()->SmallUpdate();
  297.     if (current_view->getScreen()->TopCursorVisible()
  298.         != current_view->getScreen()->first){
  299.         current_view->currentBuffer()->update(f);
  300.         return;
  301.     }
  302.  
  303.     current_view->fitCursor();
  304.     current_view->updateScrollbar();
  305.    
  306.     if (!current_view->currentBuffer()->text->selection)
  307.         current_view->currentBuffer()->text->sel_cursor = 
  308.             current_view->currentBuffer()->text->cursor;
  309.  
  310.     if (f==1 || f==-1) {
  311.         if (current_view->currentBuffer()->isLyxClean()) {
  312.             current_view->currentBuffer()->markDirty();
  313.             minibuffer->setTimer(4);
  314.         }
  315.         else {
  316.             current_view->currentBuffer()->markDirty();
  317.         }
  318.     }
  319. }
  320.  
  321.  
  322. //
  323. // Menu callbacks
  324. //
  325.  
  326. //
  327. // File menu
  328. //
  329.  
  330. // should be moved to lyxfunc.C
  331. void MenuWrite(Buffer* buf)
  332. {
  333.     XFlush(fl_display);
  334.     if (!bufferlist.write(buf)) {
  335.         LString fname = buf->getFileName();
  336.         LString s = MakeAbsPath(fname);
  337.         if (AskQuestion(_("Save failed. Rename and try again?"),
  338.                  MakeDisplayPath(s,50),
  339.                  _("(If not, document is not saved.)"))) {
  340.             MenuWriteAs(buf);
  341.         }
  342.     } else {
  343.         lastfiles->newFile(buf->getFileName());
  344.     }
  345. }
  346.  
  347.  
  348. // should be moved to BufferView.C
  349. void MenuWriteAs(Buffer *buffer)
  350. {
  351.     if (!buffer->text) return;
  352.  
  353.     LString fname = buffer->getFileName();
  354.     LString oldname = fname;
  355.     LyXFileDlg fileDlg;
  356.  
  357.     ProhibitInput();
  358.     fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
  359.     fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
  360.  
  361.     if (!IsLyXFilename(fname))
  362.         fname += ".lyx";
  363.  
  364.     fname = fileDlg.Select(_("Enter Filename to Save Document as"), 
  365.                    OnlyPath(fname),
  366.                    "*.lyx", 
  367.                    OnlyFilename(fname));
  368.     AllowInput();
  369.  
  370.     if (fname.empty()) {
  371.         minibuffer->Set(_("Canceled."));
  372.         return;
  373.     }
  374.  
  375.     // Make sure the absolute filename ends with appropriate suffix
  376.     LString s= MakeAbsPath(fname);
  377.     if (!IsLyXFilename(s))
  378.         s += ".lyx";
  379.  
  380.     // Same name as we have already?
  381.     if (s == oldname) {
  382.         if (!AskQuestion(_("Same name as document already has:"),
  383.                  MakeDisplayPath(s,50),
  384.                  _("Save anyway?")))
  385.             return;
  386.         // Falls through to name change and save
  387.     } 
  388.     // No, but do we have another file with this name open?
  389.     else if (bufferlist.exists(s)) {
  390.         if (AskQuestion(_("Another document with same name open!"),
  391.                 MakeDisplayPath(s,50),
  392.                 _("Replace with current document?")))
  393.             {
  394.                 bufferlist.close(bufferlist.getBuffer(s));
  395.  
  396.                 // Ok, change the name of the buffer, but don't save!
  397.                 buffer->setFileName(s);
  398.                 buffer->markDirty();
  399.  
  400.                 minibuffer->Set(_("Document renamed to '"),
  401.                         MakeDisplayPath(s),
  402.                         _("', but not saved..."));
  403.             }
  404.         return;
  405.     } // Check whether the file exists
  406.     else {
  407.         FileInfo myfile(s);
  408.         if (myfile.isOK() && !AskQuestion(_("Document already exists:"), 
  409.                           MakeDisplayPath(s,50),
  410.                           _("Replace file?")))
  411.             return;
  412.     }
  413.  
  414.     // Ok, change the name of the buffer
  415.     buffer->setFileName(s);
  416.     buffer->markDirty();
  417.     // And save
  418.     // Small bug: If the save fails, we have irreversible changed the name
  419.     // of the document.
  420.     MenuWrite(buffer);
  421. }    
  422.  
  423.  
  424. int MenuRunLaTeX(Buffer *buffer)
  425. {
  426.     int ret;
  427.  
  428.     if (buffer->isLinuxDoc())
  429.         ret = RunLinuxDoc(1, buffer->getFileName());
  430.     else 
  431.         ret = buffer->runLaTeX();
  432.    
  433.     if (ret > 0) {
  434.         LString s;
  435.         LString t;
  436.         if (ret == 1) {
  437.             s = _("One error detected");
  438.             t = _("You should try to fix it.");
  439.         } else {
  440.             s += ret;
  441.             s += _(" errors detected.");
  442.             t = _("You should try to fix them.");
  443.         }
  444.         WriteAlert(_("There where errors during the LaTeX run."),
  445.                s, t);
  446.     }
  447.     return ret;
  448. }
  449.  
  450.  
  451. int MenuRunChktex(Buffer *buffer)
  452. {
  453.     int ret;
  454.  
  455.     if (buffer->isLinuxDoc()) {
  456.         WriteAlert(_("Chktex is no fun for LinuxDoc."));
  457.         return 0;
  458.     } else 
  459.         ret = buffer->runChktex();
  460.    
  461.     if (ret >= 0) {
  462.         LString s;
  463.         LString t;
  464.         if (ret == 0) {
  465.             s = _("No warnings found.");
  466.         } else if (ret == 1) {
  467.             s = _("One warning found.");
  468.             t = _("Use 'Edit->Go to Error' to find it.");
  469.         } else {
  470.             s += ret;
  471.             s += _(" warnings found.");
  472.             t = _("Use 'Edit->Go to Error' to find them.");
  473.         }
  474.         WriteAlert(_("Chktex run successfully"), s, t);
  475.     } else {
  476.         WriteAlert(_("Error!"),_("It seems chktex does not work."));
  477.     }
  478.     return ret;
  479. }
  480.  
  481.  
  482. int MakeDVIOutput(Buffer *buffer)
  483. {
  484.     if (!(buffer->text))
  485.         return 1;
  486.  
  487.     int ret = 0;
  488.  
  489.     LString path = OnlyPath(buffer->getFileName());
  490.     if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
  491.         path = buffer->tmppath;
  492.     }
  493.     if (!buffer->isDviClean()) {
  494.         //PathPush(path);
  495.         Path p(path);
  496.         ret = MenuRunLaTeX(buffer);
  497.         //PathPop();
  498.     }
  499.     return ret;
  500. }
  501.  
  502.  
  503. /* wait == false means don't wait for termination */
  504. /* wait == true means wait for termination       */
  505. // The bool should be placed last on the argument line. (Lgb)
  506. // Returns false if we fail.
  507. bool RunScript(Buffer *buffer, bool wait,
  508.            LString const & command, LString const & orgname = LString(),
  509.            bool need_shell=true)
  510. {
  511.     LString path;
  512.     LString cmd;
  513.     LString name= orgname;
  514.     
  515.     if (MakeDVIOutput(buffer) > 0)
  516.         return false;
  517.     /* get DVI-Filename */
  518.     if (name.empty())
  519.         name = ChangeExtension(buffer->getFileName(),
  520.                        ".dvi", true);
  521.  
  522.     path = OnlyPath(name);
  523.     if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
  524.         path = buffer->tmppath;
  525.     }
  526.     //PathPush(path);
  527.     Path p(path);
  528.  
  529.     cmd = command + ' ' + SpaceLess(name);
  530.     if (need_shell) {
  531.         if (!wait)
  532.             cmd += " &";
  533.         
  534.         minibuffer->Set(_("Executing command:"), cmd);
  535.         Systemcalls one(Systemcalls::System, cmd);
  536.     } else {
  537.         minibuffer->Set(_("Executing command:"), cmd);
  538.         Systemcalls one(wait ? Systemcalls::Wait
  539.                                      : Systemcalls::DontWait, cmd);
  540.     }
  541.     //PathPop();
  542.     return true;
  543. }
  544.  
  545.  
  546. // Returns false if we fail
  547. bool MenuRunDvips(Buffer *buffer, bool wait=false)
  548. {
  549.     if (!buffer->text)
  550.         return false;
  551.  
  552.     ProhibitInput();
  553.  
  554.     // Generate dvi file
  555.         if (MakeDVIOutput(buffer) > 0) {
  556.                 AllowInput();
  557.         return false;
  558.         }
  559.     // Generate postscript file
  560.     LString ps = ChangeExtension (buffer->getFileName(),
  561.                       ".ps_tmp", true);
  562.  
  563.     LString paper;
  564.     
  565.     char real_papersize = buffer->params.papersize;
  566.     if (real_papersize == PAPER_DEFAULT)
  567.         real_papersize = lyxrc->default_papersize;
  568.  
  569.     switch (real_papersize) {
  570.     case PAPER_USLETTER:
  571.         paper = "letter";
  572.         break;
  573.     case PAPER_A3PAPER:
  574.         paper = "a3";
  575.         break;
  576.     case PAPER_A4PAPER:
  577.         paper = "a4";
  578.         break;
  579.     case PAPER_A5PAPER:
  580.         paper = "a5";
  581.         break;
  582.     case PAPER_B5PAPER:
  583.         paper = "b5";
  584.         break;
  585.     case PAPER_EXECUTIVEPAPER:
  586.         paper = "foolscap";
  587.         break;
  588.     case PAPER_LEGALPAPER:
  589.         paper = "legal";
  590.         break;
  591.     default: /* If nothing else fits, keep an empty value... */
  592.         break;
  593.     }
  594.  
  595.     // Make postscript file.
  596.     LString command = "dvips -o " + SpaceLess(ps);
  597.     // dvips won't accept -t letter -t landscape.  In all other
  598.     // cases, include the paper size explicitly.
  599.     if (!paper.empty() 
  600.         && (real_papersize != PAPER_USLETTER ||
  601.         buffer->params.orientation == ORIENTATION_PORTRAIT))
  602.       command += " -t " + paper;
  603.     if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
  604.         command += " -t landscape";
  605.     // push directorypath, if necessary 
  606.         LString path = OnlyPath(buffer->getFileName());
  607.         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
  608.         path = buffer->tmppath;
  609.         }
  610.         //PathPush(path);
  611.     Path p(path);
  612.     bool ret = RunScript(buffer, wait, command);
  613.     AllowInput();
  614.         //PathPop();
  615.     return ret;
  616. }
  617.  
  618.  
  619. // Returns false if we fail
  620. bool MenuPreviewPS(Buffer *buffer)
  621. {
  622.     if (!buffer->text)
  623.         return false;
  624.  
  625.     // Generate postscript file
  626.     if (!MenuRunDvips(buffer, true)) {
  627.         return false;
  628.     }
  629.  
  630.     // Start postscript viewer
  631.     ProhibitInput();
  632.     LString ps = ChangeExtension (buffer->getFileName(),
  633.                       ".ps_tmp", true);
  634.     // push directorypath, if necessary 
  635.         LString path = OnlyPath(buffer->getFileName());
  636.         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
  637.         path = buffer->tmppath;
  638.         }
  639.         //PathPush(path);
  640.     Path p(path);
  641.     bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
  642.         //PathPop();
  643.     AllowInput();
  644.     return ret;
  645. }
  646.  
  647.  
  648. void MenuFax(Buffer *buffer)
  649. {
  650.     if (!buffer->text)
  651.         return;
  652.  
  653.     // Generate postscript file
  654.     if (!MenuRunDvips(buffer, true)) {
  655.         return;
  656.     }
  657.  
  658.     // Send fax
  659.     LString ps = ChangeExtension (buffer->getFileName(), ".ps_tmp", true);
  660.     LString path = OnlyPath (buffer->getFileName());
  661.     if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
  662.         path = buffer->tmppath;
  663.     }
  664.     //PathPush(path);
  665.     Path p(path);
  666.     if (!lyxrc->fax_program.empty()) {
  667.         LString help2;
  668.         char *ptr1, *ptr2;
  669.         char *help = new char[lyxrc->fax_program.length()+1]; // note +1
  670.         lyxrc->fax_program.copy(help, LString::npos);
  671.         help[lyxrc->fax_program.length()] = 0; // add terminator
  672.         if ((ptr1=strstr(help,"$$FName"))) {
  673.             ptr2=strchr(ptr1+1,'\'');
  674.             *ptr1 = 0;
  675.             help2 = help + ' ' + ps +' ' + (ptr2) + " &";
  676.             Systemcalls one(Systemcalls::System, help2);
  677.         } else {
  678.             help2 = lyxrc->fax_program +" &";
  679.             Systemcalls one(Systemcalls::System, help2);
  680.         }
  681.         delete [] help;
  682.     } else
  683.         send_fax(ps,lyxrc->fax_command);
  684.     //PathPop();
  685. }
  686.  
  687.  
  688. // Returns false if we fail
  689. bool MenuPreview(Buffer *buffer)
  690. {
  691.     if (!buffer->text)
  692.         return false;
  693.    
  694.     LString paper;
  695.     
  696.     char real_papersize = buffer->params.papersize;
  697.     if (real_papersize == PAPER_DEFAULT)
  698.         real_papersize = lyxrc->default_papersize;
  699.    
  700.     switch (real_papersize) {
  701.     case PAPER_USLETTER:
  702.         paper = "us";
  703.         break;
  704.     case PAPER_A3PAPER:
  705.         paper = "a3";
  706.         break;
  707.     case PAPER_A4PAPER:
  708.         paper = "a4";
  709.         break;
  710.     case PAPER_A5PAPER:
  711.         paper = "a5";
  712.         break;
  713.     case PAPER_B5PAPER:
  714.         paper = "b5";
  715.         break;
  716.     case PAPER_EXECUTIVEPAPER:
  717.         paper = "foolscap";
  718.         break;
  719.     case PAPER_LEGALPAPER:
  720.         paper = "legal";
  721.         break;
  722.     default: /* If nothing else fits, keep the empty value */
  723.         break;
  724.     }
  725.    
  726.     if (paper.empty()) {
  727.         if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
  728.             // we HAVE to give a size when the page is in
  729.             // landscape, so use USletter.        
  730.             paper = " -paper usr";
  731.     } else {
  732.         paper = " -paper " + paper;
  733.         if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
  734.             paper+='r';
  735.     }
  736.  
  737.     // push directorypath, if necessary 
  738.         LString path = OnlyPath(buffer->getFileName());
  739.         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
  740.         path = buffer->tmppath;
  741.         }
  742.         //PathPush(path);
  743.     Path p(path);
  744.     // Run dvi-viewer
  745.     LString command = lyxrc->view_dvi_command + paper ;
  746. #ifndef __EMX__
  747.     bool ret = RunScript(buffer, false, command);
  748. #else
  749.     bool ret = RunScript(buffer, false, command, LString(), false);
  750. #endif
  751.         //PathPop();
  752.     return ret;
  753. }
  754.  
  755.  
  756. void MenuMakeLaTeX(Buffer *buffer)
  757. {
  758.     if (buffer->text) {
  759.         // Get LaTeX-Filename
  760.         LString s = SpaceLess(ChangeExtension(
  761.                         buffer->getFileName(),
  762.                         ".tex", false));
  763.  
  764.         if (buffer->isLinuxDoc())
  765.             RunLinuxDoc(0, buffer->getFileName());
  766.         else
  767.             buffer->makeLaTeXFile(s, LString(), true);
  768.         minibuffer->Set(_("Nice LaTeX file saved as"),
  769.                 MakeDisplayPath(s));
  770.         buffer->markDviDirty();
  771.     }
  772. }
  773.  
  774.  
  775. void MenuMakeLinuxDoc(Buffer *buffer)
  776. {
  777.     if (buffer->text) {
  778.  
  779.         if (!buffer->isLinuxDoc()) {
  780.             WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
  781.             return;
  782.         }
  783.  
  784.         // Get LinuxDoc-Filename
  785.         LString s = ChangeExtension (buffer->getFileName(), 
  786.                          ".sgml", false);
  787.         minibuffer->Set(_("Building LinuxDoc SGML file `"),
  788.                 MakeDisplayPath(s), "'..."); 
  789.  
  790.         buffer->makeLinuxDocFile(s, 65);
  791.                 buffer->redraw();
  792.         minibuffer->Set(_("LinuxDoc SGML file"),
  793.                 MakeDisplayPath(s), _("built")); 
  794.     }
  795. }
  796.  
  797.  
  798. void MenuMakeAscii(Buffer *buffer)
  799. {
  800.     if (!buffer->text) return;
  801.     
  802.     /* get LaTeX-Filename */
  803.     LString s = ChangeExtension (buffer->getFileName(),
  804.                      ".txt", false);
  805.     buffer->writeFileAscii(s, lyxrc->ascii_linelen);
  806.     
  807.     minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s));
  808. }
  809.  
  810.  
  811. void MenuPrint(Buffer *buffer)
  812. {
  813.     LString input_file;
  814.  
  815.     if (!buffer->text) 
  816.         return;
  817.     
  818.     input_file = ChangeExtension(buffer->getFileName(),
  819.                      lyxrc->print_file_extension,
  820.                      true);
  821.     fl_set_input(fd_form_print->input_file, input_file.c_str());
  822.     
  823.     if (fd_form_print->form_print->visible) {
  824.         fl_raise_form(fd_form_print->form_print);
  825.     } else {
  826.         fl_show_form(fd_form_print->form_print,
  827.                  FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
  828.                  _("Print"));
  829.     }
  830. }
  831.  
  832.  
  833. void QuitLyX()
  834. {
  835.     lyxerr.debug("Running QuitLyX.");
  836.  
  837.     if (!bufferlist.QwriteAll()) return;
  838.     
  839.     lastfiles->writeFile(lyxrc->lastfiles);
  840.  
  841.     // Set a flag that we do quitting from the program,
  842.     // so no refreshes are necessary.
  843.     quitting = true;
  844.  
  845.     // close buffers first
  846.     bufferlist.closeAll();
  847.  
  848.     // do any other cleanup procedures now
  849.     lyxerr.debug("Deleting tmp dir " + system_tempdir);
  850.  
  851.     DestroyLyXTmpDir(system_tempdir);
  852.  
  853.     finished = true;
  854. }
  855.  
  856.  
  857. void AutoSave()
  858.     // should probably be moved into BufferList (Lgb)
  859.     // Perfect target for a thread...
  860. {
  861.     if (!current_view->getScreen() || !current_view->available())
  862.         return;
  863.     
  864.     if (current_view->currentBuffer()->isBakClean()
  865.         || current_view->currentBuffer()->isReadonly())
  866.         return;
  867.     
  868.     LString fname;
  869.     
  870.     minibuffer->Set(_("Autosaving current document..."));
  871.     
  872.     // create autosave filename
  873.     fname =    OnlyPath(current_view->currentBuffer()->getFileName());
  874.     fname += "#";
  875.     fname += OnlyFilename(current_view->currentBuffer()->getFileName());
  876.     fname += "#";
  877.     
  878.     // tmp_ret will be located (usually) in /tmp
  879.     // will that we a problem?
  880.     LString tmp_ret = tmpnam(NULL);
  881.  
  882.     pid_t pid = fork(); // If you want to debug the autosave
  883.     // you should set pid to -1, and comment out the
  884.     // fork.
  885.     if (pid == 0 || pid == -1) {
  886.         // pid = -1 signifies that lyx was unable
  887.         // to fork. But we will do the save
  888.         // anyway.
  889.         bool failed = false;
  890.         if (!tmp_ret.empty()) {
  891.             current_view->currentBuffer()->writeFile(tmp_ret, 1);
  892.             // assume successful write of tmp_ret
  893.             if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
  894.                 failed = true;
  895.                 // most likely couldn't move between filesystems
  896.                 // unless write of tmp_ret failed
  897.                 // so remove tmp file (if it exists)
  898.                 remove(tmp_ret.c_str());
  899.             }
  900.         } else {
  901.             failed = true;
  902.         }
  903.         
  904.         if (failed) {
  905.             // failed to write/rename tmp_ret so try writing direct
  906.             if (!current_view->currentBuffer()->writeFile(fname,
  907.                                       1)) {
  908.                 minibuffer->Set(_("Autosave Failed!"));
  909.             }
  910.         }
  911.         if (pid == 0){
  912.             _exit(0);
  913.         }
  914.     }
  915.     
  916.     current_view->currentBuffer()->markBakClean();
  917.     current_view->getOwner()->resetAutosaveTimer();
  918. }
  919.  
  920.  
  921. //
  922. // (c) CHT Software Service GmbH
  923. // Uwe C. Schroeder
  924. //
  925. // create new file with template
  926. // SERVERCMD !
  927. //
  928. Buffer * NewLyxFile(LString const & filename)
  929. {
  930.     // Split argument by :
  931.     LString tmpname = filename;
  932.     LString name;
  933.     tmpname.split(name, ':');
  934. #warning __EMX__ FIX ME!
  935. #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
  936.     if (name.length() == 1 && isalpha((unsigned char) name[0]) &&
  937.         (tmpname.prefixIs("/") || tmpname.prefixIs("\\"))) {
  938.         name += ':';
  939.         name += tmpname.token(':');
  940.         tmpname.split(':');
  941.     }
  942. #endif
  943.     lyxerr.print("Arg is " + filename);
  944.     lyxerr.print("Name is " + name);
  945.     lyxerr.print("Template is " + tmpname);
  946.  
  947.     // find a free buffer 
  948.     Buffer *tmpbuf = bufferlist.newFile(name,tmpname);
  949.     if (tmpbuf)
  950.         lastfiles->newFile(tmpbuf->getFileName());
  951.     return tmpbuf;
  952. }
  953.  
  954.  
  955. // Insert ascii file
  956. void InsertAsciiFile(bool asParagraph)
  957. {
  958.     LString fname;
  959.     LyXParagraph *tmppar;
  960.     LyXFileDlg fileDlg;
  961.  
  962.     if (!current_view->getScreen()) return;
  963.      
  964.     ProhibitInput();
  965.   
  966.     fname =    fileDlg.Select(_("File to Insert"), 
  967.                    current_view->getOwner()->currentBuffer()->filepath,
  968.                    "*");
  969.   
  970.     AllowInput();
  971.  
  972.     if (fname.empty()) return;
  973.  
  974.     FileInfo fi(fname);
  975.     FilePtr myfile(fname, FilePtr::read);
  976.  
  977.     if (!fi.exist() || !fi.readable() || !myfile()) {
  978.         WriteFSAlert(_("Error! Cannot open specified file:"),
  979.                  MakeDisplayPath(fname,50));
  980.         return;
  981.     }
  982.     
  983.     tmppar = new LyXParagraph();
  984.     tmppar->readSimpleWholeFile(myfile);
  985.     
  986.     // set the end of the string
  987.     tmppar->InsertChar(tmppar->last-1,'\0');
  988.       
  989.     // insert the string
  990.     current_view->getScreen()->HideCursor();
  991.       
  992.     // clear the selection
  993.     BeforeChange();
  994.     if (!asParagraph)
  995.         current_view->currentBuffer()->text->InsertStringA(tmppar->text);
  996.     else
  997.         current_view->currentBuffer()->text->InsertStringB(tmppar->text);
  998.     delete tmppar;
  999.     current_view->currentBuffer()->update(1);
  1000. }
  1001.  
  1002.  
  1003. void MenuShowTableOfContents()
  1004. {
  1005.     TocUpdateCB(NULL, 0);
  1006.     if (fd_form_toc->form_toc->visible) {
  1007.         fl_raise_form(fd_form_toc->form_toc);
  1008.     } else {
  1009.         fl_show_form(fd_form_toc->form_toc,
  1010.                  FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
  1011.                  _("Table Of Contents"));
  1012.     }
  1013. }
  1014.  
  1015.  
  1016. void MenuInsertLabel()
  1017. {
  1018.     ProhibitInput();
  1019.     LString label = fl_show_input(_("Enter new label to insert:"),"");
  1020.     label.strip();
  1021.     label.frontStrip();
  1022.     if (!label.empty()) {
  1023.         InsetLabel *new_inset = new InsetLabel;
  1024.         new_inset->setContents(label);
  1025.         current_view->currentBuffer()->insertInset(new_inset);
  1026.     }
  1027.     AllowInput();
  1028. }
  1029.  
  1030.  
  1031. void MenuInsertRef()
  1032. {
  1033.     RefUpdateCB(NULL, 0);
  1034.     if (fd_form_ref->form_ref->visible) {
  1035.         fl_raise_form(fd_form_ref->form_ref);
  1036.     } else {
  1037.         fl_show_form(fd_form_ref->form_ref,
  1038.                  FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
  1039.                  _("Insert Reference"));
  1040.     }
  1041. }
  1042.  
  1043.  
  1044. void MenuPasteSelection(char at)
  1045. {
  1046.     if (!current_view->getScreen())
  1047.         return;
  1048.  
  1049.     ascii_type = at;
  1050.   
  1051.     Atom data_prop = XInternAtom(fl_display, 
  1052.                      "LyX_Primary",
  1053.                      false);
  1054.     if (data_prop == None) 
  1055.         return;
  1056.     XConvertSelection(fl_display,
  1057.               XA_PRIMARY, XA_STRING, data_prop, 
  1058.               fd_form_main->form_main->window, 0);
  1059.     XFlush(fl_display);
  1060. }
  1061.  
  1062.  
  1063. void FootCB(FL_OBJECT*, long)
  1064. {
  1065.     if (!current_view->available()) return;
  1066.     
  1067.     minibuffer->Set(_("Inserting Footnote..."));
  1068.     current_view->getScreen()->HideCursor();
  1069.     current_view->currentBuffer()->update(-2);
  1070.     current_view->currentBuffer()->text
  1071.         ->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
  1072.     current_view->currentBuffer()->update(1);
  1073. }
  1074.  
  1075.  
  1076. void LayoutsCB(int sel, void *)
  1077. {
  1078.     LString tmp;
  1079.     tmp += sel;
  1080.     current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
  1081.                              tmp.c_str());
  1082. }
  1083.  
  1084.  
  1085. /*
  1086.  * SGML support:
  1087.  * (flag == -1) import SGML file
  1088.  * (flag == 0) make TeX output
  1089.  * (flag == 1) make dvi output
  1090.  */
  1091. int RunLinuxDoc(int flag, LString const & filename)
  1092. {
  1093.     LString name;
  1094.     LString s2;
  1095.     LString path;
  1096.     LString add_flags;
  1097.  
  1098.     int errorcode = 0;
  1099.  
  1100.     /* generate a path-less extension name */
  1101.     name = ChangeExtension (filename, ".sgml", true);
  1102.     path = OnlyPath (filename);
  1103.     if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
  1104.         path = current_view->currentBuffer()->tmppath;
  1105.     }
  1106.     //PathPush (path);
  1107.     Path p(path);
  1108.     
  1109.     if (flag != -1) {
  1110.         if (!current_view->available())
  1111.             return 0;
  1112.         current_view->currentBuffer()->makeLinuxDocFile(name,0);
  1113.         LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->currentBuffer()->params.papersize;
  1114.         switch (ps) {
  1115.         case PAPER_A4PAPER:  add_flags = "-p a4";     break;
  1116.         case PAPER_USLETTER: add_flags = "-p letter"; break;
  1117.         default: /* nothing to be done yet ;-) */     break; 
  1118.         }
  1119.     }
  1120.     
  1121.     ProhibitInput();
  1122.     
  1123.     Systemcalls one;
  1124.     switch (flag) {
  1125.     case -1: /* Import file */
  1126.         minibuffer->Set(_("Importing LinuxDoc SGML file `"), 
  1127.                 MakeDisplayPath(filename), "'...");
  1128.         s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' ' 
  1129.             + name;
  1130.         if (one.Startscript(Systemcalls::System, s2)) 
  1131.             errorcode = 1;
  1132.         break;
  1133.     case 0: /* TeX output asked */
  1134.         minibuffer->Set(_("Converting LinuxDoc SGML to TeX file..."));
  1135.         s2 = "sgml2latex " + add_flags + " -o tex "
  1136.             + lyxrc->sgml_extra_options + ' ' + name;
  1137.         if (one.Startscript(Systemcalls::System, s2)) 
  1138.             errorcode = 1;
  1139.         break;
  1140.     case 1: /* dvi output asked */
  1141.         minibuffer->Set(_("Converting LinuxDoc SGML to dvi file..."));
  1142.         s2 = "sgml2latex " + add_flags + " -o dvi "
  1143.             + lyxrc->sgml_extra_options + ' ' + name;
  1144.         if (one.Startscript(Systemcalls::System, s2)) {
  1145.             errorcode = 1;
  1146.         } else
  1147.             current_view->currentBuffer()->markDviClean();
  1148.         break;
  1149.     default: /* unknown output */
  1150.         break;
  1151.     }
  1152.     
  1153.     //PathPop();
  1154.     AllowInput();
  1155.     return errorcode;
  1156. }
  1157.  
  1158.  
  1159. void AllFloats(char flag, char figmar)
  1160. {
  1161.     if (!current_view->available())    return;
  1162.    
  1163.     LyXCursor cursor = current_view->currentBuffer()->text->cursor;
  1164.  
  1165.     if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
  1166.         && ((figmar 
  1167.          && cursor.par->footnotekind != LyXParagraph::FOOTNOTE 
  1168.          && cursor.par->footnotekind != LyXParagraph::MARGIN)
  1169.         || (!figmar
  1170.             && cursor.par->footnotekind != LyXParagraph::FIG 
  1171.             && cursor.par->footnotekind != LyXParagraph::TAB
  1172.              && cursor.par->footnotekind != LyXParagraph::WIDE_FIG 
  1173.              && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
  1174.             && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
  1175.         ToggleFloat();
  1176.     else
  1177.         BeforeChange();
  1178.  
  1179.     LyXCursor tmpcursor = cursor;
  1180.     cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
  1181.     cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
  1182.  
  1183.     LyXParagraph *par = current_view->currentBuffer()->paragraph;
  1184.     while (par) {
  1185.         if (flag) {
  1186.             if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
  1187.                 && ((figmar &&
  1188.                  par->footnotekind != LyXParagraph::FOOTNOTE 
  1189.                  &&
  1190.                  par->footnotekind !=  LyXParagraph::MARGIN)
  1191.                 || (!figmar &&
  1192.                     par->footnotekind != LyXParagraph::FIG 
  1193.                     &&
  1194.                     par->footnotekind != LyXParagraph::TAB
  1195.                     &&
  1196.                     par->footnotekind != LyXParagraph::WIDE_FIG 
  1197.                     &&
  1198.                     par->footnotekind != LyXParagraph::WIDE_TAB
  1199.                     &&
  1200.                     par->footnotekind != LyXParagraph::ALGORITHM
  1201.                     ))) {
  1202.                 if (par->previous
  1203.                     && par->previous->footnoteflag !=
  1204.                     LyXParagraph::CLOSED_FOOTNOTE){ /* should be */ 
  1205.                     current_view->currentBuffer()->text->SetCursorIntern(par->previous,
  1206.                                                  0);
  1207.                     current_view->currentBuffer()->text->OpenFootnote();
  1208.                 }
  1209.             }
  1210.         } else  {
  1211.             if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
  1212.                 && ((figmar 
  1213.                  &&
  1214.                  par->footnotekind != LyXParagraph::FOOTNOTE 
  1215.                  &&
  1216.                  par->footnotekind !=  LyXParagraph::MARGIN
  1217.                     )
  1218.                 ||
  1219.                 (!figmar
  1220.                  &&
  1221.                  par->footnotekind != LyXParagraph::FIG 
  1222.                  &&
  1223.                  par->footnotekind != LyXParagraph::TAB
  1224.                  &&
  1225.                  par->footnotekind != LyXParagraph::WIDE_FIG 
  1226.                  &&
  1227.                  par->footnotekind != LyXParagraph::WIDE_TAB
  1228.                  &&
  1229.                  par->footnotekind != LyXParagraph::ALGORITHM
  1230.                     )
  1231.                     )
  1232.                 ){
  1233.                 current_view->currentBuffer()->text->SetCursorIntern(par, 0);
  1234.                 current_view->currentBuffer()->text->CloseFootnote();
  1235.             }
  1236.         }
  1237.         par = par->next;
  1238.     }
  1239.     
  1240.     current_view->currentBuffer()->text->SetCursorIntern(cursor.par, cursor.pos);
  1241.     current_view->redraw();
  1242.     current_view->fitCursor();
  1243.     current_view->updateScrollbar();
  1244. }
  1245.  
  1246.  
  1247. void MenuLayoutCharacter()
  1248. {
  1249.     if (fd_form_character->form_character->visible) {
  1250.         fl_raise_form(fd_form_character->form_character);
  1251.     } else {
  1252.         fl_show_form(fd_form_character->form_character,
  1253.                  FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
  1254.                  _("Character Style"));
  1255.     }
  1256. }
  1257.  
  1258.  
  1259. inline void DeactivateParagraphButtons ()
  1260. {
  1261.     fl_deactivate_object (fd_form_paragraph->button_ok);
  1262.     fl_deactivate_object (fd_form_paragraph->button_apply);
  1263.     fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
  1264.     fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
  1265. }
  1266.  
  1267. inline void ActivateParagraphButtons ()
  1268. {
  1269.     fl_activate_object (fd_form_paragraph->button_ok);
  1270.     fl_activate_object (fd_form_paragraph->button_apply);
  1271.     fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
  1272.     fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
  1273. }
  1274.  
  1275. inline void DisableParagraphLayout ()
  1276. {
  1277.         DeactivateParagraphButtons();
  1278.     fl_deactivate_object (fd_form_paragraph->input_labelwidth);
  1279.     fl_deactivate_object (fd_form_paragraph->check_lines_top);
  1280.     fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
  1281.     fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
  1282.     fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
  1283.     fl_deactivate_object (fd_form_paragraph->check_noindent);
  1284.     fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
  1285.     fl_deactivate_object (fd_form_paragraph->radio_align_right);
  1286.     fl_deactivate_object (fd_form_paragraph->radio_align_left);
  1287.     fl_deactivate_object (fd_form_paragraph->radio_align_block);
  1288.     fl_deactivate_object (fd_form_paragraph->radio_align_center);
  1289.     fl_deactivate_object (fd_form_paragraph->input_space_above);
  1290.     fl_deactivate_object (fd_form_paragraph->input_space_below);
  1291.     fl_deactivate_object (fd_form_paragraph->choice_space_above);
  1292.     fl_deactivate_object (fd_form_paragraph->choice_space_below);
  1293.     fl_deactivate_object (fd_form_paragraph->check_space_above);
  1294.     fl_deactivate_object (fd_form_paragraph->check_space_below);
  1295. }
  1296.  
  1297. inline void EnableParagraphLayout ()
  1298. {
  1299.         ActivateParagraphButtons();
  1300.     fl_activate_object (fd_form_paragraph->input_labelwidth);
  1301.     fl_activate_object (fd_form_paragraph->check_lines_top);
  1302.     fl_activate_object (fd_form_paragraph->check_lines_bottom);
  1303.     fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
  1304.     fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
  1305.     fl_activate_object (fd_form_paragraph->check_noindent);
  1306.     fl_activate_object (fd_form_paragraph->group_radio_alignment);
  1307.     fl_activate_object (fd_form_paragraph->radio_align_right);
  1308.     fl_activate_object (fd_form_paragraph->radio_align_left);
  1309.     fl_activate_object (fd_form_paragraph->radio_align_block);
  1310.     fl_activate_object (fd_form_paragraph->radio_align_center);
  1311.     fl_activate_object (fd_form_paragraph->input_space_above);
  1312.     fl_activate_object (fd_form_paragraph->input_space_below);
  1313.     fl_activate_object (fd_form_paragraph->choice_space_above);
  1314.     fl_activate_object (fd_form_paragraph->choice_space_below);
  1315.     fl_activate_object (fd_form_paragraph->check_space_above);
  1316.     fl_activate_object (fd_form_paragraph->check_space_below);
  1317. }
  1318.  
  1319. bool UpdateLayoutParagraph()
  1320. {
  1321.     if (!current_view->getScreen() || !current_view->available()) {
  1322.         if (fd_form_paragraph->form_paragraph->visible) 
  1323.             fl_hide_form(fd_form_paragraph->form_paragraph);
  1324.         return false;
  1325.     }
  1326.  
  1327.     Buffer * buf = current_view->currentBuffer();
  1328.  
  1329.     fl_set_input(fd_form_paragraph->input_labelwidth,
  1330.              buf->text->cursor.par->GetLabelWidthString().c_str());
  1331.     fl_set_button(fd_form_paragraph->radio_align_right, 0);
  1332.     fl_set_button(fd_form_paragraph->radio_align_left, 0);
  1333.     fl_set_button(fd_form_paragraph->radio_align_center, 0);
  1334.     fl_set_button(fd_form_paragraph->radio_align_block, 0);
  1335.  
  1336.     int align = buf->text->cursor.par->GetAlign();
  1337.     if (align == LYX_ALIGN_LAYOUT)
  1338.         align =    lyxstyle.Style(buf->params.textclass,
  1339.                        buf->text->cursor.par->GetLayout())->align;
  1340.      
  1341.     switch (align) {
  1342.     case LYX_ALIGN_RIGHT:
  1343.         fl_set_button(fd_form_paragraph->radio_align_right, 1);
  1344.         break;
  1345.     case LYX_ALIGN_LEFT:
  1346.         fl_set_button(fd_form_paragraph->radio_align_left, 1);
  1347.         break;
  1348.     case LYX_ALIGN_CENTER:
  1349.         fl_set_button(fd_form_paragraph->radio_align_center, 1);
  1350.         break;
  1351.     default:
  1352.         fl_set_button(fd_form_paragraph->radio_align_block, 1);
  1353.         break;
  1354.     }
  1355.      
  1356.     fl_set_button(fd_form_paragraph->check_lines_top,
  1357.               buf->text->cursor.par->FirstPhysicalPar()->line_top);
  1358.     fl_set_button(fd_form_paragraph->check_lines_bottom,
  1359.               buf->text->cursor.par->FirstPhysicalPar()->line_bottom);
  1360.     fl_set_button(fd_form_paragraph->check_pagebreaks_top,
  1361.               buf->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
  1362.     fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
  1363.               buf->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
  1364.     fl_set_button(fd_form_paragraph->check_noindent,
  1365.               buf->text->cursor.par->FirstPhysicalPar()->noindent);
  1366.     fl_set_input (fd_form_paragraph->input_space_above, "");
  1367.     
  1368.     switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
  1369.     case VSpace::NONE:
  1370.         fl_set_choice (fd_form_paragraph->choice_space_above,
  1371.                    1);
  1372.         break;
  1373.     case VSpace::DEFSKIP:
  1374.         fl_set_choice (fd_form_paragraph->choice_space_above,
  1375.                    2);
  1376.         break;
  1377.     case VSpace::SMALLSKIP:
  1378.         fl_set_choice (fd_form_paragraph->choice_space_above,
  1379.                    3);
  1380.         break;
  1381.     case VSpace::MEDSKIP:
  1382.         fl_set_choice (fd_form_paragraph->choice_space_above,
  1383.                    4);
  1384.         break;
  1385.     case VSpace::BIGSKIP:
  1386.         fl_set_choice (fd_form_paragraph->choice_space_above,
  1387.                    5);
  1388.         break;
  1389.     case VSpace::VFILL:
  1390.         fl_set_choice (fd_form_paragraph->choice_space_above,
  1391.                    6);
  1392.         break;
  1393.     case VSpace::LENGTH:
  1394.         fl_set_choice (fd_form_paragraph->choice_space_above,
  1395.                    7); 
  1396.         fl_set_input  (fd_form_paragraph->input_space_above, 
  1397.                    buf->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
  1398.         break;
  1399.     }
  1400.     fl_set_button (fd_form_paragraph->check_space_above,
  1401.                buf->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
  1402.     fl_set_input (fd_form_paragraph->input_space_below, "");
  1403.     switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
  1404.     case VSpace::NONE:
  1405.         fl_set_choice (fd_form_paragraph->choice_space_below,
  1406.                    1);
  1407.         break;
  1408.     case VSpace::DEFSKIP:
  1409.         fl_set_choice (fd_form_paragraph->choice_space_below,
  1410.                    2);
  1411.         break;
  1412.     case VSpace::SMALLSKIP:
  1413.         fl_set_choice (fd_form_paragraph->choice_space_below,
  1414.                    3);
  1415.         break;
  1416.     case VSpace::MEDSKIP:
  1417.         fl_set_choice (fd_form_paragraph->choice_space_below,
  1418.                    4);
  1419.         break;
  1420.     case VSpace::BIGSKIP:
  1421.         fl_set_choice (fd_form_paragraph->choice_space_below,
  1422.                    5);
  1423.         break;
  1424.     case VSpace::VFILL:
  1425.         fl_set_choice (fd_form_paragraph->choice_space_below,
  1426.                    6);
  1427.         break;
  1428.     case VSpace::LENGTH:
  1429.         fl_set_choice (fd_form_paragraph->choice_space_below,
  1430.                    7); 
  1431.         fl_set_input  (fd_form_paragraph->input_space_below, 
  1432.                    buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
  1433.         break;
  1434.     }
  1435.     fl_set_button (fd_form_paragraph->check_space_below,
  1436.                buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
  1437.  
  1438.     fl_set_button(fd_form_paragraph->check_noindent,
  1439.               buf->text->cursor.par->FirstPhysicalPar()->noindent);
  1440.     return true;
  1441. }
  1442.  
  1443.  
  1444. void MenuLayoutParagraph()
  1445. {
  1446.     if (UpdateLayoutParagraph()) {
  1447.         if (current_view->currentBuffer()->isReadonly()) {
  1448.           DisableParagraphLayout();
  1449.           WriteAlert(_("Any changes will be ignored"),
  1450.                  _("The document is read-only:"),
  1451.                  current_view->currentBuffer()->getFileName());
  1452.         } else
  1453.             EnableParagraphLayout();
  1454.       
  1455.         if (fd_form_paragraph->form_paragraph->visible) {
  1456.             fl_raise_form(fd_form_paragraph->form_paragraph);
  1457.         } else {
  1458.             fl_show_form(fd_form_paragraph->form_paragraph,
  1459.                      FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
  1460.                      _("Paragraph Environment"));
  1461.         }
  1462.     }
  1463. }
  1464.  
  1465.  
  1466. inline
  1467. void DeactivateDocumentButtons ()
  1468. {
  1469.     fl_deactivate_object (fd_form_document->button_ok);
  1470.     fl_deactivate_object (fd_form_document->button_apply);
  1471.     fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
  1472.     fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
  1473. }
  1474.  
  1475.  
  1476. inline
  1477. void ActivateDocumentButtons ()
  1478. {
  1479.     fl_activate_object (fd_form_document->button_ok);
  1480.     fl_activate_object (fd_form_document->button_apply);
  1481.     fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
  1482.     fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
  1483. }
  1484.  
  1485.  
  1486. inline
  1487. void DisableDocumentLayout ()
  1488. {
  1489.         DeactivateDocumentButtons ();
  1490.     fl_deactivate_object (fd_form_document->group_radio_separation);
  1491.     fl_deactivate_object (fd_form_document->radio_indent);
  1492.     fl_deactivate_object (fd_form_document->radio_skip);
  1493.     fl_deactivate_object (fd_form_document->choice_class);
  1494.     fl_deactivate_object (fd_form_document->choice_pagestyle);
  1495.     fl_deactivate_object (fd_form_document->choice_fonts);
  1496.     fl_deactivate_object (fd_form_document->choice_fontsize);
  1497.     fl_deactivate_object (fd_form_document->input_float_placement);
  1498.     fl_deactivate_object (fd_form_document->choice_postscript_driver);
  1499.     fl_deactivate_object (fd_form_document->choice_inputenc);
  1500.     fl_deactivate_object (fd_form_document->group_radio_sides);
  1501.     fl_deactivate_object (fd_form_document->radio_sides_one);
  1502.     fl_deactivate_object (fd_form_document->radio_sides_two);
  1503.     fl_deactivate_object (fd_form_document->group_radio_columns);
  1504.     fl_deactivate_object (fd_form_document->radio_columns_one);
  1505.     fl_deactivate_object (fd_form_document->radio_columns_two);
  1506.     fl_deactivate_object (fd_form_document->input_extra);
  1507.     fl_deactivate_object (fd_form_document->choice_language);
  1508.     combo_language->deactivate();
  1509.     fl_deactivate_object (fd_form_document->input_default_skip);
  1510.     fl_deactivate_object (fd_form_document->choice_default_skip);
  1511.     fl_deactivate_object (fd_form_document->slider_secnumdepth);
  1512.     fl_deactivate_object (fd_form_document->slider_tocdepth);
  1513.     fl_deactivate_object (fd_form_document->choice_spacing);
  1514.     fl_deactivate_object (fd_form_document->check_use_amsmath);
  1515. }
  1516.  
  1517.  
  1518. inline
  1519. void EnableDocumentLayout ()
  1520. {
  1521.         ActivateDocumentButtons ();
  1522.     fl_activate_object (fd_form_document->group_radio_separation);
  1523.     fl_activate_object (fd_form_document->radio_indent);
  1524.     fl_activate_object (fd_form_document->radio_skip);
  1525.     fl_activate_object (fd_form_document->choice_class);
  1526.     fl_activate_object (fd_form_document->choice_pagestyle);
  1527.     fl_activate_object (fd_form_document->choice_fonts);
  1528.     fl_activate_object (fd_form_document->choice_fontsize);
  1529.     fl_activate_object (fd_form_document->input_float_placement);
  1530.     fl_activate_object (fd_form_document->choice_postscript_driver);
  1531.     fl_activate_object (fd_form_document->choice_inputenc);
  1532.     fl_activate_object (fd_form_document->group_radio_sides);
  1533.     fl_activate_object (fd_form_document->radio_sides_one);
  1534.     fl_activate_object (fd_form_document->radio_sides_two);
  1535.     fl_activate_object (fd_form_document->group_radio_columns);
  1536.     fl_activate_object (fd_form_document->radio_columns_one);
  1537.     fl_activate_object (fd_form_document->radio_columns_two);
  1538.     fl_activate_object (fd_form_document->input_extra);
  1539.     fl_activate_object (fd_form_document->choice_language);
  1540.     combo_language->activate();
  1541.     fl_activate_object (fd_form_document->input_default_skip);
  1542.     fl_activate_object (fd_form_document->choice_default_skip);
  1543.     fl_activate_object (fd_form_document->slider_secnumdepth);
  1544.     fl_activate_object (fd_form_document->slider_tocdepth);
  1545.     fl_activate_object (fd_form_document->choice_spacing);
  1546.     fl_activate_object (fd_form_document->check_use_amsmath);
  1547. }
  1548.  
  1549.  
  1550. bool UpdateLayoutDocument(BufferParams *params)
  1551. {
  1552.     if (!current_view->getScreen() || !current_view->available()) {
  1553.         if (fd_form_document->form_document->visible) 
  1554.             fl_hide_form(fd_form_document->form_document);
  1555.         return false;
  1556.     }               
  1557.     
  1558.     if (params == NULL)
  1559.         params = ¤t_view->currentBuffer()->params;
  1560.     LyXTextClass *tclass = lyxstyle.TextClass(params->textclass);
  1561.     
  1562.     EnableDocumentLayout();
  1563.     
  1564.     fl_set_choice_text(fd_form_document->choice_class, 
  1565.                lyxstyle.DescOfClass(params->textclass).c_str());
  1566.     
  1567.     combo_language->select_text(params->language.c_str());
  1568.     
  1569.     fl_set_choice_text(fd_form_document->choice_fonts, 
  1570.                params->fonts.c_str());
  1571.     fl_set_choice_text(fd_form_document->choice_inputenc, 
  1572.                params->inputenc.c_str());
  1573.     fl_set_choice_text(fd_form_document->choice_postscript_driver, 
  1574.                params->graphicsDriver.c_str());
  1575.     
  1576.     // ale970405+lasgoutt970513
  1577.     fl_clear_choice(fd_form_document->choice_fontsize);
  1578.     fl_addto_choice(fd_form_document->choice_fontsize, "default");
  1579.     fl_addto_choice(fd_form_document->choice_fontsize, 
  1580.             tclass->opt_fontsize.c_str());
  1581.     fl_set_choice(fd_form_document->choice_fontsize, 
  1582.               tclass->opt_fontsize.tokenPos('|',
  1583.                             params->fontsize) + 2);
  1584.     
  1585.     // ale970405+lasgoutt970513
  1586.     fl_clear_choice(fd_form_document->choice_pagestyle);
  1587.     fl_addto_choice(fd_form_document->choice_pagestyle, "default");
  1588.     fl_addto_choice(fd_form_document->choice_pagestyle, 
  1589.             tclass->opt_pagestyle.c_str());
  1590.     
  1591.     fl_set_choice(fd_form_document->choice_pagestyle,
  1592.               tclass->opt_pagestyle.tokenPos('|',
  1593.                              params->pagestyle) + 2);
  1594.     
  1595.     fl_set_button(fd_form_document->radio_indent, 0);
  1596.     fl_set_button(fd_form_document->radio_skip, 0);
  1597.     
  1598.     
  1599.     fl_set_button(fd_form_document->check_use_amsmath,
  1600.               params->use_amsmath);
  1601.     
  1602.     if (params->paragraph_separation == LYX_PARSEP_INDENT)
  1603.         fl_set_button(fd_form_document->radio_indent, 1);
  1604.     else
  1605.         fl_set_button(fd_form_document->radio_skip, 1);
  1606.     
  1607.     switch (params->getDefSkip().kind()) {
  1608.     case VSpace::SMALLSKIP: 
  1609.         fl_set_choice (fd_form_document->choice_default_skip, 1);
  1610.         break;
  1611.     case VSpace::MEDSKIP: 
  1612.         fl_set_choice (fd_form_document->choice_default_skip, 2);
  1613.         break;
  1614.     case VSpace::BIGSKIP: 
  1615.         fl_set_choice (fd_form_document->choice_default_skip, 3);
  1616.         break;
  1617.     case VSpace::LENGTH: 
  1618.         fl_set_choice (fd_form_document->choice_default_skip, 4);
  1619.         fl_set_input (fd_form_document->input_default_skip,
  1620.                   params->getDefSkip().asLyXCommand().c_str());
  1621.         break;
  1622.     default:
  1623.         fl_set_choice (fd_form_document->choice_default_skip, 2);
  1624.         break;
  1625.     }
  1626.     
  1627.     fl_set_button(fd_form_document->radio_sides_one, 0);
  1628.     fl_set_button(fd_form_document->radio_sides_two, 0);
  1629.      
  1630.     if (params->sides == 2)
  1631.         fl_set_button(fd_form_document->radio_sides_two, 1);
  1632.     else
  1633.         fl_set_button(fd_form_document->radio_sides_one, 1);
  1634.     
  1635.     fl_set_button(fd_form_document->radio_columns_one, 0);
  1636.     fl_set_button(fd_form_document->radio_columns_two, 0);
  1637.     
  1638.     if (params->columns == 2)
  1639.         fl_set_button(fd_form_document->radio_columns_two, 1);
  1640.     else
  1641.         fl_set_button(fd_form_document->radio_columns_one, 1);
  1642.     
  1643.     switch (params->spacing.getSpace()) {
  1644.     case Spacing::Single:
  1645.     {
  1646.         // \singlespacing
  1647.         fl_set_choice(fd_form_document->choice_spacing, 1);
  1648.         break;
  1649.     }
  1650.     case Spacing::Onehalf:
  1651.     {
  1652.         // \onehalfspacing
  1653.         fl_set_choice(fd_form_document->choice_spacing, 2);
  1654.         break;
  1655.     }
  1656.     case Spacing::Double:
  1657.     {
  1658.         // \doublespacing
  1659.         fl_set_choice(fd_form_document->choice_spacing, 3);
  1660.         break;
  1661.     }
  1662.     case Spacing::Other:
  1663.     {
  1664.         // This might be used some day. However so far there
  1665.         // is only partially support for this. However it is
  1666.         // easy to make it work:ájust add a stretch object in
  1667.         // the document form for the user to set to a value
  1668.         // if LYX_SPACING_OTHER is in use.
  1669.         fl_set_choice(fd_form_document->choice_spacing, 4);
  1670.         break;
  1671.     }
  1672.     }
  1673.         
  1674.     fl_set_counter_value(fd_form_document->slider_secnumdepth, 
  1675.                  params->secnumdepth);
  1676.     fl_set_counter_value(fd_form_document->slider_tocdepth, 
  1677.                  params->tocdepth);
  1678.     if (!params->float_placement.empty()) { // buffer local (Lgb)
  1679.         fl_set_input(fd_form_document->input_float_placement,
  1680.                  params->float_placement.c_str());
  1681.     } else {
  1682.         fl_set_input(fd_form_document->input_float_placement,
  1683.                  LString("").c_str());
  1684.     }
  1685.     if (!params->options.empty())
  1686.         fl_set_input(fd_form_document->input_extra,
  1687.                  params->options.c_str());
  1688.     else
  1689.         fl_set_input(fd_form_document->input_extra,
  1690.                  LString("").c_str());
  1691.     
  1692.     if (current_view->currentBuffer()->isLinuxDoc()) {
  1693.         // bullets not used in LinuxDoc
  1694.         fl_deactivate_object(fd_form_document->button_bullets);
  1695.         fl_set_object_lcol(fd_form_document->button_bullets,
  1696.                    FL_INACTIVE);
  1697.     } else {
  1698.         fl_activate_object(fd_form_document->button_bullets);
  1699.         fl_set_object_lcol(fd_form_document->button_bullets,
  1700.                    FL_BLACK);
  1701.     }
  1702.     return true; 
  1703. }
  1704.  
  1705.  
  1706. void MenuLayoutDocument()
  1707. {
  1708.     if (UpdateLayoutDocument()) {
  1709.         if (current_view->currentBuffer()->isReadonly()) {
  1710.           DisableDocumentLayout();
  1711.           WriteAlert(_("Any changes will be ignored"),
  1712.                  _("The document is read-only:"),
  1713.                  current_view->currentBuffer()->getFileName());
  1714.         }
  1715.       
  1716.         if (fd_form_document->form_document->visible) {
  1717.             fl_raise_form(fd_form_document->form_document);
  1718.         } else {
  1719.             fl_show_form(fd_form_document->form_document,
  1720.                      FL_PLACE_MOUSE | FL_FREE_SIZE,
  1721.                      FL_FULLBORDER,
  1722.                      _("Document Layout"));
  1723.         }
  1724.     }
  1725. }
  1726.  
  1727.  
  1728. bool UpdateLayoutQuotes()
  1729. {
  1730.     bool update = true;
  1731.     if (!current_view->getScreen() || !current_view->available())
  1732.         update = false;
  1733.  
  1734.     if (update) {
  1735.         fl_set_choice(fd_form_quotes->choice_quotes_language,
  1736.               current_view->currentBuffer()->params.quotes_language + 1);
  1737.         fl_set_button(fd_form_quotes->radio_single, 0);
  1738.         fl_set_button(fd_form_quotes->radio_double, 0);
  1739.     
  1740.         if (current_view->currentBuffer()->params.quotes_times == InsetQuotes::SingleQ)
  1741.             fl_set_button(fd_form_quotes->radio_single, 1);
  1742.         else
  1743.             fl_set_button(fd_form_quotes->radio_double, 1);
  1744.     } else if (fd_form_quotes->form_quotes->visible) {
  1745.         fl_hide_form(fd_form_quotes->form_quotes);
  1746.     }
  1747.     return update;
  1748. }
  1749.  
  1750.  
  1751. void MenuLayoutQuotes()
  1752. {
  1753.     if (UpdateLayoutQuotes()) {
  1754.         if (fd_form_quotes->form_quotes->visible) {
  1755.             fl_raise_form(fd_form_quotes->form_quotes);
  1756.         } else {
  1757.             fl_show_form(fd_form_quotes->form_quotes,
  1758.                      FL_PLACE_MOUSE | FL_FREE_SIZE,
  1759.                      FL_FULLBORDER,
  1760.                      _("Quotes"));
  1761.         }
  1762.     }
  1763. }
  1764.  
  1765.  
  1766. bool UpdateLayoutPreamble()
  1767. {
  1768.     bool update = true;
  1769.     if (!current_view->getScreen() || ! current_view->available())
  1770.         update = false;
  1771.  
  1772.     if (update) {
  1773.         fl_set_input(fd_form_preamble->input_preamble,
  1774.              current_view->currentBuffer()->params.preamble.c_str());
  1775.  
  1776.         if (current_view->currentBuffer()->isReadonly()) {
  1777.           fl_deactivate_object(fd_form_preamble->input_preamble);
  1778.           fl_deactivate_object(fd_form_preamble->button_ok);
  1779.           fl_deactivate_object(fd_form_preamble->button_apply);
  1780.           fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
  1781.           fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
  1782.         }
  1783.         else {
  1784.           fl_activate_object(fd_form_preamble->input_preamble);
  1785.           fl_activate_object(fd_form_preamble->button_ok);
  1786.           fl_activate_object(fd_form_preamble->button_apply);
  1787.           fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
  1788.           fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
  1789.         }
  1790.     } else if (fd_form_preamble->form_preamble->visible) {
  1791.         fl_hide_form(fd_form_preamble->form_preamble);
  1792.     }
  1793.     return update;
  1794. }
  1795.  
  1796.  
  1797. void MenuLayoutPreamble()
  1798. {
  1799.     if (UpdateLayoutPreamble()) {
  1800.         if (fd_form_preamble->form_preamble->visible) {
  1801.             fl_raise_form(fd_form_preamble->form_preamble);
  1802.         } else {
  1803.             fl_show_form(fd_form_preamble->form_preamble,
  1804.                      FL_PLACE_MOUSE | FL_FREE_SIZE,
  1805.                      FL_FULLBORDER,
  1806.                      _("LaTeX Preamble"));
  1807.         }
  1808.     }
  1809. }
  1810.  
  1811.  
  1812. void MenuLayoutSave()
  1813. {
  1814.     if (!current_view->getScreen() || ! current_view->available())
  1815.         return;
  1816.  
  1817.     if (AskQuestion(_("Do you want to save the current settings"),
  1818.             _("for Character, Document, Paper and Quotes"),
  1819.             _("as default for new documents?")))
  1820.         current_view->currentBuffer()->saveParamsAsDefaults();
  1821. }
  1822.  
  1823. /* callbacks added for LinuxDoc support (Pascal AndrΘ) : 
  1824.  *   - marks and cross references TeX macros
  1825.  *   - url display macros
  1826.  *   - htmlurl macros
  1827.  */
  1828.  
  1829. /* inserts an url skeleton */
  1830. void UrlCB()
  1831. {
  1832. #warning do it right!
  1833. }
  1834.  
  1835.  
  1836. /* inserts an html url skeleton */ 
  1837. void HtmlUrlCB()
  1838. {
  1839. #warning do it right!
  1840. }
  1841.  
  1842. /* end of LinuxDoc SGML special CB */
  1843.  
  1844. void NoteCB()
  1845. {
  1846.     LString string;
  1847.     LString userName(getUserName());
  1848.     string = userName + ' ' + date();
  1849.     InsetInfo *new_inset = new InsetInfo(string);
  1850.     current_view->currentBuffer()->insertInset(new_inset);
  1851. }
  1852.  
  1853.  
  1854. void OpenStuff()
  1855. {
  1856.     if (current_view->available()) {
  1857.         minibuffer->Set(_("Open/Close..."));
  1858.         current_view->getScreen()->HideCursor();
  1859.         BeforeChange();
  1860.         current_view->currentBuffer()->update(-2);
  1861.         current_view->currentBuffer()->text->OpenStuff();
  1862.         current_view->currentBuffer()->update(0);
  1863.     }
  1864. }
  1865.  
  1866. void ToggleFloat()
  1867. {
  1868.     if (current_view->available()) {
  1869.         minibuffer->Set(_("Open/Close..."));
  1870.         current_view->getScreen()->HideCursor();
  1871.         BeforeChange();
  1872.         current_view->currentBuffer()->update(-2);
  1873.         current_view->currentBuffer()->text->ToggleFootnote();
  1874.         current_view->currentBuffer()->update(0);
  1875.     }
  1876. }
  1877.  
  1878.  
  1879. void MenuUndo()
  1880. {
  1881.     if (current_view->available()) {
  1882.         minibuffer->Set(_("Undo"));
  1883.         current_view->getScreen()->HideCursor();
  1884.         BeforeChange();
  1885.         current_view->currentBuffer()->update(-2);
  1886.         if (!current_view->currentBuffer()->text->TextUndo())
  1887.             minibuffer->Set(_("No further undo information"));
  1888.         else
  1889.             current_view->currentBuffer()->update(-1);
  1890.     }
  1891. }
  1892.  
  1893.  
  1894. void MenuRedo()
  1895. {
  1896.     if (current_view->currentBuffer()->the_locking_inset) {
  1897.         minibuffer->Set(_("Redo not yet supported in math mode"));
  1898.         return;
  1899.     }    
  1900.    
  1901.     if (current_view->available()) {
  1902.         minibuffer->Set(_("Redo"));
  1903.         current_view->getScreen()->HideCursor();
  1904.         BeforeChange();
  1905.         current_view->currentBuffer()->update(-2);
  1906.         if (!current_view->currentBuffer()->text->TextRedo())
  1907.             minibuffer->Set(_("No further redo information"));
  1908.         else
  1909.             current_view->currentBuffer()->update(-1);
  1910.     }
  1911. }
  1912.  
  1913.  
  1914. void HyphenationPoint()
  1915. {
  1916.     if (current_view->available())  {
  1917.         current_view->getScreen()->HideCursor();
  1918.         current_view->currentBuffer()->update(-2);
  1919.         InsetSpecialChar *new_inset = 
  1920.             new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
  1921.         current_view->currentBuffer()->insertInset(new_inset);
  1922.     }
  1923. }
  1924.  
  1925.  
  1926. void Ldots()
  1927. {
  1928.     if (current_view->available())  {
  1929.         current_view->getScreen()->HideCursor();
  1930.         current_view->currentBuffer()->update(-2);
  1931.         InsetSpecialChar *new_inset = 
  1932.             new InsetSpecialChar(InsetSpecialChar::LDOTS);
  1933.         current_view->currentBuffer()->insertInset(new_inset);
  1934.     }
  1935. }
  1936.  
  1937.  
  1938. void EndOfSentenceDot()
  1939. {
  1940.     if (current_view->available())  {
  1941.         current_view->getScreen()->HideCursor();
  1942.         current_view->currentBuffer()->update(-2);
  1943.         InsetSpecialChar *new_inset = 
  1944.             new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
  1945.         current_view->currentBuffer()->insertInset(new_inset);
  1946.     }
  1947. }
  1948.  
  1949.  
  1950. void Newline()
  1951. {
  1952.     if (current_view->available())  {
  1953.         current_view->getScreen()->HideCursor();
  1954.         current_view->currentBuffer()->update(-2);
  1955.         current_view->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
  1956.         current_view->currentBuffer()->update(-1);
  1957.     }
  1958. }
  1959.  
  1960.  
  1961. void ProtectedBlank()
  1962. {
  1963.     if (current_view->available())  {
  1964.         current_view->getScreen()->HideCursor();
  1965.         current_view->currentBuffer()->update(-2);
  1966.         current_view->currentBuffer()->text->InsertChar(LYX_META_PROTECTED_SEPARATOR);
  1967.         current_view->currentBuffer()->update(-1);
  1968.     }
  1969. }
  1970.  
  1971.  
  1972. void HFill()
  1973. {
  1974.     if (current_view->available())  {
  1975.         current_view->getScreen()->HideCursor();
  1976.         current_view->currentBuffer()->update(-2);
  1977.         current_view->currentBuffer()->text->InsertChar(LYX_META_HFILL);
  1978.         current_view->currentBuffer()->update(-1);
  1979.     }
  1980. }
  1981.  
  1982.  
  1983. /* -------> These CB's use ToggleFree() as the (one and only?) font-changer. 
  1984.             They also show the current font state. */
  1985.  
  1986. static
  1987. void ToggleAndShow(LyXFont const &);
  1988.  
  1989.  
  1990. void FontSizeCB(LString const & size)
  1991. {
  1992.     LyXFont font(LyXFont::ALL_IGNORE);
  1993.     font.setGUISize(size);
  1994.     ToggleAndShow( font);
  1995. }
  1996.  
  1997.  
  1998. void EmphCB()
  1999. {
  2000.     LyXFont font(LyXFont::ALL_IGNORE);
  2001.     font.setEmph(LyXFont::TOGGLE);
  2002.     ToggleAndShow(font);
  2003. }
  2004.  
  2005.  
  2006. void NounCB()
  2007. {
  2008.     LyXFont font(LyXFont::ALL_IGNORE);
  2009.     font.setNoun(LyXFont::TOGGLE);
  2010.     ToggleAndShow( font);
  2011. }
  2012.  
  2013.  
  2014. void BoldCB()
  2015. {
  2016.     LyXFont font(LyXFont::ALL_IGNORE);
  2017.     font.setSeries(LyXFont::BOLD_SERIES);
  2018.     ToggleAndShow( font);
  2019. }
  2020.  
  2021.  
  2022. void UnderlineCB()
  2023. {
  2024.     LyXFont font(LyXFont::ALL_IGNORE);
  2025.     font.setUnderbar(LyXFont::TOGGLE);
  2026.     ToggleAndShow( font);
  2027. }
  2028.  
  2029.  
  2030. void CodeCB()
  2031. {
  2032.     LyXFont font(LyXFont::ALL_IGNORE);
  2033.     font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
  2034.     ToggleAndShow( font);
  2035. }
  2036.  
  2037.  
  2038. void SansCB()
  2039. {
  2040.     LyXFont font(LyXFont::ALL_IGNORE);
  2041.     font.setFamily(LyXFont::SANS_FAMILY);
  2042.     ToggleAndShow( font);
  2043. }
  2044.  
  2045.  
  2046. void RomanCB()
  2047. {
  2048.     LyXFont font(LyXFont::ALL_IGNORE);
  2049.     font.setFamily(LyXFont::ROMAN_FAMILY);
  2050.     ToggleAndShow( font);
  2051. }
  2052.  
  2053.  
  2054. void TexCB()
  2055. {
  2056.     LyXFont font(LyXFont::ALL_IGNORE);
  2057.     font.setLatex (LyXFont::TOGGLE);
  2058.     ToggleAndShow( font);
  2059. }
  2060.  
  2061.  
  2062. void StyleResetCB()
  2063. {
  2064.     LyXFont font(LyXFont::ALL_INHERIT);
  2065.     ToggleAndShow( font);
  2066. }
  2067.  
  2068.  
  2069. /* -------> Returns the current font and depth by printing a message. In the
  2070.  * future perhaps we could try to implement a callback to the button-bar.
  2071.  * That is, `light' the bold button when the font is currently bold, etc.
  2072.  */
  2073. LString CurrentState()
  2074. {
  2075.     LString state;
  2076.     if (current_view->available()) { 
  2077.         // I think we should only show changes from the default
  2078.         // font. (Asger)
  2079.         Buffer * buffer = current_view->currentBuffer();
  2080.         LyXFont font = buffer->text->real_current_font;
  2081.         LyXFont defaultfont = lyxstyle.TextClass(buffer->
  2082.                              params.textclass)->defaultfont;
  2083.         font.reduce(defaultfont);
  2084.         state = _("Font: ") + font.stateText();
  2085.  
  2086.         int depth = buffer->text->GetDepth();
  2087.         if (depth>0) 
  2088.             state += LString(_(", Depth: ")) + depth;
  2089.     }
  2090.     return state;
  2091. }
  2092.  
  2093.  
  2094. /* -------> Does the actual toggle job of the XxxCB() calls above.
  2095.  * Also shows the current font state.
  2096.  */
  2097. static
  2098. void ToggleAndShow(LyXFont const & font)
  2099. {
  2100.     if (current_view->available()) { 
  2101.         current_view->getScreen()->HideCursor();
  2102.         current_view->currentBuffer()->update(-2);
  2103.          current_view->currentBuffer()->text->ToggleFree(font);
  2104.         current_view->currentBuffer()->update(1);
  2105.     }
  2106. }
  2107.  
  2108.  
  2109. void MarginCB(FL_OBJECT *, long)
  2110. {
  2111.     if (current_view->available()) {
  2112.         minibuffer->Set(_("Inserting margin note..."));
  2113.         current_view->getScreen()->HideCursor();
  2114.         current_view->currentBuffer()->update(-2);
  2115.         current_view->currentBuffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
  2116.         current_view->currentBuffer()->update(1);
  2117.     }
  2118. }
  2119.  
  2120.  
  2121. void FigureCB(FL_OBJECT *, long)
  2122. {
  2123.     if (fd_form_figure->form_figure->visible) {
  2124.         fl_raise_form(fd_form_figure->form_figure);
  2125.     } else {
  2126.         fl_show_form(fd_form_figure->form_figure,
  2127.                  FL_PLACE_MOUSE, FL_FULLBORDER,
  2128.                  _("Insert Figure"));
  2129.     }
  2130. }
  2131.  
  2132.  
  2133. void TableCB(FL_OBJECT *, long)
  2134. {
  2135.     if (fd_form_table->form_table->visible) {
  2136.         fl_raise_form(fd_form_table->form_table);
  2137.     } else {
  2138.         fl_show_form(fd_form_table->form_table,
  2139.                  FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
  2140.                  _("Insert Table"));
  2141.     }
  2142. }
  2143.  
  2144.  
  2145. void CopyEnvironmentCB()
  2146. {
  2147.     if (current_view->available()) {
  2148.         current_view->currentBuffer()->text->copyEnvironmentType();
  2149.         /* clear the selection, even if mark_set */ 
  2150.         current_view->getScreen()->ToggleSelection();
  2151.         current_view->currentBuffer()->text->ClearSelection();
  2152.         current_view->currentBuffer()->update(-2);
  2153.         minibuffer->Set(_("Paragraph environment type copied"));
  2154.     }
  2155. }
  2156.  
  2157.  
  2158. void PasteEnvironmentCB()
  2159. {
  2160.     if (current_view->available()) {
  2161.         current_view->currentBuffer()->text->pasteEnvironmentType();
  2162.         minibuffer->Set(_("Paragraph environment type set"));
  2163.         current_view->currentBuffer()->update(1);
  2164.     }
  2165. }
  2166.  
  2167.  
  2168. void CopyCB()
  2169. {
  2170.     if (current_view->available()) {
  2171.         current_view->currentBuffer()->text->CopySelection();
  2172.         /* clear the selection, even if mark_set */ 
  2173.         current_view->getScreen()->ToggleSelection();
  2174.         current_view->currentBuffer()->text->ClearSelection();
  2175.         current_view->currentBuffer()->update(-2);
  2176.         minibuffer->Set(_("Copy"));
  2177.     }
  2178. }
  2179.  
  2180.  
  2181. void CutCB()
  2182. {
  2183.     if (current_view->available()) {
  2184.         current_view->getScreen()->HideCursor();
  2185.         current_view->currentBuffer()->update(-2);
  2186.         current_view->currentBuffer()->text->CutSelection();
  2187.         current_view->currentBuffer()->update(1);
  2188.         minibuffer->Set(_("Cut"));
  2189.     }
  2190. }
  2191.  
  2192.  
  2193. void PasteCB()
  2194. {
  2195.     if (!current_view->available()) return;
  2196.     
  2197.     minibuffer->Set(_("Paste"));
  2198.     current_view->getScreen()->HideCursor();
  2199.     /* clear the selection */ 
  2200.     current_view->getScreen()->ToggleSelection();
  2201.     current_view->currentBuffer()->text->ClearSelection();
  2202.     current_view->currentBuffer()->update(-2);
  2203.     
  2204.     /* paste */ 
  2205.     current_view->currentBuffer()->text->PasteSelection();
  2206.     current_view->currentBuffer()->update(1);
  2207.     
  2208.     /* clear the selection */ 
  2209.     current_view->getScreen()->ToggleSelection();
  2210.     current_view->currentBuffer()->text->ClearSelection();
  2211.     current_view->currentBuffer()->update(-2);
  2212. }
  2213.  
  2214.  
  2215. void MeltCB(FL_OBJECT *, long)
  2216. {
  2217.     if (!current_view->available()) return;
  2218.     
  2219.     minibuffer->Set(_("Melt"));
  2220.     current_view->getScreen()->HideCursor();
  2221.     BeforeChange();
  2222.     current_view->currentBuffer()->update(-2);
  2223.     current_view->currentBuffer()->text->MeltFootnoteEnvironment();
  2224.     current_view->currentBuffer()->update(1);
  2225. }
  2226.  
  2227.  
  2228. // Change environment depth.
  2229. // if decInc == 0, depth change taking mouse button number into account
  2230. // if decInc == 1, increment depth
  2231. // if decInc == -1, decrement depth
  2232. void DepthCB(FL_OBJECT *ob, long decInc)
  2233. {
  2234.     int button = 1;
  2235.  
  2236.     /* When decInc != 0, fake a mouse button. This allows us to
  2237.        implement depth-plus and depth-min commands. RVDK_PATCH_5. */
  2238.     /* check out wether ob is defined, too (Matthias) */ 
  2239.     if ( decInc < 0 )
  2240.         button = 0;
  2241.     else if (!decInc && ob) {
  2242.         button = fl_get_button_numb(ob);
  2243.     }
  2244.   
  2245.     if (current_view->available()) {
  2246.         current_view->getScreen()->HideCursor();
  2247.         current_view->currentBuffer()->update(-2);
  2248.         if (button == 1)
  2249.             current_view->currentBuffer()->text->IncDepth();
  2250.         else
  2251.             current_view->currentBuffer()->text->DecDepth();
  2252.         current_view->currentBuffer()->update(1);
  2253.         minibuffer->Set(_("Changed environment depth"
  2254.                   " (in possible range, maybe not)"));
  2255.     }
  2256. }
  2257.  
  2258.  
  2259. // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
  2260. // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
  2261. LyXFont UserFreeFont()
  2262. {
  2263.     LyXFont font(LyXFont::ALL_IGNORE);
  2264.     int pos;
  2265.  
  2266.     pos = fl_get_choice(fd_form_character->choice_family);
  2267.     switch(pos) {
  2268.     case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
  2269.     case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
  2270.     case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
  2271.     case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
  2272.     case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
  2273.     }
  2274.  
  2275.     pos = fl_get_choice(fd_form_character->choice_series);
  2276.     switch(pos) {
  2277.     case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
  2278.     case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
  2279.     case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
  2280.     case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
  2281.     }
  2282.  
  2283.     pos = fl_get_choice(fd_form_character->choice_shape);
  2284.     switch(pos) {
  2285.     case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
  2286.     case 2: font.setShape(LyXFont::UP_SHAPE); break;
  2287.     case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
  2288.     case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
  2289.     case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
  2290.     case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
  2291.     }
  2292.  
  2293.     pos = fl_get_choice(fd_form_character->choice_size);
  2294.     switch(pos) {
  2295.     case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
  2296.     case 2: font.setSize(LyXFont::SIZE_TINY); break;
  2297.     case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
  2298.     case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
  2299.     case 5: font.setSize(LyXFont::SIZE_SMALL); break;
  2300.     case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
  2301.     case 7: font.setSize(LyXFont::SIZE_LARGE); break;
  2302.     case 8: font.setSize(LyXFont::SIZE_LARGER); break;
  2303.     case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
  2304.     case 10: font.setSize(LyXFont::SIZE_HUGE); break;
  2305.     case 11: font.setSize(LyXFont::SIZE_HUGER); break;
  2306.     case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
  2307.     case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
  2308.     case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
  2309.     }
  2310.  
  2311.     pos = fl_get_choice(fd_form_character->choice_bar);
  2312.     switch(pos) {
  2313.     case 1: font.setEmph(LyXFont::IGNORE);
  2314.         font.setUnderbar(LyXFont::IGNORE);
  2315.         font.setNoun(LyXFont::IGNORE);
  2316.         font.setLatex(LyXFont::IGNORE);
  2317.         break;
  2318.     case 2: font.setEmph(LyXFont::TOGGLE); break;
  2319.     case 3: font.setUnderbar(LyXFont::TOGGLE); break;
  2320.     case 4: font.setNoun(LyXFont::TOGGLE); break;
  2321.     case 5: font.setLatex(LyXFont::TOGGLE); break;
  2322.     case 6: font.setEmph(LyXFont::INHERIT);
  2323.         font.setUnderbar(LyXFont::INHERIT);
  2324.         font.setNoun(LyXFont::INHERIT);
  2325.         font.setLatex(LyXFont::INHERIT);
  2326.         break;
  2327.     }
  2328.  
  2329.     pos = fl_get_choice(fd_form_character->choice_color);
  2330.     switch(pos) {
  2331.     case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
  2332.     case 2: font.setColor(LyXFont::NONE); break;
  2333.     case 3: font.setColor(LyXFont::BLACK); break;
  2334.     case 4: font.setColor(LyXFont::WHITE); break;
  2335.     case 5: font.setColor(LyXFont::RED); break;
  2336.     case 6: font.setColor(LyXFont::GREEN); break;
  2337.     case 7: font.setColor(LyXFont::BLUE); break;
  2338.     case 8: font.setColor(LyXFont::CYAN); break;
  2339.     case 9: font.setColor(LyXFont::MAGENTA); break;
  2340.     case 10: font.setColor(LyXFont::YELLOW); break;
  2341.     case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
  2342.     }
  2343.  
  2344.     return font; 
  2345. }
  2346.  
  2347.  
  2348. void FreeCB()
  2349. {
  2350.     ToggleAndShow( UserFreeFont());
  2351. }
  2352.  
  2353.  
  2354. /* callbacks for form form_title */
  2355. void TimerCB(FL_OBJECT *, long)
  2356. {
  2357.     // only if the form still exists
  2358.     if (fd_form_title->form_title != NULL) {
  2359.         if (fd_form_title->form_title->visible) {
  2360.             fl_hide_form(fd_form_title->form_title);
  2361.         }
  2362.         fl_free_form(fd_form_title->form_title);
  2363.         fd_form_title->form_title = NULL;
  2364.     }
  2365. }
  2366.  
  2367.  
  2368. /* callbacks for form form_paragraph */
  2369.  
  2370. void ParagraphVSpaceCB(FL_OBJECT* obj, long )
  2371. {
  2372.     // "Synchronize" the choices and input fields, making it
  2373.     // impossible to commit senseless data.
  2374.  
  2375.     const FD_form_paragraph* fp = fd_form_paragraph;
  2376.  
  2377.     if (obj == fp->choice_space_above) {
  2378.         if (fl_get_choice (fp->choice_space_above) != 7) {
  2379.             fl_set_input (fp->input_space_above, "");
  2380.             ActivateParagraphButtons();
  2381.         }
  2382.     } else if (obj == fp->choice_space_below) {
  2383.         if (fl_get_choice (fp->choice_space_below) != 7) {
  2384.             fl_set_input (fp->input_space_below, "");
  2385.             ActivateParagraphButtons();
  2386.         }
  2387.     } else if (obj == fp->input_space_above) {
  2388.         LString input = fl_get_input (fp->input_space_above);
  2389.  
  2390.         if (input.empty()) {
  2391.             fl_set_choice (fp->choice_space_above, 1);
  2392.             ActivateParagraphButtons();
  2393.         }
  2394.         else if (isValidGlueLength (input)) {
  2395.             fl_set_choice (fp->choice_space_above, 7);
  2396.             ActivateParagraphButtons();
  2397.         }
  2398.         else {
  2399.             fl_set_choice (fp->choice_space_above, 7);
  2400.             DeactivateParagraphButtons();
  2401.         }
  2402.     } else if (obj == fp->input_space_below) {
  2403.         LString input = fl_get_input (fp->input_space_below);
  2404.  
  2405.         if (input.empty()) {
  2406.             fl_set_choice (fp->choice_space_below, 1);
  2407.             ActivateParagraphButtons();
  2408.         }
  2409.         else if (isValidGlueLength (input)) {
  2410.             fl_set_choice (fp->choice_space_below, 7);
  2411.             ActivateParagraphButtons();
  2412.         }
  2413.         else {
  2414.             fl_set_choice (fp->choice_space_below, 7);
  2415.             DeactivateParagraphButtons();
  2416.         }
  2417.     }
  2418. }
  2419.  
  2420.  
  2421. void ParagraphApplyCB(FL_OBJECT *, long)
  2422. {
  2423.     if (!current_view->available())
  2424.         return;
  2425.     
  2426.     bool line_top, line_bottom;
  2427.     bool pagebreak_top, pagebreak_bottom;
  2428.     VSpace space_top, space_bottom;
  2429.     char align;
  2430.     LString labelwidthstring;
  2431.     bool noindent;
  2432.  
  2433.     // If a vspace kind is "Length" but there's no text in
  2434.     // the input field, reset the kind to "None". 
  2435.     if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
  2436.         && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
  2437.         fl_set_choice (fd_form_paragraph->choice_space_above, 1);
  2438.     }
  2439.     if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
  2440.         && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
  2441.         fl_set_choice (fd_form_paragraph->choice_space_below, 1);
  2442.     }
  2443.    
  2444.     line_top = fl_get_button(fd_form_paragraph->check_lines_top);
  2445.     line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
  2446.     pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
  2447.     pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
  2448.     switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
  2449.     case 1: space_top = VSpace::NONE; break;
  2450.     case 2: space_top = VSpace::DEFSKIP; break;
  2451.     case 3: space_top = VSpace::SMALLSKIP; break;
  2452.     case 4: space_top = VSpace::MEDSKIP; break;
  2453.     case 5: space_top = VSpace::BIGSKIP; break;
  2454.     case 6: space_top = VSpace::VFILL; break;
  2455.     case 7: space_top = LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above)); break;
  2456.     }
  2457.     if (fl_get_button (fd_form_paragraph->check_space_above))
  2458.       space_top.setKeep (true);
  2459.     switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
  2460.     case 1: space_bottom = VSpace::NONE; break;
  2461.     case 2: space_bottom = VSpace::DEFSKIP; break;
  2462.     case 3: space_bottom = VSpace::SMALLSKIP; break;
  2463.     case 4: space_bottom = VSpace::MEDSKIP; break;
  2464.     case 5: space_bottom = VSpace::BIGSKIP; break;
  2465.     case 6: space_bottom = VSpace::VFILL; break;
  2466.     case 7: space_bottom = LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below)); break;
  2467.     }
  2468.     if (fl_get_button (fd_form_paragraph->check_space_below))
  2469.       space_bottom.setKeep (true);
  2470.  
  2471.     if (fl_get_button(fd_form_paragraph->radio_align_left))
  2472.         align = LYX_ALIGN_LEFT;
  2473.     else if (fl_get_button(fd_form_paragraph->radio_align_right))
  2474.         align = LYX_ALIGN_RIGHT;
  2475.     else if (fl_get_button(fd_form_paragraph->radio_align_center))
  2476.         align = LYX_ALIGN_CENTER;
  2477.     else 
  2478.         align = LYX_ALIGN_BLOCK;
  2479.    
  2480.     labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
  2481.     noindent = fl_get_button(fd_form_paragraph->check_noindent);
  2482.    
  2483.     current_view->currentBuffer()->text->SetParagraph(line_top,
  2484.                               line_bottom,
  2485.                               pagebreak_top,
  2486.                               pagebreak_bottom,
  2487.                               space_top,
  2488.                               space_bottom,
  2489.                               align, 
  2490.                               labelwidthstring,
  2491.                               noindent);
  2492.     current_view->currentBuffer()->update(1);
  2493.     minibuffer->Set(_("Paragraph layout set"));
  2494. }
  2495.  
  2496.  
  2497. void ParagraphCancelCB(FL_OBJECT *, long)
  2498. {
  2499.     fl_hide_form(fd_form_paragraph->form_paragraph);
  2500. }
  2501.  
  2502.  
  2503. void ParagraphOKCB(FL_OBJECT *ob, long data)
  2504. {
  2505.     ParagraphApplyCB(ob, data);
  2506.     ParagraphCancelCB(ob, data);
  2507. }
  2508.  
  2509.  
  2510. /* callbacks for form form_character */
  2511.  
  2512. void CharacterApplyCB(FL_OBJECT *, long)
  2513. {
  2514.     ToggleAndShow( UserFreeFont());
  2515. }
  2516.  
  2517.  
  2518. void CharacterCancelCB(FL_OBJECT *, long)
  2519. {
  2520.     fl_hide_form(fd_form_character->form_character);
  2521. }
  2522.  
  2523.  
  2524. void CharacterOKCB(FL_OBJECT *ob, long data)
  2525. {
  2526.     CharacterApplyCB(ob,data);
  2527.     CharacterCancelCB(ob,data);
  2528. }
  2529.  
  2530.  
  2531. /* callbacks for form form_document */
  2532.  
  2533. void UpdateDocumentButtons(BufferParams const ¶ms) 
  2534. {
  2535.     fl_set_choice(fd_form_document->choice_pagestyle, 1);
  2536.     
  2537.     if (params.sides == 2)
  2538.         fl_set_button(fd_form_document->radio_sides_two, 1);
  2539.     else
  2540.         fl_set_button(fd_form_document->radio_sides_one, 1);
  2541.     
  2542.     if (params.columns == 2)
  2543.         fl_set_button(fd_form_document->radio_columns_two, 1);
  2544.     else
  2545.         fl_set_button(fd_form_document->radio_columns_one, 1);
  2546.     
  2547.     fl_set_input(fd_form_document->input_extra, params.options.c_str());
  2548.     fl_set_counter_value(fd_form_document->slider_secnumdepth, 
  2549.                  params.secnumdepth);
  2550.     fl_set_counter_value(fd_form_document->slider_tocdepth, 
  2551.                  params.tocdepth);
  2552.     
  2553. }
  2554.  
  2555. void ChoiceClassCB(FL_OBJECT *ob, long)
  2556. {
  2557.     ProhibitInput();
  2558.     if (lyxstyle.Load(fl_get_choice(ob)-1)) {
  2559.         if (AskQuestion(_("Should I set some parameters to"),
  2560.                 fl_get_choice_text(ob),
  2561.                 _("the defaults of this document class?"))) {
  2562.             BufferParams params = BufferParams();
  2563.             params.textclass = fl_get_choice(ob)-1;
  2564.             params.useClassDefaults();
  2565.             UpdateLayoutDocument(¶ms);
  2566.             UpdateDocumentButtons(params);
  2567.         }
  2568.     } else {
  2569.         // unable to load new style
  2570.         WriteAlert(_("Conversion Errors!"),
  2571.                _("Unable to switch to new document class."),
  2572.                _("Reverting to original document class."));
  2573.         fl_set_choice(fd_form_document->choice_class, 
  2574.                   GetCurrentTextClass() + 1);
  2575.     }
  2576.     AllowInput();
  2577. }
  2578.  
  2579.  
  2580. void DocumentDefskipCB(FL_OBJECT *obj, long)
  2581. {
  2582.     // "Synchronize" the choice and the input field, so that it
  2583.     // is impossible to commit senseless data.
  2584.     const FD_form_document* fd = fd_form_document;
  2585.  
  2586.     if (obj == fd->choice_default_skip) {
  2587.         if (fl_get_choice (fd->choice_default_skip) != 4) {
  2588.             fl_set_input (fd->input_default_skip, "");
  2589.             ActivateDocumentButtons();
  2590.         }
  2591.     } else if (obj == fd->input_default_skip) {
  2592.  
  2593.         const char* input = fl_get_input (fd->input_default_skip);
  2594.  
  2595.         if (!*input) {
  2596.             fl_set_choice (fd->choice_default_skip, 2);
  2597.             ActivateDocumentButtons();
  2598.         } else if (isValidGlueLength (input)) {
  2599.             fl_set_choice (fd->choice_default_skip, 4);
  2600.             ActivateDocumentButtons();
  2601.         } else {
  2602.             fl_set_choice (fd->choice_default_skip, 4);
  2603.             DeactivateDocumentButtons();
  2604.         }
  2605.     }
  2606. }
  2607.  
  2608.  
  2609. void DocumentApplyCB(FL_OBJECT *, long)
  2610. {
  2611.     bool redo = false;
  2612.     BufferParams *params = &(current_view->currentBuffer()->params);
  2613.     current_view->currentBuffer()->params.language =
  2614.         combo_language->getline();
  2615.  
  2616.     // If default skip is a "Length" but there's no text in the
  2617.     // input field, reset the kind to "Medskip", which is the default.
  2618.     if (fl_get_choice (fd_form_document->choice_default_skip) == 4
  2619.         && !*(fl_get_input (fd_form_document->input_default_skip))) {
  2620.         fl_set_choice (fd_form_document->choice_default_skip, 2);
  2621.     }
  2622.  
  2623.     params->fonts =
  2624.         fl_get_choice_text(fd_form_document->choice_fonts);
  2625.     params->inputenc =
  2626.         fl_get_choice_text(fd_form_document->choice_inputenc);
  2627.     params->fontsize =
  2628.         fl_get_choice_text(fd_form_document->choice_fontsize);
  2629.     params->pagestyle =
  2630.         fl_get_choice_text(fd_form_document->choice_pagestyle);
  2631.     params->graphicsDriver =
  2632.         fl_get_choice_text(fd_form_document->choice_postscript_driver);
  2633.     params->use_amsmath =
  2634.         fl_get_button(fd_form_document->check_use_amsmath);
  2635.    
  2636.     if (!current_view->available())
  2637.         return;
  2638.  
  2639.     char new_class = fl_get_choice(fd_form_document->choice_class) - 1;
  2640.     if (params->textclass != new_class) {
  2641.         // try to load new_class
  2642.         if (lyxstyle.Load(new_class)) {
  2643.             // successfully loaded
  2644.             redo = true;
  2645.             minibuffer->Set(_("Converting document to new document class..."));
  2646.             int ret = current_view->currentBuffer()->
  2647.                 text->
  2648.                 SwitchLayoutsBetweenClasses(current_view->currentBuffer()->
  2649.                                 params.textclass,
  2650.                                 new_class,
  2651.                                 current_view->currentBuffer()->
  2652.                                 paragraph);
  2653.  
  2654.             if (ret){
  2655.                 LString s;
  2656.                 if (ret==1)
  2657.                     s= _("One paragraph couldn't be converted");
  2658.                 else {
  2659.                     s += ret;
  2660.                     s += _(" paragraphs couldn't be converted");
  2661.                 }
  2662.                 WriteAlert(_("Conversion Errors!"),s,
  2663.                        _("into chosen document class"));
  2664.             }
  2665.  
  2666.             params->textclass = new_class;
  2667.         } else {
  2668.             // problem changing class -- warn user and retain old style
  2669.             WriteAlert(_("Conversion Errors!"),
  2670.                    _("Unable to switch to new document class."),
  2671.                    _("Reverting to original document class."));
  2672.             fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
  2673.         }
  2674.     }
  2675.  
  2676.     char tmpsep = params->paragraph_separation;
  2677.     if (fl_get_button(fd_form_document->radio_indent))
  2678.         params->paragraph_separation = LYX_PARSEP_INDENT;
  2679.     else
  2680.         params->paragraph_separation = LYX_PARSEP_SKIP;
  2681.     if (tmpsep != params->paragraph_separation)
  2682.         redo = true;
  2683.    
  2684.     VSpace tmpdefskip = params->getDefSkip();
  2685.     switch (fl_get_choice (fd_form_document->choice_default_skip)) {
  2686.     case 1: params->setDefSkip(VSpace::SMALLSKIP); break;
  2687.     case 2: params->setDefSkip(VSpace::MEDSKIP); break;
  2688.     case 3: params->setDefSkip(VSpace::BIGSKIP); break;
  2689.     case 4: params->setDefSkip( 
  2690.         VSpace (LyXGlueLength (fl_get_input 
  2691.                        (fd_form_document->input_default_skip))));
  2692.     break;
  2693.     // DocumentDefskipCB assures that this never happens
  2694.     default: params->setDefSkip(VSpace::MEDSKIP); break;
  2695.     }
  2696.     if (!(tmpdefskip == params->getDefSkip()))
  2697.         redo = true;
  2698.  
  2699.     if (fl_get_button(fd_form_document->radio_columns_two))
  2700.         params->columns = 2;
  2701.     else
  2702.         params->columns = 1;
  2703.     if (fl_get_button(fd_form_document->radio_sides_two))
  2704.         params->sides = 2;
  2705.     else
  2706.         params->sides = 1;
  2707.  
  2708.     Spacing tmpSpacing = params->spacing;
  2709.     switch(fl_get_choice(fd_form_document->choice_spacing)) {
  2710.     case 1:
  2711.         lyxerr.debug("Spacing: SINGLE");
  2712.         params->spacing.set(Spacing::Single);
  2713.         break;
  2714.     case 2:
  2715.         lyxerr.debug("Spacing: ONEHALF");
  2716.         params->spacing.set(Spacing::Onehalf);
  2717.         break;
  2718.     case 3:
  2719.         lyxerr.debug("Spacing: DOUBLE");
  2720.         params->spacing.set(Spacing::Double);
  2721.         break;
  2722.     case 4:
  2723.         lyxerr.debug("Spacing: OTHER");
  2724.         // not fully supported yet.
  2725.         params->spacing.set(Spacing::Other, 1.0);
  2726.         // The value needs to be set in another way.
  2727.         break;
  2728.     }
  2729.     if (tmpSpacing != params->spacing)
  2730.         redo = true;
  2731.     
  2732.     signed char tmpchar = (signed char) 
  2733.         fl_get_counter_value(fd_form_document->slider_secnumdepth);;
  2734.     if (params->secnumdepth != tmpchar)
  2735.         redo = true;
  2736.     params->secnumdepth = tmpchar;
  2737.    
  2738.     params->tocdepth = (signed char) 
  2739.         fl_get_counter_value(fd_form_document->slider_tocdepth);;
  2740.  
  2741.     params->float_placement =
  2742.         fl_get_input(fd_form_document->input_float_placement);
  2743.  
  2744.     // More checking should be done to ensure the string doesn't have
  2745.     // spaces or illegal placement characters in it. (thornley)
  2746.  
  2747.     if (redo)
  2748.         current_view->redoCurrentBuffer();
  2749.    
  2750.     minibuffer->Set(_("Document layout set"));
  2751.     current_view->currentBuffer()->markDirty();
  2752.  
  2753.         params->options =
  2754.         fl_get_input(fd_form_document->input_extra);
  2755.    
  2756. }
  2757.  
  2758.  
  2759. void DocumentCancelCB(FL_OBJECT *, long)
  2760. {
  2761.     fl_hide_form(fd_form_document->form_document);
  2762. }
  2763.  
  2764.  
  2765. void DocumentOKCB(FL_OBJECT *ob, long data)
  2766. {
  2767.     DocumentCancelCB(ob,data);
  2768.     DocumentApplyCB(ob,data);
  2769. }
  2770.  
  2771.  
  2772. void DocumentBulletsCB(FL_OBJECT *, long)
  2773. {
  2774.     bulletForm();
  2775.     // bullet callbacks etc. in bullet_panel.C -- ARRae
  2776. }
  2777.  
  2778.  
  2779. void GotoNote()
  2780. {
  2781.     if (!current_view->getScreen())
  2782.         return;
  2783.    
  2784.     current_view->getScreen()->HideCursor();
  2785.     BeforeChange();
  2786.     current_view->currentBuffer()->update(-2);
  2787.     LyXCursor tmp;
  2788.    
  2789.     if (!current_view->currentBuffer()->text->GotoNextNote()) {
  2790.         if (current_view->currentBuffer()->text->cursor.pos 
  2791.             || current_view->currentBuffer()->text->cursor.par !=
  2792.             current_view->currentBuffer()->text->FirstParagraph())
  2793.             {
  2794.                 tmp = current_view->currentBuffer()->text->cursor;
  2795.                 current_view->currentBuffer()->text->cursor.par =
  2796.                     current_view->currentBuffer()->text->FirstParagraph();
  2797.                 current_view->currentBuffer()->text->cursor.pos = 0;
  2798.                 if (!current_view->currentBuffer()->text->GotoNextNote()) {
  2799.                     current_view->currentBuffer()->text->cursor = tmp;
  2800.                     minibuffer->Set(_("No more notes"));
  2801.                     LyXBell();
  2802.                 }
  2803.             } else {
  2804.                 minibuffer->Set(_("No more notes"));
  2805.                 LyXBell();
  2806.             }
  2807.     }
  2808.     current_view->currentBuffer()->update(0);
  2809.     current_view->currentBuffer()->text->sel_cursor =
  2810.         current_view->currentBuffer()->text->cursor;
  2811. }
  2812.  
  2813.  
  2814. void InsertCorrectQuote()
  2815. {
  2816.     Buffer *cbuffer = current_view->currentBuffer();
  2817.     char c;
  2818.  
  2819.     if  (cbuffer->text->cursor.pos )
  2820.         c = cbuffer->text->cursor.par->GetChar(cbuffer->text->cursor.pos - 1);
  2821.     else 
  2822.         c = ' ';
  2823.  
  2824.     cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
  2825. }
  2826.  
  2827.  
  2828. /* callbacks for form form_quotes */
  2829.  
  2830. void QuotesApplyCB(FL_OBJECT *, long)
  2831. {
  2832.     if (!current_view->available())
  2833.         return;
  2834.     
  2835.     minibuffer->Set(_("Quotes type set"));
  2836.     InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
  2837.     switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
  2838.     case 0:
  2839.         lga = InsetQuotes::EnglishQ;
  2840.         break;
  2841.     case 1:
  2842.         lga = InsetQuotes::SwedishQ;
  2843.         break;
  2844.     case 2:
  2845.         lga = InsetQuotes::GermanQ;
  2846.         break;
  2847.     case 3:
  2848.         lga = InsetQuotes::PolishQ;
  2849.         break;
  2850.     case 4:
  2851.         lga = InsetQuotes::FrenchQ;
  2852.         break;
  2853.     case 5:
  2854.         lga = InsetQuotes::DanishQ;
  2855.         break;
  2856.     }
  2857.     current_view->currentBuffer()->params.quotes_language = lga;
  2858.     if (fl_get_button(fd_form_quotes->radio_single))   
  2859.         current_view->currentBuffer()->
  2860.             params.quotes_times = InsetQuotes::SingleQ;
  2861.     else
  2862.         current_view->currentBuffer()->
  2863.             params.quotes_times = InsetQuotes::DoubleQ;
  2864. }
  2865.  
  2866.  
  2867. void QuotesCancelCB(FL_OBJECT *, long)
  2868. {
  2869.     fl_hide_form(fd_form_quotes->form_quotes);
  2870. }
  2871.  
  2872.  
  2873. void QuotesOKCB(FL_OBJECT *ob, long data)
  2874. {
  2875.     QuotesApplyCB(ob, data);
  2876.     QuotesCancelCB(ob, data);
  2877. }
  2878.  
  2879.  
  2880.  
  2881. /* callbacks for form form_preamble */
  2882.  
  2883. void PreambleCancelCB(FL_OBJECT *, long)
  2884. {
  2885.     fl_hide_form(fd_form_preamble->form_preamble);
  2886. }
  2887.  
  2888.  
  2889. void PreambleApplyCB(FL_OBJECT *, long)
  2890. {
  2891.     if (!current_view->available())
  2892.         return;
  2893.     
  2894.     current_view->currentBuffer()->params.preamble =
  2895.         fl_get_input(fd_form_preamble->input_preamble);
  2896.     current_view->currentBuffer()->markDirty();
  2897.     minibuffer->Set(_("LaTeX preamble set"));
  2898. }
  2899.  
  2900.    
  2901. void PreambleOKCB(FL_OBJECT *ob, long data)
  2902. {
  2903.     PreambleApplyCB(ob, data);
  2904.     PreambleCancelCB(ob, data);
  2905. }
  2906.  
  2907.  
  2908. /* callbacks for form form_table */
  2909.  
  2910. void TableApplyCB(FL_OBJECT *, long)
  2911. {
  2912.     int xsize,ysize;
  2913.     if (!current_view->getScreen())
  2914.         return;
  2915.    
  2916.     // check for tables in tables
  2917.     if (current_view->currentBuffer()->text->cursor.par->table){
  2918.         WriteAlert(_("Impossible Operation!"),
  2919.                _("Cannot insert table in table."),
  2920.                _("Sorry."));
  2921.         return;
  2922.     }
  2923.  
  2924.     minibuffer->Set(_("Inserting table..."));
  2925.  
  2926.     ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
  2927.     xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
  2928.    
  2929.    
  2930.     current_view->getScreen()->HideCursor();
  2931.     BeforeChange();
  2932.     current_view->currentBuffer()->update(-2);
  2933.    
  2934.     current_view->currentBuffer()->text->SetCursorParUndo(); 
  2935.     current_view->currentBuffer()->text->FreezeUndo();
  2936.  
  2937.     current_view->currentBuffer()->text->BreakParagraph();
  2938.     current_view->currentBuffer()->update(-1);
  2939.    
  2940.     if (current_view->currentBuffer()->text->cursor.par->Last()) {
  2941.         current_view->currentBuffer()->text->CursorLeft();
  2942.       
  2943.         current_view->currentBuffer()->text->BreakParagraph();
  2944.         current_view->currentBuffer()->update(-1);
  2945.     }
  2946.  
  2947.     current_view->currentBuffer()->text->current_font.setLatex(LyXFont::OFF);
  2948.     // insert the new wysiwy table
  2949.     current_view->currentBuffer()->text->SetLayout(0); // standard layout
  2950.     if (current_view->currentBuffer()->text->cursor.par->footnoteflag ==
  2951.         LyXParagraph::NO_FOOTNOTE) {
  2952.         current_view->currentBuffer()->
  2953.             text->SetParagraph(0, 0,
  2954.                        0, 0,
  2955.                        VSpace (0.3 * current_view->currentBuffer()->
  2956.                            params.spacing.getValue(),
  2957.                            LyXLength::CM),
  2958.                        VSpace (0.3 * current_view->currentBuffer()->
  2959.                            params.spacing.getValue(),
  2960.                            LyXLength::CM),
  2961.                        LYX_ALIGN_CENTER,
  2962.                        LString(),
  2963.                        0);
  2964.     } else
  2965.         current_view->currentBuffer()->text->SetParagraph(0, 0,
  2966.                        0, 0,
  2967.                        VSpace::NONE, VSpace::NONE,
  2968.                        LYX_ALIGN_CENTER, 
  2969.                        LString(),
  2970.                        0);
  2971.  
  2972.     current_view->currentBuffer()->text->cursor.par->table = new LyXTable(xsize, ysize);
  2973.     int i;
  2974.     for (i=0; i<xsize * ysize - 1; i++)
  2975.         current_view->currentBuffer()->text->cursor.par->InsertChar(0,LYX_META_NEWLINE);
  2976.     current_view->currentBuffer()->text->RedoParagraph();
  2977.    
  2978.     current_view->currentBuffer()->text->UnFreezeUndo();
  2979.      
  2980.     current_view->currentBuffer()->update(1);
  2981.     minibuffer->Set(_("Table inserted"));
  2982. }
  2983.  
  2984.  
  2985. void TableCancelCB(FL_OBJECT *, long)
  2986. {
  2987.     fl_hide_form(fd_form_table->form_table);
  2988. }
  2989.  
  2990.  
  2991. void TableOKCB(FL_OBJECT *ob, long data)
  2992. {
  2993.     TableApplyCB(ob,data);
  2994.     TableCancelCB(ob,data);
  2995. }
  2996.  
  2997.  
  2998. /* callbacks for form form_print */
  2999.  
  3000. void PrintCancelCB(FL_OBJECT *, long)
  3001. {
  3002.     fl_hide_form(fd_form_print->form_print);
  3003. }
  3004.  
  3005.  
  3006. void PrintApplyCB(FL_OBJECT *, long)
  3007. {
  3008.     if (!current_view->available())
  3009.         return;
  3010.         Buffer *buffer = current_view->currentBuffer();
  3011.         LString path = OnlyPath(buffer->getFileName());
  3012.  
  3013.     LString pageflag;
  3014.     if (fl_get_button(fd_form_print->radio_even_pages))
  3015.         pageflag = lyxrc->print_evenpage_flag + ' ';
  3016.     else if (fl_get_button(fd_form_print->radio_odd_pages))
  3017.         pageflag = lyxrc->print_oddpage_flag + ' ';
  3018.    
  3019.     LString reverseflag;
  3020.     if (fl_get_button(fd_form_print->radio_order_reverse))
  3021.         reverseflag = lyxrc->print_reverse_flag + ' ';
  3022.    
  3023.     LString orientationflag;
  3024.     if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
  3025.         orientationflag = lyxrc->print_landscape_flag + ' ';
  3026.    
  3027.     LString ps_file = fl_get_input(fd_form_print->input_file);
  3028.     LString printer = fl_get_input(fd_form_print->input_printer);
  3029.  
  3030.     LString printerflag;
  3031.     if (lyxrc->print_adapt_output // printer name should be passed to dvips
  3032.         && ! printer.empty()) // a printer name has been given
  3033.         printerflag = lyxrc->print_to_printer + printer + ' ';
  3034.      
  3035.     LString command = lyxrc->print_command + ' ' 
  3036.         + printerflag + pageflag + reverseflag 
  3037.         + orientationflag + lyxrc->print_extra_options;
  3038.  
  3039.     if (fl_get_button(fd_form_print->radio_file))
  3040.         command += lyxrc->print_to_file + " \""
  3041.             + MakeAbsPath(ps_file, path)
  3042.             + '\"';
  3043.     else if (!lyxrc->print_spool_command.empty())
  3044.         command += lyxrc->print_to_file 
  3045.             + " \"" + ps_file + '\"';
  3046.     
  3047.     // push directorypath, if necessary 
  3048.         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
  3049.         path = buffer->tmppath;
  3050.         }
  3051.         //PathPush(path);
  3052.     Path p(path);
  3053.     if (!lyxrc->print_spool_command.empty() && 
  3054.         !fl_get_button(fd_form_print->radio_file)) {
  3055.             LString command2 = lyxrc->print_spool_command + ' ';
  3056.         if (!printer.empty())
  3057.             command2 += lyxrc->print_spool_printerprefix 
  3058.                     + printer;
  3059.         // First run dvips and, if succesful, then spool command
  3060.         if (RunScript(buffer, true, command)) {
  3061.             RunScript(buffer, false, command2, ps_file);
  3062.         }
  3063.         } else
  3064.         RunScript(buffer, false, command);
  3065.         //PathPop();
  3066. }
  3067.  
  3068.  
  3069. void PrintOKCB(FL_OBJECT *ob, long data)
  3070. {
  3071.     PrintCancelCB(ob, data);  
  3072.     PrintApplyCB(ob,data);
  3073. }
  3074.  
  3075.  
  3076. /* callbacks for form form_figure */
  3077.  
  3078. void FigureApplyCB(FL_OBJECT *, long)
  3079. {
  3080.     if (!current_view->available())
  3081.         return;
  3082.  
  3083.     Buffer * buffer = current_view->currentBuffer();
  3084.     if(buffer->isReadonly()) // paranoia
  3085.         return;
  3086.     
  3087.     minibuffer->Set(_("Inserting figure..."));
  3088.     if (fl_get_button(fd_form_figure->radio_inline)
  3089.         || buffer->text->cursor.par->table){
  3090.         buffer->insertInset(new InsetFig(100, 20, buffer));
  3091.         minibuffer->Set(_("Figure inserted"));
  3092.         return;
  3093.     }
  3094.     
  3095.     current_view->getScreen()->HideCursor();
  3096.     buffer->update(-2);
  3097.     BeforeChange();
  3098.       
  3099.     buffer->text->SetCursorParUndo(); 
  3100.     buffer->text->FreezeUndo();
  3101.  
  3102.     buffer->text->BreakParagraph();
  3103.     buffer->update(-1);
  3104.       
  3105.     if (buffer->text->cursor.par->Last()) {
  3106.         buffer->text->CursorLeft();
  3107.      
  3108.         buffer->text->BreakParagraph();
  3109.         buffer->update(-1);
  3110.     }
  3111.  
  3112.     // The standard layout should always be numer 0;
  3113.     buffer->text->SetLayout(0);
  3114.     
  3115.     if (buffer->text->cursor.par->footnoteflag ==
  3116.         LyXParagraph::NO_FOOTNOTE) {
  3117.         buffer->text->SetParagraph(0, 0,
  3118.                        0, 0,
  3119.                        VSpace (0.3 * buffer->params.spacing.getValue(),
  3120.                            LyXLength::CM),
  3121.                        VSpace (0.3 *
  3122.                            buffer->params.spacing.getValue(),
  3123.                            LyXLength::CM),
  3124.                        LYX_ALIGN_CENTER, LString(), 0);
  3125.     } else
  3126.         buffer->text->SetParagraph(0, 0,
  3127.                        0, 0,
  3128.                        VSpace::NONE, VSpace::NONE,
  3129.                        LYX_ALIGN_CENTER, 
  3130.                        LString(),
  3131.                        0);
  3132.     
  3133.     buffer->update(-1);
  3134.       
  3135.     Inset *new_inset = NULL;
  3136.     
  3137.     new_inset = new InsetFig(100, 100, buffer);
  3138.     buffer->insertInset(new_inset);
  3139.     
  3140.     buffer->update(0);
  3141.     minibuffer->Set(_("Figure inserted"));
  3142.     buffer->text->UnFreezeUndo();
  3143. }
  3144.  
  3145.    
  3146. void FigureCancelCB(FL_OBJECT *, long)
  3147. {
  3148.     fl_hide_form(fd_form_figure->form_figure);
  3149. }
  3150.  
  3151.  
  3152. void FigureOKCB(FL_OBJECT *ob, long data)
  3153. {
  3154.     FigureApplyCB(ob,data);
  3155.     FigureCancelCB(ob,data);
  3156. }
  3157.  
  3158. void ScreenApplyCB(FL_OBJECT *, long)
  3159. {
  3160.     lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
  3161.     lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
  3162.     lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
  3163.     lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
  3164.     lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
  3165.     fontloader.update();
  3166.    
  3167.     // All buffers will need resize
  3168.     bufferlist.resize();
  3169.  
  3170.     minibuffer->Set(_("Screen options set"));
  3171. }
  3172.  
  3173.  
  3174. void ScreenCancelCB(FL_OBJECT *, long)
  3175. {
  3176.     fl_hide_form(fd_form_screen->form_screen);
  3177. }
  3178.  
  3179.  
  3180. void ScreenOKCB(FL_OBJECT *ob, long data)
  3181. {
  3182.     ScreenCancelCB(ob,data);
  3183.     ScreenApplyCB(ob,data);
  3184. }
  3185.  
  3186.  
  3187. void LaTeXOptions()
  3188. {
  3189.     if (!current_view->available())
  3190.         return;
  3191.  
  3192.     fl_set_button(fd_latex_options->accents,
  3193.               (int)current_view->currentBuffer()->params.allowAccents);
  3194.     
  3195.     if (fd_latex_options->LaTeXOptions->visible) {
  3196.         fl_raise_form(fd_latex_options->LaTeXOptions);
  3197.     } else {
  3198.         fl_show_form(fd_latex_options->LaTeXOptions,
  3199.                  FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
  3200.                  _("LaTeX Options"));
  3201.     }
  3202. }
  3203.  
  3204.  
  3205. // This function runs "configure" and then rereads lyx.defaults to
  3206. // reconfigure the automatic settings.
  3207. void Reconfigure()
  3208. {
  3209.     minibuffer->Set(_("Running configure..."));
  3210.  
  3211.     // Run configure in user lyx directory
  3212.     //PathPush(user_lyxdir);
  3213.     Path p(user_lyxdir);
  3214.     Systemcalls one(Systemcalls::System, 
  3215.                           AddName(system_lyxdir,"configure"));
  3216.     //PathPop();
  3217.     minibuffer->Set(_("Reloading configuration..."));
  3218.     lyxrc->Read(LibFileSearch(LString(), "lyxrc.defaults"));
  3219.     WriteAlert(_("The system has been reconfigured."), 
  3220.            _("You need to restart LyX to make use of any"),
  3221.            _("updated document class specifications."));
  3222. }
  3223.  
  3224.  
  3225. /* these functions are for the spellchecker */ 
  3226. char* NextWord(float &value)
  3227. {
  3228.     if (!current_view->available()){
  3229.         value = 1;
  3230.         return NULL;
  3231.     }
  3232.    
  3233.     char* string =  current_view->currentBuffer()->text->SelectNextWord(value);
  3234.  
  3235.     return string;
  3236. }
  3237.  
  3238.   
  3239. void SelectLastWord()
  3240. {
  3241.     if (!current_view->available())
  3242.         return;
  3243.    
  3244.     current_view->getScreen()->HideCursor();
  3245.     BeforeChange(); 
  3246.     current_view->currentBuffer()->text->SelectSelectedWord();
  3247.     current_view->getScreen()->ToggleSelection(false);
  3248.     current_view->currentBuffer()->update(0);
  3249. }
  3250.  
  3251.  
  3252. void EndOfSpellCheck()
  3253. {
  3254.     if (!current_view->available())
  3255.         return;
  3256.    
  3257.     current_view->getScreen()->HideCursor();
  3258.     BeforeChange(); 
  3259.     current_view->currentBuffer()->text->SelectSelectedWord();
  3260.     current_view->currentBuffer()->text->ClearSelection();
  3261.     current_view->currentBuffer()->update(0);
  3262. }
  3263.  
  3264.  
  3265. void ReplaceWord(LString const & replacestring)
  3266. {
  3267.     if (!current_view->getScreen())
  3268.         return;
  3269.  
  3270.     current_view->getScreen()->HideCursor();
  3271.     current_view->currentBuffer()->update(-2);
  3272.    
  3273.     /* clear the selection (if there is any) */ 
  3274.     current_view->getScreen()->ToggleSelection(false);
  3275.     current_view->currentBuffer()->text->
  3276.         ReplaceSelectionWithString(replacestring.c_str());
  3277.    
  3278.     current_view->currentBuffer()->text->SetSelectionOverString(replacestring.c_str());
  3279.  
  3280.     // Go back so that replacement string is also spellchecked
  3281.     for (int i=-1; i< replacestring.length(); i++) {
  3282.         current_view->currentBuffer()->text->CursorLeftIntern();
  3283.     }
  3284.     current_view->currentBuffer()->update(1);
  3285. }
  3286. // End of spellchecker stuff
  3287.  
  3288.  
  3289.  
  3290. //
  3291. // Table of Contents
  3292. //
  3293.  
  3294. struct TocList {
  3295.     char counter[6];
  3296.     TocList *next;
  3297. };
  3298.  
  3299.  
  3300. static TocList* toclist = NULL;
  3301.  
  3302.  
  3303. void TocSelectCB(FL_OBJECT *ob, long)
  3304. {
  3305.     if (!current_view->available())
  3306.         return;
  3307.    
  3308.     TocList* tmptoclist = toclist;
  3309.     int i = fl_get_browser(ob);
  3310.     int a = 0;
  3311.  
  3312.     for (a=1; a<i && tmptoclist->next; a++){
  3313.         tmptoclist = tmptoclist->next;
  3314.     }
  3315.  
  3316.     if (!tmptoclist)
  3317.         return;
  3318.      
  3319.  
  3320.     LyXParagraph *par = current_view->currentBuffer()->paragraph;
  3321.     while (par && 
  3322.            (
  3323.                par->GetCounter(0) != tmptoclist->counter[0] ||
  3324.                par->GetCounter(1) != tmptoclist->counter[1] ||
  3325.                par->GetCounter(2) != tmptoclist->counter[2] ||
  3326.                par->GetCounter(3) != tmptoclist->counter[3] ||
  3327.                par->GetCounter(4) != tmptoclist->counter[4] ||
  3328.                par->GetCounter(5) != tmptoclist->counter[5]
  3329.                )
  3330.         ) {
  3331.         par = par->LastPhysicalPar()->Next();
  3332.     }
  3333.    
  3334.     if (par) {
  3335.         BeforeChange();
  3336.         current_view->currentBuffer()->text->SetCursor(par, 0);
  3337.         current_view->currentBuffer()->text->sel_cursor =
  3338.             current_view->currentBuffer()->text->cursor;
  3339.         current_view->currentBuffer()->update(0);
  3340.     }
  3341.     else {
  3342.         WriteAlert(_("Error"), 
  3343.                _("Couldn't find this label"), 
  3344.                _("in current document."));
  3345.     }
  3346.       
  3347. }
  3348.  
  3349.  
  3350. void TocCancelCB(FL_OBJECT *, long)
  3351. {
  3352.     fl_hide_form(fd_form_toc->form_toc);
  3353. }
  3354.  
  3355.  
  3356. void TocUpdateCB(FL_OBJECT *, long)
  3357. {
  3358.     static LyXParagraph* stapar = NULL;
  3359.     TocList *tmptoclist = NULL;
  3360.    
  3361.     /* deleted the toclist */ 
  3362.     if (toclist){
  3363.         while (toclist){
  3364.             tmptoclist = toclist->next;
  3365.             delete toclist;
  3366.             toclist = tmptoclist;
  3367.         }
  3368.     }
  3369.     toclist = NULL;
  3370.     tmptoclist = toclist;
  3371.  
  3372.  
  3373.     fl_clear_browser(fd_form_toc->browser_toc);
  3374.     if (!current_view->available()) {
  3375.         fl_add_browser_line(fd_form_toc->browser_toc, _("*** No Document ***"));
  3376.         return;
  3377.     }
  3378.     fl_hide_object(fd_form_toc->browser_toc);
  3379.     /* get the table of contents */ 
  3380.     LyXParagraph *par = current_view->currentBuffer()->paragraph;
  3381.     char labeltype;
  3382.     char* line = new char[200];
  3383.     int i = 0;
  3384.     int pos = 0;
  3385.     unsigned char c;
  3386.     int topline = 0;
  3387.    
  3388.     if (stapar == par)
  3389.         topline = fl_get_browser_topline(fd_form_toc->browser_toc);
  3390.     stapar = par;
  3391.    
  3392.     while (par) {
  3393.         labeltype = lyxstyle.Style(current_view->currentBuffer()->params.textclass, 
  3394.                        par->GetLayout())->labeltype;
  3395.       
  3396.         if (labeltype >= LABEL_COUNTER_CHAPTER
  3397.             && labeltype <= LABEL_COUNTER_CHAPTER +
  3398.             current_view->currentBuffer()->params.tocdepth) {
  3399.             /* insert this into the table of contents */ 
  3400.             /* first indent a little bit */ 
  3401.             
  3402.             for (pos=0; 
  3403.                  pos < (labeltype - 
  3404.                     lyxstyle.TextClass(current_view->currentBuffer()->
  3405.                                params.textclass)->maxcounter) * 4 + 2;
  3406.                  pos++)
  3407.                 line[pos] = ' ';
  3408.             
  3409.             /* then the labelstring */ 
  3410.             i = 0;
  3411.             if (!par->labelstring.empty()) {
  3412.                 while (pos < 199 && i < par->labelstring.length()) {
  3413.                     line[pos] = par->labelstring[i];
  3414.                     i++;
  3415.                     pos++;
  3416.                 }
  3417.             }
  3418.      
  3419.             line[pos] = ' ';
  3420.             pos++;
  3421.             
  3422.             /* now the contents */ 
  3423.             i = 0;
  3424.             while (pos < 199 && i < par->last) {
  3425.                 c = par->GetChar(i);
  3426.                 if (isprint((unsigned char) c) || c >= 128) {
  3427.                     line[pos] = c;
  3428.                     pos++;
  3429.                 }
  3430.                 i++;
  3431.             }
  3432.             line[pos] = '\0';
  3433.             fl_add_browser_line(fd_form_toc->browser_toc, line);
  3434.             
  3435.             /* make a toclist entry */
  3436.             if (!tmptoclist){
  3437.                 tmptoclist = new TocList;
  3438.                 toclist = tmptoclist;
  3439.             } else {
  3440.                 tmptoclist->next = new TocList;
  3441.                 tmptoclist = tmptoclist->next;
  3442.             }
  3443.             
  3444.             tmptoclist->next = NULL;
  3445.             int a = 0;
  3446.             for (a=0; a<6; a++){
  3447.                 tmptoclist->counter[a] = par->GetCounter(a);
  3448.             }
  3449.         }
  3450.         par = par->LastPhysicalPar()->Next();
  3451.         
  3452.     }
  3453.     delete[] line;
  3454.     fl_set_browser_topline(fd_form_toc->browser_toc, topline);
  3455.     fl_show_object(fd_form_toc->browser_toc);
  3456. }
  3457.  
  3458.  
  3459. /* callbacks for form form_ref */
  3460. void RefSelectCB(FL_OBJECT *, long data)
  3461. {
  3462.     if (!current_view->available())
  3463.         return;
  3464.  
  3465.     LString s =
  3466.         fl_get_browser_line(fd_form_ref->browser_ref,
  3467.                     fl_get_browser(fd_form_ref->browser_ref));
  3468.     if (s.empty())
  3469.         return;
  3470.  
  3471.     if (!current_view->currentBuffer()->isLinuxDoc()) {
  3472.             if (data==2) {
  3473.                     current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
  3474.                 return;
  3475.         }
  3476.         
  3477.         LString t;
  3478.         if (data==0)
  3479.             t += "\\ref{";
  3480.         else
  3481.             t += "\\pageref{";
  3482.         t += s;
  3483.         t += '}';
  3484.         Inset *new_inset =
  3485.             new InsetRef(t, current_view->currentBuffer());
  3486.         current_view->currentBuffer()->insertInset(new_inset);
  3487.     } else {
  3488. #ifdef WITH_WARNINGS
  3489. #warning FIXME!
  3490. #endif
  3491.         // probably changes should be made to InsetRef to handle
  3492.         // linuxdoc as well. (Lgb)
  3493.     }
  3494. }
  3495.  
  3496.  
  3497. void RefUpdateCB(FL_OBJECT *, long)
  3498. {
  3499.     fl_clear_browser(fd_form_ref->browser_ref);
  3500.     if (!current_view->available())
  3501.         return;
  3502.  
  3503.     LString references;
  3504.     LString curr_ref;
  3505.     int ref_num;
  3506.  
  3507.     ref_num=0;
  3508.     references=current_view->currentBuffer()->getReferenceList();
  3509.     
  3510.     while(true) {
  3511.         curr_ref=references.token('|',ref_num);
  3512.         
  3513.         if (curr_ref=="")
  3514.             break;
  3515.  
  3516.         fl_add_browser_line(fd_form_ref->browser_ref,curr_ref.c_str());
  3517.         ref_num++;
  3518.     }
  3519.  
  3520.     if (!fl_get_browser_maxline(fd_form_ref->browser_ref)) {
  3521.         fl_add_browser_line(fd_form_ref->browser_ref, 
  3522.                     _("*** No labels found in document ***"));
  3523.         fl_deactivate_object(fd_form_ref->browser_ref);
  3524.     } else {
  3525.         fl_select_browser_line(fd_form_ref->browser_ref, 1);
  3526.         fl_activate_object(fd_form_ref->browser_ref);
  3527.     }
  3528. }
  3529.  
  3530.  
  3531. void RefHideCB(FL_OBJECT *, long)
  3532. {
  3533.     fl_hide_form(fd_form_ref->form_ref);
  3534. }
  3535.  
  3536.  
  3537. void UpdateInset(Inset* inset, bool mark_dirty)
  3538. {
  3539.     if (!inset)
  3540.         return;
  3541.  
  3542.     /* very first check for locking insets*/
  3543.     if (current_view->currentBuffer()->the_locking_inset == inset){
  3544.         if (current_view->currentBuffer()->text->UpdateInset(inset)){
  3545.             current_view->update();
  3546.             if (mark_dirty){
  3547.                 if (current_view->currentBuffer()->isLyxClean())
  3548.                     minibuffer->setTimer(4);
  3549.                 current_view->currentBuffer()->markDirty();
  3550.             }
  3551.             current_view->updateScrollbar();
  3552.             return;
  3553.         }
  3554.     }
  3555.   
  3556.     /* first check the current buffer */
  3557.     if (current_view->available()){
  3558.         current_view->getScreen()->HideCursor();
  3559.         current_view->currentBuffer()->update(-3);
  3560.         if (current_view->currentBuffer()->text->UpdateInset(inset)){
  3561.             if (mark_dirty)
  3562.                 current_view->currentBuffer()->update(1);
  3563.             else 
  3564.                 current_view->currentBuffer()->update(3);
  3565.             return;
  3566.         }
  3567.     }
  3568.   
  3569.     // check all buffers
  3570.     bufferlist.updateInset(inset, mark_dirty);
  3571.  
  3572. }
  3573.  
  3574.  
  3575. /* these functions return 1 if an error occured, 
  3576.    otherwise 0 */
  3577. bool LockInset(UpdatableInset* inset)
  3578. {
  3579.     if (!current_view->currentBuffer()->the_locking_inset && inset){
  3580.         current_view->currentBuffer()->the_locking_inset = inset;
  3581.         return false;
  3582.     }
  3583.     return true;
  3584. }
  3585.  
  3586.  
  3587. void ShowLockedInsetCursor(long x, long y, int asc, int desc)
  3588. {
  3589.     if (current_view->currentBuffer()->the_locking_inset &&
  3590.         current_view->getScreen()){
  3591.         y += current_view->currentBuffer()->text->cursor.y;
  3592.         current_view->getScreen()->ShowManualCursor(x, y,
  3593.                                 asc, desc);
  3594.     }
  3595. }
  3596.  
  3597.  
  3598. void HideLockedInsetCursor(long x, long y, int asc, int desc)
  3599. {
  3600.     if (current_view->currentBuffer()->the_locking_inset &&
  3601.         current_view->getScreen()){
  3602.         y += current_view->currentBuffer()->text->cursor.y;
  3603.         current_view->getScreen()->HideManualCursor(x, y,
  3604.                                 asc, desc);
  3605.     }
  3606. }
  3607.  
  3608.  
  3609. void FitLockedInsetCursor(long x, long y, int asc, int desc)
  3610. {
  3611.     if (current_view->currentBuffer()->the_locking_inset &&
  3612.         current_view->getScreen()){
  3613.         y += current_view->currentBuffer()->text->cursor.y;
  3614.         if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
  3615.             current_view->updateScrollbar();
  3616.     }
  3617. }
  3618.  
  3619.  
  3620. int UnlockInset(UpdatableInset* inset)
  3621. {
  3622.     if (inset &&
  3623.         current_view->currentBuffer()->the_locking_inset == inset){
  3624.         inset->InsetUnlock();
  3625.         current_view->currentBuffer()->the_locking_inset = NULL;
  3626.         current_view->currentBuffer()->text->FinishUndo();
  3627.         return 0;
  3628.     }
  3629.     return bufferlist.unlockInset(inset);
  3630. }
  3631.  
  3632.  
  3633. void LockedInsetStoreUndo(Undo::undo_kind kind)
  3634. {
  3635.     if (!current_view->currentBuffer()->the_locking_inset)
  3636.         return; // shouldn't happen
  3637.     if (kind == Undo::EDIT) // in this case insets would not be stored!
  3638.         kind = Undo::FINISH;
  3639.     current_view->currentBuffer()->text->SetUndo(kind,
  3640.                   current_view->currentBuffer()->text->cursor.par->
  3641.                   ParFromPos(current_view->currentBuffer()->text->cursor.pos)->previous, 
  3642.                   current_view->currentBuffer()->text->cursor.par->
  3643.                   ParFromPos(current_view->currentBuffer()->text->cursor.pos)->next); 
  3644. }
  3645.  
  3646.  
  3647. void PutInsetIntoInsetUpdateList(Inset* inset)
  3648. {
  3649.     if (inset) {
  3650.         InsetUpdateStruct* tmp = new InsetUpdateStruct();
  3651.         tmp->inset = inset;
  3652.         tmp->next = InsetUpdateList;
  3653.         InsetUpdateList = tmp;
  3654.     }
  3655. }
  3656.  
  3657.  
  3658. void UpdateInsetUpdateList()
  3659. {
  3660.     InsetUpdateStruct *tmp = InsetUpdateList;
  3661.     while (tmp) {
  3662.         UpdateInset(tmp->inset, false); // "false" because no document change
  3663.         tmp = tmp->next;
  3664.     }
  3665.   
  3666.     /* delete the update list */
  3667.     while (InsetUpdateList) {
  3668.         tmp = InsetUpdateList;
  3669.         InsetUpdateList = InsetUpdateList->next;
  3670.         delete tmp;
  3671.     }
  3672.     InsetUpdateList = NULL;
  3673. }
  3674.