]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
Point fix, earlier forgotten
[lyx.git] / src / BufferView.C
index dfeefc02c52acc5434a7ae166947b1c34f92b2e8..b8ee1de146b91b3e58607a1b6743a021f195de47 100644 (file)
@@ -1,10 +1,15 @@
 /**
  * \file BufferView.C
- * Copyright 1995-2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
+ * \author Alfredo Braustein
  * \author Lars Gullik Bjønnes
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ * \author André Pönitz
+ * \author Jürgen Vigna
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
@@ -42,6 +47,7 @@
 #include "support/filetools.h"
 #include "support/types.h"
 #include "support/lyxalgo.h" // lyx_count
+#include "support/LAssert.h"
 
 #include <fstream>
 
@@ -214,15 +220,21 @@ int BufferView::workWidth() const
 }
 
 
-void BufferView::toggleSelection(bool b)
+void BufferView::center()
 {
-       pimpl_->toggleSelection(b);
+       pimpl_->center();
 }
 
 
-void BufferView::center()
+int BufferView::top_y() const
 {
-       pimpl_->center();
+       return pimpl_->top_y();
+}
+
+
+void BufferView::top_y(int y)
+{
+       pimpl_->top_y(y);
 }
 
 
@@ -260,51 +272,15 @@ bool BufferView::insertLyXFile(string const & filen)
        //
        // Moved from lyx_cb.C (Lgb)
 {
-       if (filen.empty())
-               return false;
+       Assert(!filen.empty());
 
        string const fname = MakeAbsPath(filen);
 
-       // check if file exist
-       FileInfo const fi(fname);
-
-       if (!fi.readable()) {
-               string const file = MakeDisplayPath(fname, 50);
-               string const text =
-                       bformat(_("The specified document\n%1$s\ncould not be read."), file);
-               Alert::error(_("Could not read document"), text);
-               return false;
-       }
-
        beforeChange(text);
 
-       ifstream ifs(fname.c_str());
-       if (!ifs) {
-               string const file = MakeDisplayPath(fname, 50);
-               string const text =
-                       bformat(_("Could not open the specified document %1$s\n"), file);
-               Alert::error(_("Could not open file"), text);
-               return false;
-       }
-
-       int const c = ifs.peek();
-
-       LyXLex lex(0, 0);
-       lex.setStream(ifs);
-
-       bool res = true;
-
        text->breakParagraph(buffer()->paragraphs);
 
-       if (c == '#') {
-               // FIXME: huh ? No we won't !
-               lyxerr[Debug::INFO] << "Will insert file with header" << endl;
-               res = buffer()->readFile(lex, fname, ParagraphList::iterator(text->cursor.par()));
-       } else {
-               lyxerr[Debug::INFO] << "Will insert file without header"
-                                   << endl;
-               res = buffer()->readBody(lex, ParagraphList::iterator(text->cursor.par()));
-       }
+       bool res = buffer()->readFile(fname, text->cursor.par());
 
        resize();
        return res;
@@ -419,7 +395,6 @@ void BufferView::selectLastWord()
        beforeChange(text);
        text->selection.cursor = cur;
        text->selectSelectedWord();
-       toggleSelection(false);
        update();
 }
 
@@ -442,22 +417,15 @@ void BufferView::replaceWord(string const & replacestring)
 
        LyXText * tt = getLyXText();
 
-       // clear the selection (if there is any)
-       toggleSelection(false);
-
-       // clear the selection (if there is any)
-       toggleSelection(false);
        tt->replaceSelectionWithString(replacestring);
-
        tt->setSelectionRange(replacestring.length());
 
        // Go back so that replacement string is also spellchecked
-       for (string::size_type i = 0; i < replacestring.length() + 1; ++i) 
+       for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
                tt->cursorLeft(this);
 
        // FIXME: should be done through LFUN
        buffer()->markDirty();
-       fitCursor();
        update();
 }
 
@@ -511,7 +479,7 @@ bool BufferView::lockInset(UpdatableInset * inset)
 bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
 {
        if (theLockingInset() && available()) {
-               y += text->cursor.iy() + theLockingInset()->insetInInsetY();
+               y += text->cursor.y() + theLockingInset()->insetInInsetY();
                if (screen().fitManualCursor(this, text, x, y, asc, desc)) {
                        updateScrollbar();
                        return true;
@@ -552,9 +520,9 @@ int BufferView::unlockInset(UpdatableInset * inset)
 }
 
 
-void BufferView::updateInset()
+void BufferView::updateInset(InsetOld const * inset)
 {
-       pimpl_->updateInset();
+       pimpl_->updateInset(inset);
 }
 
 
@@ -638,25 +606,11 @@ LyXText * BufferView::getLyXText() const
 }
 
 
-LyXText * BufferView::getParentText(InsetOld * inset) const
-{
-       if (inset->owner()) {
-               LyXText * txt = inset->getLyXText(this);
-               inset = inset->owner();
-               while (inset && inset->getLyXText(this) == txt)
-                       inset = inset->owner();
-               if (inset)
-                       return inset->getLyXText(this);
-       }
-       return text;
-}
-
-
 Language const * BufferView::getParentLanguage(InsetOld * inset) const
 {
-       LyXText * text = getParentText(inset);
-       return text->cursor.par()->getFontSettings(buffer()->params,
-                                                  text->cursor.pos()).language();
+       Paragraph const & par = ownerPar(*buffer(), inset);
+       return par.getFontSettings(buffer()->params,
+                                  par.getPositionOfInset(inset)).language();
 }