richedit: Prevent typing text at end of table row.

This commit is contained in:
Dylan Smith 2008-08-28 16:52:00 -04:00 committed by Alexandre Julliard
parent 36be721027
commit f11fe1c7a9
3 changed files with 78 additions and 4 deletions

View File

@ -3685,6 +3685,8 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
if (((unsigned)wstr)>=' ' if (((unsigned)wstr)>=' '
|| (wstr=='\r' && (GetWindowLongW(hWnd, GWL_STYLE) & ES_MULTILINE)) || (wstr=='\r' && (GetWindowLongW(hWnd, GWL_STYLE) & ES_MULTILINE))
|| wstr=='\t') { || wstr=='\t') {
ME_Cursor cursor = editor->pCursors[0];
ME_DisplayItem *para = ME_GetParagraph(cursor.pRun);
int from, to; int from, to;
BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000; BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
ME_GetSelection(editor, &from, &to); ME_GetSelection(editor, &from, &to);
@ -3693,7 +3695,6 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
&& !(ctrl_is_down && !editor->bEmulateVersion10) && !(ctrl_is_down && !editor->bEmulateVersion10)
) )
{ {
ME_Cursor cursor = editor->pCursors[0];
ME_DisplayItem *para; ME_DisplayItem *para;
BOOL bSelectedRow = FALSE; BOOL bSelectedRow = FALSE;
@ -3712,6 +3713,74 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
ME_CommitUndo(editor); ME_CommitUndo(editor);
return 0; return 0;
} }
} else if (!editor->bEmulateVersion10) { /* v4.1 */
if (para->member.para.nFlags & MEPF_ROWEND) {
if (wstr=='\r') {
/* FIXME: Add a new table row after this row. */
return 0;
} else if (from == to) {
para = para->member.para.next_para;
if (para->member.para.nFlags & MEPF_ROWSTART)
para = para->member.para.next_para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0];
}
}
else if (para == ME_GetParagraph(editor->pCursors[1].pRun) &&
cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 &&
para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART &&
!para->member.para.prev_para->member.para.nCharOfs)
{
/* FIXME: Insert a newline before the table. */
}
} else { /* v1.0 - 3.0 */
ME_DisplayItem *para = ME_GetParagraph(cursor.pRun);
if (ME_IsInTable(cursor.pRun))
{
if (cursor.pRun->member.run.nFlags & MERF_ENDPARA)
{
if (from == to) {
if (wstr=='\r') {
ME_ContinueCoalescingTransaction(editor);
para = ME_AppendTableRow(editor, para);
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0];
ME_CommitCoalescingUndo(editor);
ME_UpdateRepaint(editor);
} else {
/* Text should not be inserted at the end of the table. */
MessageBeep(-1);
}
return 0;
}
} else if (wstr == '\r') {
ME_ContinueCoalescingTransaction(editor);
if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 &&
!ME_IsInTable(para->member.para.prev_para))
{
/* Insert newline before table */
WCHAR endl = '\r';
cursor.pRun = ME_FindItemBack(para, diRun);
if (cursor.pRun)
editor->pCursors[0].pRun = cursor.pRun;
editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0];
ME_InsertTextFromCursor(editor, 0, &endl, 1,
editor->pCursors[0].pRun->member.run.style);
} else {
editor->pCursors[1] = editor->pCursors[0];
para = ME_AppendTableRow(editor, para);
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0];
}
ME_CommitCoalescingUndo(editor);
ME_UpdateRepaint(editor);
return 0;
}
}
} }
/* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */ /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
/* WM_CHAR is restricted to nTextLimit */ /* WM_CHAR is restricted to nTextLimit */

View File

@ -296,6 +296,7 @@ ME_DisplayItem *ME_GetTableRowEnd(ME_DisplayItem *para);
ME_DisplayItem *ME_GetTableRowStart(ME_DisplayItem *para); ME_DisplayItem *ME_GetTableRowStart(ME_DisplayItem *para);
void ME_CheckTablesForCorruption(ME_TextEditor *editor); void ME_CheckTablesForCorruption(ME_TextEditor *editor);
void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars); void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars);
ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ME_DisplayItem *table_row);
void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow); void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow);
struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor); struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor);
void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef); void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef);

View File

@ -381,8 +381,8 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars)
} }
} }
static ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
ME_DisplayItem *table_row) ME_DisplayItem *table_row)
{ {
WCHAR endl = '\r', tab = '\t'; WCHAR endl = '\r', tab = '\t';
ME_DisplayItem *run; ME_DisplayItem *run;
@ -390,9 +390,13 @@ static ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
int i; int i;
assert(table_row); assert(table_row);
assert(table_row->type == diParagraph);
if (!editor->bEmulateVersion10) { /* v4.1 */ if (!editor->bEmulateVersion10) { /* v4.1 */
ME_DisplayItem *insertedCell, *para, *cell; ME_DisplayItem *insertedCell, *para, *cell;
cell = ME_FindItemFwd(table_row, diCell); if (table_row->member.para.nFlags & MEPF_ROWEND)
cell = ME_FindItemBack(table_row, diCell);
else
cell = ME_FindItemFwd(table_row, diCell);
run = ME_GetTableRowEnd(table_row)->member.para.next_para; run = ME_GetTableRowEnd(table_row)->member.para.next_para;
run = ME_FindItemFwd(run, diRun); run = ME_FindItemFwd(run, diRun);
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run;