BufferView::BufferView(LyXView * owner, int xpos, int ypos,
int width, int height)
- : pimpl_(new Pimpl(*this, owner, xpos, ypos, width, height)),
- x_target_(0)
+ : pimpl_(new Pimpl(*this, owner, xpos, ypos, width, height))
{}
string const fname = MakeAbsPath(filen);
- clearSelection();
+ cursor().clearSelection();
text()->breakParagraph(buffer()->paragraphs());
bool res = buffer()->readFile(fname, text()->cursorPar());
vector<string> labels;
it->getLabelList(*buffer(), labels);
if (find(labels.begin(),labels.end(),label) != labels.end()) {
- clearSelection();
+ cursor().clearSelection();
text()->setCursor(
std::distance(text()->paragraphs().begin(), it.getPar()),
it.getPos());
- resetAnchor();
+ cursor().resetAnchor();
update();
return;
}
return;
owner()->message(_("Undo"));
- clearSelection();
+ cursor().clearSelection();
if (!textUndo(this))
owner()->message(_("No further undo information"));
update();
return;
owner()->message(_("Redo"));
- clearSelection();
+ cursor().clearSelection();
if (!textRedo(this))
owner()->message(_("No further redo information"));
update();
}
-UpdatableInset * BufferView::innerInset() const
-{
- return static_cast<UpdatableInset*>(fullCursor().innerInset());
-}
-
-
LyXText * BufferView::getLyXText() const
{
- return fullCursor().innerText();
+ return cursor().innerText();
}
}
-void BufferView::fullCursor(LCursor const & cur)
-{
- pimpl_->cursor_ = cur;
-}
-
-
-LCursor & BufferView::fullCursor()
-{
- return pimpl_->cursor_;
-}
-
-
-LCursor const & BufferView::fullCursor() const
-{
- return pimpl_->cursor_;
-}
-
-
-CursorSlice & BufferView::cursor()
-{
- return fullCursor().cursor_.back();
-}
-
-
-CursorSlice const & BufferView::cursor() const
-{
- return fullCursor().cursor_.back();
-}
-
-
-CursorSlice & BufferView::anchor()
-{
- return fullCursor().anchor_.back();
-}
-
-
-CursorSlice const & BufferView::anchor() const
-{
- return fullCursor().anchor_.back();
-}
-
-
-Selection & BufferView::selection()
-{
- return selection_;
-}
-
-
-Selection const & BufferView::selection() const
-{
- return selection_;
-}
-
-
-void BufferView::x_target(int x)
-{
- x_target_ = x;
-}
-
-
-int BufferView::x_target() const
-{
- return x_target_;
-}
-
-
void BufferView::updateParagraphDialog()
{
pimpl_->updateParagraphDialog();
}
-void BufferView::resetAnchor()
-{
- return fullCursor().resetAnchor();
-}
-
-
-CursorSlice const & BufferView::selStart() const
-{
- if (!selection().set())
- return cursor();
- // can't use std::min as this creates a new object
- return anchor() < cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice const & BufferView::selEnd() const
-{
- if (!selection().set())
- return cursor();
- return anchor() > cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice & BufferView::selStart()
-{
- if (!selection().set())
- return cursor();
- return anchor() < cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice & BufferView::selEnd()
-{
- if (selection().set())
- return cursor();
- return anchor() > cursor() ? anchor() : cursor();
-}
-
-
-void BufferView::setSelection()
-{
- selection().set(true);
- // a selection with no contents is not a selection
- if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
- selection().set(false);
-}
-
-
-void BufferView::clearSelection()
-{
- selection().set(false);
- selection().mark(false);
- resetAnchor();
- unsetXSel();
-}
-
/*
{
ParIterator par(cur);
- clearSelection();
+ cursor().clearSelection();
LyXText * text = par.text(*buffer());
par.lockPath(this);
top_y(par.outerPar()->y);
update();
text->setCursor(cur.pit(), cur.pos());
- fullCursor().updatePos();
+ cursor().updatePos();
if (length) {
text->setSelectionRange(length);
- setSelection();
+ cursor().setSelection();
if (backwards)
- std::swap(cursor(), anchor());
+ std::swap(cursor().cursor_, cursor().anchor_);
}
fitCursor();
}
-CursorSlice & cursorTip(BufferView & bv)
+LCursor & BufferView::cursor()
+{
+ return pimpl_->cursor_;
+}
+
+
+LCursor const & BufferView::cursor() const
{
- return bv.cursor();
+ return pimpl_->cursor_;
}
+
class Buffer;
class Change;
-class CursorSlice;
class Encoding;
class ErrorList;
class FuncRequest;
class LyXView;
class Painter;
class PosIterator;
-class Selection;
class TeXErrors;
class UpdatableInset;
-
-// The structure that keeps track of the selections set.
-struct Selection {
- Selection()
- : set_(false), mark_(false)
- {}
- bool set() const {
- return set_;
- }
- void set(bool s) {
- set_ = s;
- }
- bool mark() const {
- return mark_;
- }
- void mark(bool m) {
- mark_ = m;
- }
-private:
- bool set_; // former selection
- bool mark_; // former mark_set
-};
-
/**
* A buffer view encapsulates a view onto a particular
* buffer, and allows access to operate upon it. A view
/// execute the given function
bool dispatch(FuncRequest const & argument);
- /// set target x position of cursor
- void x_target(int x);
- /// return target x position of cursor
- int x_target() const;
-
/// clear the X selection
void unsetXSel();
/// access to full cursor
- LCursor & fullCursor();
- /// access to full cursor
- void fullCursor(LCursor const &);
+ LCursor & cursor();
/// access to full cursor
- LCursor const & fullCursor() const;
- /// access to topmost cursor slice
- CursorSlice & cursor();
- /// access to topmost cursor slice
- CursorSlice const & cursor() const;
- /// access to selection anchor
- CursorSlice & anchor();
- /// access to selection anchor
- CursorSlice const & anchor() const;
- ///
- UpdatableInset * innerInset() const;
+ LCursor const & cursor() const;
///
LyXText * text() const;
- ///
- void resetAnchor();
- ///
- Selection & selection();
- ///
- Selection const & selection() const;
- ///
- CursorSlice & selStart();
- ///
- CursorSlice const & selStart() const;
- ///
- CursorSlice & selEnd();
- ///
- CursorSlice const & selEnd() const;
- ///
- void setSelection();
- ///
- void clearSelection();
///
void putSelectionAt(PosIterator const & cur, int length, bool backwards);
- ///
- Selection selection_;
-
private:
///
struct Pimpl;
friend struct BufferView::Pimpl;
///
Pimpl * pimpl_;
-
- /**
- * The target x position of the cursor. This is used for when
- * we have text like :
- *
- * blah blah blah blah| blah blah blah
- * blah blah blah
- * blah blah blah blah blah blah
- *
- * When we move onto row 3, we would like to be vertically aligned
- * with where we were in row 1, despite the fact that row 2 is
- * shorter than x()
- */
- int x_target_;
-
};
#endif // BUFFERVIEW_H
if (!text)
return;
- par = bv_->cursor().par();
- pos = bv_->cursor().pos();
- selstartpar = bv_->selStart().par();
- selstartpos = bv_->selStart().pos();
- selendpar = bv_->selEnd().par();
- selendpos = bv_->selEnd().pos();
- sel = bv_->selection().set();
- mark_set = bv_->selection().mark();
+ LCursor & cur = bv_->cursor();
+ par = cur.par();
+ pos = cur.pos();
+ selstartpar = cur.selStart().par();
+ selstartpos = cur.selStart().pos();
+ selendpar = cur.selEnd().par();
+ selendpos = cur.selEnd().pos();
+ sel = cur.selection();
+ mark_set = cur.mark();
text->textwidth_ = bv_->workWidth();
text->fullRebreak();
update();
if (par != -1) {
- bv_->selection().set(true);
+ cur.selection() = true;
// At this point just to avoid the Delete-Empty-Paragraph-
// Mechanism when setting the cursor.
- bv_->selection().mark(mark_set);
+ cur.mark() = mark_set;
if (sel) {
text->setCursor(selstartpar, selstartpos);
- bv_->resetAnchor();
+ cur.resetAnchor();
text->setCursor(selendpar, selendpos);
- bv_->setSelection();
+ cur.setSelection();
text->setCursor(par, pos);
} else {
text->setCursor(par, pos);
- bv_->resetAnchor();
- bv_->selection().set(false);
+ cur.resetAnchor();
+ cur.selection() = false;
}
}
if (!available())
return;
- LyXText * text = bv_->getLyXText();
+ LCursor & cur = bv_->cursor();
- if (!bv_->selection().set()) {
+ if (!cur.selection()) {
xsel_cache_.set = false;
return;
}
if (!xsel_cache_.set ||
- bv_->cursor() != xsel_cache_.cursor ||
- bv_->anchor() != xsel_cache_.anchor)
+ cur.cursor_.back() != xsel_cache_.cursor ||
+ cur.anchor_.back() != xsel_cache_.anchor)
{
- xsel_cache_.cursor = bv_->cursor();
- xsel_cache_.anchor = bv_->anchor();
- xsel_cache_.set = bv_->selection().set();
- sel = text->selectionAsString(*bv_->buffer(), false);
+ xsel_cache_.cursor = cur.cursor_.back();
+ xsel_cache_.anchor = cur.anchor_.back();
+ xsel_cache_.set = cur.selection();
+ sel = bv_->getLyXText()->selectionAsString(*bv_->buffer(), false);
if (!sel.empty())
workarea().putClipboard(sel);
}
{
if (available()) {
screen().hideCursor();
- bv_->clearSelection();
+ bv_->cursor().clearSelection();
xsel_cache_.set = false;
}
}
return Change(Change::UNCHANGED);
LyXText * text = bv_->getLyXText();
+ LCursor & cur = bv_->cursor();
- if (!bv_->selection().set())
+ if (!cur.selection())
return Change(Change::UNCHANGED);
- return text->getPar(bv_->selStart())
- ->lookupChangeFull(bv_->selStart().pos());
+ return text->getPar(cur.selStart())
+ ->lookupChangeFull(cur.selStart().pos());
}
string const fname = saved_positions[i].filename;
- bv_->clearSelection();
+ bv_->cursor().clearSelection();
if (fname != buffer_->fileName()) {
Buffer * b = 0;
{
LyXText * text = bv_->text();
- bv_->clearSelection();
+ bv_->cursor().clearSelection();
int const half_height = workarea().workHeight() / 2;
int new_y = std::max(0, text->cursorY() - half_height);
}
#warning remove me
-LCursor theTempCursor;
+CursorBase theTempCursor;
namespace {
lyxerr << "insetFromCoords" << endl;
LyXText * text = bv->text();
InsetOld * inset = 0;
- theTempCursor = LCursor(*bv);
+ theTempCursor.clear();
while (true) {
InsetOld * const inset_hit = text->checkInsetHit(x, y);
if (!inset_hit) {
text = inset_hit->getText(cell);
lyxerr << "Hit inset: " << inset << " at x: " << x
<< " text: " << text << " y: " << y << endl;
- theTempCursor.push(static_cast<UpdatableInset*>(inset));
+ theTempCursor.push_back(CursorSlice(inset));
}
- lyxerr << "theTempCursor: " << theTempCursor << endl;
+ //lyxerr << "theTempCursor: " << theTempCursor << endl;
return inset;
}
bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
{
+ LCursor & cur = bv_->cursor();
switch (cmd.action) {
case LFUN_MOUSE_MOTION: {
if (!available())
return false;
FuncRequest cmd1 = cmd;
- UpdatableInset * inset = bv_->fullCursor().innerInset();
+ InsetBase * inset = cur.inset();
DispatchResult res;
if (inset) {
cmd1.x -= inset->x();
cmd1.y -= inset->y();
- res = inset->dispatch(*bv_, cmd1);
+ res = inset->dispatch(cur, cmd1);
} else {
cmd1.y += bv_->top_y();
- res = bv_->fullCursor().innerText()->dispatch(*bv_, cmd1);
+ res = cur.innerText()->dispatch(cur, cmd1);
}
if (bv_->fitCursor() || res.update()) {
bv_->update();
- bv_->fullCursor().updatePos();
+ cur.updatePos();
}
return true;
<< " to inset " << inset << endl;
cmd2.x -= inset->x();
cmd2.y -= inset->y();
- res = inset->dispatch(*bv_, cmd2);
+ res = inset->dispatch(cur, cmd2);
if (res.update()) {
bv_->update();
- bv_->fullCursor().updatePos();
+ cur.updatePos();
}
res.update(false);
switch (res.val()) {
case FINISHED_RIGHT:
case FINISHED_UP:
case FINISHED_DOWN:
- theTempCursor.pop();
- bv_->fullCursor(theTempCursor);
- bv_->fullCursor().innerText()
+ theTempCursor.pop_back();
+ cur.cursor_ = theTempCursor;
+ cur.innerText()
->setCursorFromCoordinates(cmd.x, top_y() + cmd.y);
if (bv_->fitCursor())
bv_->update();
// otherwise set cursor to surrounding LyXText
if (!res.dispatched()) {
- lyxerr << "temp cursor is: " << theTempCursor << endl;
- lyxerr << "dispatching " << cmd
- << " to surrounding LyXText "
- << theTempCursor.innerText() << endl;
- bv_->fullCursor(theTempCursor);
+ //lyxerr << "temp cursor is: " << theTempCursor << endl;
+ //lyxerr << "dispatching " << cmd
+ // << " to surrounding LyXText "
+ // << theTempCursor.innerText() << endl;
+ cur.cursor_ = theTempCursor;
FuncRequest cmd1 = cmd;
cmd1.y += bv_->top_y();
- res = bv_->fullCursor().innerText()->dispatch(*bv_, cmd1);
+ res = cur.innerText()->dispatch(cur, cmd1);
if (bv_->fitCursor() || res.update())
bv_->update();
<< endl;
LyXTextClass const & tclass = buffer_->params().getLyXTextClass();
+ LCursor & cur = bv_->cursor();
switch (ev.action) {
case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
case LFUN_MATH_DISPLAY: // Open or create a displayed math inset
case LFUN_MATH_MODE: // Open or create an inlined math inset
- mathDispatch(*bv_, ev);
+ mathDispatch(cur, ev);
break;
case LFUN_INSET_INSERT: {
break;
case LFUN_MARK_OFF:
- bv_->clearSelection();
+ cur.clearSelection();
bv_->update();
- bv_->resetAnchor();
+ cur.resetAnchor();
ev.message(N_("Mark off"));
break;
case LFUN_MARK_ON:
- bv_->clearSelection();
- bv_->selection().mark(true);
+ cur.clearSelection();
+ cur.mark() = true;
bv_->update();
- bv_->resetAnchor();
+ cur.resetAnchor();
ev.message(N_("Mark on"));
break;
case LFUN_SETMARK:
- bv_->clearSelection();
- if (bv_->selection().mark()) {
+ cur.clearSelection();
+ if (cur.mark()) {
ev.message(N_("Mark removed"));
} else {
- bv_->selection().mark(true);
+ cur.mark() = true;
ev.message(N_("Mark set"));
}
- bv_->resetAnchor();
+ cur.resetAnchor();
bv_->update();
break;
break;
default:
- return bv_->getLyXText()->dispatch(*bv_, ev).dispatched();
+ return cur.dispatch(ev).dispatched();
} // end of switch
return true;
bv_->text()->recUndo(bv_->text()->cursor().par());
freezeUndo();
- bv_->clearSelection();
+ bv_->cursor().clearSelection();
if (!lout.empty()) {
bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
bv_->text()->setLayout(hasLayout ? lres : tclass.defaultLayoutName());
bv_->text()->setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
}
- bv_->fullCursor().innerText()->insertInset(inset);
+ bv_->cursor().innerText()->insertInset(inset);
unFreezeUndo();
return true;
}
+2004-01-20 André Pönitz <poenitz@gmx.net>
+
+ * BufferView.[Ch]:
+ * BufferView_pimpl.C:
+ * PosIterator.C:
+ * bufferview_funcs.C:
+ * cursor.[Ch]:
+ * cursor_slice.[Ch]:
+ * factory.C:
+ * iterators.C:
+ * lyx_cb.C:
+ * lyxfind.C:
+ * lyxfunc.C:
+ * lyxtext.h:
+ * rowpainter.C:
+ * text.C:
+ * text2.C:
+ * text3.C:
+ * undo.[Ch]: lots of IU. Shift selection stuff from the BufferView to
+ LCursor and mathcursor parts to LCursor and InsetBase.
+
2004-01-15 André Pönitz <poenitz@gmx.net>
* cursor_slice.[Ch]: add a few covienience functions
#include "buffer.h"
#include "BufferView.h"
-#include "cursor_slice.h"
+#include "cursor.h"
#include "iterators.h"
#include "lyxtext.h"
#include "paragraph.h"
// Returns the current font and depth as a message.
string const currentState(BufferView * bv)
{
+ ostringstream state;
+
if (!bv->available())
return string();
- if (mathcursor)
- return mathcursor->info(bv->fullCursor());
-
- ostringstream state;
+ if (inMathed()) {
+ bv->cursor().info(state);
+ return state.str();
+ }
LyXText * text = bv->getLyXText();
Buffer * buffer = bv->buffer();
// deletes a selection during an insertion
void replaceSelection(LyXText * text)
{
- if (text->bv()->selection().set()) {
+ if (text->bv()->cursor().selection()) {
text->cutSelection(true, false);
text->bv()->update();
}
#include "insets/insettext.h"
#include "mathed/math_data.h"
+#include "mathed/math_inset.h"
#include <boost/assert.hpp>
using std::endl;
-std::ostream & operator<<(std::ostream & os, LCursor const & cur)
-{
- os << "\n";
- for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i)
- os << " (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
- return os;
-}
-
-
-LCursor::LCursor()
- : cursor_(1), anchor_(1), bv_(0)
-{}
-
-
LCursor::LCursor(BufferView & bv)
- : cursor_(1), anchor_(1), bv_(&bv)
+ : cursor_(1), anchor_(1), bv_(&bv), current_(0),
+ cached_y_(0), x_target_(-1),
+ selection_(false), mark_(false)
{}
FuncRequest cmd = cmd0;
for (int i = cursor_.size() - 1; i >= 1; --i) {
+ current_ = i;
CursorSlice const & citem = cursor_[i];
lyxerr << "trying to dispatch to inset " << citem.inset_ << endl;
- DispatchResult res = citem.inset_->dispatch(*bv_, cmd);
+ DispatchResult res = inset()->dispatch(*this, cmd);
if (res.dispatched()) {
lyxerr << " successfully dispatched to inset " << citem.inset_ << endl;
return DispatchResult(true, true);
}
}
lyxerr << "trying to dispatch to main text " << bv_->text() << endl;
- DispatchResult res = bv_->text()->dispatch(*bv_, cmd);
+ DispatchResult res = bv_->text()->dispatch(*this, cmd);
lyxerr << " result: " << res.val() << endl;
if (!res.dispatched()) {
lyxerr << "LCursor::push() inset: " << inset << endl;
cursor_.push_back(CursorSlice(inset));
anchor_.push_back(CursorSlice(inset));
+ ++current_;
updatePos();
}
-
void LCursor::pop(int depth)
{
- lyxerr << "LCursor::pop() to " << depth << endl;
- while (cursor_.size() > 1 && depth < cursor_.size()) {
- lyxerr << "LCursor::pop a level " << endl;
- cursor_.pop_back();
- anchor_.pop_back();
- }
+ lyxerr << "LCursor::pop() to depth " << depth << endl;
+ while (cursor_.size() > depth)
+ pop();
}
void LCursor::pop()
{
- lyxerr << "LCursor::pop() " << endl;
+ lyxerr << "LCursor::pop() a level" << endl;
//BOOST_ASSERT(!cursor_.empty());
if (cursor_.size() <= 1)
lyxerr << "### TRYING TO POP FROM EMPTY CURSOR" << endl;
else {
cursor_.pop_back();
anchor_.pop_back();
+ current_ = cursor_.size() - 1;
}
+ lyxerr << "LCursor::pop() current now: " << current_ << endl;
+}
+
+
+CursorSlice & LCursor::current()
+{
+ //lyxerr << "accessing cursor slice " << current_
+ // << ": " << cursor_[current_] << endl;
+ return cursor_[current_];
}
-UpdatableInset * LCursor::innerInset() const
+CursorSlice const & LCursor::current() const
{
- return cursor_.size() <= 1 ? 0 : cursor_.back().asUpdatableInset();
+ //lyxerr << "accessing cursor slice " << current_
+ // << ": " << cursor_[current_] << endl;
+ return cursor_[current_];
}
LyXText * LCursor::innerText() const
{
+ //lyxerr << "LCursor::innerText() depth: " << cursor_.size() << endl;
if (cursor_.size() > 1) {
// go up until first non-0 text is hit
// (innermost text is 0 e.g. for mathed and the outer tabular level)
asc = row.baseline();
desc = row.height() - asc;
} else {
- innerInset()->getCursorDim(asc, desc);
+ asc = 10;
+ desc = 10;
+ //innerInset()->getCursorDim(asc, desc);
}
}
y = bv_->text()->cursorY();
// y -= bv_->top_y();
} else {
- // Would be nice to clean this up to make some understandable sense...
- UpdatableInset * inset = innerInset();
- // Non-obvious. The reason we have to have these
- // extra checks is that the ->getCursor() calls rely
- // on the inset's own knowledge of its screen position.
- // If we scroll up or down in a big enough increment, the
- // inset->draw() is not called: this doesn't update
- // inset.top_baseline, so getCursor() returns an old value.
- // Ugly as you like.
- if (inset) {
- inset->getCursorPos(cursor_.back().idx_, x, y);
- x += inset->x();
+ if (inset()->asUpdatableInset()) {
+ // Would be nice to clean this up to make some understandable sense...
+ // Non-obvious. The reason we have to have these
+ // extra checks is that the ->getCursor() calls rely
+ // on the inset's own knowledge of its screen position.
+ // If we scroll up or down in a big enough increment, the
+ // inset->draw() is not called: this doesn't update
+ // inset.top_baseline, so getCursor() returns an old value.
+ // Ugly as you like.
+ inset()->asUpdatableInset()->getCursorPos(cursor_.back().idx_, x, y);
+ x += inset()->asUpdatableInset()->x();
y += cached_y_;
+ } else if (inset()->asMathInset()) {
+#warning FIXME
+ x = 100;
+ y = 100;
+ } else {
+ // this should not happen
+ BOOST_ASSERT(false);
}
}
}
-UpdatableInset * LCursor::innerInsetOfType(int code) const
+InsetBase * LCursor::innerInsetOfType(int code) const
{
for (int i = cursor_.size() - 1; i >= 1; --i)
- if (cursor_[i].asUpdatableInset()->lyxCode() == code)
- return cursor_[i].asUpdatableInset();
+ if (cursor_[i].inset_->lyxCode() == code)
+ return cursor_[i].inset_;
return 0;
}
InsetTabular * LCursor::innerInsetTabular() const
{
- return static_cast<InsetTabular *>
- (innerInsetOfType(InsetOld::TABULAR_CODE));
+ return static_cast<InsetTabular *>(innerInsetOfType(InsetBase::TABULAR_CODE));
}
++pos();
return true;
}
+
+
+CursorSlice & LCursor::anchor()
+{
+ return anchor_.back();
+}
+
+
+CursorSlice const & LCursor::anchor() const
+{
+ return anchor_.back();
+}
+
+
+CursorSlice const & LCursor::selStart() const
+{
+ if (!selection())
+ return cursor_.back();
+ // can't use std::min as this creates a new object
+ return anchor() < cursor_.back() ? anchor() : cursor_.back();
+}
+
+
+CursorSlice const & LCursor::selEnd() const
+{
+ if (!selection())
+ return cursor_.back();
+ return anchor() > cursor_.back() ? anchor() : cursor_.back();
+}
+
+
+CursorSlice & LCursor::selStart()
+{
+ if (!selection())
+ return cursor_.back();
+ return anchor() < cursor_.back() ? anchor() : cursor_.back();
+}
+
+
+CursorSlice & LCursor::selEnd()
+{
+ if (selection())
+ return cursor_.back();
+ return anchor() > cursor_.back() ? anchor() : cursor_.back();
+}
+
+
+void LCursor::setSelection()
+{
+ selection() = true;
+ // a selection with no contents is not a selection
+ if (par() == anchor().par() && pos() == anchor().pos())
+ selection() = false;
+}
+
+
+void LCursor::clearSelection()
+{
+ selection() = false;
+ mark() = false;
+ resetAnchor();
+ bv().unsetXSel();
+}
+
+
+
+//
+// CursorBase
+//
+
+
+void increment(CursorBase & it)
+{
+ CursorSlice & top = it.back();
+ MathArray & ar = top.asMathInset()->cell(top.idx_);
+
+ // move into the current inset if possible
+ // it is impossible for pos() == size()!
+ MathInset * n = 0;
+ if (top.pos() != top.lastpos())
+ n = (ar.begin() + top.pos_)->nucleus();
+ if (n && n->isActive()) {
+ it.push_back(CursorSlice(n));
+ return;
+ }
+
+ // otherwise move on one cell back if possible
+ if (top.pos() < top.lastpos()) {
+ // pos() == lastpos() is valid!
+ ++top.pos_;
+ return;
+ }
+
+ // otherwise try to move on one cell if possible
+ while (top.idx_ + 1 < top.asMathInset()->nargs()) {
+ // idx() == nargs() is _not_ valid!
+ ++top.idx_;
+ if (top.asMathInset()->validCell(top.idx_)) {
+ top.pos_ = 0;
+ return;
+ }
+ }
+
+ // otherwise leave array, move on one back
+ // this might yield pos() == size(), but that's a ok.
+ it.pop_back();
+ // it certainly invalidates top
+ ++it.back().pos_;
+}
+
+
+CursorBase ibegin(InsetBase * p)
+{
+ CursorBase it;
+ it.push_back(CursorSlice(p));
+ return it;
+}
+
+
+CursorBase iend(InsetBase * p)
+{
+ CursorBase it;
+ it.push_back(CursorSlice(p));
+ CursorSlice & top = it.back();
+ top.idx_ = top.asMathInset()->nargs() - 1;
+ top.pos_ = top.asMathInset()->cell(top.idx_).size();
+ return it;
+}
+
+
+void LCursor::x_target(int x)
+{
+ x_target_ = x;
+}
+
+
+int LCursor::x_target() const
+{
+ return x_target_;
+}
+
+
+Paragraph & LCursor::paragraph()
+{
+ return current_ ? current().paragraph() : *bv_->text()->getPar(par());
+}
+
+
+Paragraph const & LCursor::paragraph() const
+{
+ return current_ ? current().paragraph() : *bv_->text()->getPar(par());
+}
+
+
+LCursor::pos_type LCursor::lastpos() const
+{
+ return current_ ? current().lastpos() : bv_->text()->getPar(par())->size();
+}
+
+
+size_t LCursor::nargs() const
+{
+ // assume 1x1 grid for 'plain text'
+ return current_ ? current().nargs() : 1;
+}
+
+
+size_t LCursor::ncols() const
+{
+ // assume 1x1 grid for 'plain text'
+ return current_ ? current().ncols() : 1;
+}
+
+
+size_t LCursor::nrows() const
+{
+ // assume 1x1 grid for 'plain text'
+ return current_ ? current().nrows() : 1;
+}
+
+
+LCursor::row_type LCursor::row() const
+{
+ BOOST_ASSERT(current_ > 0);
+ return current().row();
+}
+
+
+LCursor::col_type LCursor::col() const
+{
+ BOOST_ASSERT(current_ > 0);
+ return current().col();
+}
+
+
+MathArray const & LCursor::cell() const
+{
+ BOOST_ASSERT(current_ > 0);
+ return current().cell();
+}
+
+
+MathArray & LCursor::cell()
+{
+ BOOST_ASSERT(current_ > 0);
+ return current().cell();
+}
+
+
+void LCursor::info(std::ostream & os)
+{
+ for (int i = 1, n = depth(); i < n; ++i) {
+ cursor_[i].inset()->infoize(os);
+ os << " ";
+ }
+#warning FIXME
+ //if (pos() != 0)
+ // prevAtom()->infoize2(os);
+ // overwite old message
+ os << " ";
+}
+
+
+std::ostream & operator<<(std::ostream & os, LCursor const & cur)
+{
+ os << "\n";
+ for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i)
+ os << " (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
+ return os;
+}
class MathAtom;
class DispatchResult;
class FuncRequest;
-class LyXText;
class InsetTabular;
+class LyXText;
+class Paragraph;
+
+
+
+// this is used for traversing math insets
+typedef std::vector<CursorSlice> CursorBase;
+/// move on one step
+void increment(CursorBase &);
+///
+CursorBase ibegin(InsetBase * p);
+///
+CursorBase iend(InsetBase * p);
/**
/// type for col indices
typedef CursorSlice::col_type col_type;
- /// create 'empty' cursor. REMOVE ME
- LCursor();
/// create the cursor of a BufferView
explicit LCursor(BufferView & bv);
/// dispatch from innermost inset upwards
void pop(int depth);
/// pop one level off the cursor
void pop();
- /// access to cursor 'tip'
- CursorSlice & top() { return cursor_.back(); }
- /// access to cursor 'tip'
- CursorSlice const & top() const { return cursor_.back(); }
+ /// access to current cursor slice
+ CursorSlice & current();
+ /// access to current cursor slice
+ CursorSlice const & current() const;
/// how many nested insets do we have?
size_t depth() const { return cursor_.size(); }
- /// access to the topmost slice
+ //
+ // selection
+ //
+ /// selection active?
+ bool selection() const { return selection_; }
+ /// selection active?
+ bool & selection() { return selection_; }
+ /// did we place the anchor?
+ bool mark() const { return mark_; }
+ /// did we place the anchor?
+ bool & mark() { return mark_; }
+ ///
+ void setSelection();
+ ///
+ void clearSelection();
+ ///
+ CursorSlice & selStart();
+ ///
+ CursorSlice const & selStart() const;
+ ///
+ CursorSlice & selEnd();
+ ///
+ CursorSlice const & selEnd() const;
+
+ //
+ // access to the 'current' cursor slice
+ //
/// the current inset
- InsetBase * inset() const { return top().inset(); }
+ InsetBase * inset() const { return current().inset(); }
/// return the text-ed cell this cursor is in
- idx_type idx() const { return top().idx(); }
+ idx_type idx() const { return current().idx(); }
/// return the text-ed cell this cursor is in
- idx_type & idx() { return top().idx(); }
+ idx_type & idx() { return current().idx(); }
/// return the paragraph this cursor is in
- par_type par() const { return top().par(); }
+ par_type par() const { return current().par(); }
/// return the paragraph this cursor is in
- par_type & par() { return top().par(); }
+ par_type & par() { return current().par(); }
/// return the position within the paragraph
- pos_type pos() const { return top().pos(); }
+ pos_type pos() const { return current().pos(); }
/// return the position within the paragraph
- pos_type & pos() { return top().pos(); }
+ pos_type & pos() { return current().pos(); }
/// return the last position within the paragraph
- pos_type lastpos() const { return top().lastpos(); }
+ pos_type lastpos() const;
/// return the number of embedded cells
- size_t nargs() const { return top().nargs(); }
+ size_t nargs() const;
/// return the number of embedded cells
- size_t ncols() const { return top().ncols(); }
+ size_t ncols() const;
/// return the number of embedded cells
- size_t nrows() const { return top().nrows(); }
+ size_t nrows() const;
/// return the grid row of the current cell
- row_type row() const { return top().row(); }
+ row_type row() const;
/// return the grid row of the current cell
- col_type col() const { return top().col(); }
+ col_type col() const;
//
// math-specific part
//
/// return the mathed cell this cursor is in
- MathArray const & cell() const { return top().cell(); }
+ MathArray const & cell() const;
/// return the mathed cell this cursor is in
- MathArray & cell() { return top().cell(); }
+ MathArray & cell();
/// the mathatom left of the cursor
MathAtom const & prevAtom() const;
/// the mathatom left of the cursor
MathAtom const & nextAtom() const;
/// the mathatom right of the cursor
MathAtom & nextAtom();
+ /// auto-correct mode
+ bool autocorrect() const { return autocorrect_; }
+ /// auto-correct mode
+ bool & autocorrect() { return autocorrect_; }
+ /// are we entering a macro name?
+ bool macromode() const { return macromode_; }
+ /// are we entering a macro name?
+ bool & macromode() { return macromode_; }
//
// text-specific part
///
- UpdatableInset * innerInset() const;
+ bool boundary() const { return current().boundary(); }
+ ///
+ Paragraph & paragraph();
+ ///
+ Paragraph const & paragraph() const;
///
- UpdatableInset * innerInsetOfType(int code) const;
+ InsetBase * innerInsetOfType(int code) const;
///
InsetTabular * innerInsetTabular() const;
///
/// move one step to the right
bool posRight();
+ /// set target x position of cursor
+ void x_target(int x);
+ /// return target x position of cursor
+ int x_target() const;
+
+ /// access to selection anchor
+ CursorSlice & anchor();
+ /// access to selection anchor
+ CursorSlice const & anchor() const;
/// cache the absolute coordinate from the top inset
void updatePos();
/// sets anchor to cursor position
void resetAnchor();
/// access to owning BufferView
BufferView & bv() const;
- ///
- friend std::ostream & operator<<(std::ostream &, LCursor const &);
+ /// get some interesting description of current position
+ void info(std::ostream & os);
+
+ /// output
+ friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
public:
+//private:
/// mainly used as stack, but wee need random access
std::vector<CursorSlice> cursor_;
- /// The
+ /// the anchor position
std::vector<CursorSlice> anchor_;
- ///
- BufferView * bv_;
+
private:
+ /// don't implement this
+ void operator=(LCursor const &);
+ /// don't implement this
+ LCursor(LCursor const &);
+
+ ///
+ BufferView * const bv_;
+ /// current slice
+ int current_;
///
int cached_y_;
+ /**
+ * The target x position of the cursor. This is used for when
+ * we have text like :
+ *
+ * blah blah blah blah| blah blah blah
+ * blah blah blah
+ * blah blah blah blah blah blah
+ *
+ * When we move onto row 3, we would like to be vertically aligned
+ * with where we were in row 1, despite the fact that row 2 is
+ * shorter than x()
+ */
+ int x_target_;
+ // do we have a selection?
+ bool selection_;
+ // are we on the way to get one?
+ bool mark_;
+
+ //
+ // math specific stuff that could be promoted to "global" later
+ //
+ /// do we allow autocorrection
+ bool autocorrect_;
+ /// are we entering a macro name?
+ bool macromode_;
};
#endif // LYXCURSOR_H
#include "cursor_slice.h"
#include "debug.h"
+#include "lyxtext.h"
+#include "paragraph.h"
#include "mathed/math_inset.h"
#include "mathed/math_data.h"
}
+size_t CursorSlice::nrows() const
+{
+ return inset_->nrows();
+}
+
+
size_t CursorSlice::ncols() const
{
return inset_->ncols();
CursorSlice::pos_type CursorSlice::lastpos() const
{
- BOOST_ASSERT(inset_);
-#warning implement me for texted, too.
- return inset_->asMathInset() ? cell().size() : 0;
+ return (inset_ && inset_->asMathInset()) ? cell().size() : paragraph().size();
}
}
+Paragraph & CursorSlice::paragraph()
+{
+ // access to the main lyx text must be handled in the cursor
+ BOOST_ASSERT(text());
+ return *text()->getPar(par_);
+}
+
+
+Paragraph const & CursorSlice::paragraph() const
+{
+ // access to the main lyx text must be handled in the cursor
+ BOOST_ASSERT(text());
+ return *text()->getPar(par_);
+}
+
+
bool operator==(CursorSlice const & p, CursorSlice const & q)
{
return p.inset_ == q.inset_
std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
{
- os << " inset: " << item.inset_
- << " text: " << item.text()
+ os << "inset: " << item.inset_
+// << " text: " << item.text()
<< " idx: " << item.idx_
<< " par: " << item.par_
<< " pos: " << item.pos_
;
return os;
}
-
-
-
-
-void increment(CursorBase & it)
-{
- CursorSlice & top = it.back();
- MathArray & ar = top.asMathInset()->cell(top.idx_);
-
- // move into the current inset if possible
- // it is impossible for pos() == size()!
- MathInset * n = 0;
- if (top.pos_ != ar.size())
- n = (ar.begin() + top.pos_)->nucleus();
- if (n && n->isActive()) {
- it.push_back(CursorSlice(n));
- return;
- }
-
- // otherwise move on one cell back if possible
- if (top.pos_ < ar.size()) {
- // pos() == size() is valid!
- ++top.pos_;
- return;
- }
-
- // otherwise try to move on one cell if possible
- while (top.idx_ + 1 < top.asMathInset()->nargs()) {
- // idx() == nargs() is _not_ valid!
- ++top.idx_;
- if (top.asMathInset()->validCell(top.idx_)) {
- top.pos_ = 0;
- return;
- }
- }
-
- // otherwise leave array, move on one back
- // this might yield pos() == size(), but that's a ok.
- it.pop_back();
- // it certainly invalidates top
- ++it.back().pos_;
-}
-
-
-CursorBase ibegin(InsetBase * p)
-{
- CursorBase it;
- it.push_back(CursorSlice(p));
- return it;
-}
-
-
-CursorBase iend(InsetBase * p)
-{
- CursorBase it;
- it.push_back(CursorSlice(p));
- CursorSlice & top = it.back();
- top.idx_ = top.asMathInset()->nargs() - 1;
- top.pos_ = top.asMathInset()->cell(top.idx_).size();
- return it;
-}
#ifndef CURSORSLICE_H
#define CURSORSLICE_H
-#include <iosfwd>
#include <cstddef>
+#include <iosfwd>
#include "support/types.h"
class MathInset;
class MathArray;
class LyXText;
+class Paragraph;
class UpdatableInset;
LyXText * text() const;
///
UpdatableInset * asUpdatableInset() const;
+ ///
+ Paragraph & paragraph();
+ ///
+ Paragraph const & paragraph() const;
///
/// mathed specific stuff
/// test for order
bool operator>(CursorSlice const &, CursorSlice const &);
-#include <vector>
-
-
-// this is used for traversing math insets
-typedef std::vector<CursorSlice> CursorBase;
-/// move on one step
-void increment(CursorBase &);
-///
-CursorBase ibegin(InsetBase * p);
-///
-CursorBase iend(InsetBase * p);
-///
-CursorSlice & cursorTip(BufferView &);
-
-
-
#endif
bv->owner()->getDialogs().show("tabularcreate");
return 0;
- case LFUN_INSET_CAPTION:
- if (!bv->innerInset()) {
- auto_ptr<InsetCaption> inset(new InsetCaption(params));
- inset->setOwner(bv->innerInset());
- inset->setAutoBreakRows(true);
- inset->setDrawFrame(InsetText::LOCKED);
- inset->setFrameColor(LColor::captionframe);
- return inset.release();
+ case LFUN_INSET_CAPTION: {
+ UpdatableInset * up = bv->cursor().inset()
+ ? bv->cursor().inset()->asUpdatableInset() : 0;
+ if (!up) {
+ auto_ptr<InsetCaption> inset(new InsetCaption(params));
+ inset->setOwner(up);
+ inset->setAutoBreakRows(true);
+ inset->setDrawFrame(InsetText::LOCKED);
+ inset->setFrameColor(LColor::captionframe);
+ return inset.release();
+ }
+ return 0;
}
- return 0;
case LFUN_INDEX_PRINT:
return new InsetPrintIndex(InsetCommandParams("printindex"));
void LyXView::updateToolbar()
{
- bool const math = mathcursor;
+ bool const math = inMathed();
bool const table =
!getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).disabled();
toolbar_->update(math, table);
int h = ascent + descent;
int x = 0;
int y = 0;
- bv.fullCursor().getPos(x, y);
+ bv.cursor().getPos(x, y);
y -= ascent + bv.top_y();
//lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl;
int newtop = top_y;
int x, y, asc, desc;
- bv->fullCursor().getPos(x, y);
- bv->fullCursor().getDim(asc, desc);
+ bv->cursor().getPos(x, y);
+ bv->cursor().getDim(asc, desc);
bool const big_row = h / 4 < asc + desc && asc + desc < h;
+2004-01-20 André Pönitz <poenitz@gmx.net>
+
+ * inset.h:
+ * insetbase.[Ch]: move stuff from mathcursor here.
+
+ * insetbibitem.[Ch]:
+ * insetbibtex.[Ch]:
+ * insetbox.[Ch]:
+ * insetbranch.[Ch]:
+ * insetcharstyle.[Ch]:
+ * insetcollapsable.[Ch]:
+ * insetcommand.[Ch]:
+ * insetert.[Ch]:
+ * insetexternal.[Ch]:
+ * insetfloat.[Ch]:
+ * insetgraphics.[Ch]:
+ * insetinclude.[Ch]:
+ * insetlabel.[Ch]:
+ * insetnote.[Ch]:
+ * insetref.[Ch]:
+ * insettabular.[Ch]:
+ * insettext.[Ch]:
+ * insetvspace.[Ch]:
+ * insetwrap.[Ch]:
+ * updatableinset.[Ch]: Adjust to IU changes (see comment in src/Changelog)
+
2004-01-15 André Pönitz <poenitz@gmx.net>
* insetbase.[Ch]:
#include "insetbase.h"
#include "dimension.h"
-#include "ParagraphList_fwd.h"
-
class Buffer;
class LColor_color;
}
}
+
/// Insets
class InsetOld : public InsetBase {
public:
- /** This is not quite the correct place for this enum. I think
- the correct would be to let each subclass of Inset declare
- its own enum code. Actually the notion of an InsetOld::Code
- should be avoided, but I am not sure how this could be done
- in a cleaner way. */
- enum Code {
- ///
- NO_CODE, // 0
- ///
- TOC_CODE, // do these insets really need a code? (ale)
- ///
- QUOTE_CODE,
- ///
- MARK_CODE,
- ///
- REF_CODE,
- ///
- URL_CODE, // 5
- ///
- HTMLURL_CODE,
- ///
- SEPARATOR_CODE,
- ///
- ENDING_CODE,
- ///
- LABEL_CODE,
- ///
- NOTE_CODE, // 10
- ///
- ACCENT_CODE,
- ///
- MATH_CODE,
- ///
- INDEX_CODE,
- ///
- INCLUDE_CODE,
- ///
- GRAPHICS_CODE, // 15
- ///
- BIBITEM_CODE,
- ///
- BIBTEX_CODE,
- ///
- TEXT_CODE,
- ///
- ERT_CODE,
- ///
- FOOT_CODE, // 20
- ///
- MARGIN_CODE,
- ///
- FLOAT_CODE,
- ///
- WRAP_CODE,
- ///
- SPACE_CODE, // 25
- ///
- SPECIALCHAR_CODE,
- ///
- TABULAR_CODE,
- ///
- EXTERNAL_CODE,
-#if 0
- ///
- THEOREM_CODE,
-#endif
- ///
- CAPTION_CODE,
- ///
- MATHMACRO_CODE, // 30
- ///
- ERROR_CODE,
- ///
- CITE_CODE,
- ///
- FLOAT_LIST_CODE,
- ///
- INDEX_PRINT_CODE,
- ///
- OPTARG_CODE, // 35
- ///
- ENVIRONMENT_CODE,
- ///
- HFILL_CODE,
- ///
- NEWLINE_CODE,
- ///
- LINE_CODE,
- ///
- BRANCH_CODE, // 40
- ///
- BOX_CODE,
- ///
- CHARSTYLE_CODE,
- ///
- VSPACE_CODE
- };
-
///
enum {
///
virtual int docbook(Buffer const &, std::ostream &,
OutputParams const &) const = 0;
- /// returns LyX code associated with the inset. Used for TOC, ...)
- virtual InsetOld::Code lyxCode() const { return NO_CODE; }
-
/// returns true to override begin and end inset in file
virtual bool directWrite() const;
#include "dispatchresult.h"
-DispatchResult InsetBase::dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
{
- return priv_dispatch(bv, cmd);
+ return priv_dispatch(cur, cmd);
}
-DispatchResult
-InsetBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const & cmd)
{
return DispatchResult(false);
}
-void InsetBase::edit(BufferView *, bool)
+void InsetBase::edit(LCursor &, bool)
{
lyxerr << "InsetBase: edit left/right" << std::endl;
}
-void InsetBase::edit(BufferView * bv, int, int)
+void InsetBase::edit(LCursor & cur, int, int)
{
lyxerr << "InsetBase: edit xy" << std::endl;
- edit(bv, true);
+ edit(cur, true);
}
class DispatchResult;
class FuncRequest;
class LaTeXFeatures;
+class LCursor;
class MathInset;
class MetricsInfo;
class Dimension;
virtual UpdatableInset * asUpdatableInset() { return 0; }
// the real dispatcher
- DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd);
+ DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
/// cursor enters
- virtual void edit(BufferView * bv, bool left);
+ virtual void edit(LCursor & cur, bool left);
/// cursor enters
- virtual void edit(BufferView * bv, int x, int y);
+ virtual void edit(LCursor & cur, int x, int y);
/// compute the size of the object returned in dim
virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
/// draw inset and update (xo, yo)-cache
virtual void draw(PainterInfo & pi, int x, int y) const = 0;
-
- /// request "external features"
- virtual void validate(LaTeXFeatures &) const {}
- /// Appends \c list with all labels found within this inset.
- virtual void getLabelList(Buffer const &,
- std::vector<std::string> & /* list */) const {}
/// last drawn position for 'important' insets
virtual int x() const { return 0; }
/// last drawn position for 'important' insets
virtual size_t nrows() const { return 0; }
/// number of columns in gridlike structures
virtual size_t ncols() const { return 0; }
+
+ /// request "external features"
+ virtual void validate(LaTeXFeatures &) const {}
+ /// Appends \c list with all labels found within this inset.
+ virtual void getLabelList(Buffer const &,
+ std::vector<std::string> & /* list */) const {}
+ /// describe content if cursor inside
+ virtual void infoize(std::ostream &) const {}
+ /// describe content if cursor behind
+ virtual void infoize2(std::ostream &) const {}
protected:
// the real dispatcher
virtual
- DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+public:
+ /** This is not quite the correct place for this enum. I think
+ the correct would be to let each subclass of Inset declare
+ its own enum code. Actually the notion of an InsetOld::Code
+ should be avoided, but I am not sure how this could be done
+ in a cleaner way. */
+ enum Code {
+ ///
+ NO_CODE, // 0
+ ///
+ TOC_CODE, // do these insets really need a code? (ale)
+ ///
+ QUOTE_CODE,
+ ///
+ MARK_CODE,
+ ///
+ REF_CODE,
+ ///
+ URL_CODE, // 5
+ ///
+ HTMLURL_CODE,
+ ///
+ SEPARATOR_CODE,
+ ///
+ ENDING_CODE,
+ ///
+ LABEL_CODE,
+ ///
+ NOTE_CODE, // 10
+ ///
+ ACCENT_CODE,
+ ///
+ MATH_CODE,
+ ///
+ INDEX_CODE,
+ ///
+ INCLUDE_CODE,
+ ///
+ GRAPHICS_CODE, // 15
+ ///
+ BIBITEM_CODE,
+ ///
+ BIBTEX_CODE,
+ ///
+ TEXT_CODE,
+ ///
+ ERT_CODE,
+ ///
+ FOOT_CODE, // 20
+ ///
+ MARGIN_CODE,
+ ///
+ FLOAT_CODE,
+ ///
+ WRAP_CODE,
+ ///
+ SPACE_CODE, // 25
+ ///
+ SPECIALCHAR_CODE,
+ ///
+ TABULAR_CODE,
+ ///
+ EXTERNAL_CODE,
+#if 0
+ ///
+ THEOREM_CODE,
+#endif
+ ///
+ CAPTION_CODE,
+ ///
+ MATHMACRO_CODE, // 30
+ ///
+ ERROR_CODE,
+ ///
+ CITE_CODE,
+ ///
+ FLOAT_LIST_CODE,
+ ///
+ INDEX_PRINT_CODE,
+ ///
+ OPTARG_CODE, // 35
+ ///
+ ENVIRONMENT_CODE,
+ ///
+ HFILL_CODE,
+ ///
+ NEWLINE_CODE,
+ ///
+ LINE_CODE,
+ ///
+ BRANCH_CODE, // 40
+ ///
+ BOX_CODE,
+ ///
+ CHARSTYLE_CODE,
+ ///
+ VSPACE_CODE,
+ ///
+ MATHGRID_CODE,
+ ///
+ MATHHULL_CODE
+ };
+ /// returns LyX code associated with the inset. Used for TOC, ...)
+ virtual InsetBase::Code lyxCode() const { return NO_CODE; }
+
};
#endif
DispatchResult
-InsetBibitem::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetBibitem::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
if (p.getCmdName().empty())
return DispatchResult(true, true);
setParams(p);
- bv.update();
- bv.fitCursor();
+ cur.bv().update();
+ cur.bv().fitCursor();
return DispatchResult(true, true);
}
default:
- return InsetCommand::priv_dispatch(bv, cmd);
+ return InsetCommand::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
int counter;
DispatchResult
-InsetBibtex::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetBibtex::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
}
default:
- return InsetCommand::priv_dispatch(bv, cmd);
+ return InsetCommand::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
};
#endif // INSET_BIBTEX_H
#include "insetbox.h"
-#include "BufferView.h"
+#include "cursor.h"
#include "dispatchresult.h"
#include "debug.h"
#include "funcrequest.h"
DispatchResult
-InsetBox::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetBox::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
}
case LFUN_INSET_DIALOG_UPDATE:
- InsetBoxMailer(*this).updateDialog(&bv);
+ InsetBoxMailer(*this).updateDialog(&cur.bv());
return DispatchResult(true);
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
- InsetBoxMailer(*this).showDialog(&bv);
+ InsetBoxMailer(*this).showDialog(&cur.bv());
return DispatchResult(true);
}
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
default:
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
friend class InsetBoxParams;
#include "buffer.h"
#include "bufferparams.h"
#include "BranchList.h"
-#include "BufferView.h"
+#include "cursor.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "gettext.h"
DispatchResult
-InsetBranch::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetBranch::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
case LFUN_MOUSE_PRESS:
if (cmd.button() != mouse_button::button3)
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
return DispatchResult(false);
case LFUN_INSET_DIALOG_UPDATE:
- InsetBranchMailer(*this).updateDialog(&bv);
+ InsetBranchMailer(*this).updateDialog(&cur.bv());
return DispatchResult(true);
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
- InsetBranchMailer(*this).showDialog(&bv);
+ InsetBranchMailer(*this).showDialog(&cur.bv());
return DispatchResult(true);
}
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
default:
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
friend class InsetBranchParams;
DispatchResult
-InsetCharStyle::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
setStatus(Inlined);
switch (cmd.action) {
has_label_ = !has_label_;
return DispatchResult(true);
}
- inset.dispatch(bv, cmd);
+ inset.dispatch(cur, cmd);
return DispatchResult(true, true);
default:
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
}
}
int InsetCharStyle::plaintext(Buffer const &, std::ostream & os,
- OutputParams const & runparams) const
+ OutputParams const & /*runparams*/) const
{
return outputVerbatim(os, inset);
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
friend class InsetCharStyleParams;
DispatchResult
-InsetCollapsable::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
+InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
{
if (cmd.button() == mouse_button::button3) {
lyxerr << "InsetCollapsable::lfunMouseRelease 0" << endl;
- showInsetDialog(&bv);
+ showInsetDialog(&cur.bv());
return DispatchResult(true, true);
}
case Collapsed:
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
setStatus(Open);
- edit(&bv, true);
+ edit(cur, true);
return DispatchResult(true, true);
case Open:
return DispatchResult(false, FINISHED_RIGHT);
}
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
- return inset.dispatch(bv, adjustCommand(cmd));
+ return inset.dispatch(cur, adjustCommand(cmd));
case Inlined:
- return inset.dispatch(bv, cmd);
+ return inset.dispatch(cur, cmd);
}
return DispatchResult(true, true);
}
-void InsetCollapsable::edit(BufferView * bv, bool left)
+void InsetCollapsable::edit(LCursor & cur, bool left)
{
lyxerr << "InsetCollapsable: edit left/right" << endl;
- inset.edit(bv, left);
+ cur.push(this);
+ inset.edit(cur, left);
open();
- bv->fullCursor().push(this);
}
-void InsetCollapsable::edit(BufferView * bv, int x, int y)
+void InsetCollapsable::edit(LCursor & cur, int x, int y)
{
+ cur.push(this);
lyxerr << "InsetCollapsable: edit xy" << endl;
if (status_ == Collapsed) {
setStatus(Open);
else
y += inset.ascent() - height_collapsed();
}
- inset.edit(bv, x, y);
- bv->fullCursor().push(this);
+ inset.edit(cur, x, y);
}
DispatchResult
-InsetCollapsable::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
// << " button y: " << button_dim.y2 << endl;
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
if (status_ == Inlined)
- inset.dispatch(bv, cmd);
+ inset.dispatch(cur, cmd);
else if (status_ == Open && cmd.y > button_dim.y2)
- inset.dispatch(bv, adjustCommand(cmd));
+ inset.dispatch(cur, adjustCommand(cmd));
return DispatchResult(true, true);
case LFUN_MOUSE_MOTION:
if (status_ == Inlined)
- inset.dispatch(bv, cmd);
+ inset.dispatch(cur, cmd);
else if (status_ == Open && cmd.y > button_dim.y2)
- inset.dispatch(bv, adjustCommand(cmd));
+ inset.dispatch(cur, adjustCommand(cmd));
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
- return lfunMouseRelease(bv, cmd);
+ return lfunMouseRelease(cur, cmd);
case LFUN_INSET_TOGGLE:
if (inset.text_.toggleInset())
}
default:
- return inset.dispatch(bv, adjustCommand(cmd));
+ return inset.dispatch(cur, adjustCommand(cmd));
}
- //lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
void dimension_collapsed(Dimension &) const;
///
///
Box const & buttonDim() const;
///
- void edit(BufferView *, bool);
+ void edit(LCursor & cur, bool left);
///
- void edit(BufferView *, int, int);
+ void edit(LCursor & cur, int x, int y);
private:
///
- DispatchResult lfunMouseRelease(BufferView & bv, FuncRequest const &);
+ DispatchResult lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
///
FuncRequest adjustCommand(FuncRequest const &);
DispatchResult
-InsetCommand::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetCommand::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
if (p.getCmdName().empty())
return DispatchResult(false);
setParams(p);
- bv.update();
+ cur.bv().update();
return DispatchResult(true, true);
}
case LFUN_INSET_DIALOG_UPDATE:
- InsetCommandMailer(cmd.argument, *this).updateDialog(&bv);
+ InsetCommandMailer(cmd.argument, *this).updateDialog(&cur.bv());
return DispatchResult(true, true);
case LFUN_INSET_DIALOG_SHOW:
case LFUN_MOUSE_RELEASE: {
if (!mailer_name_.empty())
- InsetCommandMailer(mailer_name_, *this).showDialog(&bv);
+ InsetCommandMailer(mailer_name_, *this).showDialog(&cur.bv());
return DispatchResult(true);
}
#ifndef INSET_LATEXCOMMAND_H
#define INSET_LATEXCOMMAND_H
-
#include "inset.h"
#include "insetcommandparams.h"
#include "render_button.h"
#include "mailinset.h"
+#include "cursor.h"
+
// Created by Alejandro 970222
/** Used to insert a LaTeX command automatically
class InsetCommand : public InsetOld {
public:
///
- explicit
- InsetCommand(InsetCommandParams const &,
- std::string const & mailer_name);
+ InsetCommand(InsetCommandParams const &, std::string const & mailer_name);
///
~InsetCommand();
///
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
std::string const getCommand() const { return p_.getCommand(); }
///
}
-DispatchResult InsetERT::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult InsetERT::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
return DispatchResult(true);
default:
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
void init();
#include "buffer.h"
#include "BufferView.h"
+#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "support/lyxlib.h"
#include "support/tostr.h"
#include "support/translator.h"
+#include "support/std_sstream.h"
#include <boost/bind.hpp>
-#include "support/std_sstream.h"
namespace support = lyx::support;
namespace external = lyx::external;
DispatchResult
-InsetExternal::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetExternal::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_EXTERNAL_EDIT: {
- Buffer const & buffer = *bv.buffer();
+ Buffer const & buffer = *cur.bv().buffer();
InsetExternalParams p;
InsetExternalMailer::string2params(cmd.argument, buffer, p);
external::editExternal(p, buffer);
}
case LFUN_INSET_MODIFY: {
- Buffer const & buffer = *bv.buffer();
+ Buffer const & buffer = *cur.bv().buffer();
InsetExternalParams p;
InsetExternalMailer::string2params(cmd.argument, buffer, p);
setParams(p, buffer);
- bv.update();
+ cur.bv().update();
return DispatchResult(true, true);
}
case LFUN_INSET_DIALOG_UPDATE:
- InsetExternalMailer(*this).updateDialog(&bv);
+ InsetExternalMailer(*this).updateDialog(&cur.bv());
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
- InsetExternalMailer(*this).showDialog(&bv);
+ InsetExternalMailer(*this).showDialog(&cur.bv());
return DispatchResult(true, true);
default:
}
-void InsetExternal::edit(BufferView * bv, bool)
+void InsetExternal::edit(LCursor & cur, bool)
{
- InsetExternalMailer(*this).showDialog(bv);
+ InsetExternalMailer(*this).showDialog(&cur.bv());
}
///
void addPreview(lyx::graphics::PreviewLoader &) const;
///
- void edit(BufferView * bv, bool);
+ void edit(LCursor & cur, bool);
protected:
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
#include "buffer.h"
#include "bufferparams.h"
#include "BufferView.h"
+#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "Floating.h"
#include "support/lstrings.h"
#include "support/tostr.h"
-
#include "support/std_sstream.h"
using lyx::support::contains;
DispatchResult
-InsetFloat::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetFloat::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
InsetFloatMailer::string2params(cmd.argument, params);
params_.placement = params.placement;
params_.wide = params.wide;
- wide(params_.wide, bv.buffer()->params());
- bv.update();
+ wide(params_.wide, cur.bv().buffer()->params());
+ cur.bv().update();
return DispatchResult(true, true);
}
case LFUN_INSET_DIALOG_UPDATE: {
- InsetFloatMailer(*this).updateDialog(&bv);
+ InsetFloatMailer(*this).updateDialog(&cur.bv());
return DispatchResult(true, true);
}
default:
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
}
}
protected:
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
InsetFloatParams params_;
#include "buffer.h"
#include "BufferView.h"
#include "converter.h"
+#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "format.h"
#include "support/os.h"
#include "support/systemcall.h"
#include "support/tostr.h"
+#include "support/std_sstream.h"
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>
-#include "support/std_sstream.h"
-
namespace support = lyx::support;
using lyx::support::AbsolutePath;
using lyx::support::bformat;
DispatchResult
-InsetGraphics::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
- Buffer const & buffer = *bv.buffer();
+ Buffer const & buffer = *cur.bv().buffer();
InsetGraphicsParams p;
InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
if (!p.filename.empty()) {
setParams(p);
- bv.update();
+ cur.bv().update();
}
return DispatchResult(true, true);
}
case LFUN_INSET_DIALOG_UPDATE:
- InsetGraphicsMailer(*this).updateDialog(&bv);
+ InsetGraphicsMailer(*this).updateDialog(&cur.bv());
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
- InsetGraphicsMailer(*this).showDialog(&bv);
+ InsetGraphicsMailer(*this).showDialog(&cur.bv());
return DispatchResult(true, true);
default:
}
-void InsetGraphics::edit(BufferView * bv, bool)
+void InsetGraphics::edit(LCursor & cur, bool)
{
- InsetGraphicsMailer(*this).showDialog(bv);
+ InsetGraphicsMailer(*this).showDialog(&cur.bv());
}
///
void draw(PainterInfo & pi, int x, int y) const;
///
- void edit(BufferView * bv, bool);
+ void edit(LCursor & cur, bool);
protected:
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
friend class InsetGraphicsMailer;
#include "bufferlist.h"
#include "bufferparams.h"
#include "BufferView.h"
+#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "funcrequest.h"
DispatchResult
-InsetInclude::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetInclude::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
InsetCommandParams p;
InsetIncludeMailer::string2params(cmd.argument, p);
if (!p.getCmdName().empty()) {
- set(p, *bv.buffer());
- bv.update();
+ set(p, *cur.bv().buffer());
+ cur.bv().update();
}
return DispatchResult(true, true);
}
case LFUN_INSET_DIALOG_UPDATE:
- InsetIncludeMailer(*this).updateDialog(&bv);
+ InsetIncludeMailer(*this).updateDialog(&cur.bv());
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
if (button_.box().contains(cmd.x, cmd.y))
- InsetIncludeMailer(*this).showDialog(&bv);
+ InsetIncludeMailer(*this).showDialog(&cur.bv());
return DispatchResult(true, true);
case LFUN_INSET_DIALOG_SHOW:
- InsetIncludeMailer(*this).showDialog(&bv);
+ InsetIncludeMailer(*this).showDialog(&cur.bv());
return DispatchResult(true, true);
default:
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
/// Slot receiving a signal that the preview is ready to display.
void statusChanged() const;
DispatchResult
-InsetLabel::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetLabel::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
return DispatchResult(false);
bool clean = true;
if (p.getContents() != params().getContents())
- clean = bv.ChangeRefsIfUnique(params().getContents(),
+ clean = cur.bv().ChangeRefsIfUnique(params().getContents(),
p.getContents());
setParams(p);
- bv.update();
+ cur.bv().update();
return DispatchResult(true, true);
}
default:
- return InsetCommand::priv_dispatch(bv, cmd);
+ return InsetCommand::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
};
#endif
#include "insetnote.h"
#include "BufferView.h"
+#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "funcrequest.h"
DispatchResult
-InsetNote::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetNote::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetNoteMailer::string2params(cmd.argument, params_);
setButtonLabel();
- bv.update();
+ cur.bv().update();
return DispatchResult(true, true);
}
case LFUN_INSET_DIALOG_UPDATE:
- InsetNoteMailer(*this).updateDialog(&bv);
+ InsetNoteMailer(*this).updateDialog(&cur.bv());
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
- InsetNoteMailer(*this).showDialog(&bv);
+ InsetNoteMailer(*this).showDialog(&cur.bv());
return DispatchResult(true, true);
}
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
default:
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
friend class InsetNoteParams;
DispatchResult
-InsetRef::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
// Eventually trigger dialog with button 3 not 1
if (cmd.button() == mouse_button::button3)
- bv.owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
+ cur.bv().owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
else
- InsetCommandMailer("ref", *this).showDialog(&bv);
+ InsetCommandMailer("ref", *this).showDialog(&cur.bv());
return DispatchResult(true, true);
default:
- return InsetCommand::priv_dispatch(bv, cmd);
+ return InsetCommand::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
bool isLatex;
}
-void InsetTabular::updateLocal(BufferView & bv) const
+void InsetTabular::updateLocal(LCursor & cur) const
{
- bv.update();
- resetPos(bv);
+ cur.bv().update();
+ resetPos(cur);
}
-extern LCursor theTempCursor;
+extern CursorBase theTempCursor;
-void InsetTabular::lfunMousePress(BufferView & bv, FuncRequest const & cmd)
+void InsetTabular::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
{
if (hasSelection() && cmd.button() == mouse_button::button3)
return;
lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl;
if (cell == -1) {
tablemode = true;
- bv.fullCursor(theTempCursor);
- bv.fullCursor().push(this);
- bv.fullCursor().idx() = cell;
+ cur.cursor_ = theTempCursor;
+ cur.push(this);
+ cur.idx() = cell;
} else {
tablemode = false;
- setPos(bv, cmd.x, cmd.y);
- bv.fullCursor(theTempCursor);
- bv.fullCursor().idx() = cell;
+ setPos(cur.bv(), cmd.x, cmd.y);
+ cur.cursor_ = theTempCursor;
+ cur.idx() = cell;
}
- lyxerr << bv.cursor() << endl;
+ cur.resetAnchor();
+ lyxerr << cur << endl;
if (cmd.button() == mouse_button::button2)
- dispatch(bv, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
+ dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
}
-void InsetTabular::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd)
+void InsetTabular::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
{
int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
lyxerr << "# InsetTabular::lfunMouseMotion cell: " << actcell << endl;
- setPos(bv, cmd.x, cmd.y);
+ setPos(cur.bv(), cmd.x, cmd.y);
if (!hasSelection()) {
setSelection(actcell, actcell);
- bv.setSelection();
+ cur.setSelection();
} else {
- bv.cursor().idx() = actcell;
+ cur.idx() = actcell;
setSelection(sel_cell_start, actcell);
tablemode = (sel_cell_start != actcell);
}
}
-void InsetTabular::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
+void InsetTabular::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
{
int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
lyxerr << "# InsetTabular::lfunMouseRelease cell: " << actcell << endl;
if (cmd.button() == mouse_button::button3)
- InsetTabularMailer(*this).showDialog(&bv);
+ InsetTabularMailer(*this).showDialog(&cur.bv());
}
-void InsetTabular::edit(BufferView * view, bool left)
+void InsetTabular::edit(LCursor & cur, bool left)
{
- BufferView & bv = *view;
lyxerr << "InsetTabular::edit: " << this << endl;
finishUndo();
//tablemode = false;
int cell;
if (left) {
- if (isRightToLeft(bv))
+ if (isRightToLeft(cur))
cell = tabular.getLastCellInRow(0);
else
cell = 0;
} else {
- if (isRightToLeft(bv))
+ if (isRightToLeft(cur))
cell = tabular.getFirstCellInRow(tabular.rows()-1);
else
cell = tabular.getNumberOfCells() - 1;
}
clearSelection();
- resetPos(bv);
- bv.fitCursor();
- bv.fullCursor().push(this);
- bv.fullCursor().idx() = cell;
- lyxerr << bv.cursor() << endl;
+ resetPos(cur);
+ cur.bv().fitCursor();
+ cur.push(this);
+ cur.idx() = cell;
}
-void InsetTabular::edit(BufferView * bv, int x, int y)
+void InsetTabular::edit(LCursor & cur, int x, int y)
{
lyxerr << "InsetTabular::edit: " << this << " first cell "
<< &tabular.cell_info[0][0].inset << endl;
finishUndo();
- setPos(*bv, x, y);
+ setPos(cur.bv(), x, y);
clearSelection();
finishUndo();
//int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
- bv->fullCursor().push(this);
+ cur.push(this);
//if (x > xx)
// activateCellInset(bv, cell, x - xx, y - cursory_);
}
DispatchResult
-InsetTabular::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
lyxerr << "# InsetTabular::dispatch: " << cmd
<< " tablemode: " << tablemode << endl;
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
- lfunMousePress(bv, cmd);
+ lfunMousePress(cur, cmd);
return DispatchResult(true, true);
case LFUN_MOUSE_MOTION:
- lfunMouseMotion(bv, cmd);
+ lfunMouseMotion(cur, cmd);
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
- lfunMouseRelease(bv, cmd);
+ lfunMouseRelease(cur, cmd);
return DispatchResult(true, true);
default:
break;
}
- CursorSlice & cur = bv.cursor();
-
if (!tablemode) {
- int cell = cur.idx_;
+ int cell = cur.idx();
lyxerr << "# InsetTabular::dispatch: A " << cur << endl;
- result = tabular.getCellInset(cell).dispatch(bv, cmd);
+ result = tabular.getCellInset(cell).dispatch(cur, cmd);
switch (result.val()) {
case FINISHED:
- if (movePrevCell(bv, cur))
+ if (movePrevCell(cur))
result = DispatchResult(true, true);
else
result = DispatchResult(false, FINISHED);
break;
case FINISHED_RIGHT:
- if (moveNextCell(bv, cur))
+ if (moveNextCell(cur))
result = DispatchResult(true, true);
else
result = DispatchResult(false, FINISHED_RIGHT);
break;
case FINISHED_UP:
- if (moveUpLock(bv, cur))
+ if (moveUpLock(cur))
result = DispatchResult(true, true);
else
result = DispatchResult(false, FINISHED_UP);
break;
case FINISHED_DOWN:
- if (moveDownLock(bv, cur))
+ if (moveDownLock(cur))
result = DispatchResult(true, true);
else
result = DispatchResult(false, FINISHED_UP);
case LFUN_CELL_BACKWARD:
case LFUN_CELL_FORWARD:
if (cmd.action == LFUN_CELL_FORWARD)
- moveNextCell(bv, cur);
+ moveNextCell(cur);
else
- movePrevCell(bv, cur);
+ movePrevCell(cur);
clearSelection();
return result;
case LFUN_SCROLL_INSET:
if (!cmd.argument.empty()) {
if (cmd.argument.find('.') != cmd.argument.npos)
- scroll(bv, static_cast<float>(strToDbl(cmd.argument)));
+ scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
else
- scroll(bv, strToInt(cmd.argument));
- bv.update();
+ scroll(cur.bv(), strToInt(cmd.argument));
+ cur.bv().update();
return DispatchResult(true, true);
}
case LFUN_RIGHTSEL: {
- int const start = hasSelection() ? sel_cell_start : cur.idx_;
- if (tabular.isLastCellInRow(cur.idx_)) {
- setSelection(start, cur.idx_);
+ int const start = hasSelection() ? sel_cell_start : cur.idx();
+ if (tabular.isLastCellInRow(cur.idx())) {
+ setSelection(start, cur.idx());
break;
}
- int end = cur.idx_;
+ int end = cur.idx();
// if we are starting a selection, only select
// the current cell at the beginning
if (hasSelection()) {
- moveRight(bv, cur);
- end = cur.idx_;
+ moveRight(cur);
+ end = cur.idx();
}
setSelection(start, end);
break;
}
case LFUN_RIGHT:
- if (!moveRightLock(bv, cur))
+ if (!moveRightLock(cur))
result = DispatchResult(false, FINISHED_RIGHT);
clearSelection();
break;
case LFUN_LEFTSEL: {
- int const start = hasSelection() ? sel_cell_start : cur.idx_;
- if (tabular.isFirstCellInRow(cur.idx_)) {
- setSelection(start, cur.idx_);
+ int const start = hasSelection() ? sel_cell_start : cur.idx();
+ if (tabular.isFirstCellInRow(cur.idx())) {
+ setSelection(start, cur.idx());
break;
}
- int end = cur.idx_;
+ int end = cur.idx();
// if we are starting a selection, only select
// the current cell at the beginning
if (hasSelection()) {
- moveLeft(bv, cur);
- end = cur.idx_;
+ moveLeft(cur);
+ end = cur.idx();
}
setSelection(start, end);
break;
}
case LFUN_LEFT:
- if (!moveLeftLock(bv, cur))
+ if (!moveLeftLock(cur))
result = DispatchResult(false, FINISHED);
clearSelection();
break;
case LFUN_DOWNSEL: {
- int const start = hasSelection() ? sel_cell_start : cur.idx_;
- int const ocell = cur.idx_;
+ int const start = hasSelection() ? sel_cell_start : cur.idx();
+ int const ocell = cur.idx();
// if we are starting a selection, only select
// the current cell at the beginning
if (hasSelection()) {
- moveDown(bv, cur);
+ moveDown(cur);
if (ocell == sel_cell_end ||
- tabular.column_of_cell(ocell) > tabular.column_of_cell(cur.idx_))
+ tabular.column_of_cell(ocell) >
+tabular.column_of_cell(cur.idx()))
setSelection(start, tabular.getCellBelow(sel_cell_end));
else
setSelection(start, tabular.getLastCellBelow(sel_cell_end));
}
case LFUN_DOWN:
- if (!moveDown(bv, cur))
+ if (!moveDown(cur))
result = DispatchResult(false, FINISHED_DOWN);
clearSelection();
break;
case LFUN_UPSEL: {
- int const start = hasSelection() ? sel_cell_start : cur.idx_;
- int const ocell = cur.idx_;
+ int const start = hasSelection() ? sel_cell_start : cur.idx();
+ int const ocell = cur.idx();
// if we are starting a selection, only select
// the current cell at the beginning
if (hasSelection()) {
- moveUp(bv, cur);
+ moveUp(cur);
if (ocell == sel_cell_end ||
- tabular.column_of_cell(ocell) > tabular.column_of_cell(cur.idx_))
+ tabular.column_of_cell(ocell) >
+tabular.column_of_cell(cur.idx()))
setSelection(start, tabular.getCellAbove(sel_cell_end));
else
setSelection(start, tabular.getLastCellAbove(sel_cell_end));
}
case LFUN_UP:
- if (!moveUp(bv, cur))
+ if (!moveUp(cur))
result = DispatchResult(false, FINISHED_DOWN);
clearSelection();
break;
case LFUN_NEXT: {
if (hasSelection())
clearSelection();
- int actcell = bv.cursor().idx();
+ int actcell = cur.idx();
int actcol = tabular.column_of_cell(actcell);
int column = actcol;
- if (bv.top_y() + bv.painter().paperHeight()
+ if (cur.bv().top_y() + cur.bv().painter().paperHeight()
< yo_ + tabular.getHeightOfTabular())
{
- bv.scrollDocView(bv.top_y() + bv.painter().paperHeight());
+ cur.bv().scrollDocView(
+ cur.bv().top_y() + cur.bv().painter().paperHeight());
cur.idx() = tabular.getCellBelow(first_visible_cell) + column;
} else {
cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
}
- resetPos(bv);
+ resetPos(cur);
break;
}
case LFUN_PRIOR: {
if (hasSelection())
clearSelection();
- int actcell = bv.cursor().idx();
- int actcol = tabular.column_of_cell(actcell);
- int column = actcol;
+ int column = tabular.column_of_cell(cur.idx());
if (yo_ < 0) {
- bv.scrollDocView(bv.top_y() - bv.painter().paperHeight());
+ cur.bv().scrollDocView(
+ cur.bv().top_y() - cur.bv().painter().paperHeight());
if (yo_ > 0)
cur.idx() = column;
else
} else {
cur.idx() = column;
}
- resetPos(bv);
+ resetPos(cur);
break;
}
break;
case LFUN_LAYOUT_TABULAR:
- InsetTabularMailer(*this).showDialog(&bv);
+ InsetTabularMailer(*this).showDialog(&cur.bv());
break;
case LFUN_INSET_DIALOG_UPDATE:
- InsetTabularMailer(*this).updateDialog(&bv);
+ InsetTabularMailer(*this).updateDialog(&cur.bv());
break;
case LFUN_TABULAR_FEATURE:
- if (!tabularFeatures(bv, cmd.argument))
+ if (!tabularFeatures(cur, cmd.argument))
result = DispatchResult(false);
break;
// insert file functions
case LFUN_FILE_INSERT_ASCII_PARA:
case LFUN_FILE_INSERT_ASCII: {
- string tmpstr = getContentsOfAsciiFile(&bv, cmd.argument, false);
- if (!tmpstr.empty() && !insertAsciiString(bv, tmpstr, false))
+ string tmpstr = getContentsOfAsciiFile(&cur.bv(), cmd.argument, false);
+ if (!tmpstr.empty() && !insertAsciiString(cur.bv(), tmpstr, false))
result = DispatchResult(false);
break;
}
break;
case LFUN_CUT:
- if (copySelection(bv)) {
- recordUndo(bv, Undo::DELETE);
- cutSelection(bv.buffer()->params());
+ if (copySelection(cur.bv())) {
+ recordUndo(cur, Undo::DELETE);
+ cutSelection(cur.bv().buffer()->params());
}
break;
case LFUN_DELETE:
- recordUndo(bv, Undo::DELETE);
- cutSelection(bv.buffer()->params());
+ recordUndo(cur, Undo::DELETE);
+ cutSelection(cur.bv().buffer()->params());
break;
case LFUN_COPY:
if (!hasSelection())
break;
finishUndo();
- copySelection(bv);
+ copySelection(cur.bv());
break;
case LFUN_PASTESELECTION: {
- string const clip = bv.getClipboard();
+ string const clip = cur.bv().getClipboard();
if (clip.empty())
break;
if (clip.find('\t') != string::npos) {
maxCols = max(cols, maxCols);
paste_tabular.reset(
- new LyXTabular(bv.buffer()->params(), rows, maxCols));
+ new LyXTabular(cur.bv().buffer()->params(), rows, maxCols));
string::size_type op = 0;
int cell = 0;
if (cell < cells && op < len)
paste_tabular->getCellInset(cell).
setText(clip.substr(op, len-op), font);
- } else if (!insertAsciiString(bv, clip, true))
+ } else if (!insertAsciiString(cur.bv(), clip, true))
{
// so that the clipboard is used and it goes on
// to default
case LFUN_PASTE:
if (hasPasteBuffer()) {
- recordUndo(bv, Undo::INSERT);
- pasteSelection(bv);
+ recordUndo(cur, Undo::INSERT);
+ pasteSelection(cur.bv());
break;
}
// fall through
break;
}
- updateLocal(bv);
- InsetTabularMailer(*this).updateDialog(&bv);
+ updateLocal(cur);
+ InsetTabularMailer(*this).updateDialog(&cur.bv());
}
if (cmd.action == LFUN_INSET_TOGGLE) {
cursorx_ = lx - tabular.getWidthOfColumn(actcell) + xo_ + 2;
#endif
- resetPos(bv);
+ resetPos(bv.cursor());
}
}
-void InsetTabular::resetPos(BufferView &) const
+void InsetTabular::resetPos(LCursor &) const
{
#if 0
#ifdef WITH_WARNINGS
if (in_reset_pos > 0)
return;
+ BufferView & bv = cur.bv();
int cell = 0;
- int actcell = bv->cursor().cell();
+ int actcell = cur.cell();
int actcol = tabular.column_of_cell(actcell);
int actrow = 0;
cursory_ = 0;
tabular.getWidthOfTabular() < bv->workWidth()-20)
{
scroll(bv, 0.0F);
- updateLocal(bv);
+ updateLocal(cur);
} else if (cursorx_ - offset > 20 &&
cursorx_ - offset + tabular.getWidthOfColumn(actcell)
> bv.workWidth() - 20) {
scroll(&bv, - tabular.getWidthOfColumn(actcell) - 20);
- updateLocal(bv);
+ updateLocal(cur);
} else if (cursorx_ - offset < 20) {
scroll(&bv, 20 - cursorx_ + offset);
- updateLocal(bv);
+ updateLocal(cur);
} else if (scroll() && xo_ > 20 &&
xo_ + tabular.getWidthOfTabular() > bv->workWidth() - 20) {
scroll(&bv, old_x - cursorx_);
- updateLocal(bv);
+ updateLocal(cur);
}
InsetTabularMailer(*this).updateDialog(bv);
in_reset_pos = 0;
}
-bool InsetTabular::moveRight(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveRight(LCursor & cur)
{
- bool moved = isRightToLeft(bv)
- ? movePrevCell(bv, cur) : moveNextCell(bv, cur);
+ bool moved = isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
if (!moved)
return false;
- resetPos(bv);
+ resetPos(cur);
return true;
}
-bool InsetTabular::moveRightLock(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveRightLock(LCursor & cur)
{
- bool moved = isRightToLeft(bv)
- ? movePrevCell(bv, cur) : moveNextCell(bv, cur);
+ bool moved = isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
if (!moved)
return false;
- activateCellInset(bv, cur.idx_, false);
+ activateCellInset(cur, cur.idx(), false);
return true;
}
-bool InsetTabular::moveLeft(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveLeft(LCursor & cur)
{
- bool moved = isRightToLeft(bv)
- ? moveNextCell(bv, cur) : movePrevCell(bv, cur);
+ bool moved = isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
if (!moved)
return false;
- resetPos(bv);
+ resetPos(cur);
return true;
}
-bool InsetTabular::moveLeftLock(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveLeftLock(LCursor & cur)
{
- bool moved = isRightToLeft(bv)
- ? moveNextCell(bv, cur) : movePrevCell(bv, cur);
+ bool moved = isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
if (!moved)
return false;
- activateCellInset(bv, cur.idx_, true);
+ activateCellInset(cur, cur.idx(), true);
return true;
}
-bool InsetTabular::moveUp(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveUp(LCursor & cur)
{
- if (tabular.row_of_cell(cur.idx_) == 0)
+ if (tabular.row_of_cell(cur.idx()) == 0)
return false;
- cur.idx_ = tabular.getCellAbove(cur.idx_);
- resetPos(bv);
+ cur.idx() = tabular.getCellAbove(cur.idx());
+ resetPos(cur);
return true;
}
-bool InsetTabular::moveUpLock(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveUpLock(LCursor & cur)
{
- if (tabular.row_of_cell(cur.idx_) == 0)
+ if (tabular.row_of_cell(cur.idx()) == 0)
return false;
- cur.idx_ = tabular.getCellAbove(cur.idx_);
- resetPos(bv);
- activateCellInset(bv, cur.idx_, bv.x_target(), 0);
+ cur.idx() = tabular.getCellAbove(cur.idx());
+ resetPos(cur);
+ activateCellInset(cur, cur.idx(), cur.x_target(), 0);
return true;
}
-bool InsetTabular::moveDown(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveDown(LCursor & cur)
{
- if (tabular.row_of_cell(cur.idx_) == tabular.rows() - 1)
+ if (tabular.row_of_cell(cur.idx()) == tabular.rows() - 1)
return false;
- cur.idx_ = tabular.getCellBelow(cur.idx_);
- resetPos(bv);
+ cur.idx() = tabular.getCellBelow(cur.idx());
+ resetPos(cur);
return true;
}
-bool InsetTabular::moveDownLock(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveDownLock(LCursor & cur)
{
- if (tabular.row_of_cell(cur.idx_) == tabular.rows() - 1)
+ if (tabular.row_of_cell(cur.idx()) == tabular.rows() - 1)
return false;
- cur.idx_ = tabular.getCellBelow(cur.idx_);
- resetPos(bv);
- activateCellInset(bv, cur.idx_, bv.x_target());
+ cur.idx() = tabular.getCellBelow(cur.idx());
+ resetPos(cur);
+ activateCellInset(cur, cur.idx(), cur.x_target());
return true;
}
-bool InsetTabular::moveNextCell(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::moveNextCell(LCursor & cur)
{
lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur << endl;
- if (isRightToLeft(bv)) {
- if (tabular.isFirstCellInRow(cur.idx_)) {
- int row = tabular.row_of_cell(cur.idx_);
+ if (isRightToLeft(cur)) {
+ if (tabular.isFirstCellInRow(cur.idx())) {
+ int row = tabular.row_of_cell(cur.idx());
if (row == tabular.rows() - 1)
return false;
- cur.idx_ = tabular.getLastCellInRow(row);
- cur.idx_ = tabular.getCellBelow(cur.idx_);
+ cur.idx() = tabular.getLastCellInRow(row);
+ cur.idx() = tabular.getCellBelow(cur.idx());
} else {
- if (cur.idx_ == 0)
+ if (cur.idx() == 0)
return false;
- --cur.idx_;
+ --cur.idx();
}
} else {
- if (tabular.isLastCell(cur.idx_))
+ if (tabular.isLastCell(cur.idx()))
return false;
- ++cur.idx_;
+ ++cur.idx();
}
- cur.par_ = 0;
- cur.pos_ = 0;
+ cur.par() = 0;
+ cur.pos() = 0;
lyxerr << "InsetTabular::moveNextCell 2 cur: " << cur << endl;
- resetPos(bv);
+ resetPos(cur);
return true;
}
-bool InsetTabular::movePrevCell(BufferView & bv, CursorSlice & cur)
+bool InsetTabular::movePrevCell(LCursor & cur)
{
- if (isRightToLeft(bv)) {
- if (tabular.isLastCellInRow(cur.idx_)) {
- int row = tabular.row_of_cell(cur.idx_);
+ if (isRightToLeft(cur)) {
+ if (tabular.isLastCellInRow(cur.idx())) {
+ int row = tabular.row_of_cell(cur.idx());
if (row == 0)
return false;
- cur.idx_ = tabular.getFirstCellInRow(row);
- cur.idx_ = tabular.getCellAbove(cur.idx_);
+ cur.idx() = tabular.getFirstCellInRow(row);
+ cur.idx() = tabular.getCellAbove(cur.idx());
} else {
- if (tabular.isLastCell(cur.idx_))
+ if (tabular.isLastCell(cur.idx()))
return false;
- ++cur.idx_;
+ ++cur.idx();
}
} else {
- if (cur.idx_ == 0) // first cell
+ if (cur.idx() == 0) // first cell
return false;
- --cur.idx_;
+ --cur.idx();
}
- cur.par_ = 0;
- cur.pos_ = 0;
- resetPos(bv);
+ cur.par() = 0;
+ cur.pos() = 0;
+ resetPos(cur);
return true;
}
-bool InsetTabular::tabularFeatures(BufferView & bv, string const & what)
+bool InsetTabular::tabularFeatures(LCursor & cur, std::string const & what)
{
LyXTabular::Feature action = LyXTabular::LAST_ACTION;
string const val =
ltrim(what.substr(tabularFeature[i].feature.length()));
- tabularFeatures(bv, action, val);
+ tabularFeatures(cur, action, val);
return true;
}
} // anon namespace
-void InsetTabular::tabularFeatures(BufferView & bv,
+void InsetTabular::tabularFeatures(LCursor & cur,
LyXTabular::Feature feature, string const & value)
{
- int actcell = bv.cursor().idx();
+ BufferView & bv = cur.bv();
+ int actcell = cur.idx();
int sel_col_start;
int sel_col_end;
int sel_row_start;
sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
}
- recordUndo(bv, Undo::ATOMIC);
+ recordUndo(cur, Undo::ATOMIC);
int row = tabular.row_of_cell(actcell);
int column = tabular.column_of_cell(actcell);
tabular.setColumnPWidth(actcell, len);
if (len.zero()
&& tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
- tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
+ tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string());
else if (!len.zero()
&& tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
- tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
+ tabularFeatures(cur, LyXTabular::ALIGN_BLOCK, string());
break;
}
break;
}
- updateLocal(bv);
+ updateLocal(cur);
InsetTabularMailer(*this).updateDialog(&bv);
}
-void InsetTabular::activateCellInset(BufferView & bv, int cell, int x, int y)
+void InsetTabular::activateCellInset(LCursor & cur, int cell, int x, int y)
{
- tabular.getCellInset(cell).edit(&bv, x, y);
- bv.cursor().idx(cell);
- updateLocal(bv);
+ tabular.getCellInset(cell).edit(cur, x, y);
+ cur.idx() = cell;
+ updateLocal(cur);
}
-void InsetTabular::activateCellInset(BufferView & bv, int cell, bool behind)
+void InsetTabular::activateCellInset(LCursor & cur, int cell, bool behind)
{
- tabular.getCellInset(cell).edit(&bv, behind);
- bv.cursor().idx(cell);
- updateLocal(bv);
+ tabular.getCellInset(cell).edit(cur, behind);
+ cur.idx() = cell;
+ updateLocal(cur);
}
}
-bool InsetTabular::isRightToLeft(BufferView & bv)
+bool InsetTabular::isRightToLeft(LCursor & cur)
{
- return bv.getParentLanguage(this)->RightToLeft();
+ return cur.bv().getParentLanguage(this)->RightToLeft();
}
///
std::string const editMessage() const;
///
- void updateLocal(BufferView & bv) const;
+ void updateLocal(LCursor & cur) const;
///
bool insetAllowed(InsetOld::Code) const { return true; }
///
/// get the absolute screen x,y of the cursor
void getCursorPos(int cell, int & x, int & y) const;
///
- bool tabularFeatures(BufferView & bv, std::string const & what);
+ bool tabularFeatures(LCursor & cur, std::string const & what);
///
- void tabularFeatures(BufferView & bv, LyXTabular::Feature feature,
+ void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
std::string const & val = std::string());
///
void openLayoutDialog(BufferView *) const;
/// set the owning buffer
void buffer(Buffer * buf);
/// lock cell with given index
- void edit(BufferView * bv, bool);
+ void edit(LCursor & cur, bool);
///
- void edit(BufferView * bv, int, int);
+ void edit(LCursor & cur, int, int);
/// can we go further down on mouse click?
bool descendable() const { return true; }
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
- void lfunMousePress(BufferView & bv, FuncRequest const & cmd);
+ void lfunMousePress(LCursor & cur, FuncRequest const & cmd);
///
- void lfunMouseRelease(BufferView & bv, FuncRequest const & cmd);
+ void lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
///
- void lfunMouseMotion(BufferView & bv, FuncRequest const & cmd);
+ void lfunMouseMotion(LCursor & cur, FuncRequest const & cmd);
///
void calculate_dimensions_of_cells(MetricsInfo & mi) const;
///
///
void setPos(BufferView &, int x, int y) const;
///
- bool moveRight(BufferView &, CursorSlice & cur);
+ bool moveRight(LCursor & cur);
///
- bool moveLeft(BufferView &, CursorSlice & cur);
+ bool moveLeft(LCursor & cur);
///
- bool moveUp(BufferView &, CursorSlice & cur);
+ bool moveUp(LCursor & cur);
///
- bool moveDown(BufferView &, CursorSlice & cur);
+ bool moveDown(LCursor & cur);
///
- bool moveRightLock(BufferView &, CursorSlice & cur);
+ bool moveRightLock(LCursor & cur);
///
- bool moveLeftLock(BufferView &, CursorSlice & cur);
+ bool moveLeftLock(LCursor & cur);
///
- bool moveUpLock(BufferView &, CursorSlice & cur);
+ bool moveUpLock(LCursor & cur);
///
- bool moveDownLock(BufferView &, CursorSlice & cur);
+ bool moveDownLock(LCursor & cur);
///
- bool moveNextCell(BufferView &, CursorSlice & cur);
+ bool moveNextCell(LCursor & cur);
///
- bool movePrevCell(BufferView &, CursorSlice & cur);
+ bool movePrevCell(LCursor & cur);
///
int getCellXPos(int cell) const;
///
- void resetPos(BufferView &) const;
+ void resetPos(LCursor & cur) const;
///
void removeTabularRow();
///
///
void setSelection(int start, int end) const;
///
- void activateCellInset(BufferView &, int cell, int x, int y);
+ void activateCellInset(LCursor &, int cell, int x, int y);
///
- void activateCellInset(BufferView &, int cell, bool behind);
+ void activateCellInset(LCursor &, int cell, bool behind);
///
bool hasPasteBuffer() const;
///
///
bool cutSelection(BufferParams const & bp);
///
- bool isRightToLeft(BufferView &);
+ bool isRightToLeft(LCursor & cur);
///
void getSelection(int cell,
int & scol, int & ecol, int & srow, int & erow) const;
}
-void InsetText::updateLocal(BufferView * bv)
-{
- if (!bv)
- return;
-
- if (!autoBreakRows_ && paragraphs().size() > 1)
- collapseParagraphs(bv);
+void InsetText::updateLocal(LCursor & cur)
+{
+ if (!autoBreakRows_ && paragraphs().size() > 1) {
+ // collapseParagraphs
+ while (paragraphs().size() > 1) {
+ ParagraphList::iterator const first = paragraphs().begin();
+ ParagraphList::iterator second = first;
+ ++second;
+ size_t const first_par_size = first->size();
+
+ if (!first->empty() &&
+ !second->empty() &&
+ !first->isSeparator(first_par_size - 1)) {
+ first->insertChar(first_par_size, ' ');
+ }
+
+ cur.clearSelection();
+ mergeParagraph(cur.bv().buffer()->params(), paragraphs(), first);
+ }
+ }
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
- bv->owner()->view_state_changed();
- bv->owner()->updateMenubar();
- bv->owner()->updateToolbar();
- if (old_par != bv->cursor().par()) {
- bv->owner()->setLayout(text_.cursorPar()->layout()->name());
- old_par = bv->cursor().par();
+ LyXView * lv = cur.bv().owner();
+ lv->view_state_changed();
+ lv->updateMenubar();
+ lv->updateToolbar();
+ if (old_par != cur.par()) {
+ lv->setLayout(text_.cursorPar()->layout()->name());
+ old_par = cur.par();
}
}
}
-void InsetText::sanitizeEmptyText(BufferView * bv)
+void InsetText::sanitizeEmptyText(BufferView & bv)
{
if (paragraphs().size() == 1
&& paragraphs().begin()->empty()
- && bv->getParentLanguage(this) != text_.current_font.language()) {
+ && bv.getParentLanguage(this) != text_.current_font.language()) {
LyXFont font(LyXFont::ALL_IGNORE);
- font.setLanguage(bv->getParentLanguage(this));
+ font.setLanguage(bv.getParentLanguage(this));
text_.setFont(font, false);
}
}
-extern LCursor theTempCursor;
+extern CursorBase theTempCursor;
-void InsetText::edit(BufferView * bv, bool left)
+void InsetText::edit(LCursor & cur, bool left)
{
lyxerr << "InsetText: edit left/right" << endl;
old_par = -1;
- setViewCache(bv);
+ setViewCache(&cur.bv());
int const par = left ? 0 : paragraphs().size() - 1;
int const pos = left ? 0 : paragraphs().back().size();
text_.setCursor(par, pos);
- bv->clearSelection();
+ cur.clearSelection();
finishUndo();
- sanitizeEmptyText(bv);
- updateLocal(bv);
- bv->updateParagraphDialog();
+ sanitizeEmptyText(cur.bv());
+ updateLocal(cur);
+ cur.bv().updateParagraphDialog();
}
-void InsetText::edit(BufferView * bv, int x, int y)
+void InsetText::edit(LCursor & cur, int x, int y)
{
lyxerr << "InsetText::edit xy" << endl;
old_par = -1;
- text_.setCursorFromCoordinates(x - text_.xo_, y + bv->top_y() - text_.yo_);
- bv->clearSelection();
+ text_.setCursorFromCoordinates(x - text_.xo_, y + cur.bv().top_y() - text_.yo_);
+ cur.clearSelection();
finishUndo();
- sanitizeEmptyText(bv);
- updateLocal(bv);
- bv->updateParagraphDialog();
+ sanitizeEmptyText(cur.bv());
+ updateLocal(cur);
+ cur.bv().updateParagraphDialog();
}
-DispatchResult
-InsetText::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult InsetText::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "InsetText::priv_dispatch (begin), act: "
// << cmd.action << " " << endl;
- setViewCache(&bv);
+ setViewCache(&cur.bv());
DispatchResult result;
result.dispatched(true);
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
- bv.fullCursor(theTempCursor);
- // fall through
+ cur.cursor_ = theTempCursor;
+ cur.resetAnchor();
+ result = text_.dispatch(cur, cmd);
+ break;
+
default:
- result = text_.dispatch(bv, cmd);
+ result = text_.dispatch(cur, cmd);
break;
}
if (!was_empty && paragraphs().begin()->empty() &&
paragraphs().size() == 1) {
LyXFont font(LyXFont::ALL_IGNORE);
- font.setLanguage(bv.getParentLanguage(this));
+ font.setLanguage(cur.bv().getParentLanguage(this));
text_.setFont(font, false);
}
}
-void InsetText::collapseParagraphs(BufferView * bv)
-{
- while (paragraphs().size() > 1) {
- ParagraphList::iterator const first = paragraphs().begin();
- ParagraphList::iterator second = first;
- ++second;
- size_t const first_par_size = first->size();
-
- if (!first->empty() &&
- !second->empty() &&
- !first->isSeparator(first_par_size - 1)) {
- first->insertChar(first_par_size, ' ');
- }
-
- bv->clearSelection();
- mergeParagraph(bv->buffer()->params(), paragraphs(), first);
- }
-}
-
-
void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
{
#warning FIXME Check if Changes stuff needs changing here. (Lgb)
void addPreview(lyx::graphics::PreviewLoader &) const;
///
- void edit(BufferView *, bool);
+ void edit(LCursor & cur, bool);
///
- void edit(BufferView *, int, int);
+ void edit(LCursor & cur, int, int);
///
int numParagraphs() const { return 1; }
private:
///
- DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
- void updateLocal(BufferView *);
+ void updateLocal(LCursor &);
///
void init();
// If the inset is empty set the language of the current font to the
// language to the surronding text (if different).
- void sanitizeEmptyText(BufferView *);
+ void sanitizeEmptyText(BufferView &);
///
void setCharFont(Buffer const &, int pos, LyXFont const & font);
///
void drawFrame(Painter &, int x) const;
///
void clearInset(Painter &, int x, int y) const;
- ///
- void collapseParagraphs(BufferView *);
/* Private structures and variables */
///
#include "buffer.h"
#include "BufferView.h"
+#include "cursor.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "gettext.h"
DispatchResult
-InsetVSpace::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetVSpace::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
}
case LFUN_MOUSE_PRESS:
- InsetVSpaceMailer(*this).showDialog(&bv);
+ InsetVSpaceMailer(*this).showDialog(&cur.bv());
return DispatchResult(true, true);
default:
- return InsetOld::priv_dispatch(bv, cmd);
+ return InsetOld::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
#include "buffer.h"
#include "bufferparams.h"
#include "BufferView.h"
+#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "Floating.h"
DispatchResult
-InsetWrap::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetWrap::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
params_.placement = params.placement;
params_.width = params.width;
- bv.update();
+ cur.bv().update();
return DispatchResult(true, true);
}
case LFUN_INSET_DIALOG_UPDATE:
- InsetWrapMailer(*this).updateDialog(&bv);
+ InsetWrapMailer(*this).updateDialog(&cur.bv());
return DispatchResult(true, true);
default:
- return InsetCollapsable::priv_dispatch(bv, cmd);
+ return InsetCollapsable::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
InsetWrapParams params_;
#include "updatableinset.h"
#include "BufferView.h"
+#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
#include "funcrequest.h"
/// An updatable inset could handle lyx editing commands
DispatchResult
-UpdatableInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+UpdatableInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_MOUSE_RELEASE:
case LFUN_SCROLL_INSET:
if (!cmd.argument.empty()) {
if (cmd.argument.find('.') != cmd.argument.npos)
- scroll(bv, static_cast<float>(strToDbl(cmd.argument)));
+ scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
else
- scroll(bv, strToInt(cmd.argument));
- bv.update();
+ scroll(cur.bv(), strToInt(cmd.argument));
+ cur.bv().update();
return DispatchResult(true, true);
}
/// An updatable inset could handle lyx editing commands
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
/// scrolls to absolute position in bufferview-workwidth * sx units
void scroll(BufferView &, float sx) const;
/// scrolls offset pixels
void ParIterator::lockPath(BufferView * bv) const
{
- bv->fullCursor() = LCursor(*bv);
+ LCursor & cur = bv->cursor();
+ cur.cursor_.clear();
for (int i = 0, last = size() - 1; i < last; ++i)
- (*pimpl_->positions[i].it)->inset->edit(bv, true);
+ (*pimpl_->positions[i].it)->inset->edit(cur, true);
+ cur.resetAnchor();
}
#include "buffer.h"
#include "bufferlist.h"
#include "BufferView.h"
+#include "cursor.h"
#include "debug.h"
#include "gettext.h"
#include "lastfiles.h"
// clear the selection
if (bv->text() == bv->getLyXText())
- bv->clearSelection();
+ bv->cursor().clearSelection();
if (asParagraph)
bv->getLyXText()->insertStringAsParagraphs(tmpstr);
else
#include "lyxfind.h"
#include "buffer.h"
-#include "cursor_slice.h"
+#include "cursor.h"
#include "BufferView.h"
#include "debug.h"
#include "iterators.h"
text->replaceSelectionWithString(replacestr);
text->setSelectionRange(replacestr.length());
- bv->cursor() = fw ? bv->selEnd() : bv->selStart();
+ bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selStart();
bv->buffer()->markDirty();
find(bv, searchstr, cs, mw, fw);
bv->update();
// actions
keyseq.clear();
// copied verbatim from do_accent_char
- view()->resetAnchor();
+ view()->cursor().resetAnchor();
view()->update();
}
}
}
- UpdatableInset * tli = view()->fullCursor().innerInset();
- InsetTabular * tab = view()->fullCursor().innerInsetTabular();
+ UpdatableInset * tli = view()->cursor().inset()
+ ? view()->cursor().inset()->asUpdatableInset() : 0;
+ InsetTabular * tab = view()->cursor().innerInsetTabular();
// I would really like to avoid having this switch and rather try to
// encode this in the function itself.
if (tab && tab->hasSelection())
disable = false;
else
- disable = !mathcursor && !view()->selection().set();
+ disable = !inMathed() && !view()->cursor().selection();
break;
case LFUN_RUNCHKTEX:
break;
case LFUN_LAYOUT_TABULAR:
- disable = !view()->fullCursor().innerInsetTabular();
+ disable = !view()->cursor().innerInsetTabular();
break;
case LFUN_DEPTH_MIN:
case LFUN_TABULAR_FEATURE:
#if 0
- if (mathcursor) {
+ if (inMathed()) {
// FIXME: check temporarily disabled
// valign code
- char align = mathcursor->valign();
+ char align = mathcursor::valign();
if (align == '\0') {
disable = true;
break;
} else {
disable = true;
- char align = mathcursor->halign();
+ char align = mathcursor::halign();
if (align == '\0') {
disable = true;
break;
}
flag.setOnOff(ev.argument[0] == align);
- disable = !mathcursor->halign();
+ disable = !mathcursor::halign();
break;
}
case LFUN_INSET_SETTINGS: {
disable = true;
- UpdatableInset * inset = view()->fullCursor().innerInset();
+ UpdatableInset * inset = view()->cursor().inset()
+ ? view()->cursor().inset()->asUpdatableInset() : 0;
if (!inset)
break;
}
case LFUN_MATH_MUTATE:
- if (mathcursor)
- //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
+ if (inMathed())
+ //flag.setOnOff(mathcursor::formula()->hullType() == ev.argument);
flag.setOnOff(false);
else
disable = true;
case LFUN_MATH_NONUMBER:
case LFUN_MATH_NUMBER:
case LFUN_MATH_EXTERN:
- disable = !mathcursor;
+ disable = !inMathed();
break;
case LFUN_DIALOG_SHOW: {
disable = !Exporter::IsExportable(*buf, "dvi") ||
lyxrc.print_command == "none";
} else if (name == "character") {
- UpdatableInset * tli = view()->fullCursor().innerInset();
- disable = tli && tli->lyxCode() == InsetOld::ERT_CODE;
+ InsetBase * inset = view()->cursor().inset();
+ disable = inset && inset->lyxCode() == InsetOld::ERT_CODE;
} else if (name == "vclog") {
disable = !buf->lyxvc().inUse();
} else if (name == "latexlog") {
break;
case LFUN_SPACE_INSERT:
// slight hack: we know this is allowed in math mode
- if (!mathcursor)
+ if (!inMathed())
code = InsetOld::SPACE_CODE;
break;
case LFUN_INSET_DIALOG_SHOW: {
#ifdef LOCK
// the font related toggles
- if (!mathcursor) {
+ if (!inMathed()) {
LyXFont const & font = view()->getLyXText()->real_current_font;
switch (ev.action) {
case LFUN_EMPH:
break;
}
} else {
- string tc = mathcursor->getLastCode();
+ string tc = mathcursor::getLastCode();
switch (ev.action) {
case LFUN_BOLD:
flag.setOnOff(tc == "mathbf");
case LFUN_ESCAPE: {
if (!view()->available())
break;
- view()->fullCursor().pop();
+ view()->cursor().pop();
// Tell the paragraph dialog that we changed paragraph
dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
break;
break;
case LFUN_LAYOUT_TABULAR:
- if (InsetTabular * tab = view()->fullCursor().innerInsetTabular())
+ if (InsetTabular * tab = view()->cursor().innerInsetTabular())
tab->openLayoutDialog(view());
break;
case LFUN_INSET_DIALOG_SHOW: {
InsetOld * inset = view()->getLyXText()->getInset();
if (inset)
- inset->dispatch(*view(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
+ inset->dispatch(view()->cursor(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
break;
}
InsetBase * inset = owner->getDialogs().getOpenInset(name);
if (inset) {
FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, func.argument);
- inset->dispatch(*view(), fr);
+ inset->dispatch(view()->cursor(), fr);
} else if (name == "paragraph") {
dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
}
break;
case LFUN_EXTERNAL_EDIT:
- InsetExternal().dispatch(*view(), FuncRequest(action, argument));
+ InsetExternal().dispatch(view()->cursor(), FuncRequest(action, argument));
break;
default:
- view()->fullCursor().dispatch(FuncRequest(func));
+ view()->cursor().dispatch(FuncRequest(func));
break;
}
}
if (view()->available()) {
view()->fitCursor();
view()->update();
- view()->fullCursor().updatePos();
+ view()->cursor().updatePos();
// if we executed a mutating lfun, mark the buffer as dirty
if (!getStatus(func).disabled()
&& !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
void draw(PainterInfo & pi, int x, int y) const;
/// try to handle that request
- DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd);
+ DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
BufferView * bv();
+2004-01-15 André Pönitz <poenitz@gmx.net>
+
+ * *.[Ch]: Part of IU. Shift stuff from MathCursor and InsetFormula
+ to LCursor and InsetBase.
2004-01-15 André Pönitz <poenitz@gmx.net>
DispatchResult
-CommandInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+CommandInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
{
switch (cmd.action) {
default:
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
std::string name_;
mutable bool set_label_;
using std::endl;
-InsetFormula::InsetFormula(bool chemistry)
+InsetFormula::InsetFormula()
: par_(MathAtom(new MathHullInset)),
preview_(new RenderPreview)
{
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
- if (chemistry)
- mutate("chemistry");
}
}
-InsetFormula::InsetFormula(BufferView *)
- : par_(MathAtom(new MathHullInset)),
- preview_(new RenderPreview)
-{
- preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
-}
-
-
InsetFormula::InsetFormula(string const & data)
: par_(MathAtom(new MathHullInset)),
preview_(new RenderPreview)
bool editing_inset(InsetFormula const * inset)
{
- return mathcursor &&
- (const_cast<InsetFormulaBase const *>(mathcursor->formula()) ==
+ return inMathed() &&
+ (const_cast<InsetFormulaBase const *>(mathcursor::formula()) ==
inset);
}
p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
if (editing_inset(this)) {
- mathcursor->drawSelection(pi);
+ mathcursor::drawSelection(pi);
//p.pain.rectangle(x, y - a, w, h, LColor::mathframe);
}
class InsetFormula : public InsetFormulaBase {
public:
///
- InsetFormula(bool chemistry = false);
- ///
- explicit InsetFormula(BufferView *);
+ InsetFormula();
///
explicit InsetFormula(std::string const & data);
///
using std::ostringstream;
-MathCursor * mathcursor = 0;
-
namespace {
// local global
int first_x;
int first_y;
-bool openNewInset(BufferView & bv, UpdatableInset * inset)
+bool openNewInset(LCursor & cur, UpdatableInset * inset)
{
- if (!bv.insertInset(inset)) {
+ if (!cur.bv().insertInset(inset)) {
delete inset;
return false;
}
- inset->edit(&bv, true);
+ inset->edit(cur, true);
return true;
}
{
// this whole function is a hack and won't work for incremental font
// changes...
- recordUndo(cur.bv(), Undo::ATOMIC);
+ recordUndo(cur, Undo::ATOMIC);
if (cur.inset()->asMathInset()->name() == font)
- mathcursor->handleFont(cur, font);
+ mathcursor::handleFont(cur, font);
else {
- mathcursor->handleNest(cur, createMathInset(font));
- mathcursor->insert(cur, arg);
+ mathcursor::handleNest(cur, createMathInset(font));
+ mathcursor::insert(cur, arg);
}
}
void InsetFormulaBase::handleFont2(LCursor & cur, string const & arg)
{
- recordUndo(cur.bv(), Undo::ATOMIC);
+ recordUndo(cur, Undo::ATOMIC);
LyXFont font;
bool b;
bv_funcs::string2font(arg, font, b);
if (font.color() != LColor::inherit) {
MathAtom at = createMathInset("color");
asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
- mathcursor->handleNest(cur, at, 1);
+ mathcursor::handleNest(cur, at, 1);
}
}
void InsetFormulaBase::insetUnlock(BufferView & bv)
{
- if (mathcursor) {
- if (mathcursor->inMacroMode(bv.fullCursor()))
- mathcursor->macroModeClose(bv.fullCursor());
- releaseMathCursor(bv);
+ if (inMathed()) {
+ if (mathcursor::inMacroMode(bv.cursor()))
+ mathcursor::macroModeClose(bv.cursor());
+ releaseMathCursor(bv.cursor());
}
if (bv.buffer())
generatePreview(*bv.buffer());
void InsetFormulaBase::getCursorPos(BufferView & bv, int & x, int & y) const
{
- if (mathcursor) {
- mathcursor->getScreenPos(bv.fullCursor(), x, y);
- x = mathcursor->targetX(bv.fullCursor());
+ if (inMathed()) {
+ mathcursor::getScreenPos(bv.cursor(), x, y);
+ x = mathcursor::targetX(bv.cursor());
x -= xo_;
y -= yo_;
lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl;
void InsetFormulaBase::getCursorDim(int & asc, int & desc) const
{
- if (mathcursor) {
+ if (inMathed()) {
asc = 10;
desc = 2;
//math_font_max_dim(font_, asc, des);
DispatchResult
-InsetFormulaBase::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
+InsetFormulaBase::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
{
- if (!mathcursor)
+ if (!inMathed())
return DispatchResult(false);
- bv.update();
+ cur.bv().update();
//lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
if (cmd.button() == mouse_button::button3) {
// try to dispatch to enclosed insets first
- if (!mathcursor->dispatch(bv.fullCursor(), cmd).dispatched()) {
+ if (!mathcursor::dispatch(cur, cmd).dispatched()) {
// launch math panel for right mouse button
lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl;
- bv.owner()->getDialogs().show("mathpanel");
+ cur.bv().owner()->getDialogs().show("mathpanel");
}
return DispatchResult(true, true);
}
if (cmd.button() == mouse_button::button2) {
MathArray ar;
- asArray(bv.getClipboard(), ar);
- mathcursor->selClear(bv.fullCursor());
- mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_);
- mathcursor->insert(bv.fullCursor(), ar);
- bv.update();
+ asArray(cur.bv().getClipboard(), ar);
+ mathcursor::selClear(cur);
+ mathcursor::setScreenPos(cur, cmd.x + xo_, cmd.y + yo_);
+ mathcursor::insert(cur, ar);
+ cur.bv().update();
return DispatchResult(true, true);
}
if (cmd.button() == mouse_button::button1) {
// try to dispatch to enclosed insets first
- mathcursor->dispatch(bv.fullCursor(), cmd);
- bv.stuffClipboard(mathcursor->grabSelection(bv.fullCursor()));
+ mathcursor::dispatch(cur, cmd);
+ cur.bv().stuffClipboard(mathcursor::grabSelection(cur));
// try to set the cursor
//delete mathcursor;
//mathcursor = new MathCursor(bv, this, x == 0);
//metrics(bv);
- //mathcursor->setScreenPos(x + xo_, y + yo_);
+ //mathcursor::setScreenPos(x + xo_, y + yo_);
return DispatchResult(true, true);
}
DispatchResult
-InsetFormulaBase::lfunMousePress(BufferView & bv, FuncRequest const & cmd)
+InsetFormulaBase::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
- if (!mathcursor || mathcursor->formula() != this) {
+ if (!inMathed() || mathcursor::formula() != this) {
lyxerr[Debug::MATHED] << "re-create cursor" << endl;
- releaseMathCursor(bv);
- mathcursor = new MathCursor(&bv, this, cmd.x == 0);
+ releaseMathCursor(cur);
+ mathcursor::formula_ = this;
+ cur.idx() = 0;
//metrics(bv);
- mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_);
+ mathcursor::setScreenPos(cur, cmd.x + xo_, cmd.y + yo_);
}
if (cmd.button() == mouse_button::button3) {
- mathcursor->dispatch(bv.fullCursor(), cmd);
+ mathcursor::dispatch(cur, cmd);
return DispatchResult(true, true);
}
if (cmd.button() == mouse_button::button1) {
first_x = cmd.x;
first_y = cmd.y;
- mathcursor->selClear(bv.fullCursor());
- mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_);
- mathcursor->dispatch(bv.fullCursor(), cmd);
+ mathcursor::selClear(cur);
+ mathcursor::setScreenPos(cur, cmd.x + xo_, cmd.y + yo_);
+ mathcursor::dispatch(cur, cmd);
return DispatchResult(true, true);
}
- bv.update();
+ cur.bv().update();
return DispatchResult(true, true);
}
DispatchResult
-InsetFormulaBase::lfunMouseMotion(BufferView & bv, FuncRequest const & cmd)
+InsetFormulaBase::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
{
- if (!mathcursor)
+ if (!inMathed())
return DispatchResult(true, true);
- if (mathcursor->dispatch(bv.fullCursor(), FuncRequest(cmd)).dispatched())
+ if (mathcursor::dispatch(cur, FuncRequest(cmd)).dispatched())
return DispatchResult(true, true);
// only select with button 1
first_x = cmd.x;
first_y = cmd.y;
- if (!mathcursor->selection())
- mathcursor->selStart(bv.fullCursor());
+ if (!cur.selection())
+ mathcursor::selStart(cur);
- mathcursor->setScreenPos(bv.fullCursor(), cmd.x + xo_, cmd.y + yo_);
- bv.update();
+ mathcursor::setScreenPos(cur, cmd.x + xo_, cmd.y + yo_);
+ cur.bv().update();
return DispatchResult(true, true);
}
-void InsetFormulaBase::edit(BufferView * bv, bool left)
+void InsetFormulaBase::edit(LCursor & cur, bool /*left*/)
{
lyxerr << "Called FormulaBase::edit" << endl;
- releaseMathCursor(*bv);
- mathcursor = new MathCursor(bv, this, left);
- bv->fullCursor().push(this);
- // if that is removed, we won't get the magenta box when entering an
- // inset for the first time
- bv->update();
+ mathcursor::formula_ = this;
+ cur.push(this);
+ cur.idx() = 0;
+ cur.pos() = 0;
+#warning FIXME
+ cur.push(par().nucleus()->asHullInset());
+ //cur.idx() = left ? 0 : cur.lastidx();
+ cur.idx() = 0;
+ cur.pos() = 0;
+ cur.resetAnchor();
}
-void InsetFormulaBase::edit(BufferView * bv, int x, int y)
+void InsetFormulaBase::edit(LCursor & cur, int x, int y)
{
lyxerr << "Called FormulaBase::EDIT with '" << x << ' ' << y << "'" << endl;
- releaseMathCursor(*bv);
- mathcursor = new MathCursor(bv, this, true);
+ releaseMathCursor(cur);
//metrics(bv);
- mathcursor->setScreenPos(bv->fullCursor(), x + xo_, y + yo_);
- bv->fullCursor().push(this);
+ cur.push(this);
+ cur.idx() = 0;
+ cur.pos() = 0;
+ mathcursor::setScreenPos(cur, x + xo_, y + yo_);
+ cur.push(par().nucleus()->asHullInset());
+ //cur.idx() = left ? 0 : cur.lastidx();
+ cur.idx() = 0;
+ cur.pos() = 0;
// if that is removed, we won't get the magenta box when entering an
// inset for the first time
- bv->update();
+ cur.bv().update();
}
DispatchResult
-InsetFormulaBase::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+InsetFormulaBase::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
+ return par().nucleus()->dispatch(cur, cmd);
+
//lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
// << " arg: '" << cmd.argument
// << "' x: '" << cmd.x
// << " y: '" << cmd.y
// << "' button: " << cmd.button() << endl;
+#if 0
// delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
bool remove_inset = false;
- LCursor & cur = bv.fullCursor();
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
//lyxerr << "Mouse single press" << endl;
- return lfunMousePress(bv, cmd);
+ return lfunMousePress(cur, cmd);
case LFUN_MOUSE_MOTION:
//lyxerr << "Mouse motion" << endl;
- return lfunMouseMotion(bv, cmd);
+ return lfunMouseMotion(cur, cmd);
case LFUN_MOUSE_RELEASE:
//lyxerr << "Mouse single release" << endl;
- return lfunMouseRelease(bv, cmd);
+ return lfunMouseRelease(cur, cmd);
case LFUN_MOUSE_DOUBLE:
//lyxerr << "Mouse double" << endl;
- return dispatch(bv, FuncRequest(LFUN_WORDSEL));
+ return dispatch(cur, FuncRequest(LFUN_WORDSEL));
default:
break;
}
- if (!mathcursor)
- return DispatchResult(false);
-
DispatchResult result(true);
string argument = cmd.argument;
bool sel = false;
- bool was_macro = mathcursor->inMacroMode(cur);
+ bool was_macro = mathcursor::inMacroMode(cur);
- mathcursor->normalize(cur);
- mathcursor->touch();
+ mathcursor::normalize(cur);
+ mathcursor::touch();
switch (cmd.action) {
case LFUN_TABULAR_FEATURE:
case LFUN_PASTESELECTION:
case LFUN_MATH_LIMITS:
- recordUndo(bv, Undo::ATOMIC);
- mathcursor->dispatch(cur, cmd);
- break;
-
- case LFUN_RIGHTSEL:
- sel = true; // fall through...
- case LFUN_RIGHT:
- result = mathcursor->right(cur, sel) ?
- DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
- //lyxerr << "calling scroll 20" << endl;
- //scroll(&bv, 20);
- // write something to the minibuffer
- //bv.owner()->message(mathcursor->info());
- break;
-
- case LFUN_LEFTSEL:
- sel = true; // fall through
- case LFUN_LEFT:
- result = mathcursor->left(cur, sel) ?
- DispatchResult(true, true) : DispatchResult(false, FINISHED);
- break;
-
- case LFUN_UPSEL:
- sel = true; // fall through
- case LFUN_UP:
- result = mathcursor->up(cur, sel) ?
- DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
- break;
-
- case LFUN_DOWNSEL:
- sel = true; // fall through
- case LFUN_DOWN:
- result = mathcursor->down(cur, sel) ?
- DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
+ recordUndo(cur, Undo::ATOMIC);
+ mathcursor::dispatch(cur, cmd);
break;
case LFUN_WORDSEL:
- mathcursor->home(cur, false);
- mathcursor->end(cur, true);
+ mathcursor::home(cur, false);
+ mathcursor::end(cur, true);
break;
case LFUN_UP_PARAGRAPHSEL:
sel = true; // fall through
case LFUN_HOME:
case LFUN_WORDLEFT:
- result = mathcursor->home(cur, sel)
+ result = mathcursor::home(cur, sel)
? DispatchResult(true, true) : DispatchResult(true, FINISHED);
break;
sel = true; // fall through
case LFUN_END:
case LFUN_WORDRIGHT:
- result = mathcursor->end(cur, sel)
+ result = mathcursor::end(cur, sel)
? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
break;
break;
case LFUN_CELL_FORWARD:
- mathcursor->idxNext(cur);
+ mathcursor::idxNext(cur);
break;
case LFUN_CELL_BACKWARD:
- mathcursor->idxPrev(cur);
+ mathcursor::idxPrev(cur);
break;
case LFUN_DELETE_WORD_BACKWARD:
case LFUN_BACKSPACE:
- recordUndo(bv, Undo::ATOMIC);
- if (!mathcursor->backspace(cur)) {
+ recordUndo(cur, Undo::ATOMIC);
+ if (!mathcursor::backspace(cur)) {
result = DispatchResult(true, FINISHED);
remove_inset = true;
}
case LFUN_DELETE_WORD_FORWARD:
case LFUN_DELETE:
- recordUndo(bv, Undo::ATOMIC);
- if (!mathcursor->erase(cur)) {
+ recordUndo(cur, Undo::ATOMIC);
+ if (!mathcursor::erase(cur)) {
result = DispatchResult(true, FINISHED);
remove_inset = true;
}
int y = 0;
istringstream is(cmd.argument.c_str());
is >> x >> y;
- mathcursor->setScreenPos(cur, x, y);
+ mathcursor::setScreenPos(cur, x, y);
break;
}
istringstream is(cmd.argument.c_str());
is >> n;
if (was_macro)
- mathcursor->macroModeClose(cur);
- recordUndo(bv, Undo::ATOMIC);
- mathcursor->selPaste(cur, n);
+ mathcursor::macroModeClose(cur);
+ recordUndo(cur, Undo::ATOMIC);
+ mathcursor::selPaste(cur, n);
break;
}
case LFUN_CUT:
- recordUndo(bv, Undo::DELETE);
- mathcursor->selCut(cur);
+ recordUndo(cur, Undo::DELETE);
+ mathcursor::selCut(cur);
break;
case LFUN_COPY:
- mathcursor->selCopy(cur);
+ mathcursor::selCopy(cur);
break;
if (cmd.argument.empty()) {
// do superscript if LyX handles
// deadkeys
- recordUndo(bv, Undo::ATOMIC);
- mathcursor->script(cur, true);
+ recordUndo(cur, Undo::ATOMIC);
+ mathcursor::script(cur, true);
}
break;
case LFUN_DEFAULT: handleFont(cur, cmd.argument, "textnormal"); break;
case LFUN_MATH_MODE:
- if (mathcursor->currentMode(cur) == MathInset::TEXT_MODE)
- mathcursor->niceInsert(cur, MathAtom(new MathHullInset("simple")));
+ if (mathcursor::currentMode(cur) == MathInset::TEXT_MODE)
+ mathcursor::niceInsert(cur, MathAtom(new MathHullInset("simple")));
else
handleFont(cur, cmd.argument, "textrm");
//cur.owner()->message(_("math text mode toggled"));
case LFUN_MATH_SIZE:
#if 0
if (!arg.empty()) {
- recordUndo(bv, Undo::ATOMIC);
- mathcursor->setSize(arg);
+ recordUndo(cur, Undo::ATOMIC);
+ mathcursor::setSize(arg);
}
#endif
break;
case LFUN_INSERT_MATRIX: {
- recordUndo(bv, Undo::ATOMIC);
+ recordUndo(cur, Undo::ATOMIC);
unsigned int m = 1;
unsigned int n = 1;
string v_align;
m = max(1u, m);
n = max(1u, n);
v_align += 'c';
- mathcursor->niceInsert(cur,
+ mathcursor::niceInsert(cur,
MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
break;
}
ls = '(';
if (rs.empty())
rs = ')';
- recordUndo(bv, Undo::ATOMIC);
- mathcursor->handleNest(cur, MathAtom(new MathDelimInset(ls, rs)));
+ recordUndo(cur, Undo::ATOMIC);
+ mathcursor::handleNest(cur, MathAtom(new MathDelimInset(ls, rs)));
break;
}
case LFUN_SPACE_INSERT:
case LFUN_MATH_SPACE:
- recordUndo(bv, Undo::ATOMIC);
- mathcursor->insert(cur, MathAtom(new MathSpaceInset(",")));
+ recordUndo(cur, Undo::ATOMIC);
+ mathcursor::insert(cur, MathAtom(new MathSpaceInset(",")));
break;
case LFUN_UNDO:
- bv.owner()->message(_("Invalid action in math mode!"));
+ cur.bv().owner()->message(_("Invalid action in math mode!"));
break;
case LFUN_INSET_ERT:
// interpret this as if a backslash was typed
- recordUndo(bv, Undo::ATOMIC);
- mathcursor->interpret(cur, '\\');
+ recordUndo(cur, Undo::ATOMIC);
+ mathcursor::interpret(cur, '\\');
break;
case LFUN_BREAKPARAGRAPH:
// handling such that "self-insert" works on "arbitrary stuff" too, and
// math-insert only handles special math things like "matrix".
case LFUN_INSERT_MATH:
- recordUndo(bv, Undo::ATOMIC);
- mathcursor->niceInsert(cur, argument);
+ recordUndo(cur, Undo::ATOMIC);
+ mathcursor::niceInsert(cur, argument);
break;
case -1:
case LFUN_SELFINSERT:
if (!argument.empty()) {
- recordUndo(bv, Undo::ATOMIC);
+ recordUndo(cur, Undo::ATOMIC);
if (argument.size() == 1)
- result = mathcursor->interpret(cur, argument[0])
+ result = mathcursor::interpret(cur, argument[0])
? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
else
- mathcursor->insert(cur, argument);
+ mathcursor::insert(cur, argument);
}
break;
case LFUN_ESCAPE:
- if (mathcursor->selection())
- mathcursor->selClear(cur);
+ if (cur.selection())
+ mathcursor::selClear(cur);
else
result = DispatchResult(false);
break;
case LFUN_INSET_TOGGLE:
- mathcursor->insetToggle(cur);
+ mathcursor::insetToggle(cur);
break;
case LFUN_DIALOG_SHOW:
if (data.empty())
result = DispatchResult(false);
else
- bv.owner()->getDialogs().show(name, data, 0);
+ cur.bv().owner()->getDialogs().show(name, data, 0);
break;
}
case LFUN_INSET_APPLY: {
string const name = cmd.getArg(0);
- InsetBase * base = bv.owner()->getDialogs().getOpenInset(name);
+ InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
if (base) {
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
- result = base->dispatch(bv, fr);
+ result = base->dispatch(cur, fr);
} else {
MathArray ar;
if (createMathInset_fromDialogStr(cmd.argument, ar)) {
- mathcursor->insert(cur, ar);
+ mathcursor::insert(cur, ar);
result = DispatchResult(true, true);
} else {
result = DispatchResult(false);
case LFUN_WORD_REPLACE:
case LFUN_WORD_FIND: {
result =
- searchForward(&bv, cmd.getArg(0), false, false)
+ searchForward(&cur.bv(), cmd.getArg(0), false, false)
? DispatchResult(true, true) : DispatchResult(false);
break;
}
}
if (result == DispatchResult(true, true))
- bv.update();
+ cur.bv().update();
- mathcursor->normalize(cur);
- mathcursor->touch();
+ mathcursor::normalize(cur);
+ mathcursor::touch();
- BOOST_ASSERT(mathcursor);
+ BOOST_ASSERT(inMathed());
if (result.dispatched()) {
- revealCodes(bv);
- bv.stuffClipboard(mathcursor->grabSelection(cur));
+ revealCodes(cur);
+ cur.bv().stuffClipboard(mathcursor::grabSelection(cur));
} else {
- releaseMathCursor(bv);
+ releaseMathCursor(cur);
if (remove_inset)
- bv.owner()->dispatch(FuncRequest(LFUN_DELETE));
+ cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
}
return result; // original version
+#endif
}
-void InsetFormulaBase::revealCodes(BufferView & bv) const
+void InsetFormulaBase::revealCodes(LCursor & cur) const
{
- if (!mathcursor)
+ if (!inMathed())
return;
- bv.owner()->message(mathcursor->info(bv.fullCursor()));
+ ostringstream os;
+ cur.info(os);
+ cur.bv().owner()->message(os.str());
/*
// write something to the minibuffer
// translate to latex
- mathcursor->markInsert(bv);
+ mathcursor::markInsert(bv);
ostringstream os;
write(NULL, os);
string str = os.str();
- mathcursor->markErase(bv);
+ mathcursor::markErase(bv);
string::size_type pos = 0;
string res;
for (string::iterator it = str.begin(); it != str.end(); ++it) {
bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
bool, bool)
{
+ return false;
#ifdef WITH_WARNINGS
#warning pretty ugly
#endif
CursorSlice & top = it.back();
MathArray const & a = top.asMathInset()->cell(top.idx_);
if (a.matchpart(ar, top.pos_)) {
- delete mathcursor;
- mathcursor = new MathCursor(bv, this, true);
- //metrics(bv);
- mathcursor->setSelection(bv->fullCursor(), it, ar.size());
+ mathcursor::formula_ = this;
+ mathcursor::setSelection(bv->cursor(), it, ar.size());
current = it;
top.pos_ += ar.size();
bv->update();
string InsetFormulaBase::selectionAsString(BufferView & bv) const
{
- return mathcursor ? mathcursor->grabSelection(bv.fullCursor()) : string();
+ return inMathed() ? mathcursor::grabSelection(bv.cursor()) : string();
}
/////////////////////////////////////////////////////////////////////
-void mathDispatchCreation(BufferView & bv, FuncRequest const & cmd,
+void mathDispatchCreation(LCursor & cur, FuncRequest const & cmd,
bool display)
{
// use selection if available..
// sel = "";
//else
- string sel = bv.getLyXText()->selectionAsString(*bv.buffer(), false);
+ string sel =
+ cur.bv().getLyXText()->selectionAsString(*cur.bv().buffer(), false);
if (sel.empty()) {
- InsetFormula * f = new InsetFormula(&bv);
- if (openNewInset(bv, f)) {
- bv.fullCursor().innerInset()->
- dispatch(bv, FuncRequest(LFUN_MATH_MUTATE, "simple"));
+ InsetFormula * f = new InsetFormula;
+ if (openNewInset(cur, f)) {
+ cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
// don't do that also for LFUN_MATH_MODE unless you want end up with
// always changing to mathrm when opening an inlined inset
// -- I really hate "LyXfunc overloading"...
if (display)
- f->dispatch(bv, FuncRequest(LFUN_MATH_DISPLAY));
- f->dispatch(bv, FuncRequest(LFUN_INSERT_MATH, cmd.argument));
+ f->dispatch(cur, FuncRequest(LFUN_MATH_DISPLAY));
+ f->dispatch(cur, FuncRequest(LFUN_INSERT_MATH, cmd.argument));
}
} else {
// create a macro if we see "\\newcommand" somewhere, and an ordinary
f = new InsetFormula(sel);
else
f = new InsetFormulaMacro(sel);
- bv.getLyXText()->cutSelection(true, false);
- openNewInset(bv, f);
+ cur.bv().getLyXText()->cutSelection(true, false);
+ openNewInset(cur, f);
}
cmd.message(N_("Math editor mode"));
}
-void mathDispatch(BufferView & bv, FuncRequest const & cmd)
+void mathDispatch(LCursor & cur, FuncRequest const & cmd)
{
- if (!bv.available())
+ if (!cur.bv().available())
return;
switch (cmd.action) {
case LFUN_MATH_DISPLAY:
- mathDispatchCreation(bv, cmd, true);
+ mathDispatchCreation(cur, cmd, true);
break;
case LFUN_MATH_MODE:
- mathDispatchCreation(bv, cmd, false);
+ mathDispatchCreation(cur, cmd, false);
break;
case LFUN_MATH_IMPORT_SELECTION:
- mathDispatchCreation(bv, cmd, false);
+ mathDispatchCreation(cur, cmd, false);
break;
case LFUN_MATH_MACRO:
int const nargs = s1.empty() ? 0 : atoi(s1);
string const s2 = token(s, ' ', 2);
string const type = s2.empty() ? "newcommand" : s2;
- openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
+ openNewInset(cur, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
}
break;
case LFUN_INSERT_MATH:
case LFUN_INSERT_MATRIX:
case LFUN_MATH_DELIM: {
- InsetFormula * f = new InsetFormula(&bv);
- if (openNewInset(bv, f)) {
- UpdatableInset * inset = bv.fullCursor().innerInset();
- inset->dispatch(bv, FuncRequest(LFUN_MATH_MUTATE, "simple"));
- inset->dispatch(bv, cmd);
+ InsetFormula * f = new InsetFormula;
+ if (openNewInset(cur, f)) {
+ cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
+ cur.inset()->dispatch(cur, cmd);
}
break;
}
///
virtual void mutateToText();
///
- virtual void revealCodes(BufferView & bv) const;
+ virtual void revealCodes(LCursor & cur) const;
///
virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
///
// return the selection as std::string
std::string selectionAsString(BufferView & bv) const;
///
- void edit(BufferView * bv, bool);
+ void edit(LCursor & cur, bool);
///
- void edit(BufferView * bv, int, int);
+ void edit(LCursor & cur, int, int);
protected:
/// To allow transparent use of math editing functions
- virtual
- DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
/// unimplemented
void operator=(const InsetFormulaBase &);
/// common base for handling accents
void handleAccent(BufferView & bv, std::string const & arg, std::string const & name);
/// lfun handler
- DispatchResult lfunMousePress(BufferView &, FuncRequest const &);
+ DispatchResult lfunMousePress(LCursor &, FuncRequest const &);
///
- DispatchResult lfunMouseRelease(BufferView &, FuncRequest const &);
+ DispatchResult lfunMouseRelease(LCursor &, FuncRequest const &);
///
- DispatchResult lfunMouseMotion(BufferView &, FuncRequest const &);
+ DispatchResult lfunMouseMotion(LCursor &, FuncRequest const &);
protected:
// We don't really mess want around with mathed stuff outside mathed.
// So do it here.
-void mathDispatch(BufferView & bv, FuncRequest const & cmd);
+void mathDispatch(LCursor & cur, FuncRequest const & cmd);
///
-void releaseMathCursor(BufferView & bv);
+void releaseMathCursor(LCursor & cur);
#endif
using std::ostream;
-extern MathCursor * mathcursor;
-
-
InsetFormulaMacro::InsetFormulaMacro()
{
// inset name is inherited from Inset
pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
pi.pain.rectangle(x, a, w, h, LColor::mathframe);
- if (mathcursor &&
- const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
- mathcursor->drawSelection(pi);
+ if (inMathed() &&
+ const_cast<InsetFormulaBase const *>(mathcursor::formula()) == this)
+ mathcursor::drawSelection(pi);
pi.pain.text(x + 2, y, prefix(), font);
limited_stack<string> theCutBuffer;
-MathCursor::MathCursor(BufferView * bv, InsetFormulaBase * formula, bool front)
- : formula_(formula), autocorrect_(false), selection_(false)
-{
- front ? first(bv->fullCursor()) : last(bv->fullCursor());
-}
+namespace mathcursor {
+ //front ? first(cur) : last(cur);
-MathCursor::~MathCursor()
-{
- // ensure that 'notifyCursorLeave' is called
- //while (popLeft())
- // ;
-}
+
+ /// moves cursor index one cell to the left
+ bool idxLeft(LCursor & cur);
+ /// moves cursor index one cell to the right
+ bool idxRight(LCursor & cur);
+ /// moves cursor to end of last cell of current line
+ bool idxLineLast(LCursor & cur);
+ /// moves position somehow up or down
+ bool goUpDown(LCursor & cur, bool up);
+ /// moves position closest to (x, y) in given box
+ bool bruteFind(LCursor & cur,
+ int x, int y, int xlow, int xhigh, int ylow, int yhigh);
+ /// moves position closest to (x, y) in current cell
+ void bruteFind2(LCursor & cur, int x, int y);
+ /// are we in a nucleus of a script inset?
+ bool inNucleus(LCursor & cur);
+
+ /// erase the selected part and re-sets the cursor
+ void eraseSelection(LCursor & cur);
+
+ /// the name of the macro we are currently inputting
+ std::string macroName(LCursor & cur);
+ /// where in the curent cell does the macro name start?
+ difference_type macroNamePos(LCursor & cur);
+ /// can we enter the inset?
+ bool openable(MathAtom const &, bool selection);
+
+ /// pointer to enclsing LyX inset
+ InsetFormulaBase * formula_;
-void MathCursor::push(LCursor & cur, MathAtom & t)
+void push(LCursor & cur, MathAtom & t)
{
cur.push(t.nucleus());
}
-void MathCursor::pushLeft(LCursor & cur, MathAtom & t)
+void pushLeft(LCursor & cur, MathAtom & t)
{
//lyxerr << "Entering atom " << t << " left" << endl;
push(cur, t);
}
-void MathCursor::pushRight(LCursor & cur, MathAtom & t)
+void pushRight(LCursor & cur, MathAtom & t)
{
//lyxerr << "Entering atom " << t << " right" << endl;
cur.posLeft();
}
-bool MathCursor::popLeft(LCursor & cur)
+bool popLeft(LCursor & cur)
{
//lyxerr << "Leaving atom to the left" << endl;
if (cur.depth() <= 1) {
}
-bool MathCursor::popRight(LCursor & cur)
+bool popRight(LCursor & cur)
{
//lyxerr << "Leaving atom "; bv.inset->asMathInset()->write(cerr, false); cerr << " right" << endl;
if (cur.depth() <= 1) {
#if FILEDEBUG
- void MathCursor::dump(char const * what) const
+ void dump(char const * what)
{
lyxerr << "MC: " << what << endl;
lyxerr << " Cursor: " << cur.depth() << endl;
lyxerr << " Anchor: " << Anchor_.size() << endl;
for (unsigned i = 0; i < Anchor_.size(); ++i)
lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
- lyxerr << " sel: " << selection_ << endl;
+ lyxerr << " sel: " << cur.selection() << endl;
}
#else
- void MathCursor::dump(char const *) const {}
+ void dump(char const *) {}
#endif
-bool MathCursor::isInside(MathInset const *) const
+bool isInside(MathInset const *)
{
#warning FIXME
/*
}
-bool MathCursor::openable(MathAtom const & t, bool sel) const
+bool openable(MathAtom const & t, bool sel)
{
if (!t->isActive())
return false;
}
-bool MathCursor::inNucleus(LCursor & cur) const
+bool inNucleus(LCursor & cur)
{
return cur.inset()->asMathInset()->asScriptInset() && cur.idx() == 2;
}
-bool MathCursor::left(LCursor & cur, bool sel)
+bool left(LCursor & cur, bool sel)
{
dump("Left 1");
- autocorrect_ = false;
- cur.bv().x_target(-1); // "no target"
+ cur.autocorrect() = false;
+ cur.x_target(-1); // "no target"
if (inMacroMode(cur)) {
macroModeClose(cur);
return true;
return true;
}
- return cur.posLeft() || idxLeft(cur) || popLeft(cur) || selection_;
+ return cur.posLeft() || idxLeft(cur) || popLeft(cur) || cur.selection();
}
-bool MathCursor::right(LCursor & cur, bool sel)
+bool right(LCursor & cur, bool sel)
{
dump("Right 1");
- autocorrect_ = false;
- cur.bv().x_target(-1); // "no target"
+ cur.autocorrect() = false;
+ cur.x_target(-1); // "no target"
if (inMacroMode(cur)) {
macroModeClose(cur);
return true;
return true;
}
- return cur.posRight() || idxRight(cur) || popRight(cur) || selection_;
-}
-
-
-void MathCursor::first(LCursor & cur)
-{
-#warning FIXME
- //Cursor_.clear();
- push(cur, formula_->par());
- cur.inset()->asMathInset()->idxFirst(cur);
- cur.resetAnchor();
-}
-
-
-void MathCursor::last(LCursor & cur)
-{
-#warning FIXME
- //Cursor_.clear();
- push(cur, formula_->par());
- cur.inset()->asMathInset()->idxLast(cur);
- cur.resetAnchor();
+ return cur.posRight() || idxRight(cur) || popRight(cur) || cur.selection();
}
}
-void MathCursor::setScreenPos(LCursor & cur, int x, int y)
+void setScreenPos(LCursor & cur, int x, int y)
{
dump("setScreenPos 1");
bool res = bruteFind(cur, x, y,
if (!res) {
// this can happen on creation of "math-display"
dump("setScreenPos 1.5");
- first(cur);
+ cur.idx() = 0;
+ cur.pos() = 0;
}
- cur.bv().x_target(-1); // "no target"
+ cur.x_target(-1); // "no target"
dump("setScreenPos 2");
}
-bool MathCursor::home(LCursor & cur, bool sel)
+bool home(LCursor & cur, bool sel)
{
dump("home 1");
- autocorrect_ = false;
+ cur.autocorrect() = false;
selHandle(cur, sel);
macroModeClose(cur);
if (!cur.inset()->asMathInset()->idxHome(cur))
return popLeft(cur);
dump("home 2");
- cur.bv().x_target(-1); // "no target"
+ cur.x_target(-1); // "no target"
return true;
}
-bool MathCursor::end(LCursor & cur, bool sel)
+bool end(LCursor & cur, bool sel)
{
dump("end 1");
- autocorrect_ = false;
+ cur.autocorrect() = false;
selHandle(cur, sel);
macroModeClose(cur);
if (!cur.inset()->asMathInset()->idxEnd(cur))
return popRight(cur);
dump("end 2");
- cur.bv().x_target(-1); // "no target"
+ cur.x_target(-1); // "no target"
return true;
}
-void MathCursor::plainErase(LCursor & cur)
+void plainErase(LCursor & cur)
{
cur.cell().erase(cur.pos());
}
-void MathCursor::markInsert(LCursor & cur)
+void markInsert(LCursor & cur)
{
//lyxerr << "inserting mark" << endl;
cur.cell().insert(cur.pos(), MathAtom(new MathCharInset(0)));
}
-void MathCursor::markErase(LCursor & cur)
+void markErase(LCursor & cur)
{
//lyxerr << "deleting mark" << endl;
cur.cell().erase(cur.pos());
}
-void MathCursor::plainInsert(LCursor & cur, MathAtom const & t)
+void plainInsert(LCursor & cur, MathAtom const & t)
{
dump("plainInsert");
cur.cell().insert(cur.pos(), t);
}
-void MathCursor::insert2(LCursor & cur, string const & str)
+void insert2(LCursor & cur, string const & str)
{
MathArray ar;
asArray(str, ar);
}
-void MathCursor::insert(LCursor & cur, string const & str)
+void insert(LCursor & cur, string const & str)
{
//lyxerr << "inserting '" << str << "'" << endl;
selClearOrDel(cur);
}
-void MathCursor::insert(LCursor & cur, char c)
+void insert(LCursor & cur, char c)
{
//lyxerr << "inserting '" << c << "'" << endl;
selClearOrDel(cur);
}
-void MathCursor::insert(LCursor & cur, MathAtom const & t)
+void insert(LCursor & cur, MathAtom const & t)
{
macroModeClose(cur);
selClearOrDel(cur);
}
-void MathCursor::niceInsert(LCursor & cur, string const & t)
+void niceInsert(LCursor & cur, string const & t)
{
MathArray ar;
asArray(t, ar);
}
-void MathCursor::niceInsert(LCursor & cur, MathAtom const & t)
+void niceInsert(LCursor & cur, MathAtom const & t)
{
macroModeClose(cur);
string safe = grabAndEraseSelection(cur);
}
-void MathCursor::insert(LCursor & cur, MathArray const & ar)
+void insert(LCursor & cur, MathArray const & ar)
{
macroModeClose(cur);
- if (selection_)
+ if (cur.selection())
eraseSelection(cur);
cur.cell().insert(cur.pos(), ar);
cur.pos() += ar.size();
}
-void MathCursor::paste(LCursor & cur, string const & data)
+void paste(LCursor & cur, string const & data)
{
dispatch(cur, FuncRequest(LFUN_PASTE, data));
}
-bool MathCursor::backspace(LCursor & cur)
+bool backspace(LCursor & cur)
{
- autocorrect_ = false;
+ cur.autocorrect() = false;
- if (selection_) {
+ if (cur.selection()) {
selDel(cur);
return true;
}
}
-bool MathCursor::erase(LCursor & cur)
+bool erase(LCursor & cur)
{
- autocorrect_ = false;
+ cur.autocorrect() = false;
if (inMacroMode(cur))
return true;
- if (selection_) {
+ if (cur.selection()) {
selDel(cur);
return true;
}
}
-bool MathCursor::up(LCursor & cur, bool sel)
+bool up(LCursor & cur, bool sel)
{
dump("up 1");
macroModeClose(cur);
selHandle(cur, sel);
-#warning FIXME
-#if 0
- CursorBase save = Cursor_;
- if (goUpDown(true))
+#warning look here
+ //CursorBase save = cur.cursor_;
+ if (goUpDown(cur, true))
return true;
- Cursor_ = save;
-#endif
- autocorrect_ = false;
- return selection_;
+ //cur.cursor_ = save;
+ cur.autocorrect() = false;
+ return cur.selection();
}
-bool MathCursor::down(LCursor & cur, bool sel)
+bool down(LCursor & cur, bool sel)
{
dump("down 1");
macroModeClose(cur);
selHandle(cur, sel);
-#warning FIXME
-#if 0
- CursorBase save = Cursor_;
- if (goUpDown(false))
+#warning look here
+ //CursorBase save = cur.cursor_;
+ if (goUpDown(cur, false))
return true;
- Cursor_ = save;
-#endif
- autocorrect_ = false;
- return selection_;
+ //cur.cursor_ = save;
+ cur.autocorrect() = false;
+ return cur.selection();
}
-void MathCursor::macroModeClose(LCursor & cur)
+void macroModeClose(LCursor & cur)
{
if (!inMacroMode(cur))
return;
}
-string MathCursor::macroName(LCursor & cur) const
+string macroName(LCursor & cur)
{
return inMacroMode(cur) ? activeMacro(cur)->name() : string();
}
-void MathCursor::selClear(LCursor & cur)
+void selClear(LCursor & cur)
{
cur.resetAnchor();
- cur.bv().clearSelection();
+ cur.clearSelection();
}
-void MathCursor::selCopy(LCursor & cur)
+void selCopy(LCursor & cur)
{
dump("selCopy");
- if (selection_) {
+ if (cur.selection()) {
theCutBuffer.push(grabSelection(cur));
- selection_ = false;
+ cur.selection() = false;
} else {
//theCutBuffer.erase();
}
}
-void MathCursor::selCut(LCursor & cur)
+void selCut(LCursor & cur)
{
dump("selCut");
theCutBuffer.push(grabAndEraseSelection(cur));
}
-void MathCursor::selDel(LCursor & cur)
+void selDel(LCursor & cur)
{
dump("selDel");
- if (selection_) {
+ if (cur.selection()) {
eraseSelection(cur);
- selection_ = false;
+ cur.selection() = false;
}
}
-void MathCursor::selPaste(LCursor & cur, size_t n)
+void selPaste(LCursor & cur, size_t n)
{
dump("selPaste");
selClearOrDel(cur);
if (n < theCutBuffer.size())
paste(cur, theCutBuffer[n]);
//grabSelection(cur);
- selection_ = false;
+ cur.selection() = false;
}
-void MathCursor::selHandle(LCursor & cur, bool sel)
+void selHandle(LCursor & cur, bool sel)
{
- if (sel == selection_)
+ if (sel == cur.selection())
return;
//clear();
cur.resetAnchor();
- selection_ = sel;
+ cur.selection() = sel;
}
-void MathCursor::selStart(LCursor & cur)
+void selStart(LCursor & cur)
{
dump("selStart 1");
//clear();
cur.resetAnchor();
- selection_ = true;
+ cur.selection() = true;
dump("selStart 2");
}
-void MathCursor::selClearOrDel(LCursor & cur)
+void selClearOrDel(LCursor & cur)
{
if (lyxrc.auto_region_delete)
selDel(cur);
else
- selection_ = false;
+ cur.selection() = false;
}
-void MathCursor::drawSelection(PainterInfo & pi) const
+void drawSelection(PainterInfo & pi)
{
- if (!selection_)
+ if (!pi.base.bv->cursor().selection())
return;
- CursorSlice i1;
- CursorSlice i2;
- getSelection(pi.base.bv->fullCursor(), i1, i2);
+ CursorSlice i1 = pi.base.bv->cursor().selStart();
+ CursorSlice i2 = pi.base.bv->cursor().selEnd();
i1.asMathInset()->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
}
-void MathCursor::handleNest(LCursor & cur, MathAtom const & a, int c)
+void handleNest(LCursor & cur, MathAtom const & a, int c)
{
MathAtom at = a;
asArray(grabAndEraseSelection(cur), at.nucleus()->cell(c));
}
-void MathCursor::getScreenPos(LCursor & cur, int & x, int & y) const
+void getScreenPos(LCursor & cur, int & x, int & y)
{
cur.inset()->asMathInset()->getScreenPos(cur.idx(), cur.pos(), x, y);
}
-int MathCursor::targetX(LCursor & cur) const
+int targetX(LCursor & cur)
{
- if (cur.bv().x_target() != -1)
- return cur.bv().x_target();
+ if (cur.x_target() != -1)
+ return cur.x_target();
int x = 0;
int y = 0;
getScreenPos(cur, x, y);
}
-InsetFormulaBase * MathCursor::formula() const
+InsetFormulaBase * formula()
{
return formula_;
}
-void MathCursor::adjust(LCursor & cur, pos_type from, difference_type diff)
+void adjust(LCursor & cur, pos_type from, difference_type diff)
{
if (cur.pos() > from)
cur.pos() += diff;
-#warning FIXME
-#if 0
- if (Anchor_.back().pos_ > from)
- Anchor_.back().pos_ += diff;
+ if (cur.anchor().pos_ > from)
+ cur.anchor().pos_ += diff;
// just to be on the safe side
// theoretically unecessary
-#endif
normalize(cur);
}
-bool MathCursor::inMacroMode(LCursor & cur) const
+bool inMacroMode(LCursor & cur)
{
if (!cur.pos() != 0)
return false;
}
-MathUnknownInset * MathCursor::activeMacro(LCursor & cur)
+MathUnknownInset * activeMacro(LCursor & cur)
{
return inMacroMode(cur) ? cur.prevAtom().nucleus()->asUnknownInset() : 0;
}
-MathUnknownInset const * MathCursor::activeMacro(LCursor & cur) const
-{
- return inMacroMode(cur) ? cur.prevAtom()->asUnknownInset() : 0;
-}
-
-
-bool MathCursor::inMacroArgMode(LCursor & cur) const
+bool inMacroArgMode(LCursor & cur)
{
return cur.pos() > 0 && cur.prevAtom()->getChar() == '#';
}
-bool MathCursor::selection() const
-{
- return selection_;
-}
-
-
-MathGridInset *
-MathCursor::enclosingGrid(LCursor & cur, MathCursor::idx_type & idx) const
+MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx)
{
for (MathInset::difference_type i = cur.depth() - 1; i >= 0; --i) {
MathInset * m = cur.cursor_[i].inset()->asMathInset();
}
-void MathCursor::popToHere(LCursor & cur, MathInset const * p)
+void popToHere(LCursor & cur, MathInset const * p)
{
while (cur.depth() && cur.inset()->asMathInset() != p)
cur.pop();
}
-void MathCursor::popToEnclosingGrid(LCursor & cur)
+void popToEnclosingGrid(LCursor & cur)
{
while (cur.depth() && !cur.inset()->asMathInset()->asGridInset())
cur.pop();
}
-void MathCursor::popToEnclosingHull(LCursor & cur)
+void popToEnclosingHull(LCursor & cur)
{
while (cur.depth() && !cur.inset()->asMathInset()->asGridInset())
cur.pop();
}
-void MathCursor::pullArg(LCursor & cur)
+void pullArg(LCursor & cur)
{
dump("pullarg");
MathArray ar = cur.cell();
}
-void MathCursor::touch()
+void touch()
{
#warning
#if 0
}
-void MathCursor::normalize(LCursor & cur)
+void normalize(LCursor & cur)
{
+#warning FIXME
+#if 0
if (cur.idx() >= cur.nargs()) {
lyxerr << "this should not really happen - 1: "
<< cur.idx() << ' ' << cur.nargs()
dump("error 4");
}
cur.pos() = min(cur.pos(), cur.lastpos());
+#endif
}
-void MathCursor::idxNext(LCursor & cur)
+void idxNext(LCursor & cur)
{
cur.inset()->asMathInset()->idxNext(cur);
}
-void MathCursor::idxPrev(LCursor & cur)
+void idxPrev(LCursor & cur)
{
cur.inset()->asMathInset()->idxPrev(cur);
}
-char MathCursor::valign(LCursor & cur) const
+char valign(LCursor & cur)
{
idx_type idx;
MathGridInset * p = enclosingGrid(cur, idx);
}
-char MathCursor::halign(LCursor & cur) const
+char halign(LCursor & cur)
{
idx_type idx;
MathGridInset * p = enclosingGrid(cur, idx);
}
-void MathCursor::getSelection(LCursor & cur,
- CursorSlice & i1, CursorSlice & i2) const
-{
- CursorSlice anc = normalAnchor(cur);
- if (anc < cur.top()) {
- i1 = anc;
- i2 = cur.top();
- } else {
- i1 = cur.top();
- i2 = anc;
- }
-}
-
-
-bool MathCursor::goUpDown(LCursor & cur, bool up)
+bool goUpDown(LCursor & cur, bool up)
{
// Be warned: The 'logic' implemented in this function is highly fragile.
// A distance of one pixel or a '<' vs '<=' _really_ matters.
getScreenPos(cur, xo, yo);
// check if we had something else in mind, if not, this is the future goal
- if (cur.bv().x_target() == -1)
- cur.bv().x_target(xo);
+ if (cur.x_target() == -1)
+ cur.x_target(xo);
else
- xo = cur.bv().x_target();
+ xo = cur.x_target();
// try neigbouring script insets
- if (!selection()) {
+ if (!cur.selection()) {
// try left
if (cur.pos() != 0) {
MathScriptInset const * p = cur.prevAtom()->asScriptInset();
}
// try current cell for e.g. text insets
- if (cur.inset()->asMathInset()->idxUpDown2(cur, up, cur.bv().x_target()))
+ if (cur.inset()->asMathInset()->idxUpDown2(cur, up, cur.x_target()))
return true;
//xarray().boundingBox(xlow, xhigh, ylow, yhigh);
while (1) {
//lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl;
// ask inset first
- if (cur.inset()->asMathInset()->idxUpDown(cur, up, cur.bv().x_target())) {
+ if (cur.inset()->asMathInset()->idxUpDown(cur, up, cur.x_target())) {
// try to find best position within this inset
- if (!selection())
+ if (!cur.selection())
bruteFind2(cur, xo, yo);
return true;
}
}
-bool MathCursor::bruteFind
+bool bruteFind
(LCursor & cur, int x, int y, int xlow, int xhigh, int ylow, int yhigh)
{
CursorBase best_cursor;
CursorBase et = iend(formula()->par().nucleus());
while (1) {
// avoid invalid nesting when selecting
- if (!selection_ || positionable(it, cur.anchor_)) {
+ if (!cur.selection() || positionable(it, cur.anchor_)) {
int xo, yo;
it.back().getScreenPos(xo, yo);
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
}
-void MathCursor::bruteFind2(LCursor & cur, int x, int y)
+void bruteFind2(LCursor & cur, int x, int y)
{
double best_dist = 1e10;
}
-bool MathCursor::idxLineLast(LCursor & cur)
+bool idxLineLast(LCursor & cur)
{
cur.idx() -= cur.idx() % cur.ncols();
cur.idx() += cur.ncols() - 1;
}
-bool MathCursor::idxLeft(LCursor & cur)
+bool idxLeft(LCursor & cur)
{
return cur.inset()->asMathInset()->idxLeft(cur);
}
-bool MathCursor::idxRight(LCursor & cur)
+bool idxRight(LCursor & cur)
{
return cur.inset()->asMathInset()->idxRight(cur);
}
-bool MathCursor::script(LCursor & cur, bool up)
+bool script(LCursor & cur, bool up)
{
// Hack to get \\^ and \\_ working
if (inMacroMode(cur) && macroName(cur) == "\\") {
}
-bool MathCursor::interpret(LCursor & cur, char c)
+bool interpret(LCursor & cur, char c)
{
//lyxerr << "interpret 2: '" << c << "'" << endl;
- cur.bv().x_target(-1); // "no target"
+ cur.x_target(-1); // "no target"
if (inMacroArgMode(cur)) {
--cur.pos();
plainErase(cur);
if (0) {
// leave autocorrect mode if necessary
- if (autocorrect_ && c == ' ') {
- autocorrect_ = false;
+ if (cur.autocorrect() && c == ' ') {
+ cur.autocorrect() = false;
return true;
}
}
// just clear selection on pressing the space bar
- if (selection_ && c == ' ') {
- selection_ = false;
+ if (cur.selection() && c == ' ') {
+ cur.selection() = false;
return true;
}
}
// try auto-correction
- //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
+ //if (cur.autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
// return true;
// no special circumstances, so insert the character without any fuss
insert(cur, c);
- autocorrect_ = true;
+ cur.autocorrect() = true;
return true;
}
-void MathCursor::setSelection
- (LCursor & cur, CursorBase const & where, size_t n)
+void setSelection(LCursor & cur, CursorBase const & where, size_t n)
{
- selection_ = true;
+ cur.selection() = true;
cur.cursor_ = where;
cur.anchor_ = where;
cur.pos() += n;
}
-void MathCursor::insetToggle(LCursor & cur)
+void insetToggle(LCursor & cur)
{
if (cur.pos() != cur.lastpos()) {
// toggle previous inset ...
}
-string MathCursor::info(LCursor & cur) const
-{
- ostringstream os;
- os << "Math editor mode. ";
- for (int i = 0, n = cur.depth(); i < n; ++i) {
- cur.cursor_[i].asMathInset()->infoize(os);
- os << " ";
- }
- if (cur.pos() != 0)
- cur.prevAtom()->infoize2(os);
- os << " ";
- return os.str();
-}
-
-
namespace {
void region(CursorSlice const & i1, CursorSlice const & i2,
}
-string MathCursor::grabSelection(LCursor & cur) const
+string grabSelection(LCursor & cur)
{
- if (!selection_)
+ if (!cur.selection())
return string();
- CursorSlice i1;
- CursorSlice i2;
- getSelection(cur, i1, i2);
+ CursorSlice i1 = cur.selStart();
+ CursorSlice i2 = cur.selEnd();
if (i1.idx_ == i2.idx_) {
MathArray::const_iterator it = i1.cell().begin();
}
-void MathCursor::eraseSelection(LCursor & cur)
+void eraseSelection(LCursor & cur)
{
- CursorSlice i1;
- CursorSlice i2;
- getSelection(cur, i1, i2);
+ CursorSlice i1 = cur.selStart();
+ CursorSlice i2 = cur.selEnd();
if (i1.idx_ == i2.idx_)
i1.cell().erase(i1.pos_, i2.pos_);
else {
for (col_type col = c1; col <= c2; ++col)
p->cell(p->index(row, col)).clear();
}
- cur.top() = i1;
+ cur.current() = i1;
}
-string MathCursor::grabAndEraseSelection(LCursor & cur)
+string grabAndEraseSelection(LCursor & cur)
{
- if (!selection_)
+ if (!cur.selection())
return string();
string res = grabSelection(cur);
eraseSelection(cur);
- selection_ = false;
+ cur.selection() = false;
return res;
}
-CursorSlice MathCursor::normalAnchor(LCursor & cur) const
+CursorSlice normalAnchor(LCursor & cur)
{
#warning FIXME
#if 0
}
return normal;
#else
- return cur.top();
+ return cur.anchor_.back();
#endif
}
-DispatchResult MathCursor::dispatch(LCursor &, FuncRequest const & cmd)
+DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd)
{
// mouse clicks are somewhat special
// check
+/*
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
case LFUN_MOUSE_MOTION:
case LFUN_MOUSE_RELEASE:
case LFUN_MOUSE_DOUBLE: {
-/*
- CursorSlice & pos = Cursor_.back();
+ CursorSlice & pos = cur.cursor_.back();
int x = 0;
int y = 0;
getScreenPos(x, y);
- if (x < cmd.x && hasPrevAtom()) {
+ if (x < cmd.x && cur.hasPrevAtom()) {
DispatchResult const res =
- prevAtom().nucleus()->dispatch(cur, cmd);
+ cur.prevAtom().nucleus()->dispatch(cur, cmd);
if (res.dispatched())
return res;
}
- if (x > cmd.x && hasNextAtom()) {
+ if (x > cmd.x && cur.hasNextAtom()) {
DispatchResult const res =
- nextAtom().nucleus()->dispatch(cur, cmd);
+ cur.nextAtom().nucleus()->dispatch(cur, cmd);
if (res.dispatched())
return res;
}
-*/
}
default:
break;
}
-/*
for (int i = cur.depth() - 1; i >= 0; --i) {
CursorBase tmp = cur->cursor_;
CursorSlice & pos = tmp.back()
}
-MathInset::mode_type MathCursor::currentMode(LCursor &) const
+MathInset::mode_type currentMode(LCursor &)
{
#if 0
for (int i = Cursor_.size() - 1; i >= 0; --i) {
}
-void MathCursor::handleFont(LCursor & cur, string const & font)
+void handleFont(LCursor & cur, string const & font)
{
string safe;
- if (selection()) {
+ if (cur.selection()) {
macroModeClose(cur);
safe = grabAndEraseSelection(cur);
}
insert(cur, safe);
}
+}
+
-void releaseMathCursor(BufferView & bv)
+void releaseMathCursor(LCursor & cur)
{
- if (mathcursor) {
- InsetFormulaBase * f = mathcursor->formula();
- delete mathcursor;
- mathcursor = 0;
- f->insetUnlock(bv);
+ if (inMathed()) {
+ mathcursor::formula_->insetUnlock(cur.bv());
+ mathcursor::formula_ = 0;
}
}
+
+
+bool inMathed()
+{
+ return mathcursor::formula_;
+}
#ifndef MATH_CURSOR
#define MATH_CURSOR
-#include "cursor_slice.h"
+#include "cursor.h"
#include "math_inset.h"
#include "math_data.h"
*/
-class MathCursor {
-public:
+namespace mathcursor {
/// short of anything else reasonable
typedef size_t size_type;
/// type for column numbers
/// type for column numbers
typedef size_t col_type;
- ///
- explicit MathCursor(BufferView *, InsetFormulaBase *, bool left);
- ///
- ~MathCursor();
///
void insert(LCursor & cur, MathAtom const &);
///
bool up(LCursor & cur, bool sel = false);
/// called for LFUN_DOWN etc
bool down(LCursor & cur, bool sel = false);
- /// Put the cursor in the first position
- void first(LCursor & cur);
- /// Put the cursor in the last position
- void last(LCursor & cur);
/// move to next cell in current inset
void idxNext(LCursor & bv);
/// move to previous cell in current inset
/// in pixels from top of screen
void setScreenPos(LCursor & cur, int x, int y);
/// in pixels from top of screen
- void getScreenPos(LCursor & cur, int & x, int & y) const;
+ void getScreenPos(LCursor & cur, int & x, int & y);
/// in pixels from left of screen
- int targetX(LCursor & cur) const;
+ int targetX(LCursor & cur);
/// return the next enclosing grid inset and the cursor's index in it
- MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx) const;
+ MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx);
/// go up to enclosing grid
void popToEnclosingGrid(LCursor & cur);
/// go up to the hull inset
/// adjust anchor position after deletions/insertions
void adjust(LCursor & cur, pos_type from, difference_type diff);
///
- InsetFormulaBase * formula() const;
+ InsetFormulaBase * formula();
/// current offset in the current cell
///
bool script(LCursor & cur, bool);
/// interpret name a name of a macro
void macroModeClose(LCursor & cur);
/// are we currently typing the name of a macro?
- bool inMacroMode(LCursor & cur) const;
+ bool inMacroMode(LCursor & cur);
/// get access to the macro we are currently typing
MathUnknownInset * activeMacro(LCursor & cur);
- /// get access to the macro we are currently typing
- MathUnknownInset const * activeMacro(LCursor & cur) const;
/// are we currently typing '#1' or '#2' or...?
- bool inMacroArgMode(LCursor & cur) const;
+ bool inMacroArgMode(LCursor & cur);
/// are we in math mode (1), text mode (-1) or unsure?
- MathInset::mode_type currentMode(LCursor & cur) const;
+ MathInset::mode_type currentMode(LCursor & cur);
// Local selection methods
///
- bool selection() const;
- ///
void selCopy(LCursor & cur);
///
void selCut(LCursor & cur);
/// clears or deletes selection depending on lyxrc setting
void selClearOrDel(LCursor & cur);
/// draws light-blue selection background
- void drawSelection(PainterInfo & pi) const;
+ void drawSelection(PainterInfo & pi);
/// replace selected stuff with at, placing the former
// selection in given cell of atom
void handleNest(LCursor & cur, MathAtom const & at, int cell = 0);
/// remove this as soon as LyXFunc::getStatus is "localized"
- std::string getLastCode() const { return "mathnormal"; }
+ inline std::string getLastCode() { return "mathnormal"; }
///
- bool isInside(MathInset const *) const;
+ bool isInside(MathInset const *);
///
- char valign(LCursor & cur) const;
+ char valign(LCursor & cur);
///
- char halign(LCursor & cur) const;
+ char halign(LCursor & cur);
/// make sure cursor position is valid
void normalize(LCursor & cur);
/// leave current MathInset to the left
bool popRight(LCursor & cur);
- /// returns the selection
- void getSelection(LCursor & cur, CursorSlice &, CursorSlice &) const;
/// returns the normalized anchor of the selection
- CursorSlice normalAnchor(LCursor & cur) const;
+ CursorSlice normalAnchor(LCursor & cur);
- /// describe the situation
- std::string info(LCursor & cur) const;
/// dump selection information for debugging
- void seldump(char const * str) const;
+ void seldump(char const * str);
/// dump selection information for debugging
- void dump(char const * str) const;
+ void dump(char const * str);
/// moves on
void setSelection(LCursor & cur, CursorBase const & where, size_type n);
/// grab selection marked by anchor and current cursor
- std::string grabSelection(LCursor & cur) const;
+ std::string grabSelection(LCursor & cur);
/// guess what
std::string grabAndEraseSelection(LCursor & cur);
///
void handleFont(LCursor & cur, std::string const & font);
///
DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
-private:
- /// moves cursor index one cell to the left
- bool idxLeft(LCursor & bv);
- /// moves cursor index one cell to the right
- bool idxRight(LCursor & bv);
- /// moves cursor to end of last cell of current line
- bool idxLineLast(LCursor & bv);
- /// moves position somehow up or down
- bool goUpDown(LCursor & cur, bool up);
- /// moves position closest to (x, y) in given box
- bool bruteFind(LCursor & cur,
- int x, int y, int xlow, int xhigh, int ylow, int yhigh);
- /// moves position closest to (x, y) in current cell
- void bruteFind2(LCursor & cur, int x, int y);
- /// are we in a nucleus of a script inset?
- bool inNucleus(LCursor & cur) const;
-
- /// erase the selected part and re-sets the cursor
- void eraseSelection(LCursor & cur);
-
- /// the name of the macro we are currently inputting
- std::string macroName(LCursor & cur) const;
- /// where in the curent cell does the macro name start?
- difference_type macroNamePos(LCursor & cur) const;
- /// can we enter the inset?
- bool openable(MathAtom const &, bool selection) const;
/// pointer to enclsing LyX inset
- InsetFormulaBase * formula_;
- // Selection stuff
- /// text code of last char entered
- //MathTextCodes lastcode_;
- /// do we allow autocorrection
- bool autocorrect_;
- /// do we currently select
- bool selection_;
- /// are we entering a macro name?
- bool macromode_;
-};
+ extern InsetFormulaBase * formula_;
+}
+
+void releaseMathCursor(LCursor & cur);
-extern MathCursor * mathcursor;
-void releaseMathCursor(BufferView & bv);
+bool inMathed();
#endif
#include "math_fracbase.h"
#include "math_data.h"
+#include "cursor.h"
MathFracbaseInset::MathFracbaseInset()
#include "math_mathmlstream.h"
#include "math_streamstr.h"
#include "BufferView.h"
+#include "cursor.h"
#include "dispatchresult.h"
#include "debug.h"
#include "funcrequest.h"
DispatchResult
-MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
- LCursor & cur = bv.fullCursor();
switch (cmd.action) {
case LFUN_MOUSE_RELEASE:
return DispatchResult(false);
case LFUN_INSET_DIALOG_UPDATE:
- GridInsetMailer(*this).updateDialog(&bv);
+ GridInsetMailer(*this).updateDialog(&cur.bv());
return DispatchResult(false);
// insert file functions
return DispatchResult(true, FINISHED);
case LFUN_CELL_SPLIT:
- //recordUndo(bv, Undo::ATOMIC);
+ //recordUndo(cur, Undo::ATOMIC);
splitCell(cur);
return DispatchResult(true, FINISHED);
case LFUN_BREAKLINE: {
- //recordUndo(bv, Undo::INSERT);
+ //recordUndo(cur, Undo::INSERT);
row_type const r = cur.row();
addRow(r);
}
default:
- return MathNestInset::priv_dispatch(bv, cmd);
+ return MathNestInset::priv_dispatch(cur, cmd);
}
}
protected:
///
- DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
/// returns x offset of cell compared to inset
int cellXOffset(idx_type idx) const;
/// returns y offset of cell compared to inset
#ifdef WITH_WARNINGS
#warning temporarily disabled
- //if (selection()) {
+ //if (cur.selection()) {
// MathArray ar;
- // selGet(ar);
+ // selGet(cur.ar);
// lyxerr << "use selection: " << ar << endl;
// insert(pipeThroughExtern(lang, extra, ar));
// return;
if (getType() == "simple") {
size_type pos = cur.cell().find_last(eq);
MathArray ar;
- if (mathcursor && mathcursor->selection()) {
- asArray(mathcursor->grabAndEraseSelection(cur), ar);
+ if (inMathed() && cur.selection()) {
+ asArray(mathcursor::grabAndEraseSelection(cur), ar);
} else if (pos == cur.cell().size()) {
ar = cur.cell();
lyxerr << "use whole cell: " << ar << endl;
DispatchResult
-MathHullInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
- CursorSlice & cur = cursorTip(bv);
switch (cmd.action) {
case LFUN_BREAKLINE:
cur.pos() = 0;
return DispatchResult(true, FINISHED);
}
- return MathGridInset::priv_dispatch(bv, cmd);
+ return MathGridInset::priv_dispatch(cur, cmd);
case LFUN_MATH_NUMBER:
//lyxerr << "toggling all numbers" << endl;
if (display()) {
- //recordUndo(bv, Undo::INSERT);
+ //recordUndo(cur, Undo::INSERT);
bool old = numberedType();
if (type_ == "multline")
numbered(nrows() - 1, !old);
else
for (row_type row = 0; row < nrows(); ++row)
numbered(row, !old);
- //bv->owner()->message(old ? _("No number") : _("Number"));
+ //cur.bv()->owner()->message(old ? _("No number") : _("Number"));
}
return DispatchResult(true, true);
case LFUN_MATH_NONUMBER:
if (display()) {
row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
- //recordUndo(bv, Undo::INSERT);
+ //recordUndo(cur, Undo::INSERT);
bool old = numbered(r);
- //bv->owner()->message(old ? _("No number") : _("Number"));
+ //cur.bv()->owner()->message(old ? _("No number") : _("Number"));
numbered(r, !old);
}
return DispatchResult(true, true);
}
case LFUN_MATH_EXTERN:
- doExtern(bv.fullCursor(), cmd);
+ doExtern(cur, cmd);
return DispatchResult(true, FINISHED);
case LFUN_MATH_MUTATE: {
}
default:
- return MathGridInset::priv_dispatch(bv, cmd);
+ return MathGridInset::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
std::string eolString(row_type row, bool fragile) const;
#ifndef MATH_INSET_H
#define MATH_INSET_H
-#include "cursor.h"
#include "insets/insetbase.h"
#include <string>
class MathMacro;
class MathPosFinder;
class Dimension;
+class LCursor;
class TextPainter;
class TextMetricsInfo;
class ReplaceData;
virtual void mathmlize(MathMLStream &) const;
/// write content as something readable by Octave
virtual void octave(OctaveStream &) const;
- /// describe content if cursor inside
- virtual void infoize(std::ostream &) const {}
- /// describe content if cursor behind
- virtual void infoize2(std::ostream &) const {}
/// plain ascii output
virtual int plaintext(std::ostream & os, OutputParams const &) const;
/// linuxdoc output
#include "math_macrotable.h"
#include "math_macrotemplate.h"
#include "math_mathmlstream.h"
+#include "cursor.h"
#include "debug.h"
#include "LaTeXFeatures.h"
#include "debug.h"
#include "funcrequest.h"
#include "LColor.h"
+#include "undo.h"
+
#include "frontends/Painter.h"
bool MathNestInset::editing() const
{
- return mathcursor && mathcursor->isInside(this);
+ return inMathed() && mathcursor::isInside(this);
}
MathArray MathNestInset::glue() const
{
MathArray ar;
- for (unsigned i = 0; i < nargs(); ++i)
+ for (size_t i = 0; i < nargs(); ++i)
ar.append(cell(i));
return ar;
}
void MathNestInset::write(WriteStream & os) const
{
os << '\\' << name().c_str();
- for (unsigned i = 0; i < nargs(); ++i)
+ for (size_t i = 0; i < nargs(); ++i)
os << '{' << cell(i) << '}';
if (nargs() == 0)
os.pendingSpace(true);
void MathNestInset::normalize(NormalStream & os) const
{
os << '[' << name().c_str();
- for (unsigned i = 0; i < nargs(); ++i)
+ for (size_t i = 0; i < nargs(); ++i)
os << ' ' << cell(i);
os << ']';
}
DispatchResult
-MathNestInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
- CursorSlice & cur = cursorTip(bv);
- switch (cmd.action) {
+ //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
+ // << " arg: '" << cmd.argument
+ // << "' x: '" << cmd.x
+ // << " y: '" << cmd.y
+ // << "' button: " << cmd.button() << endl;
- case LFUN_PASTE: {
- MathArray ar;
- mathed_parse_cell(ar, cmd.argument);
- cur.cell().insert(cur.pos(), ar);
- cur.pos() += ar.size();
- return DispatchResult(true, true);
- }
+ switch (cmd.action) {
- case LFUN_PASTESELECTION:
- return dispatch(bv, FuncRequest(LFUN_PASTE, bv.getClipboard()));
+ case LFUN_PASTE: {
+ MathArray ar;
+ mathed_parse_cell(ar, cmd.argument);
+ cur.cell().insert(cur.pos(), ar);
+ cur.pos() += ar.size();
+ return DispatchResult(true, true);
+ }
- case LFUN_MOUSE_PRESS:
- if (cmd.button() == mouse_button::button2)
- return priv_dispatch(bv, FuncRequest(LFUN_PASTESELECTION));
- return DispatchResult(false);
+ case LFUN_PASTESELECTION:
+ return dispatch(cur, FuncRequest(LFUN_PASTE, cur.bv().getClipboard()));
+
+ case LFUN_MOUSE_PRESS:
+ if (cmd.button() == mouse_button::button2)
+ return priv_dispatch(cur, FuncRequest(LFUN_PASTESELECTION));
+ return DispatchResult(false);
+
+ case LFUN_RIGHTSEL:
+ cur.selection() = true; // fall through...
+ case LFUN_RIGHT:
+ return mathcursor::right(cur, cur.selection()) ?
+ DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
+ //lyxerr << "calling scroll 20" << endl;
+ //scroll(&cur.bv(), 20);
+ // write something to the minibuffer
+ //cur.bv().owner()->message(mathcursor::info());
+
+ case LFUN_LEFTSEL:
+ cur.selection() = true; // fall through
+ case LFUN_LEFT:
+ return mathcursor::left(cur, cur.selection()) ?
+ DispatchResult(true, true) : DispatchResult(false, FINISHED);
+
+ case LFUN_UPSEL:
+ cur.selection() = true; // fall through
+ case LFUN_UP:
+ return mathcursor::up(cur, cur.selection()) ?
+ DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
+
+ case LFUN_DOWNSEL:
+ cur.selection() = true; // fall through
+ case LFUN_DOWN:
+ return mathcursor::down(cur, cur.selection()) ?
+ DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
+
+ case LFUN_SELFINSERT:
+ if (!cmd.argument.empty()) {
+ recordUndo(cur, Undo::ATOMIC);
+ if (cmd.argument.size() == 1) {
+ if (mathcursor::interpret(cur, cmd.argument[0]))
+ return DispatchResult(true, true);
+ else
+ return DispatchResult(false, FINISHED_RIGHT);
+ }
+ mathcursor::insert(cur, cmd.argument);
+ }
+ break;
- default:
- return MathInset::priv_dispatch(bv, cmd);
+ default:
+ return MathInset::priv_dispatch(cur, cmd);
}
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
/// we store the cells in a vector
typedef std::vector<MathArray> cells_type;
#include "math_oversetinset.h"
#include "math_data.h"
#include "math_mathmlstream.h"
-
+#include "cursor.h"
using std::max;
using std::auto_ptr;
#include "math_rootinset.h"
#include "math_data.h"
#include "math_mathmlstream.h"
+#include "cursor.h"
#include "LColor.h"
-#include "frontends/Painter.h"
+#include "frontends/Painter.h"
using std::max;
using std::auto_ptr;
+
MathRootInset::MathRootInset()
: MathNestInset(2)
{}
#include "math_support.h"
#include "math_symbolinset.h"
#include "dispatchresult.h"
+#include "cursor.h"
#include "debug.h"
#include "funcrequest.h"
#include <boost/assert.hpp>
-
using std::string;
using std::max;
using std::auto_ptr;
using std::endl;
+
MathScriptInset::MathScriptInset()
: MathNestInset(3), limits_(0)
{
DispatchResult
-MathScriptInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathScriptInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
{
if (cmd.action == LFUN_MATH_LIMITS) {
if (!cmd.argument.empty()) {
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
/// returns x offset for main part
int dxx() const;
#include "math_undersetinset.h"
#include "math_data.h"
#include "math_mathmlstream.h"
-
+#include "cursor.h"
using std::max;
using std::auto_ptr;
+
auto_ptr<InsetBase> MathUndersetInset::clone() const
{
return auto_ptr<InsetBase>(new MathUndersetInset(*this));
#include "math_factory.h"
#include "BufferView.h"
+#include "cursor.h"
#include "dispatchresult.h"
#include "debug.h"
#include "funcrequest.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
-
using std::string;
using std::auto_ptr;
using std::endl;
+
RefInset::RefInset()
: CommandInset("ref")
{}
}
-DispatchResult
-RefInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+DispatchResult RefInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY:
MathArray ar;
if (!createMathInset_fromDialogStr(cmd.argument, ar))
return DispatchResult(false);
-
*this = *ar[0].nucleus()->asRefInset();
-
return DispatchResult(true, true);
}
- break;
+ return DispatchResult(false);
+
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3) {
lyxerr << "trying to goto ref" << cell(0) << endl;
- bv.dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
+ cur.bv().dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
return DispatchResult(true, true);
}
if (cmd.button() == mouse_button::button1) {
// Eventually trigger dialog with button 3
// not 1
string const data = createDialogStr("ref");
- bv.owner()->getDialogs().show("ref", data, this);
+ cur.bv().owner()->getDialogs().show("ref", data, this);
return DispatchResult(true, true);
}
- break;
+ return DispatchResult(false);
+
case LFUN_MOUSE_PRESS:
case LFUN_MOUSE_MOTION:
// eat other mouse commands
return DispatchResult(true, true);
+
default:
- return CommandInset::priv_dispatch(bv, cmd);
+ return CommandInset::priv_dispatch(cur, cmd);
}
- // not our business
- return DispatchResult(false);
}
///
virtual
DispatchResult
- priv_dispatch(BufferView & bv, FuncRequest const & cmd);
+ priv_dispatch(LCursor & cur, FuncRequest const & cmd);
};
#endif
paintBackground();
// paint the selection background
- if (bv_.selection().set() && &text_ == bv_.fullCursor().innerText())
+ if (bv_.cursor().selection() && &text_ == bv_.cursor().innerText())
paintSelection();
// vertical lines for appendix
bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
// the current selection
- int const startx = text_.cursorX(bv_.selStart());
- int const endx = text_.cursorX(bv_.selEnd());
- int const starty = text_.cursorY(bv_.selStart());
- int const endy = text_.cursorY(bv_.selEnd());
- ParagraphList::iterator startpit = text_.getPar(bv_.selStart());
- ParagraphList::iterator endpit = text_.getPar(bv_.selEnd());
- RowList::iterator startrow = startpit->getRow(bv_.selStart().pos());
- RowList::iterator endrow = endpit->getRow(bv_.selEnd().pos());
+ LCursor const & cur = bv_.cursor();
+ int const startx = text_.cursorX(cur.selStart());
+ int const endx = text_.cursorX(cur.selEnd());
+ int const starty = text_.cursorY(cur.selStart());
+ int const endy = text_.cursorY(cur.selEnd());
+ ParagraphList::iterator startpit = text_.getPar(cur.selStart());
+ ParagraphList::iterator endpit = text_.getPar(cur.selEnd());
+ RowList::iterator startrow = startpit->getRow(cur.selStart().pos());
+ RowList::iterator endrow = endpit->getRow(cur.selEnd().pos());
int const h = row_.height();
int const row_y = pit_->y + row_.y_offset();
}
if (((startpit != pit_ && startrow != rit_)
- || bv_.selStart().pos() <= pos) &&
+ || cur.selStart().pos() <= pos) &&
((endpit != pit_ && endrow != rit_)
- || pos < bv_.selEnd().pos())) {
+ || pos < cur.selEnd().pos())) {
// Here we do not use x_ as xo_ was added to x_.
pain_.fillRectangle(int(old_tmpx), yo_,
int(tmpx - old_tmpx + 1), h, LColor::selection);
// convenience function
void LyXText::redoParagraph()
{
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
redoParagraph(cursorPar());
setCursorIntern(cursor().par(), cursor().pos());
}
setCursor(from.par(), from.pos());
if (to == from)
return;
- bv()->resetAnchor();
+ bv()->cursor().resetAnchor();
setCursor(to.par(), to.pos());
- bv()->setSelection();
+ bv()->cursor().setSelection();
}
// selection is currently set
bool LyXText::selectWordWhenUnderCursor(word_location loc)
{
- if (!bv()->selection().set()) {
- selectWord(loc);
- return bv()->selection().set();
- }
- return false;
+ if (bv()->cursor().selection())
+ return false;
+ selectWord(loc);
+ return bv()->cursor().selection();
}
void LyXText::acceptChange()
{
- if (!bv()->selection().set() && cursorPar()->size())
+ LCursor & cur = bv()->cursor();
+ if (!cur.selection() && cursorPar()->size())
return;
- if (bv()->selStart().par() == bv()->selEnd().par()) {
- CursorSlice const & startc = bv()->selStart();
- CursorSlice const & endc = bv()->selEnd();
+ if (cur.selStart().par() == cur.par()) {
+ CursorSlice const & startc = cur.selStart();
+ CursorSlice const & endc = cur.selEnd();
recordUndo(Undo::INSERT, this, startc.par());
getPar(startc)->acceptChange(startc.pos(), endc.pos());
finishUndo();
- bv()->clearSelection();
+ cur.clearSelection();
redoParagraph(getPar(startc));
setCursorIntern(startc.par(), 0);
}
void LyXText::rejectChange()
{
- if (!bv()->selection().set() && cursorPar()->size())
+ LCursor & cur = bv()->cursor();
+ if (!cur.selection() && cursorPar()->size())
return;
- if (bv()->selStart().par() == bv()->selEnd().par()) {
- CursorSlice const & startc = bv()->selStart();
- CursorSlice const & endc = bv()->selEnd();
+ if (cur.selStart().par() == cur.selEnd().par()) {
+ CursorSlice const & startc = cur.selStart();
+ CursorSlice const & endc = cur.selEnd();
recordUndo(Undo::INSERT, this, startc.par());
getPar(startc)->rejectChange(startc.pos(), endc.pos());
finishUndo();
- bv()->clearSelection();
+ cur.clearSelection();
redoParagraph(getPar(startc));
setCursorIntern(startc.par(), 0);
}
// Delete from cursor up to the end of the current or next word.
void LyXText::deleteWordForward()
{
+ LCursor & cur = bv()->cursor();
if (cursorPar()->empty())
- cursorRight(bv());
+ cursorRight(true);
else {
CursorSlice tmpcursor = cursor();
- bv()->selection().set(true); // to avoid deletion
+ cur.selection() = true; // to avoid deletion
cursorRightOneWord();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
- bv()->resetAnchor();
+ cur.resetAnchor();
cursor() = tmpcursor;
- bv()->setSelection();
+ cur.setSelection();
cutSelection(true, false);
}
}
// Delete from cursor to start of current or prior word.
void LyXText::deleteWordBackward()
{
+ LCursor & cur = bv()->cursor();
if (cursorPar()->empty())
- cursorLeft(bv());
+ cursorLeft(true);
else {
CursorSlice tmpcursor = cursor();
- bv()->selection().set(true); // to avoid deletion
+ cur.selection() = true; // to avoid deletion
cursorLeftOneWord();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
- bv()->resetAnchor();
+ cur.resetAnchor();
cursor() = tmpcursor;
- bv()->setSelection();
+ cur.setSelection();
cutSelection(true, false);
}
}
// Kill to end of line.
void LyXText::deleteLineForward()
{
+ LCursor & cur = bv()->cursor();
if (cursorPar()->empty()) {
// Paragraph is empty, so we just go to the right
- cursorRight(bv());
+ cursorRight(true);
} else {
CursorSlice tmpcursor = cursor();
- bv()->selection().set(true); // to avoid deletion
+ cur.selection() = true; // to avoid deletion
cursorEnd();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
- bv()->resetAnchor();
+ cur.resetAnchor();
cursor() = tmpcursor;
- bv()->setSelection();
+ cur.setSelection();
// What is this test for ??? (JMarc)
- if (!bv()->selection().set())
+ if (!cur.selection())
deleteWordForward();
else
cutSelection(true, false);
void LyXText::changeCase(LyXText::TextCase action)
{
+ LCursor & cur = bv()->cursor();
CursorSlice from;
CursorSlice to;
- if (bv()->selection().set()) {
- from = bv()->selStart();
- to = bv()->selEnd();
+ if (cur.selection()) {
+ from = cur.selStart();
+ to = cur.selEnd();
} else {
from = cursor();
getWord(from, to, lyx::PARTIAL_WORD);
string LyXText::selectionAsString(Buffer const & buffer, bool label) const
{
- if (!bv()->selection().set())
+ LCursor & cur = bv()->cursor();
+ if (!cur.selection())
return string();
// should be const ...
- ParagraphList::iterator startpit = getPar(bv()->selStart());
- ParagraphList::iterator endpit = getPar(bv()->selEnd());
- size_t const startpos = bv()->selStart().pos();
- size_t const endpos = bv()->selEnd().pos();
+ ParagraphList::iterator startpit = getPar(cur.selStart());
+ ParagraphList::iterator endpit = getPar(cur.selEnd());
+ size_t const startpos = cur.selStart().pos();
+ size_t const endpos = cur.selEnd().pos();
if (startpit == endpit)
return startpit->asString(buffer, startpos, endpos, label);
void LyXText::fullRebreak()
{
redoParagraphs(paragraphs().begin(), paragraphs().end());
- bv()->resetAnchor();
+ bv()->cursor().resetAnchor();
}
CursorSlice & LyXText::cursor()
{
- return bv()->cursor();
+ return bv()->cursor().cursor_.back();
}
CursorSlice const & LyXText::cursor() const
{
- return bv()->cursor();
+ return bv()->cursor().cursor_.back();
}
CursorSlice & LyXText::anchor()
{
- return bv()->anchor();
+ return bv()->cursor().anchor_.back();
}
CursorSlice const & LyXText::anchor() const
{
- return bv()->anchor();
+ return bv()->cursor().anchor_.back();
}
redoParagraphs(beg, end);
setCursorIntern(0, 0);
- bv()->resetAnchor();
+ bv()->cursor().resetAnchor();
updateCounters();
}
return;
}
- ParagraphList::iterator start = getPar(bv()->selStart().par());
- ParagraphList::iterator end = boost::next(getPar(bv()->selEnd().par()));
+ ParagraphList::iterator start =
+ getPar(bv()->cursor().selStart().par());
+ ParagraphList::iterator end =
+ boost::next(getPar(bv()->cursor().selEnd().par()));
ParagraphList::iterator endpit = setLayout(start, end, layout);
redoParagraphs(start, endpit);
ParagraphList::iterator & beg,
ParagraphList::iterator & end)
{
- if (!text.bv()->selection().set()) {
+ if (!text.bv()->cursor().selection()) {
beg = text.cursorPar();
end = boost::next(beg);
} else {
- beg = text.getPar(text.bv()->selStart());
- end = boost::next(text.getPar(text.bv()->selEnd()));
+ beg = text.getPar(text.bv()->cursor().selStart());
+ end = boost::next(text.getPar(text.bv()->cursor().selEnd()));
}
}
// set font over selection and make a total rebreak of those paragraphs
void LyXText::setFont(LyXFont const & font, bool toggleall)
{
+ LCursor & cur = bv()->cursor();
// if there is no selection just set the current_font
- if (!bv()->selection().set()) {
+ if (!cur.selection()) {
// Determine basis font
LyXFont layoutfont;
if (cursor().pos() < cursorPar()->beginOfBody())
}
// ok we have a selection.
- recUndo(bv()->selStart().par(), bv()->selEnd().par());
+ recUndo(cur.selStart().par(), cur.selEnd().par());
freezeUndo();
- ParagraphList::iterator beg = getPar(bv()->selStart().par());
- ParagraphList::iterator end = getPar(bv()->selEnd().par());
+ ParagraphList::iterator beg = getPar(cur.selStart().par());
+ ParagraphList::iterator end = getPar(cur.selEnd().par());
- PosIterator pos(¶graphs(), beg, bv()->selStart().pos());
- PosIterator posend(¶graphs(), end, bv()->selEnd().pos());
+ PosIterator pos(¶graphs(), beg, cur.selStart().pos());
+ PosIterator posend(¶graphs(), end, cur.selEnd().pos());
BufferParams const & params = bv()->buffer()->params();
// Implicit selections are cleared afterwards
//and cursor is set to the original position.
if (implicitSelection) {
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
cursor() = resetCursor;
- bv()->resetAnchor();
+ bv()->cursor().resetAnchor();
}
}
string LyXText::getStringToIndex()
{
+ LCursor & cur = bv()->cursor();
// Try implicit word selection
// If there is a change in the language the implicit word selection
// is disabled.
selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
string idxstring;
- if (!bv()->selection().set())
+ if (!cur.selection())
bv()->owner()->message(_("Nothing to index!"));
- else if (bv()->selStart().par() != bv()->selEnd().par())
+ else if (cur.selStart().par() != cur.selEnd().par())
bv()->owner()->message(_("Cannot index more than one paragraph!"));
else
idxstring = selectionAsString(*bv()->buffer(), false);
// Reset cursors to their original position.
cursor() = reset_cursor;
- bv()->resetAnchor();
+ cur.resetAnchor();
// Clear the implicit selection.
if (implicitSelection)
- bv()->clearSelection();
+ cur.clearSelection();
return idxstring;
}
void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
string const & labelwidthstring, bool noindent)
{
+ LCursor & cur = bv()->cursor();
// make sure that the depth behind the selection are restored, too
- ParagraphList::iterator undopit = undoSpan(getPar(bv()->selEnd()));
- recUndo(bv()->selStart().par(), parOffset(undopit) - 1);
+ ParagraphList::iterator undopit = undoSpan(getPar(cur.selEnd()));
+ recUndo(cur.selStart().par(), parOffset(undopit) - 1);
- ParagraphList::reverse_iterator pit(getPar(bv()->selEnd().par()));
- ParagraphList::reverse_iterator beg(getPar(bv()->selStart().par()));
+ ParagraphList::reverse_iterator pit(getPar(cur.selEnd().par()));
+ ParagraphList::reverse_iterator beg(getPar(cur.selStart().par()));
for (--pit; pit != beg; ++pit) {
ParagraphParameters & params = pit->params();
params.noindent(noindent);
}
- redoParagraphs(getPar(bv()->selStart()), undopit);
+ redoParagraphs(getPar(cur.selStart()), undopit);
}
void LyXText::cutSelection(bool doclear, bool realcut)
{
+ LCursor & cur = bv()->cursor();
// Stuff what we got on the clipboard. Even if there is no selection.
// There is a problem with having the stuffing here in that the
bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
// This doesn't make sense, if there is no selection
- if (!bv()->selection().set())
+ if (!cur.selection())
return;
- // OK, we have a selection. This is always between bv()->selStart()
- // and bv()->selEnd()
+ // OK, we have a selection. This is always between cur.selStart()
+ // and cur.selEnd()
// make sure that the depth behind the selection are restored, too
- ParagraphList::iterator begpit = getPar(bv()->selStart().par());
- ParagraphList::iterator endpit = getPar(bv()->selEnd().par());
+ ParagraphList::iterator begpit = getPar(cur.selStart().par());
+ ParagraphList::iterator endpit = getPar(cur.selEnd().par());
ParagraphList::iterator undopit = undoSpan(endpit);
- recUndo(bv()->selStart().par(), parOffset(undopit) - 1);
+ recUndo(cur.selStart().par(), parOffset(undopit) - 1);
- int endpos = bv()->selEnd().pos();
+ int endpos = cur.selEnd().pos();
BufferParams const & bufparams = bv()->buffer()->params();
boost::tie(endpit, endpos) = realcut ?
CutAndPaste::cutSelection(bufparams,
paragraphs(),
begpit , endpit,
- bv()->selStart().pos(), endpos,
+ cur.selStart().pos(), endpos,
bufparams.textclass,
doclear)
: CutAndPaste::eraseSelection(bufparams,
paragraphs(),
begpit, endpit,
- bv()->selStart().pos(), endpos,
+ cur.selStart().pos(), endpos,
doclear);
// sometimes necessary
if (doclear)
cursor().par(parOffset(endpit));
// need a valid cursor. (Lgb)
- bv()->clearSelection();
+ cur.clearSelection();
updateCounters();
}
void LyXText::copySelection()
{
+ LCursor & cur = bv()->cursor();
// stuff the selection onto the X clipboard, from an explicit copy request
bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
// this doesnt make sense, if there is no selection
- if (!bv()->selection().set())
+ if (!cur.selection())
return;
- // ok we have a selection. This is always between bv()->selStart()
+ // ok we have a selection. This is always between cur.selStart()
// and sel_end cursor
// copy behind a space if there is one
- while (getPar(bv()->selStart())->size() > bv()->selStart().pos()
- && getPar(bv()->selStart())->isLineSeparator(bv()->selStart().pos())
- && (bv()->selStart().par() != bv()->selEnd().par()
- || bv()->selStart().pos() < bv()->selEnd().pos()))
- bv()->selStart().pos(bv()->selStart().pos() + 1);
-
- CutAndPaste::copySelection(getPar(bv()->selStart().par()),
- getPar(bv()->selEnd().par()),
- bv()->selStart().pos(),
- bv()->selEnd().pos(),
+ while (getPar(cur.selStart())->size() > cur.selStart().pos()
+ && getPar(cur.selStart())->isLineSeparator(cur.selStart().pos())
+ && (cur.selStart().par() != cur.selEnd().par()
+ || cur.selStart().pos() < cur.selEnd().pos()))
+ cur.selStart().pos(cur.selStart().pos() + 1);
+
+ CutAndPaste::copySelection(getPar(cur.selStart().par()),
+ getPar(cur.selEnd().par()),
+ cur.selStart().pos(),
+ cur.selEnd().pos(),
bv()->buffer()->params().textclass);
}
void LyXText::pasteSelection(size_t sel_index)
{
+ LCursor & cur = bv()->cursor();
// this does not make sense, if there is nothing to paste
if (!CutAndPaste::checkPastePossible())
return;
redoParagraphs(cursorPar(), endpit);
- bv()->clearSelection();
- bv()->resetAnchor();
+ cur.clearSelection();
+ cur.resetAnchor();
setCursor(ppp.first, ppp.second);
- bv()->setSelection();
+ cur.setSelection();
updateCounters();
}
if (!length)
return;
- bv()->resetAnchor();
+ LCursor & cur = bv()->cursor();
+ cur.resetAnchor();
while (length--)
cursorRight(true);
- bv()->setSelection();
+ cur.setSelection();
}
// simple replacing. The font of the first selected character is used
void LyXText::replaceSelectionWithString(string const & str)
{
- recUndo(cursor().par());
+ LCursor & cur = bv()->cursor();
+ recUndo(cur.par());
freezeUndo();
// Get font setting before we cut
- pos_type pos = bv()->selEnd().pos();
- LyXFont const font = getPar(bv()->selStart())
+ pos_type pos = cur.selEnd().pos();
+ LyXFont const font = getPar(cur.selStart())
->getFontSettings(bv()->buffer()->params(),
- bv()->selStart().pos());
+ cur.selStart().pos());
// Insert the new string
string::const_iterator cit = str.begin();
string::const_iterator end = str.end();
for (; cit != end; ++cit) {
- getPar(bv()->selEnd())->insertChar(pos, (*cit), font);
+ getPar(cur.selEnd())->insertChar(pos, (*cit), font);
++pos;
}
// needed to insert the selection
void LyXText::insertStringAsLines(string const & str)
{
+ LCursor & cur = bv()->cursor();
ParagraphList::iterator pit = cursorPar();
pos_type pos = cursor().pos();
ParagraphList::iterator endpit = boost::next(cursorPar());
recUndo(cursor().par());
// only to be sure, should not be neccessary
- bv()->clearSelection();
+ cur.clearSelection();
bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
redoParagraphs(cursorPar(), endpit);
- bv()->resetAnchor();
+ cur.resetAnchor();
setCursor(pit, pos);
- bv()->setSelection();
+ cur.setSelection();
}
return;
// now some strict checking
- ParagraphList::iterator pit = getPar(par);
- Row const & row = *pit->getRow(pos);
+ Paragraph & para = *getPar(par);
+ Row const & row = *para.getRow(pos);
pos_type const end = row.endpos();
// None of these should happen, but we're scaredy-cats
pos = 0;
cur.pos(0);
BOOST_ASSERT(false);
- } else if (pos > pit->size()) {
+ } else if (pos > para.size()) {
lyxerr << "dont like 1, pos: " << pos
- << " size: " << pit->size()
+ << " size: " << para.size()
<< " row.pos():" << row.pos()
<< " paroffset: " << par << endl;
pos = 0;
BOOST_ASSERT(false);
} else if (pos < row.pos()) {
lyxerr << "dont like 3 please report pos:" << pos
- << " size: " << pit->size()
+ << " size: " << para.size()
<< " row.pos():" << row.pos()
<< " paroffset: " << par << endl;
pos = row.pos();
pos_type pos, bool setfont, bool boundary)
{
setCursor(cursor(), par, pos, boundary);
- bv()->x_target(cursorX() + xo_);
+ bv()->cursor().x_target(cursorX() + xo_);
if (setfont)
setCurrentFont();
}
void LyXText::setCurrentFont()
{
- pos_type pos = cursor().pos();
+ LCursor & cur = bv()->cursor();
+ pos_type pos = cur.pos();
ParagraphList::iterator pit = cursorPar();
if (cursor().boundary() && pos > 0)
// If lastrow is false, we don't need to compute
// the value of rtl.
- bool const rtl = (lastrow)
+ bool const rtl = lastrow
? pit->isRightToLeftPar(bv()->buffer()->params())
: false;
if (lastrow &&
InsetOld * inset = cursorPar()->getInset(cursor().pos());
if (!isHighlyEditableInset(inset))
return false;
- inset->edit(bv(), front);
+ inset->edit(bv()->cursor(), front);
return true;
}
return DispatchResult(true, true);
cursorRight(true);
if (!selecting)
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
return DispatchResult(true);
}
return DispatchResult(false, FINISHED);
cursorLeft(true);
if (!selecting)
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
if (activate_inset && checkAndActivateInset(front))
return DispatchResult(true, true);
return DispatchResult(true);
if (cursorPar() == firstPar() && cursorRow() == firstRow())
return DispatchResult(false, FINISHED_UP);
cursorUp(false);
- bv()->clearSelection();
+ bv()->cursor().clearSelection();
return DispatchResult(true);
}
DispatchResult LyXText::moveDown()
{
+ LCursor & cur = bv()->cursor();
if (cursorPar() == lastPar() && cursorRow() == lastRow())
return DispatchResult(false, FINISHED_DOWN);
cursorDown(false);
- bv()->clearSelection();
+ cur.clearSelection();
return DispatchResult(true);
}
bool LyXText::cursorLeft(bool internal)
{
- if (cursor().pos() > 0) {
- bool boundary = cursor().boundary();
- setCursor(cursor().par(), cursor().pos() - 1, true, false);
+ LCursor & cur = bv()->cursor();
+ if (cur.pos() > 0) {
+ bool boundary = cur.boundary();
+ setCursor(cur.par(), cur.pos() - 1, true, false);
if (!internal && !boundary &&
- bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor().pos() + 1))
- setCursor(cursor().par(), cursor().pos() + 1, true, true);
+ bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
+ setCursor(cur.par(), cur.pos() + 1, true, true);
return true;
}
- if (cursor().par() != 0) {
+ if (cur.par() != 0) {
// steps into the paragraph above
- setCursor(cursor().par() - 1, boost::prior(cursorPar())->size());
+ setCursor(cur.par() - 1, boost::prior(cursorPar())->size());
return true;
}
bool LyXText::cursorRight(bool internal)
{
- if (!internal && cursor().boundary()) {
- setCursor(cursor().par(), cursor().pos(), true, false);
+ LCursor & cur = bv()->cursor();
+ if (!internal && cur.boundary()) {
+ setCursor(cur.par(), cur.pos(), true, false);
return true;
}
- if (cursor().pos() != cursorPar()->size()) {
- setCursor(cursor().par(), cursor().pos() + 1, true, false);
- if (!internal && bidi.isBoundary(*bv()->buffer(), *cursorPar(),
- cursor().pos()))
- setCursor(cursor().par(), cursor().pos(), true, true);
+ if (cur.pos() != cur.lastpos()) {
+ setCursor(cur.par(), cur.pos() + 1, true, false);
+ if (!internal && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
+ cur.pos()))
+ setCursor(cur.par(), cur.pos(), true, true);
return true;
}
- if (cursor().par() + 1 != int(paragraphs().size())) {
- setCursor(cursor().par() + 1, 0);
+ if (cur.par() + 1 != int(paragraphs().size())) {
+ setCursor(cur.par() + 1, 0);
return true;
}
void LyXText::cursorUp(bool selecting)
{
+ LCursor & cur = bv()->cursor();
Row const & row = *cursorRow();
- int x = bv()->x_target() - xo_;
+ int x = cur.x_target() - xo_;
int y = cursorY() - row.baseline() - 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
int y_abs = y + yo_ - bv()->top_y();
- InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y_abs);
+ InsetOld * inset_hit = checkInsetHit(cur.x_target(), y_abs);
if (inset_hit && isHighlyEditableInset(inset_hit))
- inset_hit->edit(bv(), bv()->x_target(), y_abs);
+ inset_hit->edit(cur, cur.x_target(), y_abs);
}
}
void LyXText::cursorDown(bool selecting)
{
+ LCursor & cur = bv()->cursor();
Row const & row = *cursorRow();
- int x = bv()->x_target() - xo_;
+ int x = cur.x_target() - xo_;
int y = cursorY() - row.baseline() + row.height() + 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
int y_abs = y + yo_ - bv()->top_y();
- InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y_abs);
+ InsetOld * inset_hit = checkInsetHit(cur.x_target(), y_abs);
if (inset_hit && isHighlyEditableInset(inset_hit))
- inset_hit->edit(bv(), bv()->x_target(), y_abs);
+ inset_hit->edit(cur, cur.x_target(), y_abs);
}
}
// check also if we don't want to set the cursor on a spot behind the
// pagragraph because we erased the last character.
- if (cur.pos() > getPar(cur)->size())
- cur.pos(getPar(cur)->size());
+ if (cur.pos() > cur.lastpos())
+ cur.pos() = cur.lastpos();
}
return false;
// Would be wrong to delete anything if we have a selection.
- if (bv()->selection().set())
+ if (bv()->cursor().selection())
return false;
// Don't do anything if the cursor is invalid
if (old_cursor.par() == -1)
return false;
+#if 0
// We allow all kinds of "mumbo-jumbo" when freespacing.
ParagraphList::iterator const old_pit = getPar(old_cursor);
if (old_pit->isFreeSpacing())
bv()->resetAnchor();
}
return false;
+#endif
}
}
- void moveCursor(BufferView * bv, bool selecting)
+ void moveCursor(LCursor & cur, bool selecting)
{
- if (selecting || bv->selection().mark())
- bv->setSelection();
-
- if (!bv->selection().set())
- bv->haveSelection(false);
- bv->switchKeyMap();
+ if (selecting || cur.mark())
+ cur.setSelection();
+ if (!cur.selection())
+ cur.bv().haveSelection(false);
+ cur.bv().switchKeyMap();
}
void finishChange(BufferView * bv, bool selecting = false)
{
finishUndo();
- moveCursor(bv, selecting);
+ moveCursor(bv->cursor(), selecting);
bv->owner()->view_state_changed();
}
}
-void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
- bool same_content)
+void LyXText::gotoInset(vector<InsetOld::Code> const & codes, bool same_content)
{
- bv()->clearSelection();
+ LCursor & cur = bv()->cursor();
+ cur.clearSelection();
string contents;
- if (same_content && cursor().pos() < cursorPar()->size()
- && cursorPar()->isInset(cursor().pos())) {
- InsetOld const * inset = cursorPar()->getInset(cursor().pos());
+ if (same_content
+ && cur.pos() < cur.lastpos()
+ && cur.paragraph().isInset(cur.pos())) {
+ InsetOld const * inset = cur.paragraph().getInset(cur.pos());
if (find(codes.begin(), codes.end(), inset->lyxCode())
!= codes.end())
contents = static_cast<InsetCommand const *>(inset)->getContents();
}
if (!gotoNextInset(codes, contents)) {
- if (cursor().pos() || cursorPar() != paragraphs().begin()) {
+ if (cur.pos() || cur.par() != 0) {
CursorSlice tmp = cursor();
- cursor().par(0);
- cursor().pos(0);
+ cur.par() = 0;
+ cur.pos() = 0;
if (!gotoNextInset(codes, contents)) {
cursor() = tmp;
- bv()->owner()->message(_("No more insets"));
+ cur.bv().owner()->message(_("No more insets"));
}
} else {
- bv()->owner()->message(_("No more insets"));
+ cur.bv().owner()->message(_("No more insets"));
}
}
- bv()->update();
- bv()->resetAnchor();
+ cur.bv().update();
+ cur.resetAnchor();
}
void LyXText::cursorPrevious()
{
-
+ LCursor & cur = bv()->cursor();
RowList::iterator crit = cursorRow();
- ParagraphList::iterator cpar = cursorPar();
+ lyx::paroffset_type cpar = cur.par();
- int x = bv()->x_target() - xo_;
+ int x = bv()->cursor().x_target() - xo_;
int y = bv()->top_y() - yo_;
setCursorFromCoordinates(x, y);
- if (cpar == cursorPar() && crit == cursorRow()) {
+ if (cpar == cur.par() && crit == cursorRow()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the previous row instead.
cursorUp(true);
RowList::iterator crit = cursorRow();
ParagraphList::iterator cpar = cursorPar();
- int x = bv()->x_target() - xo_;
+ int x = bv()->cursor().x_target() - xo_;
int y = bv()->top_y() + bv()->workHeight() - yo_;
setCursorFromCoordinates(x, y);
return;
bool gotsel = false;
- if (bv->selection().set()) {
+ if (bv->cursor().selection()) {
bv->owner()->dispatch(FuncRequest(LFUN_CUT));
gotsel = true;
}
if (bv->insertInset(inset)) {
if (edit)
- inset->edit(bv, true);
+ inset->edit(bv->cursor(), true);
if (gotsel && pastesel)
bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
- } else
+ } else {
delete inset;
+ }
}
} // anon namespace
}
-DispatchResult LyXText::dispatch(BufferView & view, FuncRequest const & cmd)
+DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
- BufferView * bv = &view;
+ BufferView * bv = &cur.bv();
switch (cmd.action) {
}
case LFUN_DELETE_WORD_FORWARD:
- bv->clearSelection();
+ cur.clearSelection();
deleteWordForward();
finishChange(bv);
break;
case LFUN_DELETE_WORD_BACKWARD:
- bv->clearSelection();
+ cur.clearSelection();
deleteWordBackward();
finishChange(bv);
break;
case LFUN_DELETE_LINE_FORWARD:
- bv->clearSelection();
+ cur.clearSelection();
deleteLineForward();
finishChange(bv);
break;
case LFUN_WORDRIGHT:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
if (rtl())
cursorLeftOneWord();
else
break;
case LFUN_WORDLEFT:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
if (rtl())
cursorRightOneWord();
else
break;
case LFUN_BEGINNINGBUF:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorTop();
finishChange(bv);
break;
case LFUN_ENDBUF:
- if (bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorBottom();
finishChange(bv);
break;
case LFUN_RIGHTSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
if (rtl())
- cursorLeft(bv);
+ cursorLeft(true);
else
- cursorRight(bv);
+ cursorRight(true);
finishChange(bv, true);
break;
case LFUN_LEFTSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
if (rtl())
- cursorRight(bv);
+ cursorRight(true);
else
- cursorLeft(bv);
+ cursorLeft(true);
finishChange(bv, true);
break;
case LFUN_UPSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorUp(true);
finishChange(bv, true);
break;
case LFUN_DOWNSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorDown(true);
finishChange(bv, true);
break;
case LFUN_UP_PARAGRAPHSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorUpParagraph();
finishChange(bv, true);
break;
case LFUN_DOWN_PARAGRAPHSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorDownParagraph();
finishChange(bv, true);
break;
case LFUN_PRIORSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorPrevious();
finishChange(bv, true);
break;
case LFUN_NEXTSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorNext();
finishChange(bv, true);
break;
case LFUN_HOMESEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorHome();
finishChange(bv, true);
break;
case LFUN_ENDSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorEnd();
finishChange(bv, true);
break;
case LFUN_WORDRIGHTSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
if (rtl())
cursorLeftOneWord();
else
break;
case LFUN_WORDLEFTSEL:
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
if (rtl())
cursorRightOneWord();
else
return moveDown();
case LFUN_UP_PARAGRAPH:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorUpParagraph();
finishChange(bv);
break;
case LFUN_DOWN_PARAGRAPH:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorDownParagraph();
finishChange(bv, false);
break;
case LFUN_PRIOR:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
finishChange(bv, false);
if (cursorPar() == firstPar() && cursorRow() == firstRow())
return DispatchResult(false, FINISHED_UP);
break;
case LFUN_NEXT:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
finishChange(bv, false);
if (cursorPar() == lastPar() && cursorRow() == lastRow())
return DispatchResult(false, FINISHED_DOWN);
break;
case LFUN_HOME:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorHome();
finishChange(bv, false);
break;
case LFUN_END:
- if (!bv->selection().mark())
- bv->clearSelection();
+ if (!cur.mark())
+ cur.clearSelection();
cursorEnd();
finishChange(bv, false);
break;
replaceSelection(bv->getLyXText());
insertInset(new InsetNewline);
- moveCursor(bv, false);
+ moveCursor(cur, false);
break;
}
case LFUN_DELETE:
- if (!bv->selection().set()) {
+ if (!cur.selection()) {
Delete();
- bv->resetAnchor();
+ cur.resetAnchor();
// It is possible to make it a lot faster still
// just comment out the line below...
} else {
cutSelection(true, false);
}
- moveCursor(bv, false);
+ moveCursor(cur, false);
bv->owner()->view_state_changed();
break;
case LFUN_DELETE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
- if (!bv->selection().set()) {
+ if (!cur.selection()) {
if (cursor().pos() == cursorPar()->size()) {
cursorRight(bv);
cursorLeft(bv);
Delete();
- bv->resetAnchor();
+ cur.resetAnchor();
} else {
Delete();
- bv->resetAnchor();
+ cur.resetAnchor();
}
} else {
cutSelection(true, false);
case LFUN_BACKSPACE:
- if (!bv->selection().set()) {
+ if (!cur.selection()) {
if (bv->owner()->getIntl().getTransManager().backspace()) {
backspace();
- bv->resetAnchor();
+ cur.resetAnchor();
// It is possible to make it a lot faster still
// just comment out the line below...
}
case LFUN_BACKSPACE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
- if (!bv->selection().set()) {
+ if (!cur.selection()) {
CursorSlice cur = cursor();
backspace();
anchor() = cur;
replaceSelection(bv->getLyXText());
breakParagraph(bv->buffer()->paragraphs(), 0);
bv->update();
- bv->resetAnchor();
+ cur.resetAnchor();
bv->switchKeyMap();
bv->owner()->view_state_changed();
break;
replaceSelection(bv->getLyXText());
breakParagraph(bv->buffer()->paragraphs(), 1);
bv->update();
- bv->resetAnchor();
+ cur.resetAnchor();
bv->switchKeyMap();
bv->owner()->view_state_changed();
break;
case LFUN_INSET_APPLY: {
string const name = cmd.getArg(0);
InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
- if (inset) {
- FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
- inset->dispatch(*bv, fr);
- } else {
- FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
- dispatch(*bv, fr);
- }
+ if (inset)
+ inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
+ else
+ dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
break;
}
}
case LFUN_INSET_SETTINGS:
- bv->fullCursor().innerInset()->showInsetDialog(bv);
+ if (cur.inset() && cur.inset()->asUpdatableInset())
+ cur.inset()->asUpdatableInset()->showInsetDialog(bv);
break;
case LFUN_INSET_TOGGLE:
- bv->clearSelection();
+ cur.clearSelection();
if (!toggleInset())
return DispatchResult(false);
bv->update();
insertChar(' ');
else
doInsertInset(bv, cmd, false, false);
- moveCursor(bv, false);
+ moveCursor(cur, false);
break;
case LFUN_HYPHENATION:
pasteSelection(strToUnsignedInt(cmd.argument));
else
pasteSelection(0);
- bv->clearSelection(); // bug 393
+ cur.clearSelection(); // bug 393
bv->update();
bv->switchKeyMap();
finishUndo();
case LFUN_BEGINNINGBUFSEL:
if (in_inset_)
return DispatchResult(false);
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorTop();
finishChange(bv, true);
break;
case LFUN_ENDBUFSEL:
if (in_inset_)
return DispatchResult(false);
- if (!bv->selection().set())
- bv->resetAnchor();
+ if (!cur.selection())
+ cur.resetAnchor();
cursorBottom();
finishChange(bv, true);
break;
bool change_layout = (current_layout != layout);
- if (!change_layout && bv->selection().set() &&
- bv->selStart().par() != bv->selEnd().par())
+ if (!change_layout && cur.selection() &&
+ cur.selStart().par() != cur.selEnd().par())
{
- ParagraphList::iterator spit = getPar(bv->selStart());
- ParagraphList::iterator epit = boost::next(getPar(bv->selEnd()));
+ ParagraphList::iterator spit = getPar(cur.selStart());
+ ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
while (spit != epit) {
if (spit->layout()->name() != current_layout) {
change_layout = true;
}
case LFUN_PASTESELECTION: {
- bv->clearSelection();
+ cur.clearSelection();
string const clip = bv->getClipboard();
if (!clip.empty()) {
if (cmd.argument == "paragraph")
for (int i = 0; i < datetmp_len; i++)
insertChar(datetmp[i]);
- bv->resetAnchor();
- moveCursor(bv, false);
+ cur.resetAnchor();
+ moveCursor(cur, false);
break;
}
case LFUN_MOUSE_TRIPLE:
- if (!bv->buffer())
- break;
- if (cmd.button() == mouse_button::button1) {
+ if (bv->buffer() && cmd.button() == mouse_button::button1) {
selection_possible = true;
cursorHome();
- bv->resetAnchor();
+ cur.resetAnchor();
cursorEnd();
- bv->setSelection();
- bv->haveSelection(bv->selection().set());
+ cur.setSelection();
+ bv->haveSelection(cur.selection());
}
break;
case LFUN_MOUSE_DOUBLE:
- if (!bv->buffer())
- break;
- if (cmd.button() == mouse_button::button1) {
+ if (bv->buffer() && cmd.button() == mouse_button::button1) {
selection_possible = true;
selectWord(lyx::WHOLE_WORD_STRICT);
- bv->haveSelection(bv->selection().set());
+ bv->haveSelection(cur.selection());
}
break;
else if (cmd.y - bv->top_y() < 0)
cursorUp(true);
}
- bv->setSelection();
+ cur.setSelection();
break;
}
// it could get cleared on the unlocking of the inset so
// we have to check this first
bool paste_internally = false;
- if (cmd.button() == mouse_button::button2 && bv->selection().set()) {
+ if (cmd.button() == mouse_button::button2 && cur.selection()) {
bv->owner()->dispatch(FuncRequest(LFUN_COPY));
paste_internally = true;
}
selection_possible = true;
// Clear the selection
- bv->clearSelection();
+ cur.clearSelection();
// Right click on a footnote flag opens float menu
if (cmd.button() == mouse_button::button3) {
}
setCursorFromCoordinates(cmd.x, cmd.y);
- bv->resetAnchor();
+ cur.resetAnchor();
finishUndo();
- bv->x_target(cursorX() + xo_);
+ cur.x_target(cursorX() + xo_);
if (bv->fitCursor())
selection_possible = false;
// finish selection
if (cmd.button() == mouse_button::button1)
- bv->haveSelection(bv->selection().set());
+ bv->haveSelection(cur.selection());
bv->switchKeyMap();
bv->owner()->view_state_changed();
// true (on).
if (lyxrc.auto_region_delete) {
- if (bv->selection().set())
+ if (cur.selection())
cutSelection(false, false);
bv->haveSelection(false);
}
- bv->clearSelection();
+ cur.clearSelection();
LyXFont const old_font = real_current_font;
string::const_iterator cit = cmd.argument.begin();
bv->owner()->getIntl().getTransManager().
TranslateAndInsert(*cit, this);
- bv->resetAnchor();
- moveCursor(bv, false);
+ cur.resetAnchor();
+ moveCursor(cur, false);
// real_current_font.number can change so we need to
// update the minibuffer
case LFUN_MATH_NUMBER:
case LFUN_MATH_EXTERN:
case LFUN_MATH_SIZE:
- mathDispatch(*bv, cmd);
+ mathDispatch(cur, cmd);
break;
case LFUN_EMPH:
case LFUN_FINISHED_LEFT:
lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
if (rtl())
- cursorRight(true);
+ cursorLeft(true);
break;
case LFUN_FINISHED_RIGHT:
#include "undo.h"
#include "buffer.h"
-#include "cursor_slice.h"
+#include "cursor.h"
#include "debug.h"
#include "BufferView.h"
#include "iterators.h"
<< std::endl;
// set cursor again to force the position to be the right one
- bv->cursor().par(undo.cursor_par);
- bv->cursor().pos(undo.cursor_pos);
+ LCursor & cur = bv->cursor();
+ cur.par() = undo.cursor_par;
+ cur.pos() = undo.cursor_pos;
// clear any selection
- bv->clearSelection();
- bv->resetAnchor();
+ cur.clearSelection();
+ cur.resetAnchor();
text->updateCounters();
// rebreak the entire lyxtext
void recordUndo(BufferView * bv, Undo::undo_kind kind)
{
- recordUndo(*bv, kind);
+ recordUndo(bv->cursor(), kind);
}
-void recordUndo(BufferView & bv, Undo::undo_kind kind)
+void recordUndo(LCursor & cur, Undo::undo_kind kind)
{
- recordUndo(kind, bv.text(), bv.text()->cursor().par());
+ recordUndo(kind, cur.bv().text(), cur.bv().text()->cursor().par());
}
#include "ParagraphList_fwd.h"
#include "support/types.h"
+class LCursor;
class LyXText;
class BufferView;
/// convienience: prepare undo for the paragraph that contains the cursor
void recordUndo(BufferView *, Undo::undo_kind kind);
-void recordUndo(BufferView &, Undo::undo_kind kind);
+void recordUndo(LCursor &, Undo::undo_kind kind);
/// are we avoiding tracking undos currently?
extern bool undo_frozen;