]> 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 1baf3d769b1da8184528e04db95f2da85175e323..01cfc41d8eef8fbf3e737869f29d0133340a3e2b 100644 (file)
@@ -1,58 +1,92 @@
-// -*- 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"
+
+#include "insets/insetcommand.h" // ChangeRefs
+#include "insets/insettext.h"
+
+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 * o, int xpos, int ypos,
-                      int width, int height)
-       : pimpl_(new Pimpl(this, o, xpos, ypos, width, height))
-{
-       text = 0;
-       inset_slept = false;
-}
+
+BufferView::BufferView(LyXView * owner, int width, int height)
+       : pimpl_(new Pimpl(*this, owner, width, height))
+{}
 
 
 BufferView::~BufferView()
 {
-       delete text;
        delete pimpl_;
 }
 
 
-Buffer * BufferView::buffer() const
+void BufferView::unsetXSel()
 {
-       return pimpl_->buffer_;
+       pimpl_->xsel_cache_.set = false;
 }
 
 
-LyXScreen * BufferView::screen() const
+Buffer * BufferView::buffer() const
 {
-       return pimpl_->screen_.get();
+       return pimpl_->buffer_;
 }
 
 
-WorkArea * BufferView::workarea() const
+LyXScreen & BufferView::screen() const
 {
-       return &pimpl_->workarea_;
+       return pimpl_->screen();
 }
 
 
@@ -62,51 +96,54 @@ LyXView * BufferView::owner() const
 }
 
 
-void BufferView::pushIntoUpdateList(Inset * i)
+Painter & BufferView::painter() const
 {
-       pimpl_->updatelist.push(i);
+       return pimpl_->painter();
 }
 
 
-Painter & BufferView::painter() 
+void BufferView::setBuffer(Buffer * b)
 {
-       return pimpl_->painter();
+       pimpl_->setBuffer(b);
 }
 
 
-void BufferView::buffer(Buffer * b)
+void BufferView::newFile(string const & fn, string const & tn, bool named)
 {
-       pimpl_->buffer(b);
+       pimpl_->newFile(fn, tn, named);
 }
 
 
-void BufferView::resize(int xpos, int ypos, int width, int height)
+bool BufferView::loadLyXFile(string const & fn, bool tl)
 {
-       pimpl_->resize(xpos, ypos, width, height);
+       return pimpl_->loadLyXFile(fn, tl);
 }
 
 
-void BufferView::resize()
+void BufferView::reload()
 {
-       pimpl_->resize();
+       string const fn = buffer()->fileName();
+       if (bufferlist.close(buffer(), false))
+               loadLyXFile(fn);
 }
 
 
-void BufferView::redraw()
+void BufferView::resize()
 {
-       pimpl_->redraw();
+       if (pimpl_->buffer_)
+               pimpl_->resizeCurrentBuffer();
 }
 
 
-void BufferView::fitCursor(LyXText * text)
+bool BufferView::fitCursor()
 {
-       pimpl_->fitCursor(text);
+       return pimpl_->fitCursor();
 }
 
 
-void BufferView::update()
+void BufferView::update(Update::flags flags)
 {
-       pimpl_->update();
+       pimpl_->update(flags);
 }
 
 
@@ -116,183 +153,287 @@ void BufferView::updateScrollbar()
 }
 
 
-void BufferView::scrollCB(double value)
+void BufferView::scrollDocView(int value)
 {
-       pimpl_->scrollCB(value);
+       pimpl_->scrollDocView(value);
 }
 
 
-Inset * BufferView::checkInsetHit(LyXText * text, int & x, int & y,
-                                 unsigned int button)
+bool BufferView::available() const
 {
-       return pimpl_->checkInsetHit(text, x, y, button);
+       return pimpl_->available();
 }
 
 
-void BufferView::redoCurrentBuffer()
+Change const BufferView::getCurrentChange()
 {
-       pimpl_->redoCurrentBuffer();
+       return pimpl_->getCurrentChange();
 }
 
 
-int BufferView::resizeCurrentBuffer()
+void BufferView::savePosition(unsigned int i)
 {
-       return pimpl_->resizeCurrentBuffer();
+       pimpl_->savePosition(i);
 }
 
 
-void BufferView::cursorPrevious(LyXText * text)
+void BufferView::restorePosition(unsigned int i)
 {
-       pimpl_->cursorPrevious(text);
+       pimpl_->restorePosition(i);
 }
 
 
-void BufferView::cursorNext(LyXText * text)
+bool BufferView::isSavedPosition(unsigned int i)
 {
-       pimpl_->cursorNext(text);
+       return pimpl_->isSavedPosition(i);
 }
 
