Commit 586e31a1 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Use the run and para helpers in the cursor movement functions.

parent 468609ae
...@@ -671,7 +671,7 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BO ...@@ -671,7 +671,7 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BO
{ {
/* new offset in the same paragraph */ /* new offset in the same paragraph */
do { do {
cursor->pRun = ME_FindItemBack(cursor->pRun, diRun); cursor->pRun = run_get_di( run_prev( &cursor->pRun->member.run ) );
} while (cursor->nOffset < cursor->pRun->member.run.nCharOfs); } while (cursor->nOffset < cursor->pRun->member.run.nCharOfs);
cursor->nOffset -= cursor->pRun->member.run.nCharOfs; cursor->nOffset -= cursor->pRun->member.run.nCharOfs;
return nRelOfs; return nRelOfs;
...@@ -688,27 +688,29 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BO ...@@ -688,27 +688,29 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BO
/* new offset in a previous paragraph */ /* new offset in a previous paragraph */
do { do {
cursor->pPara = cursor->pPara->member.para.prev_para; cursor->pPara = para_get_di( para_prev( &cursor->pPara->member.para ) );
} while (cursor->nOffset < cursor->pPara->member.para.nCharOfs); } while (cursor->nOffset < cursor->pPara->member.para.nCharOfs);
cursor->nOffset -= cursor->pPara->member.para.nCharOfs; cursor->nOffset -= cursor->pPara->member.para.nCharOfs;
cursor->pRun = ME_FindItemBack(cursor->pPara->member.para.next_para, diRun); cursor->pRun = run_get_di( para_end_run( &cursor->pPara->member.para ) );
while (cursor->nOffset < cursor->pRun->member.run.nCharOfs) { while (cursor->nOffset < cursor->pRun->member.run.nCharOfs) {
cursor->pRun = ME_FindItemBack(cursor->pRun, diRun); cursor->pRun = run_get_di( run_prev( &cursor->pRun->member.run ) );
} }
cursor->nOffset -= cursor->pRun->member.run.nCharOfs; cursor->nOffset -= cursor->pRun->member.run.nCharOfs;
} else if (cursor->nOffset >= cursor->pRun->member.run.len) { }
ME_DisplayItem *next_para; else if (cursor->nOffset >= cursor->pRun->member.run.len)
{
ME_Paragraph *next_para;
int new_offset; int new_offset;
new_offset = ME_GetCursorOfs(cursor); new_offset = ME_GetCursorOfs(cursor);
next_para = cursor->pPara->member.para.next_para; next_para = para_next( &cursor->pPara->member.para );
if (new_offset < next_para->member.para.nCharOfs) if (new_offset < next_para->nCharOfs)
{ {
/* new offset in the same paragraph */ /* new offset in the same paragraph */
do { do {
cursor->nOffset -= cursor->pRun->member.run.len; cursor->nOffset -= cursor->pRun->member.run.len;
cursor->pRun = ME_FindItemFwd(cursor->pRun, diRun); cursor->pRun = run_get_di( run_next( &cursor->pRun->member.run ) );
} while (cursor->nOffset >= cursor->pRun->member.run.len); } while (cursor->nOffset >= cursor->pRun->member.run.len);
return nRelOfs; return nRelOfs;
} }
...@@ -723,16 +725,16 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BO ...@@ -723,16 +725,16 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BO
/* new offset in a following paragraph */ /* new offset in a following paragraph */
do { do {
cursor->pPara = next_para; cursor->pPara = para_get_di( next_para );
next_para = next_para->member.para.next_para; next_para = para_next( next_para );
} while (new_offset >= next_para->member.para.nCharOfs); } while (new_offset >= next_para->nCharOfs);
cursor->nOffset = new_offset - cursor->pPara->member.para.nCharOfs; cursor->nOffset = new_offset - cursor->pPara->member.para.nCharOfs;
cursor->pRun = ME_FindItemFwd(cursor->pPara, diRun); cursor->pRun = run_get_di( para_first_run( &cursor->pPara->member.para ) );
while (cursor->nOffset >= cursor->pRun->member.run.len) while (cursor->nOffset >= cursor->pRun->member.run.len)
{ {
cursor->nOffset -= cursor->pRun->member.run.len; cursor->nOffset -= cursor->pRun->member.run.len;
cursor->pRun = ME_FindItemFwd(cursor->pRun, diRun); cursor->pRun = run_get_di( run_next( &cursor->pRun->member.run ) );
} }
} /* else new offset is in the same run */ } /* else new offset is in the same run */
return nRelOfs; return nRelOfs;
...@@ -742,8 +744,8 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BO ...@@ -742,8 +744,8 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BO
BOOL BOOL
ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
{ {
ME_DisplayItem *pRun = cursor->pRun, *pOtherRun; ME_Run *run = &cursor->pRun->member.run, *other_run;
ME_DisplayItem *pPara = cursor->pPara; ME_Paragraph *para = &cursor->pPara->member.para;
int nOffset = cursor->nOffset; int nOffset = cursor->nOffset;
if (nRelOfs == -1) if (nRelOfs == -1)
...@@ -751,40 +753,33 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) ...@@ -751,40 +753,33 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
/* Backward movement */ /* Backward movement */
while (TRUE) while (TRUE)
{ {
nOffset = ME_CallWordBreakProc(editor, get_text( &pRun->member.run, 0 ), nOffset = ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, nOffset, WB_MOVEWORDLEFT );
pRun->member.run.len, nOffset, WB_MOVEWORDLEFT); if (nOffset) break;
if (nOffset) other_run = run_prev( run );
break; if (other_run)
pOtherRun = ME_FindItemBack(pRun, diRunOrParagraph);
if (pOtherRun->type == diRun)
{ {
if (ME_CallWordBreakProc(editor, get_text( &pOtherRun->member.run, 0 ), if (ME_CallWordBreakProc( editor, get_text( other_run, 0 ), other_run->len, other_run->len - 1, WB_ISDELIMITER )
pOtherRun->member.run.len, && !(run->nFlags & MERF_ENDPARA)
pOtherRun->member.run.len - 1, && !(&cursor->pRun->member.run == run && cursor->nOffset == 0)
WB_ISDELIMITER) && !ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, 0, WB_ISDELIMITER ))
&& !(pRun->member.run.nFlags & MERF_ENDPARA)
&& !(cursor->pRun == pRun && cursor->nOffset == 0)
&& !ME_CallWordBreakProc(editor, get_text( &pRun->member.run, 0 ),
pRun->member.run.len, 0,
WB_ISDELIMITER))
break; break;
pRun = pOtherRun; run = other_run;
nOffset = pOtherRun->member.run.len; nOffset = other_run->len;
} }
else if (pOtherRun->type == diParagraph) else
{ {
if (cursor->pRun == pRun && cursor->nOffset == 0) if (&cursor->pRun->member.run == run && cursor->nOffset == 0)
{ {
pPara = pOtherRun; para = run->para;
/* Skip empty start of table row paragraph */ /* Skip empty start of table row paragraph */
if (pPara->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART) if (para_prev( para )->nFlags & MEPF_ROWSTART)
pPara = pPara->member.para.prev_para; para = para_prev( para );
/* Paragraph breaks are treated as separate words */ /* Paragraph breaks are treated as separate words */
if (pPara->member.para.prev_para->type == diTextStart) if (para_get_di( para_prev( para ) )->type == diTextStart)
return FALSE; return FALSE;
pRun = ME_FindItemBack(pPara, diRun); para = para_prev( para );
pPara = pPara->member.para.prev_para; run = para_end_run( para );
} }
break; break;
} }
...@@ -797,43 +792,35 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) ...@@ -797,43 +792,35 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
while (TRUE) while (TRUE)
{ {
if (last_delim && !ME_CallWordBreakProc(editor, get_text( &pRun->member.run, 0 ), if (last_delim && !ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, nOffset, WB_ISDELIMITER ))
pRun->member.run.len, nOffset, WB_ISDELIMITER))
break;
nOffset = ME_CallWordBreakProc(editor, get_text( &pRun->member.run, 0 ),
pRun->member.run.len, nOffset, WB_MOVEWORDRIGHT);
if (nOffset < pRun->member.run.len)
break; break;
pOtherRun = ME_FindItemFwd(pRun, diRunOrParagraphOrEnd); nOffset = ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, nOffset, WB_MOVEWORDRIGHT );
if (pOtherRun->type == diRun) if (nOffset < run->len) break;
other_run = run_next( run );
if (other_run)
{ {
last_delim = ME_CallWordBreakProc(editor, get_text( &pRun->member.run, 0 ), last_delim = ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, nOffset - 1, WB_ISDELIMITER );
pRun->member.run.len, nOffset - 1, WB_ISDELIMITER); run = other_run;
pRun = pOtherRun;
nOffset = 0; nOffset = 0;
} }
else if (pOtherRun->type == diParagraph) else
{ {
if (pOtherRun->member.para.nFlags & MEPF_ROWSTART) para = para_next( para );
pOtherRun = pOtherRun->member.para.next_para; if (para_get_di( para )->type == diTextEnd)
if (cursor->pRun == pRun) { {
pPara = pOtherRun; if (&cursor->pRun->member.run == run) return FALSE;
pRun = ME_FindItemFwd(pPara, diRun); nOffset = 0;
break;
} }
nOffset = 0; if (para->nFlags & MEPF_ROWSTART) para = para_next( para );
break; if (&cursor->pRun->member.run == run) run = para_first_run( para );
}
else /* diTextEnd */
{
if (cursor->pRun == pRun)
return FALSE;
nOffset = 0; nOffset = 0;
break; break;
} }
} }
} }
cursor->pPara = pPara; cursor->pPara = para_get_di( para );
cursor->pRun = pRun; cursor->pRun = run_get_di( run );
cursor->nOffset = nOffset; cursor->nOffset = nOffset;
return TRUE; return TRUE;
} }
......
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