]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
minimal effort implementation of:
[lyx.git] / src / BufferView.C
index 1cce3fed18a115f5255b92dbe0ae4438849ea44e..6c8f4bce793a55d69841219884feb0b52f52100a 100644 (file)
 #include "bufferlist.h"
 #include "bufferparams.h"
 #include "BufferView_pimpl.h"
+#include "coordcache.h"
 #include "debug.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
-#include "iterators.h"
+#include "insetiterator.h"
 #include "language.h"
 #include "lyxlayout.h"
 #include "lyxtext.h"
 #include "lyxtextclass.h"
 #include "paragraph.h"
 #include "paragraph_funcs.h"
-#include "PosIterator.h"
+#include "pariterator.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"
 
-#include "support/filetools.h"
-#include "support/lyxalgo.h" // lyx_count
 
 using lyx::support::bformat;
-using lyx::support::MakeAbsPath;
 
 using std::distance;
 using std::find;
 using std::string;
-using std::swap;
 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))
+BufferView::BufferView(LyXView * owner)
+       : pimpl_(new Pimpl(*this, owner))
 {}
 
 
@@ -84,33 +81,15 @@ 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::buffer(Buffer * b)
-{
-       pimpl_->buffer(b);
-}
-
-
-bool BufferView::newFile(string const & fn, string const & tn, bool named)
+void BufferView::setBuffer(Buffer * b)
 {
-       return pimpl_->newFile(fn, tn, named);
+       pimpl_->setBuffer(b);
 }
 
 
@@ -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,79 +202,45 @@ 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)
-{
-       pimpl_->top_y(y);
-}
-
-
-string const BufferView::getClipboard() const
+bool BufferView::dispatch(FuncRequest const & ev)
 {
-       return pimpl_->workarea().getClipboard();
+       return pimpl_->dispatch(ev);
 }
 
 
-void BufferView::stuffClipboard(string const & stuff) const
+void BufferView::selectionRequested()
 {
-       pimpl_->stuffClipboard(stuff);
+       pimpl_->selectionRequested();
 }
 
 
-bool BufferView::dispatch(FuncRequest const & ev)
+void BufferView::selectionLost()
 {
-       return pimpl_->dispatch(ev);
+       pimpl_->selectionLost();
 }
 
 
-void BufferView::scroll(int lines)
+void BufferView::workAreaResize(int width, int height)
 {
-       pimpl_->scroll(lines);
+       pimpl_->workAreaResize(width, height);
 }
 
 
-// Inserts a file into current document
-bool BufferView::insertLyXFile(string const & filen)
-       //
-       // Copyright CHT Software Service GmbH
-       // Uwe C. Schroeder
-       //
-       // Insert a LyXformat - file into current buffer
-       //
-       // Moved from lyx_cb.C (Lgb)
+bool BufferView::workAreaDispatch(FuncRequest const & ev)
 {
-       BOOST_ASSERT(!filen.empty());
-
-       string const fname = MakeAbsPath(filen);
-
-       cursor().clearSelection();
-       text()->breakParagraph(cursor());
-
-       bool res = buffer()->readFile(fname, text()->cursorPar());
-       resize();
-       return res;
+       return pimpl_->workAreaDispatch(ev);
 }
 
 
-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
+void BufferView::scroll(int lines)
 {
-       return pimpl_->errorlist_;
+       pimpl_->scroll(lines);
 }
 
 
@@ -299,24 +254,17 @@ void BufferView::setCursorFromRow(int row)
        if (tmpid == -1)
                text()->setCursor(cursor(), 0, 0);
        else
-               text()->setCursor(cursor(),
-                       text()->parOffset(buffer()->getParFromID(tmpid).pit()),
-                       tmppos);
+               text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
 }
 
 
 void BufferView::gotoLabel(string const & label)
 {
-       for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
-            it != buffer()->inset_iterator_end(); ++it) {
+       for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
                vector<string> labels;
                it->getLabelList(*buffer(), labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
-                       cursor().clearSelection();
-                       text()->setCursor(cursor(), 
-                               distance(text()->paragraphs().begin(), it.getPar()),
-                               it.getPos());
-                       cursor().resetAnchor();
+                       setCursor(it);
                        update();
                        return;
                }
@@ -324,119 +272,81 @@ void BufferView::gotoLabel(string const & label)
 }
 
 
