mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
move cursor related data fro LyXText to new strcut TextCursor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7216 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
fb27166b77
commit
cc19a4ff58
@ -1047,7 +1047,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
|
||||
break;
|
||||
// no break here!
|
||||
case LFUN_DELETE:
|
||||
setUndo(bv, Undo::DELETE, bv->text->cursor.par());
|
||||
setUndo(bv, Undo::DELETE);
|
||||
cutSelection(bv->buffer()->params);
|
||||
updateLocal(bv, INIT);
|
||||
break;
|
||||
@ -1130,7 +1130,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
|
||||
}
|
||||
case LFUN_PASTE:
|
||||
if (hasPasteBuffer()) {
|
||||
setUndo(bv, Undo::INSERT, bv->text->cursor.par());
|
||||
setUndo(bv, Undo::INSERT);
|
||||
pasteSelection(bv);
|
||||
updateLocal(bv, INIT);
|
||||
break;
|
||||
@ -1624,7 +1624,7 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
|
||||
setSelection(0, tabular.getNumberOfCells() - 1);
|
||||
}
|
||||
if (hasSelection()) {
|
||||
setUndo(bv, Undo::EDIT, bv->text->cursor.par());
|
||||
setUndo(bv, Undo::EDIT);
|
||||
bool const frozen = undo_frozen;
|
||||
if (!frozen)
|
||||
freezeUndo();
|
||||
@ -1746,7 +1746,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
|
||||
sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
|
||||
sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
|
||||
}
|
||||
setUndo(bv, Undo::FINISH, bv->text->cursor.par());
|
||||
setUndo(bv, Undo::FINISH);
|
||||
|
||||
int row = tabular.row_of_cell(actcell);
|
||||
int column = tabular.column_of_cell(actcell);
|
||||
|
@ -87,42 +87,33 @@ void InsetText::saveLyXTextState(LyXText * t) const
|
||||
break;
|
||||
}
|
||||
|
||||
if (it != end && t->cursor.pos() <= it->size()) {
|
||||
sstate.lpar = t->cursor.par();
|
||||
sstate.pos = t->cursor.pos();
|
||||
sstate.boundary = t->cursor.boundary();
|
||||
sstate.selstartpar = t->selection.start.par();
|
||||
sstate.selstartpos = t->selection.start.pos();
|
||||
sstate.selstartboundary = t->selection.start.boundary();
|
||||
sstate.selendpar = t->selection.end.par();
|
||||
sstate.selendpos = t->selection.end.pos();
|
||||
sstate.selendboundary = t->selection.end.boundary();
|
||||
sstate.selection = t->selection.set();
|
||||
sstate.mark_set = t->selection.mark();
|
||||
} else {
|
||||
sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
|
||||
}
|
||||
if (it != end && t->cursor.pos() <= it->size())
|
||||
sstate = *t; // slicing intended
|
||||
else
|
||||
sstate.cursor.par(end);
|
||||
}
|
||||
|
||||
|
||||
void InsetText::restoreLyXTextState(LyXText * t) const
|
||||
{
|
||||
if (sstate.lpar == const_cast<ParagraphList&>(paragraphs).end())
|
||||
if (sstate.cursor.par() == const_cast<ParagraphList&>(paragraphs).end())
|
||||
return;
|
||||
|
||||
t->selection.set(true);
|
||||
/* at this point just to avoid the DEPM when setting the cursor */
|
||||
t->selection.mark(sstate.mark_set);
|
||||
if (sstate.selection) {
|
||||
t->setCursor(sstate.selstartpar, sstate.selstartpos,
|
||||
true, sstate.selstartboundary);
|
||||
// at this point just to avoid the DEPM when setting the cursor
|
||||
t->selection.mark(sstate.selection.mark());
|
||||
if (sstate.selection.set()) {
|
||||
t->setCursor(sstate.selection.start.par(),
|
||||
sstate.selection.start.pos(),
|
||||
true, sstate.selection.start.boundary());
|
||||
t->selection.cursor = t->cursor;
|
||||
t->setCursor(sstate.selendpar, sstate.selendpos,
|
||||
true, sstate.selendboundary);
|
||||
t->setCursor(sstate.selection.end.par(), sstate.selection.end.pos(),
|
||||
true, sstate.selection.end.boundary());
|
||||
t->setSelection();
|
||||
t->setCursor(sstate.lpar, sstate.pos);
|
||||
t->setCursor(sstate.cursor.par(), sstate.cursor.pos());
|
||||
} else {
|
||||
t->setCursor(sstate.lpar, sstate.pos, true, sstate.boundary);
|
||||
t->setCursor(sstate.cursor.par(), sstate.cursor.pos(),
|
||||
true, sstate.cursor.boundary());
|
||||
t->selection.cursor = t->cursor;
|
||||
t->selection.set(false);
|
||||
}
|
||||
@ -189,7 +180,7 @@ void InsetText::init(InsetText const * ins)
|
||||
old_par = paragraphs.end();
|
||||
last_drawn_width = -1;
|
||||
cached_bview = 0;
|
||||
sstate.lpar = paragraphs.end();
|
||||
sstate.cursor.par(paragraphs.end());
|
||||
in_insetAllowed = false;
|
||||
}
|
||||
|
||||
@ -2114,7 +2105,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
|
||||
if (locked) {
|
||||
saveLyXTextState(it->second.text.get());
|
||||
} else {
|
||||
sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
|
||||
sstate.cursor.par(const_cast<ParagraphList&>(paragraphs).end());
|
||||
}
|
||||
}
|
||||
//
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define INSETTEXT_H
|
||||
|
||||
#include "updatableinset.h"
|
||||
#include "textcursor.h"
|
||||
#include "LString.h"
|
||||
#include "LColor.h"
|
||||
#include "ParagraphList.h"
|
||||
@ -372,22 +373,9 @@ private:
|
||||
mutable BufferView * cached_bview;
|
||||
///
|
||||
mutable boost::shared_ptr<LyXText> cached_text;
|
||||
///
|
||||
struct save_state {
|
||||
ParagraphList::iterator lpar;
|
||||
ParagraphList::iterator selstartpar;
|
||||
ParagraphList::iterator selendpar;
|
||||
lyx::pos_type pos;
|
||||
lyx::pos_type selstartpos;
|
||||
lyx::pos_type selendpos;
|
||||
bool boundary;
|
||||
bool selstartboundary;
|
||||
bool selendboundary;
|
||||
bool selection;
|
||||
bool mark_set;
|
||||
};
|
||||
///
|
||||
mutable save_state sstate;
|
||||
|
||||
/// some funny 'temporarily saved state'
|
||||
mutable TextCursor sstate;
|
||||
|
||||
///
|
||||
// this is needed globally so we know that we're using it actually and
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "insets/inset.h"
|
||||
#include "RowList.h"
|
||||
#include "bufferview_funcs.h"
|
||||
#include "textcursor.h"
|
||||
|
||||
class Buffer;
|
||||
class BufferParams;
|
||||
@ -38,7 +39,10 @@ class ParagraphList;
|
||||
/**
|
||||
This class holds the mapping between buffer paragraphs and screen rows.
|
||||
*/
|
||||
class LyXText {
|
||||
|
||||
// The inheritance from TextCursor should go. It's just there to ease
|
||||
// transition...
|
||||
class LyXText : public TextCursor {
|
||||
public:
|
||||
/// what repainting is needed
|
||||
enum refresh_status {
|
||||
@ -268,54 +272,7 @@ public:
|
||||
return rowlist_;
|
||||
}
|
||||
|
||||
/** The cursor.
|
||||
Later this variable has to be removed. There should be now 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...
|
||||
*/
|
||||
LyXCursor cursor; // actual cursor position
|
||||
|
||||
/** 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;
|
||||
}
|
||||
LyXCursor cursor; // temporary cursor to hold a cursor position
|
||||
// until setSelection is called!
|
||||
LyXCursor start; // start of a REAL selection
|
||||
LyXCursor end; // end of a REAL selection
|
||||
private:
|
||||
bool set_; // former selection
|
||||
bool mark_; // former mark_set
|
||||
|
||||
};
|
||||
Selection selection;
|
||||
// this is used to handle XSelection events in the right manner
|
||||
Selection xsel_cache;
|
||||
|
||||
/// needed for the toggling (cursor position on last selection made)
|
||||
LyXCursor last_sel_cursor;
|
||||
/// needed for toggling the selection in screen.C
|
||||
LyXCursor toggle_cursor;
|
||||
/// needed for toggling the selection in screen.C
|
||||
LyXCursor toggle_end_cursor;
|
||||
|
||||
|
||||
/// need the selection cursor:
|
||||
void setSelection();
|
||||
///
|
||||
@ -636,6 +593,13 @@ public:
|
||||
|
||||
/// return true if this is owned by an inset.
|
||||
bool isInInset() const;
|
||||
|
||||
private:
|
||||
/** Cursor related data.
|
||||
Later this variable has to be removed. There should be now internal
|
||||
cursor in a text */
|
||||
///
|
||||
///TextCursor cursor_;
|
||||
};
|
||||
|
||||
/// return the default height of a row in pixels, considering font zoom
|
||||
|
74
src/textcursor.h
Normal file
74
src/textcursor.h
Normal file
@ -0,0 +1,74 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file cursor.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author unknown
|
||||
* \author Lars Gullik Bjønnes
|
||||
* \author John Levon
|
||||
*
|
||||
* Full author contact details are available in file CREDITS
|
||||
*/
|
||||
|
||||
#include "lyxcursor.h"
|
||||
|
||||
#ifndef TEXTCURSOR_H
|
||||
#define TEXTCURSOR_H
|
||||
|
||||
/** The cursor.
|
||||
Later this variable has to be removed. There should be now 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]
|
||||
It should neverthe less to keep classes and intedependencies small
|
||||
*/
|
||||
|
||||
// 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;
|
||||
}
|
||||
LyXCursor cursor; // temporary cursor to hold a cursor position
|
||||
// until setSelection is called!
|
||||
LyXCursor start; // start of a REAL selection
|
||||
LyXCursor end; // end of a REAL selection
|
||||
private:
|
||||
bool set_; // former selection
|
||||
bool mark_; // former mark_set
|
||||
|
||||
};
|
||||
|
||||
struct TextCursor {
|
||||
// actual cursor position
|
||||
LyXCursor cursor;
|
||||
|
||||
Selection selection;
|
||||
// this is used to handle XSelection events in the right manner
|
||||
Selection xsel_cache;
|
||||
|
||||
/// needed for the toggling (cursor position on last selection made)
|
||||
LyXCursor last_sel_cursor;
|
||||
/// needed for toggling the selection in screen.C
|
||||
LyXCursor toggle_cursor;
|
||||
/// needed for toggling the selection in screen.C
|
||||
LyXCursor toggle_end_cursor;
|
||||
};
|
||||
|
||||
#endif
|
@ -344,6 +344,12 @@ bool textRedo(BufferView * bv)
|
||||
}
|
||||
|
||||
|
||||
void setUndo(BufferView * bv, Undo::undo_kind kind)
|
||||
{
|
||||
setUndo(bv, kind, bv->text->cursor.par());
|
||||
}
|
||||
|
||||
|
||||
void setUndo(BufferView * bv, Undo::undo_kind kind,
|
||||
ParagraphList::iterator first)
|
||||
{
|
||||
|
@ -33,6 +33,8 @@ void setUndo(BufferView *, Undo::undo_kind kind,
|
||||
ParagraphList::iterator first, ParagraphList::iterator last);
|
||||
void setUndo(BufferView *, Undo::undo_kind kind,
|
||||
ParagraphList::iterator first);
|
||||
// set undo for containing paragraph
|
||||
void setUndo(BufferView *, Undo::undo_kind kind);
|
||||
/// FIXME
|
||||
void setCursorParUndo(BufferView *);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user