Commit 581321d4 authored by Lei Zhang's avatar Lei Zhang Committed by Alexandre Julliard

riched20: Move EM_EXSETSEL fix into ME_SetSelection.

parent 03fa9106
......@@ -78,41 +78,81 @@ int ME_GetTextLengthEx(ME_TextEditor *editor, GETTEXTLENGTHEX *how)
}
void ME_SetSelection(ME_TextEditor *editor, int from, int to)
int ME_SetSelection(ME_TextEditor *editor, int from, int to)
{
int selectionEnd = 0;
const int len = ME_GetTextLength(editor);
/* all negative values are effectively the same */
if (from < 0)
from = -1;
if (to < 0)
to = -1;
/* select all */
if (from == 0 && to == -1)
{
editor->pCursors[1].pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun);
editor->pCursors[1].pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun);
editor->pCursors[1].nOffset = 0;
editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
editor->pCursors[0].nOffset = 0;
editor->pCursors[0].nOffset = 0;
ME_InvalidateSelection(editor);
ME_ClearTempStyle(editor);
return;
return len + 1;
}
if (from == -1 && to == -1) /*-1,-1 means put the selection at the end of the text */
/* if both values are equal and also out of bound, that means to */
/* put the selection at the end of the text */
if ((from == to) && (to < 0 || to > len))
{
editor->pCursors[1].pRun = editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
editor->pCursors[1].nOffset = editor->pCursors[0].nOffset = 0;
ME_InvalidateSelection(editor);
ME_ClearTempStyle(editor);
return;
selectionEnd = 1;
}
if (from == -1)
else
{
editor->pCursors[1] = editor->pCursors[0];
ME_Repaint(editor);
ME_ClearTempStyle(editor);
return;
/* if from is negative and to is positive then selection is */
/* deselected and caret moved to end of the current selection */
if (from < 0)
{
int start, end;
ME_GetSelection(editor, &start, &end);
editor->pCursors[1] = editor->pCursors[0];
ME_Repaint(editor);
ME_ClearTempStyle(editor);
return end;
}
/* adjust to if it's a negative value */
if (to < 0)
to = len + 1;
/* flip from and to if they are reversed */
if (from>to)
{
int tmp = from;
from = to;
to = tmp;
}
/* after fiddling with the values, we find from > len && to > len */
if (from > len)
selectionEnd = 1;
/* special case with to too big */
else if (to > len)
to = len + 1;
}
if (from>to)
if (selectionEnd)
{
int tmp = from;
from = to;
to = tmp;
editor->pCursors[1].pRun = editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
editor->pCursors[1].nOffset = editor->pCursors[0].nOffset = 0;
ME_InvalidateSelection(editor);
ME_ClearTempStyle(editor);
return len;
}
ME_RunOfsFromCharOfs(editor, from, &editor->pCursors[1].pRun, &editor->pCursors[1].nOffset);
ME_RunOfsFromCharOfs(editor, to, &editor->pCursors[0].pRun, &editor->pCursors[0].nOffset);
ME_RunOfsFromCharOfs(editor, to, &editor->pCursors[0].pRun, &editor->pCursors[0].nOffset);
return to;
}
......
......@@ -1615,70 +1615,17 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
}
case EM_EXSETSEL:
{
int start, end;
int swap;
int end;
CHARRANGE range = *(CHARRANGE *)lParam;
TRACE("EM_EXSETSEL (%d,%d)\n", range.cpMin, range.cpMax);
/* all negative values are effectively the same */
if (range.cpMin < 0)
range.cpMin = -1;
if (range.cpMax < 0)
range.cpMax = -1;
if (range.cpMin != range.cpMax)
{
/* if cpMin is negative and cpMax is positive then selection is */
/* deselected and caret moved to end of the current selection */
if (range.cpMin < 0)
{
ME_GetSelection(editor, &start, &end);
range.cpMin = end;
range.cpMax = end;
}
else
{
/* adjust cpMax if it's a negative value */
if (range.cpMax < 0)
range.cpMax = ME_GetTextLength(editor) + 1;
/* flip cpMin and cpMax if they are reversed */
if (range.cpMin > range.cpMax)
{
swap = range.cpMin;
range.cpMin = range.cpMax;
range.cpMax = swap;
}
/* special case with cpMin too big */
if (range.cpMin > ME_GetTextLength(editor))
{
range.cpMin = ME_GetTextLength(editor);
range.cpMax = ME_GetTextLength(editor);
}
/* special case with cpMax too big */
else if (range.cpMax > ME_GetTextLength(editor))
range.cpMax = ME_GetTextLength(editor) + 1;
}
}
else
{
/* special case with cpMin == cpMax */
/* make sure both values are within bounds */
if (range.cpMax < 0 || range.cpMax > ME_GetTextLength(editor))
{
range.cpMin = ME_GetTextLength(editor);
range.cpMax = range.cpMin;
}
}
ME_InvalidateSelection(editor);
ME_SetSelection(editor, range.cpMin, range.cpMax);
end = ME_SetSelection(editor, range.cpMin, range.cpMax);
ME_InvalidateSelection(editor);
ME_SendSelChange(editor);
return range.cpMax;
return end;
}
case EM_SHOWSCROLLBAR:
{
......
......@@ -178,7 +178,7 @@ void ME_GetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt);
void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod);
/* caret.c */
void ME_SetSelection(ME_TextEditor *editor, int from, int to);
int ME_SetSelection(ME_TextEditor *editor, int from, int to);
void ME_SelectWord(ME_TextEditor *editor);
void ME_HideCaret(ME_TextEditor *ed);
void ME_ShowCaret(ME_TextEditor *ed);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment