]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
paragraph-spacing, redoparagraph in deleteemptyparagraphmechanism, got rid of some...
[lyx.git] / src / lyx_cb.C
index e28a61aaccd01e2dc8df0b60dce653728d714ae3..3bc8c6d426aec2dda78001ce07e57b998cce066d 100644 (file)
 
 #include <config.h>
 
-#include <cctype>
-#include <unistd.h>
-#include <csignal>
-#include <cstring>
-#include <cstdlib>
-
 #include <fstream>
-using std::ifstream;
+#include <algorithm>
+#include <iostream>
 
 #include "LString.h"
 #include "support/lstrings.h"
@@ -49,7 +44,6 @@ using std::ifstream;
 #include "LyXView.h"
 #include "lastfiles.h"
 #include "support/FileInfo.h"
-#include "lyxscreen.h"
 #include "debug.h"
 #include "support/syscall.h"
 #include "support/lyxlib.h"
@@ -59,6 +53,17 @@ using std::ifstream;
 #include "lyxtext.h"
 #include "gettext.h"
 #include "layout.h"
+#include "language.h"
+#include "CutAndPaste.h"
+
+using std::ifstream;
+using std::copy;
+using std::back_inserter;
+using std::endl;
+using std::cout;
+using std::ios;
+using std::istream_iterator;
+using std::pair;
 
 extern Combox * combo_language;
 extern BufferList bufferlist;
@@ -86,7 +91,6 @@ extern bool send_fax(string const & fname, string const & sendcmd);
 extern void MenuSendto();
 
 extern LyXServer * lyxserver;
-extern FontLoader fontloader;
 
 // this should be static, but I need it in buffer.C
 bool quitting; // flag, that we are quitting the program
@@ -145,7 +149,8 @@ bool toggleall = true;
                   Matthias
    */
 
-void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
+//void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
+
 /* these functions return 1 if an error occured, 
    otherwise 0 */
 // Now they work only for updatable insets. [Alejandro 080596]
@@ -157,10 +162,10 @@ void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
 
 /* this is for asyncron updating. UpdateInsetUpdateList will be called
    automatically from LyX. Just insert the Inset into the Updatelist */
-void UpdateInsetUpdateList();
-void PutInsetIntoInsetUpdateList(Inset * inset);
+//void UpdateInsetUpdateList();
+//void PutInsetIntoInsetUpdateList(Inset * inset);
 
-InsetUpdateStruct * InsetUpdateList = 0;
+//InsetUpdateStruct * InsetUpdateList = 0;
 
 
 /*
@@ -169,7 +174,7 @@ InsetUpdateStruct * InsetUpdateList = 0;
 
 /* some function prototypes */
 
-int RunLinuxDoc(int, string const &);
+int RunLinuxDoc(BufferView *, int, string const &);
 int RunDocBook(int, string const &);
 void MenuWrite(Buffer * buf);
 void MenuWriteAs(Buffer * buffer);
@@ -177,6 +182,20 @@ void MenuReload(Buffer * buf);
 void MenuLayoutSave();
 
 
+void ShowMessage(Buffer * buf,
+                string const & msg1,
+                string const & msg2 = string(),
+                string const & msg3 = string(), int delay = 6)
+{
+       if (lyxrc.use_gui) {
+               buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
+                                                             msg3, delay);
+       } else {
+               // can somebody think of something more clever? cerr?
+               cout << msg1 << msg2 << msg3 << endl;
+       }
+}
+
 // How should this actually work? Should it prohibit input in all BufferViews,
 // or just in the current one? If "just the current one", then it should be
 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
@@ -184,11 +203,10 @@ void MenuLayoutSave();
 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
 // current LyxView that should be prohibited (Lgb) (This applies to
 // "AllowInput" as well.)
-void ProhibitInput()
+void ProhibitInput(BufferView * bv)
 {
        input_prohibited = true;
-       if (current_view->getScreen())
-               current_view->getScreen()->HideCursor();
+       bv->hideCursor();
 
        static Cursor cursor;
        static bool cursor_undefined = true;
@@ -200,7 +218,7 @@ void ProhibitInput()
        }
    
        /* set the cursor to the watch for all forms and the canvas */ 
