}
+Selection & BufferView::selection()
+{
+ return selection_;
+}
+
+
+Selection const & BufferView::selection() const
+{
+ return selection_;
+}
+
+
void BufferView::x_target(int x)
{
x_target_ = x;
class LyXScreen;
class LyXView;
class Painter;
+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
LyXText * text() const;
///
void resetAnchor();
+ ///
+ Selection & selection();
+ ///
+ Selection const & selection() const;
+
+ ///
+ Selection selection_;
private:
///
pos_type pos = 0;
pos_type selstartpos = 0;
pos_type selendpos = 0;
- bool selection = false;
+ bool sel = false;
bool mark_set = false;
owner_->busy(true);
selstartpos = text->selStart().pos();
selendpar = text->selEnd().par();
selendpos = text->selEnd().pos();
- selection = text->selection.set();
- mark_set = text->selection.mark();
+ sel = bv_->selection().set();
+ mark_set = bv_->selection().mark();
text->textwidth_ = bv_->workWidth();
text->fullRebreak();
update();
if (par != -1) {
- text->selection.set(true);
+ bv_->selection().set(true);
// At this point just to avoid the Delete-Empty-Paragraph-
// Mechanism when setting the cursor.
- text->selection.mark(mark_set);
- if (selection) {
+ bv_->selection().mark(mark_set);
+ if (sel) {
text->setCursor(selstartpar, selstartpos);
bv_->resetAnchor();
text->setCursor(selendpar, selendpos);
} else {
text->setCursor(par, pos);
bv_->resetAnchor();
- text->selection.set(false);
+ bv_->selection().set(false);
}
}
LyXText * text = bv_->getLyXText();
- if (!text->selection.set()) {
+ if (!bv_->selection().set()) {
xsel_cache_.set = false;
return;
}
{
xsel_cache_.cursor = bv_->cursor();
xsel_cache_.anchor = bv_->anchor();
- xsel_cache_.set = text->selection.set();
+ xsel_cache_.set = bv_->selection().set();
sel = text->selectionAsString(*bv_->buffer(), false);
if (!sel.empty())
workarea().putClipboard(sel);
LyXText * text = bv_->getLyXText();
- if (!text->selection.set())
+ if (!bv_->selection().set())
return Change(Change::UNCHANGED);
return text->getPar(text->selStart())
}
-
// deletes a selection during an insertion
void replaceSelection(LyXText * text)
{
- if (text->selection.set()) {
+ if (text->bv()->selection().set()) {
text->cutSelection(true, false);
text->bv()->update();
}
if (!autoBreakRows_ && paragraphs().size() > 1)
collapseParagraphs(bv);
- if (!text_.selection.set())
- text_.anchor() = text_.cursor();
+ if (!bv->selection().set())
+ bv->resetAnchor();
bv->owner()->view_state_changed();
bv->owner()->updateMenubar();
bv->owner()->updateToolbar();
- if (old_par != text_.cursor().par()) {
+ if (old_par != bv->cursor().par()) {
bv->owner()->setLayout(text_.cursorPar()->layout()->name());
- old_par = text_.cursor().par();
+ old_par = bv->cursor().par();
}
}
if (tab && tab->hasSelection())
disable = false;
else
- disable = !mathcursor && !view()->getLyXText()->selection.set();
+ disable = !mathcursor && !view()->selection().set();
break;
case LFUN_RUNCHKTEX:
class VSpace;
-// 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
-};
-
-
/// This class encapsulates the main text data and operations in LyX
class LyXText {
public:
///
void clearSelection();
///
- CursorSlice const & selStart() const;
- ///
- CursorSlice const & selEnd() const;
- ///
CursorSlice & selStart();
///
+ CursorSlice const & selStart() const;
+ ///
CursorSlice & selEnd();
+ ///
+ CursorSlice const & selEnd() const;
public:
-/** The cursor.
- Later this variable has to be removed. There should be no internal
- cursor in a text (and thus not in a buffer). By keeping this it is
- (I think) impossible to have several views with the same buffer, but
- the cursor placed at different places.
- [later]
- Since the LyXText now has been moved from Buffer to BufferView
- it should not be absolutely needed to move the cursor...
- [even later]
- Nevertheless, it should still be moved, in order to keep classes
- and interdependencies small.
- */
- // the other end of the selection
- CursorSlice anchor_;
- //
- Selection selection;
-
///
int height;
///
paintBackground();
// paint the selection background
- if (text_.selection.set() && &text_ == bv_.fullCursor().innerText())
+ if (bv_.selection().set() && &text_ == bv_.fullCursor().innerText())
paintSelection();
// vertical lines for appendix
// selection is currently set
bool LyXText::selectWordWhenUnderCursor(word_location loc)
{
- if (!selection.set()) {
+ if (!bv()->selection().set()) {
selectWord(loc);
- return selection.set();
+ return bv()->selection().set();
}
return false;
}
void LyXText::acceptChange()
{
- if (!selection.set() && cursorPar()->size())
+ if (!bv()->selection().set() && cursorPar()->size())
return;
if (selStart().par() == selEnd().par()) {
void LyXText::rejectChange()
{
- if (!selection.set() && cursorPar()->size())
+ if (!bv()->selection().set() && cursorPar()->size())
return;
if (selStart().par() == selEnd().par()) {
cursorRight(bv());
else {
CursorSlice tmpcursor = cursor();
- selection.set(true); // to avoid deletion
+ bv()->selection().set(true); // to avoid deletion
cursorRightOneWord();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
bv()->resetAnchor();
cursorLeft(bv());
else {
CursorSlice tmpcursor = cursor();
- selection.set(true); // to avoid deletion
+ bv()->selection().set(true); // to avoid deletion
cursorLeftOneWord();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
bv()->resetAnchor();
cursorRight(bv());
} else {
CursorSlice tmpcursor = cursor();
- selection.set(true); // to avoid deletion
+ bv()->selection().set(true); // to avoid deletion
cursorEnd();
setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
bv()->resetAnchor();
cursor() = tmpcursor;
setSelection();
// What is this test for ??? (JMarc)
- if (!selection.set())
+ if (!bv()->selection().set())
deleteWordForward();
else
cutSelection(true, false);
CursorSlice from;
CursorSlice to;
- if (selection.set()) {
+ if (bv()->selection().set()) {
from = selStart();
to = selEnd();
} else {
string LyXText::selectionAsString(Buffer const & buffer, bool label) const
{
- if (!selection.set())
+ if (!bv()->selection().set())
return string();
// should be const ...
CursorSlice const & LyXText::selStart() const
{
- if (!selection.set())
+ if (!bv()->selection().set())
return cursor();
// can't use std::min as this creates a new object
return anchor() < cursor() ? anchor() : cursor();
CursorSlice const & LyXText::selEnd() const
{
- if (!selection.set())
+ if (!bv()->selection().set())
return cursor();
return anchor() > cursor() ? anchor() : cursor();
}
CursorSlice & LyXText::selStart()
{
- if (!selection.set())
+ if (!bv()->selection().set())
return cursor();
return anchor() < cursor() ? anchor() : cursor();
}
CursorSlice & LyXText::selEnd()
{
- if (!selection.set())
+ if (!bv()->selection().set())
return cursor();
return anchor() > cursor() ? anchor() : cursor();
}
void LyXText::setSelection()
{
- selection.set(true);
+ bv()->selection().set(true);
// a selection with no contents is not a selection
if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
- selection.set(false);
+ bv()->selection().set(false);
}
void LyXText::clearSelection()
{
- selection.set(false);
- selection.mark(false);
+ bv()->selection().set(false);
+ bv()->selection().mark(false);
bv()->resetAnchor();
// reset this in the bv()!
if (bv() && bv()->text())
ParagraphList::iterator & beg,
ParagraphList::iterator & end)
{
- if (!text.selection.set()) {
+ if (!text.bv()->selection().set()) {
beg = text.cursorPar();
end = boost::next(beg);
} else {
void LyXText::setFont(LyXFont const & font, bool toggleall)
{
// if there is no selection just set the current_font
- if (!selection.set()) {
+ if (!bv()->selection().set()) {
// Determine basis font
LyXFont layoutfont;
if (cursor().pos() < cursorPar()->beginOfBody())
selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
string idxstring;
- if (!selection.set())
+ if (!bv()->selection().set())
bv()->owner()->message(_("Nothing to index!"));
else if (selStart().par() != selEnd().par())
bv()->owner()->message(_("Cannot index more than one paragraph!"));
bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
// This doesn't make sense, if there is no selection
- if (!selection.set())
+ if (!bv()->selection().set())
return;
// OK, we have a selection. This is always between selStart()
bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
// this doesnt make sense, if there is no selection
- if (!selection.set())
+ if (!bv()->selection().set())
return;
// ok we have a selection. This is always between selStart()
bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor)
{
// Would be wrong to delete anything if we have a selection.
- if (selection.set())
+ if (bv()->selection().set())
return false;
// Don't do anything if the cursor is invalid
{
LyXText * lt = bv->getLyXText();
-// if (!lt->selection.set())
-// lt->selection.cursor = lt->cursor();
-
- if (selecting || lt->selection.mark())
+ if (selecting || bv->selection().mark())
lt->setSelection();
- if (!lt->selection.set())
+ if (!bv->selection().set())
bv->haveSelection(false);
bv->switchKeyMap();
}
}
-void doInsertInset(LyXText const & lt, FuncRequest const & cmd,
- bool edit, bool pastesel)
+void doInsertInset(FuncRequest const & cmd, bool edit, bool pastesel)
{
InsetOld * inset = createInset(cmd);
if (!inset)
BufferView * bv = cmd.view();
bool gotsel = false;
- if (lt.selection.set()) {
+ if (bv->selection().set()) {
bv->owner()->dispatch(FuncRequest(LFUN_CUT));
gotsel = true;
}
break;
case LFUN_WORDRIGHT:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
if (rtl())
cursorLeftOneWord();
break;
case LFUN_WORDLEFT:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
if (rtl())
cursorRightOneWord();
break;
case LFUN_BEGINNINGBUF:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
cursorTop();
finishChange(bv);
break;
case LFUN_ENDBUF:
- if (selection.mark())
+ if (bv->selection().mark())
clearSelection();
cursorBottom();
finishChange(bv);
break;
case LFUN_RIGHTSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
if (rtl())
cursorLeft(bv);
break;
case LFUN_LEFTSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
if (rtl())
cursorRight(bv);
break;
case LFUN_UPSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorUp(true);
finishChange(bv, true);
break;
case LFUN_DOWNSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorDown(true);
finishChange(bv, true);
break;
case LFUN_UP_PARAGRAPHSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorUpParagraph();
finishChange(bv, true);
break;
case LFUN_DOWN_PARAGRAPHSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorDownParagraph();
finishChange(bv, true);
break;
case LFUN_PRIORSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorPrevious();
finishChange(bv, true);
break;
case LFUN_NEXTSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorNext();
finishChange(bv, true);
break;
case LFUN_HOMESEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorHome();
finishChange(bv, true);
break;
case LFUN_ENDSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorEnd();
finishChange(bv, true);
break;
case LFUN_WORDRIGHTSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
if (rtl())
cursorLeftOneWord();
break;
case LFUN_WORDLEFTSEL:
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
if (rtl())
cursorRightOneWord();
return moveDown();
case LFUN_UP_PARAGRAPH:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
cursorUpParagraph();
finishChange(bv);
break;
case LFUN_DOWN_PARAGRAPH:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
cursorDownParagraph();
finishChange(bv, false);
break;
case LFUN_PRIOR:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
finishChange(bv, false);
if (cursorPar() == firstPar() && cursorRow() == firstRow())
break;
case LFUN_NEXT:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
finishChange(bv, false);
if (cursorPar() == lastPar() && cursorRow() == lastRow())
break;
case LFUN_HOME:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
cursorHome();
finishChange(bv, false);
break;
case LFUN_END:
- if (!selection.mark())
+ if (!bv->selection().mark())
clearSelection();
cursorEnd();
finishChange(bv, false);
}
case LFUN_DELETE:
- if (!selection.set()) {
+ if (!bv->selection().set()) {
Delete();
bv->resetAnchor();
// It is possible to make it a lot faster still
case LFUN_DELETE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
- if (!selection.set()) {
+ if (!bv->selection().set()) {
if (cursor().pos() == cursorPar()->size()) {
cursorRight(bv);
cursorLeft(bv);
case LFUN_BACKSPACE:
- if (!selection.set()) {
+ if (!bv->selection().set()) {
if (bv->owner()->getIntl().getTransManager().backspace()) {
backspace();
bv->resetAnchor();
case LFUN_BACKSPACE_SKIP:
// Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
- if (!selection.set()) {
+ if (!bv->selection().set()) {
CursorSlice cur = cursor();
backspace();
anchor() = cur;
if (cursorPar()->layout()->free_spacing)
insertChar(' ');
else
- doInsertInset(*this, cmd, false, false);
+ doInsertInset(cmd, false, false);
moveCursor(bv, false);
break;
case LFUN_MARK_ON:
clearSelection();
- selection.mark(true);
+ bv->selection().mark(true);
bv->update();
bv->resetAnchor();
cmd.message(N_("Mark on"));
case LFUN_SETMARK:
clearSelection();
- if (selection.mark()) {
+ if (bv->selection().mark()) {
cmd.message(N_("Mark removed"));
} else {
- selection.mark(true);
+ bv->selection().mark(true);
cmd.message(N_("Mark set"));
}
bv->resetAnchor();
case LFUN_BEGINNINGBUFSEL:
if (in_inset_)
return DispatchResult(false);
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorTop();
finishChange(bv, true);
case LFUN_ENDBUFSEL:
if (in_inset_)
return DispatchResult(false);
- if (!selection.set())
+ if (!bv->selection().set())
bv->resetAnchor();
cursorBottom();
finishChange(bv, true);
bool change_layout = (current_layout != layout);
- if (!change_layout && selection.set() &&
+ if (!change_layout && bv->selection().set() &&
selStart().par() != selEnd().par())
{
ParagraphList::iterator spit = getPar(selStart());
bv->resetAnchor();
cursorEnd();
setSelection();
- bv->haveSelection(selection.set());
+ bv->haveSelection(bv->selection().set());
}
break;
if (cmd.button() == mouse_button::button1) {
selection_possible = true;
selectWord(lyx::WHOLE_WORD_STRICT);
- bv->haveSelection(selection.set());
+ bv->haveSelection(bv->selection().set());
}
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 && selection.set()) {
+ if (cmd.button() == mouse_button::button2 && bv->selection().set()) {
bv->owner()->dispatch(FuncRequest(LFUN_COPY));
paste_internally = true;
}
// finish selection
if (cmd.button() == mouse_button::button1)
- bv->haveSelection(selection.set());
+ bv->haveSelection(bv->selection().set());
bv->switchKeyMap();
bv->owner()->view_state_changed();
// true (on).
if (lyxrc.auto_region_delete) {
- if (selection.set())
+ if (bv->selection().set())
cutSelection(false, false);
bv->haveSelection(false);
}
case LFUN_ENVIRONMENT_INSERT:
// Open the inset, and move the current selection
// inside it.
- doInsertInset(*this, cmd, true, true);
+ doInsertInset(cmd, true, true);
break;
case LFUN_INDEX_INSERT:
// Just open the inset
- doInsertInset(*this, cmd, true, false);
+ doInsertInset(cmd, true, false);
break;
case LFUN_INDEX_PRINT:
case LFUN_INSERT_LINE:
case LFUN_INSERT_PAGEBREAK:
// do nothing fancy
- doInsertInset(*this, cmd, false, false);
+ doInsertInset(cmd, false, false);
break;
case LFUN_DEPTH_MIN: