-// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
+/**
+ * \file BufferView.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ====================================================== */
+ * \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 "WorkArea.h"
-#include "lyxscreen.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"
-BufferView::BufferView(LyXView * o, int xpos, int ypos,
- int width, int height)
- : pimpl_(new Pimpl(this, o, xpos, ypos, width, height))
-{
- text = 0;
- inset_slept = false;
-}
+#include "insets/insetcommand.h" // ChangeRefs
+#include "insets/updatableinset.h"
+#include "insets/insettext.h"
+using lyx::support::bformat;
-BufferView::~BufferView()
-{
- delete text;
- delete pimpl_;
-}
+using lyx::cap::setSelectionRange;
+using std::distance;
+using std::find;
+using std::string;
+using std::swap;
+using std::vector;
-Buffer * BufferView::buffer() const
-{
- return pimpl_->buffer_;
-}
+extern BufferList bufferlist;
-LyXScreen * BufferView::screen() const
-{
- return pimpl_->screen_;
-}
+BufferView::BufferView(LyXView * owner, int width, int height)
+ : pimpl_(new Pimpl(*this, owner, width, height))
+{}
-WorkArea * BufferView::workarea() const
-{
- return pimpl_->workarea_;
-}
-
-LyXView * BufferView::owner() const
+BufferView::~BufferView()
{
- return pimpl_->owner_;
+ delete pimpl_;
}
-void BufferView::pushIntoUpdateList(Inset * i)
+void BufferView::unsetXSel()
{
- pimpl_->updatelist.push(i);
+ pimpl_->xsel_cache_.set = false;
}
-Painter & BufferView::painter()
+Buffer * BufferView::buffer() const
{
- return pimpl_->painter();
+ return pimpl_->buffer_;
}
-void BufferView::buffer(Buffer * b)
+LyXScreen & BufferView::screen() const
{
- pimpl_->buffer(b);
+ return pimpl_->screen();
}
-void BufferView::resize(int xpos, int ypos, int width, int height)
+LyXView * BufferView::owner() const
{
- pimpl_->resize(xpos, ypos, width, height);
+ return pimpl_->owner_;
}
-void BufferView::resize()
+Painter & BufferView::painter() const
{
- pimpl_->resize();
+ return pimpl_->painter();
}
-void BufferView::redraw()
+void BufferView::setBuffer(Buffer * b)
{
- pimpl_->redraw();
+ pimpl_->setBuffer(b);
}
-void BufferView::fitCursor(LyXText * text)
+void BufferView::newFile(string const & fn, string const & tn, bool named)
{
- pimpl_->fitCursor(text);
+ pimpl_->newFile(fn, tn, named);
}
-void BufferView::update()
+bool BufferView::loadLyXFile(string const & fn, bool tl)
{
- pimpl_->update();
+ return pimpl_->loadLyXFile(fn, tl);
}
-void BufferView::updateScrollbar()
+void BufferView::reload()
{
- pimpl_->updateScrollbar();
+ string const fn = buffer()->fileName();
+ if (bufferlist.close(buffer(), false))
+ loadLyXFile(fn);
}
-Inset * BufferView::checkInsetHit(LyXText * text, int & x, int & y,
- unsigned int button)
+void BufferView::resize()
{
- return pimpl_->checkInsetHit(text, x, y, button);
+ if (pimpl_->buffer_)
+ pimpl_->resizeCurrentBuffer();
}
-void BufferView::redoCurrentBuffer()
+bool BufferView::fitCursor()
{
- pimpl_->redoCurrentBuffer();
+ return pimpl_->fitCursor();
}
-int BufferView::resizeCurrentBuffer()
+void BufferView::update(bool fitcursor, bool forceupdate)
{
- return pimpl_->resizeCurrentBuffer();
+ pimpl_->update(fitcursor, forceupdate);
}
-#if 0
-void BufferView::enterView()
+void BufferView::updateScrollbar()
{
- pimpl_->enterView();
+ pimpl_->updateScrollbar();
}
-void BufferView::leaveView()
+void BufferView::scrollDocView(int value)
{
- pimpl_->leaveView();
+ pimpl_->scrollDocView(value);
}
-// Callback for scrollbar slider
-void BufferView::scrollCB(double value)
+bool BufferView::available() const
{
- pimpl_->scrollCB(value);
+ return pimpl_->available();
}
-void BufferView::workAreaMotionNotify(int x, int y, unsigned int state)
+Change const BufferView::getCurrentChange()
{
- pimpl_->workAreaMotionNotify(x, y, state);
+ return pimpl_->getCurrentChange();
}
-/// Single-click on work area
-void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
+void BufferView::savePosition(unsigned int i)
{
- pimpl_->workAreaButtonPress(xpos, ypos, button);
+ pimpl_->savePosition(i);
}
-void BufferView::doubleClick(int x, int y, unsigned int button)
+void BufferView::restorePosition(unsigned int i)
{
- pimpl_->doubleClick(x, y, button);
+ pimpl_->restorePosition(i);
}
-void BufferView::tripleClick(int x, int y, unsigned int button)
+bool BufferView::isSavedPosition(unsigned int i)
{
- pimpl_->tripleClick(x, y, button);
+ return pimpl_->isSavedPosition(i);
}
-void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
+void BufferView::switchKeyMap()
{
- pimpl_->workAreaButtonRelease(x, y, button);
+ pimpl_->switchKeyMap();
}
-void BufferView::workAreaExpose()
+int BufferView::workWidth() const
{
- pimpl_->workAreaExpose();
+ return pimpl_->workarea().workWidth();
}
-#endif
-void BufferView::cursorPrevious(LyXText * text)
+void BufferView::center()
{
- pimpl_->cursorPrevious(text);
+ pimpl_->center();
}
-void BufferView::cursorNext(LyXText * text)
+string const BufferView::getClipboard() const
{
- pimpl_->cursorNext(text);
+ return pimpl_->workarea().getClipboard();
}
-bool BufferView::available() const
+void BufferView::stuffClipboard(string const & stuff) const
{
- return pimpl_->available();
+ pimpl_->stuffClipboard(stuff);
}
-void BufferView::beforeChange()
+FuncStatus BufferView::getStatus(FuncRequest const & cmd)
{
- pimpl_->beforeChange();
+ return pimpl_->getStatus(cmd);
}
-void BufferView::savePosition()
+bool BufferView::dispatch(FuncRequest const & ev)
{
- pimpl_->savePosition();
+ return pimpl_->dispatch(ev);
}
-void BufferView::restorePosition()
+void BufferView::scroll(int lines)
{
- pimpl_->restorePosition();
+ pimpl_->scroll(lines);
}
-bool BufferView::NoSavedPositions()
+void BufferView::showErrorList(string const & action) const
{
- return pimpl_->NoSavedPositions();
+ if (getErrorList().size()) {
+ string const title = bformat(_("LyX: %1$s errors (%2$s)"),
+ action, buffer()->fileName());
+ owner()->getDialogs().show("errorlist", title);
+ pimpl_->errorlist_.clear();
+ }
}
-void BufferView::update(UpdateCodes f)
+ErrorList const & BufferView::getErrorList() const
{
- pimpl_->update(f);
+ return pimpl_->errorlist_;
}
-void BufferView::setState()
+void BufferView::setCursorFromRow(int row)
{
- pimpl_->setState();
-}
+ int tmpid = -1;
+ int tmppos = -1;
+ buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
-void BufferView::insetSleep()
-{
- pimpl_->insetSleep();
+ if (tmpid == -1)
+ text()->setCursor(cursor(), 0, 0);
+ else
+ text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
}
-void BufferView::insetWakeup()
+void BufferView::gotoLabel(string const & label)
{
- pimpl_->insetWakeup();
+ 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::insetUnlock()
+void BufferView::hideCursor()
{
- pimpl_->insetUnlock();
+ screen().hideCursor();
}
-bool BufferView::focus() const
+LyXText * BufferView::getLyXText() const
{
- return pimpl_->focus();
+ LyXText * text = cursor().innerText();
+ BOOST_ASSERT(text);
+ return text;
}
-void BufferView::focus(bool f)
+void BufferView::haveSelection(bool sel)
{
- pimpl_->focus(f);
+ pimpl_->workarea().haveSelection(sel);
}
-bool BufferView::active() const
+int BufferView::workHeight() const
{
- return pimpl_->active();
+ return pimpl_->workarea().workHeight();
}
-int BufferView::workWidth() const
+LyXText * BufferView::text() const
{
- return pimpl_->workarea_->workWidth();
+ return buffer() ? &buffer()->text() : 0;
}
-bool BufferView::belowMouse() const
+void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
{
- return pimpl_->belowMouse();
-}
-
+ for (int i = 0, n = par.size(); i < n; ++i)
+ par[i].inset().edit(cursor(), true);
-void BufferView::showCursor()
-{
- pimpl_->showCursor();
+ cursor().setCursor(makeDocIterator(par, pos));
+ cursor().selection() = false;
}
-void BufferView::hideCursor()
+void BufferView::putSelectionAt(DocIterator const & cur,
+ int length, bool backwards)
{
- pimpl_->hideCursor();
-}
+ ParIterator par(cur);
+ cursor().clearSelection();
-void BufferView::toggleSelection(bool b)
-{
- pimpl_->toggleSelection(b);
-}
+ setCursor(par, cur.pos());
-
-void BufferView::toggleToggle()
-{
- pimpl_->toggleToggle();
+ if (length) {
+ if (backwards) {
+ cursor().pos() += length;
+ cursor().setSelection(cursor(), -length);
+ } else
+ cursor().setSelection(cursor(), length);
+ }
}
-void BufferView::center()
+LCursor & BufferView::cursor()
{
- pimpl_->center();
+ return pimpl_->cursor_;
}
-void BufferView::pasteClipboard(bool asPara)
+LCursor const & BufferView::cursor() const
{
- pimpl_->pasteClipboard(asPara);
+ return pimpl_->cursor_;
}
-void BufferView::stuffClipboard(string const & stuff) const
+lyx::pit_type BufferView::anchor_ref() const
{
- pimpl_->stuffClipboard(stuff);
+ return pimpl_->anchor_ref_;
}
-BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
- BufferView::UpdateCodes uc2)
+int BufferView::offset_ref() const
{
- return static_cast<BufferView::UpdateCodes>
- (static_cast<int>(uc1) | static_cast<int>(uc2));
+ return pimpl_->offset_ref_;
}