Module: wine Branch: master Commit: be0fb1ef5dfcf3031e4b230523f8288ecc6d215c URL: http://source.winehq.org/git/wine.git/?a=commit;h=be0fb1ef5dfcf3031e4b230523...
Author: Dylan Smith dylan.ah.smith@gmail.com Date: Wed Aug 12 09:05:42 2009 -0400
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).
---
dlls/riched20/caret.c | 26 +++++++++++++------------- dlls/riched20/editor.c | 16 ++++++++-------- dlls/riched20/editor.h | 2 +- dlls/riched20/table.c | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index ca34977..2f93f0d 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -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,8 +1498,9 @@ 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; else diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 2b6f61f..2a37584 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -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); diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h index 7d9f704..7fa0566 100644 --- a/dlls/riched20/editor.h +++ b/dlls/riched20/editor.h @@ -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); diff --git a/dlls/riched20/table.c b/dlls/riched20/table.c index 0d2dab5..10e276a 100644 --- a/dlls/riched20/table.c +++ b/dlls/riched20/table.c @@ -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];