-void BufferView::hideCursor()
+LyXText * BufferView::getLyXText()
 {
-       screen().hideCursor();
+       LyXText * text = cursor().innerText();
+       BOOST_ASSERT(text);
+       return text;
 }
 
 
-LyXText * BufferView::getLyXText() const
+LyXText const * BufferView::getLyXText() const
 {
-       return cursor().innerText();
+       LyXText const * text = cursor().innerText();
+       BOOST_ASSERT(text);
+       return text;
 }
 
 
-Language const * BufferView::getParentLanguage(InsetOld * inset) const
+int BufferView::workHeight() const
 {
-       Paragraph const & par = ownerPar(*buffer(), inset);
-       return par.getFontSettings(buffer()->params(),
-                                  par.getPositionOfInset(inset)).language();
+       return pimpl_->height();
 }
 
 
-Encoding const * BufferView::getEncoding() const
+LyXText * BufferView::text() const
 {
-       LyXText * t = getLyXText();
-       if (!t)
-               return 0;
-       CursorSlice const & cur = cursor().innerTextSlice();
-       return t->getPar(cur.par())->getFont(
-               buffer()->params(), cur.pos(),
-               outerFont(t->getPar(cur.par()), t->paragraphs())
-       ).language()->encoding();
+       return buffer() ? &buffer()->text() : 0;
 }
 
 
-void BufferView::haveSelection(bool sel)
+void BufferView::setCursor(DocIterator const & dit)
 {
-       pimpl_->workarea().haveSelection(sel);
-}
-
+       size_t const n = dit.depth();
+       for (size_t i = 0; i < n; ++i)
+               dit[i].inset().edit(cursor(), true);
 
-int BufferView::workHeight() const
-{
-       return pimpl_->workarea().workHeight();
+       cursor().setCursor(dit);
+       cursor().selection() = false;
 }
 
 
-LyXText * BufferView::text() const
+void BufferView::mouseSetCursor(LCursor & cur)
 {
-       return pimpl_->buffer_ ? &pimpl_->buffer_->text() : 0;
-}
-
+       BOOST_ASSERT(&cur.bv() == this);
 
-void BufferView::setCursor(ParIterator const & par,
-                          lyx::pos_type pos)
-{
-       LCursor & cur = cursor();
-       cur.reset();
-       ParIterator::PosHolder const & positions = par.positions();
-       int const last = par.size() - 1;
-       for (int i = 0; i < last; ++i)
-               (*positions[i].it)->inset->edit(cur, true);
-       cur.resetAnchor();
-       LyXText * lt = par.text(*buffer());
-       lt->setCursor(cur, lt->parOffset(par.pit()), pos);
-}
+       // 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());
 
-/*
-if the fitCursor call refers to some point in never-explored-land, then we
-don't have y information in insets there, then we cannot even do an update
-to get it (because we need the y infomation for setting top_y first). So
-this is solved in putSelectionAt with:
+       cursor() = cur;
+       cursor().clearSelection();
+       cursor().setTargetX();
+       finishUndo();
 
-- setting top_y to the y of the outerPar (that has good info)
-- calling update
-- calling cursor().updatePos()
-- then call fitCursor()
+}
 
-Ab.
-*/
 
-void BufferView::putSelectionAt(PosIterator const & cur,
-                     int length, bool backwards)
+void BufferView::putSelectionAt(DocIterator const & cur,
+                               int length, bool backwards)
 {
-       ParIterator par(cur);
-
        cursor().clearSelection();
 
-       LyXText * text = par.text(*buffer());
-       setCursor(par, cur.pos());
-       
-       // hack for the chicken and egg problem
-       if (par.inset())
-               top_y(par.outerPar()->y);
-       update();
-       text->setCursor(cursor(), text->parOffset(cur.pit()), cur.pos());
-       cursor().updatePos();
+       setCursor(cur);
 
        if (length) {
-               text->setSelectionRange(cursor(), length);
-               cursor().setSelection();
                if (backwards) {
-#if 0
-                       swap(cursor().cursor_, cursor().anchor_);
-#else
-                       DocumentIterator it = cursor();
-                       cursor().setCursor(cursor().anchor_, false);
-                       cursor().anchor_ = it;
-#endif
-               }
+                       cursor().pos() += length;
+                       cursor().setSelection(cursor(), -length);
+               } else
+                       cursor().setSelection(cursor(), length);
        }
-
-       fitCursor();
-       update();
 }
 
 
@@ -450,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);
+}