-       XDefineCursor(fl_display, current_view->owner()->getForm()->window, 
+       XDefineCursor(fl_display, bv->owner()->getForm()->window, 
                      cursor);
        if (fd_form_paragraph->form_paragraph->visible)
                XDefineCursor(fl_display,
@@ -231,23 +249,24 @@ void SetXtermCursor(Window win)
 }
 
 
-void AllowInput()
+void AllowInput(BufferView * bv)
 {
        input_prohibited = false;
 
        /* reset the cursor from the watch for all forms and the canvas */
    
-       XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
+       XUndefineCursor(fl_display, bv->owner()->getForm()->window);
        if (fd_form_paragraph->form_paragraph->visible)
                XUndefineCursor(fl_display,
                                fd_form_paragraph->form_paragraph->window);
        if (fd_form_character->form_character->visible)
                XUndefineCursor(fl_display,
                                fd_form_character->form_character->window);
-#ifndef NEW_WA
-       if (current_view->getWorkArea()->belowmouse)
-               SetXtermCursor(current_view->owner()->getForm()->window);
-#endif
+
+       // What to do about this? (Lgb)
+       if (bv->belowMouse())
+               SetXtermCursor(bv->owner()->getForm()->window);
+
        XFlush(fl_display);
        fl_activate_all_forms();
 }
@@ -280,7 +299,7 @@ void SetUpdateTimer(float time)
 void MenuWrite(Buffer * buffer)
 {
        XFlush(fl_display);
-       if (!bufferlist.write(buffer, lyxrc->make_backup)) {
+       if (!buffer->save()) {
                string fname = buffer->fileName();
                string s = MakeAbsPath(fname);
                if (AskQuestion(_("Save failed. Rename and try again?"),
@@ -306,9 +325,9 @@ void MenuWriteAs(Buffer * buffer)
        string oldname = fname;
        LyXFileDlg fileDlg;
 
-       ProhibitInput();
-       fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
-       fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
+       ProhibitInput(current_view);
+       fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
+       fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
 
        if (!IsLyXFilename(fname))
                fname += ".lyx";
@@ -317,7 +336,7 @@ void MenuWriteAs(Buffer * buffer)
                               OnlyPath(fname),
                               "*.lyx", 
                               OnlyFilename(fname));
-       AllowInput();
+       AllowInput(current_view);
 
        if (fname.empty()) {
                return;
@@ -347,9 +366,8 @@ void MenuWriteAs(Buffer * buffer)
                                buffer->fileName(s);
                                buffer->markDirty();
 
-                               buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document renamed to '"),
-                                               MakeDisplayPath(s),
-                                               _("', but not saved..."));
+                               ShowMessage(buffer, _("Document renamed to '"),
+                                               MakeDisplayPath(s), _("', but not saved..."));
                        }
                return;
        } // Check whether the file exists
@@ -376,7 +394,7 @@ int MenuRunLaTeX(Buffer * buffer)
        int ret = 0;
 
        if (buffer->isLinuxDoc())
-               ret = RunLinuxDoc(1, buffer->fileName());
+               ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
        else if (buffer->isLiterate())
                ret = buffer->runLiterate();
        else if (buffer->isDocBook())
@@ -469,7 +487,7 @@ int MakeLaTeXOutput(Buffer * buffer)
        //      return 1;
        int ret = 0;
        string path = OnlyPath(buffer->fileName());
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
        }
        if (!buffer->isDviClean()) {
@@ -502,7 +520,7 @@ bool RunScript(Buffer * buffer, bool wait,
                                       ".dvi", true);
 
        path = OnlyPath(name);
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
        }
        Path p(path);
@@ -511,8 +529,8 @@ bool RunScript(Buffer * buffer, bool wait,
        // substitute the real file name otherwise the filename is
        // simply appended. rokrau 1/12/00
        cmd = command;
-       std::string::size_type i;
-       if ( (i=command.find("$$FName")) != std::string::npos)
+       string::size_type i;
+       if ( (i=command.find("$$FName")) != string::npos)
        {
                cmd.replace(i,7,QuoteName(name));
        }
@@ -551,12 +569,10 @@ bool RunScript(Buffer * buffer, bool wait,
 #ifdef WITH_WARNINGS
 #warning What should we do here?
 #endif         
-               buffer->getUser()->owner()->getMiniBuffer()->Set(
-                       _("Executing command:"), cmd);
+               ShowMessage(buffer, _("Executing command:"), cmd);
                result = one.startscript(Systemcalls::System, cmd);
        } else {
-               buffer->getUser()->owner()->getMiniBuffer()->Set(
-                       _("Executing command:"), cmd);
+               ShowMessage(buffer, _("Executing command:"), cmd);
                result = one.startscript(wait ? Systemcalls::Wait
                                         : Systemcalls::DontWait, cmd);
        }
@@ -571,11 +587,11 @@ bool CreatePostscript(Buffer * buffer, bool wait = false)
        //if (!bv->text)
        //      return false;
 
-       ProhibitInput();
+       ProhibitInput(current_view);
 
        // Generate dvi file
         if (MakeLaTeXOutput(buffer) > 0) {
-               AllowInput();
+               AllowInput(current_view);
                return false;
         }
        // Generate postscript file
@@ -587,7 +603,7 @@ bool CreatePostscript(Buffer * buffer, bool wait = false)
        // Wrong type
        char real_papersize = buffer->params.papersize;
        if (real_papersize == BufferParams::PAPER_DEFAULT)
-               real_papersize = lyxrc->default_papersize;
+               real_papersize = lyxrc.default_papersize;
 
        switch (real_papersize) {
        case BufferParams::PAPER_USLETTER:
@@ -616,16 +632,16 @@ bool CreatePostscript(Buffer * buffer, bool wait = false)
        }
 
        // Make postscript file.
-       string command = lyxrc->dvi_to_ps_command + ' ' + lyxrc->print_to_file + ' ';
+       string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
        command += QuoteName(psname);
        if (buffer->params.use_geometry
            && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
-           && !lyxrc->print_paper_dimension_flag.empty()
+           && !lyxrc.print_paper_dimension_flag.empty()
            && !buffer->params.paperwidth.empty()
            && !buffer->params.paperheight.empty()) {
                // using a custom papersize
                command += ' ';
-               command += lyxrc->print_paper_dimension_flag + ' ';
+               command += lyxrc.print_paper_dimension_flag + ' ';
                command += buffer->params.paperwidth + ',';
                command += buffer->params.paperheight;
        } else if (!paper.empty()
@@ -634,20 +650,20 @@ bool CreatePostscript(Buffer * buffer, bool wait = false)
                // dvips won't accept -t letter -t landscape.  In all other
                // cases, include the paper size explicitly.
                command += ' ';
-               command += lyxrc->print_paper_flag + ' ' + paper;
+               command += lyxrc.print_paper_flag + ' ' + paper;
        }
        if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
                command += ' ';
-               command += lyxrc->print_landscape_flag;
+               command += lyxrc.print_landscape_flag;
        }
        // push directorypath, if necessary 
         string path = OnlyPath(buffer->fileName());
-        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
+        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
                path = buffer->tmppath;
         }
         Path p(path);
        bool ret = RunScript(buffer, wait, command);
-       AllowInput();
+       AllowInput(current_view);
        return ret;
 }
 
@@ -666,17 +682,17 @@ bool PreviewPostscript(Buffer * buffer)
        }
 
        // Start postscript viewer
-       ProhibitInput();
+       ProhibitInput(current_view);
        string ps = ChangeExtension (buffer->fileName(),
                                     ".ps_tmp", true);
        // push directorypath, if necessary 
         string path = OnlyPath(buffer->fileName());
-        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
+        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
                path = buffer->tmppath;
         }
         Path p(path);
-       bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
-       AllowInput();
+       bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
+       AllowInput(current_view);
        return ret;
 }
 
@@ -695,16 +711,16 @@ void MenuFax(Buffer * buffer)
        // Send fax
        string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
        string path = OnlyPath (buffer->fileName());
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
        }
        Path p(path);
-       if (!lyxrc->fax_program.empty()) {
-                string help2 = subst(lyxrc->fax_program, "$$FName", ps);
+       if (!lyxrc.fax_program.empty()) {
+                string help2 = subst(lyxrc.fax_program, "$$FName", ps);
                 help2 += " &";
                 Systemcalls one(Systemcalls::System, help2);
        } else
-               send_fax(ps, lyxrc->fax_command);
+               send_fax(ps, lyxrc.fax_command);
 }
 
 
@@ -715,12 +731,12 @@ bool PreviewDVI(Buffer * buffer)
        //if (!bv->text)
        //      return false;
 
-       string paper = lyxrc->view_dvi_paper_option;
+       string paper = lyxrc.view_dvi_paper_option;
        if (!paper.empty()) {
                // wrong type
                char real_papersize = buffer->params.papersize;
                if (real_papersize == BufferParams::PAPER_DEFAULT)
-                       real_papersize = lyxrc->default_papersize;
+                       real_papersize = lyxrc.default_papersize;
   
                switch (real_papersize) {
                case BufferParams::PAPER_USLETTER:
@@ -763,17 +779,33 @@ bool PreviewDVI(Buffer * buffer)
         }
         // push directorypath, if necessary 
        string path = OnlyPath(buffer->fileName());
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
        }
        Path p(path);
         // Run dvi-viewer
-       string command = lyxrc->view_dvi_command + " " + paper;
+       string command = lyxrc.view_dvi_command + " " + paper;
        bool ret = RunScript(buffer, false, command);
        return ret;
 }
 
 
+bool AskOverwrite(Buffer * buffer, string const & s)
+{
+       if (lyxrc.use_gui) {
+               // be friendly if there is a gui
+               FileInfo fi(s);
+               if (fi.readable() &&
+                               !AskQuestion(_("File already exists:"), 
+                                MakeDisplayPath(s, 50),
+                                _("Do you want to overwrite the file?"))) {
+                       ShowMessage(buffer, _("Canceled"));
+                       return false;
+               }
+       }
+       return true;
+}
+
 void MenuMakeLaTeX(Buffer * buffer)
 {
        // Why care about this?
@@ -783,25 +815,18 @@ void MenuMakeLaTeX(Buffer * buffer)
        // Get LaTeX-Filename
        string s = buffer->getLatexName(false);
        
-       FileInfo fi(s);
-       if (fi.readable() &&
-           !AskQuestion(_("File already exists:"), 
-                        MakeDisplayPath(s, 50),
-                        _("Do you want to overwrite the file?"))) {
-               buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
-               return;
-       }
+       if (!AskOverwrite(buffer, s))
+               return; 
        
        if (buffer->isDocBook())
-               buffer->getUser()->owner()->getMiniBuffer()->Set(
-                       _("DocBook does not have a latex backend"));
+               ShowMessage(buffer, _("DocBook does not have a latex backend"));
        else {
                if (buffer->isLinuxDoc())
-                       RunLinuxDoc(0, buffer->fileName());
+                       RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
                else
                        buffer->makeLaTeXFile(s, string(), true);
-               buffer->getUser()->owner()->getMiniBuffer()->Set(
-                       _("Nice LaTeX file saved as"), MakeDisplayPath(s));
+               ShowMessage(buffer, _("Nice LaTeX file saved as"), 
+                           MakeDisplayPath(s));
                buffer->markDviDirty();
        }
 }
@@ -820,22 +845,16 @@ void MenuMakeLinuxDoc(Buffer * buffer)
        // Get LinuxDoc-Filename
        string s = ChangeExtension(buffer->fileName(), 
                                   ".sgml", false);
-       
-       FileInfo fi(s);
-       if (fi.readable() &&
-           !AskQuestion(_("File already exists:"), 
-                        MakeDisplayPath(s, 50),
-                        _("Do you want to overwrite the file?"))) {
-               buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
+
+       if (!AskOverwrite(buffer, s))
                return;
-       }
        
-       buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building LinuxDoc SGML file `"),
+       ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
                                          MakeDisplayPath(s),"'...");
        
        buffer->makeLinuxDocFile(s, 65);
        buffer->redraw();
-       buffer->getUser()->owner()->getMiniBuffer()->Set(_("LinuxDoc SGML file save as"),
+       ShowMessage(buffer, _("LinuxDoc SGML file save as"),
                                          MakeDisplayPath(s)); 
 }
 
@@ -854,22 +873,16 @@ void MenuMakeDocBook(Buffer * buffer)
        // Get DocBook-Filename
        string s = ChangeExtension(buffer->fileName(), 
                                   ".sgml", false);
-       
-       FileInfo fi(s);
-       if (fi.readable() &&
-           !AskQuestion(_("File already exists:"), 
-                        MakeDisplayPath(s, 50),
-                        _("Do you want to overwrite the file?"))) {
-               buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
+
+       if (!AskOverwrite(buffer, s))
                return;
-       }
        
-       buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
+       ShowMessage(buffer, _("Building DocBook SGML file `"),
                                          MakeDisplayPath(s), "'..."); 
        
        buffer->makeDocBookFile(s, 65);
        buffer->redraw();
-       buffer->getUser()->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
+       ShowMessage(buffer, _("DocBook SGML file save as"),
                                          MakeDisplayPath(s)); 
 }
 
@@ -883,18 +896,13 @@ void MenuMakeAscii(Buffer * buffer)
        string s = ChangeExtension (buffer->fileName(),
                                    ".txt", false);
        
-       FileInfo fi(s);
-       if (fi.readable() &&
-           !AskQuestion(_("File already exists:"), 
-                        MakeDisplayPath(s, 50),
-                        _("Do you want to overwrite the file?"))) {
-               buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
+
+       if (!AskOverwrite(buffer, s))
                return;
-       }
        
-       buffer->writeFileAscii(s, lyxrc->ascii_linelen);
+       buffer->writeFileAscii(s, lyxrc.ascii_linelen);
        
-       buffer->getUser()->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
+       ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
 }
 
 
@@ -905,7 +913,7 @@ void MenuPrint(Buffer * buffer)
        //      return;
 
        string input_file = ChangeExtension(buffer->fileName(),
-                                           lyxrc->print_file_extension,
+                                           lyxrc.print_file_extension,
                                            true);
        fl_set_input(fd_form_print->input_file, input_file.c_str());
        
@@ -932,16 +940,67 @@ void MenuMakeHTML(Buffer * buffer)
        // anything.
        string result = ChangeExtension(file, ".html", false);
        string infile = buffer->getLatexName(false);
-       string tmp = lyxrc->html_command;
+       string tmp = lyxrc.html_command;
+       tmp = subst(tmp, "$$FName", infile);
+       tmp = subst(tmp, "$$OutName", result);
+       Systemcalls one;
+       int res = one.startscript(Systemcalls::System, tmp);
+       if (res == 0) {
+               ShowMessage(buffer, _("Document exported as HTML to file `")
+                                                 + MakeDisplayPath(result) +'\'');
+       } else {
+               ShowMessage(buffer, _("Unable to convert to HTML the file `")
+                                                 + MakeDisplayPath(infile) 
+                                                 + '\'');
+       }
+
+}
+
+void MenuMakeHTML_LinuxDoc(Buffer * buffer)
+{
+       // First, create LinuxDoc file
+       MenuMakeLinuxDoc(buffer);
+
+       // And now, run the converter
+       string file = buffer->fileName();
+
+       string result = ChangeExtension(file, ".html", false);
+       string infile = ChangeExtension(file, ".sgml", false);
+       string tmp = lyxrc.linuxdoc_to_html_command;
+       tmp = subst(tmp, "$$FName", infile);
+       tmp = subst(tmp, "$$OutName", result);
+       Systemcalls one;
+       int res = one.startscript(Systemcalls::System, tmp);
+       if (res == 0) {
+               ShowMessage(buffer,_("Document exported as HTML to file `")
+                                                 + MakeDisplayPath(result) +'\'');
+       } else {
+               ShowMessage(buffer,_("Unable to convert to HTML the file `")
+                                                 + MakeDisplayPath(infile) 
+                                                 + '\'');
+       }
+
+}
+
+void MenuMakeHTML_DocBook(Buffer * buffer)
+{
+       // First, create LaTeX file
+       MenuMakeDocBook(buffer);
+
+       // And now, run the converter
+       string file = buffer->fileName();
+       string result = ChangeExtension(file, ".html", false);
+       string infile = ChangeExtension(file, ".sgml", false);
+       string tmp = lyxrc.docbook_to_html_command;
        tmp = subst(tmp, "$$FName", infile);
        tmp = subst(tmp, "$$OutName", result);
        Systemcalls one;
        int res = one.startscript(Systemcalls::System, tmp);
        if (res == 0) {
-               buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
+               ShowMessage(buffer,_("Document exported as HTML to file `")
                                                  + MakeDisplayPath(result) +'\'');
        } else {
-               buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
+               ShowMessage(buffer,_("Unable to convert to HTML the file `")
                                                  + MakeDisplayPath(infile) 
                                                  + '\'');
        }
@@ -972,10 +1031,10 @@ void MenuExport(Buffer * buffer, string const & extyp)
                // is achieved by temporarily disabling use of
                // temp directory. As a side-effect, we get
                // *.log and *.aux files also. (Asger)
-               bool flag = lyxrc->use_tempdir;
-               lyxrc->use_tempdir = false;
+               bool flag = lyxrc.use_tempdir;
+               lyxrc.use_tempdir = false;
                MenuRunLaTeX(buffer);
-               lyxrc->use_tempdir = flag;
+               lyxrc.use_tempdir = flag;
        }
        // postscript
        else if (extyp == "postscript") {
@@ -997,8 +1056,16 @@ void MenuExport(Buffer * buffer, string const & extyp)
        else if (extyp == "html") {
                MenuMakeHTML(buffer);
        }
+       // HTML from linuxdoc
+       else if (extyp == "html-linuxdoc") {
+               MenuMakeHTML_LinuxDoc(buffer);
+       }
+       // HTML from docbook
+       else if (extyp == "html-docbook") {
+               MenuMakeHTML_DocBook(buffer);
+       }
        else {
-               buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unknown export type: ") + extyp);
+               ShowMessage(buffer, _("Unknown export type: ") + extyp);
        }
 }
 
@@ -1010,7 +1077,7 @@ void QuitLyX()
        if (!bufferlist.QwriteAll())
                return;
 
-       lastfiles->writeFile(lyxrc->lastfiles);
+       lastfiles->writeFile(lyxrc.lastfiles);
 
        // Set a flag that we do quitting from the program,
        // so no refreshes are necessary.
@@ -1029,26 +1096,26 @@ void QuitLyX()
 
 
 
-void AutoSave()
+void AutoSave(BufferView * bv)
        // should probably be moved into BufferList (Lgb)
        // Perfect target for a thread...
 {
-       if (!current_view->getScreen() || !current_view->available())
+       if (!bv->available())
                return;
 
-       if (current_view->buffer()->isBakClean()
-           || current_view->buffer()->isReadonly()) {
+       if (bv->buffer()->isBakClean()
+           || bv->buffer()->isReadonly()) {
                // We don't save now, but we'll try again later
-               current_view->owner()->resetAutosaveTimer();
+               bv->owner()->resetAutosaveTimer();
                return;
        }
 
-       current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
+       bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
        
        // create autosave filename
-       string fname =  OnlyPath(current_view->buffer()->fileName());
+       string fname =  OnlyPath(bv->buffer()->fileName());
        fname += "#";
-       fname += OnlyFilename(current_view->buffer()->fileName());
+       fname += OnlyFilename(bv->buffer()->fileName());
        fname += "#";
        
        // tmp_ret will be located (usually) in /tmp
@@ -1064,7 +1131,7 @@ void AutoSave()
                // anyway.
                bool failed = false;
                if (!tmp_ret.empty()) {
-                       current_view->buffer()->writeFile(tmp_ret, 1);
+                       bv->buffer()->writeFile(tmp_ret, 1);
                        // assume successful write of tmp_ret
                        if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
                                failed = true;
@@ -1079,11 +1146,11 @@ void AutoSave()
                
                if (failed) {
                        // failed to write/rename tmp_ret so try writing direct
-                       if (!current_view->buffer()->writeFile(fname, 1)) {
+                       if (!bv->buffer()->writeFile(fname, 1)) {
                                // It is dangerous to do this in the child,
                                // but safe in the parent, so...
                                if (pid == -1)
-                                       current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
+                                       bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
                        }
                }
                if (pid == 0) { // we are the child so...
@@ -1091,13 +1158,13 @@ void AutoSave()
                }
        }
        
-       current_view->buffer()->markBakClean();
-       current_view->owner()->resetAutosaveTimer();
+       bv->buffer()->markBakClean();
+       bv->owner()->resetAutosaveTimer();
 }
 
 
 //
-// (c) CHT Software Service GmbH
+// Copyright CHT Software Service GmbH
 // Uwe C. Schroeder
 //
 // create new file with template
@@ -1130,19 +1197,19 @@ Buffer * NewLyxFile(string const & filename)
 
 
 // Insert ascii file (if filename is empty, prompt for one)
-void InsertAsciiFile(string const & f, bool asParagraph)
+void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
 {
        string fname = f;
        LyXFileDlg fileDlg;
  
-       if (!current_view->getScreen()) return;
+       if (!bv->available()) return;
      
        if (fname.empty()) {
-               ProhibitInput();
+               ProhibitInput(bv);
                fname = fileDlg.Select(_("File to Insert"), 
-                                      current_view->owner()->buffer()->filepath,
+                                      bv->owner()->buffer()->filepath,
                                       "*");
-               AllowInput();
+               AllowInput(bv);
                if (fname.empty()) return;
        }
 
@@ -1160,27 +1227,24 @@ void InsertAsciiFile(string const & f, bool asParagraph)
                             MakeDisplayPath(fname, 50));
                return;
        }
-       LyXParagraph * tmppar = new LyXParagraph;
-       tmppar->readSimpleWholeFile(ifs);
-       
-       // set the end of the string
-#ifdef WITH_WARNINGS
-#warning why do we do this?
-#endif
-       // I don't think this is needed. Actually it might be plain wrong.
-       tmppar->InsertChar(tmppar->text.size() - 1, '\0');
 
+       ifs.unsetf(ios::skipws);
+       istream_iterator<char> ii(ifs);
+       istream_iterator<char> end;
+       //string tmpstr(ii, end); // yet a reason for using std::string
+       // alternate approach to get the file into a string:
+       string tmpstr;
+       copy(ii, end, back_inserter(tmpstr));
        // insert the string
-       current_view->getScreen()->HideCursor();
+       current_view->hideCursor();
        
        // clear the selection
-       current_view->beforeChange();
+       bv->beforeChange();
        if (!asParagraph)
-               current_view->text->InsertStringA(tmppar->text);
+               bv->text->InsertStringA(tmpstr);
        else
-               current_view->text->InsertStringB(tmppar->text);
-       delete tmppar;
-       current_view->update(1);
+               bv->text->InsertStringB(tmpstr);
+       bv->update(1);
 }
 
 
@@ -1207,7 +1271,7 @@ void MenuShowTableOfContents()
 void MenuInsertLabel(char const * arg)
 {
        string label = arg;
-       ProhibitInput();
+       ProhibitInput(current_view);
        if (label.empty()) {
                pair<bool, string>
                        result = askForText(_("Enter new label to insert:"));
@@ -1220,7 +1284,7 @@ void MenuInsertLabel(char const * arg)
                new_inset->setContents(label);
                current_view->insertInset(new_inset);
        }
-       AllowInput();
+       AllowInput(current_view);
 }
 
 
