Huw Davies : riched20: Return a row ptr from the row from row number function.
Alexandre Julliard
julliard at winehq.org
Mon Nov 2 16:21:19 CST 2020
Module: wine
Branch: master
Commit: fe2fd44e0a30c519c3b650f69f0e94a6212cc7b0
URL: https://source.winehq.org/git/wine.git/?a=commit;h=fe2fd44e0a30c519c3b650f69f0e94a6212cc7b0
Author: Huw Davies <huw at codeweavers.com>
Date: Mon Nov 2 08:23:17 2020 +0000
riched20: Return a row ptr from the row from row number function.
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/riched20/editor.c | 48 +++++++++++++++++++++++++++---------------------
dlls/riched20/editor.h | 2 +-
dlls/riched20/row.c | 42 +++++++++++++++---------------------------
3 files changed, 43 insertions(+), 49 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 620cb4fedcb..c01bd873634 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -4237,26 +4237,32 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
case EM_GETLINE:
{
- ME_DisplayItem *run;
+ ME_Row *row;
+ ME_Run *run;
const unsigned int nMaxChars = *(WORD *) lParam;
unsigned int nCharsLeft = nMaxChars;
char *dest = (char *) lParam;
BOOL wroteNull = FALSE;
+ ME_Cursor start, end;
TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam, nMaxChars,
unicode ? "Unicode" : "Ansi");
- run = ME_FindRowWithNumber(editor, wParam);
- if (run == NULL)
- return 0;
+ row = row_from_row_number( editor, wParam );
+ if (row == NULL) return 0;
- while (nCharsLeft && (run = ME_FindItemFwd(run, diRunOrStartRow))
- && run->type == diRun)
+ row_first_cursor( row, &start );
+ 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;
+ 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)
memcpy(dest, str, nCopy * sizeof(WCHAR));
@@ -4265,6 +4271,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
nCharsLeft, NULL, NULL);
dest += nCopy * (unicode ? sizeof(WCHAR) : 1);
nCharsLeft -= nCopy;
+ if (run == &end.pRun->member.run) break;
+ run = row_next_run( row, run );
}
/* append line termination, space allowing */
@@ -4321,20 +4329,18 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
case EM_LINEINDEX:
{
- ME_DisplayItem *item, *para;
- int nCharOfs;
+ ME_Row *row;
+ ME_Cursor cursor;
+ int ofs;
- if (wParam == -1)
- item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow);
- else
- item = ME_FindRowWithNumber(editor, wParam);
- if (!item)
- return -1;
- para = ME_GetParagraph(item);
- item = ME_FindItemFwd(item, diRun);
- nCharOfs = para->member.para.nCharOfs + item->member.run.nCharOfs;
- TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs);
- return nCharOfs;
+ if (wParam == -1) row = row_from_cursor( editor->pCursors );
+ else row = row_from_row_number( editor, wParam );
+ if (!row) return -1;
+
+ row_first_cursor( row, &cursor );
+ ofs = ME_GetCursorOfs( &cursor );
+ TRACE( "EM_LINEINDEX: nCharOfs==%d\n", ofs );
+ return ofs;
}
case EM_LINELENGTH:
{
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 5f93aa39db9..d0d34ac5afc 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -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;
ME_Run *row_first_run( ME_Row *row ) 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_Run *row_next_run( ME_Row *row, ME_Run *run ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) DECLSPEC_HIDDEN;
/* 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;
static inline ME_DisplayItem *row_get_di( ME_Row *row )
{
diff --git a/dlls/riched20/row.c b/dlls/riched20/row.c
index ba082244cfc..2c77962b56b 100644
--- a/dlls/riched20/row.c
+++ b/dlls/riched20/row.c
@@ -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;
}
-/* 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) {
return ME_FindItemBackOrHere(item, diStartRow);
}
-/*
-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_Row *row_from_row_number( ME_TextEditor *editor, int row_num )
{
- ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
- int nCount = 0;
+ ME_Paragraph *para = editor_first_para( editor );
+ ME_Row *row;
+ int count = 0;
- while (item->type == diParagraph &&
- nCount + item->member.para.nRows <= nRow)
- {
- nCount += item->member.para.nRows;
- item = item->member.para.next_para;
- }
- if (item->type != diParagraph)
- return NULL;
- for (item = ME_FindItemFwd(item, diStartRow); item && nCount < nRow; nCount++)
- item = ME_FindItemFwd(item, diStartRow);
- return item;
+ while (para_next( para ) && count + para->nRows <= row_num)
+ {
+ count += para->nRows;
+ para = para_next( para );
+ }
+ if (!para_next( para )) return NULL;
+
+ for (row = para_first_row( para ); row && count < row_num; count++)
+ row = row_next( row );
+
+ return row;
}
More information about the wine-cvs
mailing list