]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
white-space changes, removed definitions.h several enum changes because of this,...
[lyx.git] / src / lyx_cb.C
index 4e9e78d556dd2058619d9f566d9d0b2aab07405d..062287c4da2804d26956507118a62fc5dba9265e 100644 (file)
@@ -1,12 +1,12 @@
 /* This file is part of
- * ======================================================
+ * ====================================================== 
  * 
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich,
  *          Copyright 1995-1999 The LyX Team.
  *
- * ======================================================*/
+ * ====================================================== */
 
 #include <config.h>
 
@@ -17,6 +17,7 @@
 #include <cstdlib>
 
 #include "LString.h"
+#include "support/lstrings.h"
 #include "lyx_main.h"
 #include FORMS_H_LOCATION
 #include "lyx.h"
@@ -30,7 +31,9 @@
 #include "credits.h"
 #include "insets/insetref.h"
 #include "insets/insetquotes.h"
+#if 0
 #include "insets/insetlatex.h"
+#endif
 #include "insets/insetlabel.h"
 #include "insets/insetinfo.h"
 #include "insets/insetspecialchar.h"
@@ -42,7 +45,7 @@
 #include "combox.h"
 #include "bufferlist.h"
 #include "support/filetools.h"
-#include "pathstack.h"
+#include "support/path.h"
 #include "filedlg.h"
 #include "lyx_gui_misc.h"
 #include "LyXView.h" // only because of form_main
@@ -57,6 +60,7 @@
 #include "lyxrc.h"
 #include "lyxtext.h"
 #include "gettext.h"
+#include "layout.h"
 
 extern MiniBuffer *minibuffer;
 extern Combox *combo_language;
@@ -194,7 +198,7 @@ unsigned char GetCurrentTextClass()
        // Shouldn't this question be directed to the buffer?
        // Indeed it should. Asger.
 {
-       return current_view->currentBuffer()->params.textclass;
+       return current_view->buffer()->params.textclass;
 }
 
 
@@ -290,7 +294,7 @@ void SetUpdateTimer(float time)
 void BeforeChange()
 {
        current_view->getScreen()->ToggleSelection();
-       current_view->currentBuffer()->text->ClearSelection();
+       current_view->buffer()->text->ClearSelection();
        FreeUpdateTimer();
 }
 
@@ -300,24 +304,24 @@ void SmallUpdate(signed char f)
        current_view->getScreen()->SmallUpdate();
        if (current_view->getScreen()->TopCursorVisible()
            != current_view->getScreen()->first){
-               current_view->currentBuffer()->update(f);
+               current_view->buffer()->update(f);
                return;
        }
 
        current_view->fitCursor();
        current_view->updateScrollbar();
    
-       if (!current_view->currentBuffer()->text->selection)
-               current_view->currentBuffer()->text->sel_cursor = 
-                       current_view->currentBuffer()->text->cursor;
+       if (!current_view->buffer()->text->selection)
+               current_view->buffer()->text->sel_cursor = 
+                       current_view->buffer()->text->cursor;
 
-       if (f==1 || f==-1) {
-               if (current_view->currentBuffer()->isLyxClean()) {
-                       current_view->currentBuffer()->markDirty();
+       if (f == 1 || f == -1) {
+               if (current_view->buffer()->isLyxClean()) {
+                       current_view->buffer()->markDirty();
                        minibuffer->setTimer(4);
                }
                else {
-                       current_view->currentBuffer()->markDirty();
+                       current_view->buffer()->markDirty();
                }
        }
 }
@@ -339,7 +343,7 @@ void MenuWrite(Buffer* buf)
                string fname = buf->getFileName();
                string s = MakeAbsPath(fname);
                if (AskQuestion(_("Save failed. Rename and try again?"),
-                                MakeDisplayPath(s,50),
+                                MakeDisplayPath(s, 50),
                                 _("(If not, document is not saved.)"))) {
                        MenuWriteAs(buf);
                }
@@ -377,14 +381,14 @@ void MenuWriteAs(Buffer *buffer)
        }
 
        // Make sure the absolute filename ends with appropriate suffix
-       string s= MakeAbsPath(fname);
+       string s = MakeAbsPath(fname);
        if (!IsLyXFilename(s))
                s += ".lyx";
 
        // Same name as we have already?
        if (s == oldname) {
                if (!AskQuestion(_("Same name as document already has:"),
-                                MakeDisplayPath(s,50),
+                                MakeDisplayPath(s, 50),
                                 _("Save anyway?")))
                        return;
                // Falls through to name change and save
@@ -392,7 +396,7 @@ void MenuWriteAs(Buffer *buffer)
        // No, but do we have another file with this name open?
        else if (bufferlist.exists(s)) {
                if (AskQuestion(_("Another document with same name open!"),
-                               MakeDisplayPath(s,50),
+                               MakeDisplayPath(s, 50),
                                _("Replace with current document?")))
                        {
                                bufferlist.close(bufferlist.getBuffer(s));
@@ -410,7 +414,7 @@ void MenuWriteAs(Buffer *buffer)
        else {
                FileInfo myfile(s);
                if (myfile.isOK() && !AskQuestion(_("Document already exists:"), 
-                                                 MakeDisplayPath(s,50),
+                                                 MakeDisplayPath(s, 50),
                                                  _("Replace file?")))
                        return;
        }
@@ -424,30 +428,11 @@ void MenuWriteAs(Buffer *buffer)
        MenuWrite(buffer);
 }    
 
-#if 0
-extern bool gsworking();
-#endif
 
 int MenuRunLaTeX(Buffer *buffer)
 {
        int ret = 0;
 
-#if 0
-       if (gsworking()) {
-               WriteAlert(_("Sorry, can't do this while pictures are being rendered."),
-                          _("Please wait a few seconds for this to finish and try again."),
-                          _("(or kill runaway gs processes by hand and try again.)"));
-               return 1;
-       }
-       extern pid_t isp_pid; // from spellchecker.C
-       if(isp_pid != -1)
-       {
-         WriteAlert(_("Can't do this while the spellchecker is running."),
-           _("Stop the spellchecker first."));
-         return 1;
-       }
-#endif
-       
        if (buffer->isLinuxDoc())
                ret = RunLinuxDoc(1, buffer->getFileName());
        else if (buffer->isLiterate())
@@ -464,7 +449,7 @@ int MenuRunLaTeX(Buffer *buffer)
                        s = _("One error detected");
                        t = _("You should try to fix it.");
                } else {
-                       s += ret;
+                       s += tostr(ret);
                        s += _(" errors detected.");
                        t = _("You should try to fix them.");
                }
@@ -496,7 +481,7 @@ int MenuBuildProg(Buffer *buffer)
                        s = _("One error detected");
                        t = _("You should try to fix it.");
                } else {
-                       s += ret;
+                       s += tostr(ret);
                        s += _(" errors detected.");
                        t = _("You should try to fix them.");
                }
@@ -525,13 +510,13 @@ int MenuRunChktex(Buffer *buffer)
                        s = _("One warning found.");
                        t = _("Use 'Edit->Go to Error' to find it.");
                } else {
-                       s += ret;
+                       s += tostr(ret);
                        s += _(" warnings found.");
                        t = _("Use 'Edit->Go to Error' to find them.");
                }
                WriteAlert(_("Chktex run successfully"), s, t);
        } else {
-               WriteAlert(_("Error!"),_("It seems chktex does not work."));
+               WriteAlert(_("Error!"), _("It seems chktex does not work."));
        }
        return ret;
 }
@@ -549,9 +534,8 @@ int MakeDVIOutput(Buffer *buffer)
                path = buffer->tmppath;
        }
        if (!buffer->isDviClean()) {
-               PathPush(path);
+               Path p(path);
                ret = MenuRunLaTeX(buffer);
-               PathPop();
        }
        return ret;
 }
@@ -561,13 +545,13 @@ int MakeDVIOutput(Buffer *buffer)
 /* wait == true means wait for termination       */
 // The bool should be placed last on the argument line. (Lgb)
 // Returns false if we fail.
-bool RunScript(Buffer *buffer, bool wait,
+bool RunScript(Buffer * buffer, bool wait,
               string const & command, string const & orgname = string(),
-              bool need_shell=true)
+              bool need_shell = true)
 {
        string path;
        string cmd;
-       string name= orgname;
+       string name = orgname;
        int result = 0;
        
        if (MakeDVIOutput(buffer) > 0)
@@ -581,7 +565,7 @@ bool RunScript(Buffer *buffer, bool wait,
        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
        }
-       PathPush(path);
+       Path p(path);
 
        cmd = command + ' ' + SpaceLess(name);
        Systemcalls one;
@@ -601,8 +585,9 @@ bool RunScript(Buffer *buffer, bool wait,
                                if (sh.empty())
                                        sh = "cmd.exe";
                        }
-                        sh = lowercase(sh);
-                        if (sh.contains("cmd.exe") || sh.contains("4os2.exe"))
+                        sh = lowercase(sh);
+                        if (contains(sh, "cmd.exe")
+                           || contains(sh, "4os2.exe"))
                                 cmd = "start /min/n " + cmd;
                         else
                                 cmd += " &";
@@ -622,13 +607,12 @@ bool RunScript(Buffer *buffer, bool wait,
                result = one.startscript(wait ? Systemcalls::Wait
                                        : Systemcalls::DontWait, cmd);
        }
-       PathPop();
-       return (result==0);
+       return (result == 0);
 }
 
 
 // Returns false if we fail
-bool MenuRunDvips(Buffer *buffer, bool wait=false)
+bool MenuRunDvips(Buffer *buffer, bool wait = false)
 {
        if (!buffer->text)
                return false;
@@ -647,29 +631,29 @@ bool MenuRunDvips(Buffer *buffer, bool wait=false)
        string paper;
        
        char real_papersize = buffer->params.papersize;
-       if (real_papersize == PAPER_DEFAULT)
+       if (real_papersize == BufferParams::PAPER_DEFAULT)
                real_papersize = lyxrc->default_papersize;
 
        switch (real_papersize) {
-       case PAPER_USLETTER:
+       case BufferParams::PAPER_USLETTER:
                paper = "letter";
                break;
-       case PAPER_A3PAPER:
+       case BufferParams::PAPER_A3PAPER:
                paper = "a3";
                break;
-       case PAPER_A4PAPER:
+       case BufferParams::PAPER_A4PAPER:
                paper = "a4";
                break;
-       case PAPER_A5PAPER:
+       case BufferParams::PAPER_A5PAPER:
                paper = "a5";
                break;
-       case PAPER_B5PAPER:
+       case BufferParams::PAPER_B5PAPER:
                paper = "b5";
                break;
-       case PAPER_EXECUTIVEPAPER:
+       case BufferParams::PAPER_EXECUTIVEPAPER:
                paper = "foolscap";
                break;
-       case PAPER_LEGALPAPER:
+       case BufferParams::PAPER_LEGALPAPER:
                paper = "legal";
                break;
        default: /* If nothing else fits, keep an empty value... */
@@ -680,7 +664,7 @@ bool MenuRunDvips(Buffer *buffer, bool wait=false)
        string command = "dvips " + lyxrc->print_to_file + ' ';
        command += SpaceLess(ps);
        if (buffer->params.use_geometry
-           && buffer->params.papersize2 == VM_PAPER_CUSTOM
+           && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
            && !lyxrc->print_paper_dimension_flag.empty()
            && !buffer->params.paperwidth.empty()
            && !buffer->params.paperheight.empty()) {
@@ -690,14 +674,14 @@ bool MenuRunDvips(Buffer *buffer, bool wait=false)
                command += buffer->params.paperwidth + ',';
                command += buffer->params.paperheight;
        } else if (!paper.empty()
-                  && (real_papersize != PAPER_USLETTER ||
-                      buffer->params.orientation == ORIENTATION_PORTRAIT)) {
+                  && (real_papersize != BufferParams::PAPER_USLETTER ||
+                      buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
                // dvips won't accept -t letter -t landscape.  In all other
                // cases, include the paper size explicitly.
                command += ' ';
                command += lyxrc->print_paper_flag + ' ' + paper;
        }
-       if (buffer->params.orientation == ORIENTATION_LANDSCAPE) {
+       if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
                command += ' ';
                command += lyxrc->print_landscape_flag;
        }
@@ -706,10 +690,9 @@ bool MenuRunDvips(Buffer *buffer, bool wait=false)
         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
                path = buffer->tmppath;
         }
-        PathPush(path);
+        Path p(path);
        bool ret = RunScript(buffer, wait, command);
        AllowInput();
-        PathPop();
        return ret;
 }
 
@@ -734,9 +717,8 @@ bool MenuPreviewPS(Buffer *buffer)
         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
                path = buffer->tmppath;
         }
