Wine-Devel
Threads by month
- ----- 2026 -----
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
October 2020
- 82 participants
- 799 discussions
Oct. 15, 2020
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/caret.c | 110 +++++++++++++++++++-----------------------
1 file changed, 49 insertions(+), 61 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index d66dd57383b..4764dec8f33 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -460,20 +460,6 @@ BOOL ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars)
nChars, FALSE);
}
-static ME_DisplayItem *
-ME_InternalInsertTextFromCursor(ME_TextEditor *editor, int nCursor,
- const WCHAR *str, int len, ME_Style *style,
- int flags)
-{
- ME_Cursor *p = &editor->pCursors[nCursor];
-
- editor->bCaretAtEnd = FALSE;
-
- assert(p->pRun->type == diRun);
-
- return run_get_di( run_insert( editor, p, style, str, len, flags ) );
-}
-
static struct re_object* create_re_object(const REOBJECT *reo)
{
struct re_object *reobj = heap_alloc(sizeof(*reobj));
@@ -489,96 +475,98 @@ static struct re_object* create_re_object(const REOBJECT *reo)
void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCursor)
{
- ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
- ME_DisplayItem *di;
- WCHAR space = ' ';
- ME_DisplayItem *di_prev = NULL;
- struct re_object *reobj_prev = NULL;
-
+ ME_Style *style = ME_GetInsertStyle( editor, nCursor );
+ ME_Run *run, *prev;
+ const WCHAR space = ' ';
+ struct re_object *reobj_prev = NULL;
+ ME_Cursor *cursor = editor->pCursors + nCursor;
+
/* FIXME no no no */
if (ME_IsSelection(editor))
ME_DeleteSelection(editor);
- di = ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle,
- MERF_GRAPHICS);
- di->member.run.reobj = create_re_object(reo);
+ run = run_insert( editor, cursor, style, &space, 1, MERF_GRAPHICS );
+ editor->bCaretAtEnd = FALSE;
+
+ run->reobj = create_re_object( reo );
- di_prev = di;
- while (ME_PrevRun(NULL, &di_prev, TRUE))
+ prev = run;
+ while ((prev = run_prev_all_paras( prev )))
{
- if (di_prev->member.run.reobj)
+ if (prev->reobj)
{
- reobj_prev = di_prev->member.run.reobj;
+ reobj_prev = prev->reobj;
break;
}
}
if (reobj_prev)
- list_add_after(&reobj_prev->entry, &di->member.run.reobj->entry);
+ list_add_after(&reobj_prev->entry, &run->reobj->entry);
else
- list_add_head(&editor->reobj_list, &di->member.run.reobj->entry);
+ list_add_head(&editor->reobj_list, &run->reobj->entry);
- ME_ReleaseStyle(pStyle);
+ ME_ReleaseStyle( style );
}
void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor)
{
- ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
- WCHAR space = ' ';
+ ME_Style *style = ME_GetInsertStyle( editor, nCursor );
+ const WCHAR space = ' ';
+ ME_Cursor *cursor = editor->pCursors + nCursor;
/* FIXME no no no */
if (ME_IsSelection(editor))
ME_DeleteSelection(editor);
- ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle,
- MERF_ENDROW);
- ME_ReleaseStyle(pStyle);
+ run_insert( editor, cursor, style, &space, 1, MERF_ENDROW );
+ editor->bCaretAtEnd = FALSE;
+
+ ME_ReleaseStyle( style );
}
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
- const WCHAR *str, int len, ME_Style *style)
+ const WCHAR *str, int len, ME_Style *style)
{
const WCHAR *pos;
- ME_Cursor *p = NULL;
+ ME_Cursor *cursor = editor->pCursors + nCursor;
int oldLen;
/* FIXME really HERE ? */
if (ME_IsSelection(editor))
ME_DeleteSelection(editor);
- /* FIXME: is this too slow? */
- /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */
oldLen = ME_GetTextLength(editor);
/* text operations set modified state */
editor->nModifyStep = 1;
+ editor->bCaretAtEnd = FALSE;
assert(style);
- assert(nCursor>=0 && nCursor<editor->nCursors);
- if (len == -1)
- len = lstrlenW(str);
+ if (len == -1) len = lstrlenW( str );
/* grow the text limit to fit our text */
- if(editor->nTextLimit < oldLen +len)
- editor->nTextLimit = oldLen + len;
+ if (editor->nTextLimit < oldLen + len) editor->nTextLimit = oldLen + len;
pos = str;
while (len)
{
/* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */
- while(pos - str < len && *pos != '\r' && *pos != '\n' && *pos != '\t')
+ while (pos - str < len && *pos != '\r' && *pos != '\n' && *pos != '\t')
pos++;
- if (pos != str) { /* handle text */
- ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0);
- } else if (*pos == '\t') { /* handle tabs */
- WCHAR tab = '\t';
- ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, style, MERF_TAB);
+ if (pos != str) /* handle text */
+ run_insert( editor, cursor, style, str, pos - str, 0 );
+ else if (*pos == '\t') /* handle tabs */
+ {
+ const WCHAR tab = '\t';
+ run_insert( editor, cursor, style, &tab, 1, MERF_TAB );
pos++;
- } else { /* handle EOLs */
+ }
+ else /* handle EOLs */
+ {
ME_Run *end_run, *run, *prev;
ME_Paragraph *new_para;
int eol_len = 0;
@@ -596,7 +584,9 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
eol_len = 3;
else
eol_len = 1;
- } else {
+ }
+ else
+ {
assert(*pos == '\n');
eol_len = 1;
}
@@ -605,8 +595,8 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
if (!editor->bEmulateVersion10 && eol_len == 3)
{
/* handle special \r\r\n sequence (richedit 2.x and higher only) */
- WCHAR space = ' ';
- ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, style, 0);
+ const WCHAR space = ' ';
+ run_insert( editor, cursor, style, &space, 1, 0 );
}
else
{
@@ -618,17 +608,15 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
eol_len = 1;
}
- p = &editor->pCursors[nCursor];
-
- if (p->nOffset == p->pRun->member.run.len)
+ if (cursor->nOffset == cursor->pRun->member.run.len)
{
- run = run_next( &p->pRun->member.run );
- if (!run) run = &p->pRun->member.run;
+ run = run_next( &cursor->pRun->member.run );
+ if (!run) run = &cursor->pRun->member.run;
}
else
{
- if (p->nOffset) run_split( editor, p );
- run = &p->pRun->member.run;
+ if (cursor->nOffset) run_split( editor, cursor );
+ run = &cursor->pRun->member.run;
}
new_para = &ME_SplitParagraph( editor, run_get_di( run ), style, eol_str, eol_len, 0 )->member.para;
--
2.23.0
1
0
[PATCH v2 3/6] riched20: Simplify the char offset from run offset function.
by Huw Davies Oct. 15, 2020
by Huw Davies Oct. 15, 2020
Oct. 15, 2020
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/editor.c | 6 +++---
dlls/riched20/editor.h | 2 +-
dlls/riched20/run.c | 13 +++++--------
3 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 30441658311..d9bcea84f74 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -4322,15 +4322,15 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
cursor_from_char_ofs( editor, wParam, &cursor );
item = ME_RowStart( cursor.pRun );
- nThisLineOfs = ME_CharOfsFromRunOfs( editor, cursor.pPara, ME_FindItemFwd( item, diRun ), 0 );
+ nThisLineOfs = run_char_ofs( &ME_FindItemFwd( item, diRun )->member.run, 0 );
item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
if (item_end->type == diStartRow)
- nNextLineOfs = ME_CharOfsFromRunOfs(editor, cursor.pPara, ME_FindItemFwd( item_end, diRun ), 0);
+ nNextLineOfs = run_char_ofs( &ME_FindItemFwd( item_end, diRun )->member.run, 0 );
else
{
ME_DisplayItem *endRun = ME_FindItemBack(item_end, diRun);
assert(endRun && endRun->member.run.nFlags & MERF_ENDPARA);
- nNextLineOfs = item_end->member.para.nCharOfs - endRun->member.run.len;
+ nNextLineOfs = run_char_ofs( &endRun->member.run, 0 );
}
nChars = nNextLineOfs - nThisLineOfs;
TRACE("EM_LINELENGTH(%ld)==%d\n", wParam, nChars);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 163be9c8179..0503a671ea1 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -120,6 +120,7 @@ int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
/* run.c */
void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor ) 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,
ME_Style *style, const WCHAR *str, int len, int flags ) DECLSPEC_HIDDEN;
@@ -140,7 +141,6 @@ ME_Run *run_split( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) DECLSPEC_HIDDEN;
SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen,
int startx, int *pAscent, int *pDescent) DECLSPEC_HIDDEN;
-int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, const ME_DisplayItem *pRun, int nOfs) DECLSPEC_HIDDEN;
void ME_SkipAndPropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN;
void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN;
void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index 92d0721247c..22a5db8610b 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -187,18 +187,15 @@ void ME_CheckCharOffsets(ME_TextEditor *editor)
}
/******************************************************************************
- * ME_CharOfsFromRunOfs
+ * run_char_ofs
*
- * Converts a character position relative to the start of the run, to a
+ * Converts a character position relative to the start of the run to a
* character position relative to the start of the document.
- * Kind of a "local to global" offset conversion.
*/
-int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara,
- const ME_DisplayItem *pRun, int nOfs)
+
+int run_char_ofs( ME_Run *run, int ofs )
{
- assert(pRun && pRun->type == diRun);
- assert(pPara && pPara->type == diParagraph);
- return pPara->member.para.nCharOfs + pRun->member.run.nCharOfs + nOfs;
+ return run->para->nCharOfs + run->nCharOfs + ofs;
}
/******************************************************************************
--
2.23.0
1
0
Oct. 15, 2020
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/caret.c | 4 +-
dlls/riched20/editor.c | 47 +++++++++++------------
dlls/riched20/editor.h | 4 +-
dlls/riched20/richole.c | 84 ++++++++++++++++++++++-------------------
dlls/riched20/run.c | 66 +++++++++++---------------------
dlls/riched20/txtsrv.c | 2 +-
dlls/riched20/undo.c | 12 +++---
7 files changed, 103 insertions(+), 116 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index c5fa51894e8..d66dd57383b 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -201,7 +201,7 @@ int set_selection_cursors(ME_TextEditor *editor, int from, int to)
return len;
}
- ME_CursorFromCharOfs(editor, from, &editor->pCursors[1]);
+ cursor_from_char_ofs( editor, from, &editor->pCursors[1] );
editor->pCursors[0] = editor->pCursors[1];
ME_MoveCursorChars(editor, &editor->pCursors[0], to - from, FALSE);
/* Selection is not allowed in the middle of an end paragraph run. */
@@ -326,7 +326,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
while(nChars > 0)
{
ME_Run *run;
- ME_CursorFromCharOfs(editor, nOfs+nChars, &c);
+ cursor_from_char_ofs( editor, nOfs + nChars, &c );
if (!c.nOffset &&
nOfs+nChars == (c.pRun->member.run.nCharOfs
+ c.pPara->member.para.nCharOfs))
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index a144137baa1..30441658311 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1788,7 +1788,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
/* put the cursor at the top */
if (!(format & SFF_SELECTION))
set_selection_cursors(editor, 0, 0);
- ME_CursorFromCharOfs(editor, from, &start);
+ cursor_from_char_ofs( editor, from, &start );
ME_UpdateLinkAttribute(editor, &start, to - from);
}
@@ -1917,12 +1917,11 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
/* If possible, find the character before where the search starts */
if ((flags & FR_WHOLEWORD) && nMin)
{
- ME_CursorFromCharOfs(editor, nMin - 1, &cursor);
+ cursor_from_char_ofs( editor, nMin - 1, &cursor );
wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
ME_MoveCursorChars(editor, &cursor, 1, FALSE);
- } else {
- ME_CursorFromCharOfs(editor, nMin, &cursor);
}
+ else cursor_from_char_ofs( editor, nMin, &cursor );
while (cursor.pRun && ME_GetCursorOfs(&cursor) + nLen <= nMax)
{
@@ -1993,12 +1992,11 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
/* If possible, find the character after where the search ends */
if ((flags & FR_WHOLEWORD) && nMax < nTextLen - 1)
{
- ME_CursorFromCharOfs(editor, nMax + 1, &cursor);
+ cursor_from_char_ofs( editor, nMax + 1, &cursor );
wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
ME_MoveCursorChars(editor, &cursor, -1, FALSE);
- } else {
- ME_CursorFromCharOfs(editor, nMax, &cursor);
}
+ else cursor_from_char_ofs( editor, nMax, &cursor );
while (cursor.pRun && ME_GetCursorOfs(&cursor) - nLen >= nMin)
{
@@ -3009,7 +3007,7 @@ static LONG ME_GetSelectionType(ME_TextEditor *editor)
{
ME_Cursor cursor;
- ME_CursorFromCharOfs(editor, start + i, &cursor);
+ cursor_from_char_ofs( editor, start + i, &cursor );
if (cursor.pRun->member.run.reobj)
object_count++;
else
@@ -4205,7 +4203,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
nEnd = textlength;
if (nStart >= nEnd) return 0;
- ME_CursorFromCharOfs(editor, nStart, &start);
+ cursor_from_char_ofs( editor, nStart, &start );
return ME_GetTextRange(editor, rng->lpstrText, &start, nEnd - nStart, unicode);
}
case EM_GETLINE:
@@ -4313,7 +4311,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
{
ME_DisplayItem *item, *item_end;
int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0;
- ME_DisplayItem *para, *run;
+ ME_Cursor cursor;
if (wParam > ME_GetTextLength(editor))
return 0;
@@ -4322,19 +4320,20 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
return 0;
}
- ME_RunOfsFromCharOfs(editor, wParam, ¶, &run, NULL);
- item = ME_RowStart(run);
- nThisLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item, diRun), 0);
+ cursor_from_char_ofs( editor, wParam, &cursor );
+ item = ME_RowStart( cursor.pRun );
+ nThisLineOfs = ME_CharOfsFromRunOfs( editor, cursor.pPara, ME_FindItemFwd( item, diRun ), 0 );
item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
- if (item_end->type == diStartRow) {
- nNextLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item_end, diRun), 0);
- } else {
+ if (item_end->type == diStartRow)
+ nNextLineOfs = ME_CharOfsFromRunOfs(editor, cursor.pPara, ME_FindItemFwd( item_end, diRun ), 0);
+ else
+ {
ME_DisplayItem *endRun = ME_FindItemBack(item_end, diRun);
assert(endRun && endRun->member.run.nFlags & MERF_ENDPARA);
nNextLineOfs = item_end->member.para.nCharOfs - endRun->member.run.len;
}
nChars = nNextLineOfs - nThisLineOfs;
- TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars);
+ TRACE("EM_LINELENGTH(%ld)==%d\n", wParam, nChars);
return nChars;
}
case EM_EXLIMITTEXT:
@@ -4424,8 +4423,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
case EM_POSFROMCHAR:
{
- ME_DisplayItem *pPara, *pRun;
- int nCharOfs, nOffset, nLength;
+ ME_Cursor cursor;
+ int nCharOfs, nLength;
POINTL pt = {0,0};
nCharOfs = wParam;
@@ -4436,11 +4435,11 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
nCharOfs = min(nCharOfs, nLength);
nCharOfs = max(nCharOfs, 0);
- ME_RunOfsFromCharOfs(editor, nCharOfs, &pPara, &pRun, &nOffset);
- assert(pRun->type == diRun);
- pt.y = pRun->member.run.pt.y;
- pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset, TRUE);
- pt.y += pPara->member.para.pt.y + editor->rcFormat.top;
+ cursor_from_char_ofs( editor, nCharOfs, &cursor );
+ pt.y = cursor.pRun->member.run.pt.y;
+ pt.x = cursor.pRun->member.run.pt.x +
+ ME_PointFromChar( editor, &cursor.pRun->member.run, cursor.nOffset, TRUE );
+ pt.y += cursor.pPara->member.para.pt.y + editor->rcFormat.top;
pt.x += editor->rcFormat.left;
pt.x -= editor->horz_si.nPos;
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 1a9f3fd6fb0..163be9c8179 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -118,6 +118,8 @@ ME_DisplayItem *ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) DECLSPEC_H
int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
/* run.c */
+void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
+
ME_Run *run_create( ME_Style *s, int nFlags ) DECLSPEC_HIDDEN;
ME_Run *run_insert( ME_TextEditor *editor, ME_Cursor *cursor,
ME_Style *style, const WCHAR *str, int len, int flags ) DECLSPEC_HIDDEN;
@@ -138,8 +140,6 @@ ME_Run *run_split( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) DECLSPEC_HIDDEN;
SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen,
int startx, int *pAscent, int *pDescent) DECLSPEC_HIDDEN;
-void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor) DECLSPEC_HIDDEN;
-void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem **ppPara, ME_DisplayItem **ppRun, int *pOfs) DECLSPEC_HIDDEN;
int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, const ME_DisplayItem *pRun, int nOfs) DECLSPEC_HIDDEN;
void ME_SkipAndPropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN;
void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 47d8442d5ce..923984e96b1 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -444,7 +444,7 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
fmt.cbSize = sizeof(fmt);
fmt.dwMask = textfont_prop_masks[propid][0];
- ME_CursorFromCharOfs(reole->editor, pos, &from);
+ cursor_from_char_ofs( reole->editor, pos, &from );
to = from;
ME_MoveCursorChars(reole->editor, &to, 1, FALSE);
ME_GetCharFormat(reole->editor, &from, &to, &fmt);
@@ -662,7 +662,8 @@ static void textrange_set_font(ITextRange *range, ITextFont *font)
fmt.wWeight = value;
}
- if (fmt.dwMask) {
+ if (fmt.dwMask)
+ {
const IRichEditOleImpl *reole = get_range_reole(range);
ME_Cursor from, to;
LONG start, end;
@@ -670,8 +671,8 @@ static void textrange_set_font(ITextRange *range, ITextFont *font)
ITextRange_GetStart(range, &start);
ITextRange_GetEnd(range, &end);
- ME_CursorFromCharOfs(reole->editor, start, &from);
- ME_CursorFromCharOfs(reole->editor, end, &to);
+ cursor_from_char_ofs( reole->editor, start, &from );
+ cursor_from_char_ofs( reole->editor, end, &to );
ME_SetCharFormat(reole->editor, &from, &to, &fmt);
}
}
@@ -828,8 +829,8 @@ static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id prop
ITextRange_GetStart(font->range, &start);
ITextRange_GetEnd(font->range, &end);
- ME_CursorFromCharOfs(reole->editor, start, &from);
- ME_CursorFromCharOfs(reole->editor, end, &to);
+ cursor_from_char_ofs( reole->editor, start, &from );
+ cursor_from_char_ofs( reole->editor, end, &to );
ME_SetCharFormat(reole->editor, &from, &to, &fmt);
return S_OK;
@@ -1349,12 +1350,15 @@ IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
if(!lplpdataobj)
return E_INVALIDARG;
- if(!lpchrg) {
+ if(!lpchrg)
+ {
int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
start = This->editor->pCursors[nStartCur];
nChars = nTo - nFrom;
- } else {
- ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
+ }
+ else
+ {
+ cursor_from_char_ofs( This->editor, lpchrg->cpMin, &start );
nChars = lpchrg->cpMax - lpchrg->cpMin;
}
return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
@@ -1385,7 +1389,7 @@ IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
ME_Cursor cursor;
TRACE("character offset: %d\n", lpreobject->cp);
- ME_CursorFromCharOfs(This->editor, lpreobject->cp, &cursor);
+ cursor_from_char_ofs( This->editor, lpreobject->cp, &cursor );
if (!cursor.pRun->member.run.reobj)
return E_INVALIDARG;
else
@@ -1647,8 +1651,8 @@ static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *str)
}
editor = This->child.reole->editor;
- ME_CursorFromCharOfs(editor, This->start, &start);
- ME_CursorFromCharOfs(editor, This->end, &end);
+ cursor_from_char_ofs( editor, This->start, &start );
+ cursor_from_char_ofs( editor, This->end, &end );
length = This->end - This->start;
*str = SysAllocStringLen(NULL, length);
@@ -1676,12 +1680,14 @@ static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
editor = This->child.reole->editor;
/* delete only where's something to delete */
- if (This->start != This->end) {
- ME_CursorFromCharOfs(editor, This->start, &cursor);
+ if (This->start != This->end)
+ {
+ cursor_from_char_ofs( editor, This->start, &cursor );
ME_InternalDeleteText(editor, &cursor, This->end - This->start, FALSE);
}
- if (!str || !*str) {
+ if (!str || !*str)
+ {
/* will update this range as well */
textranges_update_ranges(This->child.reole, This->start, This->end, RANGE_UPDATE_DELETE);
return S_OK;
@@ -1690,7 +1696,7 @@ static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
/* it's safer not to rely on stored BSTR length */
len = lstrlenW(str);
cursor = editor->pCursors[0];
- ME_CursorFromCharOfs(editor, This->start, &editor->pCursors[0]);
+ cursor_from_char_ofs( editor, This->start, &editor->pCursors[0] );
style = ME_GetInsertStyle(editor, 0);
ME_InsertTextFromCursor(editor, 0, str, len, style);
ME_ReleaseStyle(style);
@@ -1729,7 +1735,7 @@ static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch)
return E_INVALIDARG;
editor = This->child.reole->editor;
- ME_CursorFromCharOfs(editor, This->start, &cursor);
+ cursor_from_char_ofs( editor, This->start, &cursor );
return range_GetChar(editor, &cursor, pch);
}
@@ -2213,18 +2219,16 @@ static HRESULT textrange_endof(ITextRange *range, ME_TextEditor *editor, LONG un
{
moved = 0;
new_end = old_end;
- if (old_end == 0) {
+ if (old_end == 0)
+ {
ME_Cursor cursor;
- ME_CursorFromCharOfs(editor, old_end, &cursor);
+ cursor_from_char_ofs( editor, old_end, &cursor );
moved = ME_MoveCursorChars(editor, &cursor, 1, TRUE);
new_end = old_end + moved;
- } else {
- if (extend == tomMove) {
- if (old_start != old_end) {
- moved = 1;
- }
- }
}
+ else if (extend == tomMove && old_start != old_end)
+ moved = 1;
+
ITextRange_SetEnd(range, new_end);
if (extend == tomMove)
ITextRange_SetStart(range, new_end);
@@ -2275,32 +2279,36 @@ static HRESULT textrange_move(ITextRange *range, ME_TextEditor *editor, LONG uni
{
ME_Cursor cursor;
- if (count > 0) {
- ME_CursorFromCharOfs(editor, old_end, &cursor);
+ if (count > 0)
+ {
+ cursor_from_char_ofs( editor, old_end, &cursor );
move_by = count;
if (old_start != old_end)
--move_by;
- } else {
- ME_CursorFromCharOfs(editor, old_start, &cursor);
+ }
+ else
+ {
+ cursor_from_char_ofs( editor, old_start, &cursor );
move_by = count;
if (old_start != old_end)
++move_by;
}
moved = ME_MoveCursorChars(editor, &cursor, move_by, FALSE);
- if (count > 0) {
+ if (count > 0)
+ {
new_end = old_end + moved;
new_start = new_end;
if (old_start != old_end)
++moved;
- } else {
+ }
+ else
+ {
new_start = old_start + moved;
new_end = new_start;
if (old_start != old_end)
--moved;
}
- if (delta) {
- *delta = moved;
- }
+ if (delta) *delta = moved;
break;
}
default:
@@ -2348,7 +2356,7 @@ static HRESULT textrange_movestart(ITextRange *range, ME_TextEditor *editor, LON
ME_Cursor cursor;
LONG moved;
- ME_CursorFromCharOfs(editor, old_start, &cursor);
+ cursor_from_char_ofs( editor, old_start, &cursor );
moved = ME_MoveCursorChars(editor, &cursor, count, FALSE);
new_start = old_start + moved;
new_end = old_end;
@@ -2404,7 +2412,7 @@ static HRESULT textrange_moveend(ITextRange *range, ME_TextEditor *editor, LONG
ME_Cursor cursor;
LONG moved;
- ME_CursorFromCharOfs(editor, old_end, &cursor);
+ cursor_from_char_ofs( editor, old_end, &cursor );
moved = ME_MoveCursorChars(editor, &cursor, count, TRUE);
new_start = old_start;
new_end = old_end + moved;
@@ -2700,11 +2708,11 @@ static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG value)
switch (value)
{
case tomStart:
- ME_CursorFromCharOfs(editor, This->start, &cursor);
+ cursor_from_char_ofs( editor, This->start, &cursor );
ME_GetCursorCoordinates(editor, &cursor, &x, &y, &height);
break;
case tomEnd:
- ME_CursorFromCharOfs(editor, This->end, &cursor);
+ cursor_from_char_ofs( editor, This->end, &cursor );
ME_GetCursorCoordinates(editor, &cursor, &x, &y, &height);
break;
default:
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index 75195e343ed..92d0721247c 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -202,58 +202,38 @@ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara,
}
/******************************************************************************
- * ME_CursorFromCharOfs
+ * cursor_from_char_ofs
*
* Converts a character offset (relative to the start of the document) to
* a cursor structure (which contains a run and a position relative to that
* run).
*/
-void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor)
+void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor )
{
- ME_RunOfsFromCharOfs(editor, nCharOfs, &pCursor->pPara,
- &pCursor->pRun, &pCursor->nOffset);
-}
+ ME_Paragraph *para;
+ ME_Run *run;
-/******************************************************************************
- * ME_RunOfsFromCharOfs
- *
- * Find a run and relative character offset given an absolute character offset
- * (absolute offset being an offset relative to the start of the document).
- * Kind of a "global to local" offset conversion.
- */
-void ME_RunOfsFromCharOfs(ME_TextEditor *editor,
- int nCharOfs,
- ME_DisplayItem **ppPara,
- ME_DisplayItem **ppRun,
- int *pOfs)
-{
- ME_DisplayItem *item, *next_item;
+ char_ofs = min( max( char_ofs, 0 ), ME_GetTextLength( editor ) );
- nCharOfs = max(nCharOfs, 0);
- nCharOfs = min(nCharOfs, ME_GetTextLength(editor));
+ /* Find the paragraph at the offset. */
+ for (para = editor_first_para( editor );
+ para_next( para )->nCharOfs <= char_ofs;
+ para = para_next( para ))
+ ;
- /* Find the paragraph at the offset. */
- next_item = editor->pBuffer->pFirst->member.para.next_para;
- do {
- item = next_item;
- next_item = item->member.para.next_para;
- } while (next_item->member.para.nCharOfs <= nCharOfs);
- assert(item->type == diParagraph);
- nCharOfs -= item->member.para.nCharOfs;
- if (ppPara) *ppPara = item;
-
- /* Find the run at the offset. */
- next_item = ME_FindItemFwd(item, diRun);
- do {
- item = next_item;
- next_item = ME_FindItemFwd(item, diRunOrParagraphOrEnd);
- } while (next_item->type == diRun &&
- next_item->member.run.nCharOfs <= nCharOfs);
- assert(item->type == diRun);
- nCharOfs -= item->member.run.nCharOfs;
-
- if (ppRun) *ppRun = item;
- if (pOfs) *pOfs = nCharOfs;
+ char_ofs -= para->nCharOfs;
+
+ /* Find the run at the offset. */
+ for (run = para_first_run( para );
+ run_next( run ) && run_next( run )->nCharOfs <= char_ofs;
+ run = run_next( run ))
+ ;
+
+ char_ofs -= run->nCharOfs;
+
+ cursor->pPara = para_get_di( para );
+ cursor->pRun = run_get_di( run );
+ cursor->nOffset = char_ofs;
}
/******************************************************************************
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index 622d8519285..3fd4ae540c5 100644
--- a/dlls/riched20/txtsrv.c
+++ b/dlls/riched20/txtsrv.c
@@ -269,7 +269,7 @@ DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetText(ITextServices *iface, BST
if (bstr == NULL)
return E_OUTOFMEMORY;
- ME_CursorFromCharOfs(This->editor, 0, &start);
+ cursor_from_char_ofs( This->editor, 0, &start );
ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE, FALSE);
*pbstrText = bstr;
} else {
diff --git a/dlls/riched20/undo.c b/dlls/riched20/undo.c
index 1f5c7ae4cd6..3f3fd48bebd 100644
--- a/dlls/riched20/undo.c
+++ b/dlls/riched20/undo.c
@@ -336,7 +336,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
{
ME_Cursor tmp;
ME_DisplayItem *para;
- ME_CursorFromCharOfs(editor, undo->u.set_para_fmt.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.set_para_fmt.pos, &tmp );
para = ME_FindItemBack(tmp.pRun, diParagraph);
add_undo_set_para_fmt( editor, ¶->member.para );
para->member.para.fmt = undo->u.set_para_fmt.fmt;
@@ -347,7 +347,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
case undo_set_char_fmt:
{
ME_Cursor start, end;
- ME_CursorFromCharOfs(editor, undo->u.set_char_fmt.pos, &start);
+ cursor_from_char_ofs( editor, undo->u.set_char_fmt.pos, &start );
end = start;
ME_MoveCursorChars(editor, &end, undo->u.set_char_fmt.len, FALSE);
ME_SetCharFormat(editor, &start, &end, &undo->u.set_char_fmt.fmt);
@@ -356,7 +356,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
case undo_insert_run:
{
ME_Cursor tmp;
- ME_CursorFromCharOfs(editor, undo->u.insert_run.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.insert_run.pos, &tmp );
run_insert( editor, &tmp, undo->u.insert_run.style,
undo->u.insert_run.str, undo->u.insert_run.len,
undo->u.insert_run.flags );
@@ -365,14 +365,14 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
case undo_delete_run:
{
ME_Cursor tmp;
- ME_CursorFromCharOfs(editor, undo->u.delete_run.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.delete_run.pos, &tmp );
ME_InternalDeleteText(editor, &tmp, undo->u.delete_run.len, TRUE);
break;
}
case undo_join_paras:
{
ME_Cursor tmp;
- ME_CursorFromCharOfs(editor, undo->u.join_paras.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.join_paras.pos, &tmp );
ME_JoinParagraphs(editor, tmp.pPara, TRUE);
break;
}
@@ -383,7 +383,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
BOOL bFixRowStart;
int paraFlags = undo->u.split_para.flags & (MEPF_ROWSTART|MEPF_CELL|MEPF_ROWEND);
- ME_CursorFromCharOfs(editor, undo->u.split_para.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.split_para.pos, &tmp );
if (tmp.nOffset) run_split( editor, &tmp );
this_para = tmp.pPara;
bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART;
--
2.23.0
1
0
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/run.c | 67 +++++++++++++++++++--------------------------
1 file changed, 28 insertions(+), 39 deletions(-)
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index a5888960f38..75195e343ed 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -816,9 +816,9 @@ void ME_SetCharFormat( ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end,
}
}
-static void ME_GetRunCharFormat(ME_TextEditor *editor, ME_DisplayItem *run, CHARFORMAT2W *pFmt)
+static void run_copy_char_fmt( ME_Run *run, CHARFORMAT2W *fmt )
{
- ME_CopyCharFormat(pFmt, &run->member.run.style->fmt);
+ ME_CopyCharFormat( fmt, &run->style->fmt );
}
/******************************************************************************
@@ -856,33 +856,25 @@ void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
* Returns the style consisting of those attributes which are consistently set
* in the whole character range.
*/
-void ME_GetCharFormat(ME_TextEditor *editor, const ME_Cursor *from,
- const ME_Cursor *to, CHARFORMAT2W *pFmt)
+void ME_GetCharFormat( ME_TextEditor *editor, const ME_Cursor *from,
+ const ME_Cursor *to, CHARFORMAT2W *fmt )
{
- ME_DisplayItem *run, *run_end;
+ ME_Run *run, *run_end, *prev_run;
CHARFORMAT2W tmp;
- run = from->pRun;
+ run = &from->pRun->member.run;
/* special case - if selection is empty, take previous char's formatting */
if (from->pRun == to->pRun && from->nOffset == to->nOffset)
{
- if (!from->nOffset)
- {
- ME_DisplayItem *tmp_run = ME_FindItemBack(run, diRunOrParagraph);
- if (tmp_run->type == diRun) {
- ME_GetRunCharFormat(editor, tmp_run, pFmt);
- return;
- }
- }
- ME_GetRunCharFormat(editor, run, pFmt);
+ if (!from->nOffset && (prev_run = run_prev( run ))) run = prev_run;
+ run_copy_char_fmt( run, fmt );
return;
}
- run_end = to->pRun;
- if (!to->nOffset)
- run_end = ME_FindItemBack(run_end, diRun);
+ run_end = &to->pRun->member.run;
+ if (!to->nOffset) run_end = run_prev_all_paras( run_end );
- ME_GetRunCharFormat(editor, run, pFmt);
+ run_copy_char_fmt( run, fmt );
if (run == run_end) return;
@@ -891,40 +883,37 @@ void ME_GetCharFormat(ME_TextEditor *editor, const ME_Cursor *from,
DWORD dwAttribs = CFM_SIZE | CFM_FACE | CFM_COLOR | CFM_UNDERLINETYPE;
DWORD dwEffects = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_LINK | CFM_SUPERSCRIPT;
- run = ME_FindItemFwd(run, diRun);
+ run = run_next_all_paras( run );
- ZeroMemory(&tmp, sizeof(tmp));
+ memset( &tmp, 0, sizeof(tmp) );
tmp.cbSize = sizeof(tmp);
- ME_GetRunCharFormat(editor, run, &tmp);
+ run_copy_char_fmt( run, &tmp );
assert((tmp.dwMask & dwAttribs) == dwAttribs);
/* reset flags that differ */
- if (pFmt->yHeight != tmp.yHeight)
- pFmt->dwMask &= ~CFM_SIZE;
- if (pFmt->dwMask & CFM_FACE)
+ if (fmt->yHeight != tmp.yHeight) fmt->dwMask &= ~CFM_SIZE;
+ if (fmt->dwMask & CFM_FACE)
{
if (!(tmp.dwMask & CFM_FACE))
- pFmt->dwMask &= ~CFM_FACE;
- else if (wcscmp(pFmt->szFaceName, tmp.szFaceName) ||
- pFmt->bPitchAndFamily != tmp.bPitchAndFamily)
- pFmt->dwMask &= ~CFM_FACE;
+ fmt->dwMask &= ~CFM_FACE;
+ else if (wcscmp( fmt->szFaceName, tmp.szFaceName ) ||
+ fmt->bPitchAndFamily != tmp.bPitchAndFamily)
+ fmt->dwMask &= ~CFM_FACE;
}
- if (pFmt->yHeight != tmp.yHeight)
- pFmt->dwMask &= ~CFM_SIZE;
- if (pFmt->bUnderlineType != tmp.bUnderlineType)
- pFmt->dwMask &= ~CFM_UNDERLINETYPE;
- if (pFmt->dwMask & CFM_COLOR)
+ if (fmt->yHeight != tmp.yHeight) fmt->dwMask &= ~CFM_SIZE;
+ if (fmt->bUnderlineType != tmp.bUnderlineType) fmt->dwMask &= ~CFM_UNDERLINETYPE;
+ if (fmt->dwMask & CFM_COLOR)
{
- if (!((pFmt->dwEffects&CFE_AUTOCOLOR) & (tmp.dwEffects&CFE_AUTOCOLOR)))
+ if (!((fmt->dwEffects&CFE_AUTOCOLOR) & (tmp.dwEffects&CFE_AUTOCOLOR)))
{
- if (pFmt->crTextColor != tmp.crTextColor)
- pFmt->dwMask &= ~CFM_COLOR;
+ if (fmt->crTextColor != tmp.crTextColor)
+ fmt->dwMask &= ~CFM_COLOR;
}
}
- pFmt->dwMask &= ~((pFmt->dwEffects ^ tmp.dwEffects) & dwEffects);
- pFmt->dwEffects = tmp.dwEffects;
+ fmt->dwMask &= ~((fmt->dwEffects ^ tmp.dwEffects) & dwEffects);
+ fmt->dwEffects = tmp.dwEffects;
} while(run != run_end);
}
--
2.23.0
1
0
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/caret.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 4764dec8f33..ffea3ee0c35 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -1215,21 +1215,23 @@ void ME_MouseMove(ME_TextEditor *editor, int x, int y)
static int ME_GetXForArrow(ME_TextEditor *editor, ME_Cursor *pCursor)
{
- ME_DisplayItem *pRun = pCursor->pRun;
+ ME_Run *run = &pCursor->pRun->member.run;
int x;
if (editor->nUDArrowX != -1)
x = editor->nUDArrowX;
- else {
+ else
+ {
if (editor->bCaretAtEnd)
{
- pRun = ME_FindItemBack(pRun, diRun);
- assert(pRun);
- x = pRun->member.run.pt.x + pRun->member.run.nWidth;
+ run = run_prev_all_paras( run );
+ assert( run );
+ x = run->pt.x + run->nWidth;
}
- else {
- x = pRun->member.run.pt.x;
- x += ME_PointFromChar(editor, &pRun->member.run, pCursor->nOffset, TRUE);
+ else
+ {
+ x = run->pt.x;
+ x += ME_PointFromChar( editor, run, pCursor->nOffset, TRUE );
}
editor->nUDArrowX = x;
}
--
2.23.0
1
0
Oct. 15, 2020
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/caret.c | 110 +++++++++++++++++++-----------------------
1 file changed, 49 insertions(+), 61 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index d66dd57383b..4764dec8f33 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -460,20 +460,6 @@ BOOL ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars)
nChars, FALSE);
}
-static ME_DisplayItem *
-ME_InternalInsertTextFromCursor(ME_TextEditor *editor, int nCursor,
- const WCHAR *str, int len, ME_Style *style,
- int flags)
-{
- ME_Cursor *p = &editor->pCursors[nCursor];
-
- editor->bCaretAtEnd = FALSE;
-
- assert(p->pRun->type == diRun);
-
- return run_get_di( run_insert( editor, p, style, str, len, flags ) );
-}
-
static struct re_object* create_re_object(const REOBJECT *reo)
{
struct re_object *reobj = heap_alloc(sizeof(*reobj));
@@ -489,96 +475,98 @@ static struct re_object* create_re_object(const REOBJECT *reo)
void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCursor)
{
- ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
- ME_DisplayItem *di;
- WCHAR space = ' ';
- ME_DisplayItem *di_prev = NULL;
- struct re_object *reobj_prev = NULL;
-
+ ME_Style *style = ME_GetInsertStyle( editor, nCursor );
+ ME_Run *run, *prev;
+ const WCHAR space = ' ';
+ struct re_object *reobj_prev = NULL;
+ ME_Cursor *cursor = editor->pCursors + nCursor;
+
/* FIXME no no no */
if (ME_IsSelection(editor))
ME_DeleteSelection(editor);
- di = ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle,
- MERF_GRAPHICS);
- di->member.run.reobj = create_re_object(reo);
+ run = run_insert( editor, cursor, style, &space, 1, MERF_GRAPHICS );
+ editor->bCaretAtEnd = FALSE;
+
+ run->reobj = create_re_object( reo );
- di_prev = di;
- while (ME_PrevRun(NULL, &di_prev, TRUE))
+ prev = run;
+ while ((prev = run_prev_all_paras( prev )))
{
- if (di_prev->member.run.reobj)
+ if (prev->reobj)
{
- reobj_prev = di_prev->member.run.reobj;
+ reobj_prev = prev->reobj;
break;
}
}
if (reobj_prev)
- list_add_after(&reobj_prev->entry, &di->member.run.reobj->entry);
+ list_add_after(&reobj_prev->entry, &run->reobj->entry);
else
- list_add_head(&editor->reobj_list, &di->member.run.reobj->entry);
+ list_add_head(&editor->reobj_list, &run->reobj->entry);
- ME_ReleaseStyle(pStyle);
+ ME_ReleaseStyle( style );
}
void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor)
{
- ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
- WCHAR space = ' ';
+ ME_Style *style = ME_GetInsertStyle( editor, nCursor );
+ const WCHAR space = ' ';
+ ME_Cursor *cursor = editor->pCursors + nCursor;
/* FIXME no no no */
if (ME_IsSelection(editor))
ME_DeleteSelection(editor);
- ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle,
- MERF_ENDROW);
- ME_ReleaseStyle(pStyle);
+ run_insert( editor, cursor, style, &space, 1, MERF_ENDROW );
+ editor->bCaretAtEnd = FALSE;
+
+ ME_ReleaseStyle( style );
}
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
- const WCHAR *str, int len, ME_Style *style)
+ const WCHAR *str, int len, ME_Style *style)
{
const WCHAR *pos;
- ME_Cursor *p = NULL;
+ ME_Cursor *cursor = editor->pCursors + nCursor;
int oldLen;
/* FIXME really HERE ? */
if (ME_IsSelection(editor))
ME_DeleteSelection(editor);
- /* FIXME: is this too slow? */
- /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */
oldLen = ME_GetTextLength(editor);
/* text operations set modified state */
editor->nModifyStep = 1;
+ editor->bCaretAtEnd = FALSE;
assert(style);
- assert(nCursor>=0 && nCursor<editor->nCursors);
- if (len == -1)
- len = lstrlenW(str);
+ if (len == -1) len = lstrlenW( str );
/* grow the text limit to fit our text */
- if(editor->nTextLimit < oldLen +len)
- editor->nTextLimit = oldLen + len;
+ if (editor->nTextLimit < oldLen + len) editor->nTextLimit = oldLen + len;
pos = str;
while (len)
{
/* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */
- while(pos - str < len && *pos != '\r' && *pos != '\n' && *pos != '\t')
+ while (pos - str < len && *pos != '\r' && *pos != '\n' && *pos != '\t')
pos++;
- if (pos != str) { /* handle text */
- ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0);
- } else if (*pos == '\t') { /* handle tabs */
- WCHAR tab = '\t';
- ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, style, MERF_TAB);
+ if (pos != str) /* handle text */
+ run_insert( editor, cursor, style, str, pos - str, 0 );
+ else if (*pos == '\t') /* handle tabs */
+ {
+ const WCHAR tab = '\t';
+ run_insert( editor, cursor, style, &tab, 1, MERF_TAB );
pos++;
- } else { /* handle EOLs */
+ }
+ else /* handle EOLs */
+ {
ME_Run *end_run, *run, *prev;
ME_Paragraph *new_para;
int eol_len = 0;
@@ -596,7 +584,9 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
eol_len = 3;
else
eol_len = 1;
- } else {
+ }
+ else
+ {
assert(*pos == '\n');
eol_len = 1;
}
@@ -605,8 +595,8 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
if (!editor->bEmulateVersion10 && eol_len == 3)
{
/* handle special \r\r\n sequence (richedit 2.x and higher only) */
- WCHAR space = ' ';
- ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, style, 0);
+ const WCHAR space = ' ';
+ run_insert( editor, cursor, style, &space, 1, 0 );
}
else
{
@@ -618,17 +608,15 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
eol_len = 1;
}
- p = &editor->pCursors[nCursor];
-
- if (p->nOffset == p->pRun->member.run.len)
+ if (cursor->nOffset == cursor->pRun->member.run.len)
{
- run = run_next( &p->pRun->member.run );
- if (!run) run = &p->pRun->member.run;
+ run = run_next( &cursor->pRun->member.run );
+ if (!run) run = &cursor->pRun->member.run;
}
else
{
- if (p->nOffset) run_split( editor, p );
- run = &p->pRun->member.run;
+ if (cursor->nOffset) run_split( editor, cursor );
+ run = &cursor->pRun->member.run;
}
new_para = &ME_SplitParagraph( editor, run_get_di( run ), style, eol_str, eol_len, 0 )->member.para;
--
2.23.0
1
0
[PATCH 3/6] riched20: Simplify the char offset from run offset function.
by Huw Davies Oct. 15, 2020
by Huw Davies Oct. 15, 2020
Oct. 15, 2020
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/editor.c | 6 +++---
dlls/riched20/editor.h | 2 +-
dlls/riched20/run.c | 13 +++++--------
3 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 30441658311..d9bcea84f74 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -4322,15 +4322,15 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
cursor_from_char_ofs( editor, wParam, &cursor );
item = ME_RowStart( cursor.pRun );
- nThisLineOfs = ME_CharOfsFromRunOfs( editor, cursor.pPara, ME_FindItemFwd( item, diRun ), 0 );
+ nThisLineOfs = run_char_ofs( &ME_FindItemFwd( item, diRun )->member.run, 0 );
item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
if (item_end->type == diStartRow)
- nNextLineOfs = ME_CharOfsFromRunOfs(editor, cursor.pPara, ME_FindItemFwd( item_end, diRun ), 0);
+ nNextLineOfs = run_char_ofs( &ME_FindItemFwd( item_end, diRun )->member.run, 0 );
else
{
ME_DisplayItem *endRun = ME_FindItemBack(item_end, diRun);
assert(endRun && endRun->member.run.nFlags & MERF_ENDPARA);
- nNextLineOfs = item_end->member.para.nCharOfs - endRun->member.run.len;
+ nNextLineOfs = run_char_ofs( &endRun->member.run, 0 );
}
nChars = nNextLineOfs - nThisLineOfs;
TRACE("EM_LINELENGTH(%ld)==%d\n", wParam, nChars);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 163be9c8179..0503a671ea1 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -120,6 +120,7 @@ int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
/* run.c */
void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor ) 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,
ME_Style *style, const WCHAR *str, int len, int flags ) DECLSPEC_HIDDEN;
@@ -140,7 +141,6 @@ ME_Run *run_split( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) DECLSPEC_HIDDEN;
SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen,
int startx, int *pAscent, int *pDescent) DECLSPEC_HIDDEN;
-int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, const ME_DisplayItem *pRun, int nOfs) DECLSPEC_HIDDEN;
void ME_SkipAndPropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN;
void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN;
void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index 92d0721247c..22a5db8610b 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -187,18 +187,15 @@ void ME_CheckCharOffsets(ME_TextEditor *editor)
}
/******************************************************************************
- * ME_CharOfsFromRunOfs
+ * run_char_ofs
*
- * Converts a character position relative to the start of the run, to a
+ * Converts a character position relative to the start of the run to a
* character position relative to the start of the document.
- * Kind of a "local to global" offset conversion.
*/
-int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara,
- const ME_DisplayItem *pRun, int nOfs)
+
+int run_char_ofs( ME_Run *run, int ofs )
{
- assert(pRun && pRun->type == diRun);
- assert(pPara && pPara->type == diParagraph);
- return pPara->member.para.nCharOfs + pRun->member.run.nCharOfs + nOfs;
+ return run->para->nCharOfs + run->nCharOfs + ofs;
}
/******************************************************************************
--
2.23.0
1
0
Oct. 15, 2020
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/caret.c | 4 +-
dlls/riched20/editor.c | 47 +++++++++++------------
dlls/riched20/editor.h | 4 +-
dlls/riched20/richole.c | 84 ++++++++++++++++++++++-------------------
dlls/riched20/run.c | 66 +++++++++++---------------------
dlls/riched20/txtsrv.c | 2 +-
dlls/riched20/undo.c | 12 +++---
7 files changed, 103 insertions(+), 116 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index c5fa51894e8..d66dd57383b 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -201,7 +201,7 @@ int set_selection_cursors(ME_TextEditor *editor, int from, int to)
return len;
}
- ME_CursorFromCharOfs(editor, from, &editor->pCursors[1]);
+ cursor_from_char_ofs( editor, from, &editor->pCursors[1] );
editor->pCursors[0] = editor->pCursors[1];
ME_MoveCursorChars(editor, &editor->pCursors[0], to - from, FALSE);
/* Selection is not allowed in the middle of an end paragraph run. */
@@ -326,7 +326,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
while(nChars > 0)
{
ME_Run *run;
- ME_CursorFromCharOfs(editor, nOfs+nChars, &c);
+ cursor_from_char_ofs( editor, nOfs + nChars, &c );
if (!c.nOffset &&
nOfs+nChars == (c.pRun->member.run.nCharOfs
+ c.pPara->member.para.nCharOfs))
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index a144137baa1..30441658311 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1788,7 +1788,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
/* put the cursor at the top */
if (!(format & SFF_SELECTION))
set_selection_cursors(editor, 0, 0);
- ME_CursorFromCharOfs(editor, from, &start);
+ cursor_from_char_ofs( editor, from, &start );
ME_UpdateLinkAttribute(editor, &start, to - from);
}
@@ -1917,12 +1917,11 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
/* If possible, find the character before where the search starts */
if ((flags & FR_WHOLEWORD) && nMin)
{
- ME_CursorFromCharOfs(editor, nMin - 1, &cursor);
+ cursor_from_char_ofs( editor, nMin - 1, &cursor );
wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
ME_MoveCursorChars(editor, &cursor, 1, FALSE);
- } else {
- ME_CursorFromCharOfs(editor, nMin, &cursor);
}
+ else cursor_from_char_ofs( editor, nMin, &cursor );
while (cursor.pRun && ME_GetCursorOfs(&cursor) + nLen <= nMax)
{
@@ -1993,12 +1992,11 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
/* If possible, find the character after where the search ends */
if ((flags & FR_WHOLEWORD) && nMax < nTextLen - 1)
{
- ME_CursorFromCharOfs(editor, nMax + 1, &cursor);
+ cursor_from_char_ofs( editor, nMax + 1, &cursor );
wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
ME_MoveCursorChars(editor, &cursor, -1, FALSE);
- } else {
- ME_CursorFromCharOfs(editor, nMax, &cursor);
}
+ else cursor_from_char_ofs( editor, nMax, &cursor );
while (cursor.pRun && ME_GetCursorOfs(&cursor) - nLen >= nMin)
{
@@ -3009,7 +3007,7 @@ static LONG ME_GetSelectionType(ME_TextEditor *editor)
{
ME_Cursor cursor;
- ME_CursorFromCharOfs(editor, start + i, &cursor);
+ cursor_from_char_ofs( editor, start + i, &cursor );
if (cursor.pRun->member.run.reobj)
object_count++;
else
@@ -4205,7 +4203,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
nEnd = textlength;
if (nStart >= nEnd) return 0;
- ME_CursorFromCharOfs(editor, nStart, &start);
+ cursor_from_char_ofs( editor, nStart, &start );
return ME_GetTextRange(editor, rng->lpstrText, &start, nEnd - nStart, unicode);
}
case EM_GETLINE:
@@ -4313,7 +4311,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
{
ME_DisplayItem *item, *item_end;
int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0;
- ME_DisplayItem *para, *run;
+ ME_Cursor cursor;
if (wParam > ME_GetTextLength(editor))
return 0;
@@ -4322,19 +4320,20 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
return 0;
}
- ME_RunOfsFromCharOfs(editor, wParam, ¶, &run, NULL);
- item = ME_RowStart(run);
- nThisLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item, diRun), 0);
+ cursor_from_char_ofs( editor, wParam, &cursor );
+ item = ME_RowStart( cursor.pRun );
+ nThisLineOfs = ME_CharOfsFromRunOfs( editor, cursor.pPara, ME_FindItemFwd( item, diRun ), 0 );
item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
- if (item_end->type == diStartRow) {
- nNextLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item_end, diRun), 0);
- } else {
+ if (item_end->type == diStartRow)
+ nNextLineOfs = ME_CharOfsFromRunOfs(editor, cursor.pPara, ME_FindItemFwd( item_end, diRun ), 0);
+ else
+ {
ME_DisplayItem *endRun = ME_FindItemBack(item_end, diRun);
assert(endRun && endRun->member.run.nFlags & MERF_ENDPARA);
nNextLineOfs = item_end->member.para.nCharOfs - endRun->member.run.len;
}
nChars = nNextLineOfs - nThisLineOfs;
- TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars);
+ TRACE("EM_LINELENGTH(%ld)==%d\n", wParam, nChars);
return nChars;
}
case EM_EXLIMITTEXT:
@@ -4424,8 +4423,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
case EM_POSFROMCHAR:
{
- ME_DisplayItem *pPara, *pRun;
- int nCharOfs, nOffset, nLength;
+ ME_Cursor cursor;
+ int nCharOfs, nLength;
POINTL pt = {0,0};
nCharOfs = wParam;
@@ -4436,11 +4435,11 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
nCharOfs = min(nCharOfs, nLength);
nCharOfs = max(nCharOfs, 0);
- ME_RunOfsFromCharOfs(editor, nCharOfs, &pPara, &pRun, &nOffset);
- assert(pRun->type == diRun);
- pt.y = pRun->member.run.pt.y;
- pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset, TRUE);
- pt.y += pPara->member.para.pt.y + editor->rcFormat.top;
+ cursor_from_char_ofs( editor, nCharOfs, &cursor );
+ pt.y = cursor.pRun->member.run.pt.y;
+ pt.x = cursor.pRun->member.run.pt.x +
+ ME_PointFromChar( editor, &cursor.pRun->member.run, cursor.nOffset, TRUE );
+ pt.y += cursor.pPara->member.para.pt.y + editor->rcFormat.top;
pt.x += editor->rcFormat.left;
pt.x -= editor->horz_si.nPos;
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 1a9f3fd6fb0..163be9c8179 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -118,6 +118,8 @@ ME_DisplayItem *ME_FindRowWithNumber(ME_TextEditor *editor, int nRow) DECLSPEC_H
int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
/* run.c */
+void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
+
ME_Run *run_create( ME_Style *s, int nFlags ) DECLSPEC_HIDDEN;
ME_Run *run_insert( ME_TextEditor *editor, ME_Cursor *cursor,
ME_Style *style, const WCHAR *str, int len, int flags ) DECLSPEC_HIDDEN;
@@ -138,8 +140,6 @@ ME_Run *run_split( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) DECLSPEC_HIDDEN;
SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen,
int startx, int *pAscent, int *pDescent) DECLSPEC_HIDDEN;
-void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor) DECLSPEC_HIDDEN;
-void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem **ppPara, ME_DisplayItem **ppRun, int *pOfs) DECLSPEC_HIDDEN;
int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, const ME_DisplayItem *pRun, int nOfs) DECLSPEC_HIDDEN;
void ME_SkipAndPropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN;
void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 47d8442d5ce..923984e96b1 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -444,7 +444,7 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
fmt.cbSize = sizeof(fmt);
fmt.dwMask = textfont_prop_masks[propid][0];
- ME_CursorFromCharOfs(reole->editor, pos, &from);
+ cursor_from_char_ofs( reole->editor, pos, &from );
to = from;
ME_MoveCursorChars(reole->editor, &to, 1, FALSE);
ME_GetCharFormat(reole->editor, &from, &to, &fmt);
@@ -662,7 +662,8 @@ static void textrange_set_font(ITextRange *range, ITextFont *font)
fmt.wWeight = value;
}
- if (fmt.dwMask) {
+ if (fmt.dwMask)
+ {
const IRichEditOleImpl *reole = get_range_reole(range);
ME_Cursor from, to;
LONG start, end;
@@ -670,8 +671,8 @@ static void textrange_set_font(ITextRange *range, ITextFont *font)
ITextRange_GetStart(range, &start);
ITextRange_GetEnd(range, &end);
- ME_CursorFromCharOfs(reole->editor, start, &from);
- ME_CursorFromCharOfs(reole->editor, end, &to);
+ cursor_from_char_ofs( reole->editor, start, &from );
+ cursor_from_char_ofs( reole->editor, end, &to );
ME_SetCharFormat(reole->editor, &from, &to, &fmt);
}
}
@@ -828,8 +829,8 @@ static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id prop
ITextRange_GetStart(font->range, &start);
ITextRange_GetEnd(font->range, &end);
- ME_CursorFromCharOfs(reole->editor, start, &from);
- ME_CursorFromCharOfs(reole->editor, end, &to);
+ cursor_from_char_ofs( reole->editor, start, &from );
+ cursor_from_char_ofs( reole->editor, end, &to );
ME_SetCharFormat(reole->editor, &from, &to, &fmt);
return S_OK;
@@ -1349,12 +1350,15 @@ IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
if(!lplpdataobj)
return E_INVALIDARG;
- if(!lpchrg) {
+ if(!lpchrg)
+ {
int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
start = This->editor->pCursors[nStartCur];
nChars = nTo - nFrom;
- } else {
- ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
+ }
+ else
+ {
+ cursor_from_char_ofs( This->editor, lpchrg->cpMin, &start );
nChars = lpchrg->cpMax - lpchrg->cpMin;
}
return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
@@ -1385,7 +1389,7 @@ IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
ME_Cursor cursor;
TRACE("character offset: %d\n", lpreobject->cp);
- ME_CursorFromCharOfs(This->editor, lpreobject->cp, &cursor);
+ cursor_from_char_ofs( This->editor, lpreobject->cp, &cursor );
if (!cursor.pRun->member.run.reobj)
return E_INVALIDARG;
else
@@ -1647,8 +1651,8 @@ static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *str)
}
editor = This->child.reole->editor;
- ME_CursorFromCharOfs(editor, This->start, &start);
- ME_CursorFromCharOfs(editor, This->end, &end);
+ cursor_from_char_ofs( editor, This->start, &start );
+ cursor_from_char_ofs( editor, This->end, &end );
length = This->end - This->start;
*str = SysAllocStringLen(NULL, length);
@@ -1676,12 +1680,14 @@ static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
editor = This->child.reole->editor;
/* delete only where's something to delete */
- if (This->start != This->end) {
- ME_CursorFromCharOfs(editor, This->start, &cursor);
+ if (This->start != This->end)
+ {
+ cursor_from_char_ofs( editor, This->start, &cursor );
ME_InternalDeleteText(editor, &cursor, This->end - This->start, FALSE);
}
- if (!str || !*str) {
+ if (!str || !*str)
+ {
/* will update this range as well */
textranges_update_ranges(This->child.reole, This->start, This->end, RANGE_UPDATE_DELETE);
return S_OK;
@@ -1690,7 +1696,7 @@ static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
/* it's safer not to rely on stored BSTR length */
len = lstrlenW(str);
cursor = editor->pCursors[0];
- ME_CursorFromCharOfs(editor, This->start, &editor->pCursors[0]);
+ cursor_from_char_ofs( editor, This->start, &editor->pCursors[0] );
style = ME_GetInsertStyle(editor, 0);
ME_InsertTextFromCursor(editor, 0, str, len, style);
ME_ReleaseStyle(style);
@@ -1729,7 +1735,7 @@ static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch)
return E_INVALIDARG;
editor = This->child.reole->editor;
- ME_CursorFromCharOfs(editor, This->start, &cursor);
+ cursor_from_char_ofs( editor, This->start, &cursor );
return range_GetChar(editor, &cursor, pch);
}
@@ -2213,18 +2219,16 @@ static HRESULT textrange_endof(ITextRange *range, ME_TextEditor *editor, LONG un
{
moved = 0;
new_end = old_end;
- if (old_end == 0) {
+ if (old_end == 0)
+ {
ME_Cursor cursor;
- ME_CursorFromCharOfs(editor, old_end, &cursor);
+ cursor_from_char_ofs( editor, old_end, &cursor );
moved = ME_MoveCursorChars(editor, &cursor, 1, TRUE);
new_end = old_end + moved;
- } else {
- if (extend == tomMove) {
- if (old_start != old_end) {
- moved = 1;
- }
- }
}
+ else if (extend == tomMove && old_start != old_end)
+ moved = 1;
+
ITextRange_SetEnd(range, new_end);
if (extend == tomMove)
ITextRange_SetStart(range, new_end);
@@ -2275,32 +2279,36 @@ static HRESULT textrange_move(ITextRange *range, ME_TextEditor *editor, LONG uni
{
ME_Cursor cursor;
- if (count > 0) {
- ME_CursorFromCharOfs(editor, old_end, &cursor);
+ if (count > 0)
+ {
+ cursor_from_char_ofs( editor, old_end, &cursor );
move_by = count;
if (old_start != old_end)
--move_by;
- } else {
- ME_CursorFromCharOfs(editor, old_start, &cursor);
+ }
+ else
+ {
+ cursor_from_char_ofs( editor, old_start, &cursor );
move_by = count;
if (old_start != old_end)
++move_by;
}
moved = ME_MoveCursorChars(editor, &cursor, move_by, FALSE);
- if (count > 0) {
+ if (count > 0)
+ {
new_end = old_end + moved;
new_start = new_end;
if (old_start != old_end)
++moved;
- } else {
+ }
+ else
+ {
new_start = old_start + moved;
new_end = new_start;
if (old_start != old_end)
--moved;
}
- if (delta) {
- *delta = moved;
- }
+ if (delta) *delta = moved;
break;
}
default:
@@ -2348,7 +2356,7 @@ static HRESULT textrange_movestart(ITextRange *range, ME_TextEditor *editor, LON
ME_Cursor cursor;
LONG moved;
- ME_CursorFromCharOfs(editor, old_start, &cursor);
+ cursor_from_char_ofs( editor, old_start, &cursor );
moved = ME_MoveCursorChars(editor, &cursor, count, FALSE);
new_start = old_start + moved;
new_end = old_end;
@@ -2404,7 +2412,7 @@ static HRESULT textrange_moveend(ITextRange *range, ME_TextEditor *editor, LONG
ME_Cursor cursor;
LONG moved;
- ME_CursorFromCharOfs(editor, old_end, &cursor);
+ cursor_from_char_ofs( editor, old_end, &cursor );
moved = ME_MoveCursorChars(editor, &cursor, count, TRUE);
new_start = old_start;
new_end = old_end + moved;
@@ -2700,11 +2708,11 @@ static HRESULT WINAPI ITextRange_fnScrollIntoView(ITextRange *me, LONG value)
switch (value)
{
case tomStart:
- ME_CursorFromCharOfs(editor, This->start, &cursor);
+ cursor_from_char_ofs( editor, This->start, &cursor );
ME_GetCursorCoordinates(editor, &cursor, &x, &y, &height);
break;
case tomEnd:
- ME_CursorFromCharOfs(editor, This->end, &cursor);
+ cursor_from_char_ofs( editor, This->end, &cursor );
ME_GetCursorCoordinates(editor, &cursor, &x, &y, &height);
break;
default:
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index 75195e343ed..92d0721247c 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -202,58 +202,38 @@ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara,
}
/******************************************************************************
- * ME_CursorFromCharOfs
+ * cursor_from_char_ofs
*
* Converts a character offset (relative to the start of the document) to
* a cursor structure (which contains a run and a position relative to that
* run).
*/
-void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor)
+void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor )
{
- ME_RunOfsFromCharOfs(editor, nCharOfs, &pCursor->pPara,
- &pCursor->pRun, &pCursor->nOffset);
-}
+ ME_Paragraph *para;
+ ME_Run *run;
-/******************************************************************************
- * ME_RunOfsFromCharOfs
- *
- * Find a run and relative character offset given an absolute character offset
- * (absolute offset being an offset relative to the start of the document).
- * Kind of a "global to local" offset conversion.
- */
-void ME_RunOfsFromCharOfs(ME_TextEditor *editor,
- int nCharOfs,
- ME_DisplayItem **ppPara,
- ME_DisplayItem **ppRun,
- int *pOfs)
-{
- ME_DisplayItem *item, *next_item;
+ char_ofs = min( max( char_ofs, 0 ), ME_GetTextLength( editor ) );
- nCharOfs = max(nCharOfs, 0);
- nCharOfs = min(nCharOfs, ME_GetTextLength(editor));
+ /* Find the paragraph at the offset. */
+ for (para = editor_first_para( editor );
+ para_next( para )->nCharOfs <= char_ofs;
+ para = para_next( para ))
+ ;
- /* Find the paragraph at the offset. */
- next_item = editor->pBuffer->pFirst->member.para.next_para;
- do {
- item = next_item;
- next_item = item->member.para.next_para;
- } while (next_item->member.para.nCharOfs <= nCharOfs);
- assert(item->type == diParagraph);
- nCharOfs -= item->member.para.nCharOfs;
- if (ppPara) *ppPara = item;
-
- /* Find the run at the offset. */
- next_item = ME_FindItemFwd(item, diRun);
- do {
- item = next_item;
- next_item = ME_FindItemFwd(item, diRunOrParagraphOrEnd);
- } while (next_item->type == diRun &&
- next_item->member.run.nCharOfs <= nCharOfs);
- assert(item->type == diRun);
- nCharOfs -= item->member.run.nCharOfs;
-
- if (ppRun) *ppRun = item;
- if (pOfs) *pOfs = nCharOfs;
+ char_ofs -= para->nCharOfs;
+
+ /* Find the run at the offset. */
+ for (run = para_first_run( para );
+ run_next( run ) && run_next( run )->nCharOfs <= char_ofs;
+ run = run_next( run ))
+ ;
+
+ char_ofs -= run->nCharOfs;
+
+ cursor->pPara = para_get_di( para );
+ cursor->pRun = run_get_di( run );
+ cursor->nOffset = char_ofs;
}
/******************************************************************************
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index 622d8519285..3fd4ae540c5 100644
--- a/dlls/riched20/txtsrv.c
+++ b/dlls/riched20/txtsrv.c
@@ -269,7 +269,7 @@ DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetText(ITextServices *iface, BST
if (bstr == NULL)
return E_OUTOFMEMORY;
- ME_CursorFromCharOfs(This->editor, 0, &start);
+ cursor_from_char_ofs( This->editor, 0, &start );
ME_GetTextW(This->editor, bstr, length, &start, INT_MAX, FALSE, FALSE);
*pbstrText = bstr;
} else {
diff --git a/dlls/riched20/undo.c b/dlls/riched20/undo.c
index 1f5c7ae4cd6..3f3fd48bebd 100644
--- a/dlls/riched20/undo.c
+++ b/dlls/riched20/undo.c
@@ -336,7 +336,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
{
ME_Cursor tmp;
ME_DisplayItem *para;
- ME_CursorFromCharOfs(editor, undo->u.set_para_fmt.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.set_para_fmt.pos, &tmp );
para = ME_FindItemBack(tmp.pRun, diParagraph);
add_undo_set_para_fmt( editor, ¶->member.para );
para->member.para.fmt = undo->u.set_para_fmt.fmt;
@@ -347,7 +347,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
case undo_set_char_fmt:
{
ME_Cursor start, end;
- ME_CursorFromCharOfs(editor, undo->u.set_char_fmt.pos, &start);
+ cursor_from_char_ofs( editor, undo->u.set_char_fmt.pos, &start );
end = start;
ME_MoveCursorChars(editor, &end, undo->u.set_char_fmt.len, FALSE);
ME_SetCharFormat(editor, &start, &end, &undo->u.set_char_fmt.fmt);
@@ -356,7 +356,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
case undo_insert_run:
{
ME_Cursor tmp;
- ME_CursorFromCharOfs(editor, undo->u.insert_run.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.insert_run.pos, &tmp );
run_insert( editor, &tmp, undo->u.insert_run.style,
undo->u.insert_run.str, undo->u.insert_run.len,
undo->u.insert_run.flags );
@@ -365,14 +365,14 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
case undo_delete_run:
{
ME_Cursor tmp;
- ME_CursorFromCharOfs(editor, undo->u.delete_run.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.delete_run.pos, &tmp );
ME_InternalDeleteText(editor, &tmp, undo->u.delete_run.len, TRUE);
break;
}
case undo_join_paras:
{
ME_Cursor tmp;
- ME_CursorFromCharOfs(editor, undo->u.join_paras.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.join_paras.pos, &tmp );
ME_JoinParagraphs(editor, tmp.pPara, TRUE);
break;
}
@@ -383,7 +383,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
BOOL bFixRowStart;
int paraFlags = undo->u.split_para.flags & (MEPF_ROWSTART|MEPF_CELL|MEPF_ROWEND);
- ME_CursorFromCharOfs(editor, undo->u.split_para.pos, &tmp);
+ cursor_from_char_ofs( editor, undo->u.split_para.pos, &tmp );
if (tmp.nOffset) run_split( editor, &tmp );
this_para = tmp.pPara;
bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART;
--
2.23.0
1
0
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/riched20/run.c | 67 +++++++++++++++++++--------------------------
1 file changed, 28 insertions(+), 39 deletions(-)
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index a5888960f38..75195e343ed 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -816,9 +816,9 @@ void ME_SetCharFormat( ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end,
}
}
-static void ME_GetRunCharFormat(ME_TextEditor *editor, ME_DisplayItem *run, CHARFORMAT2W *pFmt)
+static void run_copy_char_fmt( ME_Run *run, CHARFORMAT2W *fmt )
{
- ME_CopyCharFormat(pFmt, &run->member.run.style->fmt);
+ ME_CopyCharFormat( fmt, &run->style->fmt );
}
/******************************************************************************
@@ -856,33 +856,25 @@ void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
* Returns the style consisting of those attributes which are consistently set
* in the whole character range.
*/
-void ME_GetCharFormat(ME_TextEditor *editor, const ME_Cursor *from,
- const ME_Cursor *to, CHARFORMAT2W *pFmt)
+void ME_GetCharFormat( ME_TextEditor *editor, const ME_Cursor *from,
+ const ME_Cursor *to, CHARFORMAT2W *fmt )
{
- ME_DisplayItem *run, *run_end;
+ ME_Run *run, *run_end, *prev_run;
CHARFORMAT2W tmp;
- run = from->pRun;
+ run = &from->pRun->member.run;
/* special case - if selection is empty, take previous char's formatting */
if (from->pRun == to->pRun && from->nOffset == to->nOffset)
{
- if (!from->nOffset)
- {
- ME_DisplayItem *tmp_run = ME_FindItemBack(run, diRunOrParagraph);
- if (tmp_run->type == diRun) {
- ME_GetRunCharFormat(editor, tmp_run, pFmt);
- return;
- }
- }
- ME_GetRunCharFormat(editor, run, pFmt);
+ if (!from->nOffset && (prev_run = run_prev( run ))) run = prev_run;
+ run_copy_char_fmt( run, fmt );
return;
}
- run_end = to->pRun;
- if (!to->nOffset)
- run_end = ME_FindItemBack(run_end, diRun);
+ run_end = &to->pRun->member.run;
+ if (!to->nOffset) run_end = run_prev_all_paras( run_end );
- ME_GetRunCharFormat(editor, run, pFmt);
+ run_copy_char_fmt( run, fmt );
if (run == run_end) return;
@@ -891,40 +883,37 @@ void ME_GetCharFormat(ME_TextEditor *editor, const ME_Cursor *from,
DWORD dwAttribs = CFM_SIZE | CFM_FACE | CFM_COLOR | CFM_UNDERLINETYPE;
DWORD dwEffects = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_LINK | CFM_SUPERSCRIPT;
- run = ME_FindItemFwd(run, diRun);
+ run = run_next_all_paras( run );
- ZeroMemory(&tmp, sizeof(tmp));
+ memset( &tmp, 0, sizeof(tmp) );
tmp.cbSize = sizeof(tmp);
- ME_GetRunCharFormat(editor, run, &tmp);
+ run_copy_char_fmt( run, &tmp );
assert((tmp.dwMask & dwAttribs) == dwAttribs);
/* reset flags that differ */
- if (pFmt->yHeight != tmp.yHeight)
- pFmt->dwMask &= ~CFM_SIZE;
- if (pFmt->dwMask & CFM_FACE)
+ if (fmt->yHeight != tmp.yHeight) fmt->dwMask &= ~CFM_SIZE;
+ if (fmt->dwMask & CFM_FACE)
{
if (!(tmp.dwMask & CFM_FACE))
- pFmt->dwMask &= ~CFM_FACE;
- else if (wcscmp(pFmt->szFaceName, tmp.szFaceName) ||
- pFmt->bPitchAndFamily != tmp.bPitchAndFamily)
- pFmt->dwMask &= ~CFM_FACE;
+ fmt->dwMask &= ~CFM_FACE;
+ else if (wcscmp( fmt->szFaceName, tmp.szFaceName ) ||
+ fmt->bPitchAndFamily != tmp.bPitchAndFamily)
+ fmt->dwMask &= ~CFM_FACE;
}
- if (pFmt->yHeight != tmp.yHeight)
- pFmt->dwMask &= ~CFM_SIZE;
- if (pFmt->bUnderlineType != tmp.bUnderlineType)
- pFmt->dwMask &= ~CFM_UNDERLINETYPE;
- if (pFmt->dwMask & CFM_COLOR)
+ if (fmt->yHeight != tmp.yHeight) fmt->dwMask &= ~CFM_SIZE;
+ if (fmt->bUnderlineType != tmp.bUnderlineType) fmt->dwMask &= ~CFM_UNDERLINETYPE;
+ if (fmt->dwMask & CFM_COLOR)
{
- if (!((pFmt->dwEffects&CFE_AUTOCOLOR) & (tmp.dwEffects&CFE_AUTOCOLOR)))
+ if (!((fmt->dwEffects&CFE_AUTOCOLOR) & (tmp.dwEffects&CFE_AUTOCOLOR)))
{
- if (pFmt->crTextColor != tmp.crTextColor)
- pFmt->dwMask &= ~CFM_COLOR;
+ if (fmt->crTextColor != tmp.crTextColor)
+ fmt->dwMask &= ~CFM_COLOR;
}
}
- pFmt->dwMask &= ~((pFmt->dwEffects ^ tmp.dwEffects) & dwEffects);
- pFmt->dwEffects = tmp.dwEffects;
+ fmt->dwMask &= ~((fmt->dwEffects ^ tmp.dwEffects) & dwEffects);
+ fmt->dwEffects = tmp.dwEffects;
} while(run != run_end);
}
--
2.23.0
1
0
Oct. 15, 2020
Signed-off-by: Myah Caron <qsniyg(a)protonmail.com>
---
I've opted to use a helper function, as it both makes the code cleaner, as well as avoid
unneeded "syscalls" (could be a performance issue for an application that calls
Encode/DecodePointer repeatedly).
dlls/ntdll/rtl.c | 30 +++++++++++-------------------
1 file changed, 11 insertions(+), 19 deletions(-)
diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c
index 154de807501..8c8c8c9bb1a 100644
--- a/dlls/ntdll/rtl.c
+++ b/dlls/ntdll/rtl.c
@@ -1516,30 +1516,22 @@ WCHAR * WINAPI RtlIpv6AddressToStringW(const IN6_ADDR *address, WCHAR *str)
}
/***********************************************************************
- * get_pointer_obfuscator (internal)
+ * get_process_cookie (internal)
*/
-static DWORD_PTR get_pointer_obfuscator( void )
+static ULONG get_process_cookie( void )
{
- static DWORD_PTR pointer_obfuscator;
+ static ULONG process_cookie;
- if (!pointer_obfuscator)
+ if (!process_cookie)
{
- ULONG seed = NtGetTickCount();
- ULONG_PTR rand;
+ ULONG cookie;
+ NtQueryInformationProcess( NtCurrentProcess(), ProcessCookie, &cookie,
+ sizeof( cookie ), NULL );
- /* generate a random value for the obfuscator */
- rand = RtlUniform( &seed );
-
- /* handle 64bit pointers */
- rand ^= (ULONG_PTR)RtlUniform( &seed ) << ((sizeof (DWORD_PTR) - sizeof (ULONG))*8);
-
- /* set the high bits so dereferencing obfuscated pointers will (usually) crash */
- rand |= (ULONG_PTR)0xc0000000 << ((sizeof (DWORD_PTR) - sizeof (ULONG))*8);
-
- InterlockedCompareExchangePointer( (void**) &pointer_obfuscator, (void*) rand, NULL );
+ InterlockedExchange( (LONG*)&process_cookie, cookie );
}
- return pointer_obfuscator;
+ return process_cookie;
}
/***********************************************************************
@@ -1575,7 +1567,7 @@ PVOID WINAPI RtlEncodePointer( PVOID ptr )
{
DWORD_PTR ptrval = (DWORD_PTR) ptr;
- DWORD_PTR cookie = get_pointer_obfuscator();
+ DWORD_PTR cookie = (DWORD_PTR) get_process_cookie();
/* http://blogs.msdn.com/b/michael_howard/archive/2006/08/16/702707.aspx */
@@ -1586,7 +1578,7 @@ PVOID WINAPI RtlEncodePointer( PVOID ptr )
PVOID WINAPI RtlDecodePointer( PVOID ptr )
{
DWORD_PTR ptrval = (DWORD_PTR) ptr;
- DWORD_PTR cookie = get_pointer_obfuscator();
+ DWORD_PTR cookie = (DWORD_PTR) get_process_cookie();
ptrval = rotl_ptr(ptrval, cookie);
return (PVOID)(ptrval ^ cookie);
--
2.28.0
2
1