2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - Caret and selection functions.
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
2006-01-12 11:54:57 +01:00
|
|
|
* Copyright 2005 by Phil Krylov
|
2005-03-05 12:19:14 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
static BOOL
|
|
|
|
ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs);
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_GetSelection(ME_TextEditor *editor, int *from, int *to)
|
|
|
|
{
|
|
|
|
*from = ME_GetCursorOfs(editor, 0);
|
|
|
|
*to = ME_GetCursorOfs(editor, 1);
|
|
|
|
|
|
|
|
if (*from > *to)
|
|
|
|
{
|
|
|
|
int tmp = *from;
|
|
|
|
*from = *to;
|
|
|
|
*to = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ME_GetTextLength(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
return ME_CharOfsFromRunOfs(editor, ME_FindItemBack(editor->pBuffer->pLast, diRun), 0);
|
|
|
|
}
|
|
|
|
|
2005-06-28 15:51:32 +02:00
|
|
|
|
2007-08-11 17:07:50 +02:00
|
|
|
int ME_GetTextLengthEx(ME_TextEditor *editor, const GETTEXTLENGTHEX *how)
|
2005-06-28 15:51:32 +02:00
|
|
|
{
|
|
|
|
int length;
|
2007-08-11 17:07:50 +02:00
|
|
|
|
2005-06-28 15:51:32 +02:00
|
|
|
if (how->flags & GTL_PRECISE && how->flags & GTL_CLOSE)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (how->flags & GTL_NUMCHARS && how->flags & GTL_NUMBYTES)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
length = ME_GetTextLength(editor);
|
2007-08-15 15:47:17 +02:00
|
|
|
|
2008-04-27 03:37:50 +02:00
|
|
|
if ((GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_MULTILINE)
|
|
|
|
&& (how->flags & GTL_USECRLF)
|
|
|
|
&& !editor->bEmulateVersion10) /* Ignore GTL_USECRLF flag in 1.0 emulation */
|
2007-12-06 19:41:28 +01:00
|
|
|
length += editor->nParagraphs - 1;
|
2005-06-28 15:51:32 +02:00
|
|
|
|
|
|
|
if (how->flags & GTL_NUMBYTES)
|
|
|
|
{
|
|
|
|
CPINFO cpinfo;
|
|
|
|
|
|
|
|
if (how->codepage == 1200)
|
|
|
|
return length * 2;
|
|
|
|
if (how->flags & GTL_PRECISE)
|
|
|
|
FIXME("GTL_PRECISE flag unsupported. Using GTL_CLOSE\n");
|
|
|
|
if (GetCPInfo(how->codepage, &cpinfo))
|
|
|
|
return length * cpinfo.MaxCharSize;
|
|
|
|
ERR("Invalid codepage %u\n", how->codepage);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-04 20:54:24 +01:00
|
|
|
int ME_SetSelection(ME_TextEditor *editor, int from, int to)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-12-04 20:54:24 +01:00
|
|
|
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 */
|
2005-03-05 12:19:14 +01:00
|
|
|
if (from == 0 && to == -1)
|
|
|
|
{
|
2006-12-04 20:54:24 +01:00
|
|
|
editor->pCursors[1].pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun);
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->pCursors[1].nOffset = 0;
|
|
|
|
editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
|
2006-12-04 20:54:24 +01:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_InvalidateSelection(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_ClearTempStyle(editor);
|
2006-12-04 20:54:24 +01:00
|
|
|
return len + 1;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-12-04 20:54:24 +01:00
|
|
|
|
|
|
|
/* 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))
|
2006-09-03 05:12:06 +02:00
|
|
|
{
|
2006-12-04 20:54:24 +01:00
|
|
|
selectionEnd = 1;
|
2006-09-03 05:12:06 +02:00
|
|
|
}
|
2006-12-04 20:54:24 +01:00
|
|
|
else
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-12-04 20:54:24 +01:00
|
|
|
/* 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;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-12-04 20:54:24 +01:00
|
|
|
|
|
|
|
if (selectionEnd)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-12-04 20:54:24 +01:00
|
|
|
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;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-12-04 20:54:24 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_RunOfsFromCharOfs(editor, from, &editor->pCursors[1].pRun, &editor->pCursors[1].nOffset);
|
2006-12-04 20:54:24 +01:00
|
|
|
ME_RunOfsFromCharOfs(editor, to, &editor->pCursors[0].pRun, &editor->pCursors[0].nOffset);
|
|
|
|
return to;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
void
|
|
|
|
ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
|
|
|
|
int *x, int *y, int *height)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_DisplayItem *pCursorRun = pCursor->pRun;
|
|
|
|
ME_DisplayItem *pSizeRun = pCursor->pRun;
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
assert(height && x && y);
|
2006-08-04 23:40:06 +02:00
|
|
|
assert(!(ME_GetParagraph(pCursorRun)->member.para.nFlags & MEPF_REWRAP));
|
2006-08-07 17:27:16 +02:00
|
|
|
assert(pCursor->pRun);
|
|
|
|
assert(pCursor->pRun->type == diRun);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
if (pCursorRun->type == diRun) {
|
|
|
|
ME_DisplayItem *row = ME_FindItemBack(pCursorRun, diStartRowOrParagraph);
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (row) {
|
2006-01-10 20:23:41 +01:00
|
|
|
HDC hDC = GetDC(editor->hWnd);
|
|
|
|
ME_Context c;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_DisplayItem *run = pCursorRun;
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_DisplayItem *para = NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
SIZE sz = {0, 0};
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
ME_InitContext(&c, editor, hDC);
|
|
|
|
|
2008-06-26 22:17:32 +02:00
|
|
|
if (!pCursor->nOffset)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-06-26 22:17:32 +02:00
|
|
|
ME_DisplayItem *prev = ME_FindItemBack(pCursorRun, diRunOrParagraph);
|
2006-08-07 17:27:16 +02:00
|
|
|
assert(prev);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (prev->type == diRun)
|
|
|
|
pSizeRun = prev;
|
|
|
|
}
|
|
|
|
assert(row->type == diStartRow); /* paragraph -> run without start row ?*/
|
|
|
|
para = ME_FindItemBack(row, diParagraph);
|
2006-08-07 17:27:16 +02:00
|
|
|
assert(para);
|
|
|
|
assert(para->type == diParagraph);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (editor->bCaretAtEnd && !pCursor->nOffset &&
|
|
|
|
run == ME_FindItemFwd(row, diRun))
|
|
|
|
{
|
|
|
|
ME_DisplayItem *tmp = ME_FindItemBack(row, diRunOrParagraph);
|
2006-08-07 17:27:16 +02:00
|
|
|
assert(tmp);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (tmp->type == diRun)
|
|
|
|
{
|
|
|
|
row = ME_FindItemBack(tmp, diStartRow);
|
|
|
|
pSizeRun = run = tmp;
|
2006-08-07 17:27:16 +02:00
|
|
|
assert(run);
|
|
|
|
assert(run->type == diRun);
|
2008-03-16 21:47:08 +01:00
|
|
|
sz = ME_GetRunSize(&c, ¶->member.para,
|
|
|
|
&run->member.run, ME_StrLen(run->member.run.strText),
|
|
|
|
row->member.row.nLMargin);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
2008-06-23 23:09:44 +02:00
|
|
|
if (pCursor->nOffset) {
|
2008-03-16 21:47:08 +01:00
|
|
|
sz = ME_GetRunSize(&c, ¶->member.para, &run->member.run, pCursor->nOffset,
|
|
|
|
row->member.row.nLMargin);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
*height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent;
|
2008-12-18 07:56:49 +01:00
|
|
|
*x = c.rcView.left + run->member.run.pt.x + sz.cx;
|
|
|
|
*y = c.rcView.top + para->member.para.pt.y + row->member.row.nBaseline
|
|
|
|
+ run->member.run.pt.y - pSizeRun->member.run.nAscent - ME_GetYScrollPos(editor);
|
2008-03-16 21:48:13 +01:00
|
|
|
ME_DestroyContext(&c, editor->hWnd);
|
2006-01-10 20:23:41 +01:00
|
|
|
return;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
*height = 10; /* FIXME use global font */
|
|
|
|
*x = 0;
|
|
|
|
*y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ME_MoveCaret(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
int x, y, height;
|
|
|
|
|
2007-08-15 19:45:07 +02:00
|
|
|
if (ME_WrapMarkedParagraphs(editor))
|
|
|
|
ME_UpdateScrollBar(editor);
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height);
|
2008-07-07 17:04:06 +02:00
|
|
|
if(editor->bHaveFocus && !ME_IsSelection(editor))
|
2007-06-05 14:56:55 +02:00
|
|
|
{
|
2008-12-18 07:56:49 +01:00
|
|
|
x = min(x, editor->rcFormat.right-1);
|
2007-06-05 14:56:55 +02:00
|
|
|
CreateCaret(editor->hWnd, NULL, 0, height);
|
|
|
|
SetCaretPos(x, y);
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_ShowCaret(ME_TextEditor *ed)
|
|
|
|
{
|
|
|
|
ME_MoveCaret(ed);
|
2008-07-07 17:04:06 +02:00
|
|
|
if(ed->bHaveFocus && !ME_IsSelection(ed))
|
2007-06-05 14:56:55 +02:00
|
|
|
ShowCaret(ed->hWnd);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_HideCaret(ME_TextEditor *ed)
|
|
|
|
{
|
2008-07-07 17:04:06 +02:00
|
|
|
if(!ed->bHaveFocus || ME_IsSelection(ed))
|
2007-06-05 14:56:55 +02:00
|
|
|
{
|
|
|
|
HideCaret(ed->hWnd);
|
|
|
|
DestroyCaret();
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2008-08-05 18:10:51 +02:00
|
|
|
BOOL ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars,
|
|
|
|
BOOL bForce)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_Cursor c;
|
|
|
|
int shift = 0;
|
2008-08-05 01:19:01 +02:00
|
|
|
int totalChars = nChars;
|
2008-08-07 18:31:37 +02:00
|
|
|
ME_DisplayItem *start_para;
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Prevent deletion past last end of paragraph run. */
|
|
|
|
ME_DisplayItem *pTextEnd = editor->pBuffer->pLast;
|
|
|
|
int nMaxChars = pTextEnd->member.para.prev_para->member.para.nCharOfs;
|
|
|
|
nMaxChars += ME_FindItemBack(pTextEnd, diRun)->member.run.nCharOfs;
|
|
|
|
nMaxChars -= nOfs;
|
|
|
|
nChars = min(nChars, nMaxChars);
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_CursorFromCharOfs(editor, nOfs, &c);
|
|
|
|
start_para = ME_GetParagraph(c.pRun);
|
2008-08-05 18:10:51 +02:00
|
|
|
|
|
|
|
if (!bForce)
|
|
|
|
{
|
|
|
|
ME_ProtectPartialTableDeletion(editor, nOfs, &nChars);
|
|
|
|
if (nChars == 0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
while(nChars > 0)
|
|
|
|
{
|
|
|
|
ME_Run *run;
|
2008-08-07 18:31:37 +02:00
|
|
|
ME_CursorFromCharOfs(editor, nOfs+nChars, &c);
|
|
|
|
if (!c.nOffset &&
|
|
|
|
nOfs+nChars == (c.pRun->member.run.nCharOfs
|
|
|
|
+ ME_GetParagraph(c.pRun)->member.para.nCharOfs))
|
|
|
|
{
|
|
|
|
/* We aren't deleting anything in this run, so we will go back to the
|
|
|
|
* last run we are deleting text in. */
|
|
|
|
c.pRun = ME_FindItemBack(c.pRun, diRun);
|
|
|
|
if (c.pRun->member.run.nFlags & MERF_ENDPARA)
|
|
|
|
c.nOffset = c.pRun->member.run.nCR + c.pRun->member.run.nLF;
|
|
|
|
else
|
|
|
|
c.nOffset = c.pRun->member.run.strText->nLen;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
run = &c.pRun->member.run;
|
|
|
|
if (run->nFlags & MERF_ENDPARA) {
|
2008-04-26 22:48:24 +02:00
|
|
|
int eollen = run->nCR + run->nLF;
|
2008-08-05 01:19:01 +02:00
|
|
|
BOOL keepFirstParaFormat;
|
2008-04-26 22:48:24 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (!ME_FindItemFwd(c.pRun, diParagraph))
|
|
|
|
{
|
2008-08-05 18:10:51 +02:00
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-08-05 01:19:01 +02:00
|
|
|
keepFirstParaFormat = (totalChars == nChars && nChars <= eollen &&
|
|
|
|
run->nCharOfs);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
|
|
|
ME_DisplayItem *next_para = ME_FindItemFwd(c.pRun, diParagraphOrEnd);
|
|
|
|
ME_DisplayItem *this_para = next_para->member.para.prev_para;
|
|
|
|
|
|
|
|
/* The end of paragraph before a table row is only deleted if there
|
|
|
|
* is nothing else on the line before it. */
|
|
|
|
if (this_para == start_para &&
|
|
|
|
next_para->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
{
|
|
|
|
/* If the paragraph will be empty, then it should be deleted, however
|
|
|
|
* it still might have text right now which would inherit the
|
|
|
|
* MEPF_STARTROW property if we joined it right now.
|
|
|
|
* Instead we will delete it after the preceding text is deleted. */
|
|
|
|
if (nOfs > this_para->member.para.nCharOfs) {
|
|
|
|
/* Skip this end of line. */
|
|
|
|
nChars -= (eollen < nChars) ? eollen : nChars;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
keepFirstParaFormat = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-08-05 01:19:01 +02:00
|
|
|
ME_JoinParagraphs(editor, ME_GetParagraph(c.pRun), keepFirstParaFormat);
|
2005-03-05 12:19:14 +01:00
|
|
|
/* ME_SkipAndPropagateCharOffset(p->pRun, shift); */
|
|
|
|
ME_CheckCharOffsets(editor);
|
2008-04-26 22:48:24 +02:00
|
|
|
nChars -= (eollen < nChars) ? eollen : nChars;
|
2005-03-05 12:19:14 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_Cursor cursor;
|
2008-08-07 18:31:37 +02:00
|
|
|
int nCharsToDelete = min(nChars, c.nOffset);
|
2005-03-05 12:19:14 +01:00
|
|
|
int i;
|
2008-08-07 18:31:37 +02:00
|
|
|
|
|
|
|
c.nOffset -= nCharsToDelete;
|
|
|
|
|
2005-03-09 12:48:59 +01:00
|
|
|
ME_FindItemBack(c.pRun, diParagraph)->member.para.nFlags |= MEPF_REWRAP;
|
2008-08-07 18:31:37 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
cursor = c;
|
|
|
|
/* nChars is the number of characters that should be deleted from the
|
2008-08-07 18:31:37 +02:00
|
|
|
PRECEDING runs (these BEFORE cursor.pRun)
|
2005-03-05 12:19:14 +01:00
|
|
|
nCharsToDelete is a number of chars to delete from THIS run */
|
2008-08-07 18:31:37 +02:00
|
|
|
nChars -= nCharsToDelete;
|
2005-03-05 12:19:14 +01:00
|
|
|
shift -= nCharsToDelete;
|
2008-08-07 18:31:37 +02:00
|
|
|
TRACE("Deleting %d (remaning %d) chars at %d in '%s' (%d)\n",
|
|
|
|
nCharsToDelete, nChars, c.nOffset,
|
2005-03-05 12:19:14 +01:00
|
|
|
debugstr_w(run->strText->szData), run->strText->nLen);
|
|
|
|
|
|
|
|
if (!c.nOffset && ME_StrVLen(run->strText) == nCharsToDelete)
|
|
|
|
{
|
|
|
|
/* undo = reinsert whole run */
|
|
|
|
/* nOfs is a character offset (from the start of the document
|
|
|
|
to the current (deleted) run */
|
|
|
|
ME_UndoItem *pUndo = ME_AddUndoItem(editor, diUndoInsertRun, c.pRun);
|
|
|
|
if (pUndo)
|
2008-08-07 18:31:37 +02:00
|
|
|
pUndo->di.member.run.nCharOfs = nOfs+nChars;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* undo = reinsert partial run */
|
|
|
|
ME_UndoItem *pUndo = ME_AddUndoItem(editor, diUndoInsertRun, c.pRun);
|
|
|
|
if (pUndo) {
|
|
|
|
ME_DestroyString(pUndo->di.member.run.strText);
|
2008-08-07 18:31:37 +02:00
|
|
|
pUndo->di.member.run.nCharOfs = nOfs+nChars;
|
2005-03-05 12:19:14 +01:00
|
|
|
pUndo->di.member.run.strText = ME_MakeStringN(run->strText->szData+c.nOffset, nCharsToDelete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE("Post deletion string: %s (%d)\n", debugstr_w(run->strText->szData), run->strText->nLen);
|
|
|
|
TRACE("Shift value: %d\n", shift);
|
|
|
|
ME_StrDeleteV(run->strText, c.nOffset, nCharsToDelete);
|
|
|
|
|
|
|
|
/* update cursors (including c) */
|
|
|
|
for (i=-1; i<editor->nCursors; i++) {
|
|
|
|
ME_Cursor *pThisCur = editor->pCursors + i;
|
|
|
|
if (i == -1) pThisCur = &c;
|
|
|
|
if (pThisCur->pRun == cursor.pRun) {
|
|
|
|
if (pThisCur->nOffset > cursor.nOffset) {
|
|
|
|
if (pThisCur->nOffset-cursor.nOffset < nCharsToDelete)
|
|
|
|
pThisCur->nOffset = cursor.nOffset;
|
|
|
|
else
|
|
|
|
pThisCur->nOffset -= nCharsToDelete;
|
|
|
|
assert(pThisCur->nOffset >= 0);
|
|
|
|
assert(pThisCur->nOffset <= ME_StrVLen(run->strText));
|
|
|
|
}
|
|
|
|
if (pThisCur->nOffset == ME_StrVLen(run->strText))
|
|
|
|
{
|
|
|
|
pThisCur->pRun = ME_FindItemFwd(pThisCur->pRun, diRunOrParagraphOrEnd);
|
|
|
|
assert(pThisCur->pRun->type == diRun);
|
|
|
|
pThisCur->nOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* c = updated data now */
|
|
|
|
|
|
|
|
if (c.pRun == cursor.pRun)
|
|
|
|
ME_SkipAndPropagateCharOffset(c.pRun, shift);
|
|
|
|
else
|
|
|
|
ME_PropagateCharOffset(c.pRun, shift);
|
|
|
|
|
|
|
|
if (!ME_StrVLen(cursor.pRun->member.run.strText))
|
|
|
|
{
|
|
|
|
TRACE("Removing useless run\n");
|
|
|
|
ME_Remove(cursor.pRun);
|
|
|
|
ME_DestroyDisplayItem(cursor.pRun);
|
|
|
|
}
|
|
|
|
|
|
|
|
shift = 0;
|
|
|
|
/*
|
|
|
|
ME_CheckCharOffsets(editor);
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2008-08-05 18:10:51 +02:00
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2008-08-05 18:10:51 +02:00
|
|
|
BOOL ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
assert(nCursor>=0 && nCursor<editor->nCursors);
|
2007-04-26 00:54:53 +02:00
|
|
|
/* text operations set modified state */
|
|
|
|
editor->nModifyStep = 1;
|
2008-08-05 18:10:51 +02:00
|
|
|
return ME_InternalDeleteText(editor, ME_GetCursorOfs(editor, nCursor), nChars,
|
|
|
|
FALSE);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-02-04 17:01:01 +01:00
|
|
|
static ME_DisplayItem *
|
2005-08-23 20:16:15 +02:00
|
|
|
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);
|
|
|
|
|
2006-02-04 17:01:01 +01:00
|
|
|
return ME_InsertRunAtCursor(editor, p, style, str, len, flags);
|
2005-08-23 20:16:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-27 19:01:41 +01:00
|
|
|
void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCursor)
|
2006-02-04 16:59:48 +01:00
|
|
|
{
|
2008-01-27 19:01:41 +01:00
|
|
|
ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
|
|
|
|
ME_DisplayItem *di;
|
|
|
|
WCHAR space = ' ';
|
2006-02-04 16:59:48 +01:00
|
|
|
|
|
|
|
/* FIXME no no no */
|
|
|
|
if (ME_IsSelection(editor))
|
|
|
|
ME_DeleteSelection(editor);
|
|
|
|
|
2008-01-27 19:01:41 +01:00
|
|
|
di = ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle,
|
|
|
|
MERF_GRAPHICS);
|
|
|
|
di->member.run.ole_obj = ALLOC_OBJ(*reo);
|
|
|
|
ME_CopyReObject(di->member.run.ole_obj, reo);
|
2006-02-04 16:59:48 +01:00
|
|
|
ME_SendSelChange(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-16 21:46:51 +01:00
|
|
|
void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor)
|
|
|
|
{
|
|
|
|
ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
|
|
|
|
ME_DisplayItem *di;
|
|
|
|
WCHAR space = ' ';
|
|
|
|
|
|
|
|
/* FIXME no no no */
|
|
|
|
if (ME_IsSelection(editor))
|
|
|
|
ME_DeleteSelection(editor);
|
|
|
|
|
|
|
|
di = ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle,
|
|
|
|
MERF_ENDROW);
|
|
|
|
ME_SendSelChange(editor);
|
|
|
|
}
|
|
|
|
|
2006-02-04 17:01:01 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
|
|
|
|
const WCHAR *str, int len, ME_Style *style)
|
|
|
|
{
|
|
|
|
const WCHAR *pos;
|
|
|
|
ME_Cursor *p = NULL;
|
2007-09-20 23:58:02 +02:00
|
|
|
int oldLen;
|
2007-03-28 15:03:41 +02:00
|
|
|
|
|
|
|
/* FIXME really HERE ? */
|
|
|
|
if (ME_IsSelection(editor))
|
|
|
|
ME_DeleteSelection(editor);
|
|
|
|
|
2006-08-09 21:33:42 +02:00
|
|
|
/* FIXME: is this too slow? */
|
|
|
|
/* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */
|
2007-09-20 23:58:02 +02:00
|
|
|
oldLen = ME_GetTextLength(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2007-01-11 08:46:35 +01:00
|
|
|
/* text operations set modified state */
|
|
|
|
editor->nModifyStep = 1;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(style);
|
|
|
|
|
|
|
|
assert(nCursor>=0 && nCursor<editor->nCursors);
|
|
|
|
if (len == -1)
|
|
|
|
len = lstrlenW(str);
|
2007-09-20 23:58:02 +02:00
|
|
|
|
|
|
|
/* grow the text limit to fit our text */
|
|
|
|
if(editor->nTextLimit < oldLen +len)
|
|
|
|
editor->nTextLimit = oldLen + len;
|
|
|
|
|
2005-08-23 20:16:15 +02:00
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
pos = str;
|
|
|
|
/* 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')
|
|
|
|
pos++;
|
|
|
|
if (pos-str < len && *pos == '\t') { /* handle tabs */
|
|
|
|
WCHAR tab = '\t';
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-08-23 20:16:15 +02:00
|
|
|
if (pos!=str)
|
|
|
|
ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0);
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-08-23 20:16:15 +02:00
|
|
|
ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, style, MERF_TAB);
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
if(pos-str <= len) {
|
|
|
|
len -= pos - str;
|
|
|
|
str = pos;
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2007-10-21 03:23:27 +02:00
|
|
|
/* handle special \r\r\n sequence (richedit 2.x and higher only) */
|
|
|
|
if (!editor->bEmulateVersion10 && pos-str < len-2 && pos[0] == '\r' && pos[1] == '\r' && pos[2] == '\n') {
|
|
|
|
WCHAR space = ' ';
|
|
|
|
|
|
|
|
if (pos!=str)
|
|
|
|
ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0);
|
|
|
|
|
|
|
|
ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, style, 0);
|
|
|
|
|
|
|
|
pos+=3;
|
|
|
|
if(pos-str <= len) {
|
|
|
|
len -= pos - str;
|
|
|
|
str = pos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2005-08-23 20:16:15 +02:00
|
|
|
if (pos-str < len) { /* handle EOLs */
|
|
|
|
ME_DisplayItem *tp, *end_run;
|
|
|
|
ME_Style *tmp_style;
|
2008-04-27 05:49:35 +02:00
|
|
|
int numCR, numLF;
|
|
|
|
|
2005-08-23 20:16:15 +02:00
|
|
|
if (pos!=str)
|
|
|
|
ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0);
|
2005-03-05 12:19:14 +01:00
|
|
|
p = &editor->pCursors[nCursor];
|
2005-08-23 20:16:15 +02:00
|
|
|
if (p->nOffset) {
|
|
|
|
ME_SplitRunSimple(editor, p->pRun, p->nOffset);
|
|
|
|
p = &editor->pCursors[nCursor];
|
|
|
|
}
|
|
|
|
tmp_style = ME_GetInsertStyle(editor, nCursor);
|
|
|
|
/* ME_SplitParagraph increases style refcount */
|
2008-04-26 20:29:53 +02:00
|
|
|
|
2008-04-27 05:49:35 +02:00
|
|
|
/* Encode and fill number of CR and LF according to emulation mode */
|
2008-04-21 17:10:05 +02:00
|
|
|
if (editor->bEmulateVersion10) {
|
|
|
|
const WCHAR * tpos;
|
|
|
|
|
2008-04-27 05:49:35 +02:00
|
|
|
/* We have to find out how many consecutive \r are there, and if there
|
|
|
|
is a \n terminating the run of \r's. */
|
|
|
|
numCR = 0; numLF = 0;
|
2008-04-21 17:10:05 +02:00
|
|
|
tpos = pos;
|
|
|
|
while (tpos-str < len && *tpos == '\r') {
|
|
|
|
tpos++;
|
2008-04-27 05:49:35 +02:00
|
|
|
numCR++;
|
2008-04-21 17:10:05 +02:00
|
|
|
}
|
|
|
|
if (tpos-str >= len) {
|
2008-04-27 05:49:35 +02:00
|
|
|
/* Reached end of text without finding anything but '\r' */
|
|
|
|
if (tpos != pos) {
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
numCR = 1; numLF = 0;
|
|
|
|
} else if (*tpos == '\n') {
|
|
|
|
/* The entire run of \r's plus the one \n is one single line break */
|
2008-04-21 17:10:05 +02:00
|
|
|
pos = tpos + 1;
|
2008-04-27 05:49:35 +02:00
|
|
|
numLF = 1;
|
|
|
|
} else {
|
|
|
|
/* Found some other content past the run of \r's */
|
2008-04-21 17:10:05 +02:00
|
|
|
pos++;
|
2008-04-27 05:49:35 +02:00
|
|
|
numCR = 1; numLF = 0;
|
|
|
|
}
|
2008-04-21 17:10:05 +02:00
|
|
|
} else {
|
|
|
|
if(pos-str < len && *pos =='\r')
|
|
|
|
pos++;
|
|
|
|
if(pos-str < len && *pos =='\n')
|
|
|
|
pos++;
|
2008-04-27 05:49:35 +02:00
|
|
|
numCR = 1; numLF = 0;
|
2008-04-21 17:10:05 +02:00
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
tp = ME_SplitParagraph(editor, p->pRun, p->pRun->member.run.style, numCR, numLF, 0);
|
2008-04-27 05:49:35 +02:00
|
|
|
p->pRun = ME_FindItemFwd(tp, diRun);
|
|
|
|
end_run = ME_FindItemBack(tp, diRun);
|
|
|
|
ME_ReleaseStyle(end_run->member.run.style);
|
|
|
|
end_run->member.run.style = tmp_style;
|
|
|
|
p->nOffset = 0;
|
|
|
|
|
2005-08-23 20:16:15 +02:00
|
|
|
if(pos-str <= len) {
|
|
|
|
len -= pos - str;
|
|
|
|
str = pos;
|
|
|
|
continue;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2005-08-23 20:16:15 +02:00
|
|
|
ME_InternalInsertTextFromCursor(editor, nCursor, str, len, style, 0);
|
|
|
|
len = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
static BOOL
|
|
|
|
ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-01-31 13:01:26 +01:00
|
|
|
ME_DisplayItem *pRun = pCursor->pRun;
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
if (nRelOfs == -1)
|
|
|
|
{
|
|
|
|
if (!pCursor->nOffset)
|
|
|
|
{
|
2006-01-31 13:01:26 +01:00
|
|
|
do {
|
|
|
|
pRun = ME_FindItemBack(pRun, diRunOrParagraph);
|
|
|
|
assert(pRun);
|
|
|
|
switch (pRun->type)
|
|
|
|
{
|
|
|
|
case diRun:
|
|
|
|
break;
|
|
|
|
case diParagraph:
|
|
|
|
if (pRun->member.para.prev_para->type == diTextStart)
|
|
|
|
return FALSE;
|
|
|
|
pRun = ME_FindItemBack(pRun, diRunOrParagraph);
|
|
|
|
/* every paragraph ought to have at least one run */
|
|
|
|
assert(pRun && pRun->type == diRun);
|
|
|
|
assert(pRun->member.run.nFlags & MERF_ENDPARA);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(pRun->type != diRun && pRun->type != diParagraph);
|
2006-01-10 20:23:41 +01:00
|
|
|
return FALSE;
|
2006-01-31 13:01:26 +01:00
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
} while (RUN_IS_HIDDEN(&pRun->member.run) ||
|
|
|
|
pRun->member.run.nFlags & MERF_HIDDEN);
|
2006-01-31 13:01:26 +01:00
|
|
|
pCursor->pRun = pRun;
|
|
|
|
if (pRun->member.run.nFlags & MERF_ENDPARA)
|
|
|
|
pCursor->nOffset = 0;
|
|
|
|
else
|
|
|
|
pCursor->nOffset = pRun->member.run.strText->nLen;
|
2006-01-10 20:23:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pCursor->nOffset)
|
|
|
|
pCursor->nOffset = ME_StrRelPos2(pCursor->pRun->member.run.strText, pCursor->nOffset, nRelOfs);
|
2005-03-05 12:19:14 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-31 13:01:26 +01:00
|
|
|
if (!(pRun->member.run.nFlags & MERF_ENDPARA))
|
2006-01-10 20:23:41 +01:00
|
|
|
{
|
2006-01-31 13:01:26 +01:00
|
|
|
int new_ofs = ME_StrRelPos2(pRun->member.run.strText, pCursor->nOffset, nRelOfs);
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2006-01-31 13:01:26 +01:00
|
|
|
if (new_ofs < pRun->member.run.strText->nLen)
|
2006-01-10 20:23:41 +01:00
|
|
|
{
|
|
|
|
pCursor->nOffset = new_ofs;
|
2005-03-05 12:19:14 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2006-01-31 13:01:26 +01:00
|
|
|
do {
|
|
|
|
pRun = ME_FindItemFwd(pRun, diRun);
|
2008-08-07 18:31:41 +02:00
|
|
|
} while (pRun && (RUN_IS_HIDDEN(&pRun->member.run) ||
|
|
|
|
pRun->member.run.nFlags & MERF_HIDDEN));
|
2006-01-10 20:23:41 +01:00
|
|
|
if (pRun)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-01-10 20:23:41 +01:00
|
|
|
pCursor->pRun = pRun;
|
|
|
|
pCursor->nOffset = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2005-03-14 11:08:00 +01:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2006-01-12 11:54:57 +01:00
|
|
|
static BOOL
|
|
|
|
ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pRun = cursor->pRun, *pOtherRun;
|
|
|
|
int nOffset = cursor->nOffset;
|
|
|
|
|
|
|
|
if (nRelOfs == -1)
|
|
|
|
{
|
|
|
|
/* Backward movement */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
nOffset = ME_CallWordBreakProc(editor, pRun->member.run.strText,
|
|
|
|
nOffset, WB_MOVEWORDLEFT);
|
|
|
|
if (nOffset)
|
|
|
|
break;
|
|
|
|
pOtherRun = ME_FindItemBack(pRun, diRunOrParagraph);
|
|
|
|
if (pOtherRun->type == diRun)
|
|
|
|
{
|
|
|
|
if (ME_CallWordBreakProc(editor, pOtherRun->member.run.strText,
|
|
|
|
pOtherRun->member.run.strText->nLen - 1,
|
|
|
|
WB_ISDELIMITER)
|
|
|
|
&& !(pRun->member.run.nFlags & MERF_ENDPARA)
|
|
|
|
&& !(cursor->pRun == pRun && cursor->nOffset == 0)
|
|
|
|
&& !ME_CallWordBreakProc(editor, pRun->member.run.strText, 0,
|
|
|
|
WB_ISDELIMITER))
|
|
|
|
break;
|
|
|
|
pRun = pOtherRun;
|
|
|
|
nOffset = pOtherRun->member.run.strText->nLen;
|
|
|
|
}
|
|
|
|
else if (pOtherRun->type == diParagraph)
|
|
|
|
{
|
|
|
|
if (cursor->pRun == pRun && cursor->nOffset == 0)
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
/* Skip empty start of table row paragraph */
|
|
|
|
if (pOtherRun->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
pOtherRun = pOtherRun->member.para.prev_para;
|
2006-01-12 11:54:57 +01:00
|
|
|
/* Paragraph breaks are treated as separate words */
|
|
|
|
if (pOtherRun->member.para.prev_para->type == diTextStart)
|
|
|
|
return FALSE;
|
2008-08-07 18:31:41 +02:00
|
|
|
|
2006-01-12 11:54:57 +01:00
|
|
|
pRun = ME_FindItemBack(pOtherRun, diRunOrParagraph);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Forward movement */
|
|
|
|
BOOL last_delim = FALSE;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (last_delim && !ME_CallWordBreakProc(editor, pRun->member.run.strText,
|
|
|
|
nOffset, WB_ISDELIMITER))
|
|
|
|
break;
|
|
|
|
nOffset = ME_CallWordBreakProc(editor, pRun->member.run.strText,
|
|
|
|
nOffset, WB_MOVEWORDRIGHT);
|
|
|
|
if (nOffset < pRun->member.run.strText->nLen)
|
|
|
|
break;
|
|
|
|
pOtherRun = ME_FindItemFwd(pRun, diRunOrParagraphOrEnd);
|
|
|
|
if (pOtherRun->type == diRun)
|
|
|
|
{
|
|
|
|
last_delim = ME_CallWordBreakProc(editor, pRun->member.run.strText,
|
|
|
|
nOffset - 1, WB_ISDELIMITER);
|
|
|
|
pRun = pOtherRun;
|
|
|
|
nOffset = 0;
|
|
|
|
}
|
|
|
|
else if (pOtherRun->type == diParagraph)
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
if (pOtherRun->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
pOtherRun = pOtherRun->member.para.next_para;
|
2006-01-12 11:54:57 +01:00
|
|
|
if (cursor->pRun == pRun)
|
|
|
|
pRun = ME_FindItemFwd(pOtherRun, diRun);
|
|
|
|
nOffset = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else /* diTextEnd */
|
|
|
|
{
|
|
|
|
if (cursor->pRun == pRun)
|
|
|
|
return FALSE;
|
|
|
|
nOffset = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cursor->pRun = pRun;
|
|
|
|
cursor->nOffset = nOffset;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2006-01-13 13:54:11 +01:00
|
|
|
void
|
2008-07-07 17:03:59 +02:00
|
|
|
ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType)
|
2006-01-13 13:54:11 +01:00
|
|
|
{
|
2008-08-05 18:10:43 +02:00
|
|
|
/* pCursor[0] is the end of the selection
|
|
|
|
* pCursor[1] is the start of the selection (or the position selection anchor)
|
2008-07-07 17:03:59 +02:00
|
|
|
* pCursor[2] and [3] are the selection anchors that are backed up
|
|
|
|
* so they are kept when the selection changes for drag selection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
editor->nSelectionType = selectionType;
|
|
|
|
switch(selectionType)
|
|
|
|
{
|
|
|
|
case stPosition:
|
|
|
|
break;
|
|
|
|
case stWord:
|
2008-08-05 18:10:43 +02:00
|
|
|
ME_MoveCursorWords(editor, &editor->pCursors[0], +1);
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
ME_MoveCursorWords(editor, &editor->pCursors[1], -1);
|
2008-07-07 17:03:59 +02:00
|
|
|
break;
|
|
|
|
case stLine:
|
|
|
|
case stParagraph:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pItem;
|
|
|
|
ME_DIType fwdSearchType, backSearchType;
|
|
|
|
if (selectionType == stParagraph) {
|
|
|
|
backSearchType = diParagraph;
|
|
|
|
fwdSearchType = diParagraphOrEnd;
|
|
|
|
} else {
|
|
|
|
backSearchType = diStartRow;
|
|
|
|
fwdSearchType = diStartRowOrParagraphOrEnd;
|
|
|
|
}
|
|
|
|
pItem = ME_FindItemFwd(editor->pCursors[0].pRun, fwdSearchType);
|
|
|
|
assert(pItem);
|
|
|
|
if (pItem->type == diTextEnd)
|
2008-08-05 18:10:43 +02:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemBack(pItem, diRun);
|
2008-07-07 17:03:59 +02:00
|
|
|
else
|
2008-08-05 18:10:43 +02:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(pItem, diRun);
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
|
|
|
|
pItem = ME_FindItemBack(pItem, backSearchType);
|
|
|
|
editor->pCursors[1].pRun = ME_FindItemFwd(pItem, diRun);
|
2008-07-07 17:03:59 +02:00
|
|
|
editor->pCursors[1].nOffset = 0;
|
|
|
|
break;
|
|
|
|
}
|
2008-07-07 17:04:02 +02:00
|
|
|
case stDocument:
|
|
|
|
/* Select everything with cursor anchored from the start of the text */
|
|
|
|
editor->nSelectionType = stDocument;
|
|
|
|
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;
|
|
|
|
break;
|
2008-07-07 17:03:59 +02:00
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
/* Store the anchor positions for extending the selection. */
|
|
|
|
editor->pCursors[2] = editor->pCursors[0];
|
|
|
|
editor->pCursors[3] = editor->pCursors[1];
|
2006-01-13 13:54:11 +01:00
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
int ME_GetCursorOfs(ME_TextEditor *editor, int nCursor)
|
|
|
|
{
|
|
|
|
ME_Cursor *pCursor = &editor->pCursors[nCursor];
|
|
|
|
return ME_GetParagraph(pCursor->pRun)->member.para.nCharOfs
|
|
|
|
+ pCursor->pRun->member.run.nCharOfs + pCursor->nOffset;
|
|
|
|
}
|
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
/* Helper function for ME_FindPixelPos to find paragraph within tables */
|
|
|
|
static ME_DisplayItem* ME_FindPixelPosInTableRow(int x, int y,
|
|
|
|
ME_DisplayItem *para)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *cell, *next_cell;
|
|
|
|
assert(para->member.para.nFlags & MEPF_ROWSTART);
|
|
|
|
cell = para->member.para.next_para->member.para.pCell;
|
|
|
|
assert(cell);
|
|
|
|
|
|
|
|
/* find the cell we are in */
|
|
|
|
while ((next_cell = cell->member.cell.next_cell) != NULL) {
|
|
|
|
if (x < next_cell->member.cell.pt.x)
|
|
|
|
{
|
|
|
|
para = ME_FindItemFwd(cell, diParagraph);
|
|
|
|
/* Found the cell, but there might be multiple paragraphs in
|
|
|
|
* the cell, so need to search down the cell for the paragraph. */
|
|
|
|
while (cell == para->member.para.pCell) {
|
|
|
|
if (y < para->member.para.pt.y + para->member.para.nHeight)
|
|
|
|
{
|
|
|
|
if (para->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
return ME_FindPixelPosInTableRow(x, y, para);
|
|
|
|
else
|
|
|
|
return para;
|
|
|
|
}
|
|
|
|
para = para->member.para.next_para;
|
|
|
|
}
|
|
|
|
/* Past the end of the cell, so go back to the last cell paragraph */
|
|
|
|
return para->member.para.prev_para;
|
|
|
|
}
|
|
|
|
cell = next_cell;
|
|
|
|
}
|
|
|
|
/* Return table row delimiter */
|
|
|
|
para = ME_FindItemFwd(cell, diParagraph);
|
|
|
|
assert(para->member.para.nFlags & MEPF_ROWEND);
|
|
|
|
assert(para->member.para.pFmt->dwMask & PFM_TABLEROWDELIMITER);
|
|
|
|
assert(para->member.para.pFmt->wEffects & PFE_TABLEROWDELIMITER);
|
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
2008-09-10 20:08:46 +02:00
|
|
|
static BOOL ME_ReturnFoundPos(ME_TextEditor *editor, ME_DisplayItem *found,
|
|
|
|
ME_Cursor *result, int rx, BOOL isExact)
|
|
|
|
{
|
|
|
|
assert(found);
|
|
|
|
assert(found->type == diRun);
|
|
|
|
if ((found->member.run.nFlags & MERF_ENDPARA) || rx < 0)
|
|
|
|
rx = 0;
|
|
|
|
result->pRun = found;
|
|
|
|
result->nOffset = ME_CharFromPointCursor(editor, rx, &found->member.run);
|
|
|
|
if (editor->pCursors[0].nOffset == found->member.run.strText->nLen && rx)
|
|
|
|
{
|
|
|
|
result->pRun = ME_FindItemFwd(editor->pCursors[0].pRun, diRun);
|
|
|
|
result->nOffset = 0;
|
|
|
|
}
|
|
|
|
return isExact;
|
|
|
|
}
|
|
|
|
|
2008-07-09 15:36:12 +02:00
|
|
|
/* Finds the run and offset from the pixel position.
|
|
|
|
*
|
|
|
|
* x & y are pixel positions in virtual coordinates into the rich edit control,
|
|
|
|
* so client coordinates must first be adjusted by the scroll position.
|
|
|
|
*
|
|
|
|
* returns TRUE if the result was exactly under the cursor, otherwise returns
|
|
|
|
* FALSE, and result is set to the closest position to the coordinates.
|
|
|
|
*/
|
|
|
|
static BOOL ME_FindPixelPos(ME_TextEditor *editor, int x, int y,
|
|
|
|
ME_Cursor *result, BOOL *is_eol)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *p = editor->pBuffer->pFirst->member.para.next_para;
|
2008-01-01 22:05:05 +01:00
|
|
|
ME_DisplayItem *last = NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
int rx = 0;
|
2008-07-09 15:36:12 +02:00
|
|
|
BOOL isExact = TRUE;
|
2008-01-01 22:05:05 +01:00
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
x -= editor->rcFormat.left;
|
|
|
|
y -= editor->rcFormat.top;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (is_eol)
|
|
|
|
*is_eol = 0;
|
|
|
|
|
2008-01-01 22:05:05 +01:00
|
|
|
/* find paragraph */
|
|
|
|
for (; p != editor->pBuffer->pLast; p = p->member.para.next_para)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-01-01 22:05:05 +01:00
|
|
|
assert(p->type == diParagraph);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (y < p->member.para.pt.y + p->member.para.nHeight)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
if (p->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
p = ME_FindPixelPosInTableRow(x, y, p);
|
|
|
|
y -= p->member.para.pt.y;
|
2005-03-05 12:19:14 +01:00
|
|
|
p = ME_FindItemFwd(p, diStartRow);
|
2008-01-01 22:05:05 +01:00
|
|
|
break;
|
2008-08-07 18:31:41 +02:00
|
|
|
} else if (p->member.para.nFlags & MEPF_ROWSTART) {
|
|
|
|
p = ME_GetTableRowEnd(p);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-01-01 22:05:05 +01:00
|
|
|
}
|
|
|
|
/* find row */
|
|
|
|
for (; p != editor->pBuffer->pLast; )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pp;
|
|
|
|
assert(p->type == diStartRow);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (y < p->member.row.pt.y + p->member.row.nHeight)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-01-01 22:05:05 +01:00
|
|
|
p = ME_FindItemFwd(p, diRun);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pp = ME_FindItemFwd(p, diStartRowOrParagraphOrEnd);
|
|
|
|
if (pp->type != diStartRow)
|
|
|
|
{
|
|
|
|
p = ME_FindItemFwd(p, diRun);
|
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-01-01 22:05:05 +01:00
|
|
|
p = pp;
|
|
|
|
}
|
2008-06-27 15:18:39 +02:00
|
|
|
if (p == editor->pBuffer->pLast)
|
|
|
|
{
|
|
|
|
/* The position is below the last paragraph, so the last row will be used
|
|
|
|
* rather than the end of the text, so the x position will be used to
|
|
|
|
* determine the offset closest to the pixel position. */
|
2008-07-09 15:36:12 +02:00
|
|
|
isExact = FALSE;
|
2008-06-27 15:18:39 +02:00
|
|
|
p = ME_FindItemBack(p, diStartRow);
|
|
|
|
if (p != NULL){
|
|
|
|
p = ME_FindItemFwd(p, diRun);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = editor->pBuffer->pLast;
|
|
|
|
}
|
|
|
|
}
|
2008-01-01 22:05:05 +01:00
|
|
|
for (; p != editor->pBuffer->pLast; p = p->next)
|
|
|
|
{
|
|
|
|
switch (p->type)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-01-01 22:05:05 +01:00
|
|
|
case diRun:
|
2005-03-05 12:19:14 +01:00
|
|
|
rx = x - p->member.run.pt.x;
|
2008-01-01 22:05:05 +01:00
|
|
|
if (rx < p->member.run.nWidth)
|
2008-09-10 20:08:46 +02:00
|
|
|
return ME_ReturnFoundPos(editor, p, result, rx, isExact);
|
2008-01-01 22:05:05 +01:00
|
|
|
break;
|
|
|
|
case diStartRow:
|
2008-07-09 15:36:12 +02:00
|
|
|
isExact = FALSE;
|
2008-01-01 22:05:05 +01:00
|
|
|
p = ME_FindItemFwd(p, diRun);
|
|
|
|
if (is_eol) *is_eol = 1;
|
|
|
|
rx = 0; /* FIXME not sure */
|
2008-09-10 20:08:46 +02:00
|
|
|
return ME_ReturnFoundPos(editor, p, result, rx, isExact);
|
2008-08-07 18:31:41 +02:00
|
|
|
case diCell:
|
2008-01-01 22:05:05 +01:00
|
|
|
case diParagraph:
|
|
|
|
case diTextEnd:
|
2008-07-09 15:36:12 +02:00
|
|
|
isExact = FALSE;
|
2008-01-01 22:05:05 +01:00
|
|
|
rx = 0; /* FIXME not sure */
|
|
|
|
p = last;
|
2008-09-10 20:08:46 +02:00
|
|
|
return ME_ReturnFoundPos(editor, p, result, rx, isExact);
|
2008-01-01 22:05:05 +01:00
|
|
|
default: assert(0);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-01-01 22:05:05 +01:00
|
|
|
last = p;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
result->pRun = ME_FindItemBack(p, diRun);
|
|
|
|
result->nOffset = 0;
|
|
|
|
assert(result->pRun->member.run.nFlags & MERF_ENDPARA);
|
2008-07-09 15:36:12 +02:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2005-07-26 12:33:00 +02:00
|
|
|
|
2008-07-09 15:36:12 +02:00
|
|
|
/* Returns the character offset closest to the pixel position
|
|
|
|
*
|
|
|
|
* x & y are pixel positions in client coordinates.
|
|
|
|
*
|
|
|
|
* isExact will be set to TRUE if the run is directly under the pixel
|
|
|
|
* position, FALSE if it not, unless isExact is set to NULL.
|
|
|
|
*/
|
|
|
|
int ME_CharFromPos(ME_TextEditor *editor, int x, int y, BOOL *isExact)
|
2005-07-26 12:33:00 +02:00
|
|
|
{
|
|
|
|
ME_Cursor cursor;
|
|
|
|
RECT rc;
|
2008-07-09 15:36:12 +02:00
|
|
|
BOOL bResult;
|
2005-07-26 12:33:00 +02:00
|
|
|
|
|
|
|
GetClientRect(editor->hWnd, &rc);
|
2008-07-09 15:36:12 +02:00
|
|
|
if (x < 0 || y < 0 || x >= rc.right || y >= rc.bottom) {
|
|
|
|
if (isExact) *isExact = FALSE;
|
2005-07-26 12:33:00 +02:00
|
|
|
return -1;
|
2008-07-09 15:36:12 +02:00
|
|
|
}
|
2006-06-18 22:21:23 +02:00
|
|
|
y += ME_GetYScrollPos(editor);
|
2008-07-09 15:36:12 +02:00
|
|
|
bResult = ME_FindPixelPos(editor, x, y, &cursor, NULL);
|
|
|
|
if (isExact) *isExact = bResult;
|
2005-07-26 12:33:00 +02:00
|
|
|
return (ME_GetParagraph(cursor.pRun)->member.para.nCharOfs
|
|
|
|
+ cursor.pRun->member.run.nCharOfs + cursor.nOffset);
|
|
|
|
}
|
|
|
|
|
2008-07-09 15:36:12 +02:00
|
|
|
|
|
|
|
|
2008-07-07 17:03:53 +02:00
|
|
|
/* Extends the selection with a word, line, or paragraph selection type.
|
|
|
|
*
|
|
|
|
* The selection is anchored by editor->pCursors[2-3] such that the text
|
|
|
|
* between the anchors will remain selected, and one end will be extended.
|
|
|
|
*
|
|
|
|
* editor->pCursors[0] should have the position to extend the selection to
|
|
|
|
* before this function is called.
|
|
|
|
*
|
|
|
|
* Nothing will be done if editor->nSelectionType equals stPosition.
|
|
|
|
*/
|
|
|
|
static void ME_ExtendAnchorSelection(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
ME_Cursor tmp_cursor;
|
|
|
|
int curOfs, anchorStartOfs, anchorEndOfs;
|
2008-07-07 17:04:02 +02:00
|
|
|
if (editor->nSelectionType == stPosition || editor->nSelectionType == stDocument)
|
2008-07-07 17:03:53 +02:00
|
|
|
return;
|
|
|
|
curOfs = ME_GetCursorOfs(editor, 0);
|
2008-08-05 18:10:43 +02:00
|
|
|
anchorStartOfs = ME_GetCursorOfs(editor, 3);
|
|
|
|
anchorEndOfs = ME_GetCursorOfs(editor, 2);
|
2008-07-07 17:03:53 +02:00
|
|
|
|
|
|
|
tmp_cursor = editor->pCursors[0];
|
|
|
|
editor->pCursors[0] = editor->pCursors[2];
|
|
|
|
editor->pCursors[1] = editor->pCursors[3];
|
|
|
|
if (curOfs < anchorStartOfs)
|
|
|
|
{
|
|
|
|
/* Extend the left side of selection */
|
2008-08-05 18:10:43 +02:00
|
|
|
editor->pCursors[1] = tmp_cursor;
|
2008-07-07 17:03:53 +02:00
|
|
|
if (editor->nSelectionType == stWord)
|
2008-08-05 18:10:43 +02:00
|
|
|
ME_MoveCursorWords(editor, &editor->pCursors[1], -1);
|
2008-07-07 17:03:53 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pItem;
|
2008-07-07 17:03:59 +02:00
|
|
|
ME_DIType searchType = ((editor->nSelectionType == stLine) ?
|
|
|
|
diStartRowOrParagraph:diParagraph);
|
2008-08-05 18:10:43 +02:00
|
|
|
pItem = ME_FindItemBack(editor->pCursors[1].pRun, searchType);
|
|
|
|
editor->pCursors[1].pRun = ME_FindItemFwd(pItem, diRun);
|
|
|
|
editor->pCursors[1].nOffset = 0;
|
2008-07-07 17:03:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (curOfs >= anchorEndOfs)
|
|
|
|
{
|
|
|
|
/* Extend the right side of selection */
|
2008-08-05 18:10:43 +02:00
|
|
|
editor->pCursors[0] = tmp_cursor;
|
2008-07-07 17:03:53 +02:00
|
|
|
if (editor->nSelectionType == stWord)
|
2008-08-05 18:10:43 +02:00
|
|
|
ME_MoveCursorWords(editor, &editor->pCursors[0], +1);
|
2008-07-07 17:03:53 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pItem;
|
2008-07-07 17:03:59 +02:00
|
|
|
ME_DIType searchType = ((editor->nSelectionType == stLine) ?
|
|
|
|
diStartRowOrParagraphOrEnd:diParagraphOrEnd);
|
2008-08-05 18:10:43 +02:00
|
|
|
pItem = ME_FindItemFwd(editor->pCursors[0].pRun, searchType);
|
2008-07-07 17:03:53 +02:00
|
|
|
if (pItem->type == diTextEnd)
|
2008-08-05 18:10:43 +02:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemBack(pItem, diRun);
|
2008-07-07 17:03:53 +02:00
|
|
|
else
|
2008-08-05 18:10:43 +02:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(pItem, diRun);
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
2008-07-07 17:03:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-07-26 12:33:00 +02:00
|
|
|
|
2008-07-05 10:23:53 +02:00
|
|
|
void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_Cursor tmp_cursor;
|
|
|
|
int is_selection = 0;
|
2008-07-07 17:03:59 +02:00
|
|
|
BOOL is_shift;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
editor->nUDArrowX = -1;
|
|
|
|
|
2005-03-21 11:27:24 +01:00
|
|
|
y += ME_GetYScrollPos(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
tmp_cursor = editor->pCursors[0];
|
|
|
|
is_selection = ME_IsSelection(editor);
|
2008-07-07 17:03:59 +02:00
|
|
|
is_shift = GetKeyState(VK_SHIFT) < 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2008-07-07 17:03:53 +02:00
|
|
|
ME_FindPixelPos(editor, x, y, &editor->pCursors[0], &editor->bCaretAtEnd);
|
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
if (x >= editor->rcFormat.left || is_shift)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-07-07 17:03:53 +02:00
|
|
|
if (clickNum > 1)
|
|
|
|
{
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
2008-07-07 17:04:02 +02:00
|
|
|
if (is_shift) {
|
2008-12-18 07:56:49 +01:00
|
|
|
if (x >= editor->rcFormat.left)
|
2008-07-07 17:04:02 +02:00
|
|
|
ME_SelectByType(editor, stWord);
|
|
|
|
else
|
|
|
|
ME_SelectByType(editor, stParagraph);
|
|
|
|
} else if (clickNum % 2 == 0) {
|
2008-07-07 17:03:59 +02:00
|
|
|
ME_SelectByType(editor, stWord);
|
2008-07-07 17:04:02 +02:00
|
|
|
} else {
|
2008-07-07 17:03:59 +02:00
|
|
|
ME_SelectByType(editor, stParagraph);
|
2008-07-07 17:04:02 +02:00
|
|
|
}
|
2008-07-07 17:03:53 +02:00
|
|
|
}
|
2008-07-07 17:03:59 +02:00
|
|
|
else if (!is_shift)
|
2007-12-14 21:29:37 +01:00
|
|
|
{
|
2008-07-07 17:03:53 +02:00
|
|
|
editor->nSelectionType = stPosition;
|
2007-12-14 21:29:37 +01:00
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
}
|
2008-07-07 17:03:53 +02:00
|
|
|
else if (!is_selection)
|
|
|
|
{
|
|
|
|
editor->nSelectionType = stPosition;
|
2007-12-14 21:29:37 +01:00
|
|
|
editor->pCursors[1] = tmp_cursor;
|
2008-07-07 17:03:53 +02:00
|
|
|
}
|
|
|
|
else if (editor->nSelectionType != stPosition)
|
|
|
|
{
|
|
|
|
ME_ExtendAnchorSelection(editor);
|
2007-12-14 21:29:37 +01:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-07 17:03:59 +02:00
|
|
|
if (clickNum < 2) {
|
|
|
|
ME_SelectByType(editor, stLine);
|
2008-07-07 17:04:02 +02:00
|
|
|
} else if (clickNum % 2 == 0 || is_shift) {
|
2008-07-07 17:03:59 +02:00
|
|
|
ME_SelectByType(editor, stParagraph);
|
2008-07-07 17:04:02 +02:00
|
|
|
} else {
|
|
|
|
ME_SelectByType(editor, stDocument);
|
2008-07-07 17:03:59 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-07-05 10:23:53 +02:00
|
|
|
ME_InvalidateSelection(editor);
|
|
|
|
HideCaret(editor->hWnd);
|
2008-07-07 17:04:06 +02:00
|
|
|
ME_ShowCaret(editor);
|
2008-07-05 10:23:53 +02:00
|
|
|
ME_ClearTempStyle(editor);
|
|
|
|
ME_SendSelChange(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_MouseMove(ME_TextEditor *editor, int x, int y)
|
|
|
|
{
|
|
|
|
ME_Cursor tmp_cursor;
|
|
|
|
|
2008-07-07 17:04:02 +02:00
|
|
|
if (editor->nSelectionType == stDocument)
|
|
|
|
return;
|
2005-03-21 11:27:24 +01:00
|
|
|
y += ME_GetYScrollPos(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
tmp_cursor = editor->pCursors[0];
|
2006-07-07 00:29:03 +02:00
|
|
|
/* FIXME: do something with the return value of ME_FindPixelPos */
|
2008-07-07 17:03:53 +02:00
|
|
|
ME_FindPixelPos(editor, x, y, &tmp_cursor, &editor->bCaretAtEnd);
|
2007-12-14 21:29:37 +01:00
|
|
|
|
2006-01-26 13:27:28 +01:00
|
|
|
ME_InvalidateSelection(editor);
|
2008-07-07 17:03:53 +02:00
|
|
|
editor->pCursors[0] = tmp_cursor;
|
|
|
|
ME_ExtendAnchorSelection(editor);
|
|
|
|
|
|
|
|
if (editor->nSelectionType != stPosition &&
|
|
|
|
memcmp(&editor->pCursors[1], &editor->pCursors[3], sizeof(ME_Cursor)))
|
2007-12-14 21:29:37 +01:00
|
|
|
{
|
2008-07-07 17:03:53 +02:00
|
|
|
/* The scroll the cursor towards the other end, since it was the one
|
2008-12-15 10:31:43 +01:00
|
|
|
* extended by ME_ExtendAnchorSelection */
|
|
|
|
ME_EnsureVisible(editor, editor->pCursors[1].pRun);
|
2008-07-07 17:03:53 +02:00
|
|
|
} else {
|
2008-12-15 10:31:43 +01:00
|
|
|
ME_EnsureVisible(editor, editor->pCursors[0].pRun);
|
2007-12-14 21:29:37 +01:00
|
|
|
}
|
|
|
|
|
2006-01-31 12:58:59 +01:00
|
|
|
ME_InvalidateSelection(editor);
|
2008-07-07 17:04:06 +02:00
|
|
|
HideCaret(editor->hWnd);
|
|
|
|
ME_ShowCaret(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SendSelChange(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ME_DisplayItem *ME_FindRunInRow(ME_TextEditor *editor, ME_DisplayItem *pRow,
|
|
|
|
int x, int *pOffset, int *pbCaretAtEnd)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pNext, *pLastRun;
|
|
|
|
pNext = ME_FindItemFwd(pRow, diRunOrStartRow);
|
|
|
|
assert(pNext->type == diRun);
|
|
|
|
pLastRun = pNext;
|
2008-06-25 17:32:52 +02:00
|
|
|
if (pbCaretAtEnd) *pbCaretAtEnd = FALSE;
|
|
|
|
if (pOffset) *pOffset = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
do {
|
|
|
|
int run_x = pNext->member.run.pt.x;
|
|
|
|
int width = pNext->member.run.nWidth;
|
|
|
|
if (x < run_x)
|
|
|
|
{
|
|
|
|
return pNext;
|
|
|
|
}
|
|
|
|
if (x >= run_x && x < run_x+width)
|
|
|
|
{
|
|
|
|
int ch = ME_CharFromPointCursor(editor, x-run_x, &pNext->member.run);
|
|
|
|
ME_String *s = pNext->member.run.strText;
|
|
|
|
if (ch < s->nLen) {
|
|
|
|
if (pOffset)
|
|
|
|
*pOffset = ch;
|
|
|
|
return pNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pLastRun = pNext;
|
|
|
|
pNext = ME_FindItemFwd(pNext, diRunOrStartRow);
|
|
|
|
} while(pNext && pNext->type == diRun);
|
|
|
|
|
|
|
|
if ((pLastRun->member.run.nFlags & MERF_ENDPARA) == 0)
|
|
|
|
{
|
|
|
|
pNext = ME_FindItemFwd(pNext, diRun);
|
2008-06-25 17:32:52 +02:00
|
|
|
if (pbCaretAtEnd) *pbCaretAtEnd = TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
return pNext;
|
|
|
|
} else {
|
|
|
|
return pLastRun;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ME_GetXForArrow(ME_TextEditor *editor, ME_Cursor *pCursor)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pRun = pCursor->pRun;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
if (editor->nUDArrowX != -1)
|
|
|
|
x = editor->nUDArrowX;
|
|
|
|
else {
|
|
|
|
if (editor->bCaretAtEnd)
|
|
|
|
{
|
|
|
|
pRun = ME_FindItemBack(pRun, diRun);
|
|
|
|
assert(pRun);
|
|
|
|
x = pRun->member.run.pt.x + pRun->member.run.nWidth;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x = pRun->member.run.pt.x;
|
|
|
|
x += ME_PointFromChar(editor, &pRun->member.run, pCursor->nOffset);
|
|
|
|
}
|
|
|
|
editor->nUDArrowX = x;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pRun = pCursor->pRun;
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_DisplayItem *pItem, *pOldPara, *pNewPara;
|
2005-03-05 12:19:14 +01:00
|
|
|
int x = ME_GetXForArrow(editor, pCursor);
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (editor->bCaretAtEnd && !pCursor->nOffset)
|
|
|
|
pRun = ME_FindItemBack(pRun, diRun);
|
2006-01-10 20:23:41 +01:00
|
|
|
if (!pRun)
|
2005-03-05 12:19:14 +01:00
|
|
|
return;
|
2008-08-07 18:31:41 +02:00
|
|
|
pOldPara = ME_GetParagraph(pRun);
|
2006-01-10 20:23:41 +01:00
|
|
|
if (nRelOfs == -1)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-01-10 20:23:41 +01:00
|
|
|
/* start of this row */
|
|
|
|
pItem = ME_FindItemBack(pRun, diStartRow);
|
|
|
|
assert(pItem);
|
|
|
|
/* start of the previous row */
|
|
|
|
pItem = ME_FindItemBack(pItem, diStartRow);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!pItem)
|
|
|
|
return; /* row not found - ignore */
|
|
|
|
pNewPara = ME_GetParagraph(pItem);
|
|
|
|
if (pOldPara->member.para.nFlags & MEPF_ROWEND ||
|
|
|
|
(pOldPara->member.para.pCell &&
|
|
|
|
pOldPara->member.para.pCell != pNewPara->member.para.pCell))
|
|
|
|
{
|
|
|
|
/* Brought out of a cell */
|
|
|
|
pNewPara = ME_GetTableRowStart(pOldPara)->member.para.prev_para;
|
|
|
|
if (pNewPara->type == diTextStart)
|
|
|
|
return; /* At the top, so don't go anywhere. */
|
|
|
|
pItem = ME_FindItemFwd(pNewPara, diStartRow);
|
|
|
|
}
|
|
|
|
if (pNewPara->member.para.nFlags & MEPF_ROWEND)
|
|
|
|
{
|
|
|
|
/* Brought into a table row */
|
|
|
|
ME_Cell *cell = &ME_FindItemBack(pNewPara, diCell)->member.cell;
|
|
|
|
while (x < cell->pt.x && cell->prev_cell)
|
|
|
|
cell = &cell->prev_cell->member.cell;
|
|
|
|
if (cell->next_cell) /* else - we are still at the end of the row */
|
|
|
|
pItem = ME_FindItemBack(cell->next_cell, diStartRow);
|
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* start of the next row */
|
|
|
|
pItem = ME_FindItemFwd(pRun, diStartRow);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!pItem)
|
|
|
|
return; /* row not found - ignore */
|
2006-01-10 20:23:41 +01:00
|
|
|
/* FIXME If diParagraph is before diStartRow, wrap the next paragraph?
|
|
|
|
*/
|
2008-08-07 18:31:41 +02:00
|
|
|
pNewPara = ME_GetParagraph(pItem);
|
|
|
|
if (pOldPara->member.para.nFlags & MEPF_ROWSTART ||
|
|
|
|
(pOldPara->member.para.pCell &&
|
|
|
|
pOldPara->member.para.pCell != pNewPara->member.para.pCell))
|
|
|
|
{
|
|
|
|
/* Brought out of a cell */
|
|
|
|
pNewPara = ME_GetTableRowEnd(pOldPara)->member.para.next_para;
|
|
|
|
if (pNewPara->type == diTextEnd)
|
|
|
|
return; /* At the bottom, so don't go anywhere. */
|
|
|
|
pItem = ME_FindItemFwd(pNewPara, diStartRow);
|
|
|
|
}
|
|
|
|
if (pNewPara->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
{
|
|
|
|
/* Brought into a table row */
|
|
|
|
ME_DisplayItem *cell = ME_FindItemFwd(pNewPara, diCell);
|
|
|
|
while (cell->member.cell.next_cell &&
|
|
|
|
x >= cell->member.cell.next_cell->member.cell.pt.x)
|
|
|
|
cell = cell->member.cell.next_cell;
|
|
|
|
pItem = ME_FindItemFwd(cell, diStartRow);
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
if (!pItem)
|
|
|
|
{
|
2006-01-10 20:23:41 +01:00
|
|
|
/* row not found - ignore */
|
2005-03-05 12:19:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
pCursor->pRun = ME_FindRunInRow(editor, pItem, x, &pCursor->nOffset, &editor->bCaretAtEnd);
|
|
|
|
assert(pCursor->pRun);
|
|
|
|
assert(pCursor->pRun->type == diRun);
|
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2005-07-01 17:40:24 +02:00
|
|
|
static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor)
|
2005-03-21 11:27:24 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pRun = pCursor->pRun;
|
|
|
|
ME_DisplayItem *pLast, *p;
|
|
|
|
int x, y, ys, yd, yp, yprev;
|
|
|
|
ME_Cursor tmp_curs = *pCursor;
|
|
|
|
|
|
|
|
x = ME_GetXForArrow(editor, pCursor);
|
|
|
|
if (!pCursor->nOffset && editor->bCaretAtEnd)
|
|
|
|
pRun = ME_FindItemBack(pRun, diRun);
|
|
|
|
|
|
|
|
p = ME_FindItemBack(pRun, diStartRowOrParagraph);
|
|
|
|
assert(p->type == diStartRow);
|
2008-08-07 18:31:41 +02:00
|
|
|
yp = ME_FindItemBack(p, diParagraph)->member.para.pt.y;
|
|
|
|
yprev = ys = y = yp + p->member.row.pt.y;
|
2005-03-21 11:27:24 +01:00
|
|
|
yd = y - editor->sizeWindow.cy;
|
|
|
|
pLast = p;
|
|
|
|
|
|
|
|
do {
|
|
|
|
p = ME_FindItemBack(p, diStartRowOrParagraph);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
if (p->type == diParagraph) { /* crossing paragraphs */
|
|
|
|
if (p->member.para.prev_para == NULL)
|
|
|
|
break;
|
2008-08-07 18:31:41 +02:00
|
|
|
yp = p->member.para.prev_para->member.para.pt.y;
|
2005-03-21 11:27:24 +01:00
|
|
|
continue;
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
y = yp + p->member.row.pt.y;
|
2005-03-21 11:27:24 +01:00
|
|
|
if (y < yd)
|
|
|
|
break;
|
|
|
|
pLast = p;
|
|
|
|
yprev = y;
|
|
|
|
} while(1);
|
|
|
|
|
|
|
|
pCursor->pRun = ME_FindRunInRow(editor, pLast, x, &pCursor->nOffset, &editor->bCaretAtEnd);
|
|
|
|
ME_UpdateSelection(editor, &tmp_curs);
|
|
|
|
if (yprev < editor->sizeWindow.cy)
|
|
|
|
{
|
|
|
|
ME_EnsureVisible(editor, ME_FindItemFwd(editor->pBuffer->pFirst, diRun));
|
|
|
|
ME_Repaint(editor);
|
|
|
|
}
|
2006-09-08 23:37:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_ScrollUp(editor, ys-yprev);
|
2005-03-21 11:27:24 +01:00
|
|
|
}
|
|
|
|
assert(pCursor->pRun);
|
|
|
|
assert(pCursor->pRun->type == diRun);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: in the original RICHEDIT, PageDown always scrolls by the same amount
|
|
|
|
of pixels, even if it makes the scroll bar position exceed its normal maximum.
|
|
|
|
In such a situation, clicking the scrollbar restores its position back to the
|
|
|
|
normal range (ie. sets it to (doclength-screenheight)). */
|
|
|
|
|
2005-07-01 17:40:24 +02:00
|
|
|
static void ME_ArrowPageDown(ME_TextEditor *editor, ME_Cursor *pCursor)
|
2005-03-19 18:06:17 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pRun = pCursor->pRun;
|
|
|
|
ME_DisplayItem *pLast, *p;
|
|
|
|
int x, y, ys, yd, yp, yprev;
|
|
|
|
ME_Cursor tmp_curs = *pCursor;
|
|
|
|
|
|
|
|
x = ME_GetXForArrow(editor, pCursor);
|
|
|
|
if (!pCursor->nOffset && editor->bCaretAtEnd)
|
|
|
|
pRun = ME_FindItemBack(pRun, diRun);
|
|
|
|
|
|
|
|
p = ME_FindItemBack(pRun, diStartRowOrParagraph);
|
|
|
|
assert(p->type == diStartRow);
|
2008-08-07 18:31:41 +02:00
|
|
|
yp = ME_FindItemBack(p, diParagraph)->member.para.pt.y;
|
|
|
|
yprev = ys = y = yp + p->member.row.pt.y;
|
2005-03-19 18:06:17 +01:00
|
|
|
yd = y + editor->sizeWindow.cy;
|
|
|
|
pLast = p;
|
|
|
|
|
|
|
|
do {
|
|
|
|
p = ME_FindItemFwd(p, diStartRowOrParagraph);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
if (p->type == diParagraph) {
|
2008-08-07 18:31:41 +02:00
|
|
|
yp = p->member.para.pt.y;
|
2005-03-19 18:06:17 +01:00
|
|
|
continue;
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
y = yp + p->member.row.pt.y;
|
2005-03-19 18:06:17 +01:00
|
|
|
if (y >= yd)
|
|
|
|
break;
|
|
|
|
pLast = p;
|
|
|
|
yprev = y;
|
|
|
|
} while(1);
|
|
|
|
|
|
|
|
pCursor->pRun = ME_FindRunInRow(editor, pLast, x, &pCursor->nOffset, &editor->bCaretAtEnd);
|
|
|
|
ME_UpdateSelection(editor, &tmp_curs);
|
|
|
|
if (yprev >= editor->nTotalLength-editor->sizeWindow.cy)
|
|
|
|
{
|
|
|
|
ME_EnsureVisible(editor, ME_FindItemBack(editor->pBuffer->pLast, diRun));
|
|
|
|
ME_Repaint(editor);
|
|
|
|
}
|
2006-09-08 23:37:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_ScrollUp(editor,ys-yprev);
|
2005-03-19 18:06:17 +01:00
|
|
|
}
|
|
|
|
assert(pCursor->pRun);
|
|
|
|
assert(pCursor->pRun->type == diRun);
|
|
|
|
}
|
|
|
|
|
2005-07-01 17:40:24 +02:00
|
|
|
static void ME_ArrowHome(ME_TextEditor *editor, ME_Cursor *pCursor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow);
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_WrapMarkedParagraphs(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (pRow) {
|
|
|
|
ME_DisplayItem *pRun;
|
|
|
|
if (editor->bCaretAtEnd && !pCursor->nOffset) {
|
|
|
|
pRow = ME_FindItemBack(pRow, diStartRow);
|
|
|
|
if (!pRow)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pRun = ME_FindItemFwd(pRow, diRun);
|
|
|
|
if (pRun) {
|
|
|
|
pCursor->pRun = pRun;
|
|
|
|
pCursor->nOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor->bCaretAtEnd = FALSE;
|
|
|
|
}
|
|
|
|
|
2005-07-01 17:40:24 +02:00
|
|
|
static void ME_ArrowCtrlHome(ME_TextEditor *editor, ME_Cursor *pCursor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diTextStart);
|
|
|
|
if (pRow) {
|
|
|
|
ME_DisplayItem *pRun = ME_FindItemFwd(pRow, diRun);
|
|
|
|
if (pRun) {
|
|
|
|
pCursor->pRun = pRun;
|
|
|
|
pCursor->nOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-01 17:40:24 +02:00
|
|
|
static void ME_ArrowEnd(ME_TextEditor *editor, ME_Cursor *pCursor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pRow;
|
|
|
|
|
|
|
|
if (editor->bCaretAtEnd && !pCursor->nOffset)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pRow = ME_FindItemFwd(pCursor->pRun, diStartRowOrParagraphOrEnd);
|
|
|
|
assert(pRow);
|
|
|
|
if (pRow->type == diStartRow) {
|
|
|
|
/* FIXME WTF was I thinking about here ? */
|
|
|
|
ME_DisplayItem *pRun = ME_FindItemFwd(pRow, diRun);
|
|
|
|
assert(pRun);
|
|
|
|
pCursor->pRun = pRun;
|
|
|
|
pCursor->nOffset = 0;
|
|
|
|
editor->bCaretAtEnd = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pCursor->pRun = ME_FindItemBack(pRow, diRun);
|
|
|
|
assert(pCursor->pRun && pCursor->pRun->member.run.nFlags & MERF_ENDPARA);
|
|
|
|
pCursor->nOffset = 0;
|
|
|
|
editor->bCaretAtEnd = FALSE;
|
|
|
|
}
|
|
|
|
|
2005-07-01 17:40:24 +02:00
|
|
|
static void ME_ArrowCtrlEnd(ME_TextEditor *editor, ME_Cursor *pCursor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *p = ME_FindItemFwd(pCursor->pRun, diTextEnd);
|
|
|
|
assert(p);
|
|
|
|
p = ME_FindItemBack(p, diRun);
|
|
|
|
assert(p);
|
|
|
|
assert(p->member.run.nFlags & MERF_ENDPARA);
|
|
|
|
pCursor->pRun = p;
|
|
|
|
pCursor->nOffset = 0;
|
|
|
|
editor->bCaretAtEnd = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ME_IsSelection(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
return memcmp(&editor->pCursors[0], &editor->pCursors[1], sizeof(ME_Cursor))!=0;
|
|
|
|
}
|
|
|
|
|
2005-07-01 17:40:24 +02:00
|
|
|
static int ME_GetSelCursor(ME_TextEditor *editor, int dir)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
int cdir = ME_GetCursorOfs(editor, 0) - ME_GetCursorOfs(editor, 1);
|
|
|
|
|
|
|
|
if (cdir*dir>0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
2007-08-11 17:07:50 +02:00
|
|
|
|
|
|
|
BOOL ME_UpdateSelection(ME_TextEditor *editor, const ME_Cursor *pTempCursor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_Cursor old_anchor = editor->pCursors[1];
|
|
|
|
|
|
|
|
if (GetKeyState(VK_SHIFT)>=0) /* cancelling selection */
|
|
|
|
{
|
|
|
|
/* any selection was present ? if so, it's no more, repaint ! */
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
if (memcmp(pTempCursor, &old_anchor, sizeof(ME_Cursor))) {
|
2005-03-19 18:06:17 +01:00
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2005-03-19 18:06:17 +01:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!memcmp(pTempCursor, &editor->pCursors[1], sizeof(ME_Cursor))) /* starting selection */
|
|
|
|
{
|
|
|
|
editor->pCursors[1] = *pTempCursor;
|
2005-03-19 18:06:17 +01:00
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_Repaint(editor);
|
2005-03-19 18:06:17 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_DeleteSelection(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
int from, to;
|
|
|
|
ME_GetSelection(editor, &from, &to);
|
|
|
|
ME_DeleteTextAtCursor(editor, ME_GetSelCursor(editor,-1), to-from);
|
|
|
|
}
|
|
|
|
|
2005-03-08 20:03:01 +01:00
|
|
|
ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor)
|
|
|
|
{
|
2008-06-26 22:17:17 +02:00
|
|
|
return ME_GetInsertStyle(editor, 0);
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_SendSelChange(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
SELCHANGE sc;
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (!(editor->nEventMask & ENM_SELCHANGE))
|
|
|
|
return;
|
2008-12-16 09:43:43 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
sc.nmhdr.code = EN_SELCHANGE;
|
2008-12-16 09:43:43 +01:00
|
|
|
ME_GetSelection(editor, &sc.chrg.cpMin, &sc.chrg.cpMax);
|
2005-03-05 12:19:14 +01:00
|
|
|
sc.seltyp = SEL_EMPTY;
|
|
|
|
if (sc.chrg.cpMin != sc.chrg.cpMax)
|
|
|
|
sc.seltyp |= SEL_TEXT;
|
|
|
|
if (sc.chrg.cpMin < sc.chrg.cpMax+1) /* wth were RICHEDIT authors thinking ? */
|
|
|
|
sc.seltyp |= SEL_MULTICHAR;
|
2008-04-27 20:08:55 +02:00
|
|
|
TRACE("cpMin=%d cpMax=%d seltyp=%d (%s %s)\n",
|
|
|
|
sc.chrg.cpMin, sc.chrg.cpMax, sc.seltyp,
|
|
|
|
(sc.seltyp & SEL_TEXT) ? "SEL_TEXT" : "",
|
|
|
|
(sc.seltyp & SEL_MULTICHAR) ? "SEL_MULTICHAR" : "");
|
|
|
|
if (sc.chrg.cpMin != editor->notified_cr.cpMin || sc.chrg.cpMax != editor->notified_cr.cpMax)
|
|
|
|
{
|
2008-05-05 05:51:52 +02:00
|
|
|
ME_ClearTempStyle(editor);
|
|
|
|
|
2008-04-27 20:08:55 +02:00
|
|
|
editor->notified_cr = sc.chrg;
|
|
|
|
SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, sc.nmhdr.idFrom, (LPARAM)&sc);
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
BOOL
|
2006-01-12 11:54:57 +01:00
|
|
|
ME_ArrowKey(ME_TextEditor *editor, int nVKey, BOOL extend, BOOL ctrl)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
int nCursor = 0;
|
|
|
|
ME_Cursor *p = &editor->pCursors[nCursor];
|
|
|
|
ME_Cursor tmp_curs = *p;
|
2006-01-10 20:23:41 +01:00
|
|
|
BOOL success = FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_CheckCharOffsets(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
switch(nVKey) {
|
2006-01-10 20:23:41 +01:00
|
|
|
case VK_LEFT:
|
|
|
|
editor->bCaretAtEnd = 0;
|
2006-01-12 11:54:57 +01:00
|
|
|
if (ctrl)
|
|
|
|
success = ME_MoveCursorWords(editor, &tmp_curs, -1);
|
|
|
|
else
|
|
|
|
success = ME_MoveCursorChars(editor, &tmp_curs, -1);
|
2006-01-10 20:23:41 +01:00
|
|
|
break;
|
|
|
|
case VK_RIGHT:
|
|
|
|
editor->bCaretAtEnd = 0;
|
2006-01-12 11:54:57 +01:00
|
|
|
if (ctrl)
|
|
|
|
success = ME_MoveCursorWords(editor, &tmp_curs, +1);
|
|
|
|
else
|
|
|
|
success = ME_MoveCursorChars(editor, &tmp_curs, +1);
|
2006-01-10 20:23:41 +01:00
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case VK_UP:
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_MoveCursorLines(editor, &tmp_curs, -1);
|
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case VK_DOWN:
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_MoveCursorLines(editor, &tmp_curs, +1);
|
|
|
|
break;
|
2005-03-21 11:27:24 +01:00
|
|
|
case VK_PRIOR:
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_ArrowPageUp(editor, &tmp_curs);
|
|
|
|
break;
|
2005-03-19 18:06:17 +01:00
|
|
|
case VK_NEXT:
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_ArrowPageDown(editor, &tmp_curs);
|
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case VK_HOME: {
|
2006-01-12 11:54:57 +01:00
|
|
|
if (ctrl)
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_ArrowCtrlHome(editor, &tmp_curs);
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_ArrowHome(editor, &tmp_curs);
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->bCaretAtEnd = 0;
|
2006-01-10 20:23:41 +01:00
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
case VK_END:
|
2006-01-12 11:54:57 +01:00
|
|
|
if (ctrl)
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_ArrowCtrlEnd(editor, &tmp_curs);
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_ArrowEnd(editor, &tmp_curs);
|
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
if (!extend)
|
|
|
|
editor->pCursors[1] = tmp_curs;
|
|
|
|
*p = tmp_curs;
|
|
|
|
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_InvalidateSelection(editor);
|
|
|
|
ME_Repaint(editor);
|
2006-01-10 20:23:41 +01:00
|
|
|
HideCaret(editor->hWnd);
|
|
|
|
ME_EnsureVisible(editor, tmp_curs.pRun);
|
|
|
|
ME_ShowCaret(editor);
|
|
|
|
ME_SendSelChange(editor);
|
|
|
|
return success;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|