riched20: Handle efficiently caret creation/destruction.

Signed-off-by: Sergio Gómez Del Real <sdelreal@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Sergio Gómez Del Real 2019-04-03 08:23:04 -05:00 committed by Alexandre Julliard
parent 406ac1bc74
commit 5868c664c1
6 changed files with 54 additions and 42 deletions

View File

@ -266,36 +266,47 @@ void ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
return;
}
void
ME_MoveCaret(ME_TextEditor *editor)
void create_caret(ME_TextEditor *editor)
{
int x, y, height;
ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height);
if(editor->bHaveFocus && !ME_IsSelection(editor))
ITextHost_TxCreateCaret(editor->texthost, NULL, 0, height);
editor->caret_height = height;
editor->caret_hidden = TRUE;
}
void show_caret(ME_TextEditor *editor)
{
ITextHost_TxShowCaret(editor->texthost, TRUE);
editor->caret_hidden = FALSE;
}
void hide_caret(ME_TextEditor *editor)
{
/* calls to HideCaret are cumulative; do so only once */
if (!editor->caret_hidden)
{
ITextHost_TxShowCaret(editor->texthost, FALSE);
editor->caret_hidden = TRUE;
}
}
void update_caret(ME_TextEditor *editor)
{
int x, y, height;
if (!editor->bHaveFocus) return;
if (!ME_IsSelection(editor))
{
ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height);
if (height != editor->caret_height) create_caret(editor);
x = min(x, editor->rcFormat.right-1);
ITextHost_TxCreateCaret(editor->texthost, NULL, 0, height);
ITextHost_TxSetCaretPos(editor->texthost, x, y);
show_caret(editor);
}
}
void ME_ShowCaret(ME_TextEditor *ed)
{
ME_MoveCaret(ed);
if(ed->bHaveFocus && !ME_IsSelection(ed))
ITextHost_TxShowCaret(ed->texthost, TRUE);
}
void ME_HideCaret(ME_TextEditor *ed)
{
if(!ed->bHaveFocus || ME_IsSelection(ed))
{
ITextHost_TxShowCaret(ed->texthost, FALSE);
DestroyCaret();
}
else
hide_caret(editor);
}
BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
@ -1200,8 +1211,7 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
}
}
ME_InvalidateSelection(editor);
ITextHost_TxShowCaret(editor->texthost, FALSE);
ME_ShowCaret(editor);
update_caret(editor);
ME_SendSelChange(editor);
}
@ -1233,8 +1243,7 @@ void ME_MouseMove(ME_TextEditor *editor, int x, int y)
}
ME_InvalidateSelection(editor);
ITextHost_TxShowCaret(editor->texthost, FALSE);
ME_ShowCaret(editor);
update_caret(editor);
ME_SendSelChange(editor);
}
@ -1627,9 +1636,9 @@ ME_ArrowKey(ME_TextEditor *editor, int nVKey, BOOL extend, BOOL ctrl)
ME_InvalidateSelection(editor);
ME_Repaint(editor);
ITextHost_TxShowCaret(editor->texthost, FALSE);
hide_caret(editor);
ME_EnsureVisible(editor, &tmp_curs);
ME_ShowCaret(editor);
update_caret(editor);
ME_SendSelChange(editor);
return success;
}

View File

@ -1802,9 +1802,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
if (!(format & SFF_SELECTION)) {
ME_ClearTempStyle(editor);
}
ITextHost_TxShowCaret(editor->texthost, FALSE);
ME_MoveCaret(editor);
ITextHost_TxShowCaret(editor->texthost, TRUE);
update_caret(editor);
ME_SendSelChange(editor);
ME_SendRequestResize(editor, FALSE);
@ -2158,8 +2156,7 @@ static int handle_EM_EXSETSEL( ME_TextEditor *editor, int to, int from )
ME_InvalidateSelection( editor );
end = ME_SetSelection( editor, to, from );
ME_InvalidateSelection( editor );
ITextHost_TxShowCaret( editor->texthost, FALSE );
ME_ShowCaret( editor );
update_caret( editor );
ME_SendSelChange( editor );
return end;
@ -3118,6 +3115,8 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
ed->bHaveFocus = FALSE;
ed->bDialogMode = FALSE;
ed->bMouseCaptured = FALSE;
ed->caret_hidden = FALSE;
ed->caret_height = 0;
for (i=0; i<HFONT_CACHE_SIZE; i++)
{
ed->pFontCache[i].nRefs = 0;
@ -3529,7 +3528,7 @@ static LRESULT ME_WmCreate(ME_TextEditor *editor, LPARAM lParam, BOOL unicode)
ME_CommitUndo(editor);
ME_WrapMarkedParagraphs(editor);
ME_MoveCaret(editor);
update_caret(editor);
return 0;
}
@ -4511,7 +4510,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
break;
case WM_SETFOCUS:
editor->bHaveFocus = TRUE;
ME_ShowCaret(editor);
create_caret(editor);
update_caret(editor);
ME_SendOldNotify(editor, EN_SETFOCUS);
if (!editor->bHideSelection && !(editor->styleFlags & ES_NOHIDESEL))
ME_InvalidateSelection( editor );
@ -4520,7 +4520,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_CommitUndo(editor); /* End coalesced undos for typed characters */
editor->bHaveFocus = FALSE;
editor->wheel_remain = 0;
ME_HideCaret(editor);
hide_caret(editor);
DestroyCaret();
ME_SendOldNotify(editor, EN_KILLFOCUS);
if (!editor->bHideSelection && !(editor->styleFlags & ES_NOHIDESEL))
ME_InvalidateSelection( editor );
@ -4978,6 +4979,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
RECT rc;
PAINTSTRUCT ps;
update_caret(editor);
hDC = BeginPaint(editor->hWnd, &ps);
if (!editor->bEmulateVersion10 || (editor->nEventMask & ENM_UPDATE))
ME_SendOldNotify(editor, EN_UPDATE);

View File

@ -152,9 +152,10 @@ void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod) DECLSPEC_
void ME_SetCursorToStart(ME_TextEditor *editor, ME_Cursor *cursor) DECLSPEC_HIDDEN;
int ME_SetSelection(ME_TextEditor *editor, int from, int to) DECLSPEC_HIDDEN;
BOOL ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) DECLSPEC_HIDDEN;
void ME_HideCaret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void ME_ShowCaret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void ME_MoveCaret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void hide_caret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void show_caret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void update_caret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
void create_caret(ME_TextEditor *ed) DECLSPEC_HIDDEN;
BOOL ME_CharFromPos(ME_TextEditor *editor, int x, int y, ME_Cursor *cursor, BOOL *isExact) DECLSPEC_HIDDEN;
void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) DECLSPEC_HIDDEN;
void ME_MouseMove(ME_TextEditor *editor, int x, int y) DECLSPEC_HIDDEN;

View File

@ -442,6 +442,8 @@ typedef struct tagME_TextEditor
/* Cache previously set scrollbar info */
SCROLLINFO vert_si, horz_si;
int caret_height;
BOOL caret_hidden;
BOOL bMouseCaptured;
int wheel_remain;
struct list style_list;

View File

@ -43,7 +43,6 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, const RECT *rcUpdate)
ME_InitContext(&c, editor, hDC);
SetBkMode(hDC, TRANSPARENT);
ME_MoveCaret(editor);
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. */

View File

@ -613,8 +613,7 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow)
}
ME_InvalidateSelection(editor);
ME_Repaint(editor);
ITextHost_TxShowCaret(editor->texthost, FALSE);
ME_ShowCaret(editor);
update_caret(editor);
ME_SendSelChange(editor);
}