-        PathPush(path);
+        Path p(path);
        bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
-        PathPop();
        AllowInput();
        return ret;
 }
@@ -758,15 +740,13 @@ void MenuFax(Buffer *buffer)
        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
        }
-       PathPush(path);
+       Path p(path);
        if (!lyxrc->fax_program.empty()) {
-               string help2 = lyxrc->fax_program;
-                subst(help2, "$$FName",ps);
+                string help2 = subst(lyxrc->fax_program, "$$FName", ps);
                 help2 += " &";
                 Systemcalls one(Systemcalls::System, help2);
        } else
-               send_fax(ps,lyxrc->fax_command);
-       PathPop();
+               send_fax(ps, lyxrc->fax_command);
 }
 
 
@@ -779,29 +759,29 @@ bool MenuPreview(Buffer *buffer)
        string paper;
        
        char real_papersize = buffer->params.papersize;
-       if (real_papersize == PAPER_DEFAULT)
+       if (real_papersize == BufferParams::PAPER_DEFAULT)
                real_papersize = lyxrc->default_papersize;
    
        switch (real_papersize) {
-       case PAPER_USLETTER:
+       case BufferParams::PAPER_USLETTER:
                paper = "us";
                break;
-       case PAPER_A3PAPER:
+       case BufferParams::PAPER_A3PAPER:
                paper = "a3";
                break;
-       case PAPER_A4PAPER:
+       case BufferParams::PAPER_A4PAPER:
                paper = "a4";
                break;
-       case PAPER_A5PAPER:
+       case BufferParams::PAPER_A5PAPER:
                paper = "a5";
                break;
-       case PAPER_B5PAPER:
+       case BufferParams::PAPER_B5PAPER:
                paper = "b5";
                break;
-       case PAPER_EXECUTIVEPAPER:
+       case BufferParams::PAPER_EXECUTIVEPAPER:
                paper = "foolscap";
                break;
-       case PAPER_LEGALPAPER:
+       case BufferParams::PAPER_LEGALPAPER:
                paper = "legal";
                break;
        default: /* If nothing else fits, keep the empty value */
@@ -809,14 +789,14 @@ bool MenuPreview(Buffer *buffer)
        }
    
        if (paper.empty()) {
-               if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
+               if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
                        // we HAVE to give a size when the page is in
                        // landscape, so use USletter.          
                        paper = " -paper usr";
        } else {
                paper = " -paper " + paper;
-               if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
-                       paper+='r';
+               if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
+                       paper+= 'r';
        }
 
        // push directorypath, if necessary 
@@ -824,16 +804,15 @@ bool MenuPreview(Buffer *buffer)
         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
                path = buffer->tmppath;
         }
-        PathPush(path);
+        Path p(path);
        // Run dvi-viewer
        string command = lyxrc->view_dvi_command + paper ;
        bool ret = RunScript(buffer, false, command);
-        PathPop();
        return ret;
 }
 
 
-void MenuMakeLaTeX(Buffer *buffer)
+void MenuMakeLaTeX(Buffer * buffer)
 {
        if (buffer->text) {
                // Get LaTeX-Filename
@@ -844,7 +823,7 @@ void MenuMakeLaTeX(Buffer *buffer)
                FilePtr myfile(s, FilePtr::read);
                if (myfile() &&
                    !AskQuestion(_("File already exists:"), 
-                               MakeDisplayPath(s,50),
+                               MakeDisplayPath(s, 50),
                                _("Do you want to overwrite the file?"))) {
                        minibuffer->Set(_("Canceled"));
                        return;
@@ -881,7 +860,7 @@ void MenuMakeLinuxDoc(Buffer *buffer)
                FilePtr myfile(s, FilePtr::read);
                if (myfile() &&
                    !AskQuestion(_("File already exists:"), 
-                               MakeDisplayPath(s,50),
+                               MakeDisplayPath(s, 50),
                                _("Do you want to overwrite the file?"))) {
                        minibuffer->Set(_("Canceled"));
                        return;
@@ -914,7 +893,7 @@ void MenuMakeDocBook(Buffer *buffer)
                FilePtr myfile(s, FilePtr::read);
                if (myfile() &&
                    !AskQuestion(_("File already exists:"), 
-                               MakeDisplayPath(s,50),
+                               MakeDisplayPath(s, 50),
                                _("Do you want to overwrite the file?"))) {
                        minibuffer->Set(_("Canceled"));
                        return;
@@ -941,7 +920,7 @@ void MenuMakeAscii(Buffer *buffer)
                FilePtr myfile(s, FilePtr::read);
                if (myfile() &&
                    !AskQuestion(_("File already exists:"), 
-                               MakeDisplayPath(s,50),
+                               MakeDisplayPath(s, 50),
                                _("Do you want to overwrite the file?"))) {
                        minibuffer->Set(_("Canceled"));
                        return;
@@ -971,7 +950,7 @@ void MenuPrint(Buffer *buffer)
        } 
        else {
                fl_show_form(fd_form_print->form_print,
-                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
+                            FL_PLACE_MOUSE, FL_FULLBORDER,
                             _("Print"));
        }
 }
@@ -1010,19 +989,19 @@ void AutoSave()
        if (!current_view->getScreen() || !current_view->available())
                return;
 
-       if (current_view->currentBuffer()->isBakClean()
-           || current_view->currentBuffer()->isReadonly()) {
+       if (current_view->buffer()->isBakClean()
+           || current_view->buffer()->isReadonly()) {
                // We don't save now, but we'll try again later
-               current_view->getOwner()->resetAutosaveTimer();
+               current_view->owner()->resetAutosaveTimer();
                return;
        }
 
        minibuffer->Set(_("Autosaving current document..."));
        
        // create autosave filename
-       string fname =  OnlyPath(current_view->currentBuffer()->getFileName());
+       string fname =  OnlyPath(current_view->buffer()->getFileName());
        fname += "#";
-       fname += OnlyFilename(current_view->currentBuffer()->getFileName());
+       fname += OnlyFilename(current_view->buffer()->getFileName());
        fname += "#";
        
        // tmp_ret will be located (usually) in /tmp
@@ -1038,7 +1017,7 @@ void AutoSave()
                // anyway.
                bool failed = false;
                if (!tmp_ret.empty()) {
-                       current_view->currentBuffer()->writeFile(tmp_ret, 1);
+                       current_view->buffer()->writeFile(tmp_ret, 1);
                        // assume successful write of tmp_ret
                        if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
                                failed = true;
@@ -1053,8 +1032,7 @@ void AutoSave()
                
                if (failed) {
                        // failed to write/rename tmp_ret so try writing direct
-                       if (!current_view->currentBuffer()->writeFile(fname,
-                                                                     1)) {
+                       if (!current_view->buffer()->writeFile(fname, 1)) {
                                // It is dangerous to do this in the child,
                                // but safe in the parent, so...
                                if (pid == -1)
@@ -1066,8 +1044,8 @@ void AutoSave()
                }
        }
        
-       current_view->currentBuffer()->markBakClean();
-       current_view->getOwner()->resetAutosaveTimer();
+       current_view->buffer()->markBakClean();
+       current_view->owner()->resetAutosaveTimer();
 }
 
 
@@ -1082,13 +1060,14 @@ Buffer * NewLyxFile(string const & filename)
 {
        // Split argument by :
        string name;
-       string tmpname=split(filename, name, ':');
+       string tmpname = split(filename, name, ':');
 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
-       if (name.length() == 1 && isalpha((unsigned char) name[0]) &&
-           (tmpname.prefixIs("/") || tmpname.prefixIs("\\"))) {
+       if (name.length() == 1
+           && isalpha(static_cast<unsigned char>(name[0]))
+           && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
                name += ':';
-               name += tmpname.token(':');
-               tmpname = split(tmpname, ':');
+               name += token(tmpname, ':', 0);
+               tmpname = split(tmpname, ':');
        }
 #endif
        lyxerr.debug() << "Arg is " << filename
@@ -1096,7 +1075,7 @@ Buffer * NewLyxFile(string const & filename)
                       << "\nTemplate is " << tmpname << endl;
 
        // find a free buffer 
-       Buffer *tmpbuf = bufferlist.newFile(name,tmpname);
+       Buffer *tmpbuf = bufferlist.newFile(name, tmpname);
        if (tmpbuf)
                lastfiles->newFile(tmpbuf->getFileName());
        return tmpbuf;
@@ -1115,7 +1094,7 @@ void InsertAsciiFile(string const & f, bool asParagraph)
        if (fname.empty()) {
                ProhibitInput();
                fname = fileDlg.Select(_("File to Insert"), 
-                                      current_view->getOwner()->currentBuffer()->filepath,
+                                      current_view->owner()->buffer()->filepath,
                                       "*");
                AllowInput();
                if (fname.empty()) return;
@@ -1126,32 +1105,36 @@ void InsertAsciiFile(string const & f, bool asParagraph)
 
        if (!fi.exist() || !fi.readable() || !myfile()) {
                WriteFSAlert(_("Error! Cannot open specified file:"),
-                            MakeDisplayPath(fname,50));
+                            MakeDisplayPath(fname, 50));
                return;
        }
        
-       tmppar = new LyXParagraph();
+       tmppar = new LyXParagraph;
        tmppar->readSimpleWholeFile(myfile);
        
        // set the end of the string
-       tmppar->InsertChar(tmppar->last-1,'\0');
-      
+#warning why do we do this?
+       // I don't think this is needed. Actually it might be plain wrong.
+       tmppar->InsertChar(tmppar->text.size() - 1,'\0');
+
        // insert the string
        current_view->getScreen()->HideCursor();
       
        // clear the selection
        BeforeChange();
        if (!asParagraph)
-               current_view->currentBuffer()->text->InsertStringA(tmppar->text);
+               current_view->buffer()->text->InsertStringA(tmppar->text);
        else
-               current_view->currentBuffer()->text->InsertStringB(tmppar->text);
+               current_view->buffer()->text->InsertStringB(tmppar->text);
        delete tmppar;
-       current_view->currentBuffer()->update(1);
+       current_view->buffer()->update(1);
 }
 
 
 void MenuShowTableOfContents()
 {
+       static int ow = -1, oh;
+
        TocUpdateCB(0, 0);
        if (fd_form_toc->form_toc->visible) {
                fl_raise_form(fd_form_toc->form_toc);
@@ -1159,21 +1142,26 @@ void MenuShowTableOfContents()
                fl_show_form(fd_form_toc->form_toc,
                             FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
                             _("Table Of Contents"));
+               if (ow < 0) {
+                       ow = fd_form_toc->form_toc->w;
+                       oh = fd_form_toc->form_toc->h;
+               }
+               fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
        }
 }
 
 
-void MenuInsertLabel(const char *arg)
+void MenuInsertLabel(char const *arg)
 {
        string label = arg;
        ProhibitInput();
-       //string label = fl_show_input(_("Enter new label to insert:"),"");
+       //string label = fl_show_input(_("Enter new label to insert:"), "");
        if (label.empty())
                label = frontStrip(strip(askForText(_("Enter new label to insert:"))));
        if (!label.empty()) {
                InsetLabel *new_inset = new InsetLabel;
                new_inset->setContents(label);
-               current_view->currentBuffer()->insertInset(new_inset);
+               current_view->buffer()->insertInset(new_inset);
        }
        AllowInput();
 }
@@ -1181,6 +1169,8 @@ void MenuInsertLabel(const char *arg)
 
 void MenuInsertRef()
 {
+       static int ow = -1, oh;
+
        RefUpdateCB(0, 0);
        if (fd_form_ref->form_ref->visible) {
                fl_raise_form(fd_form_ref->form_ref);
@@ -1188,6 +1178,11 @@ void MenuInsertRef()
                fl_show_form(fd_form_ref->form_ref,
                             FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
                             _("Insert Reference"));
+               if (ow < 0) {
+                       ow = fd_form_ref->form_ref->w;
+                       oh = fd_form_ref->form_ref->h;
+               }
+               fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
        }
 }
 
@@ -1211,24 +1206,23 @@ void MenuPasteSelection(char at)
 }
 
 
-void FootCB(FL_OBJECT*, long)
+extern "C" void FootCB(FL_OBJECT*, long)
 {
        if (!current_view->available()) 
                return;
        
        minibuffer->Set(_("Inserting Footnote..."));
        current_view->getScreen()->HideCursor();
-       current_view->currentBuffer()->update(-2);
-       current_view->currentBuffer()->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
-       current_view->currentBuffer()->update(1);
+       current_view->buffer()->update(-2);
+       current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
+       current_view->buffer()->update(1);
 }
 
 
 void LayoutsCB(int sel, void *)
 {
-       string tmp;
-       tmp += sel;
-       current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
+       string tmp = tostr(sel);
+       current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
                                                         tmp.c_str());
 }
 
@@ -1252,18 +1246,18 @@ int RunLinuxDoc(int flag, string const & filename)
        name = ChangeExtension (filename, ".sgml", true);
        path = OnlyPath (filename);
        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
-               path = current_view->currentBuffer()->tmppath;
+               path = current_view->buffer()->tmppath;
        }
-       PathPush (path);
+       Path p(path);
        
        if (flag != -1) {
                if (!current_view->available())
                        return 0;
-               current_view->currentBuffer()->makeLinuxDocFile(name,0);
-               LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->currentBuffer()->params.papersize;
+               current_view->buffer()->makeLinuxDocFile(name, 0);
+               BufferParams::PAPER_SIZE ps = current_view->buffer()->params.papersize;
                switch (ps) {
-               case PAPER_A4PAPER:  add_flags = "-p a4";     break;
-               case PAPER_USLETTER: add_flags = "-p letter"; break;
+               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; 
                }
        }
@@ -1294,16 +1288,15 @@ int RunLinuxDoc(int flag, string const & filename)
                if (one.startscript(Systemcalls::System, s2)) {
                        errorcode = 1;
                } else
-                       current_view->currentBuffer()->markDviClean();
+                       current_view->buffer()->markDviClean();
                break;
        default: /* unknown output */
                break;
        }
        
-       PathPop();
        AllowInput();
 
-        current_view->currentBuffer()->redraw();
+        current_view->buffer()->redraw();
        return errorcode;
 }
 
@@ -1324,23 +1317,23 @@ int RunDocBook(int flag, string const & filename)
        name = ChangeExtension (filename, ".sgml", true);
        path = OnlyPath (filename);
        if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
-               path = current_view->currentBuffer()->tmppath;
+               path = current_view->buffer()->tmppath;
        }
-       PathPush (path);
+       Path p(path);
 
        if (!current_view->available())
                return 0;
        
-       current_view->currentBuffer()->makeDocBookFile(name,0);
-#if 0
-       string add_flags;
-       LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->currentBuffer()->params.papersize;
-       switch (ps) {
-       case PAPER_A4PAPER:  add_flags = "-p a4";     break;
-       case PAPER_USLETTER: add_flags = "-p letter"; break;
-       default: /* nothing to be done yet ;-) */     break; 
-       }
-#endif 
+       current_view->buffer()->makeDocBookFile(name, 0);
+
+       // Shall this code go or should it stay? (Lgb)
+//     string add_flags;
+//     LYX_PAPER_SIZE ps = (LYX_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; 
+//     }
        ProhibitInput();
        
        Systemcalls one;
@@ -1351,16 +1344,15 @@ int RunDocBook(int flag, string const & filename)
                if (one.startscript(Systemcalls::System, s2)) {
                        errorcode = 1;
                } else
-                       current_view->currentBuffer()->markDviClean();
+                       current_view->buffer()->markDviClean();
                break;
        default: /* unknown output */
                break;
        }
        
-       PathPop();
        AllowInput();
 
-        current_view->currentBuffer()->redraw();
+        current_view->buffer()->redraw();
        return errorcode;
 }
 
@@ -1370,7 +1362,7 @@ void AllFloats(char flag, char figmar)
        if (!current_view->available())
                return;
    
-       LyXCursor cursor = current_view->currentBuffer()->text->cursor;
+       LyXCursor cursor = current_view->buffer()->text->cursor;
 
        if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
            && ((figmar 
@@ -1390,7 +1382,7 @@ void AllFloats(char flag, char figmar)
        cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
        cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
 
-       LyXParagraph *par = current_view->currentBuffer()->paragraph;
+       LyXParagraph *par = current_view->buffer()->paragraph;
        while (par) {
                if (flag) {
                        if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
@@ -1417,11 +1409,11 @@ void AllFloats(char flag, char figmar)
                                    )
                                ){
                                if (par->previous
-                                   && par->previous->footnoteflag !=
+                                   && par->previous->footnoteflag != 
                                    LyXParagraph::CLOSED_FOOTNOTE){ /* should be */ 
-                                       current_view->currentBuffer()->text->SetCursorIntern(par->previous,
+                                       current_view->buffer()->text->SetCursorIntern(par->previous,
                                                                      0);
-                                       current_view->currentBuffer()->text->OpenFootnote();
+                                       current_view->buffer()->text->OpenFootnote();
                                }
                        }
                }
@@ -1449,14 +1441,14 @@ void AllFloats(char flag, char figmar)
                                            )
                                    )
                                ){
-                               current_view->currentBuffer()->text->SetCursorIntern(par, 0);
-                               current_view->currentBuffer()->text->CloseFootnote();
+                               current_view->buffer()->text->SetCursorIntern(par, 0);
+                               current_view->buffer()->text->CloseFootnote();
                        }
                }
                par = par->next;
        }
 
-       current_view->currentBuffer()->text->SetCursorIntern(cursor.par, cursor.pos);
+       current_view->buffer()->text->SetCursorIntern(cursor.par, cursor.pos);
        current_view->redraw();
        current_view->fitCursor();
        current_view->updateScrollbar();
@@ -1465,12 +1457,19 @@ void AllFloats(char flag, char figmar)
 
 void MenuLayoutCharacter()
 {
+       static int ow = -1, oh;
+
        if (fd_form_character->form_character->visible) {
                fl_raise_form(fd_form_character->form_character);
        } else {
                fl_show_form(fd_form_character->form_character,
-                            FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
+                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
                             _("Character Style"));
+               if (ow < 0) {
+                       ow = fd_form_character->form_character->w;
+                       oh = fd_form_character->form_character->h;
+               }
+               fl_set_form_minsize(fd_form_character->form_character, ow, oh);
        }
 }
 
@@ -1543,7 +1542,7 @@ bool UpdateLayoutParagraph()
                return false;
        }
 
-       Buffer * buf = current_view->currentBuffer();
+       Buffer * buf = current_view->buffer();
 
        fl_set_input(fd_form_paragraph->input_labelwidth,
                     buf->text->cursor.par->GetLabelWidthString().c_str());
@@ -1554,8 +1553,8 @@ bool UpdateLayoutParagraph()
 
        int align = buf->text->cursor.par->GetAlign();
        if (align == LYX_ALIGN_LAYOUT)
-               align = lyxstyle.Style(buf->params.textclass,
-                                      buf->text->cursor.par->GetLayout())->align;
+               align =         textclasslist.Style(buf->params.textclass,
+                                      buf->text->cursor.par->GetLayout()).align;
         
        switch (align) {
        case LYX_ALIGN_RIGHT:
@@ -1657,7 +1656,7 @@ bool UpdateLayoutParagraph()
        fl_set_button(fd_form_paragraph->check_noindent,
                      buf->text->cursor.par->FirstPhysicalPar()->noindent);
 
-       if (current_view->currentBuffer()->isReadonly()) {
+       if (current_view->buffer()->isReadonly()) {
                DisableParagraphLayout();
        } else {
                EnableParagraphLayout();
@@ -1672,7 +1671,7 @@ void MenuLayoutParagraph()
                        fl_raise_form(fd_form_paragraph->form_paragraph);
                } else {
                        fl_show_form(fd_form_paragraph->form_paragraph,
-                                    FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
+                                    FL_PLACE_MOUSEFL_FULLBORDER,
                                     _("Paragraph Environment"));
                }
        }
@@ -1771,11 +1770,11 @@ bool UpdateLayoutDocument(BufferParams *params)
        }               
 
        if (params == 0)
-               params = &current_view->currentBuffer()->params;
-       LyXTextClass *tclass = lyxstyle.TextClass(params->textclass);
+               params = &current_view->buffer()->params;
+       LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
        
        fl_set_choice_text(fd_form_document->choice_class, 
-                          lyxstyle.DescOfClass(params->textclass).c_str());
+                          textclasslist.DescOfClass(params->textclass).c_str());
        combo_language->select_text(params->language.c_str());
        
        fl_set_choice_text(fd_form_document->choice_fonts, 
@@ -1789,18 +1788,18 @@ bool UpdateLayoutDocument(BufferParams *params)
        fl_clear_choice(fd_form_document->choice_fontsize);
        fl_addto_choice(fd_form_document->choice_fontsize, "default");
        fl_addto_choice(fd_form_document->choice_fontsize, 
-                       tclass->opt_fontsize.c_str());
+                       tclass.opt_fontsize().c_str());
        fl_set_choice(fd_form_document->choice_fontsize, 
-                     tokenPos(tclass->opt_fontsize, '|', params->fontsize) + 2);
+                     tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
 
        // ale970405+lasgoutt970513
        fl_clear_choice(fd_form_document->choice_pagestyle);
        fl_addto_choice(fd_form_document->choice_pagestyle, "default");
        fl_addto_choice(fd_form_document->choice_pagestyle, 
-                       tclass->opt_pagestyle.c_str());
+                       tclass.opt_pagestyle().c_str());
     
        fl_set_choice(fd_form_document->choice_pagestyle,
-                     tokenPos(tclass->opt_pagestyle, '|', params->pagestyle) + 2);
+                     tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
 
        fl_set_button(fd_form_document->radio_indent, 0);
        fl_set_button(fd_form_document->radio_skip, 0);
@@ -1808,7 +1807,7 @@ bool UpdateLayoutDocument(BufferParams *params)
         
        fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
 
-       if (params->paragraph_separation == LYX_PARSEP_INDENT)
+       if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
                fl_set_button(fd_form_document->radio_indent, 1);
        else
                fl_set_button(fd_form_document->radio_skip, 1);
@@ -1873,7 +1872,7 @@ bool UpdateLayoutDocument(BufferParams *params)
                {
                        fl_set_choice(fd_form_document->choice_spacing, 4);
                        char sval[20];
-                       sprintf(sval,"%g",params->spacing.getValue()); 
+                       sprintf(sval, "%g", params->spacing.getValue()); 
                        fl_set_input(fd_form_document->input_spacing, sval);
                        break;
                }
@@ -1896,7 +1895,7 @@ bool UpdateLayoutDocument(BufferParams *params)
        else
                fl_set_input(fd_form_document->input_extra, "");
 
-       if (current_view->currentBuffer()->isSGML()) {
+       if (current_view->buffer()->isSGML()) {
                // bullets not used in SGML derived documents
                fl_deactivate_object(fd_form_document->button_bullets);
                fl_set_object_lcol(fd_form_document->button_bullets,
@@ -1907,7 +1906,7 @@ bool UpdateLayoutDocument(BufferParams *params)
                                   FL_BLACK);
        }
 
-       if (current_view->currentBuffer()->isReadonly()) {
+       if (current_view->buffer()->isReadonly()) {
                DisableDocumentLayout();
        } else {
                EnableDocumentLayout();
@@ -1923,8 +1922,7 @@ void MenuLayoutDocument()
                        fl_raise_form(fd_form_document->form_document);
                } else {
                        fl_show_form(fd_form_document->form_document,
-                                    FL_PLACE_MOUSE | FL_FREE_SIZE,
-                                    FL_FULLBORDER,
+                                    FL_PLACE_MOUSE, FL_FULLBORDER,
                                     _("Document Layout"));
                }
        }
@@ -1936,16 +1934,16 @@ bool UpdateLayoutQuotes()
        bool update = true;
        if (!current_view->getScreen()
            || !current_view->available()
-           || current_view->currentBuffer()->isReadonly())
+           || current_view->buffer()->isReadonly())
                update = false;
        
        if (update) {
                fl_set_choice(fd_form_quotes->choice_quotes_language,
-                     current_view->currentBuffer()->params.quotes_language + 1);
+                     current_view->buffer()->params.quotes_language + 1);
                fl_set_button(fd_form_quotes->radio_single, 0);
                fl_set_button(fd_form_quotes->radio_double, 0);
        
