lyx_mirror/src/BufferView.C

394 lines
6.1 KiB
C++
Raw Normal View History

/**
* \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<EFBFBD>nnes
* \author John Levon
* \author Andr<EFBFBD> P<EFBFBD>nitz
* \author J<EFBFBD>rgen Vigna
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "BufferView.h"
#include "buffer.h"
#include "bufferlist.h"
#include "bufferparams.h"
#include "BufferView_pimpl.h"
the stuff from the sneak preview: For one, it still contains a few things that are already in CVS (the 'brown paperbag' changes). Secondly, this changes the ParagraphList to a std::vector but does not yet take full advantage of it except removing LyXText::parOffset() and similar. I had an extensive talk with my profiler and we are happy nevertheless. This also moves almost all Cut&Paste specific stuff from text.C to CutAndPaste.C. Much smaller interface now... Namespace CutAndPaste is now lyx::cap::. Was inconsistent with the rest.... Make ParagraphList a proper class. We'll need this later for a specialized erase/insert. Remove some unneeded prototypes and function declarations Use ParameterStruct directly instead of ShareContainer<ParameterStruct> Inline a few accesses to CursorSlice members as suggested by the profiler. Fix commandline conversion crash reported by Kayvan. Replace PosIterator by DocumentIterator. The latter can also iterate through math and nested text in math... Remove math specific hack from Documentiterator Derive InsetCollapsable from InsetText instead of using an InsetText member. This give us the opportunity to get rid of the InsetOld::owner_ backpointer. Cosmetics in CutAndPaste.C and cursor.C. Fix nasty crash (popping slices off an empty selection anchor). Add a few asserts. Remove all 'manual' update calls. We do now one per user interaction which is completely sufficient. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8527 a592a061-630c-0410-9148-cb99ea01b6c8
2004-03-25 09:16:36 +00:00
#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 "metricsinfo.h"
#include "frontends/Alert.h"
#include "frontends/Clipboard.h"
#include "frontends/Dialogs.h"
#include "frontends/LyXView.h"
#include "insets/insetcommand.h" // ChangeRefs
#include "insets/insettext.h"
using lyx::support::bformat;
the stuff from the sneak preview: For one, it still contains a few things that are already in CVS (the 'brown paperbag' changes). Secondly, this changes the ParagraphList to a std::vector but does not yet take full advantage of it except removing LyXText::parOffset() and similar. I had an extensive talk with my profiler and we are happy nevertheless. This also moves almost all Cut&Paste specific stuff from text.C to CutAndPaste.C. Much smaller interface now... Namespace CutAndPaste is now lyx::cap::. Was inconsistent with the rest.... Make ParagraphList a proper class. We'll need this later for a specialized erase/insert. Remove some unneeded prototypes and function declarations Use ParameterStruct directly instead of ShareContainer<ParameterStruct> Inline a few accesses to CursorSlice members as suggested by the profiler. Fix commandline conversion crash reported by Kayvan. Replace PosIterator by DocumentIterator. The latter can also iterate through math and nested text in math... Remove math specific hack from Documentiterator Derive InsetCollapsable from InsetText instead of using an InsetText member. This give us the opportunity to get rid of the InsetOld::owner_ backpointer. Cosmetics in CutAndPaste.C and cursor.C. Fix nasty crash (popping slices off an empty selection anchor). Add a few asserts. Remove all 'manual' update calls. We do now one per user interaction which is completely sufficient. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8527 a592a061-630c-0410-9148-cb99ea01b6c8
2004-03-25 09:16:36 +00:00
using lyx::cap::setSelectionRange;
using std::distance;
using std::find;
using std::string;
using std::vector;
extern BufferList bufferlist;
BufferView::BufferView(LyXView * owner)
: pimpl_(new Pimpl(*this, owner))
{}
BufferView::~BufferView()
{
delete pimpl_;
}
void BufferView::unsetXSel()
{
pimpl_->xsel_cache_.set = false;
}
Buffer * BufferView::buffer() const
{
return pimpl_->buffer_;
}
LyXView * BufferView::owner() const
{
return pimpl_->owner_;
}
void BufferView::setBuffer(Buffer * b)
{
pimpl_->setBuffer(b);
}
string BufferView::firstLayout()
{
return pimpl_->firstLayout();
}
bool BufferView::loadLyXFile(string const & fn, bool tl)
{
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();
}
bool BufferView::fitCursor()
{
return pimpl_->fitCursor();
}
bool BufferView::update(Update::flags flags)
{
return pimpl_->update(flags);
}
void BufferView::updateScrollbar()
{
pimpl_->updateScrollbar();
}
ScrollbarParameters const & BufferView::scrollbarParameters() const
{
return pimpl_->scrollbarParameters();
}
void BufferView::scrollDocView(int value)
{
pimpl_->scrollDocView(value);
}
bool BufferView::available() const
{
return pimpl_->available();
}
Change const BufferView::getCurrentChange()
{
return pimpl_->getCurrentChange();
}
void BufferView::savePosition(unsigned int i)
{
pimpl_->savePosition(i);
}
void BufferView::restorePosition(unsigned int i)
{
pimpl_->restorePosition(i);
}
bool BufferView::isSavedPosition(unsigned int i)
{
return pimpl_->isSavedPosition(i);
}
void BufferView::saveSavedPositions()
{
return pimpl_->saveSavedPositions();
}
void BufferView::switchKeyMap()
{
pimpl_->switchKeyMap();
}
int BufferView::workWidth() const
{
return pimpl_->width();
}
void BufferView::center()
{
pimpl_->center();
}
FuncStatus BufferView::getStatus(FuncRequest const & cmd)
{
return pimpl_->getStatus(cmd);
}
bool BufferView::dispatch(FuncRequest const & ev)
{
return pimpl_->dispatch(ev);
}
void BufferView::selectionRequested()
{
pimpl_->selectionRequested();
}
void BufferView::selectionLost()
{
pimpl_->selectionLost();
}
void BufferView::workAreaResize(int width, int height)
{
pimpl_->workAreaResize(width, height);
}
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::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;
}
}
}
LyXText * BufferView::getLyXText()
{
LyXText * text = cursor().innerText();
BOOST_ASSERT(text);
return text;
}
LyXText const * BufferView::getLyXText() const
{
LyXText const * text = cursor().innerText();
BOOST_ASSERT(text);
return text;
}
int BufferView::workHeight() const
{
return pimpl_->height();
}
LyXText * BufferView::text() const
{
return buffer() ? &buffer()->text() : 0;
}
void BufferView::setCursor(DocIterator const & dit)
{
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::mouseSetCursor(LCursor & cur)
{
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);
}
}
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_;
}
ViewMetricsInfo const & BufferView::viewMetricsInfo()
{
return pimpl_->viewMetricsInfo();
}
void BufferView::updateMetrics(bool singlepar)
{
pimpl_->updateMetrics(singlepar);
}