]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
gettext support, fast_start option, scons all, mingw bug fix and some cleanup for...
[lyx.git] / src / BufferView.C
index 475720d1f20f77c7ea39b20dea2d9bfa33ae8a5c..01cfc41d8eef8fbf3e737869f29d0133340a3e2b 100644 (file)
@@ -1,40 +1,83 @@
 /**
  * \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/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_;
@@ -59,23 +102,36 @@ Painter & BufferView::painter() const
 }
 
 
-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);
 }
 
 
-void BufferView::repaint()
+bool BufferView::loadLyXFile(string const & fn, bool tl)
 {
-       pimpl_->repaint();
+       return pimpl_->loadLyXFile(fn, tl);
+}
+
+
+void BufferView::reload()
+{
+       string const fn = buffer()->fileName();
+       if (bufferlist.close(buffer(), false))
+               loadLyXFile(fn);
+}
+
+
+void BufferView::resize()
+{
+       if (pimpl_->buffer_)
+               pimpl_->resizeCurrentBuffer();
 }
 
 
@@ -85,9 +141,9 @@ bool BufferView::fitCursor()
 }
 
 
-void BufferView::update()
+void BufferView::update(Update::flags flags)
 {
-       pimpl_->update();
+       pimpl_->update(flags);
 }
 
 
@@ -103,141 +159,281 @@ void BufferView::scrollDocView(int value)
 }
 
 
-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::saveSavedPositions()
+{
+       return pimpl_->saveSavedPositions();
+}
 
-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::selectionRequested()
 {
-       return pimpl_->workarea().workWidth();
+        pimpl_->selectionRequested();
+}
+
+
+void BufferView::selectionLost()
+{
+        pimpl_->selectionLost();
 }
 
 
-void BufferView::showCursor()
+void BufferView::workAreaResize()
 {
-       pimpl_->showCursor();
+        pimpl_->workAreaResize();
+}
+
+
+void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
+{
+        pimpl_->workAreaKeyPress(key, state);
+}
+
+
+bool BufferView::workAreaDispatch(FuncRequest const & ev)
+{
+        return pimpl_->workAreaDispatch(ev);
+}
+
+
+void BufferView::scroll(int lines)
+{
+       pimpl_->scroll(lines);
+}
+
+
+void BufferView::showErrorList(string const & action) const
+{
+       if (getErrorList().size()) {
+               string const title = bformat(_("%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::gotoLabel(string const & label)
+{
+       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()) {
+                       setCursor(it);
+                       update();
+                       return;
+               }
+       }
 }
 
 
 void BufferView::hideCursor()
 {
-       pimpl_->hideCursor();
+       screen().hideCursor();
+}
+
+LyXText * BufferView::getLyXText()
+{
+       LyXText * text = cursor().innerText();
+       BOOST_ASSERT(text);
+       return text;
 }
 
 
-void BufferView::toggleSelection(bool b)
+LyXText const * BufferView::getLyXText() const
 {
-       pimpl_->toggleSelection(b);
+       LyXText const * 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(DocIterator const & dit)
 {
-       return pimpl_->workarea().getClipboard();
+       size_t const n = dit.depth();
+       for (size_t i = 0; i < n; ++i)
+               dit[i].inset().edit(cursor(), true);
+
+       cursor().setCursor(dit);
+       cursor().selection() = false;
 }
 
 
-void BufferView::stuffClipboard(string const & stuff) const
+void BufferView::mouseSetCursor(LCursor & cur)
 {
-       pimpl_->stuffClipboard(stuff);
+       BOOST_ASSERT(&cur.bv() == this);
+
+       // Has the cursor just left the inset?
+       if (&cursor().inset() != &cur.inset())
+               cursor().inset().notifyCursorLeaves(cursor());
+
+       // do the dEPM magic if needed
+       if (cursor().inTexted())
+               cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
+
+       cursor() = cur;
+       cursor().clearSelection();
+       cursor().setTargetX();
+       finishUndo();
+
 }
 
 
-BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
-                                 BufferView::UpdateCodes uc2)
+void BufferView::putSelectionAt(DocIterator const & cur,
+                               int length, bool backwards)
 {
-       return static_cast<BufferView::UpdateCodes>
-               (static_cast<int>(uc1) | static_cast<int>(uc2));
+       cursor().clearSelection();
+
+       setCursor(cur);
+
+       if (length) {
+               if (backwards) {
+                       cursor().pos() += length;
+                       cursor().setSelection(cursor(), -length);
+               } else
+                       cursor().setSelection(cursor(), length);
+       }
 }
 
 
-bool BufferView::dispatch(FuncRequest const & ev)
+bool const BufferView::repaintAll() const
 {
-       return pimpl_->dispatch(ev);
+       return pimpl_->repaintAll();
+}
+
+
+void const BufferView::repaintAll(bool r) const
+{
+       pimpl_->repaintAll(r);
+}
+
+
+LCursor & BufferView::cursor()
+{
+       return pimpl_->cursor_;
+}
+
+
+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_;
 }