-               if (current_view->currentBuffer()->params.quotes_times == InsetQuotes::SingleQ)
+               if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
                        fl_set_button(fd_form_quotes->radio_single, 1);
                else
                        fl_set_button(fd_form_quotes->radio_double, 1);
@@ -1962,8 +1960,7 @@ void MenuLayoutQuotes()
                        fl_raise_form(fd_form_quotes->form_quotes);
                } else {
                        fl_show_form(fd_form_quotes->form_quotes,
-                                    FL_PLACE_MOUSE | FL_FREE_SIZE,
-                                    FL_FULLBORDER,
+                                    FL_PLACE_MOUSE, FL_FULLBORDER,
                                     _("Quotes"));
                }
        }
@@ -1978,9 +1975,9 @@ bool UpdateLayoutPreamble()
 
        if (update) {
                fl_set_input(fd_form_preamble->input_preamble,
-                    current_view->currentBuffer()->params.preamble.c_str());
+                    current_view->buffer()->params.preamble.c_str());
 
-               if (current_view->currentBuffer()->isReadonly()) {
+               if (current_view->buffer()->isReadonly()) {
                  fl_deactivate_object(fd_form_preamble->input_preamble);
                  fl_deactivate_object(fd_form_preamble->button_ok);
                  fl_deactivate_object(fd_form_preamble->button_apply);
@@ -2002,6 +1999,8 @@ bool UpdateLayoutPreamble()
 
 void MenuLayoutPreamble()
 {
+       static int ow = -1, oh;
+
        if (UpdateLayoutPreamble()) {
                if (fd_form_preamble->form_preamble->visible) {
                        fl_raise_form(fd_form_preamble->form_preamble);
@@ -2010,6 +2009,12 @@ void MenuLayoutPreamble()
                                     FL_PLACE_MOUSE | FL_FREE_SIZE,
                                     FL_FULLBORDER,
                                     _("LaTeX Preamble"));
+                       if (ow < 0) {
+                               ow = fd_form_preamble->form_preamble->w;
+                               oh = fd_form_preamble->form_preamble->h;
+                       }
+                       fl_set_form_minsize(fd_form_preamble->form_preamble,
+                                           ow, oh);
                }
        }
 }
@@ -2022,16 +2027,16 @@ void MenuLayoutSave()
        if (AskQuestion(_("Do you want to save the current settings"),
                        _("for Character, Document, Paper and Quotes"),
                        _("as default for new documents?")))
-               current_view->currentBuffer()->saveParamsAsDefaults();
+               current_view->buffer()->saveParamsAsDefaults();
 }
 
 
 void NoteCB()
 {
        InsetInfo *new_inset = new InsetInfo();
-       current_view->currentBuffer()->insertInset(new_inset);
-       new_inset->Edit(0,0);
-       //current_view->currentBuffer()->update(-1);
+       current_view->buffer()->insertInset(new_inset);
+       new_inset->Edit(0, 0);
+       //current_view->buffer()->update(-1);
 }
 
 
@@ -2041,9 +2046,9 @@ void OpenStuff()
                minibuffer->Set(_("Open/Close..."));
                current_view->getScreen()->HideCursor();
                BeforeChange();
-               current_view->currentBuffer()->update(-2);
-               current_view->currentBuffer()->text->OpenStuff();
-               current_view->currentBuffer()->update(0);
+               current_view->buffer()->update(-2);
+               current_view->buffer()->text->OpenStuff();
+               current_view->buffer()->update(0);
        }
 }
 
@@ -2053,16 +2058,16 @@ void ToggleFloat()
                minibuffer->Set(_("Open/Close..."));
                current_view->getScreen()->HideCursor();
                BeforeChange();
-               current_view->currentBuffer()->update(-2);
-               current_view->currentBuffer()->text->ToggleFootnote();
-               current_view->currentBuffer()->update(0);
+               current_view->buffer()->update(-2);
+               current_view->buffer()->text->ToggleFootnote();
+               current_view->buffer()->update(0);
        }
 }
 
 
 void MenuUndo()
 {
-/*     if (current_view->currentBuffer()->the_locking_inset) {
+/*     if (current_view->buffer()->the_locking_inset) {
                minibuffer->Set(_("Undo not yet supported in math mode"));
                return;
        }*/
@@ -2071,18 +2076,18 @@ void MenuUndo()
                minibuffer->Set(_("Undo"));
                current_view->getScreen()->HideCursor();
                BeforeChange();
-               current_view->currentBuffer()->update(-2);
-               if (!current_view->currentBuffer()->text->TextUndo())
+               current_view->buffer()->update(-2);
+               if (!current_view->buffer()->text->TextUndo())
                        minibuffer->Set(_("No further undo information"));
                else
-                       current_view->currentBuffer()->update(-1);
+                       current_view->buffer()->update(-1);
        }
 }
 
 
 void MenuRedo()
 {
-       if (current_view->currentBuffer()->the_locking_inset) {
+       if (current_view->buffer()->the_locking_inset) {
                minibuffer->Set(_("Redo not yet supported in math mode"));
                return;
        }    
@@ -2091,11 +2096,11 @@ void MenuRedo()
                minibuffer->Set(_("Redo"));
                current_view->getScreen()->HideCursor();
                BeforeChange();
-               current_view->currentBuffer()->update(-2);
-               if (!current_view->currentBuffer()->text->TextRedo())
+               current_view->buffer()->update(-2);
+               if (!current_view->buffer()->text->TextRedo())
                        minibuffer->Set(_("No further redo information"));
                else
-                       current_view->currentBuffer()->update(-1);
+                       current_view->buffer()->update(-1);
        }
 }
 
@@ -2104,11 +2109,11 @@ void HyphenationPoint()
 {
        if (current_view->available())  {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
+               current_view->buffer()->update(-2);
                InsetSpecialChar *new_inset = 
                        new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
-               current_view->currentBuffer()->insertInset(new_inset);
-               //current_view->currentBuffer()->update(-1);
+               current_view->buffer()->insertInset(new_inset);
+               //current_view->buffer()->update(-1);
        }
 }
 
@@ -2117,10 +2122,10 @@ void Ldots()
 {
        if (current_view->available())  {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
+               current_view->buffer()->update(-2);
                InsetSpecialChar *new_inset = 
                        new InsetSpecialChar(InsetSpecialChar::LDOTS);
-               current_view->currentBuffer()->insertInset(new_inset);
+               current_view->buffer()->insertInset(new_inset);
        }
 }
 
@@ -2129,10 +2134,10 @@ void EndOfSentenceDot()
 {
        if (current_view->available())  {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
+               current_view->buffer()->update(-2);
                InsetSpecialChar *new_inset = 
                        new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
-               current_view->currentBuffer()->insertInset(new_inset);
+               current_view->buffer()->insertInset(new_inset);
        }
 }
 
@@ -2141,11 +2146,11 @@ void MenuSeparator()
 {
        if (current_view->available())  {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
+               current_view->buffer()->update(-2);
                InsetSpecialChar *new_inset = 
                        new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
-               current_view->currentBuffer()->insertInset(new_inset);
-               //current_view->currentBuffer()->update(-1);
+               current_view->buffer()->insertInset(new_inset);
+               //current_view->buffer()->update(-1);
        }
 }
 
@@ -2154,9 +2159,9 @@ void Newline()
 {
        if (current_view->available())  {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
-               current_view->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
-               current_view->currentBuffer()->update(-1);
+               current_view->buffer()->update(-2);
+               current_view->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
+               current_view->buffer()->update(-1);
        }
 }
 
@@ -2165,9 +2170,9 @@ void ProtectedBlank()
 {
        if (current_view->available())  {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
-               current_view->currentBuffer()->text->InsertChar(LYX_META_PROTECTED_SEPARATOR);
-               current_view->currentBuffer()->update(-1);
+               current_view->buffer()->update(-2);
+               current_view->buffer()->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
+               current_view->buffer()->update(-1);
        }
 }
 
@@ -2176,9 +2181,9 @@ void HFill()
 {
        if (current_view->available())  {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
-               current_view->currentBuffer()->text->InsertChar(LYX_META_HFILL);
-               current_view->currentBuffer()->update(-1);
+               current_view->buffer()->update(-2);
+               current_view->buffer()->text->InsertChar(LyXParagraph::META_HFILL);
+               current_view->buffer()->update(-1);
        }
 }
 
