Commit 12dd2d5d authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Add next / prev run from cursor helpers.

parent 3131f919
......@@ -5423,7 +5423,7 @@ static BOOL ME_FindNextURLCandidate(ME_TextEditor *editor,
}
cursor.nOffset = 0;
if (!ME_NextRun(&cursor.pPara, &cursor.pRun, TRUE))
if (!cursor_next_run( &cursor, TRUE ))
goto done;
}
......
......@@ -67,8 +67,6 @@ void ME_CharFormatFromLogFont(HDC hDC, const LOGFONTW *lf, CHARFORMAT2W *fmt) DE
/* list.c */
void ME_InsertBefore(ME_DisplayItem *diWhere, ME_DisplayItem *diWhat) DECLSPEC_HIDDEN;
void ME_Remove(ME_DisplayItem *diWhere) DECLSPEC_HIDDEN;
BOOL ME_NextRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para) DECLSPEC_HIDDEN;
BOOL ME_PrevRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_FindItemBackOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN;
......@@ -126,7 +124,8 @@ static inline ME_DisplayItem *row_get_di( ME_Row *row )
/* run.c */
void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
BOOL cursor_next_run( ME_Cursor *cursor, BOOL all_para ) DECLSPEC_HIDDEN;
BOOL cursor_prev_run( ME_Cursor *cursor, BOOL all_para ) DECLSPEC_HIDDEN;
int run_char_ofs( ME_Run *run, int ofs ) DECLSPEC_HIDDEN;
ME_Run *run_create( ME_Style *s, int nFlags ) DECLSPEC_HIDDEN;
ME_Run *run_insert( ME_TextEditor *editor, ME_Cursor *cursor,
......
......@@ -63,51 +63,6 @@ static BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass)
}
}
/* Modifies run pointer to point to the next run.
* If all_para is FALSE constrain the search to the current para,
* otherwise modify the paragraph pointer if moving into the next paragraph.
*
* Returns TRUE if next run is found, otherwise returns FALSE. */
BOOL ME_NextRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para)
{
ME_DisplayItem *p = (*run)->next;
while (p->type != diTextEnd)
{
if (p->type == diParagraph) {
if (!all_para) return FALSE;
*para = p;
} else if (p->type == diRun) {
*run = p;
return TRUE;
}
p = p->next;
}
return FALSE;
}
/* Modifies run pointer to point to the previous run.
* If all_para is FALSE constrain the search to the current para,
* otherwise modify the paragraph pointer if moving into the previous paragraph.
*
* Returns TRUE if previous run is found, otherwise returns FALSE. */
BOOL ME_PrevRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para)
{
ME_DisplayItem *p = (*run)->prev;
while (p->type != diTextStart)
{
if (p->type == diParagraph) {
if (!all_para) return FALSE;
if (para && p->member.para.prev_para->type == diParagraph)
*para = p->member.para.prev_para;
} else if (p->type == diRun) {
*run = p;
return TRUE;
}
p = p->prev;
}
return FALSE;
}
ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass)
{
if (!di)
......
......@@ -27,42 +27,96 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit);
WINE_DECLARE_DEBUG_CHANNEL(richedit_check);
WINE_DECLARE_DEBUG_CHANNEL(richedit_lists);
BOOL cursor_next_run( ME_Cursor *cursor, BOOL all_para )
{
ME_DisplayItem *p = cursor->pRun->next;
while (p->type != diTextEnd)
{
if (p->type == diParagraph && !all_para) return FALSE;
else if (p->type == diRun)
{
cursor->pRun = p;
cursor->pPara = para_get_di( cursor->pRun->member.run.para );
cursor->nOffset = 0;
return TRUE;
}
p = p->next;
}
return FALSE;
}
BOOL cursor_prev_run( ME_Cursor *cursor, BOOL all_para )
{
ME_DisplayItem *p = cursor->pRun->prev;
while (p->type != diTextStart)
{
if (p->type == diParagraph && !all_para) return FALSE;
else if (p->type == diRun)
{
cursor->pRun = p;
cursor->pPara = para_get_di( cursor->pRun->member.run.para );
cursor->nOffset = 0;
return TRUE;
}
p = p->prev;
}
return FALSE;
}
ME_Run *run_next( ME_Run *run )
{
ME_DisplayItem *item = run_get_di( run );
ME_Cursor cursor;
cursor.pRun = run_get_di( run );
cursor.pPara = para_get_di( run->para );
cursor.nOffset = 0;
if (ME_NextRun( NULL, &item, FALSE ))
return &item->member.run;
if (cursor_next_run( &cursor, FALSE ))
return &cursor.pRun->member.run;
return NULL;
}
ME_Run *run_prev( ME_Run *run )
{
ME_DisplayItem *item = run_get_di( run );
ME_Cursor cursor;
if (ME_PrevRun( NULL, &item, FALSE ))
return &item->member.run;
cursor.pRun = run_get_di( run );
cursor.pPara = para_get_di( run->para );
cursor.nOffset = 0;
if (cursor_prev_run( &cursor, FALSE ))
return &cursor.pRun->member.run;
return NULL;
}
ME_Run *run_next_all_paras( ME_Run *run )
{
ME_DisplayItem *item = run_get_di( run ), *dummy = para_get_di( run->para );
ME_Cursor cursor;
cursor.pRun = run_get_di( run );
cursor.pPara = para_get_di( run->para );
cursor.nOffset = 0;
if (ME_NextRun( &dummy, &item, TRUE ))
return &item->member.run;
if (cursor_next_run( &cursor, TRUE ))
return &cursor.pRun->member.run;
return NULL;
}
ME_Run *run_prev_all_paras( ME_Run *run )
{
ME_DisplayItem *item = run_get_di( run ), *dummy = para_get_di( run->para );
ME_Cursor cursor;
cursor.pRun = run_get_di( run );
cursor.pPara = para_get_di( run->para );
cursor.nOffset = 0;
if (ME_PrevRun( &dummy, &item, TRUE ))
return &item->member.run;
if (cursor_prev_run( &cursor, TRUE ))
return &cursor.pRun->member.run;
return NULL;
}
......
......@@ -1107,7 +1107,7 @@ static BOOL ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream,
return FALSE;
cursor.nOffset = 0;
}
} while (cursor.pRun != endCur.pRun && ME_NextRun(&cursor.pPara, &cursor.pRun, TRUE));
} while (cursor.pRun != endCur.pRun && cursor_next_run( &cursor, TRUE ));
if (!ME_StreamOutMove(pStream, "}\0", 2))
return FALSE;
......
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