riched20: Return a row ptr from the row from row number function.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-11-02 08:23:17 +00:00 committed by Alexandre Julliard
parent c5b1378756
commit fe2fd44e0a
3 changed files with 43 additions and 49 deletions

View File

@ -4237,26 +4237,32 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
} }
case EM_GETLINE: case EM_GETLINE:
{ {
ME_DisplayItem *run; ME_Row *row;
ME_Run *run;
const unsigned int nMaxChars = *(WORD *) lParam; const unsigned int nMaxChars = *(WORD *) lParam;
unsigned int nCharsLeft = nMaxChars; unsigned int nCharsLeft = nMaxChars;
char *dest = (char *) lParam; char *dest = (char *) lParam;
BOOL wroteNull = FALSE; BOOL wroteNull = FALSE;
ME_Cursor start, end;
TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam, nMaxChars, TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam, nMaxChars,
unicode ? "Unicode" : "Ansi"); unicode ? "Unicode" : "Ansi");
run = ME_FindRowWithNumber(editor, wParam); row = row_from_row_number( editor, wParam );
if (run == NULL) if (row == NULL) return 0;
return 0;
while (nCharsLeft && (run = ME_FindItemFwd(run, diRunOrStartRow)) row_first_cursor( row, &start );
&& run->type == diRun) row_end_cursor( row, &end, TRUE );
run = &start.pRun->member.run;
while (nCharsLeft)
{ {
WCHAR *str = get_text( &run->member.run, 0 ); WCHAR *str;
unsigned int nCopy; unsigned int nCopy;
int ofs = (run == &start.pRun->member.run) ? start.nOffset : 0;
int len = (run == &end.pRun->member.run) ? end.nOffset : run->len;
nCopy = min(nCharsLeft, run->member.run.len); str = get_text( run, ofs );
nCopy = min( nCharsLeft, len );
if (unicode) if (unicode)
memcpy(dest, str, nCopy * sizeof(WCHAR)); memcpy(dest, str, nCopy * sizeof(WCHAR));
@ -4265,6 +4271,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
nCharsLeft, NULL, NULL); nCharsLeft, NULL, NULL);
dest += nCopy * (unicode ? sizeof(WCHAR) : 1); dest += nCopy * (unicode ? sizeof(WCHAR) : 1);
nCharsLeft -= nCopy; nCharsLeft -= nCopy;
if (run == &end.pRun->member.run) break;
run = row_next_run( row, run );
} }
/* append line termination, space allowing */ /* append line termination, space allowing */
@ -4321,20 +4329,18 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
} }
case EM_LINEINDEX: case EM_LINEINDEX:
{ {
ME_DisplayItem *item, *para; ME_Row *row;
int nCharOfs; ME_Cursor cursor;
int ofs;
if (wParam == -1) if (wParam == -1) row = row_from_cursor( editor->pCursors );
item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow); else row = row_from_row_number( editor, wParam );
else if (!row) return -1;
item = ME_FindRowWithNumber(editor, wParam);
if (!item) row_first_cursor( row, &cursor );
return -1; ofs = ME_GetCursorOfs( &cursor );
para = ME_GetParagraph(item); TRACE( "EM_LINEINDEX: nCharOfs==%d\n", ofs );
item = ME_FindItemFwd(item, diRun); return ofs;
nCharOfs = para->member.para.nCharOfs + item->member.run.nCharOfs;
TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs);
return nCharOfs;
} }
case EM_LINELENGTH: case EM_LINELENGTH:
{ {

View File

@ -115,11 +115,11 @@ void row_end_cursor( ME_Row *row, ME_Cursor *cursor, BOOL include_eop ) DECLSPEC
void row_first_cursor( ME_Row *row, ME_Cursor *cursor ) DECLSPEC_HIDDEN; void row_first_cursor( ME_Row *row, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
ME_Run *row_first_run( ME_Row *row ) DECLSPEC_HIDDEN; ME_Run *row_first_run( ME_Row *row ) DECLSPEC_HIDDEN;
ME_Row *row_from_cursor( ME_Cursor *cursor ) DECLSPEC_HIDDEN; ME_Row *row_from_cursor( ME_Cursor *cursor ) DECLSPEC_HIDDEN;
ME_Row *row_from_row_number( ME_TextEditor *editor, int row_num ) DECLSPEC_HIDDEN;
ME_Row *row_next( ME_Row *row ) DECLSPEC_HIDDEN; ME_Row *row_next( ME_Row *row ) DECLSPEC_HIDDEN;
ME_Run *row_next_run( ME_Row *row, ME_Run *run ) DECLSPEC_HIDDEN; ME_Run *row_next_run( ME_Row *row, ME_Run *run ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) DECLSPEC_HIDDEN; ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) DECLSPEC_HIDDEN;
/* ME_DisplayItem *ME_RowEnd(ME_DisplayItem *item); */ /* ME_DisplayItem *ME_RowEnd(ME_DisplayItem *item); */
ME_DisplayItem *ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) DECLSPEC_HIDDEN;
int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN; int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
static inline ME_DisplayItem *row_get_di( ME_Row *row ) static inline ME_DisplayItem *row_get_di( ME_Row *row )
{ {

View File

@ -82,39 +82,27 @@ void row_end_cursor( ME_Row *row, ME_Cursor *cursor, BOOL include_eop )
cursor->nOffset = (item->type == diStartRow || include_eop) ? cursor->pRun->member.run.len : 0; cursor->nOffset = (item->type == diStartRow || include_eop) ? cursor->pRun->member.run.len : 0;
} }
/* I'm sure these functions would simplify some code in caret ops etc,
* I just didn't remember them when I wrote that code
*/
ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) { ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) {
return ME_FindItemBackOrHere(item, diStartRow); return ME_FindItemBackOrHere(item, diStartRow);
} }
/* ME_Row *row_from_row_number( ME_TextEditor *editor, int row_num )
ME_DisplayItem *ME_RowEnd(ME_DisplayItem *item) {
ME_DisplayItem *item2 = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
if (!item2) return NULL;
return ME_FindItemBack(item, diRun);
}
*/
ME_DisplayItem *
ME_FindRowWithNumber(ME_TextEditor *editor, int nRow)
{ {
ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph); ME_Paragraph *para = editor_first_para( editor );
int nCount = 0; ME_Row *row;
int count = 0;
while (item->type == diParagraph && while (para_next( para ) && count + para->nRows <= row_num)
nCount + item->member.para.nRows <= nRow) {
{ count += para->nRows;
nCount += item->member.para.nRows; para = para_next( para );
item = item->member.para.next_para; }
} if (!para_next( para )) return NULL;
if (item->type != diParagraph)
return NULL; for (row = para_first_row( para ); row && count < row_num; count++)
for (item = ME_FindItemFwd(item, diStartRow); item && nCount < nRow; nCount++) row = row_next( row );
item = ME_FindItemFwd(item, diStartRow);
return item; return row;
} }