]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
minimal effort implementation of:
[lyx.git] / src / BufferView.C
index 88f6ea25303a16963a7a076ec59765d28689bbec..6c8f4bce793a55d69841219884feb0b52f52100a 100644 (file)
@@ -20,7 +20,7 @@
 #include "bufferlist.h"
 #include "bufferparams.h"
 #include "BufferView_pimpl.h"
-#include "CutAndPaste.h"
+#include "coordcache.h"
 #include "debug.h"
 #include "funcrequest.h"
 #include "FuncStatus.h"
 #include "texrow.h"
 #include "undo.h"
 #include "WordLangTuple.h"
+#include "metricsinfo.h"
 
 #include "frontends/Alert.h"
+#include "frontends/Clipboard.h"
 #include "frontends/Dialogs.h"
 #include "frontends/LyXView.h"
-#include "frontends/screen.h"
-#include "frontends/WorkArea.h"
 
 #include "insets/insetcommand.h" // ChangeRefs
-#include "insets/updatableinset.h"
 #include "insets/insettext.h"
 
-using lyx::support::bformat;
 
-using lyx::cap::setSelectionRange;
+using lyx::support::bformat;
 
 using std::distance;
 using std::find;
 using std::string;
-using std::swap;
 using std::vector;
 
 
 extern BufferList bufferlist;
 
 
-BufferView::BufferView(LyXView * owner, int width, int height)
-       : pimpl_(new Pimpl(*this, owner, width, height))
+BufferView::BufferView(LyXView * owner)
+       : pimpl_(new Pimpl(*this, owner))
 {}
 
 
@@ -84,36 +81,18 @@ Buffer * BufferView::buffer() const
 }
 
 
-LyXScreen & BufferView::screen() const
-{
-       return pimpl_->screen();
-}
-
-
 LyXView * BufferView::owner() const
 {
        return pimpl_->owner_;
 }
 
 
-Painter & BufferView::painter() const
-{
-       return pimpl_->painter();
-}
-
-
 void BufferView::setBuffer(Buffer * b)
 {
        pimpl_->setBuffer(b);
 }
 
 
-void BufferView::newFile(string const & fn, string const & tn, bool named)
-{
-       pimpl_->newFile(fn, tn, named);
-}
-
-
 bool BufferView::loadLyXFile(string const & fn, bool tl)
 {
        return pimpl_->loadLyXFile(fn, tl);
@@ -141,9 +120,9 @@ bool BufferView::fitCursor()
 }
 
 
-void BufferView::update()
+bool BufferView::update(Update::flags flags)
 {
-       pimpl_->update();
+       return pimpl_->update(flags);
 }
 
 
@@ -153,15 +132,21 @@ void BufferView::updateScrollbar()
 }
 
 
+ScrollbarParameters const & BufferView::scrollbarParameters() const
+{
+       return pimpl_->scrollbarParameters();
+}
+
+
 void BufferView::scrollDocView(int value)
 {
        pimpl_->scrollDocView(value);
 }
 
 
-void BufferView::redoCurrentBuffer()
+void BufferView::setCursorFromScrollbar()
 {
-       pimpl_->redoCurrentBuffer();
+       pimpl_->setCursorFromScrollbar();
 }
 
 
@@ -194,6 +179,10 @@ bool BufferView::isSavedPosition(unsigned int i)
        return pimpl_->isSavedPosition(i);
 }
 
+void BufferView::saveSavedPositions()
+{
+       return pimpl_->saveSavedPositions();
+}
 
 void BufferView::switchKeyMap()
 {
@@ -203,7 +192,7 @@ void BufferView::switchKeyMap()
 
 int BufferView::workWidth() const
 {
-       return pimpl_->workarea().workWidth();
+       return pimpl_->width();
 }
 
 
@@ -213,39 +202,39 @@ void BufferView::center()
 }
 
 
-int BufferView::top_y() const
+FuncStatus BufferView::getStatus(FuncRequest const & cmd)
 {
-       return pimpl_->top_y();
+       return pimpl_->getStatus(cmd);
 }
 
 
-void BufferView::top_y(int y)
+bool BufferView::dispatch(FuncRequest const & ev)
 {
-       pimpl_->top_y(y);
+       return pimpl_->dispatch(ev);
 }
 
 
-string const BufferView::getClipboard() const
+void BufferView::selectionRequested()
 {
-       return pimpl_->workarea().getClipboard();
+       pimpl_->selectionRequested();
 }
 
 
-void BufferView::stuffClipboard(string const & stuff) const
+void BufferView::selectionLost()
 {
-       pimpl_->stuffClipboard(stuff);
+       pimpl_->selectionLost();
 }
 
 
-FuncStatus BufferView::getStatus(FuncRequest const & cmd)
+void BufferView::workAreaResize(int width, int height)
 {
-       return pimpl_->getStatus(cmd);
+       pimpl_->workAreaResize(width, height);
 }
 
 
