#include "Painter.h"
#include "lyx_gui_misc.h"
#include "support/LAssert.h"
+#include "lyxtext.h"
+#include "lyxcursor.h"
extern unsigned char getCurrentTextClass(Buffer *);
InsetText::InsetText(Buffer * buf)
{
par = new LyXParagraph();
- the_locking_inset = 0;
- buffer = buf;
- cursor_visible = false;
- maxWidth = old_x = -1;
- actpos = selection_start = selection_end = 0;
- interline_space = 1;
- no_selection = false;
- init_inset = true;
- maxAscent = maxDescent = insetWidth = widthOffset = 0;
- autoBreakRows = false;
- xpos = 0.0;
+ init(buf);
}
InsetText::InsetText(InsetText const & ins, Buffer * buf)
{
- par = new LyXParagraph(ins.par);
+ par = 0;
+ init(buf, ins.par);
+}
+
+void InsetText::init(Buffer * buf, LyXParagraph *p)
+{
+ if (p) {
+ if (par)
+ delete par;
+ par = new LyXParagraph(p);
+ for(int pos = 0; pos < p->Last(); ++pos) {
+ par->InsertChar(pos, p->GetChar(pos));
+ par->SetFont(pos, p->GetFontSettings(pos));
+ if ((p->GetChar(pos) == LyXParagraph::META_INSET) &&
+ p->GetInset(pos)) {
+ par->InsertInset(pos, p->GetInset(pos)->Clone());
+ }
+ }
+ }
the_locking_inset = 0;
buffer = buf;
cursor_visible = false;
setPos(bv, x,y);
selection_start = selection_end = actpos;
current_font = real_current_font = GetFont(par, actpos);
+ bv->text->FinishUndo();
}
switch (action) {
// Normal chars
case -1:
+ bv->text->SetUndo(Undo::INSERT,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
cutSelection();
actpos = selection_start;
par->InsertChar(actpos,arg[0]);
break;
// --- Cursor Movements ---------------------------------------------
case LFUN_RIGHTSEL:
+ bv->text->FinishUndo();
moveRight(bv, false);
selection_end = actpos;
UpdateLocal(bv, false);
break;
case LFUN_RIGHT:
+ bv->text->FinishUndo();
result= DISPATCH_RESULT(moveRight(bv));
if (hasSelection()) {
selection_start = selection_end = actpos;
}
break;
case LFUN_LEFTSEL:
+ bv->text->FinishUndo();
moveLeft(bv, false);
selection_end = actpos;
UpdateLocal(bv, false);
break;
case LFUN_LEFT:
- result= DISPATCH_RESULT(moveLeft(bv));
- if (hasSelection()) {
- selection_start = selection_end = actpos;
- UpdateLocal(bv, false);
- } else {
- selection_start = selection_end = actpos;
- }
- break;
+ bv->text->FinishUndo();
+ result= DISPATCH_RESULT(moveLeft(bv));
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ UpdateLocal(bv, false);
+ } else {
+ selection_start = selection_end = actpos;
+ }
+ break;
case LFUN_DOWNSEL:
+ bv->text->FinishUndo();
moveDown(bv, false);
selection_end = actpos;
UpdateLocal(bv, false);
break;
case LFUN_DOWN:
+ bv->text->FinishUndo();
result= DISPATCH_RESULT(moveDown(bv));
if (hasSelection()) {
selection_start = selection_end = actpos;
}
break;
case LFUN_UPSEL:
+ bv->text->FinishUndo();
moveUp(bv, false);
selection_end = actpos;
UpdateLocal(bv, false);
break;
case LFUN_UP:
+ bv->text->FinishUndo();
result= DISPATCH_RESULT(moveUp(bv));
if (hasSelection()) {
selection_start = selection_end = actpos;
}
break;
case LFUN_BACKSPACE:
- if (!actpos || par->IsNewline(actpos-1)) {
+ if (!actpos) { // || par->IsNewline(actpos-1)) {
if (hasSelection()) {
selection_start = selection_end = actpos;
UpdateLocal(bv, false);
moveLeft(bv);
case LFUN_DELETE:
bool ret;
+ bv->text->SetUndo(Undo::DELETE,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
if (hasSelection())
ret = cutSelection();
else
}
break;
case LFUN_CUT:
+ bv->text->SetUndo(Undo::DELETE,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
if (cutSelection()) { // we need update
actpos = selection_end = selection_start;
UpdateLocal(bv, true);
}
break;
case LFUN_COPY:
+ bv->text->FinishUndo();
if (copySelection()) { // we need update
selection_start = selection_end = actpos;
UpdateLocal(bv, true);
}
break;
case LFUN_PASTE:
+ bv->text->SetUndo(Undo::INSERT,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
if (pasteSelection()) {
selection_start = selection_end = actpos;
UpdateLocal(bv, true);
}
break;
case LFUN_HOME:
+ bv->text->FinishUndo();
for(; actpos > rows[actrow].pos; --actpos)
cx -= SingleWidth(bv->getPainter(), par, actpos);
cx -= SingleWidth(bv->getPainter(), par, actpos);
break;
case LFUN_END:
{
+ bv->text->FinishUndo();
int checkpos = (int)rows[actrow + 1].pos;
if ((actrow + 2) < (int)rows.size())
--checkpos;
}
break;
case LFUN_MATH_MODE: // Open or create a math inset
+ bv->text->SetUndo(Undo::INSERT,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
InsertInset(bv, new InsetFormula);
if (hasSelection()) {
selection_start = selection_end = actpos;
}
return DISPATCHED;
case LFUN_BREAKLINE:
+ bv->text->SetUndo(Undo::INSERT,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous,
+ bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next);
par->InsertChar(actpos,LyXParagraph::META_NEWLINE);
par->SetFont(actpos,real_current_font);
UpdateLocal(bv, true);
width -= lastWordWidth;
} else {
// assign last row data
-// width = lastWordWidth;
-// lastWordWidth = 0;
rows.back().asc = max(oasc, wordAscent);
rows.back().desc = max(odesc, wordDescent);
}