/**
* \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 unknown
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author Alfredo Braunstein
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ * \author André Pönitz
+ * \author Jürgen Vigna
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "BufferView.h"
+
+#include "buffer.h"
+#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 "gettext.h"
+#include "insetiterator.h"
+#include "language.h"
+#include "lyxlayout.h"
#include "lyxtext.h"
+#include "lyxtextclass.h"
+#include "paragraph.h"
+#include "paragraph_funcs.h"
+#include "pariterator.h"
+#include "texrow.h"
+#include "undo.h"
+#include "WordLangTuple.h"
+
+#include "frontends/Alert.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"
-BufferView::BufferView(LyXView * o, int xpos, int ypos,
- int width, int height)
- : pimpl_(new Pimpl(this, o, xpos, ypos, width, height))
-{
- text = 0;
-}
+using lyx::support::bformat;
+
+using lyx::cap::setSelectionRange;
+
+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()
{
- delete text;
delete pimpl_;
}
+void BufferView::unsetXSel()
+{
+ pimpl_->xsel_cache_.set = false;
+}
+
+
Buffer * BufferView::buffer() const
{
return pimpl_->buffer_;
}
-void BufferView::buffer(Buffer * b)
+void BufferView::setBuffer(Buffer * b)
{
- pimpl_->buffer(b);
+ pimpl_->setBuffer(b);
}
-void BufferView::resize()
+void BufferView::newFile(string const & fn, string const & tn, bool named)
{
- if (pimpl_->buffer_) {
- pimpl_->resizeCurrentBuffer();
- }
+ pimpl_->newFile(fn, tn, named);
+}
+
+
+bool BufferView::loadLyXFile(string const & fn, bool tl)
+{
+ return pimpl_->loadLyXFile(fn, tl);
}
-void BufferView::repaint()
+void BufferView::reload()
{
- pimpl_->repaint();
+ string const fn = buffer()->fileName();
+ if (bufferlist.close(buffer(), false))
+ loadLyXFile(fn);
+}
+
+
+void BufferView::resize()
+{
+ if (pimpl_->buffer_)
+ pimpl_->resizeCurrentBuffer();
}
}
-void BufferView::update()
+void BufferView::update(bool fitcursor, bool forceupdate)
{
- pimpl_->update();
+ pimpl_->update(fitcursor, forceupdate);
}
}
-Inset * BufferView::checkInsetHit(LyXText * text, int & x, int & y)
+bool BufferView::available() const
{
- return pimpl_->checkInsetHit(text, x, y);
+ return pimpl_->available();
}
-void BufferView::redoCurrentBuffer()
+Change const BufferView::getCurrentChange()
{
- pimpl_->redoCurrentBuffer();
+ return pimpl_->getCurrentChange();
}
-void BufferView::cursorPrevious(LyXText * text)
+void BufferView::savePosition(unsigned int i)
{
- pimpl_->cursorPrevious(text);
+ pimpl_->savePosition(i);
}
-void BufferView::cursorNext(LyXText * text)
+void BufferView::restorePosition(unsigned int i)
{
- pimpl_->cursorNext(text);
+ pimpl_->restorePosition(i);
}
-bool BufferView::available() const
+bool BufferView::isSavedPosition(unsigned int i)
{
- return pimpl_->available();
+ return pimpl_->isSavedPosition(i);
}
-void BufferView::beforeChange(LyXText * text)
+void BufferView::switchKeyMap()
{
- pimpl_->beforeChange(text);
+ pimpl_->switchKeyMap();
}
-void BufferView::savePosition(unsigned int i)
+int BufferView::workWidth() const
{
- pimpl_->savePosition(i);
+ return pimpl_->workarea().workWidth();
}
-void BufferView::restorePosition(unsigned int i)
+void BufferView::center()
{
- pimpl_->restorePosition(i);
+ pimpl_->center();
}
-bool BufferView::isSavedPosition(unsigned int i)
+string const BufferView::getClipboard() const
{
- return pimpl_->isSavedPosition(i);
+ return pimpl_->workarea().getClipboard();
}
-void BufferView::update(LyXText * text, UpdateCodes f)
+void BufferView::stuffClipboard(string const & stuff) const
{
- pimpl_->update(text, f);
+ pimpl_->stuffClipboard(stuff);
}
-void BufferView::switchKeyMap()
+FuncStatus BufferView::getStatus(FuncRequest const & cmd)
{
- pimpl_->switchKeyMap();
+ return pimpl_->getStatus(cmd);
}
-void BufferView::insetUnlock()
+bool BufferView::dispatch(FuncRequest const & ev)
{
- pimpl_->insetUnlock();
+ return pimpl_->dispatch(ev);
}
-int BufferView::workWidth() const
+void BufferView::scroll(int lines)
{
- return pimpl_->workarea().workWidth();
+ pimpl_->scroll(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;
+ int tmppos = -1;
+
+ buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
+
+ if (tmpid == -1)
+ text()->setCursor(cursor(), 0, 0);
+ else
+ text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
}
-void BufferView::showCursor()
+void BufferView::gotoLabel(string const & label)
{
- pimpl_->showCursor();
+ 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(), it.pit(), it.pos());
+ cursor().resetAnchor();
+ update();
+ return;
+ }
+ }
}
void BufferView::hideCursor()
{
- pimpl_->hideCursor();
+ screen().hideCursor();
}
-void BufferView::toggleSelection(bool b)
+LyXText * BufferView::getLyXText() const
{
- pimpl_->toggleSelection(b);
+ LyXText * text = cursor().innerText();
+ BOOST_ASSERT(text);
+ return text;
}
-void BufferView::toggleToggle()
+void BufferView::haveSelection(bool sel)
{
- pimpl_->toggleToggle();
+ pimpl_->workarea().haveSelection(sel);
}
-void BufferView::center()
+int BufferView::workHeight() const
{
- pimpl_->center();
+ return pimpl_->workarea().workHeight();
}
-void BufferView::pasteClipboard(bool asPara)
+LyXText * BufferView::text() const
{
- pimpl_->pasteClipboard(asPara);
+ return buffer() ? &buffer()->text() : 0;
}
-string const BufferView::getClipboard() const
+void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
{
- return pimpl_->workarea().getClipboard();
+ for (int i = 0, n = par.size(); i < n; ++i)
+ par[i].inset().edit(cursor(), true);
+
+ cursor().setCursor(makeDocIterator(par, pos));
+ cursor().selection() = false;
}
-void BufferView::stuffClipboard(string const & stuff) const
+void BufferView::putSelectionAt(DocIterator const & cur,
+ int length, bool backwards)
{
- pimpl_->stuffClipboard(stuff);
+ ParIterator par(cur);
+
+ cursor().clearSelection();
+
+ setCursor(par, cur.pos());
+
+ if (length) {
+ if (backwards) {
+ cursor().pos() += length;
+ cursor().setSelection(cursor(), -length);
+ } else
+ cursor().setSelection(cursor(), length);
+ }
}
-BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
- BufferView::UpdateCodes uc2)
+LCursor & BufferView::cursor()
{
- return static_cast<BufferView::UpdateCodes>
- (static_cast<int>(uc1) | static_cast<int>(uc2));
+ return pimpl_->cursor_;
}
-bool BufferView::dispatch(FuncRequest const & ev)
+LCursor const & BufferView::cursor() const
{
- return pimpl_->dispatch(ev);
+ return pimpl_->cursor_;
+}
+
+
+lyx::pit_type BufferView::anchor_ref() const
+{
+ return pimpl_->anchor_ref_;
+}
+
+
+int BufferView::offset_ref() const
+{
+ return pimpl_->offset_ref_;
}