[PATCH 2/5] riched20: Use row ptrs in the cursor from virtual co-ords function.
Huw Davies
huw at codeweavers.com
Mon Oct 26 03:46:39 CDT 2020
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
dlls/riched20/caret.c | 16 +++++++---------
dlls/riched20/editor.h | 2 ++
dlls/riched20/para.c | 19 +++++++++++++++++++
dlls/riched20/row.c | 4 ++--
4 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 0c5f221a7c4..5af4cd04d55 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -952,7 +952,7 @@ static BOOL cursor_from_virtual_coords( ME_TextEditor *editor, int x, int y,
ME_Cursor *result, BOOL final_eop )
{
ME_Paragraph *para = editor_first_para( editor );
- ME_DisplayItem *row = NULL;
+ ME_Row *row = NULL, *next_row;
BOOL isExact = TRUE;
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)
para = pixel_pos_in_table_row( x, y, para );
y -= para->pt.y;
- row = ME_FindItemFwd( para_get_di( para ), diStartRow);
+ row = para_first_row( para );
break;
}
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 */
while (row)
{
- ME_DisplayItem *next_row;
-
- if (y < row->member.row.pt.y + row->member.row.nHeight) break;
- next_row = ME_FindItemFwd(row, diStartRow);
+ if (y < row->pt.y + row->nHeight) break;
+ next_row = row_next( row );
if (!next_row) break;
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
* rather than the end of the text, so the x position will be used to
* determine the offset closest to the pixel position. */
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);
return FALSE;
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index cf5e2d84fc2..7025ddceea7 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -213,7 +213,9 @@ void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_
int get_total_width(ME_TextEditor *editor) DECLSPEC_HIDDEN;
ME_Cell *para_cell( ME_Paragraph *para ) 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_Row *para_first_row( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Run *para_first_run( 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;
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index db258947916..e1b848cf8f9 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -130,6 +130,25 @@ ME_Cell *para_cell( ME_Paragraph *para )
return ¶->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)
{
static const WCHAR cr_lf[] = {'\r','\n',0};
diff --git a/dlls/riched20/row.c b/dlls/riched20/row.c
index a149231dcbe..ce8de935a19 100644
--- a/dlls/riched20/row.c
+++ b/dlls/riched20/row.c
@@ -28,8 +28,8 @@ ME_Row *row_next( ME_Row *row )
{
ME_DisplayItem *item;
- item = ME_FindItemFwd( row_get_di( row ), diStartRow );
- if (!item) return NULL;
+ item = ME_FindItemFwd( row_get_di( row ), diStartRowOrParagraphOrEnd );
+ if (!item || item->type != diStartRow) return NULL;
return &item->member.row;
}
--
2.23.0
More information about the wine-devel
mailing list