Commit dee40e90 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Move undo handling to a different set of structs as the display item…

riched20: Move undo handling to a different set of structs as the display item structs are not a good fit.
parent cc796b95
......@@ -361,7 +361,6 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
else
{
ME_Cursor cursor;
ME_UndoItem *undo;
int nCharsToDelete = min(nChars, c.nOffset);
int i;
......@@ -379,14 +378,9 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
nCharsToDelete, nChars, c.nOffset,
debugstr_w(run->strText->szData), run->strText->nLen);
undo = ME_AddUndoItem(editor, diUndoInsertRun, c.pRun);
if (undo)
{
/* nOfs is a character offset (from the start of the document
to the current (deleted) run */
undo->di.member.run.nCharOfs = nOfs + nChars;
undo->di.member.run.strText = ME_MakeStringN(run->strText->szData + c.nOffset, nCharsToDelete);
}
/* nOfs is a character offset (from the start of the document
to the current (deleted) run */
add_undo_insert_run( editor, nOfs + nChars, run->strText->szData + c.nOffset, nCharsToDelete, run->nFlags, run->style );
TRACE("Post deletion string: %s (%d)\n", debugstr_w(run->strText->szData), run->strText->nLen);
TRACE("Shift value: %d\n", shift);
......
......@@ -2709,7 +2709,8 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
ed->nEventMask = 0;
ed->nModifyStep = 0;
ed->nTextLimit = TEXT_LIMIT_DEFAULT;
ed->pUndoStack = ed->pRedoStack = ed->pUndoStackBottom = NULL;
list_init( &ed->undo_stack );
list_init( &ed->redo_stack );
ed->nUndoStackSize = 0;
ed->nUndoLimit = STACK_SIZE_DEFAULT;
ed->nUndoMode = umAddToUndo;
......@@ -3106,9 +3107,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
return editor->nUndoLimit;
}
case EM_CANUNDO:
return editor->pUndoStack != NULL;
return !list_empty( &editor->undo_stack );
case EM_CANREDO:
return editor->pRedoStack != NULL;
return !list_empty( &editor->redo_stack );
case WM_UNDO: /* FIXME: actually not the same */
case EM_UNDO:
return ME_Undo(editor);
......@@ -4348,7 +4349,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
int mask = 0;
int changes = 0;
if (ME_GetTextLength(editor) || editor->pUndoStack || editor->pRedoStack)
if (ME_GetTextLength(editor) ||
!list_empty( &editor->undo_stack ) || !list_empty( &editor->redo_stack ))
return E_UNEXPECTED;
/* Check for mutually exclusive flags in adjacent bits of wParam */
......
......@@ -317,7 +317,12 @@ ITextHost *ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion1
#define ITextHost_TxGetSelectionBarWidth(This,a) TXTHOST_VTABLE(This)->TxGetSelectionBarWidth(This,a)
/* undo.c */
ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_DisplayItem *pdi) DECLSPEC_HIDDEN;
BOOL add_undo_insert_run( ME_TextEditor *, int pos, const WCHAR *str, int len, int flags, ME_Style *style ) DECLSPEC_HIDDEN;
BOOL add_undo_delete_run( ME_TextEditor *, int pos, int len ) DECLSPEC_HIDDEN;
BOOL add_undo_set_para_fmt( ME_TextEditor *, const ME_Paragraph *para ) DECLSPEC_HIDDEN;
BOOL add_undo_set_char_fmt( ME_TextEditor *, int pos, int len, const CHARFORMAT2W *fmt ) DECLSPEC_HIDDEN;
BOOL add_undo_join_paras( ME_TextEditor *, int pos ) DECLSPEC_HIDDEN;
BOOL add_undo_split_para( ME_TextEditor *, const ME_Paragraph *para, const ME_Run *run, const ME_Cell *cell) DECLSPEC_HIDDEN;
void ME_CommitUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_ContinueCoalescingTransaction(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_CommitCoalescingUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN;
......
......@@ -49,6 +49,7 @@
#include <textserv.h>
#include "wine/debug.h"
#include "wine/list.h"
#ifdef __i386__
extern const struct ITextHostVtbl itextHostStdcallVtbl;
......@@ -85,15 +86,6 @@ typedef enum {
diRunOrStartRow,
diParagraphOrEnd,
diRunOrParagraphOrEnd, /* 12 */
diUndoInsertRun, /* 13 */
diUndoDeleteRun, /* 14 */
diUndoJoinParagraphs, /* 15 */
diUndoSplitParagraph, /* 16 */
diUndoSetParagraphFormat, /* 17 */
diUndoSetCharFormat, /* 18 */
diUndoEndTransaction, /* 19 - marks the end of a group of changes for undo */
diUndoPotentialEndTransaction, /* 20 - allows grouping typed chars for undo */
} ME_DIType;
#define SELECTIONBAR_WIDTH 8
......@@ -230,17 +222,9 @@ typedef struct tagME_DisplayItem
ME_Row row;
ME_Cell cell;
ME_Paragraph para;
ME_Style *ustyle; /* used by diUndoSetCharFormat */
} member;
} ME_DisplayItem;
typedef struct tagME_UndoItem
{
ME_DisplayItem di;
int nStart, nLen;
ME_String *eol_str; /* used by diUndoSplitParagraph */
} ME_UndoItem;
typedef struct tagME_TextBuffer
{
ME_DisplayItem *pFirst, *pLast;
......@@ -262,6 +246,75 @@ typedef enum {
umAddBackToUndo
} ME_UndoMode;
enum undo_type
{
undo_insert_run,
undo_delete_run,
undo_join_paras,
undo_split_para,
undo_set_para_fmt,
undo_set_char_fmt,
undo_end_transaction, /* marks the end of a group of changes for undo */
undo_potential_end_transaction /* allows grouping typed chars for undo */
};
struct insert_run_item
{
int pos, len;
WCHAR *str;
ME_Style *style;
DWORD flags;
};
struct delete_run_item
{
int pos, len;
};
struct join_paras_item
{
int pos;
};
struct split_para_item
{
int pos;
PARAFORMAT2 fmt;
ME_BorderRect border;
ME_String *eol_str;
DWORD flags;
ME_BorderRect cell_border;
int cell_right_boundary;
};
struct set_para_fmt_item
{
int pos;
PARAFORMAT2 fmt;
ME_BorderRect border;
};
struct set_char_fmt_item
{
int pos, len;
CHARFORMAT2W fmt;
};
struct undo_item
{
struct list entry;
enum undo_type type;
union
{
struct insert_run_item insert_run;
struct delete_run_item delete_run;
struct join_paras_item join_paras;
struct split_para_item split_para;
struct set_para_fmt_item set_para_fmt;
struct set_char_fmt_item set_char_fmt;
} u;
};
typedef enum {
stPosition = 0,
stWord,
......@@ -337,7 +390,8 @@ typedef struct tagME_TextEditor
BOOL bCaretAtEnd;
int nEventMask;
int nModifyStep;
ME_DisplayItem *pUndoStack, *pRedoStack, *pUndoStackBottom;
struct list undo_stack;
struct list redo_stack;
int nUndoStackSize;
int nUndoLimit;
ME_UndoMode nUndoMode;
......
......@@ -139,32 +139,29 @@ ME_DisplayItem *ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass)
return NULL;
}
void ME_DestroyDisplayItem(ME_DisplayItem *item) {
void ME_DestroyDisplayItem(ME_DisplayItem *item)
{
/* TRACE("type=%s\n", ME_GetDITypeName(item->type)); */
if (item->type==diParagraph || item->type == diUndoSetParagraphFormat) {
if (item->type==diParagraph)
FREE_OBJ(item->member.para.pFmt);
}
if (item->type==diRun || item->type == diUndoInsertRun) {
if (item->type==diRun)
{
if (item->member.run.ole_obj) ME_DeleteReObject(item->member.run.ole_obj);
ME_ReleaseStyle(item->member.run.style);
ME_DestroyString(item->member.run.strText);
}
if (item->type==diUndoSetCharFormat) {
ME_ReleaseStyle(item->member.ustyle);
}
if (item->type==diUndoSplitParagraph) {
FREE_OBJ(item->member.para.pFmt);
FREE_OBJ(item->member.para.pCell);
}
FREE_OBJ(item);
}
ME_DisplayItem *ME_MakeDI(ME_DIType type) {
ME_DisplayItem *ME_MakeDI(ME_DIType type)
{
ME_DisplayItem *item = ALLOC_OBJ(ME_DisplayItem);
ZeroMemory(item, sizeof(ME_DisplayItem));
item->type = type;
item->prev = item->next = NULL;
if (type == diParagraph || type == diUndoSplitParagraph) {
if (type == diParagraph)
{
item->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
ME_SetDefaultParaFormat(item->member.para.pFmt);
item->member.para.nFlags = MEPF_REWRAP;
......@@ -183,14 +180,6 @@ const char *ME_GetDITypeName(ME_DIType type)
case diTextStart: return "diTextStart";
case diTextEnd: return "diTextEnd";
case diStartRow: return "diStartRow";
case diUndoEndTransaction: return "diUndoEndTransaction";
case diUndoPotentialEndTransaction: return "diUndoPotentialEndTransaction";
case diUndoSetParagraphFormat: return "diUndoSetParagraphFormat";
case diUndoSetCharFormat: return "diUndoSetCharFormat";
case diUndoInsertRun: return "diUndoInsertRun";
case diUndoDeleteRun: return "diUndoDeleteRun";
case diUndoJoinParagraphs: return "diJoinParagraphs";
case diUndoSplitParagraph: return "diSplitParagraph";
default: return "?";
}
}
......
......@@ -127,7 +127,7 @@ static BOOL ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const
else
dwMask &= PFM_ALL2;
ME_AddUndoItem(editor, diUndoSetParagraphFormat, para);
add_undo_set_para_fmt( editor, &para->member.para );
copy = *para->member.para.pFmt;
......@@ -198,7 +198,6 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
ME_DisplayItem *run_para = NULL;
ME_DisplayItem *new_para = ME_MakeDI(diParagraph);
ME_DisplayItem *end_run;
ME_UndoItem *undo = NULL;
int ofs, i;
ME_DisplayItem *pp;
int run_flags = MERF_ENDPARA;
......@@ -224,9 +223,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
next_para = run_para->member.para.next_para;
assert(next_para == ME_FindItemFwd(run_para, diParagraphOrEnd));
undo = ME_AddUndoItem(editor, diUndoJoinParagraphs, NULL);
if (undo)
undo->nStart = run_para->member.para.nCharOfs + ofs;
add_undo_join_paras( editor, run_para->member.para.nCharOfs + ofs );
/* Update selection cursors to point to the correct paragraph. */
for (i = 0; i < editor->nCursors; i++) {
......@@ -324,7 +321,6 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
{
ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp, *pCell = NULL;
int i, shift;
ME_UndoItem *undo = NULL;
int end_len;
CHARFORMAT2W fmt;
ME_Cursor startCur, endCur;
......@@ -370,26 +366,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
}
}
undo = ME_AddUndoItem(editor, diUndoSplitParagraph, pNext);
if (undo)
{
undo->nStart = pNext->member.para.nCharOfs - end_len;
undo->eol_str = pRun->member.run.strText;
pRun->member.run.strText = NULL; /* Avoid freeing the string */
if (pCell)
{
assert(!(undo->di.member.para.nFlags & MEPF_ROWEND));
if (!(undo->di.member.para.nFlags & MEPF_ROWSTART))
undo->di.member.para.nFlags |= MEPF_CELL;
undo->di.member.para.pCell = ALLOC_OBJ(ME_DisplayItem);
*undo->di.member.para.pCell = *pCell;
undo->di.member.para.pCell->next = NULL;
undo->di.member.para.pCell->prev = NULL;
undo->di.member.para.pCell->member.cell.next_cell = NULL;
undo->di.member.para.pCell->member.cell.prev_cell = NULL;
}
}
add_undo_split_para( editor, &pNext->member.para, &pRun->member.run, pCell ? &pCell->member.cell : NULL );
if (pCell)
{
......@@ -403,7 +380,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
if (!keepFirstParaFormat)
{
ME_AddUndoItem(editor, diUndoSetParagraphFormat, tp);
add_undo_set_para_fmt( editor, &tp->member.para );
*tp->member.para.pFmt = *pNext->member.para.pFmt;
tp->member.para.border = pNext->member.para.border;
}
......
......@@ -357,17 +357,12 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
const WCHAR *str, int len, int flags)
{
ME_DisplayItem *pDI;
ME_UndoItem *pUI;
if (cursor->nOffset)
ME_SplitRunSimple(editor, cursor);
pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
if (pUI) {
pUI->nStart = cursor->pPara->member.para.nCharOfs
+ cursor->pRun->member.run.nCharOfs;
pUI->nLen = len;
}
add_undo_delete_run( editor, cursor->pPara->member.para.nCharOfs +
cursor->pRun->member.run.nCharOfs, len );
pDI = ME_MakeRun(style, ME_MakeStringN(str, len), flags);
pDI->member.run.nCharOfs = cursor->pRun->member.run.nCharOfs;
......@@ -769,19 +764,12 @@ void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, C
while(run != end_run)
{
ME_UndoItem *undo = NULL;
ME_Style *new_style = ME_ApplyStyle(run->member.run.style, pFmt);
/* ME_DumpStyle(new_style); */
undo = ME_AddUndoItem(editor, diUndoSetCharFormat, NULL);
if (undo) {
undo->nStart = run->member.run.nCharOfs+para->member.para.nCharOfs;
undo->nLen = run->member.run.strText->nLen;
undo->di.member.ustyle = run->member.run.style;
/* we'd have to addref undo...ustyle and release tmp...style
but they'd cancel each other out so we can do nothing instead */
}
else
ME_ReleaseStyle(run->member.run.style);
add_undo_set_char_fmt( editor, para->member.para.nCharOfs + run->member.run.nCharOfs,
run->member.run.strText->nLen, &run->member.run.style->fmt );
ME_ReleaseStyle(run->member.run.style);
run->member.run.style = new_style;
run = ME_FindItemFwd(run, diRunOrParagraph);
if (run && run->type == diParagraph)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment