streamlining setter syntax. using mutable references seems a bit

outlandish compared to the rest of LyX


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26527 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-09-24 21:27:41 +00:00
parent 7aa28f3efe
commit 4c7fdddd74
10 changed files with 53 additions and 51 deletions

View File

@ -1221,7 +1221,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
case LFUN_MARK_ON:
cur.clearSelection();
cur.mark() = true;
cur.setMark(true);
cur.resetAnchor();
cur.message(from_utf8(N_("Mark on")));
break;
@ -1229,10 +1229,10 @@ bool BufferView::dispatch(FuncRequest const & cmd)
case LFUN_MARK_TOGGLE:
cur.clearSelection();
if (cur.mark()) {
cur.mark() = false;
cur.setMark(false);
cur.message(from_utf8(N_("Mark removed")));
} else {
cur.mark() = true;
cur.setMark(true);
cur.message(from_utf8(N_("Mark set")));
}
cur.resetAnchor();
@ -1570,7 +1570,7 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
Cursor old = cursor();
Cursor cur(*this);
cur.push(buffer_.inset());
cur.selection() = d->cursor_.selection();
cur.setSelection(d->cursor_.selection());
// Either the inset under the cursor or the
// surrounding Text will handle this event.
@ -1816,7 +1816,7 @@ void BufferView::setCursor(DocIterator const & dit)
dit[i].inset().edit(d->cursor_, true);
d->cursor_.setCursor(dit);
d->cursor_.selection() = false;
d->cursor_.setSelection(false);
}

View File

@ -249,13 +249,13 @@ bool bruteFind3(Cursor & cur, int x, int y, bool up)
docstring parbreak(Paragraph const & par)
{
odocstringstream ods;
ods << '\n';
odocstringstream os;
os << '\n';
// only add blank line if we're not in an ERT or Listings inset
if (par.ownerCode() != ERT_CODE
&& par.ownerCode() != LISTINGS_CODE)
ods << '\n';
return ods.str();
os << '\n';
return os.str();
}
} // namespace anon
@ -980,20 +980,20 @@ DocIterator Cursor::selectionEnd() const
void Cursor::setSelection()
{
selection() = true;
setSelection(true);
// A selection with no contents is not a selection
// FIXME: doesnt look ok
if (idx() == anchor().idx() &&
pit() == anchor().pit() &&
pos() == anchor().pos())
selection() = false;
setSelection(false);
}
void Cursor::setSelection(DocIterator const & where, int n)
{
setCursor(where);
selection() = true;
setSelection(true);
anchor_ = where;
pos() += n;
}
@ -1001,8 +1001,8 @@ void Cursor::setSelection(DocIterator const & where, int n)
void Cursor::clearSelection()
{
selection() = false;
mark() = false;
setSelection(false);
setMark(false);
resetAnchor();
}
@ -1065,7 +1065,7 @@ bool Cursor::selHandle(bool sel)
cap::saveSelection(*this);
resetAnchor();
selection() = sel;
setSelection(sel);
return true;
}
@ -1324,7 +1324,7 @@ bool Cursor::backspace()
// let's require two backspaces for 'big stuff' and
// highlight on the first
resetAnchor();
selection() = true;
setSelection(true);
--pos();
} else {
--pos();
@ -1372,7 +1372,7 @@ bool Cursor::erase()
// 'clever' UI hack: only erase large items if previously slected
if (pos() != lastpos() && nextAtom()->nargs() > 0) {
resetAnchor();
selection() = true;
setSelection(true);
++pos();
} else {
plainErase();

View File

@ -37,7 +37,8 @@ class Encoding;
// The public inheritance should go in favour of a suitable data member
// (or maybe private inheritance) at some point of time.
class Cursor : public DocIterator {
class Cursor : public DocIterator
{
public:
/// create the cursor of a BufferView
explicit Cursor(BufferView & bv);
@ -69,8 +70,8 @@ public:
//
/// selection active?
bool selection() const { return selection_; }
/// selection active?
bool & selection() { return selection_; }
/// set selection;
void setSelection(bool sel) { selection_ = sel; }
/// do we have a multicell selection?
bool selIsMultiCell() const
{ return selection_ && selBegin().idx() != selEnd().idx(); }
@ -80,7 +81,7 @@ public:
/// did we place the anchor?
bool mark() const { return mark_; }
/// did we place the anchor?
bool & mark() { return mark_; }
void setMark(bool mark) { mark_ = mark; }
///
void setSelection();
/// set selection at given position

View File

@ -993,7 +993,7 @@ void selClearOrDel(Cursor & cur)
if (lyxrc.auto_region_delete)
selDel(cur);
else
cur.selection() = false;
cur.setSelection(false);
}

View File

@ -922,7 +922,7 @@ void Text::deleteWordForward(Cursor & cur)
cursorForward(cur);
else {
cur.resetAnchor();
cur.selection() = true;
cur.setSelection(true);
cursorForwardOneWord(cur);
cur.setSelection();
cutSelection(cur, true, false);
@ -938,7 +938,7 @@ void Text::deleteWordBackward(Cursor & cur)
cursorBackward(cur);
else {
cur.resetAnchor();
cur.selection() = true;
cur.setSelection(true);
cursorBackwardOneWord(cur);
cur.setSelection();
cutSelection(cur, true, false);
@ -1180,14 +1180,15 @@ bool Text::backspace(Cursor & cur)
}
bool Text::dissolveInset(Cursor & cur) {
LASSERT(this == cur.text(), /**/);
bool Text::dissolveInset(Cursor & cur)
{
LASSERT(this == cur.text(), return false);
if (isMainText(cur.bv().buffer()) || cur.inset().nargs() != 1)
return false;
cur.recordUndoInset();
cur.mark() = false;
cur.setMark(false);
cur.selHandle(false);
// save position
pos_type spos = cur.pos();

View File

@ -1148,7 +1148,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
// Single-click on work area
case LFUN_MOUSE_PRESS:
// We are not marking a selection with the keyboard in any case.
cur.bv().cursor().mark() = false;
cur.bv().cursor().setMark(false);
switch (cmd.button()) {
case mouse_button::button1:
// Set the cursor
@ -1230,7 +1230,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
// We continue with our existing selection or start a new one, so don't
// reset the anchor.
bvcur.setCursor(cur);
bvcur.selection() = true;
bvcur.setSelection(true);
if (cur.top() == old) {
// We didn't move one iota, so no need to update the screen.
cur.updateFlags(Update::SinglePar | Update::FitCursor);
@ -1491,7 +1491,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.push(*inset);
cur.top().pos() = cur.top().lastpos();
cur.resetAnchor();
cur.selection() = true;
cur.setSelection(true);
cur.top().pos() = 0;
}
break;
@ -1768,7 +1768,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_ESCAPE:
if (cur.selection()) {
cur.selection() = false;
cur.setSelection(false);
} else {
cur.undispatched();
// This used to be LFUN_FINISHED_RIGHT, I think FORWARD is more

View File

@ -1733,7 +1733,7 @@ void TextMetrics::deleteLineForward(Cursor & cur)
text_->cursorForward(cur);
} else {
cur.resetAnchor();
cur.selection() = true; // to avoid deletion
cur.setSelection(true); // to avoid deletion
cursorEnd(cur);
cur.setSelection();
// What is this test for ??? (JMarc)

View File

@ -3136,7 +3136,7 @@ void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
{
//lyxerr << "InsetTabular::edit: " << this << endl;
cur.finishUndo();
cur.selection() = false;
cur.setSelection(false);
cur.push(*this);
if (front) {
if (isRightToLeft(cur))
@ -3199,7 +3199,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.resetAnchor();
cur.idx() = tabular.getLastCellInRow(r);
cur.pos() = cur.lastpos();
cur.selection() = true;
cur.setSelection(true);
bvcur = cur;
rowselect_ = true;
break;
@ -3214,7 +3214,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.resetAnchor();
cur.idx() = tabular.cellIndex(tabular.row_info.size() - 1, c);
cur.pos() = cur.lastpos();
cur.selection() = true;
cur.setSelection(true);
bvcur = cur;
colselect_ = true;
break;
@ -3247,7 +3247,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.pit() = 0;
cur.pos() = 0;
bvcur.setCursor(cur);
bvcur.selection() = true;
bvcur.setSelection(true);
break;
}
// select (additional) column
@ -3259,7 +3259,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.pit() = 0;
cur.pos() = 0;
bvcur.setCursor(cur);
bvcur.selection() = true;
bvcur.setSelection(true);
break;
}
// only update if selection changes
@ -3268,7 +3268,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.noUpdate();
setCursorFromCoordinates(cur, cmd.x, cmd.y);
bvcur.setCursor(cur);
bvcur.selection() = true;
bvcur.setSelection(true);
// if this is a multicell selection, we just set the cursor to
// the beginning of the cell's text.
if (bvcur.selIsMultiCell()) {
@ -3285,12 +3285,12 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CELL_BACKWARD:
movePrevCell(cur);
cur.selection() = false;
cur.setSelection(false);
break;
case LFUN_CELL_FORWARD:
moveNextCell(cur);
cur.selection() = false;
cur.setSelection(false);
break;
case LFUN_CHAR_FORWARD_SELECT:
@ -4009,7 +4009,7 @@ int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const
Inset * InsetTabular::editXY(Cursor & cur, int x, int y)
{
//lyxerr << "InsetTabular::editXY: " << this << endl;
cur.selection() = false;
cur.setSelection(false);
cur.push(*this);
cur.idx() = getNearestCell(cur.bv(), x, y);
resetPos(cur);
@ -4325,7 +4325,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.cellIndex(sel_row_start, column);
cur.pit() = 0;
cur.pos() = 0;
cur.selection() = false;
cur.setSelection(false);
break;
case Tabular::DELETE_COLUMN:
@ -4336,7 +4336,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.cellIndex(row, sel_col_start);
cur.pit() = 0;
cur.pos() = 0;
cur.selection() = false;
cur.setSelection(false);
break;
case Tabular::COPY_ROW:
@ -4423,7 +4423,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = s_start;
cur.pit() = 0;
cur.pos() = 0;
cur.selection() = false;
cur.setSelection(false);
break;
}
@ -4542,7 +4542,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
cur.idx() = tabular.setLTCaption(row, !tabular.ltCaption(row));
cur.pit() = 0;
cur.pos() = 0;
cur.selection() = false;
cur.setSelection(false);
break;
case Tabular::SET_BOOKTABS:

View File

@ -1079,7 +1079,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CELL_BACKWARD:
// See below.
cur.selection() = false;
cur.setSelection(false);
if (!idxPrev(cur)) {
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
cur.undispatched();
@ -1089,7 +1089,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CELL_FORWARD:
// Can't handle selection by additional 'shift' as this is
// hard bound to LFUN_CELL_BACKWARD
cur.selection() = false;
cur.setSelection(false);
if (!idxNext(cur)) {
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
cur.undispatched();

View File

@ -672,7 +672,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.pos() = 0;
cur.idx() = 0;
cur.resetAnchor();
cur.selection() = true;
cur.setSelection(true);
cur.pos() = cur.lastpos();
cur.idx() = cur.lastidx();
break;
@ -1361,7 +1361,7 @@ void InsetMathNest::lfunMouseMotion(Cursor & cur, FuncRequest & cmd)
if (bvcur.anchor_.hasPart(cur)) {
//lyxerr << "## lfunMouseMotion: cursor: " << cur << endl;
bvcur.setCursor(cur);
bvcur.selection() = true;
bvcur.setSelection(true);
//lyxerr << "MOTION " << bvcur << endl;
} else
cur.undispatched();
@ -1378,7 +1378,7 @@ void InsetMathNest::lfunMouseRelease(Cursor & cur, FuncRequest & cmd)
cur.noUpdate();
else {
Cursor & bvcur = cur.bv().cursor();
bvcur.selection() = true;
bvcur.setSelection(true);
}
return;
}
@ -1496,7 +1496,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
// just clear selection on pressing the space bar
if (cur.selection() && c == ' ') {
cur.selection() = false;
cur.setSelection(false);
return true;
}