-bool BufferView::dispatch(FuncRequest const & ev)
+bool BufferView::workAreaDispatch(FuncRequest const & ev)
 {
-       return pimpl_->dispatch(ev);
+       return pimpl_->workAreaDispatch(ev);
 }
 
 
@@ -255,23 +244,6 @@ void BufferView::scroll(int lines)
 }
 
 
-void BufferView::showErrorList(string const & action) const
-{
-       if (getErrorList().size()) {
-               string const title = bformat(_("LyX: %1$s errors (%2$s)"),
-                       action, buffer()->fileName());
-               owner()->getDialogs().show("errorlist", title);
-               pimpl_->errorlist_.clear();
-       }
-}
-
-
-ErrorList const & BufferView::getErrorList() const
-{
-       return pimpl_->errorlist_;
-}
-
-
 void BufferView::setCursorFromRow(int row)
 {
        int tmpid = -1;
@@ -292,9 +264,7 @@ void BufferView::gotoLabel(string const & label)
                vector<string> labels;
                it->getLabelList(*buffer(), labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
-                       cursor().clearSelection();
-                       text()->setCursor(cursor(), it.par(), it.pos());
-                       cursor().resetAnchor();
+                       setCursor(it);
                        update();
                        return;
                }
@@ -302,13 +272,7 @@ void BufferView::gotoLabel(string const & label)
 }
 
 
-void BufferView::hideCursor()
-{
-       screen().hideCursor();
-}
-
-
-LyXText * BufferView::getLyXText() const
+LyXText * BufferView::getLyXText()
 {
        LyXText * text = cursor().innerText();
        BOOST_ASSERT(text);
@@ -316,15 +280,17 @@ LyXText * BufferView::getLyXText() const
 }
 
 
-void BufferView::haveSelection(bool sel)
+LyXText const * BufferView::getLyXText() const
 {
-       pimpl_->workarea().haveSelection(sel);
+       LyXText const * text = cursor().innerText();
+       BOOST_ASSERT(text);
+       return text;
 }
 
 
 int BufferView::workHeight() const
 {
-       return pimpl_->workarea().workHeight();
+       return pimpl_->height();
 }
 
 
@@ -334,34 +300,50 @@ LyXText * BufferView::text() const
 }
 
 
-void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
+void BufferView::setCursor(DocIterator const & dit)
 {
-       int const last = par.size();
-       for (int i = 0; i < last; ++i)
-               par[i].inset().edit(cursor(), true);
+       size_t const n = dit.depth();
+       for (size_t i = 0; i < n; ++i)
+               dit[i].inset().edit(cursor(), true);
 
-       cursor().setCursor(makeDocIterator(par, pos));
+       cursor().setCursor(dit);
        cursor().selection() = false;
-       par.bottom().text()->redoParagraph(par.bottom().par());
+}
+
+
+void BufferView::mouseSetCursor(LCursor & cur)
+{
+       BOOST_ASSERT(&cur.bv() == this);
+
+       // Has the cursor just left the inset?
+       bool badcursor = false;
+       if (&cursor().inset() != &cur.inset())
+               badcursor = cursor().inset().notifyCursorLeaves(cursor());
+
+       // do the dEPM magic if needed
+       // FIXME: move this to InsetText::notifyCursorLeaves?
+       if (!badcursor && cursor().inTexted())
+               cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
+
+       cursor() = cur;
+       cursor().clearSelection();
+       cursor().setTargetX();
+       finishUndo();
+
 }
 
 
 void BufferView::putSelectionAt(DocIterator const & cur,
                                int length, bool backwards)
 {
-       ParIterator par(cur);
-
        cursor().clearSelection();
 
-       setCursor(par, cur.pos());
+       setCursor(cur);
 
        if (length) {
                if (backwards) {
+                       cursor().pos() += length;
                        cursor().setSelection(cursor(), -length);
-                       DocIterator const it = cursor();
-                       cursor().setCursor(cursor().anchor_);
-                       cursor().selection() = true;
-                       cursor().anchor_ = it;
                } else
                        cursor().setSelection(cursor(), length);
        }
@@ -378,3 +360,27 @@ LCursor const & BufferView::cursor() const
 {
        return pimpl_->cursor_;
 }
+
+
+lyx::pit_type BufferView::anchor_ref() const
+{
+       return pimpl_->anchor_ref_;
+}
+
+
+int BufferView::offset_ref() const
+{
+       return pimpl_->offset_ref_;
+}
+
+
+ViewMetricsInfo const & BufferView::viewMetricsInfo()
+{
+       return pimpl_->viewMetricsInfo();
+}
+
+
+void BufferView::updateMetrics(bool singlepar)
+{
+       pimpl_->updateMetrics(singlepar);
+}