diff --git a/reactos/dll/win32/riched20/caret.c b/reactos/dll/win32/riched20/caret.c index ab44dac12ff..461ad005cc7 100644 --- a/reactos/dll/win32/riched20/caret.c +++ b/reactos/dll/win32/riched20/caret.c @@ -57,7 +57,7 @@ int ME_GetTextLengthEx(ME_TextEditor *editor, const GETTEXTLENGTHEX *how) length = ME_GetTextLength(editor); - if ((GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_MULTILINE) + if ((editor->styleFlags & ES_MULTILINE) && (how->flags & GTL_USECRLF) && !editor->bEmulateVersion10) /* Ignore GTL_USECRLF flag in 1.0 emulation */ length += editor->nParagraphs - 1; @@ -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) { ME_DisplayItem *prev = ME_FindItemBack(pCursorRun, diRunOrParagraph); @@ -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); @@ -214,9 +214,9 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor, } *height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent; - *x = c.rcView.left + run->member.run.pt.x + sz.cx; + *x = c.rcView.left + run->member.run.pt.x + sz.cx - editor->horz_si.nPos; *y = c.rcView.top + para->member.para.pt.y + row->member.row.nBaseline - + run->member.run.pt.y - pSizeRun->member.run.nAscent - ME_GetYScrollPos(editor); + + run->member.run.pt.y - pSizeRun->member.run.nAscent - editor->vert_si.nPos; ME_DestroyContext(&c, editor->hWnd); return; } @@ -782,7 +782,7 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) } -void +static void ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType) { /* pCursor[0] is the end of the selection @@ -1025,7 +1025,8 @@ int ME_CharFromPos(ME_TextEditor *editor, int x, int y, BOOL *isExact) if (isExact) *isExact = FALSE; return -1; } - y += ME_GetYScrollPos(editor); + x += editor->horz_si.nPos; + y += editor->vert_si.nPos; bResult = ME_FindPixelPos(editor, x, y, &cursor, NULL); if (isExact) *isExact = bResult; return (ME_GetParagraph(cursor.pRun)->member.para.nCharOfs @@ -1099,10 +1100,11 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) ME_Cursor tmp_cursor; int is_selection = 0; BOOL is_shift; - + editor->nUDArrowX = -1; - - y += ME_GetYScrollPos(editor); + + x += editor->horz_si.nPos; + y += editor->vert_si.nPos; tmp_cursor = editor->pCursors[0]; is_selection = ME_IsSelection(editor); @@ -1161,10 +1163,11 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) void ME_MouseMove(ME_TextEditor *editor, int x, int y) { ME_Cursor tmp_cursor; - + if (editor->nSelectionType == stDocument) return; - y += ME_GetYScrollPos(editor); + x += editor->horz_si.nPos; + y += editor->vert_si.nPos; tmp_cursor = editor->pCursors[0]; /* FIXME: do something with the return value of ME_FindPixelPos */ @@ -1179,9 +1182,9 @@ void ME_MouseMove(ME_TextEditor *editor, int x, int y) { /* The scroll the cursor towards the other end, since it was the one * extended by ME_ExtendAnchorSelection */ - ME_EnsureVisible(editor, editor->pCursors[1].pRun); + ME_EnsureVisible(editor, &editor->pCursors[1]); } else { - ME_EnsureVisible(editor, editor->pCursors[0].pRun); + ME_EnsureVisible(editor, &editor->pCursors[0]); } ME_InvalidateSelection(editor); @@ -1335,105 +1338,119 @@ ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs) assert(pCursor->pRun->type == diRun); } - static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor) { - ME_DisplayItem *pRun = pCursor->pRun; - 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.pt.y; - yprev = ys = y = yp + p->member.row.pt.y; - yd = y - editor->sizeWindow.cy; - pLast = p; - - do { - p = ME_FindItemBack(p, diStartRowOrParagraph); - if (!p) - break; - if (p->type == diParagraph) { /* crossing paragraphs */ - if (p->member.para.prev_para == NULL) - break; - yp = p->member.para.prev_para->member.para.pt.y; - continue; - } - y = yp + p->member.row.pt.y; - if (y < yd) - break; + ME_DisplayItem *p = ME_FindItemFwd(editor->pBuffer->pFirst, diStartRow); + + if (editor->vert_si.nPos < p->member.row.nHeight) + { + pCursor->pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun); + pCursor->nOffset = 0; + editor->bCaretAtEnd = FALSE; + /* Native clears seems to clear this x value on page up at the top + * of the text, but not on page down at the end of the text. + * Doesn't make sense, but we try to be bug for bug compatible. */ + editor->nUDArrowX = -1; + } else { + ME_DisplayItem *pRun = pCursor->pRun; + ME_DisplayItem *pLast; + int x, y, ys, yd, yp, yprev; + int yOldScrollPos = editor->vert_si.nPos; + + 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.pt.y; + yprev = ys = y = yp + p->member.row.pt.y; + + ME_ScrollUp(editor, editor->sizeWindow.cy); + /* Only move the cursor by the amount scrolled. */ + yd = y + editor->vert_si.nPos - yOldScrollPos; 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) - { - ME_EnsureVisible(editor, ME_FindItemFwd(editor->pBuffer->pFirst, diRun)); - ME_Repaint(editor); - } - else - { - ME_ScrollUp(editor, ys-yprev); + + do { + p = ME_FindItemBack(p, diStartRowOrParagraph); + if (!p) + break; + if (p->type == diParagraph) { /* crossing paragraphs */ + if (p->member.para.prev_para == NULL) + break; + yp = p->member.para.prev_para->member.para.pt.y; + continue; + } + y = yp + p->member.row.pt.y; + if (y < yd) + break; + pLast = p; + yprev = y; + } while(1); + + pCursor->pRun = ME_FindRunInRow(editor, pLast, x, &pCursor->nOffset, + &editor->bCaretAtEnd); } assert(pCursor->pRun); assert(pCursor->pRun->type == diRun); } -/* 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)). */ - static void ME_ArrowPageDown(ME_TextEditor *editor, ME_Cursor *pCursor) { - ME_DisplayItem *pRun = pCursor->pRun; - ME_DisplayItem *pLast, *p; - int x, y, ys, yd, yp, yprev; - ME_Cursor tmp_curs = *pCursor; - + ME_DisplayItem *pLast; + int x, y; + + /* Find y position of the last row */ + pLast = editor->pBuffer->pLast; + y = pLast->member.para.prev_para->member.para.pt.y + + ME_FindItemBack(pLast, diStartRow)->member.row.pt.y; + 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.pt.y; - yprev = ys = y = yp + p->member.row.pt.y; - yd = y + editor->sizeWindow.cy; - pLast = p; - - do { - p = ME_FindItemFwd(p, diStartRowOrParagraph); - if (!p) - break; - if (p->type == diParagraph) { - yp = p->member.para.pt.y; - continue; - } - y = yp + p->member.row.pt.y; - if (y >= yd) - break; + + if (editor->vert_si.nPos >= y - editor->sizeWindow.cy) + { + pCursor->pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun); + pCursor->nOffset = 0; + editor->bCaretAtEnd = FALSE; + } else { + ME_DisplayItem *pRun = pCursor->pRun; + ME_DisplayItem *p; + int ys, yd, yp, yprev; + int yOldScrollPos = editor->vert_si.nPos; + + 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.pt.y; + yprev = ys = y = yp + p->member.row.pt.y; + + /* For native richedit controls: + * v1.0 - v3.1 can only scroll down as far as the scrollbar lets us + * v4.1 can scroll past this position here. */ + ME_ScrollDown(editor, editor->sizeWindow.cy); + /* Only move the cursor by the amount scrolled. */ + yd = y + editor->vert_si.nPos - yOldScrollPos; 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) - { - ME_EnsureVisible(editor, ME_FindItemBack(editor->pBuffer->pLast, diRun)); - ME_Repaint(editor); - } - else - { - ME_ScrollUp(editor,ys-yprev); + + do { + p = ME_FindItemFwd(p, diStartRowOrParagraph); + if (!p) + break; + if (p->type == diParagraph) { + yp = p->member.para.pt.y; + continue; + } + y = yp + p->member.row.pt.y; + if (y >= yd) + break; + pLast = p; + yprev = y; + } while(1); + + pCursor->pRun = ME_FindRunInRow(editor, pLast, x, &pCursor->nOffset, + &editor->bCaretAtEnd); } assert(pCursor->pRun); assert(pCursor->pRun->type == diRun); @@ -1522,32 +1539,6 @@ static int ME_GetSelCursor(ME_TextEditor *editor, int dir) return 1; } -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 ! */ - editor->pCursors[1] = editor->pCursors[0]; - if (memcmp(pTempCursor, &old_anchor, sizeof(ME_Cursor))) { - return TRUE; - } - return FALSE; - } - else - { - if (!memcmp(pTempCursor, &editor->pCursors[1], sizeof(ME_Cursor))) /* starting selection */ - { - editor->pCursors[1] = *pTempCursor; - return TRUE; - } - } - - ME_Repaint(editor); - return TRUE; -} - void ME_DeleteSelection(ME_TextEditor *editor) { int from, to; @@ -1594,7 +1585,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); switch(nVKey) { case VK_LEFT: @@ -1631,22 +1622,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); ME_ShowCaret(editor); ME_SendSelChange(editor); return success; diff --git a/reactos/dll/win32/riched20/editor.c b/reactos/dll/win32/riched20/editor.c index b5a69f78910..b67ca6045dd 100644 --- a/reactos/dll/win32/riched20/editor.c +++ b/reactos/dll/win32/riched20/editor.c @@ -65,7 +65,7 @@ - EM_GETREDONAME 2.0 + EM_GETSEL + EM_GETSELTEXT (ANSI&Unicode) - + EM_GETSCROLLPOS 3.0 (only Y value valid) + + EM_GETSCROLLPOS 3.0 ! - EM_GETTHUMB + EM_GETTEXTEX 2.0 + EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented) @@ -137,12 +137,14 @@ + WM_GETDLGCODE (the current implementation is incomplete) + WM_GETTEXT (ANSI&Unicode) + WM_GETTEXTLENGTH (ANSI version sucks) + + WM_HSCROLL + WM_PASTE + WM_SETFONT + WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode - WM_STYLECHANGING - WM_STYLECHANGED (things like read-only flag) + WM_UNICHAR + + WM_VSCROLL Notifications @@ -184,7 +186,7 @@ - ES_VERTICAL - ES_WANTRETURN (don't know how to do WM_GETDLGCODE part) - WS_SETFONT - - WS_HSCROLL + + WS_HSCROLL + WS_VSCROLL */ @@ -197,7 +199,6 @@ * - pictures/OLE objects (not just smiling faces that lack API support ;-) ) * - COM interface (looks like a major pain in the TODO list) * - calculate heights of pictures (half-done) - * - horizontal scrolling (not even started) * - hysteresis during wrapping (related to scrollbars appearing/disappearing) * - find/replace * - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible) @@ -240,6 +241,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit); static BOOL ME_RegisterEditorClass(HINSTANCE); +static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_max); static const WCHAR RichEdit20W[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0}; static const WCHAR RichEdit50W[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0}; @@ -2114,6 +2116,42 @@ ME_FilterEvent(ME_TextEditor *editor, UINT msg, WPARAM* wParam, LPARAM* lParam) return TRUE; } +static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor) +{ + ME_DisplayItem * startPara, * endPara; + ME_DisplayItem * item; + int dummy; + int from, to; + + ME_GetSelection(editor, &from, &to); + if (from > to) from ^= to, to ^=from, from ^= to; + startPara = NULL; endPara = NULL; + + /* Find paragraph previous to the one that contains start cursor */ + item = ME_FindItemAtOffset(editor, diRun, from, &dummy); + if (item) { + startPara = ME_FindItemBack(item, diParagraph); + item = ME_FindItemBack(startPara, diParagraph); + if (item) startPara = item; + } + + /* Find paragraph that contains end cursor */ + item = ME_FindItemAtOffset(editor, diRun, to, &dummy); + if (item) { + endPara = ME_FindItemFwd(item, diParagraph); + } + + if (startPara && endPara) { + ME_UpdateLinkAttribute(editor, + startPara->member.para.nCharOfs, + endPara->member.para.nCharOfs); + } else if (startPara) { + ME_UpdateLinkAttribute(editor, + startPara->member.para.nCharOfs, + -1); + } +} + static BOOL ME_KeyDown(ME_TextEditor *editor, WORD nKey) { @@ -2142,7 +2180,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) case VK_DELETE: editor->nUDArrowX = -1; /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */ - if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) + if (editor->styleFlags & ES_READONLY) return FALSE; if (ME_IsSelection(editor)) { @@ -2177,6 +2215,121 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) ME_UpdateRepaint(editor); ME_SendRequestResize(editor, FALSE); return TRUE; + case VK_RETURN: + if (editor->styleFlags & ES_MULTILINE) + { + ME_Cursor cursor = editor->pCursors[0]; + ME_DisplayItem *para = ME_GetParagraph(cursor.pRun); + int from, to; + const WCHAR endl = '\r'; + ME_Style *style; + + if (editor->styleFlags & ES_READONLY) { + MessageBeep(MB_ICONERROR); + return TRUE; + } + + ME_GetSelection(editor, &from, &to); + if (editor->nTextLimit > ME_GetTextLength(editor) - (to-from)) + { + if (!editor->bEmulateVersion10) { /* v4.1 */ + if (para->member.para.nFlags & MEPF_ROWEND) { + /* Add a new table row after this row. */ + para = ME_AppendTableRow(editor, para); + para = para->member.para.next_para; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[0].nOffset = 0; + editor->pCursors[1] = editor->pCursors[0]; + ME_CommitUndo(editor); + ME_CheckTablesForCorruption(editor); + ME_UpdateRepaint(editor); + return TRUE; + } + else if (para == ME_GetParagraph(editor->pCursors[1].pRun) && + cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 && + para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART && + !para->member.para.prev_para->member.para.nCharOfs) + { + /* Insert a newline before the table. */ + para = para->member.para.prev_para; + para->member.para.nFlags &= ~MEPF_ROWSTART; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[1] = editor->pCursors[0]; + ME_InsertTextFromCursor(editor, 0, &endl, 1, + editor->pCursors[0].pRun->member.run.style); + para = editor->pBuffer->pFirst->member.para.next_para; + ME_SetDefaultParaFormat(para->member.para.pFmt); + para->member.para.nFlags = MEPF_REWRAP; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[1] = editor->pCursors[0]; + para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART; + ME_CommitCoalescingUndo(editor); + ME_CheckTablesForCorruption(editor); + ME_UpdateRepaint(editor); + return TRUE; + } + } else { /* v1.0 - 3.0 */ + ME_DisplayItem *para = ME_GetParagraph(cursor.pRun); + if (ME_IsInTable(para)) + { + if (cursor.pRun->member.run.nFlags & MERF_ENDPARA) + { + if (from == to) { + ME_ContinueCoalescingTransaction(editor); + para = ME_AppendTableRow(editor, para); + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[0].nOffset = 0; + editor->pCursors[1] = editor->pCursors[0]; + ME_CommitCoalescingUndo(editor); + ME_UpdateRepaint(editor); + return TRUE; + } + } else { + ME_ContinueCoalescingTransaction(editor); + if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 && + !ME_IsInTable(para->member.para.prev_para)) + { + /* Insert newline before table */ + cursor.pRun = ME_FindItemBack(para, diRun); + if (cursor.pRun) + editor->pCursors[0].pRun = cursor.pRun; + editor->pCursors[0].nOffset = 0; + editor->pCursors[1] = editor->pCursors[0]; + ME_InsertTextFromCursor(editor, 0, &endl, 1, + editor->pCursors[0].pRun->member.run.style); + } else { + editor->pCursors[1] = editor->pCursors[0]; + para = ME_AppendTableRow(editor, para); + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[0].nOffset = 0; + editor->pCursors[1] = editor->pCursors[0]; + } + ME_CommitCoalescingUndo(editor); + ME_UpdateRepaint(editor); + return TRUE; + } + } + } + + style = ME_GetInsertStyle(editor, 0); + ME_SaveTempStyle(editor); + ME_ContinueCoalescingTransaction(editor); + if (shift_is_down) + ME_InsertEndRowFromCursor(editor, 0); + else + ME_InsertTextFromCursor(editor, 0, &endl, 1, style); + ME_ReleaseStyle(style); + ME_CommitCoalescingUndo(editor); + SetCursor(NULL); + + if (editor->AutoURLDetect_bEnable) + ME_UpdateSelectionLinkAttribute(editor); + + ME_UpdateRepaint(editor); + } + return TRUE; + } + break; case 'A': if (ctrl_is_down) { @@ -2258,23 +2411,21 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode, MultiByteToWideChar(CP_ACP, 0, &charA, 1, &wstr, 1); } - if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) { + if (editor->styleFlags & ES_READONLY) { MessageBeep(MB_ICONERROR); return 0; /* FIXME really 0 ? */ } - if (((unsigned)wstr)>=' ' - || (wstr=='\r' && (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_MULTILINE)) - || wstr=='\t') { + if ((unsigned)wstr >= ' ' || wstr == '\t') + { ME_Cursor cursor = editor->pCursors[0]; ME_DisplayItem *para = ME_GetParagraph(cursor.pRun); int from, to; BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000; ME_GetSelection(editor, &from, &to); - if (wstr=='\t' + if (wstr == '\t' && /* v4.1 allows tabs to be inserted with ctrl key down */ - && !(ctrl_is_down && !editor->bEmulateVersion10) - ) + !(ctrl_is_down && !editor->bEmulateVersion10)) { ME_DisplayItem *para; BOOL bSelectedRow = FALSE; @@ -2296,18 +2447,7 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode, } } else if (!editor->bEmulateVersion10) { /* v4.1 */ if (para->member.para.nFlags & MEPF_ROWEND) { - if (wstr=='\r') { - /* Add a new table row after this row. */ - para = ME_AppendTableRow(editor, para); - para = para->member.para.next_para; - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[0].nOffset = 0; - editor->pCursors[1] = editor->pCursors[0]; - ME_CommitUndo(editor); - ME_CheckTablesForCorruption(editor); - ME_UpdateRepaint(editor); - return 0; - } else if (from == to) { + if (from == to) { para = para->member.para.next_para; if (para->member.para.nFlags & MEPF_ROWSTART) para = para->member.para.next_para; @@ -2316,76 +2456,14 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode, editor->pCursors[1] = editor->pCursors[0]; } } - else if (para == ME_GetParagraph(editor->pCursors[1].pRun) && - cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 && - para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART && - !para->member.para.prev_para->member.para.nCharOfs) - { - /* Insert a newline before the table. */ - WCHAR endl = '\r'; - para = para->member.para.prev_para; - para->member.para.nFlags &= ~MEPF_ROWSTART; - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[1] = editor->pCursors[0]; - ME_InsertTextFromCursor(editor, 0, &endl, 1, - editor->pCursors[0].pRun->member.run.style); - para = editor->pBuffer->pFirst->member.para.next_para; - ME_SetDefaultParaFormat(para->member.para.pFmt); - para->member.para.nFlags = MEPF_REWRAP; - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[1] = editor->pCursors[0]; - para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART; - ME_CommitCoalescingUndo(editor); - ME_CheckTablesForCorruption(editor); - ME_UpdateRepaint(editor); - return 0; - } } else { /* v1.0 - 3.0 */ - ME_DisplayItem *para = ME_GetParagraph(cursor.pRun); - if (ME_IsInTable(cursor.pRun)) + if (ME_IsInTable(cursor.pRun) && + cursor.pRun->member.run.nFlags & MERF_ENDPARA && + from == to) { - if (cursor.pRun->member.run.nFlags & MERF_ENDPARA) - { - if (from == to) { - if (wstr=='\r') { - ME_ContinueCoalescingTransaction(editor); - para = ME_AppendTableRow(editor, para); - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[0].nOffset = 0; - editor->pCursors[1] = editor->pCursors[0]; - ME_CommitCoalescingUndo(editor); - ME_UpdateRepaint(editor); - } else { - /* Text should not be inserted at the end of the table. */ - MessageBeep(-1); - } - return 0; - } - } else if (wstr == '\r') { - ME_ContinueCoalescingTransaction(editor); - if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 && - !ME_IsInTable(para->member.para.prev_para)) - { - /* Insert newline before table */ - WCHAR endl = '\r'; - cursor.pRun = ME_FindItemBack(para, diRun); - if (cursor.pRun) - editor->pCursors[0].pRun = cursor.pRun; - editor->pCursors[0].nOffset = 0; - editor->pCursors[1] = editor->pCursors[0]; - ME_InsertTextFromCursor(editor, 0, &endl, 1, - editor->pCursors[0].pRun->member.run.style); - } else { - editor->pCursors[1] = editor->pCursors[0]; - para = ME_AppendTableRow(editor, para); - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[0].nOffset = 0; - editor->pCursors[1] = editor->pCursors[0]; - } - ME_CommitCoalescingUndo(editor); - ME_UpdateRepaint(editor); - return 0; - } + /* Text should not be inserted at the end of the table. */ + MessageBeep(-1); + return 0; } } /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */ @@ -2395,10 +2473,7 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode, ME_Style *style = ME_GetInsertStyle(editor, 0); ME_SaveTempStyle(editor); ME_ContinueCoalescingTransaction(editor); - if (wstr == '\r' && (GetKeyState(VK_SHIFT) & 0x8000)) - ME_InsertEndRowFromCursor(editor, 0); - else - ME_InsertTextFromCursor(editor, 0, &wstr, 1, style); + ME_InsertTextFromCursor(editor, 0, &wstr, 1, style); ME_ReleaseStyle(style); ME_CommitCoalescingUndo(editor); SetCursor(NULL); @@ -2492,7 +2567,7 @@ static BOOL ME_SetCursor(ME_TextEditor *editor) } ScreenToClient(editor->hWnd, &pt); - if (editor->nSelectionType == stLine && GetCapture() == editor->hWnd) { + if (editor->nSelectionType == stLine && editor->bMouseCaptured) { SetCursor(hLeft); return TRUE; } @@ -2582,11 +2657,17 @@ static BOOL ME_ShowContextMenu(ME_TextEditor *editor, int x, int y) return TRUE; } -ME_TextEditor *ME_MakeEditor(HWND hWnd) { +static ME_TextEditor *ME_MakeEditor(HWND hWnd, BOOL bEmulateVersion10) +{ ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor); int i; ed->hWnd = hWnd; - ed->bEmulateVersion10 = FALSE; + ed->bEmulateVersion10 = bEmulateVersion10; + ed->styleFlags = GetWindowLongW(hWnd, GWL_STYLE); + if (ed->styleFlags & WS_VSCROLL) + ed->styleFlags |= ES_AUTOVSCROLL; + if (!ed->bEmulateVersion10 && (ed->styleFlags & WS_HSCROLL)) + ed->styleFlags |= ES_AUTOHSCROLL; ed->pBuffer = ME_MakeText(); ed->nZoomNumerator = ed->nZoomDenominator = 0; ME_MakeFirstParagraph(ed); @@ -2605,6 +2686,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) { ed->pCursors[2] = ed->pCursors[0]; ed->pCursors[3] = ed->pCursors[1]; ed->nLastTotalLength = ed->nTotalLength = 0; + ed->nLastTotalWidth = ed->nTotalWidth = 0; ed->nUDArrowX = -1; ed->nSequence = 0; ed->rgbBackColor = -1; @@ -2620,7 +2702,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) { ed->nParagraphs = 1; ed->nLastSelStart = ed->nLastSelEnd = 0; ed->pLastSelStartPara = ed->pLastSelEndPara = ME_FindItemFwd(ed->pBuffer->pFirst, diParagraph); - ed->bWordWrap = (GetWindowLongW(hWnd, GWL_STYLE) & (WS_HSCROLL|ES_AUTOHSCROLL)) ? FALSE : TRUE; + ed->bWordWrap = !(ed->styleFlags & ES_AUTOHSCROLL); ed->bHideSelection = FALSE; ed->nInvalidOfs = -1; ed->pfnWordBreak = NULL; @@ -2628,41 +2710,48 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) { ed->mode = TM_RICHTEXT | TM_MULTILEVELUNDO | TM_MULTICODEPAGE; ed->AutoURLDetect_bEnable = FALSE; ed->bHaveFocus = FALSE; + ed->bMouseCaptured = FALSE; for (i=0; ipFontCache[i].nRefs = 0; ed->pFontCache[i].nAge = 0; ed->pFontCache[i].hFont = NULL; } - + ME_CheckCharOffsets(ed); - if (GetWindowLongW(hWnd, GWL_STYLE) & ES_SELECTIONBAR) + if (ed->styleFlags & ES_SELECTIONBAR) ed->selofs = SELECTIONBAR_WIDTH; else ed->selofs = 0; ed->bDefaultFormatRect = TRUE; ed->nSelectionType = stPosition; - if (GetWindowLongW(hWnd, GWL_STYLE) & ES_PASSWORD) + if (ed->styleFlags & ES_PASSWORD) ed->cPasswordMask = '*'; else ed->cPasswordMask = 0; - + ed->notified_cr.cpMin = ed->notified_cr.cpMax = 0; - /* Default vertical scrollbar information */ + /* Default scrollbar information */ ed->vert_si.cbSize = sizeof(SCROLLINFO); ed->vert_si.nMin = 0; ed->vert_si.nMax = 0; ed->vert_si.nPage = 0; ed->vert_si.nPos = 0; + ed->horz_si.cbSize = sizeof(SCROLLINFO); + ed->horz_si.nMin = 0; + ed->horz_si.nMax = 0; + ed->horz_si.nPage = 0; + ed->horz_si.nPos = 0; + OleInitialize(NULL); return ed; } -void ME_DestroyEditor(ME_TextEditor *editor) +static void ME_DestroyEditor(ME_TextEditor *editor) { ME_DisplayItem *pFirst = editor->pBuffer->pFirst; ME_DisplayItem *p = pFirst, *pNext = NULL; @@ -2861,43 +2950,37 @@ get_msg_name(UINT msg) return ""; } -static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, - LPARAM lParam, BOOL unicode) +void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam) { - ME_TextEditor *editor; - HRESULT hresult; - LRESULT lresult; + int x,y; + ME_Cursor tmpCursor; + BOOL isExact; + int nCharOfs; /* The start of the clicked text. Absolute character offset */ - TRACE("enter hwnd %p msg %04x (%s) %lx %lx, unicode %d\n", - hWnd, msg, get_msg_name(msg), wParam, lParam, unicode); + ME_Run *tmpRun; - editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0); - if (!editor) - { - if (msg == WM_NCCREATE) - { - CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam; - TRACE("WM_NCCREATE: style 0x%08x\n", pcs->style); - editor = ME_MakeEditor(hWnd); - SetWindowLongPtrW(hWnd, 0, (LONG_PTR)editor); - return TRUE; - } - else if (msg != WM_NCDESTROY) - { - ERR("called with invalid hWnd %p - application bug?\n", hWnd); - return 0; - } + ENLINK info; + x = (short)LOWORD(lParam); + y = (short)HIWORD(lParam); + nCharOfs = ME_CharFromPos(editor, x, y, &isExact); + if (!isExact) return; + + ME_CursorFromCharOfs(editor, nCharOfs, &tmpCursor); + tmpRun = &tmpCursor.pRun->member.run; + + if ((tmpRun->style->fmt.dwMask & CFM_LINK) + && (tmpRun->style->fmt.dwEffects & CFE_LINK)) + { /* The clicked run has CFE_LINK set */ + info.nmhdr.hwndFrom = editor->hWnd; + info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID); + info.nmhdr.code = EN_LINK; + info.msg = msg; + info.wParam = wParam; + info.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); } - - lresult = ME_HandleMessage(editor, msg, wParam, lParam, unicode, &hresult); - - if (hresult == S_FALSE) - lresult = DefWindowProcW(hWnd, msg, wParam, lParam); - - TRACE("exit hwnd %p msg %04x (%s) %lx %lx, unicode %d -> %lu\n", - hWnd, msg, get_msg_name(msg), wParam, lParam, unicode, lresult); - - return lresult; } #define UNSUPPORTED_MSG(e) \ @@ -2911,7 +2994,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, * The LRESULT that is returned is a return value for window procs, * and the phresult parameter is the COM return code needed by the * text services interface. */ -LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, +static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode, HRESULT* phresult) { *phresult = S_OK; @@ -2956,21 +3039,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, return ME_StreamOut(editor, wParam, (EDITSTREAM *)lParam); case WM_GETDLGCODE: { - UINT code = DLGC_WANTCHARS|DLGC_WANTARROWS; - if(lParam && (((LPMSG)lParam)->message == WM_KEYDOWN)) - { - int vk = (int)((LPMSG)lParam)->wParam; - /* if style says we want return key */ - if((vk == VK_RETURN) && (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_WANTRETURN)) - { - code |= DLGC_WANTMESSAGE; - } - /* we always handle ctrl-tab */ - if((vk == VK_TAB) && (GetKeyState(VK_CONTROL) & 0x8000)) - { - code |= DLGC_WANTMESSAGE; - } - } + UINT code = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL; + if (editor->styleFlags & ES_MULTILINE) + code |= DLGC_WANTMESSAGE; return code; } case EM_EMPTYUNDOBUFFER: @@ -3019,7 +3090,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, /* these flags are equivalent to the ES_* counterparts */ DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL | ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN | ECO_SELECTIONBAR; - DWORD settings = GetWindowLongW(editor->hWnd, GWL_STYLE) & mask; + DWORD settings = editor->styleFlags & mask; return settings; } @@ -3031,8 +3102,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, */ DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL | ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN | ECO_SELECTIONBAR; - DWORD raw = GetWindowLongW(editor->hWnd, GWL_STYLE); - DWORD settings = mask & raw; + DWORD settings = mask & editor->styleFlags; DWORD oldSettings = settings; DWORD changedSettings; @@ -3050,14 +3120,17 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case ECOOP_XOR: settings ^= lParam; } - SetWindowLongW(editor->hWnd, GWL_STYLE, (raw & ~mask) | (settings & mask)); - changedSettings = oldSettings ^ settings; if (settings & ECO_AUTOWORDSELECTION) FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n"); if (oldSettings ^ settings) { + DWORD dwStyle = GetWindowLongW(editor->hWnd, GWL_STYLE); + + editor->styleFlags = (editor->styleFlags & ~mask) | (settings & mask); + SetWindowLongW(editor->hWnd, GWL_STYLE, (dwStyle & ~mask) | (settings & mask)); + if (settings & ECO_SELECTIONBAR) { editor->selofs = SELECTIONBAR_WIDTH; editor->rcFormat.left += SELECTIONBAR_WIDTH; @@ -3094,12 +3167,12 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case EM_SETSCROLLPOS: { POINT *point = (POINT *)lParam; - ME_ScrollAbs(editor, point->y); + ME_ScrollAbs(editor, point->x, point->y); return 0; } case EM_AUTOURLDETECT: { - if (wParam==1 || wParam ==0) + if (wParam==1 || wParam ==0) { editor->AutoURLDetect_bEnable = (BOOL)wParam; return 0; @@ -3217,12 +3290,15 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, } case EM_SETREADONLY: { - long nStyle = GetWindowLongW(editor->hWnd, GWL_STYLE); - if (wParam) - nStyle |= ES_READONLY; - else - nStyle &= ~ES_READONLY; - SetWindowLongW(editor->hWnd, GWL_STYLE, nStyle); + LONG winStyle = GetWindowLongW(editor->hWnd, GWL_STYLE); + if (wParam) { + editor->styleFlags |= ES_READONLY; + winStyle |= ES_READONLY; + } else { + editor->styleFlags &= ~ES_READONLY; + winStyle &= ~ES_READONLY; + } + SetWindowLongW(editor->hWnd, GWL_STYLE, winStyle); return 0; } case EM_SETEVENTMASK: @@ -3263,7 +3339,11 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, } ME_CommitUndo(editor); if (bRepaint) - ME_RewrapRepaint(editor); + { + ME_WrapMarkedParagraphs(editor); + ME_UpdateScrollBar(editor); + ME_Repaint(editor); + } return 1; } case EM_GETCHARFORMAT: @@ -3285,7 +3365,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case EM_SETPARAFORMAT: { BOOL result = ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam); - ME_RewrapRepaint(editor); + ME_WrapMarkedParagraphs(editor); + ME_UpdateScrollBar(editor); + ME_Repaint(editor); ME_CommitUndo(editor); return result; } @@ -3295,7 +3377,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case EM_GETFIRSTVISIBLELINE: { ME_DisplayItem *p = editor->pBuffer->pFirst; - int y = ME_GetYScrollPos(editor); + int y = editor->vert_si.nPos; int ypara = 0; int count = 0; int ystart, yend; @@ -3365,7 +3447,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, return len; } case EM_SCROLLCARET: - ME_EnsureVisible(editor, editor->pCursors[0].pRun); + ME_EnsureVisible(editor, &editor->pCursors[0]); return 0; case WM_SETFONT: { @@ -3408,7 +3490,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, int len = -1; /* uses default style! */ - if (!(GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_MULTILINE)) + if (!(editor->styleFlags & ES_MULTILINE)) { WCHAR * p; @@ -3519,10 +3601,10 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, } case EM_GETSCROLLPOS: { - POINT *point = (POINT *)lParam; - point->x = 0; /* FIXME side scrolling not implemented */ - point->y = ME_GetYScrollPos(editor); - return 1; + POINT *point = (POINT *)lParam; + point->x = editor->horz_si.nPos; + point->y = editor->vert_si.nPos; + return 1; } case EM_GETTEXTRANGE: { @@ -3558,7 +3640,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, nCopy = min(nCharsLeft, strText->nLen); if (unicode) - lstrcpynW((LPWSTR) dest, strText->szData, nCopy); + memcpy(dest, strText->szData, nCopy * sizeof(WCHAR)); else nCopy = WideCharToMultiByte(CP_ACP, 0, strText->szData, nCopy, dest, nCharsLeft, NULL, NULL); @@ -3769,9 +3851,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, ME_DisplayItem *pRun; int nCharOfs, nOffset, nLength; POINTL pt = {0,0}; - SCROLLINFO si; - - nCharOfs = wParam; + + nCharOfs = wParam; /* detect which API version we're dealing with */ if (wParam >= 0x40000) nCharOfs = lParam; @@ -3786,10 +3867,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, pt.y += ME_GetParagraph(pRun)->member.para.pt.y + editor->rcFormat.top; pt.x += editor->rcFormat.left; + pt.x -= editor->horz_si.nPos; pt.y -= editor->vert_si.nPos; - si.cbSize = sizeof(si); - si.fMask = SIF_POS; - if (GetScrollInfo(editor->hWnd, SB_HORZ, &si)) pt.x -= si.nPos; if (wParam >= 0x40000) { *(POINTL *)wParam = pt; @@ -3801,19 +3880,16 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, SCROLLINFO si; ME_SetDefaultFormatRect(editor); - if (GetWindowLongW(editor->hWnd, GWL_STYLE) & WS_HSCROLL) - { /* Squelch the default horizontal scrollbar it would make */ - ShowScrollBar(editor->hWnd, SB_HORZ, FALSE); - } si.cbSize = sizeof(si); si.fMask = SIF_PAGE | SIF_RANGE; - if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_DISABLENOSCROLL) + if (editor->styleFlags & ES_DISABLENOSCROLL) si.fMask |= SIF_DISABLENOSCROLL; si.nMax = (si.fMask & SIF_DISABLENOSCROLL) ? 1 : 0; si.nMin = 0; si.nPage = 0; SetScrollInfo(editor->hWnd, SB_VERT, &si, TRUE); + SetScrollInfo(editor->hWnd, SB_HORZ, &si, TRUE); ME_CommitUndo(editor); ME_WrapMarkedParagraphs(editor); @@ -3838,6 +3914,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam), ME_CalculateClickCount(editor, msg, wParam, lParam)); SetCapture(editor->hWnd); + editor->bMouseCaptured = TRUE; ME_LinkNotify(editor,msg,wParam,lParam); if (!ME_SetCursor(editor)) goto do_default; break; @@ -3846,16 +3923,18 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, if ((editor->nEventMask & ENM_MOUSEEVENTS) && !ME_FilterEvent(editor, msg, &wParam, &lParam)) return 0; - if (GetCapture() == editor->hWnd) + if (editor->bMouseCaptured) ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam)); ME_LinkNotify(editor,msg,wParam,lParam); /* Set cursor if mouse is captured, since WM_SETCURSOR won't be received. */ - if (GetCapture() == editor->hWnd) + if (editor->bMouseCaptured) ME_SetCursor(editor); break; case WM_LBUTTONUP: - if (GetCapture() == editor->hWnd) + if (editor->bMouseCaptured) { ReleaseCapture(); + editor->bMouseCaptured = FALSE; + } if (editor->nSelectionType == stDocument) editor->nSelectionType = stPosition; if ((editor->nEventMask & ENM_MOUSEEVENTS) && @@ -3975,21 +4054,72 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case EM_STOPGROUPTYPING: ME_CommitUndo(editor); /* End coalesced undos for typed characters */ return 0; + case WM_HSCROLL: + { + const int scrollUnit = 7; + + switch(LOWORD(wParam)) + { + case SB_LEFT: + ME_ScrollAbs(editor, 0, 0); + break; + case SB_RIGHT: + ME_ScrollAbs(editor, + editor->horz_si.nMax - (int)editor->horz_si.nPage, + editor->vert_si.nMax - (int)editor->vert_si.nPage); + break; + case SB_LINELEFT: + ME_ScrollLeft(editor, scrollUnit); + break; + case SB_LINERIGHT: + ME_ScrollRight(editor, scrollUnit); + break; + case SB_PAGELEFT: + ME_ScrollLeft(editor, editor->sizeWindow.cx); + break; + case SB_PAGERIGHT: + ME_ScrollRight(editor, editor->sizeWindow.cx); + break; + case SB_THUMBTRACK: + case SB_THUMBPOSITION: + { + SCROLLINFO sbi; + sbi.cbSize = sizeof(sbi); + sbi.fMask = SIF_TRACKPOS; + /* Try to get 32-bit track position value. */ + if (!GetScrollInfo(editor->hWnd, SB_HORZ, &sbi)) + /* GetScrollInfo failed, settle for 16-bit value in wParam. */ + sbi.nTrackPos = HIWORD(wParam); + + ME_HScrollAbs(editor, sbi.nTrackPos); + break; + } + } + break; + } case EM_SCROLL: /* fall through */ - case WM_VSCROLL: + case WM_VSCROLL: { int origNPos; int lineHeight; - - origNPos = ME_GetYScrollPos(editor); + + origNPos = editor->vert_si.nPos; 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_TOP: + ME_ScrollAbs(editor, 0, 0); + break; + case SB_BOTTOM: + ME_ScrollAbs(editor, + editor->horz_si.nMax - (int)editor->horz_si.nPage, + editor->vert_si.nMax - (int)editor->vert_si.nPage); + break; case SB_LINEUP: ME_ScrollUp(editor,lineHeight); break; @@ -4004,29 +4134,56 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, break; case SB_THUMBTRACK: case SB_THUMBPOSITION: - ME_ScrollAbs(editor,HIWORD(wParam)); + { + SCROLLINFO sbi; + sbi.cbSize = sizeof(sbi); + sbi.fMask = SIF_TRACKPOS; + /* Try to get 32-bit track position value. */ + if (!GetScrollInfo(editor->hWnd, SB_VERT, &sbi)) + /* GetScrollInfo failed, settle for 16-bit value in wParam. */ + sbi.nTrackPos = HIWORD(wParam); + + ME_VScrollAbs(editor, sbi.nTrackPos); break; + } } if (msg == EM_SCROLL) - return 0x00010000 | (((ME_GetYScrollPos(editor) - origNPos)/lineHeight) & 0xffff); + return 0x00010000 | (((editor->vert_si.nPos - origNPos)/lineHeight) & 0xffff); break; } case WM_MOUSEWHEEL: { int gcWheelDelta; UINT pulScrollLines; + BOOL ctrl_is_down; if ((editor->nEventMask & ENM_MOUSEEVENTS) && !ME_FilterEvent(editor, msg, &wParam, &lParam)) return 0; - SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0); - gcWheelDelta = -GET_WHEEL_DELTA_WPARAM(wParam); - - if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines) + ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000; + + gcWheelDelta = GET_WHEEL_DELTA_WPARAM(wParam); + + if (abs(gcWheelDelta) >= WHEEL_DELTA) { - /* FIXME follow the original */ - ME_ScrollDown(editor,pulScrollLines * (gcWheelDelta / WHEEL_DELTA) * 8); + if (ctrl_is_down) { + int numerator; + if (!editor->nZoomNumerator || !editor->nZoomDenominator) + { + numerator = 100; + } else { + numerator = editor->nZoomNumerator * 100 / editor->nZoomDenominator; + } + numerator = numerator + (gcWheelDelta / WHEEL_DELTA) * 10; + if (numerator >= 10 && numerator <= 500) + ME_SetZoom(editor, numerator, 100); + } else { + SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0); + /* FIXME follow the original */ + if (pulScrollLines) + ME_ScrollDown(editor,pulScrollLines * (-gcWheelDelta / WHEEL_DELTA) * 8); + } } break; } @@ -4238,6 +4395,45 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, return 0L; } +static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, + LPARAM lParam, BOOL unicode) +{ + ME_TextEditor *editor; + HRESULT hresult; + LRESULT lresult; + + TRACE("enter hwnd %p msg %04x (%s) %lx %lx, unicode %d\n", + hWnd, msg, get_msg_name(msg), wParam, lParam, unicode); + + editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0); + if (!editor) + { + if (msg == WM_NCCREATE) + { + CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam; + TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style); + editor = ME_MakeEditor(hWnd, FALSE); + SetWindowLongPtrW(hWnd, 0, (LONG_PTR)editor); + return TRUE; + } + else if (msg != WM_NCDESTROY) + { + ERR("called with invalid hWnd %p - application bug?\n", hWnd); + return 0; + } + } + + lresult = ME_HandleMessage(editor, msg, wParam, lParam, unicode, &hresult); + + if (hresult == S_FALSE) + lresult = DefWindowProcW(hWnd, msg, wParam, lParam); + + TRACE("exit hwnd %p msg %04x (%s) %lx %lx, unicode %d -> %lu\n", + hWnd, msg, get_msg_name(msg), wParam, lParam, unicode, lresult); + + return lresult; +} + static LRESULT WINAPI RichEditWndProcW(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { BOOL unicode = TRUE; @@ -4267,62 +4463,23 @@ 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) + if (msg == WM_NCCREATE && !GetWindowLongPtrW(hWnd, 0)) { - ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0); - - TRACE("Emulating version 1.0 (hWnd=%p)\n", hWnd); - editor->bEmulateVersion10 = TRUE; - editor->bWordWrap = (GetWindowLongW(hWnd, GWL_STYLE) & ES_AUTOHSCROLL) ? FALSE : TRUE; - editor->pBuffer->pLast->member.para.nCharOfs = 2; - assert(editor->pBuffer->pLast->prev->type == diRun); - assert(editor->pBuffer->pLast->prev->member.run.nFlags & MERF_ENDPARA); - editor->pBuffer->pLast->prev->member.run.nLF = 1; + ME_TextEditor *editor; + CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam; + + TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style); + editor = ME_MakeEditor(hWnd, TRUE); + SetWindowLongPtrW(hWnd, 0, (LONG_PTR)editor); + return TRUE; } - return result; + return RichEditANSIWndProc(hWnd, msg, wParam, lParam); } void ME_SendOldNotify(ME_TextEditor *editor, int nCode) { HWND hWnd = editor->hWnd; - SendMessageA(GetParent(hWnd), WM_COMMAND, (nCode<<16)|GetWindowLongW(hWnd, GWLP_ID), (LPARAM)hWnd); -} - -void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam) -{ - int x,y; - ME_Cursor tmpCursor; - BOOL isExact; - int nCharOfs; /* The start of the clicked text. Absolute character offset */ - - ME_Run *tmpRun; - - ENLINK info; - x = (short)LOWORD(lParam); - y = (short)HIWORD(lParam); - nCharOfs = ME_CharFromPos(editor, x, y, &isExact); - if (!isExact) return; - - ME_CursorFromCharOfs(editor, nCharOfs, &tmpCursor); - tmpRun = &tmpCursor.pRun->member.run; - - if ((tmpRun->style->fmt.dwMask & CFM_LINK) - && (tmpRun->style->fmt.dwEffects & CFE_LINK)) - { /* The clicked run has CFE_LINK set */ - info.nmhdr.hwndFrom = editor->hWnd; - info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID); - info.nmhdr.code = EN_LINK; - info.msg = msg; - info.wParam = wParam; - info.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); - } + SendMessageA(GetParent(hWnd), WM_COMMAND, MAKEWPARAM(GetWindowLongW(hWnd, GWLP_ID), nCode), (LPARAM)hWnd); } int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to) @@ -4569,7 +4726,7 @@ static BOOL isurlspecial(WCHAR c) * * sel_max == -1 indicates scan to end of text. */ -BOOL ME_FindNextURLCandidate(ME_TextEditor *editor, int sel_min, int sel_max, +static BOOL ME_FindNextURLCandidate(ME_TextEditor *editor, int sel_min, int sel_max, int * candidate_min, int * candidate_max) { ME_DisplayItem * item; @@ -4665,7 +4822,7 @@ BOOL ME_FindNextURLCandidate(ME_TextEditor *editor, int sel_min, int sel_max, /** * This proc evaluates the selection and returns TRUE if it can be considered an URL */ -BOOL ME_IsCandidateAnURL(ME_TextEditor *editor, int sel_min, int sel_max) +static BOOL ME_IsCandidateAnURL(ME_TextEditor *editor, int sel_min, int sel_max) { struct prefix_s { const char *text; @@ -4717,7 +4874,7 @@ BOOL ME_IsCandidateAnURL(ME_TextEditor *editor, int sel_min, int sel_max) * * Returns TRUE if at least one section was modified. */ -BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_max) +static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_max) { BOOL modified = FALSE; int cMin, cMax; @@ -4790,39 +4947,3 @@ BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_max) } while (sel_min < sel_max); return modified; } - -void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor) -{ - ME_DisplayItem * startPara, * endPara; - ME_DisplayItem * item; - int dummy; - int from, to; - - ME_GetSelection(editor, &from, &to); - if (from > to) from ^= to, to ^=from, from ^= to; - startPara = NULL; endPara = NULL; - - /* Find paragraph previous to the one that contains start cursor */ - item = ME_FindItemAtOffset(editor, diRun, from, &dummy); - if (item) { - startPara = ME_FindItemBack(item, diParagraph); - item = ME_FindItemBack(startPara, diParagraph); - if (item) startPara = item; - } - - /* Find paragraph that contains end cursor */ - item = ME_FindItemAtOffset(editor, diRun, to, &dummy); - if (item) { - endPara = ME_FindItemFwd(item, diParagraph); - } - - if (startPara && endPara) { - ME_UpdateLinkAttribute(editor, - startPara->member.para.nCharOfs, - endPara->member.para.nCharOfs); - } else if (startPara) { - ME_UpdateLinkAttribute(editor, - startPara->member.para.nCharOfs, - -1); - } -} diff --git a/reactos/dll/win32/riched20/editor.h b/reactos/dll/win32/riched20/editor.h index df82073af67..d052d5d37fb 100644 --- a/reactos/dll/win32/riched20/editor.h +++ b/reactos/dll/win32/riched20/editor.h @@ -83,7 +83,6 @@ ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass); ME_DisplayItem *ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass); ME_DisplayItem *ME_FindItemBackOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass); ME_DisplayItem *ME_FindItemFwdOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass); -BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass); ME_DisplayItem *ME_MakeDI(ME_DIType type); void ME_DestroyDisplayItem(ME_DisplayItem *item); void ME_DumpDocument(ME_TextBuffer *buffer); @@ -177,7 +176,6 @@ void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod); /* caret.c */ int ME_SetSelection(ME_TextEditor *editor, int from, int to); -void ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType); void ME_HideCaret(ME_TextEditor *ed); void ME_ShowCaret(ME_TextEditor *ed); void ME_MoveCaret(ME_TextEditor *ed); @@ -204,7 +202,6 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars, BOOL bFo int ME_GetTextLength(ME_TextEditor *editor); int ME_GetTextLengthEx(ME_TextEditor *editor, const GETTEXTLENGTHEX *how); ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor); -BOOL ME_UpdateSelection(ME_TextEditor *editor, const ME_Cursor *pTempCursor); /* context.c */ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC); @@ -224,12 +221,9 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp, BOOL keepFirstParaFormat); void ME_DumpParaStyle(ME_Paragraph *s); void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]); -BOOL ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const PARAFORMAT2 *pFmt); BOOL 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, const ME_DisplayItem *last); void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last); void ME_MarkAllForWrapping(ME_TextEditor *editor); void ME_SetDefaultParaFormat(PARAFORMAT2 *pFmt); @@ -239,8 +233,7 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT * 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); +void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor); void ME_InvalidateSelection(ME_TextEditor *editor); void ME_QueueInvalidateFromCursor(ME_TextEditor *editor, int nCursor); BOOL ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator); @@ -249,13 +242,14 @@ int ME_twips2pointsY(ME_Context *c, int y); /* scroll functions in paint.c */ -void ME_ScrollAbs(ME_TextEditor *editor, int absY); +void ME_ScrollAbs(ME_TextEditor *editor, int x, int y); +void ME_HScrollAbs(ME_TextEditor *editor, int x); +void ME_VScrollAbs(ME_TextEditor *editor, int y); void ME_ScrollUp(ME_TextEditor *editor, int cy); void ME_ScrollDown(ME_TextEditor *editor, int cy); -void ME_Scroll(ME_TextEditor *editor, int value, int type); +void ME_ScrollLeft(ME_TextEditor *editor, int cx); +void ME_ScrollRight(ME_TextEditor *editor, int cx); void ME_UpdateScrollBar(ME_TextEditor *editor); -int ME_GetYScrollPos(ME_TextEditor *editor); -BOOL ME_GetYScrollVisible(ME_TextEditor *editor); /* other functions in paint.c */ int ME_GetParaBorderWidth(ME_TextEditor *editor, int); @@ -269,12 +263,7 @@ void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src); void ME_DeleteReObject(REOBJECT* reo); /* editor.c */ -ME_TextEditor *ME_MakeEditor(HWND hWnd); -void ME_DestroyEditor(ME_TextEditor *editor); -LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, - LPARAM lParam, BOOL unicode, HRESULT* phresult); void ME_SendOldNotify(ME_TextEditor *editor, int nCode); -void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam); int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, BOOL bCRLF); ME_DisplayItem *ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset); void ME_RTFCharAttrHook(struct _RTF_Info *info); @@ -284,11 +273,6 @@ void ME_RTFSpecialCharHook(struct _RTF_Info *info); void ME_StreamInFill(ME_InStream *stream); extern int me_debug; extern void DoWrap(ME_TextEditor *editor); -extern BOOL ME_FindNextURLCandidate(ME_TextEditor *editor, int sel_min, int sel_max, - int * candidate_min, int * candidate_max); -extern BOOL ME_IsCandidateAnURL(ME_TextEditor *editor, int sel_min, int sel_max); -BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_max); -void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor); /* table.c */ BOOL ME_IsInTable(ME_DisplayItem *pItem); diff --git a/reactos/dll/win32/riched20/editstr.h b/reactos/dll/win32/riched20/editstr.h index cde05f933ee..d289509454b 100644 --- a/reactos/dll/win32/riched20/editstr.h +++ b/reactos/dll/win32/riched20/editstr.h @@ -189,7 +189,7 @@ typedef struct tagME_Paragraph int nCharOfs; int nFlags; POINT pt; - int nHeight; + int nHeight, nWidth; int nLastPaintYPos, nLastPaintHeight; int nRows; struct tagME_DisplayItem *prev_para, *next_para, *document; @@ -330,9 +330,11 @@ typedef struct tagME_TextEditor BOOL bEmulateVersion10; ME_TextBuffer *pBuffer; ME_Cursor *pCursors; + DWORD styleFlags; int nCursors; SIZE sizeWindow; int nTotalLength, nLastTotalLength; + int nTotalWidth, nLastTotalWidth; int nUDArrowX; int nSequence; COLORREF rgbBackColor; @@ -374,8 +376,10 @@ typedef struct tagME_TextEditor /* Track previous notified selection */ CHARRANGE notified_cr; - /* Cache previously set vertical scrollbar info */ - SCROLLINFO vert_si; + /* Cache previously set scrollbar info */ + SCROLLINFO vert_si, horz_si; + + BOOL bMouseCaptured; } ME_TextEditor; typedef struct tagME_Context diff --git a/reactos/dll/win32/riched20/list.c b/reactos/dll/win32/riched20/list.c index 4ddc54a9bfc..804fd608bc0 100644 --- a/reactos/dll/win32/riched20/list.c +++ b/reactos/dll/win32/riched20/list.c @@ -42,6 +42,27 @@ void ME_Remove(ME_DisplayItem *diWhere) diNext->prev = diPrev; } +static BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass) +{ + if (type==nTypeOrClass) + return TRUE; + if (nTypeOrClass==diRunOrParagraph && (type==diRun || type==diParagraph)) + return TRUE; + if (nTypeOrClass==diRunOrStartRow && (type==diRun || type==diStartRow)) + return TRUE; + if (nTypeOrClass==diParagraphOrEnd && (type==diTextEnd || type==diParagraph)) + return TRUE; + if (nTypeOrClass==diStartRowOrParagraph && (type==diStartRow || type==diParagraph)) + return TRUE; + if (nTypeOrClass==diStartRowOrParagraphOrEnd + && (type==diStartRow || type==diParagraph || type==diTextEnd)) + return TRUE; + if (nTypeOrClass==diRunOrParagraphOrEnd + && (type==diRun || type==diParagraph || type==diTextEnd)) + return TRUE; + return FALSE; +} + ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass) { if (!di) @@ -87,27 +108,6 @@ ME_DisplayItem *ME_FindItemFwdOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass) return NULL; } -BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass) -{ - if (type==nTypeOrClass) - return TRUE; - if (nTypeOrClass==diRunOrParagraph && (type==diRun || type==diParagraph)) - return TRUE; - if (nTypeOrClass==diRunOrStartRow && (type==diRun || type==diStartRow)) - return TRUE; - if (nTypeOrClass==diParagraphOrEnd && (type==diTextEnd || type==diParagraph)) - return TRUE; - if (nTypeOrClass==diStartRowOrParagraph && (type==diStartRow || type==diParagraph)) - return TRUE; - if (nTypeOrClass==diStartRowOrParagraphOrEnd - && (type==diStartRow || type==diParagraph || type==diTextEnd)) - return TRUE; - if (nTypeOrClass==diRunOrParagraphOrEnd - && (type==diRun || type==diParagraph || type==diTextEnd)) - return TRUE; - return FALSE; -} - void ME_DestroyDisplayItem(ME_DisplayItem *item) { /* TRACE("type=%s\n", ME_GetDITypeName(item->type)); */ if (item->type==diParagraph || item->type == diUndoSetParagraphFormat) { diff --git a/reactos/dll/win32/riched20/paint.c b/reactos/dll/win32/riched20/paint.c index 94a1f87d9cf..bc0441bcdd8 100644 --- a/reactos/dll/win32/riched20/paint.c +++ b/reactos/dll/win32/riched20/paint.c @@ -23,23 +23,33 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit); +static void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph); + void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *rcUpdate) { ME_DisplayItem *item; ME_Context c; - int yoffset; int ys, ye; + HRGN oldRgn; + + oldRgn = CreateRectRgn(0, 0, 0, 0); + if (!GetClipRgn(hDC, oldRgn)) + { + DeleteObject(oldRgn); + oldRgn = NULL; + } + IntersectClipRect(hDC, rcUpdate->left, rcUpdate->top, + rcUpdate->right, rcUpdate->bottom); editor->nSequence++; - yoffset = ME_GetYScrollPos(editor); ME_InitContext(&c, editor, hDC); SetBkMode(hDC, TRANSPARENT); ME_MoveCaret(editor); /* Calls ME_WrapMarkedParagraphs */ item = editor->pBuffer->pFirst->next; /* This context point is an offset for the paragraph positions stored * during wrapping. It shouldn't be modified during painting. */ - c.pt.x = c.rcView.left; - c.pt.y = c.rcView.top - yoffset; + c.pt.x = c.rcView.left - editor->horz_si.nPos; + c.pt.y = c.rcView.top - editor->vert_si.nPos; while(item != editor->pBuffer->pLast) { assert(item->type == diParagraph); @@ -101,10 +111,16 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT * if (!IsRectEmpty(&rc)) FillRect(hDC, &rc, c.editor->hbrBackground); } - if (editor->nTotalLength != editor->nLastTotalLength) + if (editor->nTotalLength != editor->nLastTotalLength || + editor->nTotalWidth != editor->nLastTotalWidth) ME_SendRequestResize(editor, FALSE); editor->nLastTotalLength = editor->nTotalLength; + editor->nLastTotalWidth = editor->nTotalWidth; ME_DestroyContext(&c, NULL); + + SelectClipRgn(hDC, oldRgn); + if (oldRgn) + DeleteObject(oldRgn); } void ME_Repaint(ME_TextEditor *editor) @@ -130,11 +146,11 @@ void ME_UpdateRepaint(ME_TextEditor *editor) wrappedParagraphs = ME_WrapMarkedParagraphs(editor); if (wrappedParagraphs) ME_UpdateScrollBar(editor); - + /* Ensure that the cursor is visible */ pCursor = &editor->pCursors[0]; - ME_EnsureVisible(editor, pCursor->pRun); - + ME_EnsureVisible(editor, pCursor); + /* send EN_CHANGE if the event mask asks for it */ if(editor->nEventMask & ENM_CHANGE) { @@ -148,7 +164,7 @@ 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. */ @@ -603,7 +619,7 @@ static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT /* Native richedit doesn't support paragraph borders in v1.0 - 4.1, * but might support it in later versions. */ if (hasParaBorder) { - int pen_width; + int pen_width, rightEdge; COLORREF pencr; HPEN pen = NULL, oldpen = NULL; POINT pt; @@ -613,6 +629,9 @@ static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT else pencr = pen_colors[(para->pFmt->wBorders >> 12) & 0xF]; + rightEdge = c->pt.x + max(c->editor->sizeWindow.cx, + c->editor->nTotalWidth); + pen_width = ME_GetBorderPenWidth(c->editor, idx); pen = CreatePen(border_details[idx].pen_style, pen_width, pencr); oldpen = SelectObject(c->hDC, pen); @@ -625,51 +644,51 @@ static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT if (para->pFmt->wBorders & 1) { - MoveToEx(c->hDC, c->rcView.left, y + bounds->top, NULL); - LineTo(c->hDC, c->rcView.left, y + para->nHeight - bounds->bottom); + MoveToEx(c->hDC, c->pt.x, y + bounds->top, NULL); + LineTo(c->hDC, c->pt.x, y + para->nHeight - bounds->bottom); if (border_details[idx].dble) { - rc.left = c->rcView.left + 1; + rc.left = c->pt.x + 1; rc.right = rc.left + border_width; rc.top = y + bounds->top; rc.bottom = y + para->nHeight - bounds->bottom; FillRect(c->hDC, &rc, c->editor->hbrBackground); - MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + bounds->top + DD(4), NULL); - LineTo(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - bounds->bottom - DD(8)); + MoveToEx(c->hDC, c->pt.x + pen_width + 1, y + bounds->top + DD(4), NULL); + LineTo(c->hDC, c->pt.x + pen_width + 1, y + para->nHeight - bounds->bottom - DD(8)); } bounds->left += border_width; } if (para->pFmt->wBorders & 2) { - MoveToEx(c->hDC, c->rcView.right - 1, y + bounds->top, NULL); - LineTo(c->hDC, c->rcView.right - 1, y + para->nHeight - bounds->bottom); + MoveToEx(c->hDC, rightEdge - 1, y + bounds->top, NULL); + LineTo(c->hDC, rightEdge - 1, y + para->nHeight - bounds->bottom); if (border_details[idx].dble) { - rc.left = c->rcView.right - pen_width - 1; - rc.right = c->rcView.right - 1; + rc.left = rightEdge - pen_width - 1; + rc.right = rc.left + pen_width; rc.top = y + bounds->top; rc.bottom = y + para->nHeight - bounds->bottom; FillRect(c->hDC, &rc, c->editor->hbrBackground); - MoveToEx(c->hDC, c->rcView.right - 1 - pen_width - 1, y + bounds->top + DD(4), NULL); - LineTo(c->hDC, c->rcView.right - 1 - pen_width - 1, y + para->nHeight - bounds->bottom - DD(8)); + MoveToEx(c->hDC, rightEdge - 1 - pen_width - 1, y + bounds->top + DD(4), NULL); + LineTo(c->hDC, rightEdge - 1 - pen_width - 1, y + para->nHeight - bounds->bottom - DD(8)); } bounds->right += border_width; } if (para->pFmt->wBorders & 4) { - MoveToEx(c->hDC, c->rcView.left, y + bounds->top, NULL); - LineTo(c->hDC, c->rcView.right, y + bounds->top); + MoveToEx(c->hDC, c->pt.x, y + bounds->top, NULL); + LineTo(c->hDC, rightEdge, y + bounds->top); if (border_details[idx].dble) { - MoveToEx(c->hDC, c->rcView.left + DD(1), y + bounds->top + pen_width + 1, NULL); - LineTo(c->hDC, c->rcView.right - DD(2), y + bounds->top + pen_width + 1); + MoveToEx(c->hDC, c->pt.x + DD(1), y + bounds->top + pen_width + 1, NULL); + LineTo(c->hDC, rightEdge - DD(2), y + bounds->top + pen_width + 1); } bounds->top += border_width; } if (para->pFmt->wBorders & 8) { - MoveToEx(c->hDC, c->rcView.left, y + para->nHeight - bounds->bottom - 1, NULL); - LineTo(c->hDC, c->rcView.right, y + para->nHeight - bounds->bottom - 1); + MoveToEx(c->hDC, c->pt.x, y + para->nHeight - bounds->bottom - 1, NULL); + LineTo(c->hDC, rightEdge, y + para->nHeight - bounds->bottom - 1); if (border_details[idx].dble) { - MoveToEx(c->hDC, c->rcView.left + DD(1), y + para->nHeight - bounds->bottom - 1 - pen_width - 1, NULL); - LineTo(c->hDC, c->rcView.right - DD(2), y + para->nHeight - bounds->bottom - 1 - pen_width - 1); + MoveToEx(c->hDC, c->pt.x + DD(1), y + para->nHeight - bounds->bottom - 1 - pen_width - 1, NULL); + LineTo(c->hDC, rightEdge - DD(2), y + para->nHeight - bounds->bottom - 1 - pen_width - 1); } bounds->bottom += border_width; } @@ -878,7 +897,7 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph) } } -void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) +static void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) { int align = SetTextAlign(c->hDC, TA_BASELINE); ME_DisplayItem *p; @@ -910,8 +929,12 @@ void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) } ME_DrawParaDecoration(c, para, y, &bounds); y += bounds.top; - rc.left += bounds.left; - rc.right -= bounds.right; + if (bounds.left || bounds.right) { + rc.left = max(rc.left, c->pt.x + bounds.left); + rc.right = min(rc.right, c->pt.x - bounds.right + + max(c->editor->sizeWindow.cx, + c->editor->nTotalWidth)); + } for (p = paragraph->next; p != para->next_para; p = p->next) { @@ -931,6 +954,16 @@ void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) if (visible) { FillRect(c->hDC, &rc, c->editor->hbrBackground); } + if (bounds.right) + { + /* If scrolled to the right past the end of the text, then + * there may be space to the right of the paragraph border. */ + RECT rcAfterBrdr = rc; + rcAfterBrdr.left = rc.right + bounds.right; + rcAfterBrdr.right = c->rcView.right; + if (RectVisible(c->hDC, &rcAfterBrdr)) + FillRect(c->hDC, &rcAfterBrdr, c->editor->hbrBackground); + } if (me_debug) { const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0}; @@ -997,162 +1030,192 @@ void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) SetTextAlign(c->hDC, align); } -void ME_ScrollAbs(ME_TextEditor *editor, int absY) +void ME_ScrollAbs(ME_TextEditor *editor, int x, int y) { - ME_Scroll(editor, absY, 1); + LONG winStyle; + BOOL bScrollBarIsVisible, bScrollBarWillBeVisible; + int scrollX = 0, scrollY = 0; + + if (editor->horz_si.nPos != x) { + x = min(x, editor->horz_si.nMax); + x = max(x, editor->horz_si.nMin); + SetScrollPos(editor->hWnd, SB_HORZ, x, TRUE); + scrollX = editor->horz_si.nPos - x; + editor->horz_si.nPos = x; + } + + if (editor->vert_si.nPos != y) { + y = min(y, editor->vert_si.nMax - (int)editor->vert_si.nPage); + y = max(y, editor->vert_si.nMin); + SetScrollPos(editor->hWnd, SB_VERT, y, TRUE); + scrollY = editor->vert_si.nPos - y; + editor->vert_si.nPos = y; + } + + if (abs(scrollX) > editor->sizeWindow.cx || + abs(scrollY) > editor->sizeWindow.cy) + InvalidateRect(editor->hWnd, NULL, TRUE); + else + ScrollWindowEx(editor->hWnd, scrollX, scrollY, &editor->rcFormat, + &editor->rcFormat, NULL, NULL, SW_INVALIDATE); + ME_Repaint(editor); + + winStyle = GetWindowLongW(editor->hWnd, GWL_STYLE); + bScrollBarIsVisible = (winStyle & WS_HSCROLL) != 0; + bScrollBarWillBeVisible = (editor->nTotalWidth > editor->sizeWindow.cx) + || (editor->styleFlags & ES_DISABLENOSCROLL); + if (bScrollBarIsVisible != bScrollBarWillBeVisible) + ShowScrollBar(editor->hWnd, SB_HORZ, bScrollBarWillBeVisible); + + bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0; + bScrollBarWillBeVisible = (editor->nTotalLength > editor->sizeWindow.cy) + || (editor->styleFlags & ES_DISABLENOSCROLL); + if (bScrollBarIsVisible != bScrollBarWillBeVisible) + ShowScrollBar(editor->hWnd, SB_VERT, bScrollBarWillBeVisible); + + ME_UpdateScrollBar(editor); +} + +void ME_HScrollAbs(ME_TextEditor *editor, int x) +{ + ME_ScrollAbs(editor, x, editor->vert_si.nPos); +} + +void ME_VScrollAbs(ME_TextEditor *editor, int y) +{ + ME_ScrollAbs(editor, editor->horz_si.nPos, y); } void ME_ScrollUp(ME_TextEditor *editor, int cy) { - ME_Scroll(editor, cy, 2); + ME_VScrollAbs(editor, editor->vert_si.nPos - cy); } void ME_ScrollDown(ME_TextEditor *editor, int cy) -{ - ME_Scroll(editor, cy, 3); -} - -void ME_Scroll(ME_TextEditor *editor, int value, int type) { - SCROLLINFO si; - int nOrigPos, nNewPos, nActualScroll; - HWND hWnd; - LONG winStyle; - BOOL bScrollBarIsVisible, bScrollBarWillBeVisible; - - nOrigPos = ME_GetYScrollPos(editor); - - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_POS; - - switch (type) - { - case 1: - /*Scroll absolutely*/ - si.nPos = value; - break; - case 2: - /* Scroll up - towards the beginning of the document */ - si.nPos = nOrigPos - value; - break; - case 3: - /* Scroll down - towards the end of the document */ - si.nPos = nOrigPos + value; - break; - default: - FIXME("ME_Scroll called incorrectly\n"); - si.nPos = 0; - } - - nNewPos = SetScrollInfo(editor->hWnd, SB_VERT, &si, TRUE); - editor->vert_si.nPos = nNewPos; - nActualScroll = nOrigPos - nNewPos; - if (abs(nActualScroll) > editor->sizeWindow.cy) - InvalidateRect(editor->hWnd, NULL, TRUE); - else - ScrollWindowEx(editor->hWnd, 0, nActualScroll, NULL, NULL, NULL, NULL, SW_INVALIDATE); - ME_Repaint(editor); - - hWnd = editor->hWnd; - winStyle = GetWindowLongW(hWnd, GWL_STYLE); - bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0; - bScrollBarWillBeVisible = (editor->nTotalLength > editor->sizeWindow.cy) - || (winStyle & ES_DISABLENOSCROLL); - if (bScrollBarIsVisible != bScrollBarWillBeVisible) - { - ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible); - } - ME_UpdateScrollBar(editor); + ME_VScrollAbs(editor, editor->vert_si.nPos + cy); +} + +void ME_ScrollLeft(ME_TextEditor *editor, int cx) +{ + ME_HScrollAbs(editor, editor->horz_si.nPos - cx); +} + +void ME_ScrollRight(ME_TextEditor *editor, int cx) +{ + ME_HScrollAbs(editor, editor->horz_si.nPos + cx); } - void ME_UpdateScrollBar(ME_TextEditor *editor) -{ - /* Note that this is the only function that should ever call SetScrolLInfo - * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never - * be used at all. */ - - HWND hWnd; +{ + /* Note that this is the only function that should ever call + * SetScrollInfo with SIF_PAGE or SIF_RANGE. */ + SCROLLINFO si; - BOOL bScrollBarWasVisible,bScrollBarWillBeVisible; - + 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; - si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; - if (GetWindowLongW(hWnd, GWL_STYLE) & ES_DISABLENOSCROLL) - { + if (editor->styleFlags & ES_DISABLENOSCROLL) si.fMask |= SIF_DISABLENOSCROLL; - bScrollBarWillBeVisible = TRUE; + + /* Update horizontal scrollbar */ + bScrollBarWasVisible = editor->horz_si.nMax > editor->horz_si.nPage; + bScrollBarWillBeVisible = editor->nTotalWidth > editor->sizeWindow.cx; + if (editor->horz_si.nPos && !bScrollBarWillBeVisible) + { + ME_HScrollAbs(editor, 0); + /* ME_HScrollAbs will call this function, + * so nothing else needs to be done here. */ + return; } - if (bScrollBarWasVisible != bScrollBarWillBeVisible) + si.nMin = 0; + si.nMax = editor->nTotalWidth; + si.nPos = editor->horz_si.nPos; + si.nPage = editor->sizeWindow.cx; + + if (si.nMin != editor->horz_si.nMin || + si.nMax != editor->horz_si.nMax || + si.nPage != editor->horz_si.nPage) { - ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible); - ME_MarkAllForWrapping(editor); - ME_WrapMarkedParagraphs(editor); + TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage); + editor->horz_si.nMin = si.nMin; + editor->horz_si.nMax = si.nMax; + editor->horz_si.nPage = si.nPage; + if (bScrollBarWillBeVisible || bScrollBarWasVisible) + SetScrollInfo(editor->hWnd, SB_HORZ, &si, TRUE); } - - si.nMin = 0; + + if (si.fMask & SIF_DISABLENOSCROLL) + bScrollBarWillBeVisible = TRUE; + + if (bScrollBarWasVisible != bScrollBarWillBeVisible) + ShowScrollBar(editor->hWnd, SB_HORZ, bScrollBarWillBeVisible); + + /* Update vertical scrollbar */ + bScrollBarWasVisible = editor->vert_si.nMax > editor->vert_si.nPage; + bScrollBarWillBeVisible = editor->nTotalLength > editor->sizeWindow.cy; + + if (editor->vert_si.nPos && !bScrollBarWillBeVisible) + { + ME_VScrollAbs(editor, 0); + /* ME_VScrollAbs will call this function, + * so nothing else needs to be done here. */ + return; + } + si.nMax = editor->nTotalLength; si.nPos = editor->vert_si.nPos; si.nPage = editor->sizeWindow.cy; - - if (!(si.nMin == editor->vert_si.nMin && si.nMax == editor->vert_si.nMax && si.nPage == editor->vert_si.nPage)) + + if (si.nMin != editor->vert_si.nMin || + si.nMax != editor->vert_si.nMax || + si.nPage != editor->vert_si.nPage) { TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage); editor->vert_si.nMin = si.nMin; editor->vert_si.nMax = si.nMax; editor->vert_si.nPage = si.nPage; - if (bScrollBarWillBeVisible) - { - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - } - else - { - if (bScrollBarWasVisible && !(si.fMask & SIF_DISABLENOSCROLL)) - { - SetScrollInfo(hWnd, SB_VERT, &si, TRUE); - ShowScrollBar(hWnd, SB_VERT, FALSE); - ME_ScrollAbs(editor, 0); - } - } + if (bScrollBarWillBeVisible || bScrollBarWasVisible) + SetScrollInfo(editor->hWnd, SB_VERT, &si, TRUE); } + + if (si.fMask & SIF_DISABLENOSCROLL) + bScrollBarWillBeVisible = TRUE; + + if (bScrollBarWasVisible != bScrollBarWillBeVisible) + ShowScrollBar(editor->hWnd, SB_VERT, bScrollBarWillBeVisible); } -int ME_GetYScrollPos(ME_TextEditor *editor) +void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor) { - return editor->vert_si.nPos; -} + ME_Run *pRun = &pCursor->pRun->member.run; + ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow); + ME_DisplayItem *pPara = ME_FindItemBack(pCursor->pRun, diParagraph); + int x, y, yheight; -BOOL ME_GetYScrollVisible(ME_TextEditor *editor) -{ /* Returns true if the scrollbar is visible */ - return (editor->vert_si.nMax - editor->vert_si.nMin >= max(editor->vert_si.nPage - 1, 0)); -} - -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.pt.y+pRow->member.row.pt.y; + + x = pRun->pt.x + ME_PointFromChar(editor, pRun, pCursor->nOffset); + if (x > editor->horz_si.nPos + editor->sizeWindow.cx) + x = x + 1 - editor->sizeWindow.cx; + else if (x > editor->horz_si.nPos) + x = editor->horz_si.nPos; + + y = pPara->member.para.pt.y + pRow->member.row.pt.y; 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) - ME_ScrollAbs(editor,y+yheight-editor->sizeWindow.cy); + + if (y < editor->vert_si.nPos) + ME_ScrollAbs(editor, x, y); + else if (y + yheight > editor->vert_si.nPos + editor->sizeWindow.cy) + ME_ScrollAbs(editor, x, y + yheight - editor->sizeWindow.cy); + else if (x != editor->horz_si.nPos) + ME_ScrollAbs(editor, x, editor->vert_si.nPos); } @@ -1234,18 +1297,19 @@ ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator) { /* TODO: Zoom images and objects */ - if (numerator != 0) + if (numerator == 0 && denominator == 0) { - if (denominator == 0) - return FALSE; - if (1.0 / 64.0 > (float)numerator / (float)denominator - || (float)numerator / (float)denominator > 64.0) - return FALSE; + editor->nZoomNumerator = editor->nZoomDenominator = 0; + return TRUE; } - + if (numerator <= 0 || denominator <= 0) + return FALSE; + if (numerator * 64 <= denominator || numerator / denominator >= 64) + 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 9cf4d97c0b4..00d81a261b9 100644 --- a/reactos/dll/win32/riched20/para.c +++ b/reactos/dll/win32/riched20/para.c @@ -67,7 +67,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) run = ME_MakeRun(style, ME_MakeString(wszParagraphSign), MERF_ENDPARA); run->member.run.nCharOfs = 0; run->member.run.nCR = 1; - run->member.run.nLF = (editor->bEmulateVersion10) ? 1 : 0; + run->member.run.nLF = editor->bEmulateVersion10 ? 1 : 0; ME_InsertBefore(text->pLast, para); ME_InsertBefore(text->pLast, run); @@ -76,17 +76,12 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) text->pFirst->member.para.next_para = para; text->pLast->member.para.prev_para = para; - text->pLast->member.para.nCharOfs = 1; + text->pLast->member.para.nCharOfs = editor->bEmulateVersion10 ? 2 : 1; ME_DestroyContext(&c, editor->hWnd); } - -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, const ME_DisplayItem *last) +static void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last) { while(first != last) { @@ -95,6 +90,11 @@ void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, const ME_D } } +void ME_MarkAllForWrapping(ME_TextEditor *editor) +{ + ME_MarkForWrapping(editor, editor->pBuffer->pFirst->member.para.next_para, editor->pBuffer->pLast); +} + void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last) { while(first != last && first) @@ -123,6 +123,82 @@ static void ME_UpdateTableFlags(ME_DisplayItem *para) para->member.para.pFmt->wEffects &= ~PFE_TABLE; } +static BOOL ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const PARAFORMAT2 *pFmt) +{ + PARAFORMAT2 copy; + DWORD dwMask; + + assert(para->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); + dwMask = pFmt->dwMask; + if (pFmt->cbSize < sizeof(PARAFORMAT)) + return FALSE; + else if (pFmt->cbSize < sizeof(PARAFORMAT2)) + dwMask &= PFM_ALL; + else + dwMask &= PFM_ALL2; + + ME_AddUndoItem(editor, diUndoSetParagraphFormat, para); + + copy = *para->member.para.pFmt; + +#define COPY_FIELD(m, f) \ + if (dwMask & (m)) { \ + para->member.para.pFmt->dwMask |= m; \ + para->member.para.pFmt->f = pFmt->f; \ + } + + COPY_FIELD(PFM_NUMBERING, wNumbering); + COPY_FIELD(PFM_STARTINDENT, dxStartIndent); + if (dwMask & PFM_OFFSETINDENT) + para->member.para.pFmt->dxStartIndent += pFmt->dxStartIndent; + COPY_FIELD(PFM_RIGHTINDENT, dxRightIndent); + COPY_FIELD(PFM_OFFSET, dxOffset); + COPY_FIELD(PFM_ALIGNMENT, wAlignment); + if (dwMask & PFM_TABSTOPS) + { + para->member.para.pFmt->cTabCount = pFmt->cTabCount; + memcpy(para->member.para.pFmt->rgxTabs, pFmt->rgxTabs, pFmt->cTabCount*sizeof(LONG)); + } + + if (dwMask & (PFM_ALL2 & ~PFM_ALL)) + { + /* PARAFORMAT2 fields */ + +#define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \ + PFM_NOLINENUMBER|PFM_NOWIDOWCONTROL|PFM_DONOTHYPHEN|PFM_SIDEBYSIDE| \ + PFM_TABLE) + /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */ + if (dwMask & EFFECTS_MASK) { + para->member.para.pFmt->dwMask |= dwMask & EFFECTS_MASK; + para->member.para.pFmt->wEffects &= ~HIWORD(dwMask); + para->member.para.pFmt->wEffects |= pFmt->wEffects & HIWORD(dwMask); + } +#undef EFFECTS_MASK + + COPY_FIELD(PFM_SPACEBEFORE, dySpaceBefore); + COPY_FIELD(PFM_SPACEAFTER, dySpaceAfter); + COPY_FIELD(PFM_LINESPACING, dyLineSpacing); + COPY_FIELD(PFM_STYLE, sStyle); + COPY_FIELD(PFM_LINESPACING, bLineSpacingRule); + COPY_FIELD(PFM_SHADING, wShadingWeight); + COPY_FIELD(PFM_SHADING, wShadingStyle); + COPY_FIELD(PFM_NUMBERINGSTART, wNumberingStart); + COPY_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle); + COPY_FIELD(PFM_NUMBERINGTAB, wNumberingTab); + COPY_FIELD(PFM_BORDER, wBorderSpace); + COPY_FIELD(PFM_BORDER, wBorderWidth); + COPY_FIELD(PFM_BORDER, wBorders); + } + + para->member.para.pFmt->dwMask |= dwMask; +#undef COPY_FIELD + + if (memcmp(©, para->member.para.pFmt, sizeof(PARAFORMAT2))) + para->member.para.nFlags |= MEPF_REWRAP; + + return TRUE; +} + /* split paragraph at the beginning of the run */ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME_Style *style, int numCR, int numLF, @@ -439,68 +515,6 @@ void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]) #undef DUMP_EFFECT } -BOOL 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); - - copy = *para->member.para.pFmt; - -#define COPY_FIELD(m, f) \ - if (pFmt->dwMask & (m)) { \ - para->member.para.pFmt->dwMask |= m; \ - para->member.para.pFmt->f = pFmt->f; \ - } - - COPY_FIELD(PFM_NUMBERING, wNumbering); -#define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \ - PFM_NOLINENUMBER|PFM_NOWIDOWCONTROL|PFM_DONOTHYPHEN|PFM_SIDEBYSIDE| \ - PFM_TABLE) - /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */ - if (pFmt->dwMask & EFFECTS_MASK) { - para->member.para.pFmt->dwMask |= pFmt->dwMask & EFFECTS_MASK; - para->member.para.pFmt->wEffects &= ~HIWORD(pFmt->dwMask); - para->member.para.pFmt->wEffects |= pFmt->wEffects & HIWORD(pFmt->dwMask); - } -#undef EFFECTS_MASK - - COPY_FIELD(PFM_STARTINDENT, dxStartIndent); - if (pFmt->dwMask & PFM_OFFSETINDENT) - para->member.para.pFmt->dxStartIndent += pFmt->dxStartIndent; - COPY_FIELD(PFM_RIGHTINDENT, dxRightIndent); - COPY_FIELD(PFM_OFFSET, dxOffset); - COPY_FIELD(PFM_ALIGNMENT, wAlignment); - - if (pFmt->dwMask & PFM_TABSTOPS) - { - para->member.para.pFmt->cTabCount = pFmt->cTabCount; - memcpy(para->member.para.pFmt->rgxTabs, pFmt->rgxTabs, pFmt->cTabCount*sizeof(LONG)); - } - COPY_FIELD(PFM_SPACEBEFORE, dySpaceBefore); - COPY_FIELD(PFM_SPACEAFTER, dySpaceAfter); - COPY_FIELD(PFM_LINESPACING, dyLineSpacing); - COPY_FIELD(PFM_STYLE, sStyle); - COPY_FIELD(PFM_LINESPACING, bLineSpacingRule); - COPY_FIELD(PFM_SHADING, wShadingWeight); - COPY_FIELD(PFM_SHADING, wShadingStyle); - COPY_FIELD(PFM_NUMBERINGSTART, wNumberingStart); - COPY_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle); - COPY_FIELD(PFM_NUMBERINGTAB, wNumberingTab); - COPY_FIELD(PFM_BORDER, wBorderSpace); - COPY_FIELD(PFM_BORDER, wBorderWidth); - COPY_FIELD(PFM_BORDER, wBorders); - - para->member.para.pFmt->dwMask |= pFmt->dwMask; -#undef COPY_FIELD - - if (memcmp(©, para->member.para.pFmt, sizeof(PARAFORMAT2))) - para->member.para.nFlags |= MEPF_REWRAP; - - return TRUE; -} - - void ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end) { @@ -541,74 +555,73 @@ BOOL ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt) return TRUE; } -void ME_GetParaFormat(ME_TextEditor *editor, const ME_DisplayItem *para, PARAFORMAT2 *pFmt) +static void ME_GetParaFormat(ME_TextEditor *editor, + const ME_DisplayItem *para, + PARAFORMAT2 *pFmt) { - if (pFmt->cbSize >= sizeof(PARAFORMAT2)) - { + UINT cbSize = pFmt->cbSize; + if (pFmt->cbSize >= sizeof(PARAFORMAT2)) { *pFmt = *para->member.para.pFmt; - return; + } else { + CopyMemory(pFmt, para->member.para.pFmt, pFmt->cbSize); + pFmt->dwMask &= PFM_ALL; } - CopyMemory(pFmt, para->member.para.pFmt, pFmt->cbSize); + pFmt->cbSize = cbSize; } void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) { ME_DisplayItem *para, *para_end; - PARAFORMAT2 tmp; - + PARAFORMAT2 *curFmt; + + if (pFmt->cbSize < sizeof(PARAFORMAT)) { + pFmt->dwMask = 0; + return; + } + ME_GetSelectionParas(editor, ¶, ¶_end); - + ME_GetParaFormat(editor, para, pFmt); - if (para == para_end) return; - + /* Invalidate values that change across the selected paragraphs. */ - do { - ZeroMemory(&tmp, sizeof(tmp)); - tmp.cbSize = sizeof(tmp); - ME_GetParaFormat(editor, para, &tmp); + while (para != para_end) + { + para = para->member.para.next_para; + curFmt = para->member.para.pFmt; #define CHECK_FIELD(m, f) \ - if (pFmt->f != tmp.f) pFmt->dwMask &= ~(m); + if (pFmt->f != curFmt->f) pFmt->dwMask &= ~(m); - pFmt->dwMask &= ~((pFmt->wEffects ^ tmp.wEffects) << 16); CHECK_FIELD(PFM_NUMBERING, wNumbering); - assert(tmp.dwMask & PFM_ALIGNMENT); - CHECK_FIELD(PFM_NUMBERING, wNumbering); - assert(tmp.dwMask & PFM_STARTINDENT); CHECK_FIELD(PFM_STARTINDENT, dxStartIndent); - assert(tmp.dwMask & PFM_RIGHTINDENT); CHECK_FIELD(PFM_RIGHTINDENT, dxRightIndent); - assert(tmp.dwMask & PFM_OFFSET); CHECK_FIELD(PFM_OFFSET, dxOffset); CHECK_FIELD(PFM_ALIGNMENT, wAlignment); - - assert(tmp.dwMask & PFM_TABSTOPS); if (pFmt->dwMask & PFM_TABSTOPS) { - if (pFmt->cTabCount != tmp.cTabCount || - memcmp(pFmt->rgxTabs, tmp.rgxTabs, tmp.cTabCount*sizeof(int))) + if (pFmt->cTabCount != para->member.para.pFmt->cTabCount || + memcmp(pFmt->rgxTabs, curFmt->rgxTabs, curFmt->cTabCount*sizeof(int))) pFmt->dwMask &= ~PFM_TABSTOPS; } - CHECK_FIELD(PFM_SPACEBEFORE, dySpaceBefore); - CHECK_FIELD(PFM_SPACEAFTER, dySpaceAfter); - CHECK_FIELD(PFM_LINESPACING, dyLineSpacing); - CHECK_FIELD(PFM_STYLE, sStyle); - CHECK_FIELD(PFM_SPACEAFTER, bLineSpacingRule); - CHECK_FIELD(PFM_SHADING, wShadingWeight); - CHECK_FIELD(PFM_SHADING, wShadingStyle); - CHECK_FIELD(PFM_NUMBERINGSTART, wNumberingStart); - CHECK_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle); - CHECK_FIELD(PFM_NUMBERINGTAB, wNumberingTab); - CHECK_FIELD(PFM_BORDER, wBorderSpace); - CHECK_FIELD(PFM_BORDER, wBorderWidth); - CHECK_FIELD(PFM_BORDER, wBorders); - + if (pFmt->dwMask >= sizeof(PARAFORMAT2)) + { + pFmt->dwMask &= ~((pFmt->wEffects ^ curFmt->wEffects) << 16); + CHECK_FIELD(PFM_SPACEBEFORE, dySpaceBefore); + CHECK_FIELD(PFM_SPACEAFTER, dySpaceAfter); + CHECK_FIELD(PFM_LINESPACING, dyLineSpacing); + CHECK_FIELD(PFM_STYLE, sStyle); + CHECK_FIELD(PFM_SPACEAFTER, bLineSpacingRule); + CHECK_FIELD(PFM_SHADING, wShadingWeight); + CHECK_FIELD(PFM_SHADING, wShadingStyle); + CHECK_FIELD(PFM_NUMBERINGSTART, wNumberingStart); + CHECK_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle); + CHECK_FIELD(PFM_NUMBERINGTAB, wNumberingTab); + CHECK_FIELD(PFM_BORDER, wBorderSpace); + CHECK_FIELD(PFM_BORDER, wBorderWidth); + CHECK_FIELD(PFM_BORDER, wBorders); + } #undef CHECK_FIELD - - if (para == para_end) - return; - para = para->member.para.next_para; - } while(1); + } } void ME_SetDefaultParaFormat(PARAFORMAT2 *pFmt) diff --git a/reactos/dll/win32/riched20/richole.c b/reactos/dll/win32/riched20/richole.c index 9eabb04754d..a5f79c7af0c 100644 --- a/reactos/dll/win32/riched20/richole.c +++ b/reactos/dll/win32/riched20/richole.c @@ -52,6 +52,7 @@ DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d); typedef struct ITextSelectionImpl ITextSelectionImpl; +typedef struct IOleClientSiteImpl IOleClientSiteImpl; typedef struct IRichEditOleImpl { const IRichEditOleVtbl *lpRichEditOleVtbl; @@ -60,6 +61,7 @@ typedef struct IRichEditOleImpl { ME_TextEditor *editor; ITextSelectionImpl *txtSel; + IOleClientSiteImpl *clientSite; } IRichEditOleImpl; struct ITextSelectionImpl { @@ -69,6 +71,13 @@ struct ITextSelectionImpl { IRichEditOleImpl *reOle; }; +struct IOleClientSiteImpl { + const IOleClientSiteVtbl *lpVtbl; + LONG ref; + + IRichEditOleImpl *reOle; +}; + static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface) { return (IRichEditOleImpl *)((BYTE*)iface - FIELD_OFFSET(IRichEditOleImpl, lpRichEditOleVtbl)); @@ -126,6 +135,7 @@ IRichEditOle_fnRelease(IRichEditOle *me) TRACE ("Destroying %p\n", This); This->txtSel->reOle = NULL; ITextSelection_Release((ITextSelection *) This->txtSel); + IOleClientSite_Release((IOleClientSite *) This->clientSite); heap_free(This); } return ref; @@ -156,13 +166,148 @@ IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob, return E_NOTIMPL; } +static HRESULT WINAPI +IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj) +{ + TRACE("%p %s\n", me, debugstr_guid(riid) ); + + *ppvObj = NULL; + if (IsEqualGUID(riid, &IID_IUnknown) || + IsEqualGUID(riid, &IID_IOleClientSite)) + *ppvObj = me; + if (*ppvObj) + { + IOleClientSite_AddRef(me); + return S_OK; + } + FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) ); + + return E_NOINTERFACE; +} + +static ULONG WINAPI +IOleClientSite_fnAddRef(IOleClientSite *me) +{ + IOleClientSiteImpl *This = (IOleClientSiteImpl *) me; + return InterlockedIncrement(&This->ref); +} + +static ULONG WINAPI +IOleClientSite_fnRelease(IOleClientSite *me) +{ + IOleClientSiteImpl *This = (IOleClientSiteImpl *) me; + ULONG ref = InterlockedDecrement(&This->ref); + if (ref == 0) + heap_free(This); + return ref; +} + +static HRESULT WINAPI +IOleClientSite_fnSaveObject(IOleClientSite *me) +{ + IOleClientSiteImpl *This = (IOleClientSiteImpl *) me; + if (!This->reOle) + return CO_E_RELEASED; + + FIXME("stub %p\n",me); + return E_NOTIMPL; +} + + +static HRESULT WINAPI +IOleClientSite_fnGetMoniker(IOleClientSite *me, DWORD dwAssign, DWORD dwWhichMoniker, + IMoniker **ppmk) +{ + IOleClientSiteImpl *This = (IOleClientSiteImpl *) me; + if (!This->reOle) + return CO_E_RELEASED; + + FIXME("stub %p\n",me); + return E_NOTIMPL; +} + +static HRESULT WINAPI +IOleClientSite_fnGetContainer(IOleClientSite *me, IOleContainer **ppContainer) +{ + IOleClientSiteImpl *This = (IOleClientSiteImpl *) me; + if (!This->reOle) + return CO_E_RELEASED; + + FIXME("stub %p\n",me); + return E_NOTIMPL; +} + +static HRESULT WINAPI +IOleClientSite_fnShowObject(IOleClientSite *me) +{ + IOleClientSiteImpl *This = (IOleClientSiteImpl *) me; + if (!This->reOle) + return CO_E_RELEASED; + + FIXME("stub %p\n",me); + return E_NOTIMPL; +} + +static HRESULT WINAPI +IOleClientSite_fnOnShowWindow(IOleClientSite *me, BOOL fShow) +{ + IOleClientSiteImpl *This = (IOleClientSiteImpl *) me; + if (!This->reOle) + return CO_E_RELEASED; + + FIXME("stub %p\n",me); + return E_NOTIMPL; +} + +static HRESULT WINAPI +IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *me) +{ + IOleClientSiteImpl *This = (IOleClientSiteImpl *) me; + if (!This->reOle) + return CO_E_RELEASED; + + FIXME("stub %p\n",me); + return E_NOTIMPL; +} + +static const IOleClientSiteVtbl ocst = { + IOleClientSite_fnQueryInterface, + IOleClientSite_fnAddRef, + IOleClientSite_fnRelease, + IOleClientSite_fnSaveObject, + IOleClientSite_fnGetMoniker, + IOleClientSite_fnGetContainer, + IOleClientSite_fnShowObject, + IOleClientSite_fnOnShowWindow, + IOleClientSite_fnRequestNewObjectLayout +}; + +static IOleClientSiteImpl * +CreateOleClientSite(IRichEditOleImpl *reOle) +{ + IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite); + if (!clientSite) + return NULL; + + clientSite->lpVtbl = &ocst; + clientSite->ref = 1; + clientSite->reOle = reOle; + return clientSite; +} + static HRESULT WINAPI IRichEditOle_fnGetClientSite(IRichEditOle *me, LPOLECLIENTSITE *lplpolesite) { IRichEditOleImpl *This = impl_from_IRichEditOle(me); - FIXME("stub %p\n",This); - return E_NOTIMPL; + + TRACE("%p,%p\n",This, lplpolesite); + + if(!lplpolesite) + return E_INVALIDARG; + *lplpolesite = (IOleClientSite *) This->clientSite; + IOleClientSite_fnAddRef(*lplpolesite); + return S_OK; } static HRESULT WINAPI @@ -1541,6 +1686,13 @@ LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj) heap_free(reo); return 0; } + reo->clientSite = CreateOleClientSite(reo); + if (!reo->txtSel) + { + ITextSelection_Release((ITextSelection *) reo->txtSel); + heap_free(reo); + return 0; + } TRACE("Created %p\n",reo); *ppObj = (LPVOID) reo; diff --git a/reactos/dll/win32/riched20/wrap.c b/reactos/dll/win32/riched20/wrap.c index 7eb844c733f..9012cfe7d21 100644 --- a/reactos/dll/win32/riched20/wrap.c +++ b/reactos/dll/win32/riched20/wrap.c @@ -133,6 +133,7 @@ static void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd) } } + para->member.para.nWidth = max(para->member.para.nWidth, width); row = ME_MakeRow(ascent+descent, ascent, width); if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */ pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) @@ -536,6 +537,7 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp) { static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp) { ME_DisplayItem *p, *pRow; + tp->member.para.nWidth = 0; /* remove all items that will be reinserted by paragraph wrapper anyway */ tp->member.para.nRows = 0; for (p = tp->next; p!=tp->member.para.next_para; p = p->next) { @@ -578,6 +580,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) ME_Context c; BOOL bModified = FALSE; int yStart = -1; + int totalWidth = 0; ME_InitContext(&c, editor, GetDC(editor->hWnd)); c.pt.x = 0; @@ -638,6 +641,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) ME_DisplayItem *startRowPara; int prevHeight, nHeight, bottomBorder = 0; ME_DisplayItem *cell = ME_FindItemBack(item, diCell); + item->member.para.nWidth = cell->member.cell.pt.x + cell->member.cell.nWidth; if (!(item->member.para.next_para->member.para.nFlags & MEPF_ROWSTART)) { /* Last row, the bottom border is added to the height. */ @@ -707,12 +711,15 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) } c.pt.y += item->member.para.nHeight; } + + totalWidth = max(totalWidth, item->member.para.nWidth); item = item->member.para.next_para; } editor->sizeWindow.cx = c.rcView.right-c.rcView.left; editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top; - + editor->nTotalLength = c.pt.y; + editor->nTotalWidth = totalWidth; editor->pBuffer->pLast->member.para.pt.x = 0; editor->pBuffer->pLast->member.para.pt.y = c.pt.y; @@ -732,7 +739,7 @@ void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) ME_InitContext(&c, editor, GetDC(editor->hWnd)); rc = c.rcView; - ofs = ME_GetYScrollPos(editor); + ofs = editor->vert_si.nPos; item = editor->pBuffer->pFirst; while(item != editor->pBuffer->pLast) { @@ -772,6 +779,7 @@ ME_SendRequestResize(ME_TextEditor *editor, BOOL force) info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID); info.nmhdr.code = EN_REQUESTRESIZE; info.rc = rc; + info.rc.right = editor->nTotalWidth; info.rc.bottom = editor->nTotalLength; editor->nEventMask &= ~ENM_REQUESTRESIZE; diff --git a/reactos/include/psdk/richedit.h b/reactos/include/psdk/richedit.h index 02ebdc2f93a..095cc8ab554 100644 --- a/reactos/include/psdk/richedit.h +++ b/reactos/include/psdk/richedit.h @@ -622,7 +622,7 @@ typedef enum tagKHYPH typedef struct hyphresult { KHYPH khyph; - long ichHyph; + LONG ichHyph; WCHAR chHyph; } HYPHRESULT; @@ -630,7 +630,7 @@ typedef struct tagHyphenateInfo { SHORT cbSize; SHORT dxHyphenateZone; - void (WINAPI* pfnHyphenate)(WCHAR*, LANGID, long, HYPHRESULT*); + void (WINAPI* pfnHyphenate)(WCHAR*, LANGID, LONG, HYPHRESULT*); } HYPHENATEINFO; typedef struct _msgfilter { @@ -712,7 +712,7 @@ typedef struct _imecomptext { DWORD flags; } IMECOMPTEXT; -void WINAPI HyphenateProc(WCHAR*, LANGID, long, HYPHRESULT*); +void WINAPI HyphenateProc(WCHAR*, LANGID, LONG, HYPHRESULT*); #define SF_TEXT 0x00000001 #define SF_RTF 0x00000002 diff --git a/reactos/include/psdk/textserv.h b/reactos/include/psdk/textserv.h index 9b3cbf92f05..e9ff4da627e 100644 --- a/reactos/include/psdk/textserv.h +++ b/reactos/include/psdk/textserv.h @@ -147,25 +147,6 @@ DECLARE_INTERFACE_(ITextServices,IUnknown) #define ITextServices_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) #define ITextServices_AddRef(p) (p)->lpVtbl->AddRef(p) #define ITextServices_Release(p) (p)->lpVtbl->Release(p) -/*** ITextServices methods ***/ -#define ITextServices_TxSendMessage(p,a,b,c,d) (p)->lpVtbl->TxSendMessage(p,a,b,c,d) -#define ITextServices_TxDraw(p,a,b,c,d,e,f,g,h,i,j,k,l) (p)->lpVtbl->TxDraw(p,a,b,c,d,e,f,g,h,i,j,k,l) -#define ITextServices_TxGetHScroll(p,a,b,c,d,e) (p)->lpVtbl->TxGetHScroll(p,a,b,c,d,e) -#define ITextServices_TxGetVScroll(p,a,b,c,d,e) (p)->lpVtbl->TxGetVScroll(p,a,b,c,d,e) -#define ITextServices_OnTxSetCursor(p,a,b,c,d,e,f,g,h,i) (p)->lpVtbl->OnTxSetCursor(p,a,b,c,d,e,f,g,h,i) -#define ITextServices_TxQueryHitPoint(p,a,b,c,d,e,f,g,h,i,j) (p)->lpVtbl->TxQueryHitPoint(p,a,b,c,d,e,f,g,h,i,j) -#define ITextServices_OnTxInplaceActivate(p,a) (p)->lpVtbl->OnTxInplaceActivate(p,a) -#define ITextServices_OnTxInplaceDeactivate(p) (p)->lpVtbl->OnTxInplaceDeactivate(p) -#define ITextServices_OnTxUIActivate(p) (p)->lpVtbl->OnTxUIActivate(p) -#define ITextServices_OnTxUIDeactivate(p) (p)->lpVtbl->OnTxUIDeactivate(p) -#define ITextServices_TxGetText(p,a) (p)->lpVtbl->TxGetText(p,a) -#define ITextServices_TxSetText(p,a) (p)->lpVtbl->TxSetText(p,a) -#define ITextServices_TxGetCurrentTargetX(p,a) (p)->lpVtbl->TxGetCurrentTargetX(p,a) -#define ITextServices_TxGetBaseLinePos(p,a) (p)->lpVtbl->TxGetBaseLinePos(p,a) -#define ITextServices_TxGetNaturalSize(p,a,b,c,d,e,f,g,h) (p)->lpVtbl->TxGetNaturalSize(p,a,b,c,d,e,f,g,h) -#define ITextServices_TxGetDropTarget(p,a) (p)->lpVtbl->TxGetDropTarget(p,a) -#define ITextServices_OnTxPropertyBitsChange(p,a,b) (p)->lpVtbl->OnTxPropertyBitsChange(p,a,b) -#define ITextServices_TxGetCachedSize(p,a,b) (p)->lpVtbl->TxGetCachedSize(p,a,b) #endif #undef INTERFACE @@ -271,7 +252,7 @@ DECLARE_INTERFACE_(ITextHost,IUnknown) STDMETHOD_(BOOL,TxShowCaret)( THIS_ BOOL fShow) PURE; - STDMETHOD_(BOOL,TxSetCarentPos)( THIS_ + STDMETHOD_(BOOL,TxSetCaretPos)( THIS_ INT x, INT y) PURE; @@ -334,7 +315,7 @@ DECLARE_INTERFACE_(ITextHost,IUnknown) STDMETHOD(TxGetMaxLength)( THIS_ DWORD* plength) PURE; - STDMETHOD(TxGetScrollbars)( THIS_ + STDMETHOD(TxGetScrollBars)( THIS_ DWORD* pdwScrollBar) PURE; STDMETHOD(TxGetPasswordChar)( THIS_ @@ -405,7 +386,7 @@ DECLARE_INTERFACE_(ITextHost,IUnknown) #define ITextHost_TxGetSysColor(p,a) (p)->lpVtbl->TxGetSysColor(p,a) #define ITextHost_TxGetBackStyle(p,a) (p)->lpVtbl->TxGetBackStyle(p,a) #define ITextHost_TxGetMaxLength(p,a) (p)->lpVtbl->TxGetMaxLength(p,a) -#define ITextHost_TxGetScrollbars(p,a) (p)->lpVtbl->TxGetScrollbars(p,a) +#define ITextHost_TxGetScrollBars(p,a) (p)->lpVtbl->TxGetScrollBars(p,a) #define ITextHost_TxGetPasswordChar(p,a) (p)->lpVtbl->TxGetPasswordChar(p,a) #define ITextHost_TxGetAcceleratorPos(p,a) (p)->lpVtbl->TxGetAcceleratorPos(p,a) #define ITextHost_TxGetExtent(p,a) (p)->lpVtbl->TxGetExtent(p,a)