@@ -2279,10 +2284,10 @@ string CurrentState()
        if (current_view->available()) { 
                // I think we should only show changes from the default
                // font. (Asger)
-               Buffer * buffer = current_view->currentBuffer();
+               Buffer * buffer = current_view->buffer();
                LyXFont font = buffer->text->real_current_font;
-               LyXFont defaultfont = lyxstyle.TextClass(buffer->
-                                                        params.textclass)->defaultfont;
+               LyXFont defaultfont = textclasslist.TextClass(buffer->
+                                                        params.textclass).defaultfont();
                font.reduce(defaultfont);
                state = _("Font: ") + font.stateText();
 
@@ -2302,9 +2307,9 @@ void ToggleAndShow(LyXFont const & font)
 {
        if (current_view->available()) { 
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
-               current_view->currentBuffer()->text->ToggleFree(font, toggleall);
-               current_view->currentBuffer()->update(1);
+               current_view->buffer()->update(-2);
+               current_view->buffer()->text->ToggleFree(font, toggleall);
+               current_view->buffer()->update(1);
        }
        // removed since it overrides the ToggleFree Message about the style
        // Since Styles are more "High Level" than raw fonts I think the user
@@ -2313,19 +2318,19 @@ void ToggleAndShow(LyXFont const & font)
 }
 
 
-void MarginCB(FL_OBJECT *, long)
+extern "C" void MarginCB(FL_OBJECT *, long)
 {
        if (current_view->available()) {
                minibuffer->Set(_("Inserting margin note..."));
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
-               current_view->currentBuffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
-               current_view->currentBuffer()->update(1);
+               current_view->buffer()->update(-2);
+               current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
+               current_view->buffer()->update(1);
        }
 }
 
 
-void FigureCB(FL_OBJECT *, long)
+extern "C" void FigureCB(FL_OBJECT *, long)
 {
        if (fd_form_figure->form_figure->visible) {
                fl_raise_form(fd_form_figure->form_figure);
@@ -2337,13 +2342,13 @@ void FigureCB(FL_OBJECT *, long)
 }
 
 
-void TableCB(FL_OBJECT *, long)
+extern "C" void TableCB(FL_OBJECT *, long)
 {
        if (fd_form_table->form_table->visible) {
                fl_raise_form(fd_form_table->form_table);
        } else {
                fl_show_form(fd_form_table->form_table,
-                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
+                            FL_PLACE_MOUSE, FL_FULLBORDER,
                             _("Insert Table"));
        }
 }
@@ -2352,11 +2357,11 @@ void TableCB(FL_OBJECT *, long)
 void CopyEnvironmentCB()
 {
        if (current_view->available()) {
-               current_view->currentBuffer()->text->copyEnvironmentType();
+               current_view->buffer()->text->copyEnvironmentType();
                /* clear the selection, even if mark_set */ 
                current_view->getScreen()->ToggleSelection();
-               current_view->currentBuffer()->text->ClearSelection();
-               current_view->currentBuffer()->update(-2);
+               current_view->buffer()->text->ClearSelection();
+               current_view->buffer()->update(-2);
                minibuffer->Set(_("Paragraph environment type copied"));
        }
 }
@@ -2365,9 +2370,9 @@ void CopyEnvironmentCB()
 void PasteEnvironmentCB()
 {
        if (current_view->available()) {
-               current_view->currentBuffer()->text->pasteEnvironmentType();
+               current_view->buffer()->text->pasteEnvironmentType();
                minibuffer->Set(_("Paragraph environment type set"));
-               current_view->currentBuffer()->update(1);
+               current_view->buffer()->update(1);
        }
 }
 
@@ -2375,11 +2380,11 @@ void PasteEnvironmentCB()
 void CopyCB()
 {
        if (current_view->available()) {
-               current_view->currentBuffer()->text->CopySelection();
+               current_view->buffer()->text->CopySelection();
                /* clear the selection, even if mark_set */ 
                current_view->getScreen()->ToggleSelection();
-               current_view->currentBuffer()->text->ClearSelection();
-               current_view->currentBuffer()->update(-2);
+               current_view->buffer()->text->ClearSelection();
+               current_view->buffer()->update(-2);
                minibuffer->Set(_("Copy"));
        }
 }
@@ -2389,9 +2394,9 @@ void CutCB()
 {
        if (current_view->available()) {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
-               current_view->currentBuffer()->text->CutSelection();
-               current_view->currentBuffer()->update(1);
+               current_view->buffer()->update(-2);
+               current_view->buffer()->text->CutSelection();
+               current_view->buffer()->update(1);
                minibuffer->Set(_("Cut"));
        }
 }
@@ -2405,30 +2410,30 @@ void PasteCB()
        current_view->getScreen()->HideCursor();
        /* clear the selection */ 
        current_view->getScreen()->ToggleSelection();
-       current_view->currentBuffer()->text->ClearSelection();
-       current_view->currentBuffer()->update(-2);
+       current_view->buffer()->text->ClearSelection();
+       current_view->buffer()->update(-2);
        
        /* paste */ 
-       current_view->currentBuffer()->text->PasteSelection();
-       current_view->currentBuffer()->update(1);
+       current_view->buffer()->text->PasteSelection();
+       current_view->buffer()->update(1);
        
        /* clear the selection */ 
        current_view->getScreen()->ToggleSelection();
-       current_view->currentBuffer()->text->ClearSelection();
-       current_view->currentBuffer()->update(-2);
+       current_view->buffer()->text->ClearSelection();
+       current_view->buffer()->update(-2);
 }
 
 
-void MeltCB(FL_OBJECT *, long)
+extern "C" void MeltCB(FL_OBJECT *, long)
 {
        if (!current_view->available()) return;
        
        minibuffer->Set(_("Melt"));
        current_view->getScreen()->HideCursor();
        BeforeChange();
-       current_view->currentBuffer()->update(-2);
-       current_view->currentBuffer()->text->MeltFootnoteEnvironment();
-       current_view->currentBuffer()->update(1);
+       current_view->buffer()->update(-2);
+       current_view->buffer()->text->MeltFootnoteEnvironment();
+       current_view->buffer()->update(1);
 }
 
 
@@ -2436,7 +2441,7 @@ void MeltCB(FL_OBJECT *, long)
 // if decInc == 0, depth change taking mouse button number into account
 // if decInc == 1, increment depth
 // if decInc == -1, decrement depth
-void DepthCB(FL_OBJECT *ob, long decInc)
+extern "C" void DepthCB(FL_OBJECT *ob, long decInc)
 {
        int button = 1;
 
@@ -2451,12 +2456,12 @@ void DepthCB(FL_OBJECT *ob, long decInc)
   
        if (current_view->available()) {
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-2);
+               current_view->buffer()->update(-2);
                if (button == 1)
-                       current_view->currentBuffer()->text->IncDepth();
+                       current_view->buffer()->text->IncDepth();
                else
-                       current_view->currentBuffer()->text->DecDepth();
-               current_view->currentBuffer()->update(1);
+                       current_view->buffer()->text->DecDepth();
+               current_view->buffer()->update(1);
                minibuffer->Set(_("Changed environment depth"
                                  " (in possible range, maybe not)"));
        }
@@ -2559,7 +2564,7 @@ void FreeCB()
 
 
 /* callbacks for form form_title */
-void TimerCB(FL_OBJECT *, long)
+extern "C" void TimerCB(FL_OBJECT *, long)
 {
        // only if the form still exists
        if (fd_form_title->form_title != 0) {
@@ -2574,7 +2579,7 @@ void TimerCB(FL_OBJECT *, long)
 
 /* callbacks for form form_paragraph */
 
-void ParagraphVSpaceCB(FL_OBJECT* obj, long )
+extern "C" void ParagraphVSpaceCB(FL_OBJECT* obj, long )
 {
        // "Synchronize" the choices and input fields, making it
        // impossible to commit senseless data.
@@ -2625,15 +2630,13 @@ void ParagraphVSpaceCB(FL_OBJECT* obj, long )
 }
 
 
-void ParagraphApplyCB(FL_OBJECT *, long)
+extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
 {
        if (!current_view->available())
                return;
        
-       bool line_top, line_bottom;
-       bool pagebreak_top, pagebreak_bottom;
        VSpace space_top, space_bottom;
-       char align;
+       LyXAlignment align;
        string labelwidthstring;
        bool noindent;
 
@@ -2648,10 +2651,10 @@ void ParagraphApplyCB(FL_OBJECT *, long)
                fl_set_choice (fd_form_paragraph->choice_space_below, 1);
        }
    
-       line_top = fl_get_button(fd_form_paragraph->check_lines_top);
-       line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
-       pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
-       pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
+       bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
+       bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
+       bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
+       bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
        switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
        case 1: space_top = VSpace(VSpace::NONE); break;
        case 2: space_top = VSpace(VSpace::DEFSKIP); break;
@@ -2687,7 +2690,7 @@ void ParagraphApplyCB(FL_OBJECT *, long)
        labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
        noindent = fl_get_button(fd_form_paragraph->check_noindent);
    
-       current_view->currentBuffer()->text->SetParagraph(line_top,
+       current_view->buffer()->text->SetParagraph(line_top,
                                                          line_bottom,
                                                          pagebreak_top,
                                                          pagebreak_bottom,
@@ -2696,18 +2699,18 @@ void ParagraphApplyCB(FL_OBJECT *, long)
                                                          align, 
                                                          labelwidthstring,
                                                          noindent);
-       current_view->currentBuffer()->update(1);
+       current_view->buffer()->update(1);
        minibuffer->Set(_("Paragraph layout set"));
 }
 
 
-void ParagraphCancelCB(FL_OBJECT *, long)
+extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_paragraph->form_paragraph);
 }
 
 
-void ParagraphOKCB(FL_OBJECT *ob, long data)
+extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
 {
        ParagraphApplyCB(ob, data);
        ParagraphCancelCB(ob, data);
@@ -2716,7 +2719,7 @@ void ParagraphOKCB(FL_OBJECT *ob, long data)
 
 /* callbacks for form form_character */
 
-void CharacterApplyCB(FL_OBJECT *, long)
+extern "C" void CharacterApplyCB(FL_OBJECT *, long)
 {
        // we set toggleall locally here, since it should be true for
        // all other uses of ToggleAndShow() (JMarc)
@@ -2726,16 +2729,16 @@ void CharacterApplyCB(FL_OBJECT *, long)
 }
 
 
-void CharacterCloseCB(FL_OBJECT *, long)
+extern "C" void CharacterCloseCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_character->form_character);
 }
 
 
-void CharacterOKCB(FL_OBJECT *ob, long data)
+extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
 {
-       CharacterApplyCB(ob,data);
-       CharacterCloseCB(ob,data);
+       CharacterApplyCB(ob, data);
+       CharacterCloseCB(ob, data);
 }
 
 
@@ -2763,10 +2766,10 @@ void UpdateDocumentButtons(BufferParams const &params)
        
 }
 
