]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
Remove the inset and view member functions from PreviewedInset.
[lyx.git] / src / BufferView.C
index 0517a129fae4c5b1a4378a2cf8c1de45ab106acd..88a8456d9d76ae4fa6f0f385ab52c1fa2d10130b 100644 (file)
@@ -15,6 +15,7 @@
 #include <config.h>
 
 #include "BufferView.h"
+
 #include "buffer.h"
 #include "bufferlist.h"
 #include "BufferView_pimpl.h"
 #include "support/filetools.h"
 #include "support/lyxalgo.h" // lyx_count
 
-
-extern BufferList bufferlist;
-
-using namespace lyx::support;
+using lyx::support::bformat;
+using lyx::support::MakeAbsPath;
 
 using std::find;
+using std::string;
 using std::vector;
 
 
+extern BufferList bufferlist;
+
+
 BufferView::BufferView(LyXView * owner, int xpos, int ypos,
                       int width, int height)
        : pimpl_(new Pimpl(this, owner, xpos, ypos, width, height))
@@ -267,7 +270,7 @@ bool BufferView::insertLyXFile(string const & filen)
 
        text->breakParagraph(buffer()->paragraphs());
 
-       bool res = buffer()->readFile(fname, text->cursor.par());
+       bool res = buffer()->readFile(fname, text->cursorPar());
 
        resize();
        return res;
@@ -298,15 +301,10 @@ void BufferView::setCursorFromRow(int row)
 
        buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
 
-       ParagraphList::iterator texrowpar;
-
-       if (tmpid == -1) {
-               texrowpar = text->ownerParagraphs().begin();
-               tmppos = 0;
-       } else {
-               texrowpar = buffer()->getParFromID(tmpid).pit();
-       }
-       text->setCursor(texrowpar, tmppos);
+       if (tmpid == -1)
+               text->setCursor(0, 0);
+       else
+               text->setCursor(buffer()->getParFromID(tmpid).pit(), tmppos);
 }
 
 
@@ -321,10 +319,12 @@ void BufferView::gotoLabel(string const & label)
        for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
             it != buffer()->inset_iterator_end(); ++it) {
                vector<string> labels;
-               it->getLabelList(labels);
+               it->getLabelList(*buffer(), labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
                        beforeChange(text);
-                       text->setCursor(it.getPar(), it.getPos());
+                       text->setCursor(
+                               std::distance(text->ownerParagraphs().begin(), it.getPar()),
+                               it.getPos());
                        text->selection.cursor = text->cursor;
                        update();
                        return;
@@ -421,45 +421,40 @@ bool BufferView::lockInset(UpdatableInset * inset)
 {
        if (!inset)
                return false;
+
        // don't relock if we're already locked
        if (theLockingInset() == inset)
                return true;
-       if (!theLockingInset()) {
-               // first check if it's the inset under the cursor we want lock
-               // should be most of the time
-               if (text->cursor.pos() < text->cursor.par()->size()
-                   && text->cursor.par()->getChar(text->cursor.pos()) ==
-                   Paragraph::META_INSET) {
-                       InsetOld * in = text->cursor.par()->getInset(text->cursor.pos());
-                       if (inset == in) {
+
+       if (theLockingInset())
+               return theLockingInset()->lockInsetInInset(this, inset);
+
+       // first check if it's the inset under the cursor we want lock
+       // should be most of the time
+       if (text->cursor.pos() < text->cursorPar()->size()
+                       && text->cursorPar()->getChar(text->cursor.pos()) ==
+                       Paragraph::META_INSET) {
+               if (inset == text->cursorPar()->getInset(text->cursor.pos())) {
+                       theLockingInset(inset);
+                       return true;
+               }
+       }
+
+       // then do a deep look at the inset and lock the right one
+       ParagraphList::iterator pit = buffer()->paragraphs().begin();
+       ParagraphList::iterator pend = buffer()->paragraphs().end();
+       for (int par = 0; pit != pend; ++pit, ++par) {
+               InsetList::iterator it = pit->insetlist.begin();
+               InsetList::iterator end = pit->insetlist.end();
+               for (; it != end; ++it) {
+                       if (it->inset == inset) {
+                               text->setCursorIntern(par, it->pos);
                                theLockingInset(inset);
                                return true;
                        }
                }
-               // Then do a deep look of the inset and lock the right one
-               int const id = inset->id();
-               ParagraphList::iterator pit = buffer()->paragraphs().begin();
-               ParagraphList::iterator pend = buffer()->paragraphs().end();
-               for (; pit != pend; ++pit) {
-                       InsetList::iterator it = pit->insetlist.begin();
-                       InsetList::iterator end = pit->insetlist.end();
-                       for (; it != end; ++it) {
-                               if (it->inset == inset) {
-                                       text->setCursorIntern(pit, it->pos);
-                                       theLockingInset(inset);
-                                       return true;
-                               }
-                               if (it->inset->getInsetFromID(id)) {
-                                       text->setCursorIntern(pit, it->pos);
-                                       FuncRequest cmd(this, LFUN_INSET_EDIT, "left");
-                                       it->inset->localDispatch(cmd);
-                                       return theLockingInset()->lockInsetInInset(this, inset);
-                               }
-                       }
-               }
-               return false;
        }
-       return theLockingInset()->lockInsetInInset(this, inset);
+       return false;
 }
 
 
@@ -490,12 +485,13 @@ int BufferView::unlockInset(UpdatableInset * inset)
                inset->insetUnlock(this);
                theLockingInset(0);
                // make sure we update the combo !
-               owner()->setLayout(getLyXText()->cursor.par()->layout()->name());
+               owner()->setLayout(getLyXText()->cursorPar()->layout()->name());
                // Tell the paragraph dialog that we changed paragraph
                dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
                finishUndo();
                return 0;
-       } else if (inset && theLockingInset() &&
+       }
+       if (inset && theLockingInset() &&
                   theLockingInset()->unlockInsetInInset(this, inset)) {
                // Tell the paragraph dialog that we changed paragraph
                dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
@@ -562,14 +558,15 @@ Language const * BufferView::getParentLanguage(InsetOld * inset) const
 
 Encoding const * BufferView::getEncoding() const
 {
-       LyXText * t = getLyXText();
-       if (!t)
+       LyXText * text = getLyXText();
+       if (!text)
                return 0;
 
-       LyXCursor const & c = t->cursor;
-       LyXFont const font = c.par()->getFont(buffer()->params(), c.pos(),
-                                             outerFont(c.par(), t->ownerParagraphs()));
-       return font.language()->encoding();
+       return text->cursorPar()->getFont(
+               buffer()->params(),
+               text->cursor.pos(),
+               outerFont(text->cursorPar(), text->ownerParagraphs())
+       ).language()->encoding();
 }