]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
Move #includes out of header files.
[lyx.git] / src / BufferView.C
index 476c6a207389b16d71562d4ed2f810f6a8266c68..81a59e3e05287a710b40764058b3c0eabcdb31a5 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>
@@ -20,6 +25,7 @@
 #include "debug.h"
 #include "gettext.h"
 #include "errorlist.h"
+#include "funcrequest.h"
 #include "iterators.h"
 #include "language.h"
 #include "lyxcursor.h"
@@ -42,6 +48,7 @@
 #include "support/filetools.h"
 #include "support/types.h"
 #include "support/lyxalgo.h" // lyx_count
+#include "support/LAssert.h"
 
 #include <fstream>
 
@@ -214,35 +221,33 @@ 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();
 }
 
 
-string const BufferView::getClipboard() const
+void BufferView::top_y(int y)
 {
-       return pimpl_->workarea().getClipboard();
+       pimpl_->top_y(y);
 }
 
 
-void BufferView::stuffClipboard(string const & stuff) const
+string const BufferView::getClipboard() const
 {
-       pimpl_->stuffClipboard(stuff);
+       return pimpl_->workarea().getClipboard();
 }
 
 
-BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
-                                 BufferView::UpdateCodes uc2)
+void BufferView::stuffClipboard(string const & stuff) const
 {
-       return static_cast<BufferView::UpdateCodes>
-               (static_cast<int>(uc1) | static_cast<int>(uc2));
+       pimpl_->stuffClipboard(stuff);
 }
 
 
@@ -268,51 +273,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;
@@ -427,7 +396,6 @@ void BufferView::selectLastWord()
        beforeChange(text);
        text->selection.cursor = cur;
        text->selectSelectedWord();
-       toggleSelection(false);
        update();
 }
 
@@ -450,22 +418,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();
 }
 
@@ -519,7 +480,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;
@@ -560,7 +521,7 @@ int BufferView::unlockInset(UpdatableInset * inset)
 }
 
 
-void BufferView::updateInset(InsetOld * inset)
+void BufferView::updateInset(InsetOld const * inset)
 {
        pimpl_->updateInset(inset);
 }
@@ -646,25 +607,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();
 }