-void ChoiceClassCB(FL_OBJECT *ob, long)
+extern "C" void ChoiceClassCB(FL_OBJECT *ob, long)
 {
        ProhibitInput();
-       if (lyxstyle.Load(fl_get_choice(ob)-1)) {
+       if (textclasslist.Load(fl_get_choice(ob)-1)) {
                if (AskQuestion(_("Should I set some parameters to"),
                                fl_get_choice_text(ob),
                                _("the defaults of this document class?"))) {
@@ -2788,7 +2791,7 @@ void ChoiceClassCB(FL_OBJECT *ob, long)
 }
 
 
-void DocumentDefskipCB(FL_OBJECT *obj, long)
+extern "C" void DocumentDefskipCB(FL_OBJECT *obj, long)
 {
        // "Synchronize" the choice and the input field, so that it
        // is impossible to commit senseless data.
@@ -2817,7 +2820,7 @@ void DocumentDefskipCB(FL_OBJECT *obj, long)
 }
 
 
-void DocumentSpacingCB(FL_OBJECT *obj, long)
+extern "C" void DocumentSpacingCB(FL_OBJECT *obj, long)
 {
        // "Synchronize" the choice and the input field, so that it
        // is impossible to commit senseless data.
@@ -2839,11 +2842,11 @@ void DocumentSpacingCB(FL_OBJECT *obj, long)
 }
 
 
-void DocumentApplyCB(FL_OBJECT *, long)
+extern "C" void DocumentApplyCB(FL_OBJECT *, long)
 {
        bool redo = false;
-       BufferParams *params = &(current_view->currentBuffer()->params);
-       current_view->currentBuffer()->params.language =
+       BufferParams *params = &(current_view->buffer()->params);
+       current_view->buffer()->params.language = 
                combo_language->getline();
 
        // If default skip is a "Length" but there's no text in the
@@ -2858,46 +2861,46 @@ void DocumentApplyCB(FL_OBJECT *, long)
    
        /* ChangeKeymap(buffer->parameters.language, TRUE, false,
           fl_get_choice(fd_form_document->choice_language)); */
-       params->fonts =
+       params->fonts = 
                fl_get_choice_text(fd_form_document->choice_fonts);
-       params->inputenc =
+       params->inputenc = 
                fl_get_choice_text(fd_form_document->choice_inputenc);
-       params->fontsize =
+       params->fontsize = 
                fl_get_choice_text(fd_form_document->choice_fontsize);
-       params->pagestyle =
+       params->pagestyle = 
                fl_get_choice_text(fd_form_document->choice_pagestyle);
-       params->graphicsDriver =
+       params->graphicsDriver = 
                fl_get_choice_text(fd_form_document->choice_postscript_driver);
-       params->use_amsmath =
+       params->use_amsmath = 
                fl_get_button(fd_form_document->check_use_amsmath);
    
        if (!current_view->available())
                return;
 
-       char new_class = fl_get_choice(fd_form_document->choice_class) - 1;
+       LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
        if (params->textclass != new_class) {
                // try to load new_class
-               if (lyxstyle.Load(new_class)) {
+               if (textclasslist.Load(new_class)) {
                        // successfully loaded
                        redo = true;
                        minibuffer->Set(_("Converting document to new document class..."));
-                       int ret = current_view->currentBuffer()->
+                       int ret = current_view->buffer()->
                                text->
-                               SwitchLayoutsBetweenClasses(current_view->currentBuffer()->
+                               SwitchLayoutsBetweenClasses(current_view->buffer()->
                                                            params.textclass,
                                                            new_class,
-                                                           current_view->currentBuffer()->
+                                                           current_view->buffer()->
                                                            paragraph);
 
                        if (ret){
                                string s;
-                               if (ret==1)
-                                       s= _("One paragraph couldn't be converted");
+                               if (ret == 1)
+                                       s = _("One paragraph couldn't be converted");
                                else {
-                                       s += ret;
+                                       s += tostr(ret);
                                        s += _(" paragraphs couldn't be converted");
                                }
-                               WriteAlert(_("Conversion Errors!"),s,
+                               WriteAlert(_("Conversion Errors!"), s,
                                           _("into chosen document class"));
                        }
 
@@ -2913,9 +2916,9 @@ void DocumentApplyCB(FL_OBJECT *, long)
 
        char tmpsep = params->paragraph_separation;
        if (fl_get_button(fd_form_document->radio_indent))
-               params->paragraph_separation = LYX_PARSEP_INDENT;
+               params->paragraph_separation = BufferParams::PARSEP_INDENT;
        else
-               params->paragraph_separation = LYX_PARSEP_SKIP;
+               params->paragraph_separation = BufferParams::PARSEP_SKIP;
        if (tmpsep != params->paragraph_separation)
                redo = true;
    
@@ -2939,9 +2942,9 @@ void DocumentApplyCB(FL_OBJECT *, long)
        else
                params->columns = 1;
        if (fl_get_button(fd_form_document->radio_sides_two))
-               params->sides = 2;
+               params->sides = LyXTextClass::TwoSides;
        else
-               params->sides = 1;
+               params->sides = LyXTextClass::OneSide;
 
        Spacing tmpSpacing = params->spacing;
        switch(fl_get_choice(fd_form_document->choice_spacing)) {
@@ -2966,16 +2969,16 @@ void DocumentApplyCB(FL_OBJECT *, long)
        if (tmpSpacing != params->spacing)
                redo = true;
        
-       signed char tmpchar = (signed char) 
-               fl_get_counter_value(fd_form_document->slider_secnumdepth);;
+       signed char tmpchar =  
+               static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
        if (params->secnumdepth != tmpchar)
                redo = true;
        params->secnumdepth = tmpchar;
    
-       params->tocdepth = (signed char) 
-               fl_get_counter_value(fd_form_document->slider_tocdepth);;
+       params->tocdepth =  
+               static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
 
-       params->float_placement =
+       params->float_placement = 
                fl_get_input(fd_form_document->input_float_placement);
 
        // More checking should be done to ensure the string doesn't have
@@ -2985,28 +2988,28 @@ void DocumentApplyCB(FL_OBJECT *, long)
                current_view->redoCurrentBuffer();
    
        minibuffer->Set(_("Document layout set"));
-       current_view->currentBuffer()->markDirty();
+       current_view->buffer()->markDirty();
 
-        params->options =
+        params->options = 
                fl_get_input(fd_form_document->input_extra);
    
 }
 
 
-void DocumentCancelCB(FL_OBJECT *, long)
+extern "C" void DocumentCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_document->form_document);
 }
 
 
-void DocumentOKCB(FL_OBJECT *ob, long data)
+extern "C" void DocumentOKCB(FL_OBJECT *ob, long data)
 {
-       DocumentCancelCB(ob,data);
-       DocumentApplyCB(ob,data);
+       DocumentCancelCB(ob, data);
+       DocumentApplyCB(ob, data);
 }
 
 
-void DocumentBulletsCB(FL_OBJECT *, long)
+extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
 {
        bulletForm();
        // bullet callbacks etc. in bullet_panel.C -- ARRae
@@ -3020,20 +3023,20 @@ void GotoNote()
    
        current_view->getScreen()->HideCursor();
        BeforeChange();
-       current_view->currentBuffer()->update(-2);
+       current_view->buffer()->update(-2);
        LyXCursor tmp;
    
-       if (!current_view->currentBuffer()->text->GotoNextNote()) {
-               if (current_view->currentBuffer()->text->cursor.pos 
-                   || current_view->currentBuffer()->text->cursor.par !=
-                   current_view->currentBuffer()->text->FirstParagraph())
+       if (!current_view->buffer()->text->GotoNextNote()) {
+               if (current_view->buffer()->text->cursor.pos 
+                   || current_view->buffer()->text->cursor.par != 
+                   current_view->buffer()->text->FirstParagraph())
                        {
-                               tmp = current_view->currentBuffer()->text->cursor;
-                               current_view->currentBuffer()->text->cursor.par =
-                                       current_view->currentBuffer()->text->FirstParagraph();
-                               current_view->currentBuffer()->text->cursor.pos = 0;
-                               if (!current_view->currentBuffer()->text->GotoNextNote()) {
-                                       current_view->currentBuffer()->text->cursor = tmp;
+                               tmp = current_view->buffer()->text->cursor;
+                               current_view->buffer()->text->cursor.par = 
+                                       current_view->buffer()->text->FirstParagraph();
+                               current_view->buffer()->text->cursor.pos = 0;
+                               if (!current_view->buffer()->text->GotoNextNote()) {
+                                       current_view->buffer()->text->cursor = tmp;
                                        minibuffer->Set(_("No more notes"));
                                        LyXBell();
                                }
@@ -3042,15 +3045,15 @@ void GotoNote()
                                LyXBell();
                        }
        }
-       current_view->currentBuffer()->update(0);
-       current_view->currentBuffer()->text->sel_cursor =
-               current_view->currentBuffer()->text->cursor;
+       current_view->buffer()->update(0);
+       current_view->buffer()->text->sel_cursor = 
+               current_view->buffer()->text->cursor;
 }
 
 
 void InsertCorrectQuote()
 {
-       Buffer *cbuffer = current_view->currentBuffer();
+       Buffer *cbuffer = current_view->buffer();
        char c;
 
        if  (cbuffer->text->cursor.pos )
@@ -3064,13 +3067,13 @@ void InsertCorrectQuote()
 
 /* callbacks for form form_quotes */
 
-void QuotesApplyCB(FL_OBJECT *, long)
+extern "C" void QuotesApplyCB(FL_OBJECT *, long)
 {
        if (!current_view->available())
                return;
        
        minibuffer->Set(_("Quotes type set"));
-       //current_view->currentBuffer()->params.quotes_language =
+       //current_view->buffer()->params.quotes_language = 
        //      fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
        InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
        switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
@@ -3093,23 +3096,23 @@ void QuotesApplyCB(FL_OBJECT *, long)
                lga = InsetQuotes::DanishQ;
                break;
        }
-       current_view->currentBuffer()->params.quotes_language = lga;
+       current_view->buffer()->params.quotes_language = lga;
        if (fl_get_button(fd_form_quotes->radio_single))   
-               current_view->currentBuffer()->
+               current_view->buffer()->
                        params.quotes_times = InsetQuotes::SingleQ;
        else
-               current_view->currentBuffer()->
+               current_view->buffer()->
                        params.quotes_times = InsetQuotes::DoubleQ;
 }
 
 
-void QuotesCancelCB(FL_OBJECT *, long)
+extern "C" void QuotesCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_quotes->form_quotes);
 }
 
 
-void QuotesOKCB(FL_OBJECT *ob, long data)
+extern "C" void QuotesOKCB(FL_OBJECT *ob, long data)
 {
        QuotesApplyCB(ob, data);
        QuotesCancelCB(ob, data);
@@ -3119,25 +3122,25 @@ void QuotesOKCB(FL_OBJECT *ob, long data)
 
 /* callbacks for form form_preamble */
 
-void PreambleCancelCB(FL_OBJECT *, long)
+extern "C" void PreambleCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_preamble->form_preamble);
 }
 
 
-void PreambleApplyCB(FL_OBJECT *, long)
+extern "C" void PreambleApplyCB(FL_OBJECT *, long)
 {
        if (!current_view->available())
                return;
        
-       current_view->currentBuffer()->params.preamble =
+       current_view->buffer()->params.preamble = 
                fl_get_input(fd_form_preamble->input_preamble);
-       current_view->currentBuffer()->markDirty();
+       current_view->buffer()->markDirty();
        minibuffer->Set(_("LaTeX preamble set"));
 }
 
    
-void PreambleOKCB(FL_OBJECT *ob, long data)
+extern "C" void PreambleOKCB(FL_OBJECT *ob, long data)
 {
        PreambleApplyCB(ob, data);
        PreambleCancelCB(ob, data);
@@ -3146,14 +3149,14 @@ void PreambleOKCB(FL_OBJECT *ob, long data)
 
 /* callbacks for form form_table */
 
-void TableApplyCB(FL_OBJECT *, long)
+extern "C" void TableApplyCB(FL_OBJECT *, long)
 {
-       int xsize,ysize;
+       int xsize, ysize;
        if (!current_view->getScreen())
                return;
    
        // check for tables in tables
-       if (current_view->currentBuffer()->text->cursor.par->table){
+       if (current_view->buffer()->text->cursor.par->table){
                WriteAlert(_("Impossible Operation!"),
                           _("Cannot insert table in table."),
                           _("Sorry."));
@@ -3168,34 +3171,34 @@ void TableApplyCB(FL_OBJECT *, long)
    
        current_view->getScreen()->HideCursor();
        BeforeChange();
-       current_view->currentBuffer()->update(-2);
+       current_view->buffer()->update(-2);
    
-       current_view->currentBuffer()->text->SetCursorParUndo(); 
-       current_view->currentBuffer()->text->FreezeUndo();
+       current_view->buffer()->text->SetCursorParUndo(); 
+       current_view->buffer()->text->FreezeUndo();
 
-       current_view->currentBuffer()->text->BreakParagraph();
-       current_view->currentBuffer()->update(-1);
+       current_view->buffer()->text->BreakParagraph();
+       current_view->buffer()->update(-1);
    
-       if (current_view->currentBuffer()->text->cursor.par->Last()) {
-               current_view->currentBuffer()->text->CursorLeft();
+       if (current_view->buffer()->text->cursor.par->Last()) {
+               current_view->buffer()->text->CursorLeft();
       
-               current_view->currentBuffer()->text->BreakParagraph();
-               current_view->currentBuffer()->update(-1);
+               current_view->buffer()->text->BreakParagraph();
+               current_view->buffer()->update(-1);
        }
 
-       current_view->currentBuffer()->text->current_font.setLatex(LyXFont::OFF);
+       current_view->buffer()->text->current_font.setLatex(LyXFont::OFF);
        //if (!fl_get_button(fd_form_table->check_latex)){
        // insert the new wysiwy table
-       current_view->currentBuffer()->text->SetLayout(0); // standard layout
-       if (current_view->currentBuffer()->text->cursor.par->footnoteflag ==
+       current_view->buffer()->text->SetLayout(0); // standard layout
+       if (current_view->buffer()->text->cursor.par->footnoteflag == 
            LyXParagraph::NO_FOOTNOTE) {
-               current_view->currentBuffer()->
+               current_view->buffer()->
                        text->SetParagraph(0, 0,
                                           0, 0,
-                                          VSpace (0.3 * current_view->currentBuffer()->
+                                          VSpace (0.3 * current_view->buffer()->
                                                   params.spacing.getValue(),
                                                   LyXLength::CM),
-                                          VSpace (0.3 * current_view->currentBuffer()->
+                                          VSpace (0.3 * current_view->buffer()->
                                                   params.spacing.getValue(),
                                                   LyXLength::CM),
                                           LYX_ALIGN_CENTER,
@@ -3203,7 +3206,7 @@ void TableApplyCB(FL_OBJECT *, long)
                                           0);
        }
        else
-               current_view->currentBuffer()->text->SetParagraph(0, 0,
+               current_view->buffer()->text->SetParagraph(0, 0,
                                                                  0, 0,
                                                                  VSpace(VSpace::NONE),
                                                                  VSpace(VSpace::NONE),
@@ -3211,51 +3214,51 @@ void TableApplyCB(FL_OBJECT *, long)
                                           string(),
                                           0);
 
-       current_view->currentBuffer()->text->cursor.par->table = new LyXTable(xsize, ysize);
+       current_view->buffer()->text->cursor.par->table = new LyXTable(xsize, ysize);
        int i;
-       for (i=0; i<xsize * ysize - 1; i++)
-               current_view->currentBuffer()->text->cursor.par->InsertChar(0,LYX_META_NEWLINE);
-       current_view->currentBuffer()->text->RedoParagraph();
+       for (i = 0; i<xsize * ysize - 1; i++)
+               current_view->buffer()->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
+       current_view->buffer()->text->RedoParagraph();
    
-       current_view->currentBuffer()->text->UnFreezeUndo();
+       current_view->buffer()->text->UnFreezeUndo();
      
-       current_view->currentBuffer()->update(1);
+       current_view->buffer()->update(1);
        minibuffer->Set(_("Table inserted"));
 }
 
 
-void TableCancelCB(FL_OBJECT *, long)
+extern "C" void TableCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_table->form_table);
 }
 
 
-void TableOKCB(FL_OBJECT *ob, long data)
+extern "C" void TableOKCB(FL_OBJECT *ob, long data)
 {
-       TableApplyCB(ob,data);
-       TableCancelCB(ob,data);
+       TableApplyCB(ob, data);
+       TableCancelCB(ob, data);
 }
 
 
 /* callbacks for form form_print */
 
-void PrintCancelCB(FL_OBJECT *, long)
+extern "C" void PrintCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_print->form_print);
 }
 
-static bool stringOnlyContains (string const & LStr, const char * cset)
+static bool stringOnlyContains (string const & LStr, char const * cset)
 {
-       const char * cstr = LStr.c_str() ;
+       char const * cstr = LStr.c_str() ;
 
-       return strspn(cstr,cset) == strlen(cstr) ;
+       return strspn(cstr, cset) == strlen(cstr) ;
 }
 
-void PrintApplyCB(FL_OBJECT *, long)
+extern "C" void PrintApplyCB(FL_OBJECT *, long)
 {
        if (!current_view->available())
                return;
-        Buffer *buffer = current_view->currentBuffer();
+        Buffer *buffer = current_view->buffer();
         string path = OnlyPath(buffer->getFileName());
 
        string pageflag;
@@ -3267,11 +3270,9 @@ void PrintApplyCB(FL_OBJECT *, long)
 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
 // User may give a page (range) list
 // User may print multiple (unsorted) copies
-       string pages = fl_get_input(fd_form_print->input_pages);
-       subst(pages, ';',',');
-       subst(pages, '+',',');
-       pages = strip (pages) ;
-       pages = frontStrip (pages) ;
+       string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
+       pages = subst(pages, '+',',');
+       pages = frontStrip(strip(pages)) ;
        while (!pages.empty()) { // a page range was given
                string piece ;
                pages = split (pages, piece, ',') ;
@@ -3312,7 +3313,7 @@ void PrintApplyCB(FL_OBJECT *, long)
                reverseflag = lyxrc->print_reverse_flag + ' ';
    
        string orientationflag;
-       if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
+       if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
                orientationflag = lyxrc->print_landscape_flag + ' ';
    
        string ps_file = SpaceLess(fl_get_input(fd_form_print->input_file));
@@ -3332,31 +3333,31 @@ void PrintApplyCB(FL_OBJECT *, long)
                + orientationflag + extraflags;
  
        char real_papersize = buffer->params.papersize;
-       if (real_papersize == PAPER_DEFAULT)
+       if (real_papersize == BufferParams::PAPER_DEFAULT)
                real_papersize = lyxrc->default_papersize;
         string
             paper;
 
        switch (real_papersize) {
-       case PAPER_USLETTER:
+       case BufferParams::PAPER_USLETTER:
                paper = "letter";
                break;
-       case PAPER_A3PAPER:
+       case BufferParams::PAPER_A3PAPER:
                paper = "a3";
                break;
-       case PAPER_A4PAPER:
+       case BufferParams::PAPER_A4PAPER:
                paper = "a4";
                break;
-       case PAPER_A5PAPER:
+       case BufferParams::PAPER_A5PAPER:
                paper = "a5";
                break;
-       case PAPER_B5PAPER:
+       case BufferParams::PAPER_B5PAPER:
                paper = "b5";
                break;
-       case PAPER_EXECUTIVEPAPER:
+       case BufferParams::PAPER_EXECUTIVEPAPER:
                paper = "foolscap";
                break;
-       case PAPER_LEGALPAPER:
+       case BufferParams::PAPER_LEGALPAPER:
                paper = "legal";
                break;
        default: /* If nothing else fits, keep an empty value... */
@@ -3364,7 +3365,7 @@ void PrintApplyCB(FL_OBJECT *, long)
        }
 
        if (buffer->params.use_geometry
-           && buffer->params.papersize2 == VM_PAPER_CUSTOM
+           && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
            && !lyxrc->print_paper_dimension_flag.empty()
            && !buffer->params.paperwidth.empty()
            && !buffer->params.paperheight.empty()) {
@@ -3375,8 +3376,8 @@ void PrintApplyCB(FL_OBJECT *, long)
                command += buffer->params.paperheight + ' ';
        } else if (!lyxrc->print_paper_flag.empty()
                   && !paper.empty()
-                  && (real_papersize != PAPER_USLETTER ||
-                      buffer->params.orientation == ORIENTATION_PORTRAIT)) {
+                  && (real_papersize != BufferParams::PAPER_USLETTER ||
+                      buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
                command += " " + lyxrc->print_paper_flag + " " + paper + " ";
        }
        if (fl_get_button(fd_form_print->radio_file))
@@ -3391,7 +3392,7 @@ void PrintApplyCB(FL_OBJECT *, long)
         if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
                path = buffer->tmppath;
         }
-        PathPush(path);
+        Path p(path);
 
        bool result;
        if (!lyxrc->print_spool_command.empty() && 
@@ -3406,7 +3407,6 @@ void PrintApplyCB(FL_OBJECT *, long)
                }
         } else
                result = RunScript(buffer, false, command);
-        PathPop();
 
        if (!result)
                WriteAlert(_("Error:"),
@@ -3415,21 +3415,21 @@ void PrintApplyCB(FL_OBJECT *, long)
 }
 
 
-void PrintOKCB(FL_OBJECT *ob, long data)
+extern "C" void PrintOKCB(FL_OBJECT *ob, long data)
 {
        PrintCancelCB(ob, data);  
-       PrintApplyCB(ob,data);
+       PrintApplyCB(ob, data);
 }
 
 
 /* callbacks for form form_figure */
 
-void FigureApplyCB(FL_OBJECT *, long)
+extern "C" void FigureApplyCB(FL_OBJECT *, long)
 {
        if (!current_view->available())
                return;
 
-       Buffer * buffer = current_view->currentBuffer();
+       Buffer * buffer = current_view->buffer();
        if(buffer->isReadonly()) // paranoia
                return;
        
@@ -3463,7 +3463,7 @@ void FigureApplyCB(FL_OBJECT *, long)
        // The standard layout should always be numer 0;
        buffer->text->SetLayout(0);
        
-       if (buffer->text->cursor.par->footnoteflag ==
+       if (buffer->text->cursor.par->footnoteflag == 
            LyXParagraph::NO_FOOTNOTE) {
                buffer->text->SetParagraph(0, 0,
                                           0, 0,
@@ -3495,19 +3495,19 @@ void FigureApplyCB(FL_OBJECT *, long)
 }
 
    
-void FigureCancelCB(FL_OBJECT *, long)
+extern "C" void FigureCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_figure->form_figure);
 }
 
 
-void FigureOKCB(FL_OBJECT *ob, long data)
+extern "C" void FigureOKCB(FL_OBJECT *ob, long data)
 {
-       FigureApplyCB(ob,data);
-       FigureCancelCB(ob,data);
+       FigureApplyCB(ob, data);
+       FigureCancelCB(ob, data);
 }
 
-void ScreenApplyCB(FL_OBJECT *, long)
+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);
@@ -3523,16 +3523,16 @@ void ScreenApplyCB(FL_OBJECT *, long)
 }
 
 
-void ScreenCancelCB(FL_OBJECT *, long)
+extern "C" void ScreenCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_screen->form_screen);
 }
 
 
-void ScreenOKCB(FL_OBJECT *ob, long data)
+extern "C" void ScreenOKCB(FL_OBJECT *ob, long data)
 {
-       ScreenCancelCB(ob,data);
-       ScreenApplyCB(ob,data);
+       ScreenCancelCB(ob, data);
+       ScreenApplyCB(ob, data);
 }
 
 
@@ -3542,13 +3542,13 @@ void LaTeXOptions()
                return;
 
        fl_set_button(fd_latex_options->accents,
-                     (int)current_view->currentBuffer()->params.allowAccents);
+                     (int)current_view->buffer()->params.allowAccents);
        
        if (fd_latex_options->LaTeXOptions->visible) {
                fl_raise_form(fd_latex_options->LaTeXOptions);
        } else {
                fl_show_form(fd_latex_options->LaTeXOptions,
-                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
+                            FL_PLACE_MOUSE, FL_FULLBORDER,
                             _("LaTeX Options"));
        }
 }
@@ -3561,10 +3561,10 @@ void Reconfigure()
        minibuffer->Set(_("Running configure..."));
 
        // Run configure in user lyx directory
-       PathPush(user_lyxdir);
+       Path p(user_lyxdir);
        Systemcalls one(Systemcalls::System, 
-                          AddName(system_lyxdir,"configure"));
-       PathPop();
+                          AddName(system_lyxdir, "configure"));
+       p.pop();
        minibuffer->Set(_("Reloading configuration..."));
        lyxrc->Read(LibFileSearch(string(), "lyxrc.defaults"));
        WriteAlert(_("The system has been reconfigured."), 
@@ -3581,7 +3581,7 @@ char* NextWord(float &value)
                return 0;
        }
    
-       char* string =  current_view->currentBuffer()->text->SelectNextWord(value);
+       char* string =  current_view->buffer()->text->SelectNextWord(value);
 
        return string;
 }
@@ -3594,9 +3594,9 @@ void SelectLastWord()
    
        current_view->getScreen()->HideCursor();
        BeforeChange(); 
-       current_view->currentBuffer()->text->SelectSelectedWord();
+       current_view->buffer()->text->SelectSelectedWord();
        current_view->getScreen()->ToggleSelection(false);
-       current_view->currentBuffer()->update(0);
+       current_view->buffer()->update(0);
 }
 
 
@@ -3607,9 +3607,9 @@ void EndOfSpellCheck()
    
        current_view->getScreen()->HideCursor();
        BeforeChange(); 
-       current_view->currentBuffer()->text->SelectSelectedWord();
-       current_view->currentBuffer()->text->ClearSelection();
-       current_view->currentBuffer()->update(0);
+       current_view->buffer()->text->SelectSelectedWord();
+       current_view->buffer()->text->ClearSelection();
+       current_view->buffer()->update(0);
 }
 
 
@@ -3619,20 +3619,20 @@ void ReplaceWord(string const & replacestring)
                return;
 
        current_view->getScreen()->HideCursor();
-       current_view->currentBuffer()->update(-2);
+       current_view->buffer()->update(-2);
    
        /* clear the selection (if there is any) */ 
        current_view->getScreen()->ToggleSelection(false);
-       current_view->currentBuffer()->text->
+       current_view->buffer()->text->
                ReplaceSelectionWithString(replacestring.c_str());
    
-       current_view->currentBuffer()->text->SetSelectionOverString(replacestring.c_str());
+       current_view->buffer()->text->SetSelectionOverString(replacestring.c_str());
 
        // Go back so that replacement string is also spellchecked
        for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
-               current_view->currentBuffer()->text->CursorLeftIntern();
+               current_view->buffer()->text->CursorLeftIntern();
        }
-       current_view->currentBuffer()->update(1);
+       current_view->buffer()->update(1);
 }
 // End of spellchecker stuff
 
@@ -3652,7 +3652,7 @@ struct TocList {
 static TocList* toclist = 0;
 
 
-void TocSelectCB(FL_OBJECT *ob, long)
+extern "C" void TocSelectCB(FL_OBJECT *ob, long)
 {
        if (!current_view->available())
                return;
@@ -3661,7 +3661,7 @@ void TocSelectCB(FL_OBJECT *ob, long)
        int i = fl_get_browser(ob);
        int a = 0;
 
-       for (a=1; a<i && tmptoclist->next; a++){
+       for (a = 1; a<i && tmptoclist->next; a++){
                tmptoclist = tmptoclist->next;
        }
 
@@ -3669,7 +3669,7 @@ void TocSelectCB(FL_OBJECT *ob, long)
                return;
      
 
-       LyXParagraph *par = current_view->currentBuffer()->paragraph;
+       LyXParagraph *par = current_view->buffer()->paragraph;
        while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
                       par->GetFirstCounter(1) != tmptoclist->counter[1] ||
                       par->GetFirstCounter(2) != tmptoclist->counter[2] ||
@@ -3682,10 +3682,10 @@ void TocSelectCB(FL_OBJECT *ob, long)
    
        if (par) {
                BeforeChange();
-               current_view->currentBuffer()->text->SetCursor(par, 0);
-               current_view->currentBuffer()->text->sel_cursor =
-                       current_view->currentBuffer()->text->cursor;
-               current_view->currentBuffer()->update(0);
+               current_view->buffer()->text->SetCursor(par, 0);
+               current_view->buffer()->text->sel_cursor = 
+                       current_view->buffer()->text->cursor;
+               current_view->buffer()->update(0);
        }
        else {
                WriteAlert(_("Error"), 
@@ -3696,16 +3696,16 @@ void TocSelectCB(FL_OBJECT *ob, long)
 }
 
 
-void TocCancelCB(FL_OBJECT *, long)
+extern "C" void TocCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_toc->form_toc);
 }
 
 
-void TocUpdateCB(FL_OBJECT *, long)
+extern "C" void TocUpdateCB(FL_OBJECT *, long)
 {
-       static LyXParagraph* stapar = 0;
-       TocList *tmptoclist = 0;
+       static LyXParagraph * stapar = 0;
+       TocList * tmptoclist = 0;
    
        /* deleted the toclist */ 
        if (toclist){
@@ -3726,10 +3726,9 @@ void TocUpdateCB(FL_OBJECT *, long)
        }
        fl_hide_object(fd_form_toc->browser_toc);
        /* get the table of contents */ 
-       LyXParagraph *par = current_view->currentBuffer()->paragraph;
+       LyXParagraph * par = current_view->buffer()->paragraph;
        char labeltype;
-       char* line = new char[200];
-       //int i = 0;
+       char * line = new char[200];
        int pos = 0;
        unsigned char c;
        int topline = 0;
@@ -3739,24 +3738,23 @@ void TocUpdateCB(FL_OBJECT *, long)
        stapar = par;
    
        while (par) {
-               labeltype = lyxstyle.Style(current_view->currentBuffer()->params.textclass, 
-                                          par->GetLayout())->labeltype;
+               labeltype = textclasslist.Style(current_view->buffer()->params.textclass, 
+                                          par->GetLayout()).labeltype;
       
                if (labeltype >= LABEL_COUNTER_CHAPTER
                    && labeltype <= LABEL_COUNTER_CHAPTER +
-                   current_view->currentBuffer()->params.tocdepth) {
+                   current_view->buffer()->params.tocdepth) {
                        /* insert this into the table of contents */ 
                        /* first indent a little bit */ 
                        
-                       for (pos=0; 
+                       for (pos = 0; 
                             pos < (labeltype - 
-                                   lyxstyle.TextClass(current_view->currentBuffer()->
-                                                      params.textclass)->maxcounter) * 4 + 2;
+                                   textclasslist.TextClass(current_view->buffer()->
+                                                      params.textclass).maxcounter()) * 4 + 2;
                             pos++)
                                line[pos] = ' ';
                        
                        // Then the labestring
-                       //i = 0;
                        if (!par->labelstring.empty()) {
                                string::size_type i = 0;
                                while (pos < 199 && i < par->labelstring.length()) {
@@ -3769,11 +3767,11 @@ void TocUpdateCB(FL_OBJECT *, long)
                        line[pos] = ' ';
                        pos++;
                        
-                       /* now the contents */ 
-                       int i = 0;
-                       while (pos < 199 && i < par->last) {
+                       /* now the contents */
+                       LyXParagraph::size_type i = 0;
+                       while (pos < 199 && i < par->size()) {
                                c = par->GetChar(i);
-                               if (isprint((unsigned char) c) || c >= 128) {
+                               if (isprint(c) || c >= 128) {
                                        line[pos] = c;
                                        pos++;
                                }
@@ -3793,7 +3791,7 @@ void TocUpdateCB(FL_OBJECT *, long)
                        
                        tmptoclist->next = 0;
                        int a = 0;
-                       for (a=0; a<6; a++){
+                       for (a = 0; a<6; a++){
                                tmptoclist->counter[a] = par->GetFirstCounter(a);
                        }
                        tmptoclist->appendix = par->appendix;
@@ -3808,12 +3806,12 @@ void TocUpdateCB(FL_OBJECT *, long)
 
 
 /* callbacks for form form_ref */
-void RefSelectCB(FL_OBJECT *, long data)
+extern "C" void RefSelectCB(FL_OBJECT *, long data)
 {
        if (!current_view->available())
                return;
 
-       string s =
+       string s = 
                fl_get_browser_line(fd_form_ref->browser_ref,
                                    fl_get_browser(fd_form_ref->browser_ref));
        string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
@@ -3821,29 +3819,29 @@ void RefSelectCB(FL_OBJECT *, long data)
        if (s.empty())
                return;
 
-        if (data==2) {
-                current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
+        if (data == 2) {
+                current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
                return;
        }
            
        string t;
-       if (data==0)
+       if (data == 0)
                t += "\\ref";
        else
                t += "\\pageref";
 
-       if(current_view->currentBuffer()->isSGML())
+       if(current_view->buffer()->isSGML())
                t += "[" + u + "]" + "{" + s + "}";
        else
                t += "{" + s + "}";
 
-       Inset *new_inset =
-               new InsetRef(t, current_view->currentBuffer());
-       current_view->currentBuffer()->insertInset(new_inset);
+       Inset *new_inset = 
+               new InsetRef(t, current_view->buffer());
+       current_view->buffer()->insertInset(new_inset);
 }
 
 
-void RefUpdateCB(FL_OBJECT *, long)
+extern "C" void RefUpdateCB(FL_OBJECT *, long)
 {
        if (!current_view->available()) {
                fl_clear_browser(fd_form_ref->browser_ref);
@@ -3853,19 +3851,19 @@ void RefUpdateCB(FL_OBJECT *, long)
        FL_OBJECT * brow = fd_form_ref->browser_ref;
 
        // Get the current line, in order to restore it later
-       char const * const btmp=fl_get_browser_line(brow,
+       char const * const btmp = fl_get_browser_line(brow,
                                                     fl_get_browser(brow));
-       string currentstr=btmp ? btmp : "";
+       string currentstr = btmp ? btmp : "";
        //string currentstr = fl_get_browser_line(brow,
        //                                      fl_get_browser(brow));
 
        fl_clear_browser(brow);
 
-       string refs = current_view->currentBuffer()->getReferenceList('\n');
+       string refs = current_view->buffer()->getReferenceList('\n');
        int topline = 1;
 
 #if FL_REVISION > 85
-       fl_addto_browser_chars(brow,refs.c_str());
+       fl_addto_browser_chars(brow, refs.c_str());
        int total_lines = fl_get_browser_maxline(brow);
        for (int i = 1; i <= total_lines ; i++) {
                if (fl_get_browser_line(brow, i) == currentstr) {
@@ -3880,10 +3878,10 @@ void RefUpdateCB(FL_OBJECT *, long)
        int ref_num = 0;
                                        
        while(true) {
-               curr_ref = refs.token('\n',ref_num);
+               curr_ref = refs.token('\n', ref_num);
                if (curr_ref.empty())
                        break;
-               fl_add_browser_line(brow,curr_ref.c_str());
+               fl_add_browser_line(brow, curr_ref.c_str());
                ref_num++;
        }
 #endif
@@ -3896,12 +3894,12 @@ void RefUpdateCB(FL_OBJECT *, long)
                fl_select_browser_line(brow, topline);
                fl_activate_object(brow);
        }
-       if (current_view->currentBuffer()->isReadonly()) {
+       if (current_view->buffer()->isReadonly()) {
                // would be better to de/activate insert buttons
                // but that's more work... besides this works. ARRae
                fl_hide_form(fd_form_ref->form_ref);
        }
-       if (!current_view->currentBuffer()->isSGML()) {
+       if (!current_view->buffer()->isSGML()) {
                fl_deactivate_object(fd_form_ref->ref_name);
                fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
        }
@@ -3912,7 +3910,7 @@ void RefUpdateCB(FL_OBJECT *, long)
 }
 
 
-void RefHideCB(FL_OBJECT *, long)
+extern "C" void RefHideCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_ref->form_ref);
 }
@@ -3924,13 +3922,13 @@ void UpdateInset(Inset* inset, bool mark_dirty)
                return;
 
        /* very first check for locking insets*/
-       if (current_view->currentBuffer()->the_locking_inset == inset){
-               if (current_view->currentBuffer()->text->UpdateInset(inset)){
+       if (current_view->buffer()->the_locking_inset == inset){
+               if (current_view->buffer()->text->UpdateInset(inset)){
                        current_view->update();
                        if (mark_dirty){
-                               if (current_view->currentBuffer()->isLyxClean())
+                               if (current_view->buffer()->isLyxClean())
                                        minibuffer->setTimer(4);
-                               current_view->currentBuffer()->markDirty();
+                               current_view->buffer()->markDirty();
                        }
                        current_view->updateScrollbar();
                        return;
@@ -3940,12 +3938,12 @@ void UpdateInset(Inset* inset, bool mark_dirty)
        /* first check the current buffer */
        if (current_view->available()){
                current_view->getScreen()->HideCursor();
-               current_view->currentBuffer()->update(-3);
-               if (current_view->currentBuffer()->text->UpdateInset(inset)){
+               current_view->buffer()->update(-3);
+               if (current_view->buffer()->text->UpdateInset(inset)){
                        if (mark_dirty)
-                               current_view->currentBuffer()->update(1);
+                               current_view->buffer()->update(1);
                        else 
-                               current_view->currentBuffer()->update(3);
+                               current_view->buffer()->update(3);
                        return;
                }
        }
@@ -3960,8 +3958,8 @@ void UpdateInset(Inset* inset, bool mark_dirty)
    otherwise 0 */
 int LockInset(UpdatableInset* inset)
 {
-       if (!current_view->currentBuffer()->the_locking_inset && inset){
-               current_view->currentBuffer()->the_locking_inset = inset;
+       if (!current_view->buffer()->the_locking_inset && inset){
+               current_view->buffer()->the_locking_inset = inset;
                return 0;
        }
        return 1;
@@ -3970,9 +3968,9 @@ int LockInset(UpdatableInset* inset)
 
 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
 {
-       if (current_view->currentBuffer()->the_locking_inset &&
+       if (current_view->buffer()->the_locking_inset &&
            current_view->getScreen()){
-               y += current_view->currentBuffer()->text->cursor.y;
+               y += current_view->buffer()->text->cursor.y;
                current_view->getScreen()->ShowManualCursor(x, y,
                                                            asc, desc);
        }
@@ -3981,9 +3979,9 @@ void ShowLockedInsetCursor(long x, long y, int asc, int desc)
 
 void HideLockedInsetCursor(long x, long y, int asc, int desc)
 {
-       if (current_view->currentBuffer()->the_locking_inset &&
+       if (current_view->buffer()->the_locking_inset &&
            current_view->getScreen()){
-               y += current_view->currentBuffer()->text->cursor.y;
+               y += current_view->buffer()->text->cursor.y;
                current_view->getScreen()->HideManualCursor(x, y,
                                                            asc, desc);
        }
@@ -3992,9 +3990,9 @@ void HideLockedInsetCursor(long x, long y, int asc, int desc)
 
 void FitLockedInsetCursor(long x, long y, int asc, int desc)
 {
-       if (current_view->currentBuffer()->the_locking_inset &&
+       if (current_view->buffer()->the_locking_inset &&
            current_view->getScreen()){
-               y += current_view->currentBuffer()->text->cursor.y;
+               y += current_view->buffer()->text->cursor.y;
                if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
                        current_view->updateScrollbar();
        }
@@ -4004,10 +4002,10 @@ void FitLockedInsetCursor(long x, long y, int asc, int desc)
 int UnlockInset(UpdatableInset* inset)
 {
        if (inset &&
-           current_view->currentBuffer()->the_locking_inset == inset){
+           current_view->buffer()->the_locking_inset == inset){
                inset->InsetUnlock();
-               current_view->currentBuffer()->the_locking_inset = 0;
-               current_view->currentBuffer()->text->FinishUndo();
+               current_view->buffer()->the_locking_inset = 0;
+               current_view->buffer()->text->FinishUndo();
                return 0;
        }
        return bufferlist.unlockInset(inset);
@@ -4016,15 +4014,15 @@ int UnlockInset(UpdatableInset* inset)
 
 void LockedInsetStoreUndo(Undo::undo_kind kind)
 {
-       if (!current_view->currentBuffer()->the_locking_inset)
+       if (!current_view->buffer()->the_locking_inset)
                return; // shouldn't happen
        if (kind == Undo::EDIT) // in this case insets would not be stored!
                kind = Undo::FINISH;
-       current_view->currentBuffer()->text->SetUndo(kind,
-                             current_view->currentBuffer()->text->cursor.par->
-                             ParFromPos(current_view->currentBuffer()->text->cursor.pos)->previous, 
-                             current_view->currentBuffer()->text->cursor.par->
-                             ParFromPos(current_view->currentBuffer()->text->cursor.pos)->next); 
+       current_view->buffer()->text->SetUndo(kind,
+                             current_view->buffer()->text->cursor.par->
+                             ParFromPos(current_view->buffer()->text->cursor.pos)->previous, 
+                             current_view->buffer()->text->cursor.par->
+                             ParFromPos(current_view->buffer()->text->cursor.pos)->next); 
 }
 
 
@@ -4047,7 +4045,7 @@ void UpdateInsetUpdateList()
                tmp = tmp->next;
        }
   
-       /* delete the update list */
+       // delete the update list
        while (InsetUpdateList) {
                tmp = InsetUpdateList;
                InsetUpdateList = InsetUpdateList->next;
@@ -4056,16 +4054,17 @@ void UpdateInsetUpdateList()
        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)
+void addNewlineAndDepth(string & file, int const depth)
 {
        file += '\n';
-       for (int j=0;j< depth;j++)
-               file += ' ';
+       file.append(depth, ' ');
 }