riched20: Use row ptrs in the cursor from virtual co-ords 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-10-26 08:46:39 +00:00 committed by Alexandre Julliard
parent b47e5d0d23
commit 0fda889f35
4 changed files with 30 additions and 11 deletions

View File

@ -952,7 +952,7 @@ static BOOL cursor_from_virtual_coords( ME_TextEditor *editor, int x, int y,
ME_Cursor *result, BOOL final_eop ) ME_Cursor *result, BOOL final_eop )
{ {
ME_Paragraph *para = editor_first_para( editor ); ME_Paragraph *para = editor_first_para( editor );
ME_DisplayItem *row = NULL; ME_Row *row = NULL, *next_row;
BOOL isExact = TRUE; BOOL isExact = TRUE;
x -= editor->rcFormat.left; x -= editor->rcFormat.left;
@ -966,7 +966,7 @@ static BOOL cursor_from_virtual_coords( ME_TextEditor *editor, int x, int y,
if (para->nFlags & MEPF_ROWSTART) if (para->nFlags & MEPF_ROWSTART)
para = pixel_pos_in_table_row( x, y, para ); para = pixel_pos_in_table_row( x, y, para );
y -= para->pt.y; y -= para->pt.y;
row = ME_FindItemFwd( para_get_di( para ), diStartRow); row = para_first_row( para );
break; break;
} }
else if (para->nFlags & MEPF_ROWSTART) else if (para->nFlags & MEPF_ROWSTART)
@ -977,24 +977,22 @@ static BOOL cursor_from_virtual_coords( ME_TextEditor *editor, int x, int y,
/* find row */ /* find row */
while (row) while (row)
{ {
ME_DisplayItem *next_row; if (y < row->pt.y + row->nHeight) break;
next_row = row_next( row );
if (y < row->member.row.pt.y + row->member.row.nHeight) break;
next_row = ME_FindItemFwd(row, diStartRow);
if (!next_row) break; if (!next_row) break;
row = next_row; row = next_row;
} }
if (!row && !final_eop) if (!row && !final_eop && para_prev( para ))
{ {
/* The position is below the last paragraph, so the last row will be used /* The position is below the last paragraph, so the last row will be used
* rather than the end of the text, so the x position will be used to * rather than the end of the text, so the x position will be used to
* determine the offset closest to the pixel position. */ * determine the offset closest to the pixel position. */
isExact = FALSE; isExact = FALSE;
row = ME_FindItemBack( para_get_di( para ), diStartRow); row = para_end_row( para_prev( para ) );
} }
if (row) return row_cursor( editor, &row->member.row, x, result ) && isExact; if (row) return row_cursor( editor, row, x, result ) && isExact;
ME_SetCursorToEnd(editor, result, TRUE); ME_SetCursorToEnd(editor, result, TRUE);
return FALSE; return FALSE;

View File

@ -213,7 +213,9 @@ void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_
int get_total_width(ME_TextEditor *editor) DECLSPEC_HIDDEN; int get_total_width(ME_TextEditor *editor) DECLSPEC_HIDDEN;
ME_Cell *para_cell( ME_Paragraph *para ) DECLSPEC_HIDDEN; ME_Cell *para_cell( ME_Paragraph *para ) DECLSPEC_HIDDEN;
void para_destroy( ME_TextEditor *editor, ME_Paragraph *item ) DECLSPEC_HIDDEN; void para_destroy( ME_TextEditor *editor, ME_Paragraph *item ) DECLSPEC_HIDDEN;
ME_Row *para_end_row( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Run *para_end_run( ME_Paragraph *para ) DECLSPEC_HIDDEN; ME_Run *para_end_run( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Row *para_first_row( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Run *para_first_run( ME_Paragraph *para ) DECLSPEC_HIDDEN; ME_Run *para_first_run( ME_Paragraph *para ) DECLSPEC_HIDDEN;
BOOL para_in_table( ME_Paragraph *para ) DECLSPEC_HIDDEN; BOOL para_in_table( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Paragraph *para_join( ME_TextEditor *editor, ME_Paragraph *para, BOOL use_first_fmt ) DECLSPEC_HIDDEN; ME_Paragraph *para_join( ME_TextEditor *editor, ME_Paragraph *para, BOOL use_first_fmt ) DECLSPEC_HIDDEN;

View File

@ -130,6 +130,25 @@ ME_Cell *para_cell( ME_Paragraph *para )
return &para->pCell->member.cell; return &para->pCell->member.cell;
} }
ME_Row *para_first_row( ME_Paragraph *para )
{
ME_DisplayItem *item;
item = ME_FindItemFwd( para_get_di( para ), diStartRowOrParagraph );
if (!item || item->type != diStartRow) return NULL;
return &item->member.row;
}
ME_Row *para_end_row( ME_Paragraph *para )
{
ME_DisplayItem *item;
para = para_next( para );
item = ME_FindItemBack( para_get_di( para ), diStartRowOrParagraph );
if (!item || item->type != diStartRow) return NULL;
return &item->member.row;
}
void ME_MakeFirstParagraph(ME_TextEditor *editor) void ME_MakeFirstParagraph(ME_TextEditor *editor)
{ {
static const WCHAR cr_lf[] = {'\r','\n',0}; static const WCHAR cr_lf[] = {'\r','\n',0};

View File

@ -28,8 +28,8 @@ ME_Row *row_next( ME_Row *row )
{ {
ME_DisplayItem *item; ME_DisplayItem *item;
item = ME_FindItemFwd( row_get_di( row ), diStartRow ); item = ME_FindItemFwd( row_get_di( row ), diStartRowOrParagraphOrEnd );
if (!item) return NULL; if (!item || item->type != diStartRow) return NULL;
return &item->member.row; return &item->member.row;
} }