]> git.lyx.org Git - features.git/blobdiff - src/buffer.C
some new (not extensive) changes, some fixes, will probably reverto to .la libs later...
[features.git] / src / buffer.C
index 19525c9d2d5210a8eec16dad97304664fd08da69..e0953cf145bdde710a6fad6f78f0acb7232a5fe5 100644 (file)
@@ -101,8 +101,6 @@ using std::setw;
 
 // all these externs should eventually be removed.
 extern BufferList bufferlist;
-extern unsigned char GetCurrentTextClass();
-extern void BeforeChange();
 
 extern void MenuExport(Buffer *, string const &);
 extern LyXAction lyxaction;
@@ -121,14 +119,12 @@ Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly)
        filename = file;
        filepath = OnlyPath(file);
        paragraph = 0;
-       the_locking_inset = 0;
        lyx_clean = true;
        bak_clean = true;
        dvi_clean_orgd = false;  // Heinrich Bauer, 23/03/98
        dvi_clean_tmpd = false;  // Heinrich Bauer, 23/03/98
        dep_clean = 0;
        read_only = ronly;
-       inset_slept = false;
        users = 0;
        lyxvc.buffer(this);
        if (read_only || (lyxrc && lyxrc->use_tempdir)) {
@@ -204,21 +200,8 @@ void Buffer::fileName(string const & newfile)
 }
 
 
-// candidate for move to BufferView
-void Buffer::InsetUnlock()
-{
-       if (the_locking_inset) {
-               if (!inset_slept) the_locking_inset->InsetUnlock();
-               the_locking_inset = 0;
-               users->text->FinishUndo();
-               inset_slept = false;
-       }
-}
-
-
-// candidate for move to BufferView
 // Inserts a file into current document
-bool Buffer::insertLyXFile(string const & filen)
+bool BufferView::insertLyXFile(string const & filen)
        //
        // (c) CHT Software Service GmbH
        // Uwe C. Schroeder
@@ -241,7 +224,7 @@ bool Buffer::insertLyXFile(string const & filen)
                return false;
        }
        
