riched20: Cache number of rows in editor.

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>
oldstable
Sergio Gómez Del Real 2018-11-29 08:44:54 -05:00 committed by Alexandre Julliard
parent 195f84cfa1
commit a60965a156
4 changed files with 12 additions and 17 deletions

View File

@ -3036,6 +3036,7 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
ed->styleFlags = 0; ed->styleFlags = 0;
ed->exStyleFlags = 0; ed->exStyleFlags = 0;
ed->first_marked_para = NULL; ed->first_marked_para = NULL;
ed->total_rows = 0;
ITextHost_TxGetPropertyBits(texthost, ITextHost_TxGetPropertyBits(texthost,
(TXTBIT_RICHTEXT|TXTBIT_MULTILINE| (TXTBIT_RICHTEXT|TXTBIT_MULTILINE|
TXTBIT_READONLY|TXTBIT_USEPASSWORD| TXTBIT_READONLY|TXTBIT_USEPASSWORD|
@ -4215,22 +4216,12 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
} }
case EM_GETLINECOUNT: case EM_GETLINECOUNT:
{ {
ME_DisplayItem *item = editor->pBuffer->pFirst->next; ME_DisplayItem *item = editor->pBuffer->pLast;
int nRows = 0; int nRows = editor->total_rows;
ME_DisplayItem *prev_para = NULL, *last_para = NULL; ME_DisplayItem *prev_para = NULL, *last_para = NULL;
while (item != editor->pBuffer->pLast)
{
assert(item->type == diParagraph);
prev_para = ME_FindItemBack(item, diRun);
if (prev_para) {
assert(prev_para->member.run.nFlags & MERF_ENDPARA);
}
nRows += item->member.para.nRows;
item = item->member.para.next_para;
}
last_para = ME_FindItemBack(item, diRun); last_para = ME_FindItemBack(item, diRun);
prev_para = ME_FindItemBack(last_para, diRun);
assert(last_para); assert(last_para);
assert(last_para->member.run.nFlags & MERF_ENDPARA); assert(last_para->member.run.nFlags & MERF_ENDPARA);
if (editor->bEmulateVersion10 && prev_para && if (editor->bEmulateVersion10 && prev_para &&

View File

@ -397,6 +397,7 @@ typedef struct tagME_TextEditor
int nTotalWidth, nLastTotalWidth; int nTotalWidth, nLastTotalWidth;
int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */ int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
int nUDArrowX; int nUDArrowX;
int total_rows;
COLORREF rgbBackColor; COLORREF rgbBackColor;
HBRUSH hbrBackground; HBRUSH hbrBackground;
BOOL bCaretAtEnd; BOOL bCaretAtEnd;

View File

@ -54,6 +54,7 @@ void destroy_para(ME_TextEditor *editor, ME_DisplayItem *item)
item->member.para.nWidth = 0; item->member.para.nWidth = 0;
editor->nTotalWidth = get_total_width(editor); editor->nTotalWidth = get_total_width(editor);
} }
editor->total_rows -= item->member.para.nRows;
ME_DestroyString(item->member.para.text); ME_DestroyString(item->member.para.text);
para_num_clear( &item->member.para.para_num ); para_num_clear( &item->member.para.para_num );
remove_marked_para(editor, item); remove_marked_para(editor, item);

View File

@ -733,12 +733,13 @@ static int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator; return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
} }
static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp) { static void ME_PrepareParagraphForWrapping(ME_TextEditor *editor, ME_Context *c, ME_DisplayItem *tp) {
ME_DisplayItem *p; ME_DisplayItem *p;
tp->member.para.nWidth = 0; tp->member.para.nWidth = 0;
/* remove row start items as they will be reinserted by the /* remove row start items as they will be reinserted by the
* paragraph wrapper anyway */ * paragraph wrapper anyway */
editor->total_rows -= tp->member.para.nRows;
tp->member.para.nRows = 0; tp->member.para.nRows = 0;
for (p = tp->next; p != tp->member.para.next_para; p = p->next) { for (p = tp->next; p != tp->member.para.next_para; p = p->next) {
if (p->type == diStartRow) { if (p->type == diStartRow) {
@ -870,7 +871,7 @@ static HRESULT shape_para( ME_Context *c, ME_DisplayItem *p )
return hr; return hr;
} }
static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp) { static void ME_WrapTextParagraph(ME_TextEditor *editor, ME_Context *c, ME_DisplayItem *tp) {
ME_DisplayItem *p; ME_DisplayItem *p;
ME_WrapContext wc; ME_WrapContext wc;
int border = 0; int border = 0;
@ -881,7 +882,7 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp) {
if (!(tp->member.para.nFlags & MEPF_REWRAP)) { if (!(tp->member.para.nFlags & MEPF_REWRAP)) {
return; return;
} }
ME_PrepareParagraphForWrapping(c, tp); ME_PrepareParagraphForWrapping(editor, c, tp);
/* Calculate paragraph numbering label */ /* Calculate paragraph numbering label */
para_num_init( c, &tp->member.para ); para_num_init( c, &tp->member.para );
@ -969,6 +970,7 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp) {
tp->member.para.nFlags &= ~MEPF_REWRAP; tp->member.para.nFlags &= ~MEPF_REWRAP;
tp->member.para.nHeight = wc.pt.y; tp->member.para.nHeight = wc.pt.y;
tp->member.para.nRows = wc.nRow; tp->member.para.nRows = wc.nRow;
editor->total_rows += wc.nRow;
} }
static void ME_MarkRepaintEnd(ME_DisplayItem *para, static void ME_MarkRepaintEnd(ME_DisplayItem *para,
@ -1114,7 +1116,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
assert(item->type == diParagraph); assert(item->type == diParagraph);
prev_width = item->member.para.nWidth; prev_width = item->member.para.nWidth;
ME_WrapTextParagraph(&c, item); ME_WrapTextParagraph(editor, &c, item);
if (prev_width == totalWidth && item->member.para.nWidth < totalWidth) if (prev_width == totalWidth && item->member.para.nWidth < totalWidth)
totalWidth = get_total_width(editor); totalWidth = get_total_width(editor);
else else