From 8fe4fd0f5269bde3ec0ac7e552cb71979cdf2b26 Mon Sep 17 00:00:00 2001 From: The Wine Synchronizer Date: Thu, 29 Nov 2007 11:12:33 +0000 Subject: [PATCH] Autosyncing with Wine HEAD svn path=/trunk/; revision=30881 --- reactos/dll/win32/riched20/caret.c | 184 ++++++------ reactos/dll/win32/riched20/clipboard.c | 10 +- reactos/dll/win32/riched20/context.c | 2 +- reactos/dll/win32/riched20/editor.c | 308 +++++++++++---------- reactos/dll/win32/riched20/editor.h | 72 ++--- reactos/dll/win32/riched20/editstr.h | 13 +- reactos/dll/win32/riched20/list.c | 8 +- reactos/dll/win32/riched20/paint.c | 116 ++++---- reactos/dll/win32/riched20/para.c | 114 ++++---- reactos/dll/win32/riched20/reader.c | 38 +-- reactos/dll/win32/riched20/riched20.rbuild | 9 +- reactos/dll/win32/riched20/richole.c | 4 +- reactos/dll/win32/riched20/row.c | 14 +- reactos/dll/win32/riched20/rtf.h | 30 +- reactos/dll/win32/riched20/run.c | 196 ++++++------- reactos/dll/win32/riched20/string.c | 58 ++-- reactos/dll/win32/riched20/style.c | 39 ++- reactos/dll/win32/riched20/undo.c | 40 +-- reactos/dll/win32/riched20/wrap.c | 16 +- reactos/dll/win32/riched20/writer.c | 84 +++--- 20 files changed, 704 insertions(+), 651 deletions(-) diff --git a/reactos/dll/win32/riched20/caret.c b/reactos/dll/win32/riched20/caret.c index d20c5b3f2cc..3bc5b5e4f10 100644 --- a/reactos/dll/win32/riched20/caret.c +++ b/reactos/dll/win32/riched20/caret.c @@ -32,22 +32,22 @@ void ME_GetSelection(ME_TextEditor *editor, int *from, int *to) { *from = ME_GetCursorOfs(editor, 0); *to = ME_GetCursorOfs(editor, 1); - + if (*from > *to) { int tmp = *from; *from = *to; - *to = tmp; + *to = tmp; } } int ME_GetTextLength(ME_TextEditor *editor) { - return ME_CharOfsFromRunOfs(editor, ME_FindItemBack(editor->pBuffer->pLast, diRun), 0); + return ME_CharOfsFromRunOfs(editor, ME_FindItemBack(editor->pBuffer->pLast, diRun), 0); } -int ME_GetTextLengthEx(ME_TextEditor *editor, GETTEXTLENGTHEX *how) +int ME_GetTextLengthEx(ME_TextEditor *editor, const GETTEXTLENGTHEX *how) { int length; @@ -55,16 +55,16 @@ int ME_GetTextLengthEx(ME_TextEditor *editor, GETTEXTLENGTHEX *how) return E_INVALIDARG; if (how->flags & GTL_NUMCHARS && how->flags & GTL_NUMBYTES) return E_INVALIDARG; - + length = ME_GetTextLength(editor); - if (how->flags & GTL_USECRLF) + if ((GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_MULTILINE) && (how->flags & GTL_USECRLF)) length += editor->nParagraphs; - + if (how->flags & GTL_NUMBYTES) { CPINFO cpinfo; - + if (how->codepage == 1200) return length * 2; if (how->flags & GTL_PRECISE) @@ -74,7 +74,7 @@ int ME_GetTextLengthEx(ME_TextEditor *editor, GETTEXTLENGTHEX *how) ERR("Invalid codepage %u\n", how->codepage); return E_INVALIDARG; } - return length; + return length; } @@ -93,8 +93,8 @@ int ME_SetSelection(ME_TextEditor *editor, int from, int to) if (from == 0 && to == -1) { editor->pCursors[1].pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun); - editor->pCursors[1].nOffset = 0; - editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun); + editor->pCursors[1].nOffset = 0; + editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun); editor->pCursors[0].nOffset = 0; ME_InvalidateSelection(editor); ME_ClearTempStyle(editor); @@ -168,7 +168,7 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor, assert(!(ME_GetParagraph(pCursorRun)->member.para.nFlags & MEPF_REWRAP)); assert(pCursor->pRun); assert(pCursor->pRun->type == diRun); - + if (pCursorRun->type == diRun) { ME_DisplayItem *row = ME_FindItemBack(pCursorRun, diStartRowOrParagraph); @@ -178,9 +178,9 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor, ME_DisplayItem *run = pCursorRun; ME_DisplayItem *para = NULL; SIZE sz = {0, 0}; - + ME_InitContext(&c, editor, hDC); - + if (!pCursor->nOffset && !editor->bCaretAtEnd) { ME_DisplayItem *prev = ME_FindItemBack(pCursorRun, diRunOrStartRow); @@ -192,7 +192,7 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor, para = ME_FindItemBack(row, diParagraph); assert(para); assert(para->type == diParagraph); - if (editor->bCaretAtEnd && !pCursor->nOffset && + if (editor->bCaretAtEnd && !pCursor->nOffset && run == ME_FindItemFwd(row, diRun)) { ME_DisplayItem *tmp = ME_FindItemBack(row, diRunOrParagraph); @@ -213,7 +213,7 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor, *height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent; *x = run->member.run.pt.x + sz.cx; *y = para->member.para.nYPos + row->member.row.nBaseline + pSizeRun->member.run.pt.y - pSizeRun->member.run.nAscent - ME_GetYScrollPos(editor); - + ME_DestroyContext(&c); ReleaseDC(editor->hWnd, hDC); return; @@ -230,7 +230,8 @@ ME_MoveCaret(ME_TextEditor *editor) { int x, y, height; - ME_WrapMarkedParagraphs(editor); + if (ME_WrapMarkedParagraphs(editor)) + ME_UpdateScrollBar(editor); ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height); if(editor->bHaveFocus) { @@ -256,12 +257,12 @@ void ME_HideCaret(ME_TextEditor *ed) } } -void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, +void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars) { ME_Cursor c; int shift = 0; - + while(nChars > 0) { ME_Run *run; @@ -287,9 +288,9 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nCharsToDelete = nChars; int i; int loc = c.nOffset; - + ME_FindItemBack(c.pRun, diParagraph)->member.para.nFlags |= MEPF_REWRAP; - + cursor = c; ME_StrRelPos(run->strText, loc, &nChars); /* nChars is the number of characters that should be deleted from the @@ -297,8 +298,8 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, nCharsToDelete is a number of chars to delete from THIS run */ nCharsToDelete -= nChars; shift -= nCharsToDelete; - TRACE("Deleting %d (intended %d-remaning %d) chars at %d in '%s' (%d)\n", - nCharsToDelete, nIntendedChars, nChars, c.nOffset, + TRACE("Deleting %d (intended %d-remaning %d) chars at %d in '%s' (%d)\n", + nCharsToDelete, nIntendedChars, nChars, c.nOffset, debugstr_w(run->strText->szData), run->strText->nLen); if (!c.nOffset && ME_StrVLen(run->strText) == nCharsToDelete) @@ -323,10 +324,10 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, TRACE("Post deletion string: %s (%d)\n", debugstr_w(run->strText->szData), run->strText->nLen); TRACE("Shift value: %d\n", shift); ME_StrDeleteV(run->strText, c.nOffset, nCharsToDelete); - + /* update cursors (including c) */ for (i=-1; inCursors; i++) { - ME_Cursor *pThisCur = editor->pCursors + i; + ME_Cursor *pThisCur = editor->pCursors + i; if (i == -1) pThisCur = &c; if (pThisCur->pRun == cursor.pRun) { if (pThisCur->nOffset > cursor.nOffset) { @@ -345,9 +346,9 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, } } } - + /* c = updated data now */ - + if (c.pRun == cursor.pRun) ME_SkipAndPropagateCharOffset(c.pRun, shift); else @@ -359,7 +360,7 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, ME_Remove(cursor.pRun); ME_DestroyDisplayItem(cursor.pRun); } - + shift = 0; /* ME_CheckCharOffsets(editor); @@ -369,9 +370,9 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, } } -void ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, +void ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars) -{ +{ assert(nCursor>=0 && nCursornCursors); /* text operations set modified state */ editor->nModifyStep = 1; @@ -386,9 +387,9 @@ ME_InternalInsertTextFromCursor(ME_TextEditor *editor, int nCursor, ME_Cursor *p = &editor->pCursors[nCursor]; editor->bCaretAtEnd = FALSE; - + assert(p->pRun->type == diRun); - + return ME_InsertRunAtCursor(editor, p, style, str, len, flags); } @@ -398,7 +399,7 @@ void ME_InsertGraphicsFromCursor(ME_TextEditor *editor, int nCursor) { ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor); WCHAR space = ' '; - + /* FIXME no no no */ if (ME_IsSelection(editor)) ME_DeleteSelection(editor); @@ -415,7 +416,7 @@ ME_InsertTableCellFromCursor(ME_TextEditor *editor, int nCursor) WCHAR tab = '\t'; ME_DisplayItem *p, *run; ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor); - + p = ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, pStyle, MERF_CELL); run = p; @@ -435,12 +436,12 @@ ME_InsertTableCellFromCursor(ME_TextEditor *editor, int nCursor) } -void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, +void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, const WCHAR *str, int len, ME_Style *style) { const WCHAR *pos; ME_Cursor *p = NULL; - int freeSpace; + int oldLen; /* FIXME really HERE ? */ if (ME_IsSelection(editor)) @@ -448,7 +449,7 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, /* FIXME: is this too slow? */ /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */ - freeSpace = editor->nTextLimit - ME_GetTextLength(editor); + oldLen = ME_GetTextLength(editor); /* text operations set modified state */ editor->nModifyStep = 1; @@ -458,7 +459,11 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, assert(nCursor>=0 && nCursornCursors); if (len == -1) len = lstrlenW(str); - len = min(len, freeSpace); + + /* grow the text limit to fit our text */ + if(editor->nTextLimit < oldLen +len) + editor->nTextLimit = oldLen + len; + while (len) { pos = str; @@ -470,9 +475,9 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, if (pos!=str) ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0); - + ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, style, MERF_TAB); - + pos++; if(pos-str <= len) { len -= pos - str; @@ -480,6 +485,22 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, continue; } } + /* handle special \r\r\n sequence (richedit 2.x and higher only) */ + if (!editor->bEmulateVersion10 && pos-str < len-2 && pos[0] == '\r' && pos[1] == '\r' && pos[2] == '\n') { + WCHAR space = ' '; + + if (pos!=str) + ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0); + + ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, style, 0); + + pos+=3; + if(pos-str <= len) { + len -= pos - str; + str = pos; + continue; + } + } if (pos-str < len) { /* handle EOLs */ ME_DisplayItem *tp, *end_run; ME_Style *tmp_style; @@ -518,7 +539,7 @@ static BOOL ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs) { ME_DisplayItem *pRun = pCursor->pRun; - + if (nRelOfs == -1) { if (!pCursor->nOffset) @@ -549,7 +570,7 @@ ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs) else pCursor->nOffset = pRun->member.run.strText->nLen; } - + if (pCursor->nOffset) pCursor->nOffset = ME_StrRelPos2(pCursor->pRun->member.run.strText, pCursor->nOffset, nRelOfs); return TRUE; @@ -559,7 +580,7 @@ ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs) if (!(pRun->member.run.nFlags & MERF_ENDPARA)) { int new_ofs = ME_StrRelPos2(pRun->member.run.strText, pCursor->nOffset, nRelOfs); - + if (new_ofs < pRun->member.run.strText->nLen) { pCursor->nOffset = new_ofs; @@ -585,7 +606,7 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) { ME_DisplayItem *pRun = cursor->pRun, *pOtherRun; int nOffset = cursor->nOffset; - + if (nRelOfs == -1) { /* Backward movement */ @@ -626,7 +647,7 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) { /* Forward movement */ BOOL last_delim = FALSE; - + while (TRUE) { if (last_delim && !ME_CallWordBreakProc(editor, pRun->member.run.strText, @@ -680,7 +701,6 @@ ME_SelectWord(ME_TextEditor *editor) int ME_GetCursorOfs(ME_TextEditor *editor, int nCursor) { ME_Cursor *pCursor = &editor->pCursors[nCursor]; - return ME_GetParagraph(pCursor->pRun)->member.para.nCharOfs + pCursor->pRun->member.run.nCharOfs + pCursor->nOffset; } @@ -689,7 +709,7 @@ int ME_FindPixelPos(ME_TextEditor *editor, int x, int y, ME_Cursor *result, BOOL { ME_DisplayItem *p = editor->pBuffer->pFirst->member.para.next_para; int rx = 0; - + if (is_eol) *is_eol = 0; @@ -804,16 +824,16 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y) { ME_Cursor tmp_cursor; int is_selection = 0; - + editor->nUDArrowX = -1; - + y += ME_GetYScrollPos(editor); tmp_cursor = editor->pCursors[0]; is_selection = ME_IsSelection(editor); ME_FindPixelPos(editor, x, y, &editor->pCursors[0], &editor->bCaretAtEnd); - + if (GetKeyState(VK_SHIFT)>=0) { editor->pCursors[1] = editor->pCursors[0]; @@ -836,17 +856,17 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y) void ME_MouseMove(ME_TextEditor *editor, int x, int y) { ME_Cursor tmp_cursor; - + y += ME_GetYScrollPos(editor); tmp_cursor = editor->pCursors[0]; /* FIXME: do something with the return value of ME_FindPixelPos */ ME_FindPixelPos(editor, x, y, &tmp_cursor, &editor->bCaretAtEnd); - - if (tmp_cursor.pRun == editor->pCursors[0].pRun && + + if (tmp_cursor.pRun == editor->pCursors[0].pRun && tmp_cursor.nOffset == editor->pCursors[0].nOffset) return; - + ME_InvalidateSelection(editor); editor->pCursors[0] = tmp_cursor; HideCaret(editor->hWnd); @@ -856,7 +876,7 @@ void ME_MouseMove(ME_TextEditor *editor, int x, int y) ME_SendSelChange(editor); } -static ME_DisplayItem *ME_FindRunInRow(ME_TextEditor *editor, ME_DisplayItem *pRow, +static ME_DisplayItem *ME_FindRunInRow(ME_TextEditor *editor, ME_DisplayItem *pRow, int x, int *pOffset, int *pbCaretAtEnd) { ME_DisplayItem *pNext, *pLastRun; @@ -879,13 +899,13 @@ static ME_DisplayItem *ME_FindRunInRow(ME_TextEditor *editor, ME_DisplayItem *pR if (ch < s->nLen) { if (pOffset) *pOffset = ch; - return pNext; + return pNext; } } pLastRun = pNext; pNext = ME_FindItemFwd(pNext, diRunOrStartRow); } while(pNext && pNext->type == diRun); - + if ((pLastRun->member.run.nFlags & MERF_ENDPARA) == 0) { pNext = ME_FindItemFwd(pNext, diRun); @@ -966,18 +986,18 @@ static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor) ME_DisplayItem *pLast, *p; int x, y, ys, yd, yp, yprev; ME_Cursor tmp_curs = *pCursor; - + x = ME_GetXForArrow(editor, pCursor); if (!pCursor->nOffset && editor->bCaretAtEnd) pRun = ME_FindItemBack(pRun, diRun); - + p = ME_FindItemBack(pRun, diStartRowOrParagraph); assert(p->type == diStartRow); yp = ME_FindItemBack(p, diParagraph)->member.para.nYPos; yprev = ys = y = yp + p->member.row.nYPos; yd = y - editor->sizeWindow.cy; pLast = p; - + do { p = ME_FindItemBack(p, diStartRowOrParagraph); if (!p) @@ -994,7 +1014,7 @@ static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor) pLast = p; yprev = y; } while(1); - + pCursor->pRun = ME_FindRunInRow(editor, pLast, x, &pCursor->nOffset, &editor->bCaretAtEnd); ME_UpdateSelection(editor, &tmp_curs); if (yprev < editor->sizeWindow.cy) @@ -1002,7 +1022,7 @@ static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor) ME_EnsureVisible(editor, ME_FindItemFwd(editor->pBuffer->pFirst, diRun)); ME_Repaint(editor); } - else + else { ME_ScrollUp(editor, ys-yprev); } @@ -1010,7 +1030,7 @@ static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor) assert(pCursor->pRun->type == diRun); } -/* FIXME: in the original RICHEDIT, PageDown always scrolls by the same amount +/* FIXME: in the original RICHEDIT, PageDown always scrolls by the same amount of pixels, even if it makes the scroll bar position exceed its normal maximum. In such a situation, clicking the scrollbar restores its position back to the normal range (ie. sets it to (doclength-screenheight)). */ @@ -1021,18 +1041,18 @@ static void ME_ArrowPageDown(ME_TextEditor *editor, ME_Cursor *pCursor) ME_DisplayItem *pLast, *p; int x, y, ys, yd, yp, yprev; ME_Cursor tmp_curs = *pCursor; - + x = ME_GetXForArrow(editor, pCursor); if (!pCursor->nOffset && editor->bCaretAtEnd) pRun = ME_FindItemBack(pRun, diRun); - + p = ME_FindItemBack(pRun, diStartRowOrParagraph); assert(p->type == diStartRow); yp = ME_FindItemBack(p, diParagraph)->member.para.nYPos; yprev = ys = y = yp + p->member.row.nYPos; yd = y + editor->sizeWindow.cy; pLast = p; - + do { p = ME_FindItemFwd(p, diStartRowOrParagraph); if (!p) @@ -1047,7 +1067,7 @@ static void ME_ArrowPageDown(ME_TextEditor *editor, ME_Cursor *pCursor) pLast = p; yprev = y; } while(1); - + pCursor->pRun = ME_FindRunInRow(editor, pLast, x, &pCursor->nOffset, &editor->bCaretAtEnd); ME_UpdateSelection(editor, &tmp_curs); if (yprev >= editor->nTotalLength-editor->sizeWindow.cy) @@ -1055,7 +1075,7 @@ static void ME_ArrowPageDown(ME_TextEditor *editor, ME_Cursor *pCursor) ME_EnsureVisible(editor, ME_FindItemBack(editor->pBuffer->pLast, diRun)); ME_Repaint(editor); } - else + else { ME_ScrollUp(editor,ys-yprev); } @@ -1101,10 +1121,10 @@ static void ME_ArrowCtrlHome(ME_TextEditor *editor, ME_Cursor *pCursor) static void ME_ArrowEnd(ME_TextEditor *editor, ME_Cursor *pCursor) { ME_DisplayItem *pRow; - + if (editor->bCaretAtEnd && !pCursor->nOffset) return; - + pRow = ME_FindItemFwd(pCursor->pRun, diStartRowOrParagraphOrEnd); assert(pRow); if (pRow->type == diStartRow) { @@ -1121,7 +1141,7 @@ static void ME_ArrowEnd(ME_TextEditor *editor, ME_Cursor *pCursor) pCursor->nOffset = 0; editor->bCaretAtEnd = FALSE; } - + static void ME_ArrowCtrlEnd(ME_TextEditor *editor, ME_Cursor *pCursor) { ME_DisplayItem *p = ME_FindItemFwd(pCursor->pRun, diTextEnd); @@ -1142,17 +1162,17 @@ BOOL ME_IsSelection(ME_TextEditor *editor) static int ME_GetSelCursor(ME_TextEditor *editor, int dir) { int cdir = ME_GetCursorOfs(editor, 0) - ME_GetCursorOfs(editor, 1); - + if (cdir*dir>0) return 0; else return 1; } -BOOL ME_UpdateSelection(ME_TextEditor *editor, ME_Cursor *pTempCursor) +BOOL ME_UpdateSelection(ME_TextEditor *editor, const ME_Cursor *pTempCursor) { ME_Cursor old_anchor = editor->pCursors[1]; - + if (GetKeyState(VK_SHIFT)>=0) /* cancelling selection */ { /* any selection was present ? if so, it's no more, repaint ! */ @@ -1187,7 +1207,7 @@ ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor) ME_Style *style; int from, to; ME_Cursor c; - + ME_GetSelection(editor, &from, &to); ME_CursorFromCharOfs(editor, from, &c); if (from != to) { @@ -1204,10 +1224,10 @@ void ME_SendSelChange(ME_TextEditor *editor) SELCHANGE sc; ME_ClearTempStyle(editor); - + if (!(editor->nEventMask & ENM_SELCHANGE)) return; - + sc.nmhdr.hwndFrom = editor->hWnd; sc.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID); sc.nmhdr.code = EN_SELCHANGE; @@ -1228,7 +1248,7 @@ ME_ArrowKey(ME_TextEditor *editor, int nVKey, BOOL extend, BOOL ctrl) ME_Cursor *p = &editor->pCursors[nCursor]; ME_Cursor tmp_curs = *p; BOOL success = FALSE; - + ME_CheckCharOffsets(editor); editor->nUDArrowX = -1; switch(nVKey) { @@ -1266,22 +1286,22 @@ ME_ArrowKey(ME_TextEditor *editor, int nVKey, BOOL extend, BOOL ctrl) editor->bCaretAtEnd = 0; break; } - case VK_END: + case VK_END: if (ctrl) ME_ArrowCtrlEnd(editor, &tmp_curs); else ME_ArrowEnd(editor, &tmp_curs); break; } - + if (!extend) editor->pCursors[1] = tmp_curs; *p = tmp_curs; - + ME_InvalidateSelection(editor); ME_Repaint(editor); HideCaret(editor->hWnd); - ME_EnsureVisible(editor, tmp_curs.pRun); + ME_EnsureVisible(editor, tmp_curs.pRun); ME_ShowCaret(editor); ME_SendSelChange(editor); return success; diff --git a/reactos/dll/win32/riched20/clipboard.c b/reactos/dll/win32/riched20/clipboard.c index 99d9503dcc4..376a2e5b3d9 100644 --- a/reactos/dll/win32/riched20/clipboard.c +++ b/reactos/dll/win32/riched20/clipboard.c @@ -45,7 +45,7 @@ typedef struct EnumFormatImpl { UINT cur; } EnumFormatImpl; -static HRESULT EnumFormatImpl_Create(FORMATETC *fmtetc, UINT size, LPENUMFORMATETC *lplpformatetc); +static HRESULT EnumFormatImpl_Create(const FORMATETC *fmtetc, UINT size, LPENUMFORMATETC *lplpformatetc); static HRESULT WINAPI EnumFormatImpl_QueryInterface(IEnumFORMATETC *iface, REFIID riid, LPVOID *ppvObj) { @@ -147,7 +147,7 @@ static const IEnumFORMATETCVtbl VT_EnumFormatImpl = { EnumFormatImpl_Clone }; -static HRESULT EnumFormatImpl_Create(FORMATETC *fmtetc, UINT fmtetc_cnt, IEnumFORMATETC **lplpformatetc) +static HRESULT EnumFormatImpl_Create(const FORMATETC *fmtetc, UINT fmtetc_cnt, IEnumFORMATETC **lplpformatetc) { EnumFormatImpl *ret; TRACE("\n"); @@ -325,7 +325,7 @@ static const IDataObjectVtbl VT_DataObjectImpl = DataObjectImpl_EnumDAdvise }; -static HGLOBAL get_unicode_text(ME_TextEditor *editor, CHARRANGE *lpchrg) +static HGLOBAL get_unicode_text(ME_TextEditor *editor, const CHARRANGE *lpchrg) { int pars, len; WCHAR *data; @@ -369,7 +369,7 @@ static DWORD CALLBACK ME_AppendToHGLOBAL(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG return 0; } -static HGLOBAL get_rtf_text(ME_TextEditor *editor, CHARRANGE *lpchrg) +static HGLOBAL get_rtf_text(ME_TextEditor *editor, const CHARRANGE *lpchrg) { EDITSTREAM es; ME_GlobalDestStruct gds; @@ -383,7 +383,7 @@ static HGLOBAL get_rtf_text(ME_TextEditor *editor, CHARRANGE *lpchrg) return gds.hData; } -HRESULT ME_GetDataObject(ME_TextEditor *editor, CHARRANGE *lpchrg, LPDATAOBJECT *lplpdataobj) +HRESULT ME_GetDataObject(ME_TextEditor *editor, const CHARRANGE *lpchrg, LPDATAOBJECT *lplpdataobj) { DataObjectImpl *obj; TRACE("(%p,%d,%d)\n", editor, lpchrg->cpMin, lpchrg->cpMax); diff --git a/reactos/dll/win32/riched20/context.c b/reactos/dll/win32/riched20/context.c index dd61c82b188..7eef5564a8e 100644 --- a/reactos/dll/win32/riched20/context.c +++ b/reactos/dll/win32/riched20/context.c @@ -22,7 +22,7 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC) { - c->nSequence = editor->nSequence++; + c->nSequence = editor->nSequence++; c->hDC = hDC; c->editor = editor; c->pt.x = 0; diff --git a/reactos/dll/win32/riched20/editor.c b/reactos/dll/win32/riched20/editor.c index 4bb229c8432..b1444c0f94c 100644 --- a/reactos/dll/win32/riched20/editor.c +++ b/reactos/dll/win32/riched20/editor.c @@ -20,9 +20,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -/* +/* API implementation status: - + Messages (ANSI versions not done yet) + EM_AUTOURLDETECT 2.0 + EM_CANPASTE @@ -140,9 +140,9 @@ - WM_STYLECHANGING - WM_STYLECHANGED (things like read-only flag) - WM_UNICHAR - + Notifications - + * EN_CHANGE (sent from the wrong place) - EN_CORRECTTEXT - EN_DROPFILES @@ -157,14 +157,14 @@ - EN_PROTECTED + EN_REQUESTRESIZE - EN_SAVECLIPBOARD - + EN_SELCHANGE + + EN_SELCHANGE + EN_SETFOCUS - EN_STOPNOUNDO * EN_UPDATE (sent from the wrong place) - EN_VSCROLL - + Styles - + - ES_AUTOHSCROLL - ES_AUTOVSCROLL - ES_CENTER @@ -188,8 +188,8 @@ /* * RICHED20 TODO (incomplete): * - * - messages/styles/notifications listed above - * - Undo coalescing + * - messages/styles/notifications listed above + * - Undo coalescing * - add remaining CHARFORMAT/PARAFORMAT fields * - right/center align should strip spaces from the beginning * - pictures/OLE objects (not just smiling faces that lack API support ;-) ) @@ -224,7 +224,7 @@ #include "editor.h" #include "commdlg.h" #include "winreg.h" -#define NO_SHLWAPI_STREAM +#define NO_SHLWAPI_STREAM #include "shlwapi.h" #include "rtf.h" #include "imm.h" @@ -233,7 +233,7 @@ #define STACK_SIZE_MAX 1000 #define TEXT_LIMIT_DEFAULT 32767 - + WINE_DEFAULT_DEBUG_CHANNEL(richedit); static BOOL ME_RegisterEditorClass(HINSTANCE); @@ -255,24 +255,24 @@ static inline int is_version_nt(void) } static ME_TextBuffer *ME_MakeText(void) { - + ME_TextBuffer *buf = ALLOC_OBJ(ME_TextBuffer); ME_DisplayItem *p1 = ME_MakeDI(diTextStart); ME_DisplayItem *p2 = ME_MakeDI(diTextEnd); - + p1->prev = NULL; p1->next = p2; p2->prev = p1; p2->next = NULL; p1->member.para.next_para = p2; p2->member.para.prev_para = p1; - p2->member.para.nCharOfs = 0; - + p2->member.para.nCharOfs = 0; + buf->pFirst = p1; buf->pLast = p2; buf->pCharStyle = NULL; - + return buf; } @@ -281,9 +281,9 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea { WCHAR wszText[STREAMIN_BUFFER_SIZE+1]; WCHAR *pText; - + TRACE("%08x %p\n", dwFormat, stream); - + do { long nWideChars = 0; @@ -295,7 +295,7 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea if (!stream->dwSize) break; } - + if (!(dwFormat & SF_UNICODE)) { /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */ @@ -307,7 +307,7 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea nWideChars = stream->dwSize >> 1; pText = (WCHAR *)stream->buffer; } - + ME_InsertTextFromCursor(editor, 0, pText, nWideChars, style); if (stream->dwSize == 0) break; @@ -431,7 +431,7 @@ static void ME_RTFParAttrHook(RTF_Info *info) PARAFORMAT2 fmt; fmt.cbSize = sizeof(fmt); fmt.dwMask = 0; - + switch(info->rtfMinor) { case rtfParDef: /* restores default paragraph attributes */ @@ -445,7 +445,7 @@ static void ME_RTFParAttrHook(RTF_Info *info) case rtfInTable: { ME_DisplayItem *para; - + RTFFlushOutputBuffer(info); para = ME_GetParagraph(info->editor->pCursors[0].pRun); assert(para->member.para.pCells); @@ -490,7 +490,7 @@ static void ME_RTFParAttrHook(RTF_Info *info) if (fmt.cTabCount < MAX_TAB_STOPS) fmt.rgxTabs[fmt.cTabCount++] = info->rtfParam; break; - } + } if (fmt.dwMask) { RTFFlushOutputBuffer(info); /* FIXME too slow ? how come ?*/ @@ -501,16 +501,16 @@ static void ME_RTFParAttrHook(RTF_Info *info) static void ME_RTFTblAttrHook(RTF_Info *info) { ME_DisplayItem *para; - + switch (info->rtfMinor) { case rtfRowDef: RTFFlushOutputBuffer(info); para = ME_GetParagraph(info->editor->pCursors[0].pRun); - + /* Release possibly inherited cell definitions */ ME_DestroyTableCellList(para); - + para->member.para.pCells = ALLOC_OBJ(ME_TableCell); para->member.para.pCells->nRightBoundary = 0; para->member.para.pCells->next = NULL; @@ -519,11 +519,11 @@ static void ME_RTFTblAttrHook(RTF_Info *info) case rtfCellPos: RTFFlushOutputBuffer(info); para = ME_GetParagraph(info->editor->pCursors[0].pRun); - + if (para->member.para.pLastCell->nRightBoundary) { ME_TableCell *pCell = ALLOC_OBJ(ME_TableCell); - + pCell->next = NULL; para->member.para.pLastCell->next = pCell; para->member.para.pLastCell = pCell; @@ -614,7 +614,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre TRACE("stream==%p hWnd==%p format==0x%X\n", stream, editor->hWnd, (UINT)format); editor->nEventMask = 0; - + ME_GetSelection(editor, &from, &to); if ((format & SFF_SELECTION) && (editor->mode & TM_RICHTEXT)) { style = ME_GetSelectionInsertStyle(editor); @@ -624,7 +624,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre else { style = editor->pBuffer->pDefaultStyle; ME_AddRefStyle(style); - SendMessageA(editor->hWnd, EM_SETSEL, 0, 0); + SendMessageA(editor->hWnd, EM_SETSEL, 0, 0); ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor)); from = to = 0; ME_ClearTempStyle(editor); @@ -672,7 +672,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre RTFInit(&parser); RTFSetReadHook(&parser, ME_RTFReadHook); BeginFile(&parser); - + /* do the parsing */ RTFRead(&parser); RTFFlushOutputBuffer(&parser); @@ -755,7 +755,7 @@ ME_DisplayItem * ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset) { ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph); - + while (item && item->member.para.next_para->member.para.nCharOfs <= nOffset) item = ME_FindItemFwd(item, diParagraph); @@ -768,7 +768,7 @@ ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset = nOffset; return item; } - + do { item = ME_FindItemFwd(item, diRun); } while (item && (item->member.run.nCharOfs + ME_StrLen(item->member.run.strText) <= nOffset)); @@ -782,7 +782,7 @@ ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int static int -ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, const WCHAR *text, CHARRANGE *chrgText) +ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCHAR *text, CHARRANGE *chrgText) { const int nLen = lstrlenW(text); const int nTextLen = ME_GetTextLength(editor); @@ -794,7 +794,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, const WCHAR *te TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n", flags, chrg->cpMin, chrg->cpMax, debugstr_w(text)); - + if (flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD)) FIXME("Flags 0x%08x not implemented\n", flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD)); @@ -804,7 +804,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, const WCHAR *te nMax = nTextLen; else nMax = chrg->cpMax > nTextLen ? nTextLen : chrg->cpMax; - + /* when searching up, if cpMin < cpMax, then instead of searching * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on * [cpMax, cpMin]. The exception is when cpMax is -1, in which @@ -827,7 +827,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, const WCHAR *te chrgText->cpMin = chrgText->cpMax = -1; return -1; } - + if (flags & FR_DOWN) /* Forward search */ { /* If possible, find the character before where the search starts */ @@ -860,7 +860,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, const WCHAR *te ME_DisplayItem *pCurItem = item; int nCurStart = nStart; int nMatched = 0; - + while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurStart + nMatched], text[nMatched], (flags & FR_MATCHCASE))) { if ((flags & FR_WHOLEWORD) && isalnumW(wLastChar)) @@ -945,23 +945,23 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, CHARRANGE *chrg, const WCHAR *te chrgText->cpMin = chrgText->cpMax = -1; return -1; } - + para = ME_GetParagraph(item); - + while (item && para->member.para.nCharOfs + item->member.run.nCharOfs + nEnd - nLen >= nMin) { ME_DisplayItem *pCurItem = item; int nCurEnd = nEnd; int nMatched = 0; - + if (nCurEnd - nMatched == 0) { pCurItem = ME_FindItemBack(pCurItem, diRun); para = ME_GetParagraph(pCurItem); nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched; } - + while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1], text[nLen - nMatched - 1], (flags & FR_MATCHCASE))) { if ((flags & FR_WHOLEWORD) && isalnumW(wLastChar)) @@ -1037,7 +1037,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) { BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000; BOOL shift_is_down = GetKeyState(VK_SHIFT) & 0x8000; - + switch (nKey) { case VK_LEFT: @@ -1074,7 +1074,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) CHARFORMAT2W chf; char buf[2048]; chf.cbSize = sizeof(chf); - + ME_GetSelectionCharFormat(editor, &chf); ME_DumpStyleToBuf(&chf, buf); MessageBoxA(NULL, buf, "Style dump", MB_OK); @@ -1131,6 +1131,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) { ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun); ed->pCursors[1].nOffset = 0; ed->nLastTotalLength = ed->nTotalLength = 0; + ed->nHeight = 0; ed->nUDArrowX = -1; ed->nSequence = 0; ed->rgbBackColor = -1; @@ -1162,14 +1163,14 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) { ed->pFontCache[i].nAge = 0; ed->pFontCache[i].hFont = NULL; } - + ME_CheckCharOffsets(ed); - + if (GetWindowLongW(hWnd, GWL_STYLE) & ES_PASSWORD) ed->cPasswordMask = '*'; else ed->cPasswordMask = 0; - + return ed; } @@ -1184,13 +1185,13 @@ static DWORD CALLBACK ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie, LPBYTE lpBuf ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie; int i; WORD *pSrc, *pDest; - + cb = cb >> 1; pDest = (WORD *)lpBuff; pSrc = (WORD *)GlobalLock(pData->hData); for (i = 0; inLength+i]; i++) { pDest[i] = pSrc[pData->nLength+i]; - } + } pData->nLength += i; *pcb = 2*i; GlobalUnlock(pData->hData); @@ -1202,12 +1203,12 @@ static DWORD CALLBACK ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie, LPBYTE lpBuff, L ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie; int i; BYTE *pSrc, *pDest; - + pDest = lpBuff; pSrc = (BYTE *)GlobalLock(pData->hData); for (i = 0; inLength+i]; i++) { pDest[i] = pSrc[pData->nLength+i]; - } + } pData->nLength += i; *pcb = i; GlobalUnlock(pData->hData); @@ -1336,7 +1337,7 @@ static const char * const richedit_messages[] = { "EM_GETOLEINTERFACE", "EM_GETPARAFORMAT", "EM_GETSELTEXT", - "EM_HIDESELECTION", + "EM_HIDESELECTION", "EM_PASTESPECIAL", "EM_REQUESTRESIZE", "EM_SELECTIONTYPE", @@ -1417,17 +1418,17 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode) { ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0); - + TRACE("hwnd %p msg %04x (%s) %lx %lx, unicode %d\n", hWnd, msg, get_msg_name(msg), wParam, lParam, unicode); - + if (!editor && msg != WM_NCCREATE && msg != WM_NCDESTROY) { ERR("called with invalid hWnd %p - application bug?\n", hWnd); - return 0; + return 0; } switch(msg) { - + UNSUPPORTED_MSG(EM_DISPLAYBAND) UNSUPPORTED_MSG(EM_FINDWORDBREAK) UNSUPPORTED_MSG(EM_FMTLINES) @@ -1457,9 +1458,9 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, UNSUPPORTED_MSG(WM_STYLECHANGING) UNSUPPORTED_MSG(WM_STYLECHANGED) /* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */ - + /* Messages specific to Richedit controls */ - + case EM_STREAMIN: return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam); case EM_STREAMOUT: @@ -1518,7 +1519,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, editor->nUndoLimit = STACK_SIZE_DEFAULT; else editor->nUndoLimit = min(wParam, STACK_SIZE_MAX); - /* Setting a max stack size keeps wine from getting killed + /* Setting a max stack size keeps wine from getting killed for hogging memory. Windows allocates all this memory at once, so no program would realistically set a value above our maximum. */ return editor->nUndoLimit; @@ -1545,9 +1546,9 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, } case EM_SETOPTIONS: { - /* these flags are equivalent to ES_* counterparts - * ECO_READONLY is already implemented in the code, only requires - * setting the bit to work + /* these flags are equivalent to ES_* counterparts + * ECO_READONLY is already implemented in the code, only requires + * setting the bit to work */ DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL | ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN; @@ -1603,7 +1604,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, } case EM_AUTOURLDETECT: { - if (wParam==1 || wParam ==0) + if (wParam==1 || wParam ==0) { editor->AutoURLDetect_bEnable = (BOOL)wParam; return 0; @@ -1704,7 +1705,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, editor->nModifyStep = 1; else editor->nModifyStep = 0; - + return 0; } case EM_SETREADONLY: @@ -1720,7 +1721,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, case EM_SETEVENTMASK: { DWORD nOldMask = editor->nEventMask; - + editor->nEventMask = lParam; return nOldMask; } @@ -1731,13 +1732,20 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, CHARFORMAT2W buf, *p; BOOL bRepaint = TRUE; p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam); - if (!wParam || (editor->mode & TM_PLAINTEXT)) + if (p == NULL) return 0; + if (!wParam) ME_SetDefaultCharFormat(editor, p); - else if (wParam == (SCF_WORD | SCF_SELECTION)) + else if (wParam == (SCF_WORD | SCF_SELECTION)) { FIXME("EM_SETCHARFORMAT: word selection not supported\n"); - else if (wParam == SCF_ALL) - ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p); - else { + return 0; + } else if (wParam == SCF_ALL) { + if (editor->mode & TM_PLAINTEXT) + ME_SetDefaultCharFormat(editor, p); + else + ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p); + } else if (editor->mode & TM_PLAINTEXT) { + return 0; + } else { int from, to; ME_GetSelection(editor, &from, &to); bRepaint = (from != to); @@ -1747,7 +1755,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ME_CommitUndo(editor); if (bRepaint) ME_RewrapRepaint(editor); - return 0; + return 1; } case EM_GETCHARFORMAT: { @@ -1821,8 +1829,8 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, { int from, to; ME_Style *style; - LPWSTR wszText = ME_ToUnicode(unicode, (void *)lParam); - size_t len = lstrlenW(wszText); + LPWSTR wszText = lParam ? ME_ToUnicode(unicode, (void *)lParam) : NULL; + size_t len = wszText ? lstrlenW(wszText) : 0; TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText)); ME_GetSelection(editor, &from, &to); @@ -1842,20 +1850,20 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, if (!wParam) ME_EmptyUndoStack(editor); ME_UpdateRepaint(editor); - return 0; + return len; } case EM_SCROLLCARET: { int top, bottom; /* row's edges relative to document top */ int nPos; ME_DisplayItem *para, *row; - + nPos = ME_GetYScrollPos(editor); row = ME_RowStart(editor->pCursors[0].pRun); para = ME_GetParagraph(row); top = para->member.para.nYPos + row->member.row.nYPos; bottom = top + row->member.row.nHeight; - + if (top < nPos) /* caret above window */ ME_ScrollAbs(editor, top); else if (nPos + editor->sizeWindow.cy < bottom) /*below*/ @@ -1868,13 +1876,13 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, CHARFORMAT2W fmt; HDC hDC; BOOL bRepaint = LOWORD(lParam); - + if (!wParam) - wParam = (WPARAM)GetStockObject(SYSTEM_FONT); + wParam = (WPARAM)GetStockObject(SYSTEM_FONT); GetObjectW((HGDIOBJ)wParam, sizeof(LOGFONTW), &lf); hDC = GetDC(hWnd); - ME_CharFormatFromLogFont(hDC, &lf, &fmt); - ReleaseDC(hWnd, hDC); + ME_CharFormatFromLogFont(hDC, &lf, &fmt); + ReleaseDC(hWnd, hDC); ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), &fmt); ME_SetDefaultCharFormat(editor, &fmt); @@ -1900,8 +1908,18 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */ if (lstrlenW(wszText) > 0) { + int len = -1; + /* uses default style! */ - ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle); + if (!(GetWindowLongW(hWnd, GWL_STYLE) & ES_MULTILINE)) + { + WCHAR * p; + + p = wszText; + while (*p != '\0' && *p != '\r' && *p != '\n') p++; + len = p - wszText; + } + ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle); } ME_EndToUnicode(unicode, wszText); } @@ -1911,6 +1929,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ME_CommitUndo(editor); ME_EmptyUndoStack(editor); ME_SetSelection(editor, 0, 0); + editor->nModifyStep = 0; ME_UpdateRepaint(editor); return 1; } @@ -1924,7 +1943,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, return FALSE; } case WM_PASTE: - { + { DWORD dwFormat = 0; EDITSTREAM es; ME_GlobalDestStruct gds; @@ -1955,10 +1974,10 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, LPDATAOBJECT dataObj = NULL; CHARRANGE range; HRESULT hr = S_OK; - + if (editor->cPasswordMask) return 0; /* Copying or Cutting masked text isn't allowed */ - + ME_GetSelection(editor, (int*)&range.cpMin, (int*)&range.cpMax); if(editor->lpOleCallback) hr = IRichEditOleCallback_GetClipboardData(editor->lpOleCallback, &range, RECO_COPY, &dataObj); @@ -1982,11 +2001,14 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, return ME_GetTextLengthEx(editor, (GETTEXTLENGTHEX *)wParam); case WM_GETTEXT: { - TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */ - tr.chrg.cpMin = 0; - tr.chrg.cpMax = wParam ? (wParam - 1) : 0; - tr.lpstrText = (WCHAR *)lParam; - return RichEditWndProc_common(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr, unicode); + GETTEXTEX ex; + + ex.cb = wParam; + ex.flags = GT_USECRLF; + ex.codepage = unicode ? 1200 : CP_ACP; + ex.lpDefaultChar = NULL; + ex.lpUsedDefaultChar = NULL; + return RichEditWndProc_common(hWnd, EM_GETTEXTEX, (WPARAM)&ex, lParam, unicode); } case EM_GETTEXTEX: { @@ -2060,7 +2082,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, int nLen = rng->chrg.cpMax-rng->chrg.cpMin; WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1); int nChars = ME_GetTextW(editor, p, rng->chrg.cpMin, nLen, editor->bEmulateVersion10); - /* FIXME this is a potential security hole (buffer overrun) + /* FIXME this is a potential security hole (buffer overrun) if you know more about wchar->mbyte conversion please explain */ WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)rng->lpstrText, nLen+1, NULL, NULL); @@ -2074,7 +2096,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, const unsigned int nMaxChars = *(WORD *) lParam; unsigned int nEndChars, nCharsLeft = nMaxChars; char *dest = (char *) lParam; - /* rich text editor 1.0 uses \r\n for line end, 2.0 uses just \r; + /* rich text editor 1.0 uses \r\n for line end, 2.0 uses just \r; we need to know how if we have the extra \n or not */ int nLF = editor->bEmulateVersion10; @@ -2148,14 +2170,14 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, { if (lParam == -1) return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor,1)); - else + else return ME_RowNumberFromCharOfs(editor, lParam); } case EM_LINEINDEX: { ME_DisplayItem *item, *para; int nCharOfs; - + if (wParam == -1) item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow); else @@ -2172,7 +2194,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, { ME_DisplayItem *item, *item_end; int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0; - + if (wParam > ME_GetTextLength(editor)) return 0; if (wParam == -1) @@ -2266,14 +2288,14 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ME_DisplayItem *pRun; int nCharOfs, nOffset, nLength; POINTL pt = {0,0}; - - nCharOfs = wParam; + + nCharOfs = wParam; /* detect which API version we're dealing with */ if (wParam >= 0x40000) nCharOfs = lParam; nLength = ME_GetTextLength(editor); - - if (nCharOfs < nLength) { + + if (nCharOfs < nLength) { ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset); assert(pRun->type == diRun); pt.y = pRun->member.run.pt.y; @@ -2366,7 +2388,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, if (ME_KeyDown(editor, LOWORD(wParam))) return 0; goto do_default; - case WM_CHAR: + case WM_CHAR: { WCHAR wstr; @@ -2379,7 +2401,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, } if (editor->AutoURLDetect_bEnable) ME_AutoURLDetect(editor, wstr); - + switch (wstr) { case 1: /* Ctrl-A */ @@ -2389,7 +2411,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, SendMessageW(editor->hWnd, WM_COPY, 0, 0); return 0; } - + if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) { MessageBeep(MB_ICONERROR); return 0; /* FIXME really 0 ? */ @@ -2410,31 +2432,39 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, SendMessageW(editor->hWnd, EM_UNDO, 0, 0); return 0; } - if (((unsigned)wstr)>=' ' || wstr=='\r' || wstr=='\t') { + if (((unsigned)wstr)>=' ' + || (wstr=='\r' && (GetWindowLongW(hWnd, GWL_STYLE) & ES_MULTILINE)) + || wstr=='\t') { /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */ - ME_Style *style = ME_GetInsertStyle(editor, 0); - ME_SaveTempStyle(editor); - ME_InsertTextFromCursor(editor, 0, &wstr, 1, style); - ME_ReleaseStyle(style); - ME_CommitUndo(editor); + /* WM_CHAR is restricted to nTextLimit */ + int from, to; + ME_GetSelection(editor, &from, &to); + if(editor->nTextLimit > ME_GetTextLength(editor) - (to-from)) + { + ME_Style *style = ME_GetInsertStyle(editor, 0); + ME_SaveTempStyle(editor); + ME_InsertTextFromCursor(editor, 0, &wstr, 1, style); + ME_ReleaseStyle(style); + ME_CommitUndo(editor); + } ME_UpdateRepaint(editor); } return 0; } case EM_SCROLL: /* fall through */ - case WM_VSCROLL: + case WM_VSCROLL: { int origNPos; int lineHeight; - + origNPos = ME_GetYScrollPos(editor); lineHeight = 24; - + if (editor && editor->pBuffer && editor->pBuffer->pDefaultStyle) lineHeight = editor->pBuffer->pDefaultStyle->tm.tmHeight; if (lineHeight <= 0) lineHeight = 24; - - switch(LOWORD(wParam)) + + switch(LOWORD(wParam)) { case SB_LINEUP: ME_ScrollUp(editor,lineHeight); @@ -2461,14 +2491,14 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, { int gcWheelDelta; UINT pulScrollLines; - + SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0); gcWheelDelta = -GET_WHEEL_DELTA_WPARAM(wParam); - + if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines) { /* FIXME follow the original */ - ME_ScrollDown(editor,pulScrollLines * (gcWheelDelta / WHEEL_DELTA) * 8); + ME_ScrollDown(editor,pulScrollLines * (gcWheelDelta / WHEEL_DELTA) * 8); } break; } @@ -2483,7 +2513,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, if (lParam) { RECT *rc = (RECT *)lParam; - + if (wParam) { editor->rcFormat.left += rc->left; @@ -2619,7 +2649,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, mask |= (TM_RICHTEXT | TM_PLAINTEXT); changes |= (wParam & (TM_RICHTEXT | TM_PLAINTEXT)); } - /*FIXME: Currently no support for undo level and code page options*/ + /*FIXME: Currently no support for undo level and code page options*/ editor->mode = (editor->mode & (~mask)) | changes; return 0; } @@ -2669,13 +2699,13 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { LRESULT result; - + /* FIXME: this is NOT the same as 2.0 version */ result = RichEditANSIWndProc(hWnd, msg, wParam, lParam); if (msg == WM_NCCREATE) { ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0); - + editor->bEmulateVersion10 = TRUE; editor->pBuffer->pLast->member.para.nCharOfs = 2; } @@ -2717,14 +2747,14 @@ void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam info.chrg.cpMin = ME_CharOfsFromRunOfs(editor,tmpCursor.pRun,0); info.chrg.cpMax = info.chrg.cpMin + ME_StrVLen(tmpRun->strText); SendMessageW(GetParent(editor->hWnd), WM_NOTIFY,info.nmhdr.idFrom, (LPARAM)&info); - } + } } int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to) { ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph); int i = 0; - + while(item && item->member.para.next_para->member.para.nCharOfs <= from) item = item->member.para.next_para; if (!item) @@ -2742,12 +2772,12 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart); int nWritten = 0; WCHAR *pStart = buffer; - + if (!item) { *buffer = 0; return 0; } - + if (nStart) { int nLen = ME_StrLen(item->member.run.strText) - nStart; @@ -2762,7 +2792,7 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in nStart = 0; item = ME_FindItemFwd(item, diRun); } - + while(nChars && item) { int nLen = ME_StrLen(item->member.run.strText); @@ -2791,8 +2821,8 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in CopyMemory(buffer, item->member.run.strText->szData, sizeof(WCHAR)*nLen); nChars -= nLen; nWritten += nLen; - buffer += nLen; - + buffer += nLen; + if (!nChars) { TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart); @@ -2803,14 +2833,14 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in } *buffer = 0; TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart); - return nWritten; + return nWritten; } static BOOL ME_RegisterEditorClass(HINSTANCE hInstance) { WNDCLASSW wcW; WNDCLASSA wcA; - + wcW.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS; wcW.lpfnWndProc = RichEditWndProcW; wcW.cbClsExtra = 0; @@ -2872,7 +2902,7 @@ LRESULT WINAPI REListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) * REExtendedRegisterClass (RICHED20.8) * * FIXME undocumented - * Need to check for errors and implement controls and callbacks + * Need to check for errors and implement controls and callbacks */ LRESULT WINAPI REExtendedRegisterClass(void) { @@ -2902,7 +2932,7 @@ LRESULT WINAPI REExtendedRegisterClass(void) wcW.style = CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW; wcW.lpfnWndProc = REComboWndProc; wcW.lpszClassName = REComboBox20W; - if (RegisterClassW(&wcW)) ME_ComboBoxRegistered = TRUE; + if (RegisterClassW(&wcW)) ME_ComboBoxRegistered = TRUE; } result = 0; @@ -2914,7 +2944,7 @@ LRESULT WINAPI REExtendedRegisterClass(void) return result; } -int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar) +int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar) { struct prefix_s { const char *text; @@ -2948,10 +2978,10 @@ int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar) RichEditANSIWndProc(editor->hWnd, EM_EXGETSEL, (WPARAM) 0, (LPARAM) &ins_pt); sel_min = ins_pt.cpMin; sel_max = ins_pt.cpMax; - if (sel_min==sel_max) + if (sel_min==sel_max) car_pos = sel_min; if (sel_min!=sel_max) - car_pos = ME_GetTextLength(editor)+1; + car_pos = ME_GetTextLength(editor)+1; cur_format.cbSize = sizeof(cur_format); default_format.cbSize = sizeof(default_format); RichEditANSIWndProc(editor->hWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cur_format); @@ -2962,9 +2992,9 @@ int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar) curf_ef = cur_format.dwEffects & link.dwEffects; def_ef = default_format.dwEffects & link.dwEffects; link_ef = link.dwEffects & link.dwEffects; - if (curf_ef == link_ef) + if (curf_ef == link_ef) { - if( curChar == '\n' || curChar=='\r' || curChar==' ') + if( curChar == '\n' || curChar=='\r' || curChar==' ') { ME_SetSelection(editor, car_pos, car_pos); RichEditANSIWndProc(editor->hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &default_format); @@ -2976,9 +3006,9 @@ int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar) { cur_prefx = 0; prefx_cnt = (sizeof(prefixes)/sizeof(struct prefix_s))-1; - while (cur_prefx<=prefx_cnt) + while (cur_prefx<=prefx_cnt) { - if (text_pos == -1) + if (text_pos == -1) { ft.lpstrText = prefixes[cur_prefx].text; URLmin=max(0,(car_pos-prefixes[cur_prefx].length)); @@ -2989,10 +3019,10 @@ int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar) } ft.chrg.cpMin = URLmin; ft.chrg.cpMax = URLmax; - text_pos=RichEditANSIWndProc(editor->hWnd, EM_FINDTEXT, FR_DOWN, (LPARAM)&ft); + text_pos=RichEditANSIWndProc(editor->hWnd, EM_FINDTEXT, FR_DOWN, (LPARAM)&ft); cur_prefx++; } - if (text_pos != -1) + if (text_pos != -1) { url.cpMin=text_pos; url.cpMax=car_pos-1; diff --git a/reactos/dll/win32/riched20/editor.h b/reactos/dll/win32/riched20/editor.h index 6e90c3be8d6..83dee767847 100644 --- a/reactos/dll/win32/riched20/editor.h +++ b/reactos/dll/win32/riched20/editor.h @@ -71,8 +71,8 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from); void ME_CopyToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from); CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from); void ME_CopyToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from); -void ME_CopyCharFormat(CHARFORMAT2W *pDest, CHARFORMAT2W *pSrc); /* only works with 2W structs */ -void ME_CharFormatFromLogFont(HDC hDC, LOGFONTW *lf, CHARFORMAT2W *fmt); /* ditto */ +void ME_CopyCharFormat(CHARFORMAT2W *pDest, const CHARFORMAT2W *pSrc); /* only works with 2W structs */ +void ME_CharFormatFromLogFont(HDC hDC, const LOGFONTW *lf, CHARFORMAT2W *fmt); /* ditto */ /* list.c */ void ME_InsertBefore(ME_DisplayItem *diWhere, ME_DisplayItem *diWhat); @@ -94,25 +94,25 @@ ME_String *ME_MakeString(LPCWSTR szText); ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars); ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars); ME_String *ME_MakeStringB(int nMaxChars); -ME_String *ME_StrDup(ME_String *s); +ME_String *ME_StrDup(const ME_String *s); void ME_DestroyString(ME_String *s); -void ME_AppendString(ME_String *s1, ME_String *s2); -ME_String *ME_ConcatString(ME_String *s1, ME_String *s2); +void ME_AppendString(ME_String *s1, const ME_String *s2); +ME_String *ME_ConcatString(const ME_String *s1, const ME_String *s2); ME_String *ME_VSplitString(ME_String *orig, int nVPos); -int ME_IsWhitespaces(ME_String *s); -int ME_IsSplitable(ME_String *s); +int ME_IsWhitespaces(const ME_String *s); +int ME_IsSplitable(const ME_String *s); /* int ME_CalcSkipChars(ME_String *s); */ -int ME_StrLen(ME_String *s); -int ME_StrVLen(ME_String *s); -int ME_FindNonWhitespaceV(ME_String *s, int nVChar); +int ME_StrLen(const ME_String *s); +int ME_StrVLen(const ME_String *s); +int ME_FindNonWhitespaceV(const ME_String *s, int nVChar); int ME_FindWhitespaceV(ME_String *s, int nVChar); int ME_CallWordBreakProc(ME_TextEditor *editor, ME_String *str, INT start, INT code); -int ME_GetCharFwd(ME_String *s, int nPos); /* get char starting from start */ -int ME_GetCharBack(ME_String *s, int nPos); /* get char starting from \0 */ -int ME_StrRelPos(ME_String *s, int nVChar, int *pRelChars); -int ME_StrRelPos2(ME_String *s, int nVChar, int nRelChars); +int ME_GetCharFwd(const ME_String *s, int nPos); /* get char starting from start */ +int ME_GetCharBack(const ME_String *s, int nPos); /* get char starting from \0 */ +int ME_StrRelPos(const ME_String *s, int nVChar, int *pRelChars); +int ME_StrRelPos2(const ME_String *s, int nVChar, int nRelChars); int ME_VPosToPos(ME_String *s, int nVPos); -int ME_PosToVPos(ME_String *s, int nPos); +int ME_PosToVPos(const ME_String *s, int nPos); void ME_StrDeleteV(ME_String *s, int nVChar, int nChars); /* smart helpers for A<->W conversions, they reserve/free memory and call MultiByte<->WideChar functions */ LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz); @@ -128,10 +128,10 @@ static inline int ME_CharCompare(WCHAR a, WCHAR b, int caseSensitive) return caseSensitive ? (a == b) : (toupperW(a) == toupperW(b)); } -/* note: those two really return the first matching offset (starting from EOS)+1 +/* note: those two really return the first matching offset (starting from EOS)+1 * in other words, an offset of the first trailing white/black */ -int ME_ReverseFindNonWhitespaceV(ME_String *s, int nVChar); -int ME_ReverseFindWhitespaceV(ME_String *s, int nVChar); +int ME_ReverseFindNonWhitespaceV(const ME_String *s, int nVChar); +int ME_ReverseFindWhitespaceV(const ME_String *s, int nVChar); /* row.c */ ME_DisplayItem *ME_FindRowStart(ME_Context *c, ME_DisplayItem *run, int nRelPos); @@ -155,15 +155,15 @@ int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run); int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run); int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset); int ME_GetLastSplittablePlace(ME_Context *c, ME_Run *run); -int ME_CanJoinRuns(ME_Run *run1, ME_Run *run2); +int ME_CanJoinRuns(const ME_Run *run1, const ME_Run *run2); void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p); ME_DisplayItem *ME_SplitRun(ME_Context *c, ME_DisplayItem *item, int nChar); ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nChar); int ME_FindSplitPoint(ME_Context *c, POINT *pt, ME_Run *run, int desperate); void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run); ME_DisplayItem *ME_SplitFurther(ME_TextEditor *editor, ME_DisplayItem *run); -void ME_CalcRunExtent(ME_Context *c, ME_Paragraph *para, ME_Run *run); -SIZE ME_GetRunSize(ME_Context *c, ME_Paragraph *para, ME_Run *run, int nLen); +void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, ME_Run *run); +SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen); void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor); void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem **ppRun, int *pOfs); int ME_CharOfsFromRunOfs(ME_TextEditor *editor, ME_DisplayItem *pRun, int nOfs); @@ -186,7 +186,7 @@ int ME_CharFromPos(ME_TextEditor *editor, int x, int y); void ME_LButtonDown(ME_TextEditor *editor, int x, int y); void ME_MouseMove(ME_TextEditor *editor, int x, int y); void ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars); -void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, +void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, const WCHAR *str, int len, ME_Style *style); BOOL ME_ArrowKey(ME_TextEditor *ed, int nVKey, BOOL extend, BOOL ctrl); @@ -206,44 +206,44 @@ void ME_InsertGraphicsFromCursor(ME_TextEditor *editor, int nCursor); void ME_InsertTableCellFromCursor(ME_TextEditor *editor, int nCursor); void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars); int ME_GetTextLength(ME_TextEditor *editor); -int ME_GetTextLengthEx(ME_TextEditor *editor, GETTEXTLENGTHEX *how); +int ME_GetTextLengthEx(ME_TextEditor *editor, const GETTEXTLENGTHEX *how); ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor); -BOOL ME_UpdateSelection(ME_TextEditor *editor, ME_Cursor *pTempCursor); +BOOL ME_UpdateSelection(ME_TextEditor *editor, const ME_Cursor *pTempCursor); /* wrap.c */ void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp); ME_DisplayItem *ME_MakeRow(int height, int baseline, int width); -void ME_InsertRowStart(ME_WrapContext *wc, ME_DisplayItem *pEnd); +void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd); void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp); BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor); void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor); void ME_SendRequestResize(ME_TextEditor *editor, BOOL force); /* para.c */ -ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run); +ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run); void ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end); void ME_MakeFirstParagraph(HDC hDC, ME_TextBuffer *editor); ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *rp, ME_Style *style); ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp); void ME_DumpParaStyle(ME_Paragraph *s); -void ME_DumpParaStyleToBuf(PARAFORMAT2 *pFmt, char buf[2048]); -void ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, PARAFORMAT2 *pFmt); -void ME_SetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt); -void ME_GetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, PARAFORMAT2 *pFmt); +void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]); +void ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const PARAFORMAT2 *pFmt); +void ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt); +void ME_GetParaFormat(ME_TextEditor *editor, const ME_DisplayItem *para, PARAFORMAT2 *pFmt); void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt); /* marks from first up to (but not including) last */ -void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, ME_DisplayItem *last); -void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, ME_DisplayItem *last); +void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last); +void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last); void ME_MarkAllForWrapping(ME_TextEditor *editor); /* paint.c */ -void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, RECT *rcUpdate); +void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *rcUpdate); void ME_Repaint(ME_TextEditor *editor); void ME_RewrapRepaint(ME_TextEditor *editor); void ME_UpdateRepaint(ME_TextEditor *editor); void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph); void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun); -COLORREF ME_GetBackColor(ME_TextEditor *editor); +COLORREF ME_GetBackColor(const ME_TextEditor *editor); void ME_InvalidateSelection(ME_TextEditor *editor); void ME_QueueInvalidateFromCursor(ME_TextEditor *editor, int nCursor); BOOL ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator); @@ -268,7 +268,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd); void ME_DestroyEditor(ME_TextEditor *editor); void ME_SendOldNotify(ME_TextEditor *editor, int nCode); void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam); -ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, ME_DisplayItem *di); +ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_DisplayItem *pdi); void ME_CommitUndo(ME_TextEditor *editor); void ME_Undo(ME_TextEditor *editor); void ME_Redo(ME_TextEditor *editor); @@ -285,4 +285,4 @@ LRESULT ME_StreamOutRange(ME_TextEditor *editor, DWORD dwFormat, int nStart, int LRESULT ME_StreamOut(ME_TextEditor *editor, DWORD dwFormat, EDITSTREAM *stream); /* clipboard.c */ -HRESULT ME_GetDataObject(ME_TextEditor *editor, CHARRANGE *lpchrg, LPDATAOBJECT *lplpdataobj); +HRESULT ME_GetDataObject(ME_TextEditor *editor, const CHARRANGE *lpchrg, LPDATAOBJECT *lplpdataobj); diff --git a/reactos/dll/win32/riched20/editstr.h b/reactos/dll/win32/riched20/editstr.h index de558dd4c81..b86aeba629b 100644 --- a/reactos/dll/win32/riched20/editstr.h +++ b/reactos/dll/win32/riched20/editstr.h @@ -70,7 +70,7 @@ typedef enum { diRun, /* run (sequence of chars with the same character format) */ diStartRow, /* start of the row (line of text on the screen) */ diTextEnd, /* end of the text buffer */ - + /********************* these below are meant for finding only *********************/ diStartRowOrParagraph, /* 5 */ diStartRowOrParagraphOrEnd, @@ -78,7 +78,7 @@ typedef enum { diRunOrStartRow, diParagraphOrEnd, diRunOrParagraphOrEnd, /* 10 */ - + diUndoInsertRun, /* 11 */ diUndoDeleteRun, /* 12 */ diUndoJoinParagraphs, /* 13 */ @@ -162,7 +162,7 @@ typedef struct tagME_TableCell typedef struct tagME_Paragraph { PARAFORMAT2 *pFmt; - + BOOL bTable; /* this paragraph is a table row */ struct tagME_TableCell *pCells; /* list of cells and their properties */ struct tagME_TableCell *pLastCell; /* points to the last cell in the list */ @@ -194,7 +194,7 @@ typedef struct tagME_Row * to a screen line (that's why there are no rows in an unformatted * paragraph * - the paragraphs contain "shortcut" pointers to the previous and the next - * paragraph, that makes iteration over paragraphs faster + * paragraph, that makes iteration over paragraphs faster * - the list starts with diTextStart and ends with diTextEnd */ @@ -291,6 +291,7 @@ typedef struct tagME_TextEditor int nCursors; SIZE sizeWindow; int nTotalLength, nLastTotalLength; + int nHeight; int nUDArrowX; int nSequence; COLORREF rgbBackColor; @@ -350,9 +351,9 @@ typedef struct tagME_WrapContext POINT pt; BOOL bOverflown; ME_DisplayItem *pRowStart; - + ME_DisplayItem *pLastSplittableRun; POINT ptLastSplittableRun; -} ME_WrapContext; +} ME_WrapContext; #endif diff --git a/reactos/dll/win32/riched20/list.c b/reactos/dll/win32/riched20/list.c index 81134112675..ad7b4b659e4 100644 --- a/reactos/dll/win32/riched20/list.c +++ b/reactos/dll/win32/riched20/list.c @@ -99,10 +99,10 @@ BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass) return TRUE; if (nTypeOrClass==diStartRowOrParagraph && (type==diStartRow || type==diParagraph)) return TRUE; - if (nTypeOrClass==diStartRowOrParagraphOrEnd + if (nTypeOrClass==diStartRowOrParagraphOrEnd && (type==diStartRow || type==diParagraph || type==diTextEnd)) return TRUE; - if (nTypeOrClass==diRunOrParagraphOrEnd + if (nTypeOrClass==diRunOrParagraphOrEnd && (type==diRun || type==diParagraph || type==diTextEnd)) return TRUE; return FALSE; @@ -154,7 +154,7 @@ ME_DisplayItem *ME_MakeDI(ME_DIType type) { item->member.para.pFmt->dwMask = 0; item->member.para.nFlags = MEPF_REWRAP; } - + return item; } @@ -197,7 +197,7 @@ void ME_DumpDocument(ME_TextBuffer *buffer) TRACE(" - StartRow\n"); break; case diRun: - TRACE(" - Run(\"%s\", %d)\n", debugstr_w(pItem->member.run.strText->szData), + TRACE(" - Run(\"%s\", %d)\n", debugstr_w(pItem->member.run.strText->szData), pItem->member.run.nCharOfs); break; case diTextEnd: diff --git a/reactos/dll/win32/riched20/paint.c b/reactos/dll/win32/riched20/paint.c index 5291f3daf8d..7c40814f88b 100644 --- a/reactos/dll/win32/riched20/paint.c +++ b/reactos/dll/win32/riched20/paint.c @@ -23,7 +23,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit); -void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, RECT *rcUpdate) { +void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *rcUpdate) { ME_DisplayItem *item; ME_Context c; int yoffset; @@ -43,7 +43,7 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, RECT *rcUpda { BOOL bPaint = (rcUpdate == NULL); if (rcUpdate) - bPaint = c.pt.ybottom && + bPaint = c.pt.ybottom && c.pt.y+item->member.para.nHeight>rcUpdate->top; if (bPaint) { @@ -59,7 +59,7 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, RECT *rcUpda RECT rc; int xs = c.rcView.left, xe = c.rcView.right; int ys = c.pt.y, ye = c.rcView.bottom; - + if (bOnlyNew) { int y1 = editor->nTotalLength-yoffset, y2 = editor->nLastTotalLength-yoffset; @@ -68,7 +68,7 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, RECT *rcUpda else ys = ye; } - + if (rcUpdate && ys!=ye) { xs = rcUpdate->left, xe = rcUpdate->right; @@ -109,18 +109,20 @@ void ME_UpdateRepaint(ME_TextEditor *editor) { /* Should be called whenever the contents of the control have changed */ ME_Cursor *pCursor; - + if (ME_WrapMarkedParagraphs(editor)) ME_UpdateScrollBar(editor); - + /* Ensure that the cursor is visible */ pCursor = &editor->pCursors[0]; ME_EnsureVisible(editor, pCursor->pRun); - + /* send EN_CHANGE if the event mask asks for it */ if(editor->nEventMask & ENM_CHANGE) { + editor->nEventMask &= ~ENM_CHANGE; ME_SendOldNotify(editor, EN_CHANGE); + editor->nEventMask |= ENM_CHANGE; } ME_Repaint(editor); ME_SendSelChange(editor); @@ -128,19 +130,19 @@ void ME_UpdateRepaint(ME_TextEditor *editor) void ME_RewrapRepaint(ME_TextEditor *editor) -{ +{ /* RewrapRepaint should be called whenever the control has changed in * looks, but not content. Like resizing. */ - + ME_MarkAllForWrapping(editor); ME_WrapMarkedParagraphs(editor); ME_UpdateScrollBar(editor); - + ME_Repaint(editor); } -static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, int nChars, +static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, int nChars, ME_Style *s, int *width, int nSelFrom, int nSelTo, int ymin, int cy) { HDC hDC = c->hDC; HGDIOBJ hOldFont; @@ -149,7 +151,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, in hOldFont = ME_SelectStyleFont(c->editor, hDC, s); rgbBack = ME_GetBackColor(c->editor); if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK)) - rgbOld = SetTextColor(hDC, RGB(0,0,255)); + rgbOld = SetTextColor(hDC, RGB(0,0,255)); else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR)) rgbOld = SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); else @@ -165,7 +167,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, in { int numerator = 1; int denominator = 1; - + if (c->editor->nZoomNumerator) { numerator = c->editor->nZoomNumerator; @@ -187,7 +189,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, in GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz); x += sz.cx; GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz); - + /* Invert selection if not hidden by EM_HIDESELECTION */ if (c->editor->bHideSelection == FALSE) PatBlt(hDC, x, ymin, sz.cx, cy, DSTINVERT); @@ -196,7 +198,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, in ME_UnselectStyleFont(c->editor, hDC, s, hOldFont); } -static void ME_DebugWrite(HDC hDC, POINT *pt, WCHAR *szText) { +static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) { int align = SetTextAlign(hDC, TA_LEFT|TA_TOP); HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT)); COLORREF color = SetTextColor(hDC, RGB(128,128,128)); @@ -230,18 +232,18 @@ static void ME_DrawGraphics(ME_Context *c, int x, int y, ME_Run *run, if (selected) { /* descent is usually (always?) 0 for graphics */ - PatBlt(c->hDC, x, y-run->nAscent, sz.cx, run->nAscent+run->nDescent, DSTINVERT); + PatBlt(c->hDC, x, y-run->nAscent, sz.cx, run->nAscent+run->nDescent, DSTINVERT); } } -static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para) +static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para) { ME_Run *run = &rundi->member.run; ME_DisplayItem *start = ME_FindItemBack(rundi, diStartRow); int runofs = run->nCharOfs+para->nCharOfs; int nSelFrom, nSelTo; const WCHAR wszSpace[] = {' ', 0}; - + if (run->nFlags & MERF_HIDDEN) return; @@ -252,9 +254,9 @@ static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Pa ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, NULL, 0, 1, c->pt.y + start->member.row.nYPos, start->member.row.nHeight); - + /* you can always comment it out if you need visible paragraph marks */ - if (run->nFlags & (MERF_ENDPARA | MERF_TAB | MERF_CELL)) + if (run->nFlags & (MERF_ENDPARA | MERF_TAB | MERF_CELL)) return; if (run->nFlags & MERF_GRAPHICS) @@ -264,19 +266,19 @@ static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Pa if (c->editor->cPasswordMask) { ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText)); - ME_DrawTextWithStyle(c, x, y, - szMasked->szData, ME_StrVLen(szMasked), run->style, NULL, + ME_DrawTextWithStyle(c, x, y, + szMasked->szData, ME_StrVLen(szMasked), run->style, NULL, nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.nYPos, start->member.row.nHeight); ME_DestroyString(szMasked); } else - ME_DrawTextWithStyle(c, x, y, - run->strText->szData, ME_StrVLen(run->strText), run->style, NULL, + ME_DrawTextWithStyle(c, x, y, + run->strText->szData, ME_StrVLen(run->strText), run->style, NULL, nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.nYPos, start->member.row.nHeight); } } -COLORREF ME_GetBackColor(ME_TextEditor *editor) +COLORREF ME_GetBackColor(const ME_TextEditor *editor) { /* Looks like I was seriously confused return GetSysColor((GetWindowLong(editor->hWnd, GWL_STYLE) & ES_READONLY) ? COLOR_3DFACE: COLOR_WINDOW); @@ -298,7 +300,7 @@ void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) { int xs, xe; int visible = 0; int nMargWidth = 0; - + c->pt.x = c->rcView.left; rcPara.left = c->rcView.left; rcPara.right = c->rcView.right; @@ -343,7 +345,7 @@ void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) { pt.y = 12+y; ME_DebugWrite(c->hDC, &pt, buf); } - + height = p->member.row.nHeight; baseline = p->member.row.nBaseline; pno++; @@ -396,7 +398,7 @@ void ME_ScrollUp(ME_TextEditor *editor, int cy) } void ME_ScrollDown(ME_TextEditor *editor, int cy) -{ +{ ME_Scroll(editor, cy, 3); } @@ -406,10 +408,10 @@ void ME_Scroll(ME_TextEditor *editor, int value, int type) int nOrigPos, nNewPos, nActualScroll; nOrigPos = ME_GetYScrollPos(editor); - + si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS; - + switch (type) { case 1: @@ -428,7 +430,7 @@ void ME_Scroll(ME_TextEditor *editor, int value, int type) FIXME("ME_Scroll called incorrectly\n"); si.nPos = 0; } - + nNewPos = SetScrollInfo(editor->hWnd, SB_VERT, &si, editor->bRedraw); nActualScroll = nOrigPos - nNewPos; if (editor->bRedraw) @@ -439,45 +441,45 @@ void ME_Scroll(ME_TextEditor *editor, int value, int type) ScrollWindowEx(editor->hWnd, 0, nActualScroll, NULL, NULL, NULL, NULL, SW_INVALIDATE); ME_Repaint(editor); } - + ME_UpdateScrollBar(editor); } - + void ME_UpdateScrollBar(ME_TextEditor *editor) -{ - /* Note that this is the only funciton that should ever call SetScrolLInfo +{ + /* Note that this is the only funciton that should ever call SetScrolLInfo * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never * be used at all. */ - + HWND hWnd; SCROLLINFO si; BOOL bScrollBarWasVisible,bScrollBarWillBeVisible; - + if (ME_WrapMarkedParagraphs(editor)) FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n"); - + hWnd = editor->hWnd; si.cbSize = sizeof(si); bScrollBarWasVisible = ME_GetYScrollVisible(editor); - bScrollBarWillBeVisible = editor->nTotalLength > editor->sizeWindow.cy; - + bScrollBarWillBeVisible = editor->nHeight > editor->sizeWindow.cy; + if (bScrollBarWasVisible != bScrollBarWillBeVisible) { ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible); ME_MarkAllForWrapping(editor); ME_WrapMarkedParagraphs(editor); } - + si.fMask = SIF_PAGE | SIF_RANGE; if (GetWindowLongW(hWnd, GWL_STYLE) & ES_DISABLENOSCROLL) si.fMask |= SIF_DISABLENOSCROLL; - - si.nMin = 0; + + si.nMin = 0; si.nMax = editor->nTotalLength; - + si.nPage = editor->sizeWindow.cy; - + TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage); SetScrollInfo(hWnd, SB_VERT, &si, TRUE); } @@ -504,18 +506,18 @@ void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun) ME_DisplayItem *pRow = ME_FindItemBack(pRun, diStartRow); ME_DisplayItem *pPara = ME_FindItemBack(pRun, diParagraph); int y, yrel, yheight, yold; - + assert(pRow); assert(pPara); - + y = pPara->member.para.nYPos+pRow->member.row.nYPos; yheight = pRow->member.row.nHeight; yold = ME_GetYScrollPos(editor); yrel = y - yold; - + if (y < yold) ME_ScrollAbs(editor,y); - else if (yrel + yheight > editor->sizeWindow.cy) + else if (yrel + yheight > editor->sizeWindow.cy) ME_ScrollAbs(editor,y+yheight-editor->sizeWindow.cy); } @@ -555,16 +557,16 @@ ME_InvalidateSelection(ME_TextEditor *editor) assert(para1->type == diParagraph); assert(para2->type == diParagraph); /* last selection markers aren't always updated, which means - they can point past the end of the document */ + they can point past the end of the document */ if (editor->nLastSelStart > len) - editor->nLastSelEnd = len; + editor->nLastSelEnd = len; if (editor->nLastSelEnd > len) - editor->nLastSelEnd = len; - + editor->nLastSelEnd = len; + /* if the start part of selection is being expanded or contracted... */ if (nStart < editor->nLastSelStart) { ME_MarkForPainting(editor, para1, ME_FindItemFwd(editor->pLastSelStartPara, diParagraphOrEnd)); - } else + } else if (nStart > editor->nLastSelStart) { ME_MarkForPainting(editor, editor->pLastSelStartPara, ME_FindItemFwd(para1, diParagraphOrEnd)); } @@ -572,7 +574,7 @@ ME_InvalidateSelection(ME_TextEditor *editor) /* if the end part of selection is being contracted or expanded... */ if (nEnd < editor->nLastSelEnd) { ME_MarkForPainting(editor, para2, ME_FindItemFwd(editor->pLastSelEndPara, diParagraphOrEnd)); - } else + } else if (nEnd > editor->nLastSelEnd) { ME_MarkForPainting(editor, editor->pLastSelEndPara, ME_FindItemFwd(para2, diParagraphOrEnd)); } @@ -605,10 +607,10 @@ ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator) || (float)numerator / (float)denominator > 64.0) return FALSE; } - + editor->nZoomNumerator = numerator; editor->nZoomDenominator = denominator; - + ME_RewrapRepaint(editor); return TRUE; } diff --git a/reactos/dll/win32/riched20/para.c b/reactos/dll/win32/riched20/para.c index b3413c371d0..a1f62611db6 100644 --- a/reactos/dll/win32/riched20/para.c +++ b/reactos/dll/win32/riched20/para.c @@ -1,6 +1,6 @@ /* * RichEdit - functions working on paragraphs of text (diParagraph). - * + * * Copyright 2004 by Krzysztof Foltman * Copyright 2006 by Phil Krylov * @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ + */ #include "editor.h" @@ -45,7 +45,7 @@ void ME_MakeFirstParagraph(HDC hDC, ME_TextBuffer *text) cf.dwMask |= CFM_IMPRINT|CFM_ITALIC|CFM_LINK|CFM_OUTLINE|CFM_PROTECTED; cf.dwMask |= CFM_REVISED|CFM_SHADOW|CFM_SMALLCAPS|CFM_STRIKEOUT; cf.dwMask |= CFM_SUBSCRIPT|CFM_UNDERLINE; - + cf.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR; lstrcpyW(cf.szFaceName, lf.lfFaceName); cf.yHeight=lf.lfHeight*1440/GetDeviceCaps(hDC, LOGPIXELSY); @@ -55,16 +55,16 @@ void ME_MakeFirstParagraph(HDC hDC, ME_TextBuffer *text) if (lf.lfItalic) cf.dwEffects |= CFE_ITALIC; if (lf.lfUnderline) cf.dwEffects |= CFE_UNDERLINE; if (lf.lfStrikeOut) cf.dwEffects |= CFE_STRIKEOUT; - + ZeroMemory(&fmt, sizeof(fmt)); fmt.cbSize = sizeof(fmt); fmt.dwMask = PFM_ALIGNMENT | PFM_OFFSET | PFM_STARTINDENT | PFM_RIGHTINDENT | PFM_TABSTOPS; CopyMemory(para->member.para.pFmt, &fmt, sizeof(PARAFORMAT2)); - + style = ME_MakeStyle(&cf); text->pDefaultStyle = style; - + run = ME_MakeRun(style, ME_MakeString(wszParagraphSign), MERF_ENDPARA); run->member.run.nCharOfs = 0; @@ -77,13 +77,13 @@ void ME_MakeFirstParagraph(HDC hDC, ME_TextBuffer *text) text->pLast->member.para.nCharOfs = 1; } - + void ME_MarkAllForWrapping(ME_TextEditor *editor) { ME_MarkForWrapping(editor, editor->pBuffer->pFirst->member.para.next_para, editor->pBuffer->pLast); } -void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, ME_DisplayItem *last) +void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last) { while(first != last) { @@ -92,7 +92,7 @@ void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, ME_Display } } -void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, ME_DisplayItem *last) +void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last) { while(first != last) { @@ -112,8 +112,8 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME int ofs; ME_DisplayItem *pp; int end_len = (editor->bEmulateVersion10 ? 2 : 1); - - assert(run->type == diRun); + + assert(run->type == diRun); run_para = ME_GetParagraph(run); assert(run_para->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); @@ -121,11 +121,11 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME ofs = end_run->member.run.nCharOfs = run->member.run.nCharOfs; 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; - + /* the new paragraph will have a different starting offset, so let's update its runs */ pp = run; while(pp->type == diRun) { @@ -134,18 +134,18 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME } new_para->member.para.nCharOfs = ME_GetParagraph(run)->member.para.nCharOfs+ofs; new_para->member.para.nCharOfs += end_len; - + new_para->member.para.nFlags = MEPF_REWRAP; /* FIXME copy flags (if applicable) */ /* FIXME initialize format style and call ME_SetParaFormat blah blah */ CopyMemory(new_para->member.para.pFmt, run_para->member.para.pFmt, sizeof(PARAFORMAT2)); - + /* FIXME remove this as soon as nLeftMargin etc are replaced with proper fields of PARAFORMAT2 */ new_para->member.para.nLeftMargin = run_para->member.para.nLeftMargin; new_para->member.para.nRightMargin = run_para->member.para.nRightMargin; new_para->member.para.nFirstMargin = run_para->member.para.nFirstMargin; new_para->member.para.bTable = run_para->member.para.bTable; - + /* Inherit previous cell definitions if any */ new_para->member.para.pCells = NULL; if (run_para->member.para.pCells) @@ -164,7 +164,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME new_para->member.para.pLastCell = pNewCell; } } - + /* fix paragraph properties. FIXME only needed when called from RTF reader */ if (run_para->member.para.pCells && !run_para->member.para.bTable) { @@ -172,7 +172,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME * stored is invalid */ ME_DestroyTableCellList(run_para); } - + /* insert paragraph into paragraph double linked list */ new_para->member.para.prev_para = run_para; new_para->member.para.next_para = next_para; @@ -186,11 +186,11 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME /* force rewrap of the */ run_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP; new_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP; - + /* we've added the end run, so we need to modify nCharOfs in the next paragraphs */ ME_PropagateCharOffset(next_para, end_len); editor->nParagraphs++; - + return new_para; } @@ -206,9 +206,9 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) assert(tp->type == diParagraph); assert(tp->member.para.next_para); assert(tp->member.para.next_para->type == diParagraph); - + pNext = tp->member.para.next_para; - + { /* null char format operation to store the original char format for the ENDPARA run */ CHARFORMAT2W fmt; @@ -222,17 +222,17 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) assert(pNext->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); CopyMemory(undo->di.member.para.pFmt, pNext->member.para.pFmt, sizeof(PARAFORMAT2)); } - + shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len; - + pRun = ME_FindItemBack(pNext, diRunOrParagraph); pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph); - + assert(pRun); assert(pRun->type == diRun); assert(pRun->member.run.nFlags & MERF_ENDPARA); assert(pFirstRunInNext->type == diRun); - + /* if some cursor points at end of paragraph, make it point to the first run of the next joined paragraph */ for (i=0; inCursors; i++) { @@ -250,7 +250,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) TRACE("shifting \"%s\" by %d (previous %d)\n", debugstr_w(pTmp->member.run.strText->szData), shift, pTmp->member.run.nCharOfs); pTmp->member.run.nCharOfs += shift; } while(1); - + ME_Remove(pRun); ME_DestroyDisplayItem(pRun); @@ -258,16 +258,16 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) editor->pLastSelStartPara = tp; if (editor->pLastSelEndPara == pNext) editor->pLastSelEndPara = tp; - + tp->member.para.next_para = pNext->member.para.next_para; pNext->member.para.next_para->member.para.prev_para = tp; ME_Remove(pNext); ME_DestroyDisplayItem(pNext); ME_PropagateCharOffset(tp->member.para.next_para, -end_len); - + ME_CheckCharOffsets(editor); - + editor->nParagraphs--; tp->member.para.nFlags |= MEPF_REWRAP; return tp; @@ -277,12 +277,12 @@ ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *item) { return ME_FindItemBackOrHere(item, diParagraph); } -static void ME_DumpStyleEffect(char **p, const char *name, PARAFORMAT2 *fmt, int mask) +static void ME_DumpStyleEffect(char **p, const char *name, const PARAFORMAT2 *fmt, int mask) { *p += sprintf(*p, "%-22s%s\n", name, (fmt->dwMask & mask) ? ((fmt->wEffects & mask) ? "yes" : "no") : "N/A"); } -void ME_DumpParaStyleToBuf(PARAFORMAT2 *pFmt, char buf[2048]) +void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]) { /* FIXME only PARAFORMAT styles implemented */ char *p; @@ -299,31 +299,31 @@ void ME_DumpParaStyleToBuf(PARAFORMAT2 *pFmt, char buf[2048]) p += sprintf(p, "Offset: %d\n", (int)pFmt->dxOffset); else p += sprintf(p, "Offset: N/A\n"); - + if (pFmt->dwMask & PFM_OFFSETINDENT) p += sprintf(p, "Offset indent: %d\n", (int)pFmt->dxStartIndent); else p += sprintf(p, "Offset indent: N/A\n"); - + if (pFmt->dwMask & PFM_STARTINDENT) p += sprintf(p, "Start indent: %d\n", (int)pFmt->dxStartIndent); else p += sprintf(p, "Start indent: N/A\n"); - + if (pFmt->dwMask & PFM_RIGHTINDENT) p += sprintf(p, "Right indent: %d\n", (int)pFmt->dxRightIndent); else p += sprintf(p, "Right indent: N/A\n"); - + ME_DumpStyleEffect(&p, "Page break before:", pFmt, PFM_PAGEBREAKBEFORE); } -void ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, PARAFORMAT2 *pFmt) +void ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const PARAFORMAT2 *pFmt) { PARAFORMAT2 copy; assert(sizeof(*para->member.para.pFmt) == sizeof(PARAFORMAT2)); ME_AddUndoItem(editor, diUndoSetParagraphFormat, para); - + CopyMemory(©, para->member.para.pFmt, sizeof(PARAFORMAT2)); if (pFmt->dwMask & PFM_ALIGNMENT) @@ -334,13 +334,13 @@ void ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, PARAFORMAT2 * para->member.para.pFmt->dxOffset = pFmt->dxOffset; if (pFmt->dwMask & PFM_OFFSETINDENT) para->member.para.pFmt->dxStartIndent += pFmt->dxStartIndent; - + if (pFmt->dwMask & PFM_TABSTOPS) { para->member.para.pFmt->cTabCount = pFmt->cTabCount; memcpy(para->member.para.pFmt->rgxTabs, pFmt->rgxTabs, pFmt->cTabCount*sizeof(int)); } - + /* FIXME to be continued (indents, bulleting and such) */ if (memcmp(©, para->member.para.pFmt, sizeof(PARAFORMAT2))) @@ -352,7 +352,7 @@ void ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end) { ME_Cursor *pEndCursor = &editor->pCursors[1]; - + *para = ME_GetParagraph(editor->pCursors[0].pRun); *para_end = ME_GetParagraph(editor->pCursors[1].pRun); if ((*para_end)->member.para.nCharOfs < (*para)->member.para.nCharOfs) { @@ -362,7 +362,7 @@ ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayIte *para_end = tmp; pEndCursor = &editor->pCursors[0]; } - + /* selection consists of chars from nFrom up to nTo-1 */ if ((*para_end)->member.para.nCharOfs > (*para)->member.para.nCharOfs) { if (!pEndCursor->nOffset) { @@ -372,12 +372,12 @@ ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayIte } -void ME_SetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) +void ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt) { ME_DisplayItem *para, *para_end; - + ME_GetSelectionParas(editor, ¶, ¶_end); - + do { ME_SetParaFormat(editor, para, pFmt); if (para == para_end) @@ -386,44 +386,44 @@ void ME_SetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) } while(1); } -void ME_GetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, PARAFORMAT2 *pFmt) +void ME_GetParaFormat(ME_TextEditor *editor, const ME_DisplayItem *para, PARAFORMAT2 *pFmt) { if (pFmt->cbSize >= sizeof(PARAFORMAT2)) { CopyMemory(pFmt, para->member.para.pFmt, sizeof(PARAFORMAT2)); return; } - CopyMemory(pFmt, para->member.para.pFmt, pFmt->cbSize); + CopyMemory(pFmt, para->member.para.pFmt, pFmt->cbSize); } void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) { ME_DisplayItem *para, *para_end; PARAFORMAT2 tmp; - + ME_GetSelectionParas(editor, ¶, ¶_end); - + ME_GetParaFormat(editor, para, pFmt); if (para == para_end) return; - + do { ZeroMemory(&tmp, sizeof(tmp)); tmp.cbSize = sizeof(tmp); ME_GetParaFormat(editor, para, &tmp); - - assert(tmp.dwMask & PFM_ALIGNMENT); + + assert(tmp.dwMask & PFM_ALIGNMENT); if (pFmt->wAlignment != tmp.wAlignment) pFmt->dwMask &= ~PFM_ALIGNMENT; - + assert(tmp.dwMask & PFM_STARTINDENT); if (pFmt->dxStartIndent != tmp.dxStartIndent) pFmt->dwMask &= ~PFM_STARTINDENT; - + assert(tmp.dwMask & PFM_OFFSET); if (pFmt->dxOffset != tmp.dxOffset) pFmt->dwMask &= ~PFM_OFFSET; - - assert(tmp.dwMask & PFM_TABSTOPS); + + assert(tmp.dwMask & PFM_TABSTOPS); if (pFmt->dwMask & PFM_TABSTOPS) { if (pFmt->cTabCount != tmp.cTabCount) pFmt->dwMask &= ~PFM_TABSTOPS; @@ -431,7 +431,7 @@ void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) if (memcmp(pFmt->rgxTabs, tmp.rgxTabs, tmp.cTabCount*sizeof(int))) pFmt->dwMask &= ~PFM_TABSTOPS; } - + if (para == para_end) return; para = para->member.para.next_para; diff --git a/reactos/dll/win32/riched20/reader.c b/reactos/dll/win32/riched20/reader.c index 6411813f5f4..e0a9e1a86e3 100644 --- a/reactos/dll/win32/riched20/reader.c +++ b/reactos/dll/win32/riched20/reader.c @@ -92,7 +92,7 @@ static void RTFPutCodePageChar(RTF_Info *info, int c); /* * Saves a string on the heap and returns a pointer to it. */ -static inline char *RTFStrSave(char *s) +static inline char *RTFStrSave(const char *s) { char *p; @@ -254,7 +254,7 @@ void RTFInit(RTF_Info *info) * to be accurate, only insofar as the calling program makes them so. */ -void RTFSetInputName(RTF_Info *info, char *name) +void RTFSetInputName(RTF_Info *info, const char *name) { info->inputName = RTFStrSave (name); if (info->inputName == NULL) @@ -262,13 +262,13 @@ void RTFSetInputName(RTF_Info *info, char *name) } -char *RTFGetInputName(RTF_Info *info) +char *RTFGetInputName(const RTF_Info *info) { return (info->inputName); } -void RTFSetOutputName(RTF_Info *info, char *name) +void RTFSetOutputName(RTF_Info *info, const char *name) { info->outputName = RTFStrSave (name); if (info->outputName == NULL) @@ -276,7 +276,7 @@ void RTFSetOutputName(RTF_Info *info, char *name) } -char *RTFGetOutputName(RTF_Info *info) +char *RTFGetOutputName(const RTF_Info *info) { return (info->outputName); } @@ -301,7 +301,7 @@ void RTFSetClassCallback(RTF_Info *info, int class, RTFFuncPtr callback) } -RTFFuncPtr RTFGetClassCallback(RTF_Info *info, int class) +RTFFuncPtr RTFGetClassCallback(const RTF_Info *info, int class) { if (class >= 0 && class < rtfMaxClass) return info->ccb[class]; @@ -320,7 +320,7 @@ void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback) } -RTFFuncPtr RTFGetDestinationCallback(RTF_Info *info, int dest) +RTFFuncPtr RTFGetDestinationCallback(const RTF_Info *info, int dest) { if (dest >= 0 && dest < rtfMaxDestination) return info->dcb[dest]; @@ -447,7 +447,7 @@ void RTFSetReadHook(RTF_Info *info, RTFFuncPtr f) } -RTFFuncPtr RTFGetReadHook(RTF_Info *info) +RTFFuncPtr RTFGetReadHook(const RTF_Info *info) { return (info->readHook); } @@ -1258,7 +1258,7 @@ static void ReadObjGroup(RTF_Info *info) */ -RTFStyle *RTFGetStyle(RTF_Info *info, int num) +RTFStyle *RTFGetStyle(const RTF_Info *info, int num) { RTFStyle *s; @@ -1273,7 +1273,7 @@ RTFStyle *RTFGetStyle(RTF_Info *info, int num) } -RTFFont *RTFGetFont(RTF_Info *info, int num) +RTFFont *RTFGetFont(const RTF_Info *info, int num) { RTFFont *f; @@ -1288,7 +1288,7 @@ RTFFont *RTFGetFont(RTF_Info *info, int num) } -RTFColor *RTFGetColor(RTF_Info *info, int num) +RTFColor *RTFGetColor(const RTF_Info *info, int num) { RTFColor *c; @@ -2373,19 +2373,19 @@ static int Hash(const char *s) * Token comparison routines */ -int RTFCheckCM(RTF_Info *info, int class, int major) +int RTFCheckCM(const RTF_Info *info, int class, int major) { return (info->rtfClass == class && info->rtfMajor == major); } -int RTFCheckCMM(RTF_Info *info, int class, int major, int minor) +int RTFCheckCMM(const RTF_Info *info, int class, int major, int minor) { return (info->rtfClass == class && info->rtfMajor == major && info->rtfMinor == minor); } -int RTFCheckMM(RTF_Info *info, int major, int minor) +int RTFCheckMM(const RTF_Info *info, int major, int minor) { return (info->rtfMajor == major && info->rtfMinor == minor); } @@ -2518,7 +2518,7 @@ CharSet(RTF_Info *info) { if (info->ansiCodePage == CP_UTF8) return; - + switch (info->rtfMinor) { case rtfAnsiCharSet: @@ -2546,7 +2546,7 @@ static void Destination (RTF_Info *info) { if (!RTFGetDestinationCallback(info, info->rtfMinor)) - RTFSkipGroup (info); + RTFSkipGroup (info); } @@ -2581,8 +2581,8 @@ static void SpecialChar (RTF_Info *info) { case rtfOptDest: /* the next token determines destination, if it's unknown, skip the group */ - /* this way we filter out the garbage coming from unknown destinations */ - RTFGetToken(info); + /* this way we filter out the garbage coming from unknown destinations */ + RTFGetToken(info); if (info->rtfClass != rtfDestination) RTFSkipGroup(info); else @@ -2661,7 +2661,7 @@ RTFFlushUnicodeOutputBuffer(RTF_Info *info) } static void -RTFPutUnicodeString(RTF_Info *info, WCHAR *string, int length) +RTFPutUnicodeString(RTF_Info *info, const WCHAR *string, int length) { if (info->dwCPOutputCount) RTFFlushCPOutputBuffer(info); diff --git a/reactos/dll/win32/riched20/riched20.rbuild b/reactos/dll/win32/riched20/riched20.rbuild index 0f25da92fa1..0a658cb8631 100644 --- a/reactos/dll/win32/riched20/riched20.rbuild +++ b/reactos/dll/win32/riched20/riched20.rbuild @@ -1,13 +1,12 @@ + + . include/reactos/wine - - - 0x600 - 0x501 - 0x501 + 0x600 + 0x600 wine ole32 imm32 diff --git a/reactos/dll/win32/riched20/richole.c b/reactos/dll/win32/riched20/richole.c index 04ad79845bb..0585e43edf8 100644 --- a/reactos/dll/win32/riched20/richole.c +++ b/reactos/dll/win32/riched20/richole.c @@ -86,8 +86,8 @@ IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj) return S_OK; } FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid) ); - - return E_NOINTERFACE; + + return E_NOINTERFACE; } static ULONG WINAPI diff --git a/reactos/dll/win32/riched20/row.c b/reactos/dll/win32/riched20/row.c index 6bf0062bd2c..3abff5f7a51 100644 --- a/reactos/dll/win32/riched20/row.c +++ b/reactos/dll/win32/riched20/row.c @@ -1,9 +1,9 @@ /* * RichEdit - Operations on rows of text (rows are recreated during * wrapping and are used for displaying the document, they don't keep any - * true document content; delete all rows, rewrap all paragraphs and + * true document content; delete all rows, rewrap all paragraphs and * you get them back). - * + * * Copyright 2004 by Krzysztof Foltman * * This library is free software; you can redistribute it and/or @@ -19,12 +19,12 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ + */ #include "editor.h" -ME_DisplayItem *ME_FindRowStart(ME_Context *c, ME_DisplayItem *item, +ME_DisplayItem *ME_FindRowStart(ME_Context *c, ME_DisplayItem *item, int nRelPos) { ME_DisplayItem *para = ME_GetParagraph(item); ME_MustBeWrapped(c, para); @@ -70,7 +70,7 @@ ME_DisplayItem *ME_FindRowStart(ME_Context *c, ME_DisplayItem *item, /* I'm sure these functions would simplify some code in caret ops etc, * I just didn't remember them when I wrote that code - */ + */ ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) { return ME_FindItemBackOrHere(item, diStartRow); @@ -89,7 +89,7 @@ ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) { ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph); int nCount = 0; - + while (item && nCount + item->member.para.nRows <= nRow) { nCount += item->member.para.nRows; @@ -117,7 +117,7 @@ ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) if (item) { ME_DisplayItem *next_para = item->member.para.next_para; - + nOfs -= item->member.para.nCharOfs; item = ME_FindItemFwd(item, diRun); while ((item = ME_FindItemFwd(item, diStartRowOrParagraph)) != NULL) diff --git a/reactos/dll/win32/riched20/rtf.h b/reactos/dll/win32/riched20/rtf.h index b88592b5ac0..7234b435f88 100644 --- a/reactos/dll/win32/riched20/rtf.h +++ b/reactos/dll/win32/riched20/rtf.h @@ -961,7 +961,7 @@ struct RTFFont /* - * Color values are -1 if the default color for the the color + * Color values are -1 if the default color for the color * number should be used. The default color is writer-dependent. */ @@ -1083,7 +1083,7 @@ struct _RTF_Info { /* edit window to output to */ HWND hwndEdit; - + ME_TextEditor *editor; ME_Style *style; @@ -1112,30 +1112,30 @@ struct _RTF_Info { void RTFInit (RTF_Info *); void RTFDestroy(RTF_Info *info); -void RTFSetInputName (RTF_Info *, char *); -char *RTFGetInputName (RTF_Info *); -void RTFSetOutputName (RTF_Info *, char *); -char *RTFGetOutputName (RTF_Info *); +void RTFSetInputName (RTF_Info *, const char *); +char *RTFGetInputName (const RTF_Info *); +void RTFSetOutputName (RTF_Info *, const char *); +char *RTFGetOutputName (const RTF_Info *); void RTFSetClassCallback (RTF_Info *, int, RTFFuncPtr); -RTFFuncPtr RTFGetClassCallback (RTF_Info *, int); +RTFFuncPtr RTFGetClassCallback (const RTF_Info *, int); void RTFSetDestinationCallback (RTF_Info *, int, RTFFuncPtr); -RTFFuncPtr RTFGetDestinationCallback (RTF_Info *, int); +RTFFuncPtr RTFGetDestinationCallback (const RTF_Info *, int); void RTFRead (RTF_Info *); int RTFGetToken (RTF_Info *); /* writer should rarely need this */ void RTFUngetToken (RTF_Info *); int RTFPeekToken (RTF_Info *); void RTFSetToken (RTF_Info *, int, int, int, int, const char *); void RTFSetReadHook (RTF_Info *, RTFFuncPtr); -RTFFuncPtr RTFGetReadHook (RTF_Info *); +RTFFuncPtr RTFGetReadHook (const RTF_Info *); void RTFRouteToken (RTF_Info *); void RTFSkipGroup (RTF_Info *); void RTFExpandStyle (RTF_Info *, int); -int RTFCheckCM (RTF_Info *, int, int); -int RTFCheckCMM (RTF_Info *, int, int, int); -int RTFCheckMM (RTF_Info *, int, int); -RTFFont *RTFGetFont (RTF_Info *, int); -RTFColor *RTFGetColor (RTF_Info *, int); -RTFStyle *RTFGetStyle (RTF_Info *, int); +int RTFCheckCM (const RTF_Info *, int, int); +int RTFCheckCMM (const RTF_Info *, int, int, int); +int RTFCheckMM (const RTF_Info *, int, int); +RTFFont *RTFGetFont (const RTF_Info *, int); +RTFColor *RTFGetColor (const RTF_Info *, int); +RTFStyle *RTFGetStyle (const RTF_Info *, int); int RTFCharToHex ( char); int RTFHexToChar ( int ); diff --git a/reactos/dll/win32/riched20/run.c b/reactos/dll/win32/riched20/run.c index dca64b657e6..16306530b0b 100644 --- a/reactos/dll/win32/riched20/run.c +++ b/reactos/dll/win32/riched20/run.c @@ -31,8 +31,8 @@ WINE_DECLARE_DEBUG_CHANNEL(richedit_lists); * ME_CanJoinRuns * * Returns 1 if two runs can be safely merged into one, 0 otherwise. - */ -int ME_CanJoinRuns(ME_Run *run1, ME_Run *run2) + */ +int ME_CanJoinRuns(const ME_Run *run1, const ME_Run *run2) { if ((run1->nFlags | run2->nFlags) & MERF_NOJOIN) return 0; @@ -53,15 +53,15 @@ void ME_SkipAndPropagateCharOffset(ME_DisplayItem *p, int shift) /****************************************************************************** * ME_PropagateCharOffsets * - * Shifts (increases or decreases) character offset (relative to beginning of - * the document) of the part of the text starting from given place. - */ + * Shifts (increases or decreases) character offset (relative to beginning of + * the document) of the part of the text starting from given place. + */ void ME_PropagateCharOffset(ME_DisplayItem *p, int shift) { /* Runs in one paragraph contain character offset relative to their owning * paragraph. If we start the shifting from the run, we need to shift * all the relative offsets until the end of the paragraph - */ + */ if (p->type == diRun) /* propagate in all runs in this para */ { TRACE("PropagateCharOffset(%s, %d)\n", debugstr_w(p->member.run.strText->szData), shift); @@ -71,10 +71,10 @@ void ME_PropagateCharOffset(ME_DisplayItem *p, int shift) p = ME_FindItemFwd(p, diRunOrParagraphOrEnd); } while(p->type == diRun); } - /* Runs in next paragraphs don't need their offsets updated, because they, + /* Runs in next paragraphs don't need their offsets updated, because they, * again, those offsets are relative to their respective paragraphs. - * Instead of that, we're updating paragraphs' character offsets. - */ + * Instead of that, we're updating paragraphs' character offsets. + */ if (p->type == diParagraph) /* propagate in all next paras */ { do { @@ -95,9 +95,9 @@ void ME_PropagateCharOffset(ME_DisplayItem *p, int shift) /****************************************************************************** * ME_CheckCharOffsets - * + * * Checks if editor lists' validity and optionally dumps the document structure - */ + */ void ME_CheckCharOffsets(ME_TextEditor *editor) { ME_DisplayItem *p = editor->pBuffer->pFirst; @@ -140,11 +140,11 @@ void ME_CheckCharOffsets(ME_TextEditor *editor) /****************************************************************************** * ME_CharOfsFromRunOfs - * + * * Converts a character position relative to the start of the run, to a * character position relative to the start of the document. - * Kind of a "local to global" offset conversion. - */ + * Kind of a "local to global" offset conversion. + */ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, ME_DisplayItem *pRun, int nOfs) { ME_DisplayItem *pPara; @@ -161,11 +161,11 @@ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, ME_DisplayItem *pRun, int nOfs) /****************************************************************************** * ME_CursorFromCharOfs - * + * * Converts a character offset (relative to the start of the document) to - * a cursor structure (which contains a run and a position relative to that - * run). - */ + * a cursor structure (which contains a run and a position relative to that + * run). + */ void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor) { ME_RunOfsFromCharOfs(editor, nCharOfs, &pCursor->pRun, &pCursor->nOffset); @@ -173,11 +173,11 @@ void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCurso /****************************************************************************** * ME_RunOfsFromCharOfs - * + * * Find a run and relative character offset given an absolute character offset * (absolute offset being an offset relative to the start of the document). - * Kind of a "global to local" offset conversion. - */ + * Kind of a "global to local" offset conversion. + */ void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem **ppRun, int *pOfs) { ME_DisplayItem *pPara; @@ -226,9 +226,9 @@ void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem ** /****************************************************************************** * ME_JoinRuns - * + * * Merges two adjacent runs, the one given as a parameter and the next one. - */ + */ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p) { ME_DisplayItem *pNext = p->next; @@ -238,7 +238,7 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p) ME_GetParagraph(p)->member.para.nFlags |= MEPF_REWRAP; /* if we were at the end of screen line, and the next run is in the new - * line, then it's not the end of the line anymore */ + * line, then it's not the end of the line anymore */ if (editor->bCaretAtEnd && editor->pCursors[0].pRun == pNext) editor->bCaretAtEnd = FALSE; /* Update all cursors so that they don't contain the soon deleted run */ @@ -263,10 +263,10 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p) /****************************************************************************** * ME_SplitRun - * + * * Splits a run into two in a given place. It also updates the screen position - * and size (extent) of the newly generated runs. - */ + * and size (extent) of the newly generated runs. + */ ME_DisplayItem *ME_SplitRun(ME_Context *c, ME_DisplayItem *item, int nVChar) { ME_TextEditor *editor = c->editor; @@ -312,10 +312,10 @@ ME_DisplayItem *ME_SplitRun(ME_Context *c, ME_DisplayItem *item, int nVChar) /****************************************************************************** * ME_SplitRunSimple - * + * * Does the most basic job of splitting a run into two - it does not - * update the positions and extents. - */ + * update the positions and extents. + */ ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nVChar) { ME_Run *run = &item->member.run; @@ -352,9 +352,9 @@ ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, i /****************************************************************************** * ME_MakeRun - * + * * A helper function to create run structures quickly. - */ + */ ME_DisplayItem *ME_MakeRun(ME_Style *s, ME_String *strData, int nFlags) { ME_DisplayItem *item = ME_MakeDI(diRun); @@ -368,9 +368,9 @@ ME_DisplayItem *ME_MakeRun(ME_Style *s, ME_String *strData, int nFlags) /****************************************************************************** * ME_InsertRun - * + * * Inserts a run at a given character position (offset). - */ + */ ME_DisplayItem *ME_InsertRun(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem *pItem) { ME_Cursor tmp; @@ -383,38 +383,38 @@ ME_DisplayItem *ME_InsertRun(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem pItem->member.run.strText->szData, pItem->member.run.strText->nLen, pItem->member.run.nFlags); - + return pDI; } /****************************************************************************** * ME_InsertRunAtCursor - * + * * Inserts a new run with given style, flags and content at a given position, - * which is passed as a cursor structure (which consists of a run and - * a run-relative character offset). - */ + * which is passed as a cursor structure (which consists of a run and + * a run-relative character offset). + */ ME_DisplayItem * 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) { /* We're inserting at the middle of the existing run, which means that * that run must be split. It isn't always necessary, but */ cursor->pRun = ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset); cursor->nOffset = 0; } - + pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL); if (pUI) { pUI->nStart = (ME_GetParagraph(cursor->pRun)->member.para.nCharOfs + cursor->pRun->member.run.nCharOfs); pUI->nLen = len; } - + pDI = ME_MakeRun(style, ME_MakeStringN(str, len), flags); pDI->member.run.nCharOfs = cursor->pRun->member.run.nCharOfs; ME_InsertBefore(cursor->pRun, pDI); @@ -426,11 +426,11 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style, /****************************************************************************** * ME_UpdateRunFlags - * + * * Determine some of run attributes given its content (style, text content). - * Some flags cannot be determined by this function (MERF_GRAPHICS, - * MERF_ENDPARA) - */ + * Some flags cannot be determined by this function (MERF_GRAPHICS, + * MERF_ENDPARA) + */ void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) { assert(run->nCharOfs != -1); @@ -469,10 +469,10 @@ void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) /****************************************************************************** * ME_GetGraphicsSize - * + * * Sets run extent for graphics runs. This functionality is just a placeholder * for future OLE object support, and will be removed. - */ + */ void ME_GetGraphicsSize(ME_TextEditor *editor, ME_Run *run, SIZE *pSize) { assert(run->nFlags & MERF_GRAPHICS); @@ -482,11 +482,11 @@ void ME_GetGraphicsSize(ME_TextEditor *editor, ME_Run *run, SIZE *pSize) /****************************************************************************** * ME_CharFromPoint - * + * * Returns a character position inside the run given a run-relative * pixel horizontal position. This version rounds left (ie. if the second - * character is at pixel position 8, then for cx=0..7 it returns 0). - */ + * character is at pixel position 8, then for cx=0..7 it returns 0). + */ int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run) { int fit = 0; @@ -498,7 +498,7 @@ int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run) if (run->nFlags & (MERF_TAB | MERF_CELL)) { - if (cx < run->nWidth/2) + if (cx < run->nWidth/2) return 0; return 1; } @@ -512,7 +512,7 @@ int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run) } hDC = GetDC(editor->hWnd); hOldFont = ME_SelectStyleFont(editor, hDC, run->style); - + if (editor->cPasswordMask) { ME_String *strMasked = ME_MakeStringR(editor->cPasswordMask,ME_StrVLen(run->strText)); @@ -525,7 +525,7 @@ int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run) GetTextExtentExPointW(hDC, run->strText->szData, run->strText->nLen, cx, &fit, NULL, &sz); } - + ME_UnselectStyleFont(editor, hDC, run->style, hOldFont); ReleaseDC(editor->hWnd, hDC); return fit; @@ -533,20 +533,20 @@ int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run) /****************************************************************************** * ME_CharFromPointCursor - * + * * Returns a character position inside the run given a run-relative - * pixel horizontal position. This version rounds to the nearest character edge - * (ie. if the second character is at pixel position 8, then for cx=0..3 + * pixel horizontal position. This version rounds to the nearest character edge + * (ie. if the second character is at pixel position 8, then for cx=0..3 * it returns 0, and for cx=4..7 it returns 1). - * + * * It is used for mouse click handling, for better usability (and compatibility - * with the native control). - */ + * with the native control). + */ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run) { ME_String *strRunText; /* This could point to either the run's real text, or it's masked form in a password control */ - + int fit = 0, fit1 = 0; HGDIOBJ hOldFont; HDC hDC; @@ -568,7 +568,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run) return 0; return 1; } - + if (editor->cPasswordMask) strRunText = ME_MakeStringR(editor->cPasswordMask,ME_StrVLen(run->strText)); else @@ -588,10 +588,10 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run) if (cx >= (sz2.cx+sz3.cx)/2) fit = fit1; } - + if (editor->cPasswordMask) ME_DestroyString(strRunText); - + ME_UnselectStyleFont(editor, hDC, run->style, hOldFont); ReleaseDC(editor->hWnd, hDC); return fit; @@ -599,10 +599,10 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run) /****************************************************************************** * ME_PointFromChar - * + * * Returns a run-relative pixel position given a run-relative character * position (character offset) - */ + */ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) { SIZE size; @@ -617,12 +617,12 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) ME_GetGraphicsSize(editor, pRun, &size); return 1; } - + if (editor->cPasswordMask) strRunText = ME_MakeStringR(editor->cPasswordMask,ME_StrVLen(pRun->strText)); else strRunText = pRun->strText; - + hOldFont = ME_SelectStyleFont(editor, hDC, pRun->style); GetTextExtentPoint32W(hDC, strRunText->szData, nOffset, &size); ME_UnselectStyleFont(editor, hDC, pRun->style, hOldFont); @@ -648,11 +648,11 @@ static void ME_GetTextExtent(ME_Context *c, LPCWSTR szText, int nChars, ME_Style /****************************************************************************** * ME_GetRunSizeCommon - * + * * Finds width, height, ascent and descent of a run, up to given character * (nLen). */ -static SIZE ME_GetRunSizeCommon(ME_Context *c, ME_Paragraph *para, ME_Run *run, int nLen, +static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, int *pAscent, int *pDescent) { SIZE size; @@ -665,11 +665,11 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, ME_Paragraph *para, ME_Run *run, * this is wasteful for MERF_NONTEXT runs, but that shouldn't matter * in practice */ - + if (c->editor->cPasswordMask) { ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,nLen); - ME_GetTextExtent(c, szMasked->szData, nLen,run->style, &size); + ME_GetTextExtent(c, szMasked->szData, nLen,run->style, &size); ME_DestroyString(szMasked); } else @@ -724,11 +724,11 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, ME_Paragraph *para, ME_Run *run, /****************************************************************************** * ME_GetRunSize - * + * * Finds width and height (but not ascent and descent) of a part of the run - * up to given character. - */ -SIZE ME_GetRunSize(ME_Context *c, ME_Paragraph *para, ME_Run *run, int nLen) + * up to given character. + */ +SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen) { int asc, desc; return ME_GetRunSizeCommon(c, para, run, nLen, &asc, &desc); @@ -736,12 +736,12 @@ SIZE ME_GetRunSize(ME_Context *c, ME_Paragraph *para, ME_Run *run, int nLen) /****************************************************************************** * ME_CalcRunExtent - * + * * Updates the size of the run (fills width, ascent and descent). The height * is calculated based on whole row's ascent and descent anyway, so no need - * to use it here. - */ -void ME_CalcRunExtent(ME_Context *c, ME_Paragraph *para, ME_Run *run) + * to use it here. + */ +void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, ME_Run *run) { if (run->nFlags & MERF_HIDDEN) run->nWidth = 0; @@ -757,10 +757,10 @@ void ME_CalcRunExtent(ME_Context *c, ME_Paragraph *para, ME_Run *run) /****************************************************************************** * ME_MustBeWrapped - * + * * This should ensure that the given paragraph is wrapped so that its screen - * row structure may be used. But it doesn't, yet. - */ + * row structure may be used. But it doesn't, yet. + */ void ME_MustBeWrapped(ME_Context *c, ME_DisplayItem *para) { assert(para->type == diParagraph); @@ -769,10 +769,10 @@ void ME_MustBeWrapped(ME_Context *c, ME_DisplayItem *para) /****************************************************************************** * ME_SetSelectionCharFormat - * + * * Applies a style change, either to a current selection, or to insert cursor * (ie. the style next typed characters will use). - */ + */ void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) { int nFrom, nTo; @@ -792,9 +792,9 @@ void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) /****************************************************************************** * ME_SetCharFormat - * + * * Applies a style change to the specified part of the text - */ + */ void ME_SetCharFormat(ME_TextEditor *editor, int nOfs, int nChars, CHARFORMAT2W *pFmt) { ME_Cursor tmp, tmp2; @@ -841,9 +841,9 @@ void ME_SetCharFormat(ME_TextEditor *editor, int nOfs, int nChars, CHARFORMAT2W /****************************************************************************** * ME_SetDefaultCharFormat - * + * * Applies a style change to the default character style. - */ + */ void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod) { ME_Style *style; @@ -872,10 +872,10 @@ static void ME_GetRunCharFormat(ME_TextEditor *editor, ME_DisplayItem *run, CHAR /****************************************************************************** * ME_GetDefaultCharFormat - * + * * Retrieves the current default character style (the one applied where no * other style was applied) . - */ + */ void ME_GetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) { int nFrom, nTo; @@ -885,10 +885,10 @@ void ME_GetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) /****************************************************************************** * ME_GetSelectionCharFormat - * + * * If selection exists, it returns all style elements that are set consistently - * in the whole selection. If not, it just returns the current style. - */ + * in the whole selection. If not, it just returns the current style. + */ void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) { int nFrom, nTo; @@ -903,10 +903,10 @@ void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) /****************************************************************************** * ME_GetCharFormat - * + * * Returns the style consisting of those attributes which are consistently set - * in the whole character range. - */ + * in the whole character range. + */ void ME_GetCharFormat(ME_TextEditor *editor, int nFrom, int nTo, CHARFORMAT2W *pFmt) { ME_DisplayItem *run, *run_end; @@ -927,7 +927,7 @@ void ME_GetCharFormat(ME_TextEditor *editor, int nFrom, int nTo, CHARFORMAT2W *p ME_GetRunCharFormat(editor, run, pFmt); return; } - + if (nTo>nFrom) /* selection consists of chars from nFrom up to nTo-1 */ nTo--; ME_RunOfsFromCharOfs(editor, nTo, &run_end, &nOffset2); diff --git a/reactos/dll/win32/riched20/string.c b/reactos/dll/win32/riched20/string.c index bb4287bbba1..2ec0092fcab 100644 --- a/reactos/dll/win32/riched20/string.c +++ b/reactos/dll/win32/riched20/string.c @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "editor.h" +#include "editor.h" WINE_DEFAULT_DEBUG_CHANNEL(richedit); @@ -40,7 +40,7 @@ ME_String *ME_MakeString(LPCWSTR szText) ME_String *ME_MakeStringN(LPCWSTR szText, int nMaxChars) { ME_String *s = ALLOC_OBJ(ME_String); - + s->nLen = nMaxChars; s->nBuffer = ME_GetOptimalBuffer(s->nLen+1); s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer); @@ -54,7 +54,7 @@ ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars) { /* Make a string by repeating a char nMaxChars times */ int i; ME_String *s = ALLOC_OBJ(ME_String); - + s->nLen = nMaxChars; s->nBuffer = ME_GetOptimalBuffer(s->nLen+1); s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer); @@ -68,7 +68,7 @@ ME_String *ME_MakeStringR(WCHAR cRepeat, int nMaxChars) ME_String *ME_MakeStringB(int nMaxChars) { /* Create a buffer (uninitialized string) of size nMaxChars */ ME_String *s = ALLOC_OBJ(ME_String); - + s->nLen = nMaxChars; s->nBuffer = ME_GetOptimalBuffer(s->nLen+1); s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer); @@ -76,7 +76,7 @@ ME_String *ME_MakeStringB(int nMaxChars) return s; } -ME_String *ME_StrDup(ME_String *s) +ME_String *ME_StrDup(const ME_String *s) { return ME_MakeStringN(s->szData, s->nLen); } @@ -87,7 +87,7 @@ void ME_DestroyString(ME_String *s) FREE_OBJ(s); } -void ME_AppendString(ME_String *s1, ME_String *s2) +void ME_AppendString(ME_String *s1, const ME_String *s2) { if (s1->nLen+s2->nLen+1 <= s1->nBuffer) { lstrcpyW(s1->szData+s1->nLen, s2->szData); @@ -98,7 +98,7 @@ void ME_AppendString(ME_String *s1, ME_String *s2) WCHAR *buf; s1->nBuffer = ME_GetOptimalBuffer(s1->nLen+s2->nLen+1); - buf = ALLOC_N_OBJ(WCHAR, s1->nBuffer); + buf = ALLOC_N_OBJ(WCHAR, s1->nBuffer); lstrcpyW(buf, s1->szData); lstrcpyW(buf+s1->nLen, s2->szData); FREE_OBJ(s1->szData); @@ -107,7 +107,7 @@ void ME_AppendString(ME_String *s1, ME_String *s2) } } -ME_String *ME_ConcatString(ME_String *s1, ME_String *s2) +ME_String *ME_ConcatString(const ME_String *s1, const ME_String *s2) { ME_String *s = ALLOC_OBJ(ME_String); s->nLen = s1->nLen+s2->nLen; @@ -115,7 +115,7 @@ ME_String *ME_ConcatString(ME_String *s1, ME_String *s2) s->szData = ALLOC_N_OBJ(WCHAR, s->nBuffer); lstrcpyW(s->szData, s1->szData); lstrcpyW(s->szData+s1->nLen, s2->szData); - return s; + return s; } ME_String *ME_VSplitString(ME_String *orig, int charidx) @@ -134,7 +134,7 @@ ME_String *ME_VSplitString(ME_String *orig, int charidx) return s; } -int ME_IsWhitespaces(ME_String *s) +int ME_IsWhitespaces(const ME_String *s) { /* FIXME multibyte */ WCHAR *pos = s->szData; @@ -147,7 +147,7 @@ int ME_IsWhitespaces(ME_String *s) return 1; } -int ME_IsSplitable(ME_String *s) +int ME_IsSplitable(const ME_String *s) { WCHAR *pos = s->szData; WCHAR ch; @@ -173,15 +173,15 @@ int ME_CalcSkipChars(ME_String *s) } */ -int ME_StrLen(ME_String *s) { +int ME_StrLen(const ME_String *s) { return s->nLen; } -int ME_StrVLen(ME_String *s) { +int ME_StrVLen(const ME_String *s) { return s->nLen; } -int ME_StrRelPos(ME_String *s, int nVChar, int *pRelChars) +int ME_StrRelPos(const ME_String *s, int nVChar, int *pRelChars) { int nRelChars = *pRelChars; @@ -190,7 +190,7 @@ int ME_StrRelPos(ME_String *s, int nVChar, int *pRelChars) assert(*pRelChars); if (!nRelChars) return nVChar; - + if (nRelChars>0) nRelChars = min(*pRelChars, s->nLen - nVChar); else @@ -200,7 +200,7 @@ int ME_StrRelPos(ME_String *s, int nVChar, int *pRelChars) return nVChar; } -int ME_StrRelPos2(ME_String *s, int nVChar, int nRelChars) +int ME_StrRelPos2(const ME_String *s, int nVChar, int nRelChars) { return ME_StrRelPos(s, nVChar, &nRelChars); } @@ -224,7 +224,7 @@ int ME_VPosToPos(ME_String *s, int nVPos) */ } -int ME_PosToVPos(ME_String *s, int nPos) +int ME_PosToVPos(const ME_String *s, int nPos) { if (!nPos) return 0; @@ -234,66 +234,66 @@ int ME_PosToVPos(ME_String *s, int nPos) void ME_StrDeleteV(ME_String *s, int nVChar, int nChars) { int end_ofs; - + assert(nVChar >=0 && nVChar <= s->nLen); assert(nChars >= 0); assert(nVChar+nChars <= s->nLen); - + end_ofs = ME_StrRelPos2(s, nVChar, nChars); assert(end_ofs <= s->nLen); memmove(s->szData+nVChar, s->szData+end_ofs, 2*(s->nLen+1-end_ofs)); s->nLen -= (end_ofs - nVChar); } -int ME_GetCharFwd(ME_String *s, int nPos) +int ME_GetCharFwd(const ME_String *s, int nPos) { int nVPos = 0; assert(nPos < ME_StrLen(s)); if (nPos) nVPos = ME_StrRelPos2(s, nVPos, nPos); - + if (nVPos < s->nLen) return s->szData[nVPos]; return -1; } -int ME_GetCharBack(ME_String *s, int nPos) +int ME_GetCharBack(const ME_String *s, int nPos) { int nVPos = ME_StrVLen(s); assert(nPos < ME_StrLen(s)); if (nPos) nVPos = ME_StrRelPos2(s, nVPos, -nPos); - + if (nVPos < s->nLen) return s->szData[nVPos]; return -1; } -int ME_FindNonWhitespaceV(ME_String *s, int nVChar) { +int ME_FindNonWhitespaceV(const ME_String *s, int nVChar) { int i; for (i = nVChar; inLen && ME_IsWSpace(s->szData[i]); i++) ; - + return i; } /* note: returns offset of the first trailing whitespace */ -int ME_ReverseFindNonWhitespaceV(ME_String *s, int nVChar) { +int ME_ReverseFindNonWhitespaceV(const ME_String *s, int nVChar) { int i; for (i = nVChar; i>0 && ME_IsWSpace(s->szData[i-1]); i--) ; - + return i; } /* note: returns offset of the first trailing nonwhitespace */ -int ME_ReverseFindWhitespaceV(ME_String *s, int nVChar) { +int ME_ReverseFindWhitespaceV(const ME_String *s, int nVChar) { int i; for (i = nVChar; i>0 && !ME_IsWSpace(s->szData[i-1]); i--) ; - + return i; } diff --git a/reactos/dll/win32/riched20/style.c b/reactos/dll/win32/riched20/style.c index ccaf932e7cd..0530c42d7f2 100644 --- a/reactos/dll/win32/riched20/style.c +++ b/reactos/dll/win32/riched20/style.c @@ -60,8 +60,7 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from) return to; } - assert(from->cbSize >= sizeof(CHARFORMAT2W)); - return from; + return (from->cbSize >= sizeof(CHARFORMAT2W)) ? from : NULL; } void ME_CopyToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from) @@ -100,7 +99,7 @@ CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from) t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */ return to; } - assert(to->cbSize >= sizeof(CHARFORMAT2W)); + assert(to->cbSize >= sizeof(CHARFORMAT2W)); return from; } @@ -113,7 +112,7 @@ void ME_CopyToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from) ME_Style *ME_MakeStyle(CHARFORMAT2W *style) { CHARFORMAT2W styledata; ME_Style *s = ALLOC_OBJ(ME_Style); - + style = ME_ToCF2W(&styledata, style); memset(s, 0, sizeof(ME_Style)); if (style->cbSize <= sizeof(CHARFORMAT2W)) @@ -141,7 +140,7 @@ ME_Style *ME_MakeStyle(CHARFORMAT2W *style) { s->fmt.dwMask |= mask;\ CopyMemory(s->fmt.member, style->member, sizeof(style->member));\ } - + void ME_InitCharFormat2W(CHARFORMAT2W *pFmt) { ZeroMemory(pFmt, sizeof(CHARFORMAT2W)); @@ -167,7 +166,7 @@ ME_Style *ME_ApplyStyle(ME_Style *sSrc, CHARFORMAT2W *style) COPY_STYLE_ITEM(CFM_STYLE, sStyle); COPY_STYLE_ITEM(CFM_UNDERLINETYPE, bUnderlineType); COPY_STYLE_ITEM(CFM_WEIGHT, wWeight); - + s->fmt.dwEffects &= ~(style->dwMask); s->fmt.dwEffects |= style->dwEffects & style->dwMask; s->fmt.dwMask |= style->dwMask; @@ -181,7 +180,7 @@ ME_Style *ME_ApplyStyle(ME_Style *sSrc, CHARFORMAT2W *style) return s; } -void ME_CopyCharFormat(CHARFORMAT2W *pDest, CHARFORMAT2W *pSrc) +void ME_CopyCharFormat(CHARFORMAT2W *pDest, const CHARFORMAT2W *pSrc) { /* using this with non-2W structs is forbidden */ assert(pSrc->cbSize == sizeof(CHARFORMAT2W)); @@ -189,7 +188,7 @@ void ME_CopyCharFormat(CHARFORMAT2W *pDest, CHARFORMAT2W *pSrc) CopyMemory(pDest, pSrc, sizeof(CHARFORMAT2W)); } -static void ME_DumpStyleEffect(char **p, const char *name, CHARFORMAT2W *fmt, int mask) +static void ME_DumpStyleEffect(char **p, const char *name, const CHARFORMAT2W *fmt, int mask) { *p += sprintf(*p, "%-22s%s\n", name, (fmt->dwMask & mask) ? ((fmt->dwEffects & mask) ? "YES" : "no") : "N/A"); } @@ -212,8 +211,8 @@ void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048]) WCHAR *q = pFmt->szFaceName; while(*q) { *p++ = (*q > 255) ? '?' : *q; - q++; - } + q++; + } } else p += sprintf(p, "N/A"); @@ -221,7 +220,7 @@ void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048]) p += sprintf(p, "\nFont size: %d\n", (int)pFmt->yHeight); else p += sprintf(p, "\nFont size: N/A\n"); - + if (pFmt->dwMask & CFM_OFFSET) p += sprintf(p, "Char offset: %d\n", (int)pFmt->yOffset); else @@ -231,7 +230,7 @@ void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048]) p += sprintf(p, "Font charset: %d\n", (int)pFmt->bCharSet); else p += sprintf(p, "Font charset: N/A\n"); - + /* I'm assuming CFM_xxx and CFE_xxx are the same values, fortunately it IS true wrt used flags*/ ME_DumpStyleEffect(&p, "Font bold:", pFmt, CFM_BOLD); ME_DumpStyleEffect(&p, "Font italic:", pFmt, CFM_ITALIC); @@ -253,7 +252,7 @@ void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048]) static void -ME_LogFontFromStyle(HDC hDC, LOGFONTW *lf, ME_Style *s, int nZoomNumerator, int nZoomDenominator) +ME_LogFontFromStyle(HDC hDC, LOGFONTW *lf, const ME_Style *s, int nZoomNumerator, int nZoomDenominator) { int rx, ry; rx = GetDeviceCaps(hDC, LOGPIXELSX); @@ -267,7 +266,7 @@ ME_LogFontFromStyle(HDC hDC, LOGFONTW *lf, ME_Style *s, int nZoomNumerator, int nZoomDenominator = 1; } lf->lfHeight = -s->fmt.yHeight*ry*nZoomNumerator/nZoomDenominator/1440; - + lf->lfWeight = 400; if (s->fmt.dwEffects & s->fmt.dwMask & CFM_BOLD) lf->lfWeight = 700; @@ -286,7 +285,7 @@ ME_LogFontFromStyle(HDC hDC, LOGFONTW *lf, ME_Style *s, int nZoomNumerator, int lf->lfCharSet = s->fmt.bCharSet; } -void ME_CharFormatFromLogFont(HDC hDC, LOGFONTW *lf, CHARFORMAT2W *fmt) +void ME_CharFormatFromLogFont(HDC hDC, const LOGFONTW *lf, CHARFORMAT2W *fmt) { int rx, ry; @@ -308,7 +307,7 @@ void ME_CharFormatFromLogFont(HDC hDC, LOGFONTW *lf, CHARFORMAT2W *fmt) fmt->bCharSet = lf->lfCharSet; } -static BOOL ME_IsFontEqual(LOGFONTW *p1, LOGFONTW *p2) +static BOOL ME_IsFontEqual(const LOGFONTW *p1, const LOGFONTW *p2) { if (memcmp(p1, p2, sizeof(LOGFONTW)-sizeof(p1->lfFaceName))) return FALSE; @@ -325,9 +324,9 @@ HFONT ME_SelectStyleFont(ME_TextEditor *editor, HDC hDC, ME_Style *s) ME_FontCacheItem *item; assert(hDC); assert(s); - + ME_LogFontFromStyle(hDC, &lf, s, editor->nZoomNumerator, editor->nZoomDenominator); - + for (i=0; ipFontCache[i].nAge++; for (i=0, nEmpty=-1, nAge=0; imember.run.style); diff --git a/reactos/dll/win32/riched20/undo.c b/reactos/dll/win32/riched20/undo.c index 403a291b88a..d277e262192 100644 --- a/reactos/dll/win32/riched20/undo.c +++ b/reactos/dll/win32/riched20/undo.c @@ -25,10 +25,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit); void ME_EmptyUndoStack(ME_TextEditor *editor) { ME_DisplayItem *p, *pNext; - + if (editor->nUndoMode == umIgnore) return; - + TRACE("Emptying undo stack\n"); p = editor->pUndoStack; @@ -36,19 +36,19 @@ void ME_EmptyUndoStack(ME_TextEditor *editor) editor->nUndoStackSize = 0; while(p) { pNext = p->next; - ME_DestroyDisplayItem(p); + ME_DestroyDisplayItem(p); p = pNext; - } + } p = editor->pRedoStack; editor->pRedoStack = NULL; while(p) { pNext = p->next; - ME_DestroyDisplayItem(p); + ME_DestroyDisplayItem(p); p = pNext; - } + } } -ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, ME_DisplayItem *pdi) { +ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_DisplayItem *pdi) { if (editor->nUndoMode == umIgnore) return NULL; else if (editor->nUndoLimit == 0) @@ -82,7 +82,7 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, ME_DisplayIte pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2); pItem->member.para.pFmt->cbSize = sizeof(PARAFORMAT2); pItem->member.para.pFmt->dwMask = 0; - + break; default: assert(0 == "AddUndoItem, unsupported item type"); @@ -105,7 +105,7 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, ME_DisplayIte else editor->pUndoStackBottom = pItem; editor->pUndoStack = pItem; - + if (editor->nUndoStackSize > editor->nUndoLimit) { /* remove oldest undo from stack */ ME_DisplayItem *p = editor->pUndoStackBottom; @@ -150,9 +150,9 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, ME_DisplayIte void ME_CommitUndo(ME_TextEditor *editor) { if (editor->nUndoMode == umIgnore) return; - + assert(editor->nUndoMode == umAddToUndo); - + /* no transactions, no need to commit */ if (!editor->pUndoStack) return; @@ -160,7 +160,7 @@ void ME_CommitUndo(ME_TextEditor *editor) { /* no need to commit empty transactions */ if (editor->pUndoStack->type == diUndoEndTransaction) return; - + ME_AddUndoItem(editor, diUndoEndTransaction, NULL); ME_SendSelChange(editor); } @@ -232,18 +232,18 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) void ME_Undo(ME_TextEditor *editor) { ME_DisplayItem *p; ME_UndoMode nMode = editor->nUndoMode; - + if (editor->nUndoMode == umIgnore) return; assert(nMode == umAddToUndo || nMode == umIgnore); - + /* no undo items ? */ if (!editor->pUndoStack) return; - + /* watch out for uncommited transactions ! */ assert(editor->pUndoStack->type == diUndoEndTransaction); - + editor->nUndoMode = umAddToRedo; p = editor->pUndoStack->next; ME_DestroyDisplayItem(editor->pUndoStack); @@ -265,18 +265,18 @@ void ME_Undo(ME_TextEditor *editor) { void ME_Redo(ME_TextEditor *editor) { ME_DisplayItem *p; ME_UndoMode nMode = editor->nUndoMode; - + assert(nMode == umAddToUndo || nMode == umIgnore); - + if (editor->nUndoMode == umIgnore) return; /* no redo items ? */ if (!editor->pRedoStack) return; - + /* watch out for uncommited transactions ! */ assert(editor->pRedoStack->type == diUndoEndTransaction); - + editor->nUndoMode = umAddBackToUndo; p = editor->pRedoStack->next; ME_DestroyDisplayItem(editor->pRedoStack); diff --git a/reactos/dll/win32/riched20/wrap.c b/reactos/dll/win32/riched20/wrap.c index e39297dc096..946aa730e43 100644 --- a/reactos/dll/win32/riched20/wrap.c +++ b/reactos/dll/win32/riched20/wrap.c @@ -51,7 +51,7 @@ static void ME_BeginRow(ME_WrapContext *wc) wc->pt.x = 0; } -void ME_InsertRowStart(ME_WrapContext *wc, ME_DisplayItem *pEnd) +void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd) { ME_DisplayItem *p, *row, *para; int ascent = 0, descent = 0, width=0, shift = 0, align = 0; @@ -429,11 +429,13 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { ME_InitContext(&c, editor, hDC); c.pt.x = 0; c.pt.y = 0; + editor->nHeight = 0; item = editor->pBuffer->pFirst->next; while(item != editor->pBuffer->pLast) { BOOL bRedraw = FALSE; assert(item->type == diParagraph); + editor->nHeight = max(editor->nHeight, item->member.para.nYPos); if ((item->member.para.nFlags & MEPF_REWRAP) || (item->member.para.nYPos != c.pt.y)) bRedraw = TRUE; @@ -457,12 +459,12 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { } editor->sizeWindow.cx = c.rcView.right-c.rcView.left; editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top; - + editor->nTotalLength = c.pt.y; ME_DestroyContext(&c); ReleaseDC(hWnd, hDC); - + if (bModified || editor->nTotalLength < editor->nLastTotalLength) ME_InvalidateMarkedParagraphs(editor); return bModified; @@ -476,11 +478,11 @@ void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) { if (editor->bRedraw) { RECT rc = c.rcView; - int ofs = ME_GetYScrollPos(editor); - + int ofs = ME_GetYScrollPos(editor); + ME_DisplayItem *item = editor->pBuffer->pFirst; while(item != editor->pBuffer->pLast) { - if (item->member.para.nFlags & MEPF_REPAINT) { + if (item->member.para.nFlags & MEPF_REPAINT) { rc.top = item->member.para.nYPos - ofs; rc.bottom = item->member.para.nYPos + item->member.para.nHeight - ofs; InvalidateRect(editor->hWnd, &rc, TRUE); @@ -517,7 +519,7 @@ ME_SendRequestResize(ME_TextEditor *editor, BOOL force) info.nmhdr.code = EN_REQUESTRESIZE; info.rc = rc; info.rc.bottom = editor->nTotalLength; - + SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, info.nmhdr.idFrom, (LPARAM)&info); } diff --git a/reactos/dll/win32/riched20/writer.c b/reactos/dll/win32/riched20/writer.c index dee72e372bc..68088f7a15c 100644 --- a/reactos/dll/win32/riched20/writer.c +++ b/reactos/dll/win32/riched20/writer.c @@ -25,7 +25,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit); static BOOL -ME_StreamOutRTFText(ME_OutStream *pStream, WCHAR *text, LONG nChars); +ME_StreamOutRTFText(ME_OutStream *pStream, const WCHAR *text, LONG nChars); static ME_OutStream* @@ -60,7 +60,7 @@ ME_StreamOutFlush(ME_OutStream *pStream) pStream->pos - nStart, &nWritten); TRACE("error=%u written=%u\n", stream->dwError, nWritten); if (nWritten > (pStream->pos - nStart) || nWritten<0) { - FIXME("Invalid returned written size *pcb: 0x%x (%d) instead of %d\n", + FIXME("Invalid returned written size *pcb: 0x%x (%d) instead of %d\n", (unsigned)nWritten, nWritten, nRemaining); nWritten = nRemaining; } @@ -92,7 +92,7 @@ ME_StreamOutMove(ME_OutStream *pStream, const char *buffer, int len) int space = STREAMOUT_BUFFER_SIZE - pStream->pos; int fit = min(space, len); - TRACE("%u:%u:%.*s\n", pStream->pos, fit, fit, buffer); + TRACE("%u:%u:%s\n", pStream->pos, fit, debugstr_an(buffer,fit)); memmove(pStream->buffer + pStream->pos, buffer, fit); len -= fit; buffer += fit; @@ -116,7 +116,7 @@ ME_StreamOutPrint(ME_OutStream *pStream, const char *format, ...) va_start(valist, format); len = vsnprintf(string, sizeof(string), format, valist); va_end(valist); - + return ME_StreamOutMove(pStream, string, len); } @@ -128,10 +128,10 @@ ME_StreamOutRTFHeader(ME_OutStream *pStream, int dwFormat) UINT nCodePage; LANGID language; BOOL success; - + if (dwFormat & SF_USECODEPAGE) { CPINFOEXW info; - + switch (HIWORD(dwFormat)) { case CP_ACP: cCharSet = "ansi"; @@ -177,10 +177,10 @@ ME_StreamOutRTFHeader(ME_OutStream *pStream, int dwFormat) return FALSE; pStream->nDefaultCodePage = nCodePage; - + /* FIXME: This should be a document property */ /* TODO: handle SFF_PLAINRTF */ - language = GetUserDefaultLangID(); + language = GetUserDefaultLangID(); if (!ME_StreamOutPrint(pStream, "\\deff0\\deflang%u\\deflangfe%u", language, language)) return FALSE; @@ -192,12 +192,12 @@ ME_StreamOutRTFHeader(ME_OutStream *pStream, int dwFormat) static BOOL -ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun, ME_DisplayItem *pLastRun) +ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun, const ME_DisplayItem *pLastRun) { ME_DisplayItem *item = pFirstRun; ME_FontTableItem *table = pStream->fonttbl; int i; - + do { CHARFORMAT2W *fmt = &item->member.run.style->fmt; COLORREF crColor; @@ -205,7 +205,7 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun, if (fmt->dwMask & CFM_FACE) { WCHAR *face = fmt->szFaceName; BYTE bCharSet = (fmt->dwMask & CFM_CHARSET) ? fmt->bCharSet : DEFAULT_CHARSET; - + for (i = 0; i < pStream->nFontTblLen; i++) if (table[i].bCharSet == bCharSet && (table[i].szFaceName == face || !lstrcmpW(table[i].szFaceName, face))) @@ -216,7 +216,7 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun, pStream->nFontTblLen++; } } - + if (fmt->dwMask & CFM_COLOR && !(fmt->dwEffects & CFE_AUTOCOLOR)) { crColor = fmt->crTextColor; for (i = 1; i < pStream->nColorTblLen; i++) @@ -242,10 +242,10 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun, break; item = ME_FindItemFwd(item, diRun); } while (item); - + if (!ME_StreamOutPrint(pStream, "{\\fonttbl")) return FALSE; - + for (i = 0; i < pStream->nFontTblLen; i++) { if (table[i].bCharSet != DEFAULT_CHARSET) { if (!ME_StreamOutPrint(pStream, "{\\f%u\\fcharset%u ", i, table[i].bCharSet)) @@ -282,7 +282,7 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun, static BOOL -ME_StreamOutRTFParaProps(ME_OutStream *pStream, ME_DisplayItem *para) +ME_StreamOutRTFParaProps(ME_OutStream *pStream, const ME_DisplayItem *para) { PARAFORMAT2 *fmt = para->member.para.pFmt; char props[STREAMOUT_BUFFER_SIZE] = ""; @@ -291,7 +291,7 @@ ME_StreamOutRTFParaProps(ME_OutStream *pStream, ME_DisplayItem *para) if (para->member.para.pCells) { ME_TableCell *cell = para->member.para.pCells; - + if (!ME_StreamOutPrint(pStream, "\\trowd")) return FALSE; do { @@ -302,19 +302,19 @@ ME_StreamOutRTFParaProps(ME_OutStream *pStream, ME_DisplayItem *para) } while (cell); props[0] = '\0'; } - + /* TODO: Don't emit anything if the last PARAFORMAT2 is inherited */ if (!ME_StreamOutPrint(pStream, "\\pard")) return FALSE; if (para->member.para.bTable) strcat(props, "\\intbl"); - + /* TODO: PFM_BORDER. M$ does not emit any keywords for these properties, and * when streaming border keywords in, PFM_BORDER is set, but wBorder field is * set very different from the documentation. * (Tested with RichEdit 5.50.25.0601) */ - + if (fmt->dwMask & PFM_ALIGNMENT) { switch (fmt->wAlignment) { case PFA_LEFT: @@ -331,7 +331,7 @@ ME_StreamOutRTFParaProps(ME_OutStream *pStream, ME_DisplayItem *para) break; } } - + if (fmt->dwMask & PFM_LINESPACING) { /* FIXME: MSDN says that the bLineSpacingRule field is controlled by the * PFM_SPACEAFTER flag. Is that true? I don't believe so. */ @@ -375,7 +375,7 @@ ME_StreamOutRTFParaProps(ME_OutStream *pStream, ME_DisplayItem *para) strcat(props, "\\sbys"); if (fmt->dwMask & PFM_TABLE && fmt->dwMask & PFE_TABLE) strcat(props, "\\intbl"); - + if (fmt->dwMask & PFM_OFFSET) sprintf(props + strlen(props), "\\li%d", fmt->dxOffset); if (fmt->dwMask & PFM_OFFSETINDENT || fmt->dwMask & PFM_STARTINDENT) @@ -391,7 +391,7 @@ ME_StreamOutRTFParaProps(ME_OutStream *pStream, ME_DisplayItem *para) if (fmt->dwMask & PFM_TABSTOPS) { static const char * const leader[6] = { "", "\\tldot", "\\tlhyph", "\\tlul", "\\tlth", "\\tleq" }; - + for (i = 0; i < fmt->cTabCount; i++) { switch ((fmt->rgxTabs[i] >> 24) & 0xF) { case 1: @@ -412,8 +412,8 @@ ME_StreamOutRTFParaProps(ME_OutStream *pStream, ME_DisplayItem *para) sprintf(props+strlen(props), "\\tx%d", fmt->rgxTabs[i]&0x00FFFFFF); } } - - + + if (fmt->dwMask & PFM_SHADING) { static const char * const style[16] = { "", "\\bgdkhoriz", "\\bgdkvert", "\\bgdkfdiag", "\\bgdkbdiag", "\\bgdkcross", "\\bgdkdcross", @@ -427,7 +427,7 @@ ME_StreamOutRTFParaProps(ME_OutStream *pStream, ME_DisplayItem *para) sprintf(props + strlen(props), "\\cfpat%d\\cbpat%d", (fmt->wShadingStyle >> 4) & 0xF, (fmt->wShadingStyle >> 8) & 0xF); } - + if (*props && !ME_StreamOutPrint(pStream, props)) return FALSE; @@ -540,10 +540,10 @@ ME_StreamOutRTFCharProps(ME_OutStream *pStream, CHARFORMAT2W *fmt) strcat(props, "\\ul"); } /* FIXME: How to emit CFM_WEIGHT? */ - + if (fmt->dwMask & CFM_FACE || fmt->dwMask & CFM_CHARSET) { WCHAR *szFaceName; - + if (fmt->dwMask & CFM_FACE) szFaceName = fmt->szFaceName; else @@ -579,7 +579,7 @@ ME_StreamOutRTFCharProps(ME_OutStream *pStream, CHARFORMAT2W *fmt) static BOOL -ME_StreamOutRTFText(ME_OutStream *pStream, WCHAR *text, LONG nChars) +ME_StreamOutRTFText(ME_OutStream *pStream, const WCHAR *text, LONG nChars) { char buffer[STREAMOUT_BUFFER_SIZE]; int pos = 0; @@ -587,7 +587,7 @@ ME_StreamOutRTFText(ME_OutStream *pStream, WCHAR *text, LONG nChars) if (nChars == -1) nChars = lstrlenW(text); - + while (nChars) { /* In UTF-8 mode, font charsets are not used. */ if (pStream->nDefaultCodePage == CP_UTF8) { @@ -650,21 +650,21 @@ static BOOL ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream, int nStart, int nChars, int dwFormat) { ME_DisplayItem *p, *pEnd, *pPara; - int nOffset, nEndLen; - + int nOffset, nEndLen; + ME_RunOfsFromCharOfs(editor, nStart, &p, &nOffset); ME_RunOfsFromCharOfs(editor, nStart+nChars, &pEnd, &nEndLen); - + pPara = ME_GetParagraph(p); - + if (!ME_StreamOutRTFHeader(pStream, dwFormat)) return FALSE; if (!ME_StreamOutRTFFontAndColorTbl(pStream, p, pEnd)) return FALSE; - + /* TODO: stylesheet table */ - + /* FIXME: maybe emit something smarter for the generator? */ if (!ME_StreamOutPrint(pStream, "{\\*\\generator Wine Riched20 2.0.????;}")) return FALSE; @@ -713,13 +713,13 @@ ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream, int nStart, int nC nChars--; } else { int nEnd; - + if (!ME_StreamOutPrint(pStream, "{")) return FALSE; TRACE("style %p\n", p->member.run.style); if (!ME_StreamOutRTFCharProps(pStream, &p->member.run.style->fmt)) return FALSE; - + nEnd = (p == pEnd) ? nEndLen : ME_StrLen(p->member.run.strText); if (!ME_StreamOutRTFText(pStream, p->member.run.strText->szData + nOffset, nEnd - nOffset)) return FALSE; @@ -754,12 +754,12 @@ ME_StreamOutText(ME_TextEditor *editor, ME_OutStream *pStream, int nStart, int n if (!item) return FALSE; - + if (dwFormat & SF_USECODEPAGE) nCodePage = HIWORD(dwFormat); /* TODO: Handle SF_TEXTIZED */ - + while (success && nChars && item) { nLen = ME_StrLen(item->member.run.strText) - nStart; if (nLen > nChars) @@ -767,7 +767,7 @@ ME_StreamOutText(ME_TextEditor *editor, ME_OutStream *pStream, int nStart, int n if (item->member.run.nFlags & MERF_ENDPARA) { static const WCHAR szEOL[2] = { '\r', '\n' }; - + if (dwFormat & SF_UNICODE) success = ME_StreamOutMove(pStream, (const char *)szEOL, sizeof(szEOL)); else @@ -791,14 +791,14 @@ ME_StreamOutText(ME_TextEditor *editor, ME_OutStream *pStream, int nStart, int n success = ME_StreamOutMove(pStream, buffer, nSize); } } - + nChars -= nLen; if (editor->bEmulateVersion10 && nChars && item->member.run.nFlags & MERF_ENDPARA) nChars--; nStart = 0; item = ME_FindItemFwd(item, diRun); } - + FREE_OBJ(buffer); return success; }