-       BeforeChange();
+       beforeChange();
 
        ifstream ifs(fname.c_str());
        if (!ifs) {
@@ -259,10 +242,10 @@ bool Buffer::insertLyXFile(string const & filen)
 
        if (c == '#') {
                lyxerr.debug() << "Will insert file with header" << endl;
-               res = readFile(lex, users->text->cursor.par);
+               res = buffer()->readFile(lex, text->cursor.par);
        } else {
                lyxerr.debug() << "Will insert file without header" << endl;
-               res = readLyXformat2(lex, users->text->cursor.par);
+               res = buffer()->readLyXformat2(lex, text->cursor.par);
        }
 
        resize();
@@ -1577,7 +1560,10 @@ void Buffer::makeLaTeXFile(string const & fname,
                           bool nice, bool only_body)
 {
        lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
-       params.textclass = GetCurrentTextClass();
+       
+       // How the **** can this be needed?
+       //params.textclass = current_view->buffer()->params.textclass;
+       
        niceFile = nice; // this will be used by Insetincludes.
 
        tex_code_break_column = lyxrc->ascii_linelen;
@@ -2121,14 +2107,6 @@ bool Buffer::isSGML() const
 void Buffer::sgmlOpenTag(ostream & os, int depth,
                         string const & latexname) const
 {
-#if 0
-       static char const * space[] = {
-               " ","  ", "   ", "    ", "     ", "      ",
-               "       ",
-               "        ", "         ", "          ",
-               "          "};
-       os << space[depth] << "<" << latexname << ">\n";
-#endif
        os << string(depth, ' ') << "<" << latexname << ">\n";
 }
 
@@ -2136,13 +2114,6 @@ void Buffer::sgmlOpenTag(ostream & os, int depth,
 void Buffer::sgmlCloseTag(ostream & os, int depth,
                          string const & latexname) const
 {
-#if 0
-       static char * space[] = {" ", "  ", "   ", "    ", "     ",
-                                "      ", "       ", "        ",
-                                "         ", "          ", "          "};
-
-       os << space[depth] << "</" << latexname << ">\n";
-#endif
        os << string(depth, ' ') << "</" << latexname << ">\n";
 }
 
@@ -2191,7 +2162,7 @@ void Buffer::makeLinuxDocFile(string const & fname, int column)
        while (par) {
                int desc_on = 0;            /* description mode*/
                LyXLayout const & style =
-                       textclasslist.Style(GetCurrentTextClass(),
+                       textclasslist.Style(users->buffer()->params.textclass,
                                            par->layout);
                par->AutoDeleteInsets();
 
@@ -2209,13 +2180,13 @@ void Buffer::makeLinuxDocFile(string const & fname, int column)
                        }
                }
 
-               /* environment tag closing */
+               // environment tag closing
                for( ; depth > par->depth; --depth) {
                        sgmlCloseTag(ofs, depth, environment_stack[depth]);
                        environment_stack[depth].clear();
                }
 
-               /* write opening SGML tags */
+               // write opening SGML tags
                switch(style.latextype) {
                case LATEX_PARAGRAPH:
                        if(depth == par->depth 
@@ -2774,7 +2745,7 @@ void Buffer::makeDocBookFile(string const & fname, int column)
 
        while (par) {
                int desc_on= 0;            /* description mode*/
-               LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
+               LyXLayout const & style = textclasslist.Style(users->buffer()->params.textclass,
                                                   par->layout);
                par->AutoDeleteInsets();
 
@@ -3135,12 +3106,11 @@ void Buffer::SimpleDocBookOnePar(string & file, string & extra,
 }
 
 
-// candidate for move to BufferView
-bool Buffer::removeAutoInsets()
+bool BufferView::removeAutoInsets()
 {
-       LyXParagraph * par = paragraph;
+       LyXParagraph * par = buffer()->paragraph;
 
-       LyXCursor cursor = users->text->cursor;
+       LyXCursor cursor = text->cursor;
        LyXCursor tmpcursor = cursor;
        cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
        cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
@@ -3150,19 +3120,20 @@ bool Buffer::removeAutoInsets()
                if (par->AutoDeleteInsets()){
                        a = true;
                        if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
-                               /* this is possible now, since SetCursor takes
-                                  care about footnotes */
-                               users->text->SetCursorIntern(par, 0);
-                               users->text->RedoParagraphs(users->text->cursor, users->text->cursor.par->Next());
-                               users->text->FullRebreak();
+                               // this is possible now, since SetCursor takes
+                               // care about footnotes
+                               text->SetCursorIntern(par, 0);
+                               text->RedoParagraphs(text->cursor,
+                                                    text->cursor.par->Next());
+                               text->FullRebreak();
                        }
                }
                par = par->next;
        }
-       /* avoid forbidden cursor positions caused by error removing */ 
+       // avoid forbidden cursor positions caused by error removing
        if (cursor.pos > cursor.par->Last())
                cursor.pos = cursor.par->Last();
-       users->text->SetCursorIntern(cursor.par, cursor.pos);
+       text->SetCursorIntern(cursor.par, cursor.pos);
 
        return a;
 }
@@ -3188,7 +3159,7 @@ int Buffer::runLaTeX()
        users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));   
 
        // Remove all error insets
-       bool a = removeAutoInsets();
+       bool a = users->removeAutoInsets();
 
        // Always generate the LaTeX file
        makeLaTeXFile(name, org_path, false);
@@ -3207,7 +3178,7 @@ int Buffer::runLaTeX()
        } else if ((res & LaTeX::ERRORS)) {
                users->owner()->getMiniBuffer()->Set(_("Done"));
                // Insert all errors as errors boxes
-               insertErrors(terr);
+               users->insertErrors(terr);
                
                // Dvi should also be kept dirty if the latex run
                // ends up with errors. However it should be possible
@@ -3254,7 +3225,7 @@ int Buffer::runLiterate()
        users->owner()->getMiniBuffer()->Set(_("Running Literate..."));   
 
        // Remove all error insets
-       bool a = removeAutoInsets();
+       bool a = users->removeAutoInsets();
 
        // generate the Literate file if necessary
        if (!isDviClean() || a) {
@@ -3276,7 +3247,7 @@ int Buffer::runLiterate()
        } else if ((res & Literate::ERRORS)) {
                users->owner()->getMiniBuffer()->Set(_("Done"));
                // Insert all errors as errors boxes
-               insertErrors(terr);
+               users->insertErrors(terr);
                
                // Dvi should also be kept dirty if the latex run
                // ends up with errors. However it should be possible
@@ -3323,7 +3294,7 @@ int Buffer::buildProgram()
         users->owner()->getMiniBuffer()->Set(_("Building Program..."));   
  
         // Remove all error insets
-        bool a = removeAutoInsets();
+        bool a = users->removeAutoInsets();
  
         // generate the LaTeX file if necessary
         if (!isNwClean() || a) {
@@ -3345,7 +3316,7 @@ int Buffer::buildProgram()
         } else if ((res & Literate::ERRORS)) {
                 users->owner()->getMiniBuffer()->Set(_("Done"));
                 // Insert all errors as errors boxes
-                insertErrors(terr);
+               users->insertErrors(terr);
                 
                 // Literate files should also be kept dirty if the literate 
                 // command run ends up with errors.
@@ -3390,7 +3361,7 @@ int Buffer::runChktex()
        users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
 
        // Remove all error insets
-       bool a = removeAutoInsets();
+       bool a = users->removeAutoInsets();
 
        // Generate the LaTeX file if neccessary
        if (!isDviClean() || a) {
@@ -3407,7 +3378,7 @@ int Buffer::runChktex()
                           _("Could not run with file:"), name);
        } else if (res > 0) {
                // Insert all errors as errors boxes
-               insertErrors(terr);
+               users->insertErrors(terr);
        }
 
        // if we removed error insets before we ran chktex or if we inserted
@@ -3423,18 +3394,14 @@ int Buffer::runChktex()
 }
 
 
-extern void AllFloats(char, char);
-
-
-// candidate for move to BufferView
-void Buffer::insertErrors(TeXErrors & terr)
+void BufferView::insertErrors(TeXErrors & terr)
 {
        // Save the cursor position
-       LyXCursor cursor = users->text->cursor;
+       LyXCursor cursor = text->cursor;
 
        // This is drastic, but it's the only fix, I could find. (Asger)
-       AllFloats(1, 0);
-       AllFloats(1, 1);
+       allFloats(1, 0);
+       allFloats(1, 1);
 
        for (TeXErrors::Errors::const_iterator cit = terr.begin();
             cit != terr.end();
@@ -3448,47 +3415,46 @@ void Buffer::insertErrors(TeXErrors & terr)
                int tmpid = -1; 
                int tmppos = -1;
 
-               texrow.getIdFromRow(errorrow, tmpid, tmppos);
+               buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos);
 
                LyXParagraph * texrowpar = 0;
 
                if (tmpid == -1) {
-                       texrowpar = users->text->FirstParagraph();
+                       texrowpar = text->FirstParagraph();
                        tmppos = 0;
                } else {
-                       texrowpar = users->text->GetParFromID(tmpid);
+                       texrowpar = text->GetParFromID(tmpid);
                }
 
                if (texrowpar == 0)
                        continue;
 
                InsetError * new_inset = new InsetError(msgtxt);
-               users->text->SetCursorIntern(texrowpar, tmppos);
-               users->text->InsertInset(new_inset);
-               users->text->FullRebreak();
+               text->SetCursorIntern(texrowpar, tmppos);
+               text->InsertInset(new_inset);
+               text->FullRebreak();
        }
        // Restore the cursor position
-       users->text->SetCursorIntern(cursor.par, cursor.pos);
+       text->SetCursorIntern(cursor.par, cursor.pos);
 }
 
 
-// candidate for move to BufferView
-void Buffer::setCursorFromRow (int row)
+void BufferView::setCursorFromRow(int row)
 {
        int tmpid = -1; 
        int tmppos = -1;
 
-       texrow.getIdFromRow(row, tmpid, tmppos);
+       buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
 
        LyXParagraph * texrowpar;
 
        if (tmpid == -1) {
-               texrowpar = users->text->FirstParagraph();
+               texrowpar = text->FirstParagraph();
                tmppos = 0;
        } else {
-               texrowpar = users->text->GetParFromID(tmpid);
+               texrowpar = text->GetParFromID(tmpid);
        }
-       users->text->SetCursor(texrowpar, tmppos);
+       text->SetCursor(texrowpar, tmppos);
 }
 
 
@@ -3751,74 +3717,72 @@ void Buffer::setOldPaperStuff()
 #endif
 
 
-// candidate for move to BufferView
-void Buffer::insertInset(Inset * inset, string const & lout,
+void BufferView::insertInset(Inset * inset, string const & lout,
                         bool no_table)
 {
        // check for table/list in tables
-       if (no_table && users->text->cursor.par->table){
+       if (no_table && text->cursor.par->table){
                WriteAlert(_("Impossible Operation!"),
                           _("Cannot insert table/list in table."),
                           _("Sorry."));
                return;
        }
        // not quite sure if we want this...
-       users->text->SetCursorParUndo();
-       users->text->FreezeUndo();
+       text->SetCursorParUndo();
+       text->FreezeUndo();
        
-       BeforeChange();
+       beforeChange();
        if (!lout.empty()) {
-               users->update(-2);
-               users->text->BreakParagraph();
-               users->update(-1);
+               update(-2);
+               text->BreakParagraph();
+               update(-1);
                
-               if (users->text->cursor.par->Last()) {
-                       users->text->CursorLeft();
+               if (text->cursor.par->Last()) {
+                       text->CursorLeft();
                        
-                       users->text->BreakParagraph();
-                       users->update(-1);
+                       text->BreakParagraph();
+                       update(-1);
                }
 
-               int lay = textclasslist.NumberOfLayout(params.textclass,
+               int lay = textclasslist.NumberOfLayout(buffer()->params.textclass,
                                                       lout).second;
                if (lay == -1) // layout not found
                        // use default layout "Standard" (0)
                        lay = 0;
                
-               users->text->SetLayout(lay);
+               text->SetLayout(lay);
                
-               users->text->SetParagraph(0, 0,
+               text->SetParagraph(0, 0,
                                   0, 0,
                                   VSpace(VSpace::NONE), VSpace(VSpace::NONE),
                                   LYX_ALIGN_LAYOUT, 
                                   string(),
                                   0);
-               users->update(-1);
+               update(-1);
                
-               users->text->current_font.setLatex(LyXFont::OFF);
+               text->current_font.setLatex(LyXFont::OFF);
        }
        
-       users->text->InsertInset(inset);
-       users->update(-1);
+       text->InsertInset(inset);
+       update(-1);
 
-       users->text->UnFreezeUndo();    
+       text->UnFreezeUndo();   
 }
 
 
 // Open and lock an updatable inset
-// candidate for move to BufferView
-void Buffer::open_new_inset(UpdatableInset * new_inset)
+void BufferView::open_new_inset(UpdatableInset * new_inset)
 {
-       BeforeChange();
-       users->text->FinishUndo();
+       beforeChange();
+       text->FinishUndo();
        insertInset(new_inset);
-       users->text->CursorLeft();
-       users->update(1);
+       text->CursorLeft();
+       update(1);
        new_inset->Edit(0, 0);
 }
 
 
-/* This function should be in Buffer because it's a buffer's property (ale) */
+// This function should be in Buffer because it's a buffer's property (ale)
 string Buffer::getIncludeonlyList(char delim)
 {
        string lst;
@@ -3847,7 +3811,7 @@ string Buffer::getIncludeonlyList(char delim)
 }
 
 
-/* This is also a buffer property (ale) */ 
+// This is also a buffer property (ale)
 string Buffer::getReferenceList(char delim)
 {
        /// if this is a child document and the parent is already loaded
@@ -3879,7 +3843,7 @@ string Buffer::getReferenceList(char delim)
 }
 
 
-/* This is also a buffer property (ale) */ 
+// This is also a buffer property (ale)
 string Buffer::getBibkeyList(char delim)
 {
        /// if this is a child document and the parent is already loaded
@@ -3933,16 +3897,15 @@ string Buffer::getBibkeyList(char delim)
 }
 
 
-// candidate for move to BufferView
 /* This is also a buffer property (ale) */
 // Not so sure about that. a goto Label function can not be buffer local, just
 // think how this will work in a multiwindo/buffer environment, all the
 // cursors in all the views showing this buffer will move. (Lgb)
 // OK, then no cursor action should be allowed in buffer. (ale)
-bool Buffer::gotoLabel(string const & label)
+bool BufferView::gotoLabel(string const & label)
 
 {
-        LyXParagraph * par = paragraph;
+        LyXParagraph * par = buffer()->paragraph;
         LyXParagraph::size_type pos;
         Inset * inset;
         while (par) {
@@ -3950,10 +3913,10 @@ bool Buffer::gotoLabel(string const & label)
                 while ((inset = par->ReturnNextInsetPointer(pos))){     
                         for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
                                if (label == inset->getLabel(i)) {
-                                       BeforeChange();
-                                       users->text->SetCursor(par, pos);
-                                       users->text->sel_cursor = users->text->cursor;
-                                       users->update(0);
+                                       beforeChange();
+                                       text->SetCursor(par, pos);
+                                       text->sel_cursor = text->cursor;
+                                       update(0);
                                        return true;
                                }
                        }
@@ -3997,7 +3960,8 @@ void Buffer::markDepClean(string const & name)
        }
 }
 
-void Buffer::Dispatch(const string & command)
+
+void Buffer::Dispatch(string const & command)
 {
        // Split command string into command and argument
        string cmd, line = frontStrip(command);
@@ -4006,7 +3970,8 @@ void Buffer::Dispatch(const string & command)
        Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
 }
 
-void Buffer::Dispatch(int action, const string & argument)
+
+void Buffer::Dispatch(int action, string const & argument)
 {
        switch (action) {
                case LFUN_EXPORT: 
@@ -4018,5 +3983,4 @@ void Buffer::Dispatch(int action, const string & argument)
                break;
 
        } // end of switch
-
 }