Author: cwittich Date: Mon Sep 22 09:29:28 2008 New Revision: 36404
URL: http://svn.reactos.org/svn/reactos?rev=36404&view=rev Log: sync riched20 with wine 1.1.5
Modified: trunk/reactos/dll/win32/riched20/caret.c trunk/reactos/dll/win32/riched20/editor.c trunk/reactos/dll/win32/riched20/editor.h trunk/reactos/dll/win32/riched20/paint.c trunk/reactos/dll/win32/riched20/para.c trunk/reactos/dll/win32/riched20/reader.c trunk/reactos/dll/win32/riched20/rtf.h trunk/reactos/dll/win32/riched20/table.c trunk/reactos/dll/win32/riched20/undo.c
Modified: trunk/reactos/dll/win32/riched20/caret.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/caret.c?... ============================================================================== --- trunk/reactos/dll/win32/riched20/caret.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/caret.c [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -889,6 +889,23 @@ return para; }
+static BOOL ME_ReturnFoundPos(ME_TextEditor *editor, ME_DisplayItem *found, + ME_Cursor *result, int rx, BOOL isExact) +{ + assert(found); + assert(found->type == diRun); + if ((found->member.run.nFlags & MERF_ENDPARA) || rx < 0) + rx = 0; + result->pRun = found; + result->nOffset = ME_CharFromPointCursor(editor, rx, &found->member.run); + if (editor->pCursors[0].nOffset == found->member.run.strText->nLen && rx) + { + result->pRun = ME_FindItemFwd(editor->pCursors[0].pRun, diRun); + result->nOffset = 0; + } + return isExact; +} + /* Finds the run and offset from the pixel position. * * x & y are pixel positions in virtual coordinates into the rich edit control, @@ -963,34 +980,21 @@ case diRun: rx = x - p->member.run.pt.x; if (rx < p->member.run.nWidth) - { - found_here: - assert(p->type == diRun); - if ((p->member.run.nFlags & MERF_ENDPARA) || rx < 0) - rx = 0; - result->pRun = p; - result->nOffset = ME_CharFromPointCursor(editor, rx, &p->member.run); - if (editor->pCursors[0].nOffset == p->member.run.strText->nLen && rx) - { - result->pRun = ME_FindItemFwd(editor->pCursors[0].pRun, diRun); - result->nOffset = 0; - } - return isExact; - } + return ME_ReturnFoundPos(editor, p, result, rx, isExact); break; case diStartRow: isExact = FALSE; p = ME_FindItemFwd(p, diRun); if (is_eol) *is_eol = 1; rx = 0; /* FIXME not sure */ - goto found_here; + return ME_ReturnFoundPos(editor, p, result, rx, isExact); case diCell: case diParagraph: case diTextEnd: isExact = FALSE; rx = 0; /* FIXME not sure */ p = last; - goto found_here; + return ME_ReturnFoundPos(editor, p, result, rx, isExact); default: assert(0); } last = p;
Modified: trunk/reactos/dll/win32/riched20/editor.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/editor.c... ============================================================================== --- trunk/reactos/dll/win32/riched20/editor.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/editor.c [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -346,7 +346,7 @@ } }
-static void ME_RTFCharAttrHook(RTF_Info *info) +void ME_RTFCharAttrHook(RTF_Info *info) { CHARFORMAT2W fmt; fmt.cbSize = sizeof(fmt); @@ -468,7 +468,7 @@
/* FIXME this function doesn't get any information about context of the RTF tag, which is very bad, the same tags mean different things in different contexts */ -static void ME_RTFParAttrHook(RTF_Info *info) +void ME_RTFParAttrHook(RTF_Info *info) { PARAFORMAT2 fmt; fmt.cbSize = sizeof(fmt); @@ -825,7 +825,7 @@ } }
-static void ME_RTFTblAttrHook(RTF_Info *info) +void ME_RTFTblAttrHook(RTF_Info *info) { switch (info->rtfMinor) { @@ -843,24 +843,27 @@ break; } case rtfCellPos: + { + int cellNum; if (!info->tableDef) { info->tableDef = ME_MakeTableDef(info->editor); } - if (info->tableDef->numCellsDefined >= MAX_TABLE_CELLS) + cellNum = info->tableDef->numCellsDefined; + if (cellNum >= MAX_TABLE_CELLS) break; - info->tableDef->cells[info->tableDef->numCellsDefined].rightBoundary = info->rtfParam; - { + info->tableDef->cells[cellNum].rightBoundary = info->rtfParam; + if (cellNum < MAX_TAB_STOPS) { /* Tab stops were used to store cell positions before v4.1 but v4.1 * still seems to set the tabstops without using them. */ ME_DisplayItem *para = ME_GetParagraph(info->editor->pCursors[0].pRun); PARAFORMAT2 *pFmt = para->member.para.pFmt; - int cellNum = info->tableDef->numCellsDefined; pFmt->rgxTabs[cellNum] &= ~0x00FFFFFF; pFmt->rgxTabs[cellNum] = 0x00FFFFFF & info->rtfParam; } info->tableDef->numCellsDefined++; break; + } case rtfRowBordTop: info->borderType = RTFBorderRowTop; break; @@ -896,7 +899,7 @@ } }
-static void ME_RTFSpecialCharHook(RTF_Info *info) +void ME_RTFSpecialCharHook(RTF_Info *info) { RTFTable *tableDef = info->tableDef; switch (info->rtfMinor) @@ -1045,7 +1048,7 @@ ME_InsertTextFromCursor(info->editor, 0, &tab, 1, info->style); tableDef->numCellsInserted++; } - pFmt->cTabCount = tableDef->numCellsDefined; + pFmt->cTabCount = min(tableDef->numCellsDefined, MAX_TAB_STOPS); if (!tableDef->numCellsDefined) pFmt->wEffects &= ~PFE_TABLE; ME_InsertTextFromCursor(info->editor, 0, &endl, 1, info->style); @@ -1325,7 +1328,8 @@ RTFRouteToken(info); /* feed "}" back to router */ }
-static void ME_RTFReadHook(RTF_Info *info) { +static void ME_RTFReadHook(RTF_Info *info) +{ switch(info->rtfClass) { case rtfGroup: @@ -1363,23 +1367,6 @@ } } break; - case rtfControl: - switch(info->rtfMajor) - { - case rtfCharAttr: - ME_RTFCharAttrHook(info); - break; - case rtfParAttr: - ME_RTFParAttrHook(info); - break; - case rtfTblAttr: - ME_RTFTblAttrHook(info); - break; - case rtfSpecialChar: - ME_RTFSpecialCharHook(info); - break; - } - break; } }
@@ -1477,8 +1464,6 @@ if (!invalidRTF && !inStream.editstream->dwError) { if (format & SF_RTF) { - ME_DisplayItem *para; - /* setup the RTF parser */ memset(&parser, 0, sizeof parser); RTFSetEditStream(&parser, &inStream); @@ -1492,20 +1477,23 @@ RTFSetDestinationCallback(&parser, rtfPict, ME_RTFReadPictGroup); RTFSetDestinationCallback(&parser, rtfObject, ME_RTFReadObjectGroup); if (!parser.editor->bEmulateVersion10) /* v4.1 */ + { RTFSetDestinationCallback(&parser, rtfNoNestTables, RTFSkipGroup); + RTFSetDestinationCallback(&parser, rtfNestTableProps, RTFReadGroup); + } BeginFile(&parser);
/* do the parsing */ RTFRead(&parser); RTFFlushOutputBuffer(&parser); if (!editor->bEmulateVersion10) { /* v4.1 */ - if (parser.tableDef && parser.tableDef->tableRowStart) + if (parser.tableDef && parser.tableDef->tableRowStart && + (parser.nestingLevel > 0 || parser.canInheritInTbl)) { /* Delete any incomplete table row at the end of the rich text. */ int nOfs, nChars; ME_DisplayItem *pCell; - - para = parser.tableDef->tableRowStart; + ME_DisplayItem *para;
parser.rtfMinor = rtfRow; /* Complete the table row before deleting it. @@ -1514,14 +1502,14 @@ * will be added for this change to the current paragraph format. */ if (parser.nestingLevel > 0) { - while (parser.nestingLevel--) - ME_RTFSpecialCharHook(&parser); - } else if (parser.canInheritInTbl) { + while (parser.nestingLevel > 1) + ME_RTFSpecialCharHook(&parser); /* Decrements nestingLevel */ + para = parser.tableDef->tableRowStart; ME_RTFSpecialCharHook(&parser); - } - if (parser.tableDef && parser.tableDef->tableRowStart && - para->member.para.nFlags & MEPF_ROWEND) - { + } else { + para = parser.tableDef->tableRowStart; + ME_RTFSpecialCharHook(&parser); + assert(para->member.para.nFlags & MEPF_ROWEND); para = para->member.para.next_para; } pCell = para->member.para.pCell; @@ -1531,7 +1519,8 @@ nOfs = ME_GetCursorOfs(editor, 1); nChars = ME_GetCursorOfs(editor, 0) - nOfs; ME_InternalDeleteText(editor, nOfs, nChars, TRUE); - parser.tableDef->tableRowStart = NULL; + if (parser.tableDef) + parser.tableDef->tableRowStart = NULL; } } ME_CheckTablesForCorruption(editor); @@ -2028,6 +2017,7 @@ } else return TRUE; + ME_MoveCursorFromTableRowStartParagraph(editor); ME_UpdateSelectionLinkAttribute(editor); ME_UpdateRepaint(editor); ME_SendRequestResize(editor, FALSE); @@ -3716,7 +3706,15 @@ } 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. */ + /* Add a new table row after this row. */ + para = ME_AppendTableRow(editor, para); + 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]; + ME_CommitUndo(editor); + ME_CheckTablesForCorruption(editor); + ME_UpdateRepaint(editor); return 0; } else if (from == to) { para = para->member.para.next_para; @@ -3732,7 +3730,24 @@ 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. */ + /* Insert a newline before the table. */ + WCHAR endl = '\r'; + para = para->member.para.prev_para; + para->member.para.nFlags &= ~MEPF_ROWSTART; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[1] = editor->pCursors[0]; + ME_InsertTextFromCursor(editor, 0, &endl, 1, + editor->pCursors[0].pRun->member.run.style); + para = editor->pBuffer->pFirst->member.para.next_para; + ME_SetDefaultParaFormat(para->member.para.pFmt); + para->member.para.nFlags = MEPF_REWRAP; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[1] = editor->pCursors[0]; + para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART; + ME_CommitCoalescingUndo(editor); + ME_CheckTablesForCorruption(editor); + ME_UpdateRepaint(editor); + return 0; } } else { /* v1.0 - 3.0 */ ME_DisplayItem *para = ME_GetParagraph(cursor.pRun);
Modified: trunk/reactos/dll/win32/riched20/editor.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/editor.h... ============================================================================== --- trunk/reactos/dll/win32/riched20/editor.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/editor.h [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -21,9 +21,11 @@ #include "editstr.h" #include "wine/unicode.h"
+struct _RTF_Info; + extern HANDLE me_heap;
-static inline void __WINE_ALLOC_SIZE(1) *heap_alloc( size_t len ) +static inline void * __WINE_ALLOC_SIZE(1) heap_alloc( size_t len ) { return HeapAlloc( me_heap, 0, len ); } @@ -33,7 +35,7 @@ return HeapFree( me_heap, 0, ptr ); }
-static inline void __WINE_ALLOC_SIZE(2) *heap_realloc( void *ptr, size_t len ) +static inline void * __WINE_ALLOC_SIZE(2) heap_realloc( void *ptr, size_t len ) { return HeapReAlloc( me_heap, 0, ptr, len ); } @@ -275,6 +277,10 @@ void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam); int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, BOOL bCRLF); ME_DisplayItem *ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset); +void ME_RTFCharAttrHook(struct _RTF_Info *info); +void ME_RTFParAttrHook(struct _RTF_Info *info); +void ME_RTFTblAttrHook(struct _RTF_Info *info); +void ME_RTFSpecialCharHook(struct _RTF_Info *info); void ME_StreamInFill(ME_InStream *stream); int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar); extern int me_debug; @@ -298,6 +304,7 @@ 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_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor); struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor); void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef);
Modified: trunk/reactos/dll/win32/riched20/paint.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/paint.c?... ============================================================================== --- trunk/reactos/dll/win32/riched20/paint.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/paint.c [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -1046,6 +1046,9 @@ { SCROLLINFO si; int nOrigPos, nNewPos, nActualScroll; + HWND hWnd; + LONG winStyle; + BOOL bScrollBarIsVisible, bScrollBarWillBeVisible;
nOrigPos = ME_GetYScrollPos(editor);
@@ -1072,6 +1075,7 @@ }
nNewPos = SetScrollInfo(editor->hWnd, SB_VERT, &si, editor->bRedraw); + editor->vert_si.nPos = nNewPos; nActualScroll = nOrigPos - nNewPos; if (editor->bRedraw) { @@ -1082,7 +1086,15 @@ ME_Repaint(editor); }
- editor->vert_si.nMax = 0; + hWnd = editor->hWnd; + winStyle = GetWindowLongW(hWnd, GWL_STYLE); + bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0; + bScrollBarWillBeVisible = (editor->nHeight > editor->sizeWindow.cy) + || (winStyle & ES_DISABLENOSCROLL); + if (bScrollBarIsVisible != bScrollBarWillBeVisible) + { + ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible); + } ME_UpdateScrollBar(editor); }
@@ -1105,11 +1117,10 @@ bScrollBarWasVisible = ME_GetYScrollVisible(editor); bScrollBarWillBeVisible = editor->nHeight > editor->sizeWindow.cy;
- si.fMask = SIF_PAGE | SIF_RANGE; + si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; if (GetWindowLongW(hWnd, GWL_STYLE) & ES_DISABLENOSCROLL) + { si.fMask |= SIF_DISABLENOSCROLL; - if ((si.fMask & SIF_DISABLENOSCROLL)) - { bScrollBarWillBeVisible = TRUE; }
@@ -1122,7 +1133,7 @@
si.nMin = 0; si.nMax = editor->nTotalLength; - + si.nPos = editor->vert_si.nPos; si.nPage = editor->sizeWindow.cy;
if (!(si.nMin == editor->vert_si.nMin && si.nMax == editor->vert_si.nMax && si.nPage == editor->vert_si.nPage)) @@ -1138,17 +1149,18 @@ else { if (bScrollBarWasVisible && !(si.fMask & SIF_DISABLENOSCROLL)) + { + SetScrollInfo(hWnd, SB_VERT, &si, TRUE); ShowScrollBar(hWnd, SB_VERT, FALSE); + ME_ScrollAbs(editor, 0); + } } } }
int ME_GetYScrollPos(ME_TextEditor *editor) { - SCROLLINFO si; - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - return GetScrollInfo(editor->hWnd, SB_VERT, &si) ? si.nPos : 0; + return editor->vert_si.nPos; }
BOOL ME_GetYScrollVisible(ME_TextEditor *editor)
Modified: trunk/reactos/dll/win32/riched20/para.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/para.c?r... ============================================================================== --- trunk/reactos/dll/win32/riched20/para.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/para.c [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -220,6 +220,13 @@ new_para->member.para.pCell = run_para->member.para.pCell; assert(run_para->member.para.prev_para->member.para.nFlags & MEPF_CELL); assert(!(run_para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART)); + if (new_para->member.para.pCell != new_para->member.para.next_para->member.para.pCell + && new_para->member.para.next_para->member.para.pCell + && !new_para->member.para.next_para->member.para.pCell->member.cell.prev_cell) + { + /* Row starts just after the row that was ended. */ + new_para->member.para.nFlags |= MEPF_ROWSTART; + } } else { new_para->member.para.pCell = run_para->member.para.pCell; }
Modified: trunk/reactos/dll/win32/riched20/reader.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/reader.c... ============================================================================== --- trunk/reactos/dll/win32/riched20/reader.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/reader.c [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -242,8 +242,6 @@ info->cpOutputBuffer = heap_alloc(info->dwMaxCPOutputCount); }
- if (info->tableDef) - ZeroMemory(info->tableDef, sizeof(info->tableDef)); info->tableDef = NULL; info->nestingLevel = 0; info->canInheritInTbl = FALSE; @@ -404,6 +402,16 @@ } } } +} + +/* + * Do no special processing on the group. + * + * This acts as a placeholder for a callback in order to indicate that it + * shouldn't be ignored. Instead it will fallback on the loop in RTFRead. + */ +void RTFReadGroup (RTF_Info *info) +{ }
@@ -2477,6 +2485,13 @@ { case rtfCharAttr: CharAttr(info); + ME_RTFCharAttrHook(info); + break; + case rtfParAttr: + ME_RTFParAttrHook(info); + break; + case rtfTblAttr: + ME_RTFTblAttrHook(info); break; case rtfCharSet: CharSet(info); @@ -2492,6 +2507,7 @@ break; case rtfSpecialChar: SpecialChar (info); + ME_RTFSpecialCharHook(info); break; } }
Modified: trunk/reactos/dll/win32/riched20/rtf.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/rtf.h?re... ============================================================================== --- trunk/reactos/dll/win32/riched20/rtf.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/rtf.h [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -1211,6 +1211,7 @@ RTFFuncPtr RTFGetReadHook (const RTF_Info *); void RTFRouteToken (RTF_Info *); void RTFSkipGroup (RTF_Info *); +void RTFReadGroup (RTF_Info *); void RTFExpandStyle (RTF_Info *, int); int RTFCheckCM (const RTF_Info *, int, int); int RTFCheckCMM (const RTF_Info *, int, int, int);
Modified: trunk/reactos/dll/win32/riched20/table.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/table.c?... ============================================================================== --- trunk/reactos/dll/win32/riched20/table.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/table.c [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -227,7 +227,7 @@ } else if (!(p->member.para.nFlags & MEPF_ROWSTART)) { - assert(!(p->member.para.pFmt->wEffects & (PFE_TABLE|PFE_TABLEROWDELIMITER))); + assert(!(p->member.para.pFmt->wEffects & PFE_TABLEROWDELIMITER)); /* ROWSTART must be followed by a cell. */ assert(!(p->member.para.nFlags & MEPF_CELL)); /* ROWSTART must be followed by a cell. */ @@ -393,10 +393,7 @@ assert(table_row->type == diParagraph); if (!editor->bEmulateVersion10) { /* v4.1 */ ME_DisplayItem *insertedCell, *para, *cell; - if (table_row->member.para.nFlags & MEPF_ROWEND) - cell = ME_FindItemBack(table_row, diCell); - else - cell = ME_FindItemFwd(table_row, diCell); + cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell); run = ME_GetTableRowEnd(table_row)->member.para.next_para; run = ME_FindItemFwd(run, diRun); editor->pCursors[0].pRun = run; @@ -588,6 +585,22 @@ ME_SendSelChange(editor); }
+/* Make sure the cursor is not in the hidden table row start paragraph + * without a selection. */ +void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor) +{ + ME_DisplayItem *para = ME_GetParagraph(editor->pCursors[0].pRun); + if (para == ME_GetParagraph(editor->pCursors[1].pRun) && + para->member.para.nFlags & MEPF_ROWSTART) { + /* The cursors should not be at the hidden start row paragraph without + * a selection, so the cursor is moved into the first cell. */ + 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]; + } +} + struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor) { RTFTable *tableDef = ALLOC_OBJ(RTFTable);
Modified: trunk/reactos/dll/win32/riched20/undo.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/riched20/undo.c?r... ============================================================================== --- trunk/reactos/dll/win32/riched20/undo.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/riched20/undo.c [iso-8859-1] Mon Sep 22 09:29:28 2008 @@ -386,6 +386,7 @@ } while(p && p->type != diUndoEndTransaction); if (p) p->prev = NULL; + ME_MoveCursorFromTableRowStartParagraph(editor); ME_AddUndoItem(editor, diUndoEndTransaction, NULL); ME_CheckTablesForCorruption(editor); editor->nUndoStackSize--; @@ -422,6 +423,7 @@ } while(p && p->type != diUndoEndTransaction); if (p) p->prev = NULL; + ME_MoveCursorFromTableRowStartParagraph(editor); ME_AddUndoItem(editor, diUndoEndTransaction, NULL); ME_CheckTablesForCorruption(editor); editor->nUndoMode = nMode;