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

riched20: Return a run ptr from the run creation function.

parent 3cade70f
...@@ -120,7 +120,7 @@ ME_DisplayItem *ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) DECLSPEC_H ...@@ -120,7 +120,7 @@ ME_DisplayItem *ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) DECLSPEC_H
int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN; int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
/* run.c */ /* run.c */
ME_DisplayItem *ME_MakeRun(ME_Style *s, int nFlags) DECLSPEC_HIDDEN; ME_Run *run_create( ME_Style *s, int nFlags ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_DisplayItem *ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor,
ME_Style *style, const WCHAR *str, int len, int flags) DECLSPEC_HIDDEN; ME_Style *style, const WCHAR *str, int len, int flags) DECLSPEC_HIDDEN;
void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN; void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN;
......
...@@ -131,7 +131,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) ...@@ -131,7 +131,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
HFONT hf; HFONT hf;
ME_TextBuffer *text = editor->pBuffer; ME_TextBuffer *text = editor->pBuffer;
ME_DisplayItem *para = make_para(editor); ME_DisplayItem *para = make_para(editor);
ME_DisplayItem *run; ME_Run *run;
ME_Style *style; ME_Style *style;
int eol_len; int eol_len;
...@@ -177,15 +177,14 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) ...@@ -177,15 +177,14 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
eol_len = editor->bEmulateVersion10 ? 2 : 1; eol_len = editor->bEmulateVersion10 ? 2 : 1;
para->member.para.text = ME_MakeStringN( cr_lf, eol_len ); para->member.para.text = ME_MakeStringN( cr_lf, eol_len );
run = ME_MakeRun(style, MERF_ENDPARA); run = run_create( style, MERF_ENDPARA );
run->member.run.nCharOfs = 0; run->nCharOfs = 0;
run->member.run.len = eol_len; run->len = eol_len;
run->member.run.para = &para->member.para; run->para = &para->member.para;
para->member.para.eop_run = run;
para->member.para.eop_run = &run->member.run;
ME_InsertBefore(text->pLast, para); ME_InsertBefore(text->pLast, para);
ME_InsertBefore(text->pLast, run); ME_InsertBefore(text->pLast, run_get_di( run ));
para->member.para.prev_para = text->pFirst; para->member.para.prev_para = text->pFirst;
para->member.para.next_para = text->pLast; para->member.para.next_para = text->pLast;
text->pFirst->member.para.next_para = para; text->pFirst->member.para.next_para = para;
...@@ -523,7 +522,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ...@@ -523,7 +522,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
ME_DisplayItem *next_para = NULL; ME_DisplayItem *next_para = NULL;
ME_DisplayItem *run_para = NULL; ME_DisplayItem *run_para = NULL;
ME_DisplayItem *new_para = make_para(editor); ME_DisplayItem *new_para = make_para(editor);
ME_DisplayItem *end_run; ME_Run *end_run;
int ofs, i; int ofs, i;
ME_DisplayItem *pp; ME_DisplayItem *pp;
int run_flags = MERF_ENDPARA; int run_flags = MERF_ENDPARA;
...@@ -549,10 +548,10 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ...@@ -549,10 +548,10 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
new_para->member.para.text = ME_VSplitString( run_para->member.para.text, run->member.run.nCharOfs ); new_para->member.para.text = ME_VSplitString( run_para->member.para.text, run->member.run.nCharOfs );
end_run = ME_MakeRun(style, run_flags); end_run = run_create( style, run_flags );
ofs = end_run->member.run.nCharOfs = run->member.run.nCharOfs; ofs = end_run->nCharOfs = run->member.run.nCharOfs;
end_run->member.run.len = eol_len; end_run->len = eol_len;
end_run->member.run.para = run->member.run.para; end_run->para = run->member.run.para;
ME_AppendString( run_para->member.para.text, eol_str, eol_len ); ME_AppendString( run_para->member.para.text, eol_str, eol_len );
next_para = run_para->member.para.next_para; next_para = run_para->member.para.next_para;
assert(next_para == ME_FindItemFwd(run_para, diParagraphOrEnd)); assert(next_para == ME_FindItemFwd(run_para, diParagraphOrEnd));
...@@ -592,11 +591,11 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ...@@ -592,11 +591,11 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
/* insert end run of the old paragraph, and new paragraph, into DI double linked list */ /* insert end run of the old paragraph, and new paragraph, into DI double linked list */
ME_InsertBefore(run, new_para); ME_InsertBefore(run, new_para);
ME_InsertBefore(new_para, end_run); ME_InsertBefore( new_para, run_get_di( end_run ));
/* Fix up the paras' eop_run ptrs */ /* Fix up the paras' eop_run ptrs */
new_para->member.para.eop_run = run_para->member.para.eop_run; new_para->member.para.eop_run = run_para->member.para.eop_run;
run_para->member.para.eop_run = &end_run->member.run; run_para->member.para.eop_run = end_run;
if (!editor->bEmulateVersion10) { /* v4.1 */ if (!editor->bEmulateVersion10) { /* v4.1 */
if (paraFlags & (MEPF_ROWSTART|MEPF_CELL)) if (paraFlags & (MEPF_ROWSTART|MEPF_CELL))
......
...@@ -273,63 +273,67 @@ void run_join( ME_TextEditor *editor, ME_Run *run ) ...@@ -273,63 +273,67 @@ void run_join( ME_TextEditor *editor, ME_Run *run )
* Does the most basic job of splitting a run into two - it does not * Does the most basic job of splitting a run into two - it does not
* update the positions and extents. * update the positions and extents.
*/ */
ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_Cursor *cursor) ME_DisplayItem *ME_SplitRunSimple( ME_TextEditor *editor, ME_Cursor *cursor )
{ {
ME_DisplayItem *run = cursor->pRun; ME_Run *run = &cursor->pRun->member.run, *new_run;
ME_DisplayItem *new_run; int i;
int i; int nOffset = cursor->nOffset;
int nOffset = cursor->nOffset;
assert( !(run->nFlags & MERF_NONTEXT) );
assert(!(run->member.run.nFlags & MERF_NONTEXT));
new_run = run_create( run->style, run->nFlags & MERF_SPLITMASK );
new_run = ME_MakeRun(run->member.run.style, new_run->nCharOfs = run->nCharOfs + nOffset;
run->member.run.nFlags & MERF_SPLITMASK); new_run->len = run->len - nOffset;
new_run->member.run.nCharOfs = run->member.run.nCharOfs + nOffset; new_run->para = run->para;
new_run->member.run.len = run->member.run.len - nOffset; run->len = nOffset;
new_run->member.run.para = run->member.run.para; cursor->pRun = run_get_di( new_run );
run->member.run.len = nOffset; cursor->nOffset = 0;
cursor->pRun = new_run;
cursor->nOffset = 0; ME_InsertBefore( run_get_di( run )->next, run_get_di( new_run ) );
ME_InsertBefore(run->next, new_run); ME_UpdateRunFlags( editor, run );
ME_UpdateRunFlags( editor, new_run );
ME_UpdateRunFlags(editor, &run->member.run); for (i = 0; i < editor->nCursors; i++)
ME_UpdateRunFlags(editor, &new_run->member.run); {
for (i = 0; i < editor->nCursors; i++) { if (editor->pCursors[i].pRun == run_get_di( run ) &&
if (editor->pCursors[i].pRun == run && editor->pCursors[i].nOffset >= nOffset)
editor->pCursors[i].nOffset >= nOffset) { {
editor->pCursors[i].pRun = new_run; editor->pCursors[i].pRun = run_get_di( new_run );
editor->pCursors[i].nOffset -= nOffset; editor->pCursors[i].nOffset -= nOffset;
}
} }
} para_mark_rewrap( editor, run->para );
para_mark_rewrap( editor, &cursor->pPara->member.para ); return run_get_di( run );
return run;
} }
/****************************************************************************** /******************************************************************************
* ME_MakeRun * run_create
* *
* A helper function to create run structures quickly. * A helper function to create run structures quickly.
*/ */
ME_DisplayItem *ME_MakeRun(ME_Style *s, int nFlags) ME_Run *run_create( ME_Style *s, int flags )
{ {
ME_DisplayItem *item = ME_MakeDI(diRun); ME_DisplayItem *item = ME_MakeDI( diRun );
item->member.run.style = s; ME_Run *run = &item->member.run;
item->member.run.reobj = NULL;
item->member.run.nFlags = nFlags; if (!item) return NULL;
item->member.run.nCharOfs = -1;
item->member.run.len = 0; ME_AddRefStyle( s );
item->member.run.para = NULL; run->style = s;
item->member.run.num_glyphs = 0; run->reobj = NULL;
item->member.run.max_glyphs = 0; run->nFlags = flags;
item->member.run.glyphs = NULL; run->nCharOfs = -1;
item->member.run.vis_attrs = NULL; run->len = 0;
item->member.run.advances = NULL; run->para = NULL;
item->member.run.offsets = NULL; run->num_glyphs = 0;
item->member.run.max_clusters = 0; run->max_glyphs = 0;
item->member.run.clusters = NULL; run->glyphs = NULL;
ME_AddRefStyle(s); run->vis_attrs = NULL;
return item; run->advances = NULL;
run->offsets = NULL;
run->max_clusters = 0;
run->clusters = NULL;
return run;
} }
/****************************************************************************** /******************************************************************************
...@@ -343,7 +347,8 @@ ME_DisplayItem * ...@@ -343,7 +347,8 @@ ME_DisplayItem *
ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style, ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
const WCHAR *str, int len, int flags) const WCHAR *str, int len, int flags)
{ {
ME_DisplayItem *pDI, *insert_before = cursor->pRun, *prev; ME_DisplayItem *insert_before = cursor->pRun, *prev;
ME_Run *run;
if (cursor->nOffset) if (cursor->nOffset)
{ {
...@@ -362,18 +367,18 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style, ...@@ -362,18 +367,18 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
add_undo_delete_run( editor, insert_before->member.run.para->nCharOfs + add_undo_delete_run( editor, insert_before->member.run.para->nCharOfs +
insert_before->member.run.nCharOfs, len ); insert_before->member.run.nCharOfs, len );
pDI = ME_MakeRun(style, flags); run = run_create( style, flags );
pDI->member.run.nCharOfs = insert_before->member.run.nCharOfs; run->nCharOfs = insert_before->member.run.nCharOfs;
pDI->member.run.len = len; run->len = len;
pDI->member.run.para = insert_before->member.run.para; run->para = insert_before->member.run.para;
ME_InsertString( pDI->member.run.para->text, pDI->member.run.nCharOfs, str, len ); ME_InsertString( run->para->text, run->nCharOfs, str, len );
ME_InsertBefore( insert_before, pDI ); ME_InsertBefore( insert_before, run_get_di( run ) );
TRACE("Shift length:%d\n", len); TRACE("Shift length:%d\n", len);
ME_PropagateCharOffset( insert_before, len ); ME_PropagateCharOffset( insert_before, len );
para_mark_rewrap( editor, insert_before->member.run.para ); para_mark_rewrap( editor, insert_before->member.run.para );
/* Move any cursors that were at the end of the previous run to the end of the inserted run */ /* Move any cursors that were at the end of the previous run to the end of the inserted run */
prev = ME_FindItemBack( pDI, diRun ); prev = ME_FindItemBack( run_get_di( run ), diRun );
if (prev) if (prev)
{ {
int i; int i;
...@@ -383,13 +388,13 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style, ...@@ -383,13 +388,13 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
if (editor->pCursors[i].pRun == prev && if (editor->pCursors[i].pRun == prev &&
editor->pCursors[i].nOffset == prev->member.run.len) editor->pCursors[i].nOffset == prev->member.run.len)
{ {
editor->pCursors[i].pRun = pDI; editor->pCursors[i].pRun = run_get_di( run );
editor->pCursors[i].nOffset = len; editor->pCursors[i].nOffset = len;
} }
} }
} }
return pDI; return run_get_di( run );
} }
static BOOL run_is_splittable( const ME_Run *run ) static BOOL run_is_splittable( const ME_Run *run )
......
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