Commit fe2fd44e authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

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

parent c5b13787
......@@ -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:
{
......
......@@ -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 )
{
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment