[PATCH 5/5] riched20: Return a run ptr from the run creation function.
Huw Davies
huw at codeweavers.com
Tue Oct 13 05:16:37 CDT 2020
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
dlls/riched20/editor.h | 2 +-
dlls/riched20/para.c | 29 +++++-----
dlls/riched20/run.c | 121 +++++++++++++++++++++--------------------
3 files changed, 78 insertions(+), 74 deletions(-)
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index de029f5bcb4..244010df735 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.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;
/* 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_Style *style, const WCHAR *str, int len, int flags) DECLSPEC_HIDDEN;
void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index 1ae7caad618..99ce1706631 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -131,7 +131,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
HFONT hf;
ME_TextBuffer *text = editor->pBuffer;
ME_DisplayItem *para = make_para(editor);
- ME_DisplayItem *run;
+ ME_Run *run;
ME_Style *style;
int eol_len;
@@ -177,15 +177,14 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
eol_len = editor->bEmulateVersion10 ? 2 : 1;
para->member.para.text = ME_MakeStringN( cr_lf, eol_len );
- run = ME_MakeRun(style, MERF_ENDPARA);
- run->member.run.nCharOfs = 0;
- run->member.run.len = eol_len;
- run->member.run.para = ¶->member.para;
-
- para->member.para.eop_run = &run->member.run;
+ run = run_create( style, MERF_ENDPARA );
+ run->nCharOfs = 0;
+ run->len = eol_len;
+ run->para = ¶->member.para;
+ para->member.para.eop_run = run;
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.next_para = text->pLast;
text->pFirst->member.para.next_para = para;
@@ -523,7 +522,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
ME_DisplayItem *next_para = NULL;
ME_DisplayItem *run_para = NULL;
ME_DisplayItem *new_para = make_para(editor);
- ME_DisplayItem *end_run;
+ ME_Run *end_run;
int ofs, i;
ME_DisplayItem *pp;
int run_flags = MERF_ENDPARA;
@@ -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 );
- end_run = ME_MakeRun(style, run_flags);
- ofs = end_run->member.run.nCharOfs = run->member.run.nCharOfs;
- end_run->member.run.len = eol_len;
- end_run->member.run.para = run->member.run.para;
+ end_run = run_create( style, run_flags );
+ ofs = end_run->nCharOfs = run->member.run.nCharOfs;
+ end_run->len = eol_len;
+ end_run->para = run->member.run.para;
ME_AppendString( run_para->member.para.text, eol_str, eol_len );
next_para = run_para->member.para.next_para;
assert(next_para == ME_FindItemFwd(run_para, diParagraphOrEnd));
@@ -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 */
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 */
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 (paraFlags & (MEPF_ROWSTART|MEPF_CELL))
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index eb5aeff0502..84b851039b7 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -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
* 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_DisplayItem *new_run;
- int i;
- int nOffset = cursor->nOffset;
-
- assert(!(run->member.run.nFlags & MERF_NONTEXT));
-
- new_run = ME_MakeRun(run->member.run.style,
- run->member.run.nFlags & MERF_SPLITMASK);
- new_run->member.run.nCharOfs = run->member.run.nCharOfs + nOffset;
- new_run->member.run.len = run->member.run.len - nOffset;
- new_run->member.run.para = run->member.run.para;
- run->member.run.len = nOffset;
- cursor->pRun = new_run;
- cursor->nOffset = 0;
-
- ME_InsertBefore(run->next, new_run);
-
- ME_UpdateRunFlags(editor, &run->member.run);
- ME_UpdateRunFlags(editor, &new_run->member.run);
- for (i = 0; i < editor->nCursors; i++) {
- if (editor->pCursors[i].pRun == run &&
- editor->pCursors[i].nOffset >= nOffset) {
- editor->pCursors[i].pRun = new_run;
- editor->pCursors[i].nOffset -= nOffset;
+ ME_Run *run = &cursor->pRun->member.run, *new_run;
+ int i;
+ int nOffset = cursor->nOffset;
+
+ assert( !(run->nFlags & MERF_NONTEXT) );
+
+ new_run = run_create( run->style, run->nFlags & MERF_SPLITMASK );
+ new_run->nCharOfs = run->nCharOfs + nOffset;
+ new_run->len = run->len - nOffset;
+ new_run->para = run->para;
+ run->len = nOffset;
+ cursor->pRun = run_get_di( new_run );
+ cursor->nOffset = 0;
+
+ ME_InsertBefore( run_get_di( run )->next, run_get_di( new_run ) );
+
+ ME_UpdateRunFlags( editor, run );
+ ME_UpdateRunFlags( editor, new_run );
+ for (i = 0; i < editor->nCursors; i++)
+ {
+ if (editor->pCursors[i].pRun == run_get_di( run ) &&
+ editor->pCursors[i].nOffset >= nOffset)
+ {
+ editor->pCursors[i].pRun = run_get_di( new_run );
+ editor->pCursors[i].nOffset -= nOffset;
+ }
}
- }
- para_mark_rewrap( editor, &cursor->pPara->member.para );
- return run;
+ para_mark_rewrap( editor, run->para );
+ return run_get_di( run );
}
/******************************************************************************
- * ME_MakeRun
+ * run_create
*
* 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);
- item->member.run.style = s;
- item->member.run.reobj = NULL;
- item->member.run.nFlags = nFlags;
- item->member.run.nCharOfs = -1;
- item->member.run.len = 0;
- item->member.run.para = NULL;
- item->member.run.num_glyphs = 0;
- item->member.run.max_glyphs = 0;
- item->member.run.glyphs = NULL;
- item->member.run.vis_attrs = NULL;
- item->member.run.advances = NULL;
- item->member.run.offsets = NULL;
- item->member.run.max_clusters = 0;
- item->member.run.clusters = NULL;
- ME_AddRefStyle(s);
- return item;
+ ME_DisplayItem *item = ME_MakeDI( diRun );
+ ME_Run *run = &item->member.run;
+
+ if (!item) return NULL;
+
+ ME_AddRefStyle( s );
+ run->style = s;
+ run->reobj = NULL;
+ run->nFlags = flags;
+ run->nCharOfs = -1;
+ run->len = 0;
+ run->para = NULL;
+ run->num_glyphs = 0;
+ run->max_glyphs = 0;
+ run->glyphs = NULL;
+ run->vis_attrs = NULL;
+ run->advances = NULL;
+ run->offsets = NULL;
+ run->max_clusters = 0;
+ run->clusters = NULL;
+ return run;
}
/******************************************************************************
@@ -343,7 +347,8 @@ ME_DisplayItem *
ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
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)
{
@@ -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 +
insert_before->member.run.nCharOfs, len );
- pDI = ME_MakeRun(style, flags);
- pDI->member.run.nCharOfs = insert_before->member.run.nCharOfs;
- pDI->member.run.len = len;
- pDI->member.run.para = insert_before->member.run.para;
- ME_InsertString( pDI->member.run.para->text, pDI->member.run.nCharOfs, str, len );
- ME_InsertBefore( insert_before, pDI );
+ run = run_create( style, flags );
+ run->nCharOfs = insert_before->member.run.nCharOfs;
+ run->len = len;
+ run->para = insert_before->member.run.para;
+ ME_InsertString( run->para->text, run->nCharOfs, str, len );
+ ME_InsertBefore( insert_before, run_get_di( run ) );
TRACE("Shift length:%d\n", len);
ME_PropagateCharOffset( insert_before, len );
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 */
- prev = ME_FindItemBack( pDI, diRun );
+ prev = ME_FindItemBack( run_get_di( run ), diRun );
if (prev)
{
int i;
@@ -383,13 +388,13 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
if (editor->pCursors[i].pRun == prev &&
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;
}
}
}
- return pDI;
+ return run_get_di( run );
}
static BOOL run_is_splittable( const ME_Run *run )
--
2.23.0
More information about the wine-devel
mailing list