+void BufferView::saveSavedPositions()
+{
+       return pimpl_->saveSavedPositions();
+}
 
-bool BufferView::available() const
+void BufferView::switchKeyMap()
 {
-       return pimpl_->available();
+       pimpl_->switchKeyMap();
 }
 
 
-void BufferView::beforeChange(LyXText * text)
+int BufferView::workWidth() const
 {
-       pimpl_->beforeChange(text);
+       return pimpl_->workarea().workWidth();
 }
 
 
-void BufferView::savePosition(unsigned int i)
+void BufferView::center()
 {
-       pimpl_->savePosition(i);
+       pimpl_->center();
 }
 
 
-void BufferView::restorePosition(unsigned int i)
+string const BufferView::getClipboard() const
 {
-       pimpl_->restorePosition(i);
+       return pimpl_->workarea().getClipboard();
 }
 
 
-bool BufferView::isSavedPosition(unsigned int i)
+void BufferView::stuffClipboard(string const & stuff) const
 {
-       return pimpl_->isSavedPosition(i);
+       pimpl_->stuffClipboard(stuff);
 }
 
 
-void BufferView::update(LyXText * text, UpdateCodes f)
+FuncStatus BufferView::getStatus(FuncRequest const & cmd)
 {
-       pimpl_->update(text, f);
+       return pimpl_->getStatus(cmd);
 }
 
 
-void BufferView::setState()
+bool BufferView::dispatch(FuncRequest const & ev)
 {
-       pimpl_->setState();
+       return pimpl_->dispatch(ev);
 }
 
 
-void BufferView::insetSleep()
+void BufferView::selectionRequested()
 {
-       pimpl_->insetSleep();
+        pimpl_->selectionRequested();
 }
 
 
-void BufferView::insetWakeup()
+void BufferView::selectionLost()
 {
-       pimpl_->insetWakeup();
+        pimpl_->selectionLost();
 }
 
 
-void BufferView::insetUnlock()
+void BufferView::workAreaResize()
 {
-       pimpl_->insetUnlock();
+        pimpl_->workAreaResize();
 }
 
 
-bool BufferView::focus() const
+void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
 {
-       return pimpl_->focus();
+        pimpl_->workAreaKeyPress(key, state);
 }
 
 
-void BufferView::focus(bool f)
+bool BufferView::workAreaDispatch(FuncRequest const & ev)
 {
-       pimpl_->focus(f);
+        return pimpl_->workAreaDispatch(ev);
 }
 
 
-bool BufferView::active() const
+void BufferView::scroll(int lines)
 {
-       return pimpl_->active();
+       pimpl_->scroll(lines);
 }
 
 
-int BufferView::workWidth() const
+void BufferView::showErrorList(string const & action) const
 {
-    return pimpl_->workarea_.workWidth();
+       if (getErrorList().size()) {
+               string const title = bformat(_("%1$s Errors (%2$s)"),
+                       action, buffer()->fileName());
+               owner()->getDialogs().show("errorlist", title);
+               pimpl_->errorlist_.clear();
+       }
 }
 
 
-bool BufferView::belowMouse() const 
+ErrorList const & BufferView::getErrorList() const
 {
-       return pimpl_->belowMouse();
+       return pimpl_->errorlist_;
 }
 
 
-void BufferView::showCursor()
+void BufferView::setCursorFromRow(int row)
 {
-       pimpl_->showCursor();
+       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;
 }
 
 
-void BufferView::stuffClipboard(string const & stuff) const
+void BufferView::setCursor(DocIterator const & dit)
 {
-       pimpl_->stuffClipboard(stuff);
+       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;
 }
 
 
-BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
-                                 BufferView::UpdateCodes uc2)
+void BufferView::mouseSetCursor(LCursor & cur)
 {
-       return static_cast<BufferView::UpdateCodes>
-               (static_cast<int>(uc1) | static_cast<int>(uc2));
+       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();
+
+}
+
+
+void BufferView::putSelectionAt(DocIterator const & cur,
+                               int length, bool backwards)
+{
+       cursor().clearSelection();
+
+       setCursor(cur);
+
+       if (length) {
+               if (backwards) {
+                       cursor().pos() += length;
+                       cursor().setSelection(cursor(), -length);
+               } else
+                       cursor().setSelection(cursor(), length);
+       }
 }
 
-bool BufferView::Dispatch(kb_action action, string const & argument)
+
+bool const BufferView::repaintAll() const
+{
+       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_->Dispatch(action, argument);
+       return pimpl_->offset_ref_;
 }