@@ -1246,7 +1310,7 @@ void MenuInsertRef()
 
 void MenuPasteSelection(char at)
 {
-       if (!current_view->getScreen())
+       if (!current_view->available())
                return;
 
        ascii_type = at;
@@ -1271,7 +1335,7 @@ void Foot(BufferView * bv)
        
        bv->owner()->getMiniBuffer()
                ->Set(_("Inserting Footnote..."));
-       bv->getScreen()->HideCursor();
+       bv->hideCursor();
        bv->update(-2);
        bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
        bv->update(1);
@@ -1290,81 +1354,67 @@ void LayoutsCB(int sel, void *)
 
 /*
  * SGML Linuxdoc support:
- * (flag == -1) import SGML file
  * (flag == 0) make TeX output
  * (flag == 1) make dvi output
  */
-int RunLinuxDoc(int flag, string const & filename)
+int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
 {
-       string name;
        string s2;
-       string path;
        string add_flags;
 
        int errorcode = 0;
 
        /* generate a path-less extension name */
-       name = ChangeExtension (filename, ".sgml", true);
-       path = OnlyPath (filename);
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
-               path = current_view->buffer()->tmppath;
+       string name = ChangeExtension (filename, ".sgml", true);
+       string path = OnlyPath (filename);
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
+               path = bv->buffer()->tmppath;
        }
        Path p(path);
        
-       if (flag != -1) {
-               if (!current_view->available())
-                       return 0;
-               current_view->buffer()->makeLinuxDocFile(name, 0);
+       if (!bv->available())
+               return 0;
+       bv->buffer()->makeLinuxDocFile(name, 0);
 #ifdef WITH_WARNINGS
 #warning remove this once we have a proper geometry class
 #endif
-               BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
-               switch (ps) {
-               case BufferParams::PAPER_A4PAPER:
-                       add_flags = "-p a4";
-                       break;
-               case BufferParams::PAPER_USLETTER:
-                       add_flags = "-p letter";
-                       break;
-               default: /* nothing to be done yet ;-) */     break; 
-               }
+       BufferParams::PAPER_SIZE ps =
+               static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
+       switch (ps) {
+       case BufferParams::PAPER_A4PAPER:
+               add_flags = "-p a4";
+               break;
+       case BufferParams::PAPER_USLETTER:
+               add_flags = "-p letter";
+               break;
+       default: /* nothing to be done yet ;-) */     break; 
        }
        
-       ProhibitInput();
+       ProhibitInput(bv);
        
        Systemcalls one;
        switch (flag) {
-       case -1: /* Import file */
-               current_view->owner()->getMiniBuffer()->Set(_("Importing LinuxDoc SGML file `"), 
-                               MakeDisplayPath(filename), "'...");
-               s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' ' 
-                       + name;
-               if (one.startscript(Systemcalls::System, s2)) 
-                       errorcode = 1;
-               break;
        case 0: /* TeX output asked */
-               current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
-               s2 = "sgml2latex " + add_flags + " -o tex "
-                       + lyxrc->sgml_extra_options + ' ' + name;
+             bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
+               s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
                if (one.startscript(Systemcalls::System, s2)) 
                        errorcode = 1;
                break;
        case 1: /* dvi output asked */
-               current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
-               s2 = "sgml2latex " + add_flags + " -o dvi "
-                       + lyxrc->sgml_extra_options + ' ' + name;
+               bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
+               s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
                if (one.startscript(Systemcalls::System, s2)) {
                        errorcode = 1;
                } else
-                       current_view->buffer()->markDviClean();
+                       bv->buffer()->markDviClean();
                break;
        default: /* unknown output */
                break;
        }
        
-       AllowInput();
+       AllowInput(bv);
 
-        current_view->buffer()->redraw();
+        bv->buffer()->redraw();
        return errorcode;
 }
 
@@ -1378,7 +1428,7 @@ int RunDocBook(int flag, string const & filename)
        /* generate a path-less extension name */
        string name = ChangeExtension (filename, ".sgml", true);
        string path = OnlyPath (filename);
-       if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = current_view->buffer()->tmppath;
        }
        Path p(path);
@@ -1389,6 +1439,7 @@ int RunDocBook(int flag, string const & filename)
        current_view->buffer()->makeDocBookFile(name, 0);
 
        // Shall this code go or should it stay? (Lgb)
+       // This code is a placeholder for future implementation. (Jose')
 //     string add_flags;
 //     LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
 //     switch (ps) {
@@ -1396,7 +1447,7 @@ int RunDocBook(int flag, string const & filename)
 //     case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
 //     default: /* nothing to be done yet ;-) */     break; 
 //     }
-       ProhibitInput();
+       ProhibitInput(current_view);
        
        int errorcode = 0;
        Systemcalls one;
@@ -1404,7 +1455,7 @@ int RunDocBook(int flag, string const & filename)
        case 1: /* dvi output asked */
        {
                current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
-               string s2 = "sgmltools --backend dvi " + name;
+               string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
                if (one.startscript(Systemcalls::System, s2)) {
                        errorcode = 1;
                } else
@@ -1415,7 +1466,7 @@ int RunDocBook(int flag, string const & filename)
                break;
        }
        
-       AllowInput();
+       AllowInput(current_view);
 
         current_view->buffer()->redraw();
        return errorcode;
@@ -1441,7 +1492,8 @@ void MenuLayoutCharacter()
 }
 
 
-inline void DeactivateParagraphButtons ()
+inline
+void DeactivateParagraphButtons ()
 {
        fl_deactivate_object (fd_form_paragraph->button_ok);
        fl_deactivate_object (fd_form_paragraph->button_apply);
@@ -1450,7 +1502,8 @@ inline void DeactivateParagraphButtons ()
 }
 
 
-inline void ActivateParagraphButtons ()
+inline
+void ActivateParagraphButtons ()
 {
        fl_activate_object (fd_form_paragraph->button_ok);
        fl_activate_object (fd_form_paragraph->button_apply);
@@ -1459,7 +1512,8 @@ inline void ActivateParagraphButtons ()
 }
 
 
-inline void DisableParagraphLayout ()
+inline
+void DisableParagraphLayout ()
 {
         DeactivateParagraphButtons();
        fl_deactivate_object (fd_form_paragraph->input_labelwidth);
@@ -1482,7 +1536,8 @@ inline void DisableParagraphLayout ()
 }
 
 
