]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
Point fix, earlier forgotten
[lyx.git] / src / BufferView.C
index ce96e909e1230509f76bc83bc1394a2e36692e2b..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>
 
@@ -196,18 +202,6 @@ bool BufferView::isSavedPosition(unsigned int i)
 }
 
 
-void BufferView::update(LyXText * text, UpdateCodes f)
-{
-       pimpl_->update(text, f);
-}
-
-
-void BufferView::update(UpdateCodes f)
-{
-       pimpl_->update(f);
-}
-
-
 void BufferView::switchKeyMap()
 {
        pimpl_->switchKeyMap();
@@ -226,15 +220,21 @@ int BufferView::workWidth() const
 }
 
 
-void BufferView::toggleSelection(bool b)
+void BufferView::center()
+{
+       pimpl_->center();
+}
+
+
+int BufferView::top_y() const
 {
-       pimpl_->toggleSelection(b);
+       return pimpl_->top_y();
 }
 
 
-void BufferView::center()
+void BufferView::top_y(int y)
 {
-       pimpl_->center();
+       pimpl_->top_y(y);
 }
 
 
@@ -250,14 +250,6 @@ void BufferView::stuffClipboard(string const & stuff) const
 }
 
 
-BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
-                                 BufferView::UpdateCodes uc2)
-{
-       return static_cast<BufferView::UpdateCodes>
-               (static_cast<int>(uc1) | static_cast<int>(uc2));
-}
-
-
 bool BufferView::dispatch(FuncRequest const & ev)
 {
        return pimpl_->dispatch(ev);
@@ -280,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;
@@ -379,12 +335,11 @@ void BufferView::gotoLabel(string const & label)
             it != buffer()->inset_iterator_end(); ++it) {
                vector<string> labels;
                it->getLabelList(labels);
-               if (find(labels.begin(),labels.end(),label)
-                    != labels.end()) {
+               if (find(labels.begin(),labels.end(),label) != labels.end()) {
                        beforeChange(text);
                        text->setCursor(it.getPar(), it.getPos());
                        text->selection.cursor = text->cursor;
-                       update(text, BufferView::SELECT);
+                       update();
                        return;
                }
        }
@@ -398,11 +353,9 @@ void BufferView::undo()
 
        owner()->message(_("Undo"));
        beforeChange(text);
-       update(text, BufferView::SELECT);
        if (!textUndo(this))
                owner()->message(_("No further undo information"));
-       else
-               update(text, BufferView::SELECT);
+       update();
        switchKeyMap();
 }
 
@@ -414,11 +367,9 @@ void BufferView::redo()
 
        owner()->message(_("Redo"));
        beforeChange(text);
-       update(text, BufferView::SELECT);
        if (!textRedo(this))
                owner()->message(_("No further redo information"));
-       else
-               update(text, BufferView::SELECT);
+       update();
        switchKeyMap();
 }
 
@@ -444,8 +395,7 @@ void BufferView::selectLastWord()
        beforeChange(text);
        text->selection.cursor = cur;
        text->selectSelectedWord();
-       toggleSelection(false);
-       update(text, BufferView::SELECT);
+       update();
 }
 
 
@@ -456,7 +406,7 @@ void BufferView::endOfSpellCheck()
        beforeChange(text);
        text->selectSelectedWord();
        text->clearSelection();
-       update(text, BufferView::SELECT);
+       update();
 }
 
 
@@ -466,29 +416,18 @@ void BufferView::replaceWord(string const & replacestring)
                return;
 
        LyXText * tt = getLyXText();
-       update(tt, BufferView::SELECT);
-
-       // clear the selection (if there is any)
-       toggleSelection(false);
-       update(tt, BufferView::SELECT);
 
-       // 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);
-       }
-       update(tt, BufferView::SELECT);
 
        // FIXME: should be done through LFUN
        buffer()->markDirty();
-       fitCursor();
+       update();
 }
-// End of spellchecker stuff
 
 
 bool BufferView::lockInset(UpdatableInset * inset)
@@ -540,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;
@@ -581,7 +520,7 @@ int BufferView::unlockInset(UpdatableInset * inset)
 }
 
 
-void BufferView::updateInset(InsetOld * inset)
+void BufferView::updateInset(InsetOld const * inset)
 {
        pimpl_->updateInset(inset);
 }
@@ -620,7 +559,6 @@ bool BufferView::ChangeInsets(InsetOld::Code code,
                        if (it.size() == 1) {
                                text->setCursorIntern(it.pit(), 0);
                                text->redoParagraph(text->cursor.par());
-                               text->partialRebreak();
                        }
                }
        }
@@ -668,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();
 }