richedit: Make the ME_GetCursorOfs function more flexible.
This function will make it easier to work with ME_Cursor objects, which should be used in a lot of places instead of character offsets (which often require seeking through the linked lists to perform operations with).
This commit is contained in:
parent
e726a5cca1
commit
be0fb1ef5d
|
@ -29,8 +29,8 @@ ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs);
|
|||
|
||||
void ME_GetSelection(ME_TextEditor *editor, int *from, int *to)
|
||||
{
|
||||
*from = ME_GetCursorOfs(editor, 0);
|
||||
*to = ME_GetCursorOfs(editor, 1);
|
||||
*from = ME_GetCursorOfs(&editor->pCursors[0]);
|
||||
*to = ME_GetCursorOfs(&editor->pCursors[1]);
|
||||
|
||||
if (*from > *to)
|
||||
{
|
||||
|
@ -426,8 +426,8 @@ BOOL ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars)
|
|||
assert(nCursor>=0 && nCursor<editor->nCursors);
|
||||
/* text operations set modified state */
|
||||
editor->nModifyStep = 1;
|
||||
return ME_InternalDeleteText(editor, ME_GetCursorOfs(editor, nCursor), nChars,
|
||||
FALSE);
|
||||
return ME_InternalDeleteText(editor, ME_GetCursorOfs(&editor->pCursors[nCursor]),
|
||||
nChars, FALSE);
|
||||
}
|
||||
|
||||
static ME_DisplayItem *
|
||||
|
@ -807,11 +807,10 @@ ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType)
|
|||
editor->pCursors[3] = editor->pCursors[1];
|
||||
}
|
||||
|
||||
int ME_GetCursorOfs(ME_TextEditor *editor, int nCursor)
|
||||
int ME_GetCursorOfs(const ME_Cursor *cursor)
|
||||
{
|
||||
ME_Cursor *pCursor = &editor->pCursors[nCursor];
|
||||
return pCursor->pPara->member.para.nCharOfs
|
||||
+ pCursor->pRun->member.run.nCharOfs + pCursor->nOffset;
|
||||
return cursor->pPara->member.para.nCharOfs
|
||||
+ cursor->pRun->member.run.nCharOfs + cursor->nOffset;
|
||||
}
|
||||
|
||||
/* Helper function for ME_FindPixelPos to find paragraph within tables */
|
||||
|
@ -1019,9 +1018,9 @@ static void ME_ExtendAnchorSelection(ME_TextEditor *editor)
|
|||
int curOfs, anchorStartOfs, anchorEndOfs;
|
||||
if (editor->nSelectionType == stPosition || editor->nSelectionType == stDocument)
|
||||
return;
|
||||
curOfs = ME_GetCursorOfs(editor, 0);
|
||||
anchorStartOfs = ME_GetCursorOfs(editor, 3);
|
||||
anchorEndOfs = ME_GetCursorOfs(editor, 2);
|
||||
curOfs = ME_GetCursorOfs(&editor->pCursors[0]);
|
||||
anchorStartOfs = ME_GetCursorOfs(&editor->pCursors[3]);
|
||||
anchorEndOfs = ME_GetCursorOfs(&editor->pCursors[2]);
|
||||
|
||||
tmp_cursor = editor->pCursors[0];
|
||||
editor->pCursors[0] = editor->pCursors[2];
|
||||
|
@ -1499,7 +1498,8 @@ BOOL ME_IsSelection(ME_TextEditor *editor)
|
|||
|
||||
static int ME_GetSelCursor(ME_TextEditor *editor, int dir)
|
||||
{
|
||||
int cdir = ME_GetCursorOfs(editor, 0) - ME_GetCursorOfs(editor, 1);
|
||||
int cdir = ME_GetCursorOfs(&editor->pCursors[0])
|
||||
- ME_GetCursorOfs(&editor->pCursors[1]);
|
||||
|
||||
if (cdir*dir>0)
|
||||
return 0;
|
||||
|
|
|
@ -1013,8 +1013,8 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
|
|||
info->editor->pCursors[1].pRun = run;
|
||||
info->editor->pCursors[1].pPara = ME_GetParagraph(run);
|
||||
info->editor->pCursors[1].nOffset = 0;
|
||||
nOfs = ME_GetCursorOfs(info->editor, 1);
|
||||
nChars = ME_GetCursorOfs(info->editor, 0) - nOfs;
|
||||
nOfs = ME_GetCursorOfs(&info->editor->pCursors[1]);
|
||||
nChars = ME_GetCursorOfs(&info->editor->pCursors[0]) - nOfs;
|
||||
ME_InternalDeleteText(info->editor, nOfs, nChars, TRUE);
|
||||
}
|
||||
|
||||
|
@ -1516,8 +1516,8 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
|
|||
editor->pCursors[1].pPara = para;
|
||||
editor->pCursors[1].pRun = ME_FindItemFwd(para, diRun);
|
||||
editor->pCursors[1].nOffset = 0;
|
||||
nOfs = ME_GetCursorOfs(editor, 1);
|
||||
nChars = ME_GetCursorOfs(editor, 0) - nOfs;
|
||||
nOfs = ME_GetCursorOfs(&editor->pCursors[1]);
|
||||
nChars = ME_GetCursorOfs(&editor->pCursors[0]) - nOfs;
|
||||
ME_InternalDeleteText(editor, nOfs, nChars, TRUE);
|
||||
if (parser.tableDef)
|
||||
parser.tableDef->tableRowStart = NULL;
|
||||
|
@ -2352,7 +2352,7 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode,
|
|||
para = cursor.pPara;
|
||||
if (ME_IsSelection(editor) &&
|
||||
cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 &&
|
||||
to == ME_GetCursorOfs(editor, 0) &&
|
||||
to == ME_GetCursorOfs(&editor->pCursors[0]) &&
|
||||
para->member.para.prev_para->type == diParagraph)
|
||||
{
|
||||
para = para->member.para.prev_para;
|
||||
|
@ -3675,14 +3675,14 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
|
|||
case EM_LINEFROMCHAR:
|
||||
{
|
||||
if (wParam == -1)
|
||||
return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor, 1));
|
||||
return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(&editor->pCursors[1]));
|
||||
else
|
||||
return ME_RowNumberFromCharOfs(editor, wParam);
|
||||
}
|
||||
case EM_EXLINEFROMCHAR:
|
||||
{
|
||||
if (lParam == -1)
|
||||
return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor,1));
|
||||
return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(&editor->pCursors[1]));
|
||||
else
|
||||
return ME_RowNumberFromCharOfs(editor, lParam);
|
||||
}
|
||||
|
@ -4171,7 +4171,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
|
|||
return 0;
|
||||
case WM_IME_STARTCOMPOSITION:
|
||||
{
|
||||
editor->imeStartIndex=ME_GetCursorOfs(editor,0);
|
||||
editor->imeStartIndex=ME_GetCursorOfs(&editor->pCursors[0]);
|
||||
ME_DeleteSelection(editor);
|
||||
ME_CommitUndo(editor);
|
||||
ME_UpdateRepaint(editor);
|
||||
|
|
|
@ -166,7 +166,7 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
|
|||
void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor);
|
||||
BOOL ME_ArrowKey(ME_TextEditor *ed, int nVKey, BOOL extend, BOOL ctrl);
|
||||
|
||||
int ME_GetCursorOfs(ME_TextEditor *editor, int nCursor);
|
||||
int ME_GetCursorOfs(const ME_Cursor *cursor);
|
||||
void ME_GetSelection(ME_TextEditor *editor, int *from, int *to);
|
||||
int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to);
|
||||
BOOL ME_IsSelection(ME_TextEditor *editor);
|
||||
|
|
|
@ -551,8 +551,8 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow)
|
|||
ME_InvalidateSelection(editor);
|
||||
{
|
||||
int from, to;
|
||||
from = ME_GetCursorOfs(editor, 0);
|
||||
to = ME_GetCursorOfs(editor, 1);
|
||||
from = ME_GetCursorOfs(&editor->pCursors[0]);
|
||||
to = ME_GetCursorOfs(&editor->pCursors[1]);
|
||||
if (from <= to)
|
||||
{
|
||||
fromCursor = editor->pCursors[0];
|
||||
|
|
Loading…
Reference in New Issue