-inline void EnableParagraphLayout ()
+inline
+void EnableParagraphLayout ()
 {
         ActivateParagraphButtons();
        fl_activate_object (fd_form_paragraph->input_labelwidth);
@@ -1507,7 +1562,7 @@ inline void EnableParagraphLayout ()
 
 bool UpdateLayoutParagraph()
 {
-       if (!current_view->getScreen() || !current_view->available()) {
+       if (!current_view->available()) {
                if (fd_form_paragraph->form_paragraph->visible) 
                        fl_hide_form(fd_form_paragraph->form_paragraph);
                return false;
@@ -1731,7 +1786,7 @@ void EnableDocumentLayout ()
 
 bool UpdateLayoutDocument(BufferParams * params)
 {
-       if (!current_view->getScreen() || !current_view->available()) {
+       if (!current_view->available()) {
                if (fd_form_document->form_document->visible) 
                        fl_hide_form(fd_form_document->form_document);
                return false;
@@ -1822,6 +1877,7 @@ bool UpdateLayoutDocument(BufferParams * params)
    
        fl_set_input(fd_form_document->input_spacing, "");
        switch (params->spacing.getSpace()) {
+       case Spacing::Default: // nothing bad should happen with this
        case Spacing::Single:
        {
                // \singlespacing
@@ -1843,9 +1899,19 @@ bool UpdateLayoutDocument(BufferParams * params)
        case Spacing::Other:
        {
                fl_set_choice(fd_form_document->choice_spacing, 4);
-               char sval[20];
-               sprintf(sval, "%g", params->spacing.getValue()); 
-               fl_set_input(fd_form_document->input_spacing, sval);
+               //char sval[20];
+               //sprintf(sval, "%g", params->spacing.getValue()); 
+#ifdef HAVE_SSTREAM
+               std::ostringstream sval;
+               sval << params->spacing.getValue(); // setw?
+               fl_set_input(fd_form_document->input_spacing,
+                            sval.str().c_str());
+#else
+               char tval[20];
+               ostrstream sval(tval, 20);
+               sval << params->spacing.getValue() << '\0'; // setw?
+               fl_set_input(fd_form_document->input_spacing, sval.str());
+#endif
                break;
        }
        }
@@ -1905,8 +1971,7 @@ void MenuLayoutDocument()
 bool UpdateLayoutQuotes()
 {
        bool update = true;
-       if (!current_view->getScreen()
-           || !current_view->available()
+       if (!current_view->available()
            || current_view->buffer()->isReadonly())
                update = false;
        
@@ -1944,7 +2009,7 @@ void MenuLayoutQuotes()
 bool UpdateLayoutPreamble()
 {
        bool update = true;
-       if (!current_view->getScreen() || ! current_view->available())
+       if (!current_view->available())
                update = false;
 
        if (update) {
@@ -1997,7 +2062,7 @@ void MenuLayoutPreamble()
 
 void MenuLayoutSave()
 {
-       if (!current_view->getScreen() || ! current_view->available())
+       if (!current_view->available())
                return;
 
        if (AskQuestion(_("Do you want to save the current settings"),
@@ -2014,89 +2079,93 @@ static
 void ToggleAndShow(BufferView *, LyXFont const &);
 
 
-void FontSize(string const & size)
+void FontSize(BufferView * bv, string const & size)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setGUISize(size);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
-void Emph()
+void Emph(BufferView * bv)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setEmph(LyXFont::TOGGLE);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
-void Noun()
+void Noun(BufferView * bv)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setNoun(LyXFont::TOGGLE);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
-void Bold()
+void Bold(BufferView * bv)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setSeries(LyXFont::BOLD_SERIES);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
-void Underline()
+void Underline(BufferView * bv)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setUnderbar(LyXFont::TOGGLE);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
-void Code()
+void Code(BufferView * bv)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
-void Sans()
+void Sans(BufferView * bv)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setFamily(LyXFont::SANS_FAMILY);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
-void Roman()
+void Roman(BufferView * bv)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setFamily(LyXFont::ROMAN_FAMILY);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
-void Tex()
+void Tex(BufferView * bv)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
        font.setLatex (LyXFont::TOGGLE);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
-void RTLCB()
+void Lang(BufferView * bv, string const & l)
 {
        LyXFont font(LyXFont::ALL_IGNORE);
-       font.setDirection (LyXFont::TOGGLE_DIR);
-       ToggleAndShow(current_view, font);
+       Languages::iterator lit = languages.find(l);
+       if (lit != languages.end()) {
+               font.setLanguage(&(*lit).second);
+               ToggleAndShow(bv, font);
+       } else
+               WriteAlert(_("Error! unknown language"),l);
 }
 
 
-void StyleReset()
+void StyleReset(BufferView * bv)
 {
-       LyXFont font(LyXFont::ALL_INHERIT);
-       ToggleAndShow(current_view, font);
+       LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
+       ToggleAndShow(bv, font);
 }
 
 
@@ -2104,27 +2173,54 @@ void StyleReset()
  * future perhaps we could try to implement a callback to the button-bar.
  * That is, `light' the bold button when the font is currently bold, etc.
  */
-string CurrentState()
+string CurrentState(BufferView * bv)
 {
        string state;
-       if (current_view->available()) { 
+       if (bv->available()) { 
                // I think we should only show changes from the default
                // font. (Asger)
-               Buffer * buffer = current_view->buffer();
-               LyXFont font = current_view->text->real_current_font;
+               Buffer * buffer = bv->buffer();
+               LyXFont font = bv->text->real_current_font;
                LyXFont defaultfont = textclasslist.TextClass(buffer->
                                                              params.textclass).defaultfont();
                font.reduce(defaultfont);
                state = _("Font: ") + font.stateText();
-
-               int depth = current_view->text->GetDepth();
+               // The paragraph depth
+               int depth = bv->text->GetDepth();
                if (depth > 0) 
                        state += string(_(", Depth: ")) + tostr(depth);
+               // The paragraph spacing, but only if different from
+               // buffer spacing.
+               if (!bv->text->cursor.par->spacing.isDefault()) {
+                       Spacing::Space cur_space =
+                               bv->text->cursor.par->spacing.getSpace();
+                       state += _(", Spacing: ");
+                       switch (cur_space) {
+                       case Spacing::Single:
+                               state += _("Single");
+                               break;
+                       case Spacing::Onehalf:
+                               state += _("Onehalf");
+                               break;
+                       case Spacing::Double:
+                               state += _("Double");
+                               break;
+                       case Spacing::Other:
+                               state += _("Other (");
+                               state += tostr(bv->text->cursor.par->spacing.getValue());
+                               state += ")";
+                               break;
+                       case Spacing::Default:
+                               // should never happen, do nothing
+                               break;
+                       }
+               }
        }
        return state;
 }
 
 
+
 // candidate for move to BufferView
 /* -------> Does the actual toggle job of the XxxCB() calls above.
  * Also shows the current font state.
@@ -2133,9 +2229,12 @@ static
 void ToggleAndShow(BufferView * bv, LyXFont const & font)
 {
        if (bv->available()) { 
-               bv->getScreen()->HideCursor();
+               bv->hideCursor();
                bv->update(-2);
-               bv->text->ToggleFree(font, toggleall);
+               if (bv->the_locking_inset)
+                       bv->the_locking_inset->SetFont(bv, font, toggleall);
+               else
+                       bv->text->ToggleFree(font, toggleall);
                bv->update(1);
        }
 }
@@ -2146,7 +2245,7 @@ void Margin(BufferView * bv)
 {
        if (bv->available()) {
                bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
-               bv->getScreen()->HideCursor();
+               bv->hideCursor();
                bv->update(-2);
                bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
                bv->update(1);
@@ -2184,7 +2283,7 @@ void Melt(BufferView * bv)
        if (!bv->available()) return;
        
        bv->owner()->getMiniBuffer()->Set(_("Melt"));
-       bv->getScreen()->HideCursor();
+       bv->hideCursor();
        bv->beforeChange();
        bv->update(-2);
        bv->text->MeltFootnoteEnvironment();
@@ -2200,7 +2299,7 @@ void changeDepth(BufferView * bv, int decInc)
 {
        if (!bv->available()) return;
        
-       bv->getScreen()->HideCursor();
+       bv->hideCursor();
        bv->update(-2);
        if (decInc >= 0)
                bv->text->IncDepth();
@@ -2283,7 +2382,6 @@ LyXFont UserFreeFont()
        }
 
        pos = fl_get_choice(fd_form_character->choice_color);
-#ifdef USE_PAINTER
        switch(pos) {
        case 1: font.setColor(LColor::ignore); break;
        case 2: font.setColor(LColor::none); break;
@@ -2297,28 +2395,14 @@ LyXFont UserFreeFont()
        case 10: font.setColor(LColor::yellow); break;
        case 11: font.setColor(LColor::inherit); break;
        }
-#else
-       switch(pos) {
-       case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
-       case 2: font.setColor(LyXFont::NONE); break;
-       case 3: font.setColor(LyXFont::BLACK); break;
-       case 4: font.setColor(LyXFont::WHITE); break;
-       case 5: font.setColor(LyXFont::RED); break;
-       case 6: font.setColor(LyXFont::GREEN); break;
-       case 7: font.setColor(LyXFont::BLUE); break;
-       case 8: font.setColor(LyXFont::CYAN); break;
-       case 9: font.setColor(LyXFont::MAGENTA); break;
-       case 10: font.setColor(LyXFont::YELLOW); break;
-       case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
-       }
-#endif
+
        return font; 
 }
 
 
-void Free()
+void Free(BufferView * bv)
 {
-       ToggleAndShow(current_view, UserFreeFont());
+       ToggleAndShow(bv, UserFreeFont());
 }
 
 
@@ -2326,7 +2410,7 @@ void Free()
 extern "C" void TimerCB(FL_OBJECT *, long)
 {
        // only if the form still exists
-       if (fd_form_title->form_title != 0) {
+       if (lyxrc.show_banner && fd_form_title->form_title != 0) {
                if (fd_form_title->form_title->visible) {
                        fl_hide_form(fd_form_title->form_title);
                }
@@ -2531,7 +2615,7 @@ void UpdateDocumentButtons(BufferParams const & params)
 
 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
 {
-       ProhibitInput();
+       ProhibitInput(current_view);
        if (textclasslist.Load(fl_get_choice(ob)-1)) {
                if (AskQuestion(_("Should I set some parameters to"),
                                fl_get_choice_text(ob),
@@ -2550,7 +2634,7 @@ extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
                fl_set_choice(fd_form_document->choice_class, 
                              current_view->buffer()->params.textclass + 1);
        }
-       AllowInput();
+       AllowInput(current_view);
 }
 
 
@@ -2609,8 +2693,26 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long)
 {
        bool redo = false;
        BufferParams * params = &(current_view->buffer()->params);
-       current_view->buffer()->params.language = 
-               combo_language->getline();
+
+       Language const * old_language = params->language_info;
+       Language const * new_language;
+       params->language = combo_language->getline();
+       Languages::iterator lit = languages.find(params->language);
+       if (lit != languages.end()) 
+               new_language = &(*lit).second;
+       else
+               new_language = default_language;
+
+       if (current_view->available()) {
+               if (old_language != new_language &&
+                   old_language->RightToLeft == new_language->RightToLeft && 
+                   ! current_view->buffer()->isMultiLingual() ) {
+                       current_view->buffer()->ChangeLanguage(old_language,
+                                                              new_language);
+                       current_view->buffer()->redraw();
+               }
+       }
+       params->language_info = new_language;
 
        // If default skip is a "Length" but there's no text in the
        // input field, reset the kind to "Medskip", which is the default.
@@ -2639,11 +2741,10 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long)
    
        if (!current_view->available())
                return;
-       if (lyxrc->rtl_support) {
-               current_view->text->SetCursor(current_view->text->cursor.par,
-                                             current_view->text->cursor.pos);
-               current_view->SetState();
-       }
+
+        current_view->text->SetCursor(current_view->text->cursor.par,
+                                      current_view->text->cursor.pos);
+        current_view->setState();
 
        LyXTextClassList::ClassList::size_type new_class =
                fl_get_choice(fd_form_document->choice_class) - 1;
@@ -2653,13 +2754,13 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long)
                if (textclasslist.Load(new_class)) {
                        // successfully loaded
                        redo = true;
-                       current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
-                       int ret = current_view->text->
-                               SwitchLayoutsBetweenClasses(current_view->buffer()->
-                                                           params.textclass,
-                                                           new_class,
-                                                           current_view->buffer()->
-                                                           paragraph);
+                       current_view->owner()->getMiniBuffer()->
+                               Set(_("Converting document to new document class..."));
+                       CutAndPaste cap;
+                       int ret = cap.SwitchLayoutsBetweenClasses(
+                               current_view->buffer()->params.textclass,
+                               new_class,
+                               current_view->buffer()->paragraph);
 
                        if (ret) {
                                string s;
@@ -2869,7 +2970,7 @@ extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
 
 extern "C" void TableApplyCB(FL_OBJECT *, long)
 {
-       if (!current_view->getScreen())
+       if (!current_view->available())
                return;
    
        // check for tables in tables
@@ -2886,7 +2987,7 @@ extern "C" void TableApplyCB(FL_OBJECT *, long)
        int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
    
    
-       current_view->getScreen()->HideCursor();
+       current_view->hideCursor();
        current_view->beforeChange();
        current_view->update(-2);
    
@@ -2935,15 +3036,20 @@ extern "C" void TableApplyCB(FL_OBJECT *, long)
        current_view->text->cursor.par->table =
                new LyXTable(xsize, ysize);
 
-       for (int i = 0; i < xsize * ysize - 1; ++i)
+       Language const * lang = 
+               current_view->text->cursor.par->getParLanguage();
+       LyXFont font(LyXFont::ALL_INHERIT,lang);
+       for (int i = 0; i < xsize * ysize - 1; ++i) {
                current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
+               current_view->text->cursor.par->SetFont(0, font);
+       }
        current_view->text->RedoParagraph();
    
        current_view->text->UnFreezeUndo();
      
        current_view->update(1);
        current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
-       current_view->SetState();
+       current_view->setState();
 }
 
 
@@ -2971,9 +3077,13 @@ extern "C" void PrintCancelCB(FL_OBJECT *, long)
 static
 bool stringOnlyContains (string const & LStr, char const * cset)
 {
-       char const * cstr = LStr.c_str() ;
+#if 0
+       char const * cstr = LStr.c_str();
 
-       return strspn(cstr, cset) == strlen(cstr) ;
+       return strspn(cstr, cset) == strlen(cstr);
+#else
+       return LStr.find_first_not_of(cset) == string::npos;
+#endif
 }
 
 
@@ -2986,9 +3096,9 @@ extern "C" void PrintApplyCB(FL_OBJECT *, long)
 
        string pageflag;
        if (fl_get_button(fd_form_print->radio_even_pages))
-               pageflag = lyxrc->print_evenpage_flag + ' ';
+               pageflag = lyxrc.print_evenpage_flag + ' ';
        else if (fl_get_button(fd_form_print->radio_odd_pages))
-               pageflag = lyxrc->print_oddpage_flag + ' ';
+               pageflag = lyxrc.print_oddpage_flag + ' ';
 
 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
 // User may give a page (range) list
@@ -3007,13 +3117,13 @@ extern "C" void PrintApplyCB(FL_OBJECT *, long)
                        return;
                }
                if (piece.find('-') == string::npos) { // not found
-                       pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
+                       pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
                } else if (suffixIs(piece, "-") ) { // missing last page
-                       pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
+                       pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
                } else if (prefixIs(piece, "-") ) { // missing first page
-                       pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
+                       pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
                } else {
-                       pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
+                       pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
                }
        }
    
@@ -3025,39 +3135,39 @@ extern "C" void PrintApplyCB(FL_OBJECT *, long)
                        return;
                }
                if (fl_get_button(fd_form_print->do_unsorted))
-                       pageflag += lyxrc->print_copies_flag;
+                       pageflag += lyxrc.print_copies_flag;
                else
-                       pageflag += lyxrc->print_collcopies_flag;
+                       pageflag += lyxrc.print_collcopies_flag;
                pageflag += " " + copies + ' ' ;
        }
 
        string reverseflag;
        if (fl_get_button(fd_form_print->radio_order_reverse))
-               reverseflag = lyxrc->print_reverse_flag + ' ';
+               reverseflag = lyxrc.print_reverse_flag + ' ';
    
        string orientationflag;
        if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
-               orientationflag = lyxrc->print_landscape_flag + ' ';
+               orientationflag = lyxrc.print_landscape_flag + ' ';
    
        string ps_file = fl_get_input(fd_form_print->input_file);
        string printer = strip(fl_get_input(fd_form_print->input_printer));
 
        string printerflag;
-       if (lyxrc->print_adapt_output // printer name should be passed to dvips
+       if (lyxrc.print_adapt_output // printer name should be passed to dvips
            && ! printer.empty()) // a printer name has been given
-               printerflag = lyxrc->print_to_printer + printer + ' ';
+               printerflag = lyxrc.print_to_printer + printer + ' ';
      
        string extraflags;
-       if (!lyxrc->print_extra_options.empty())
-               extraflags = lyxrc->print_extra_options + ' ';
+       if (!lyxrc.print_extra_options.empty())
+               extraflags = lyxrc.print_extra_options + ' ';
 
-       string command = lyxrc->print_command + ' ' 
+       string command = lyxrc.print_command + ' ' 
                + printerflag + pageflag + reverseflag 
                + orientationflag + extraflags;
  
        char real_papersize = buffer->params.papersize;
        if (real_papersize == BufferParams::PAPER_DEFAULT)
-               real_papersize = lyxrc->default_papersize;
+               real_papersize = lyxrc.default_papersize;
        
         string paper;
        switch (real_papersize) {
@@ -3088,39 +3198,39 @@ extern "C" void PrintApplyCB(FL_OBJECT *, long)
 
        if (buffer->params.use_geometry
            && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
-           && !lyxrc->print_paper_dimension_flag.empty()
+           && !lyxrc.print_paper_dimension_flag.empty()
            && !buffer->params.paperwidth.empty()
            && !buffer->params.paperheight.empty()) {
                // using a custom papersize
                command += ' ';
-               command += lyxrc->print_paper_dimension_flag + ' ';
+               command += lyxrc.print_paper_dimension_flag + ' ';
                command += buffer->params.paperwidth + ',';
                command += buffer->params.paperheight + ' ';
-       } else if (!lyxrc->print_paper_flag.empty()
+       } else if (!lyxrc.print_paper_flag.empty()
                   && !paper.empty()
                   && (real_papersize != BufferParams::PAPER_USLETTER ||
                       buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
-               command += " " + lyxrc->print_paper_flag + " " + paper + " ";
+               command += " " + lyxrc.print_paper_flag + " " + paper + " ";
        }
        if (fl_get_button(fd_form_print->radio_file))
-               command += lyxrc->print_to_file 
+               command += lyxrc.print_to_file 
                        + QuoteName(MakeAbsPath(ps_file, path));
-       else if (!lyxrc->print_spool_command.empty())
-               command += lyxrc->print_to_file 
+       else if (!lyxrc.print_spool_command.empty())
+               command += lyxrc.print_to_file 
                        + QuoteName(ps_file);
        
        // push directorypath, if necessary 
-        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
+        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
                path = buffer->tmppath;
         }
         Path p(path);
 
        bool result;
-       if (!lyxrc->print_spool_command.empty() && 
+       if (!lyxrc.print_spool_command.empty() && 
            !fl_get_button(fd_form_print->radio_file)) {
-               string command2 = lyxrc->print_spool_command + ' ';
+               string command2 = lyxrc.print_spool_command + ' ';
                if (!printer.empty())
-                       command2 += lyxrc->print_spool_printerprefix 
+                       command2 += lyxrc.print_spool_printerprefix 
                                + printer;
                // First run dvips and, if succesful, then spool command
                if ((result = RunScript(buffer, true, command))) {
@@ -3159,11 +3269,11 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long)
                InsetFig * new_inset = new InsetFig(100, 20, buffer);
                current_view->insertInset(new_inset);
                current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
-               new_inset->Edit(0, 0);
+               new_inset->Edit(current_view, 0, 0, 0);
                return;
        }
        
-       current_view->getScreen()->HideCursor();
+       current_view->hideCursor();
        current_view->update(-2);
        current_view->beforeChange();
       
@@ -3208,11 +3318,11 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long)
       
        Inset * new_inset = new InsetFig(100, 100, buffer);
        current_view->insertInset(new_inset);
-       new_inset->Edit(0, 0);
+       new_inset->Edit(current_view, 0, 0, 0);
        current_view->update(0);
        current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
        current_view->text->UnFreezeUndo();
-       current_view->SetState();
+       current_view->setState();
 }
 
 
@@ -3231,11 +3341,11 @@ extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
 
 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
 {
-       lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
-       lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
-       lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
-       lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
-       lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
+       lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
+       lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
+       lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
+       lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
+       lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
        fontloader.update();
    
        // All buffers will need resize
@@ -3288,7 +3398,7 @@ void Reconfigure(BufferView * bv)
                        AddName(system_lyxdir, "configure"));
        p.pop();
        bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
-       lyxrc->read(LibFileSearch(string(), "lyxrc.defaults"));
+       lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
        WriteAlert(_("The system has been reconfigured."), 
                   _("You need to restart LyX to make use of any"),
                   _("updated document class specifications."));
@@ -3554,84 +3664,3 @@ extern "C" void RefHideCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_ref->form_ref);
 }
-
-
-// candidate for move to BufferView
-void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty)
-{
-       if (!inset)
-               return;
-
-       /* very first check for locking insets*/
-       if (bv->the_locking_inset == inset) {
-               if (bv->text->UpdateInset(inset)){
-                       bv->update();
-                       if (mark_dirty){
-                               if (bv->buffer()->isLyxClean())
-                                       bv->owner()->getMiniBuffer()->setTimer(4);
-                               bv->buffer()->markDirty();
-                       }
-                       bv->updateScrollbar();
-                       return;
-               }
-       }
-  
-       /* first check the current buffer */
-       if (bv->available()) {
-               bv->getScreen()->HideCursor();
-               bv->update(-3);
-               if (bv->text->UpdateInset(inset)){
-                       if (mark_dirty)
-                               bv->update(1);
-                       else 
-                               bv->update(3);
-                       return;
-               }
-       }
-  
-       // check all buffers
-       bufferlist.updateInset(inset, mark_dirty);
-
-}
-
-
-void PutInsetIntoInsetUpdateList(Inset * inset)
-{
-       Assert(inset);
-       InsetUpdateStruct * tmp = new InsetUpdateStruct();
-       tmp->inset = inset;
-       tmp->next = InsetUpdateList;
-       InsetUpdateList = tmp;
-}
-
-
-void UpdateInsetUpdateList()
-{
-       InsetUpdateStruct * tmp = InsetUpdateList;
-       while (tmp) {
-               UpdateInset(current_view, tmp->inset, false); // "false" because no document change
-               tmp = tmp->next;
-       }
-  
-       // delete the update list
-       while (InsetUpdateList) {
-               tmp = InsetUpdateList;
-               InsetUpdateList = InsetUpdateList->next;
-               delete tmp;
-       }
-       InsetUpdateList = 0;
-}
-
-
-#ifdef WITH_WARNINGS
-#warning UGLY!!
-#endif
-// I know we shouldn't put anything in here but this seems the fastest
-// way to do this (and the cleanest for now). This function just inserts
-// a newline in the string and the inserts 'depth'-spaces so that the
-// code is indented in the right way!!!
-void addNewlineAndDepth(string & file, int const depth)
-{
-       file += '\n';
-       file.append(depth, ' ');
-}