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);
|
|
|
|
|
2009-08-12 15:06:05 +02:00
|
|
|
void ME_SetCursorToStart(ME_TextEditor *editor, ME_Cursor *cursor)
|
|
|
|
{
|
2020-10-19 13:21:19 +02:00
|
|
|
cursor->pPara = para_get_di( editor_first_para( editor ) );
|
|
|
|
cursor->pRun = run_get_di( para_first_run( &cursor->pPara->member.para ) );
|
2009-08-12 15:06:05 +02:00
|
|
|
cursor->nOffset = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-04 14:07:32 +02:00
|
|
|
static void ME_SetCursorToEnd(ME_TextEditor *editor, ME_Cursor *cursor, BOOL final_eop)
|
2009-08-12 15:06:05 +02:00
|
|
|
{
|
2020-10-19 13:21:19 +02:00
|
|
|
cursor->pPara = para_get_di( para_prev( editor_end_para( editor ) ) );
|
|
|
|
cursor->pRun = run_get_di( para_end_run( &cursor->pPara->member.para ) );
|
2016-10-04 14:07:32 +02:00
|
|
|
cursor->nOffset = final_eop ? cursor->pRun->member.run.len : 0;
|
2009-08-12 15:06:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-12 15:05:46 +02:00
|
|
|
int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2009-08-12 15:05:42 +02:00
|
|
|
*from = ME_GetCursorOfs(&editor->pCursors[0]);
|
|
|
|
*to = ME_GetCursorOfs(&editor->pCursors[1]);
|
2009-08-12 15:05:46 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (*from > *to)
|
|
|
|
{
|
|
|
|
int tmp = *from;
|
|
|
|
*from = *to;
|
2009-08-12 15:05:46 +02:00
|
|
|
*to = tmp;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ME_GetSelection(ME_TextEditor *editor, ME_Cursor **from, ME_Cursor **to)
|
|
|
|
{
|
2013-12-10 12:19:08 +01:00
|
|
|
int from_ofs = ME_GetCursorOfs( &editor->pCursors[0] );
|
|
|
|
int to_ofs = ME_GetCursorOfs( &editor->pCursors[1] );
|
|
|
|
BOOL swap = (from_ofs > to_ofs);
|
|
|
|
|
|
|
|
if (from_ofs == to_ofs)
|
|
|
|
{
|
|
|
|
/* If cursor[0] is at the beginning of a run and cursor[1] at the end
|
|
|
|
of the prev run then we need to swap. */
|
|
|
|
if (editor->pCursors[0].nOffset < editor->pCursors[1].nOffset)
|
|
|
|
swap = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!swap)
|
2009-08-12 15:05:46 +02:00
|
|
|
{
|
|
|
|
*from = &editor->pCursors[0];
|
|
|
|
*to = &editor->pCursors[1];
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
*from = &editor->pCursors[1];
|
|
|
|
*to = &editor->pCursors[0];
|
|
|
|
return 1;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ME_GetTextLength(ME_TextEditor *editor)
|
|
|
|
{
|
2009-08-12 15:06:05 +02:00
|
|
|
ME_Cursor cursor;
|
2016-10-04 14:07:32 +02:00
|
|
|
ME_SetCursorToEnd(editor, &cursor, FALSE);
|
2009-08-12 15:06:05 +02:00
|
|
|
return ME_GetCursorOfs(&cursor);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-01-15 20:46:25 +01:00
|
|
|
if ((editor->styleFlags & ES_MULTILINE)
|
2008-04-27 03:37:50 +02:00
|
|
|
&& (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;
|
2010-02-27 17:58:16 +01:00
|
|
|
|
|
|
|
if (how->flags & GTL_NUMBYTES ||
|
|
|
|
(how->flags & GTL_PRECISE && /* GTL_PRECISE seems to imply GTL_NUMBYTES */
|
|
|
|
!(how->flags & GTL_NUMCHARS))) /* unless GTL_NUMCHARS is given */
|
2005-06-28 15:51:32 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-19 11:55:25 +02:00
|
|
|
/******************************************************************
|
|
|
|
* set_selection_cursors
|
|
|
|
*
|
|
|
|
* Updates the selection cursors.
|
|
|
|
*
|
|
|
|
* Note that this does not invalidate either the old or the new selections.
|
|
|
|
*/
|
|
|
|
int set_selection_cursors(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)
|
|
|
|
{
|
2009-08-12 15:06:05 +02:00
|
|
|
ME_SetCursorToStart(editor, &editor->pCursors[1]);
|
2016-10-04 14:07:32 +02:00
|
|
|
ME_SetCursorToEnd(editor, &editor->pCursors[0], TRUE);
|
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;
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_GetSelectionOfs(editor, &start, &end);
|
2012-05-09 23:53:01 +02:00
|
|
|
if (start != end)
|
|
|
|
{
|
2014-07-21 18:40:48 +02:00
|
|
|
if (end > len)
|
|
|
|
{
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
end --;
|
|
|
|
}
|
2012-05-09 23:53:01 +02:00
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
}
|
2006-12-04 20:54:24 +01:00
|
|
|
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
|
|
|
{
|
2016-10-04 14:07:32 +02:00
|
|
|
ME_SetCursorToEnd(editor, &editor->pCursors[0], FALSE);
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
2006-12-04 20:54:24 +01:00
|
|
|
return len;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-12-04 20:54:24 +01:00
|
|
|
|
2020-10-15 11:39:38 +02:00
|
|
|
cursor_from_char_ofs( editor, from, &editor->pCursors[1] );
|
2009-08-13 14:43:57 +02:00
|
|
|
editor->pCursors[0] = editor->pCursors[1];
|
2016-10-04 14:07:33 +02:00
|
|
|
ME_MoveCursorChars(editor, &editor->pCursors[0], to - from, FALSE);
|
2009-01-27 09:39:23 +01:00
|
|
|
/* Selection is not allowed in the middle of an end paragraph run. */
|
|
|
|
if (editor->pCursors[1].pRun->member.run.nFlags & MERF_ENDPARA)
|
|
|
|
editor->pCursors[1].nOffset = 0;
|
|
|
|
if (editor->pCursors[0].pRun->member.run.nFlags & MERF_ENDPARA)
|
2014-07-21 18:40:48 +02:00
|
|
|
{
|
|
|
|
if (to > len)
|
|
|
|
editor->pCursors[0].nOffset = editor->pCursors[0].pRun->member.run.len;
|
|
|
|
else
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
}
|
2006-12-04 20:54:24 +01:00
|
|
|
return to;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-26 09:46:42 +01:00
|
|
|
void cursor_coords( ME_TextEditor *editor, ME_Cursor *cursor,
|
|
|
|
int *x, int *y, int *height )
|
2006-01-10 20:23:41 +01:00
|
|
|
{
|
2020-10-26 09:46:42 +01:00
|
|
|
ME_Row *row;
|
|
|
|
ME_Run *run = &cursor->pRun->member.run;
|
|
|
|
ME_Paragraph *para = &cursor->pPara->member.para;
|
2020-10-12 14:09:08 +02:00
|
|
|
ME_Run *size_run = run, *prev;
|
2009-02-07 19:21:03 +01:00
|
|
|
ME_Context c;
|
2013-02-15 17:13:41 +01:00
|
|
|
int run_x;
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2020-10-12 14:09:08 +02:00
|
|
|
assert(~para->nFlags & MEPF_REWRAP);
|
2009-02-07 19:21:03 +01:00
|
|
|
|
2020-10-26 09:46:42 +01:00
|
|
|
row = row_from_cursor( cursor );
|
2009-02-07 19:21:03 +01:00
|
|
|
|
|
|
|
ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
|
|
|
|
|
2020-10-26 09:46:42 +01:00
|
|
|
if (!cursor->nOffset && (prev = run_prev( run ))) size_run = prev;
|
2020-10-12 14:09:08 +02:00
|
|
|
|
2020-10-26 09:46:42 +01:00
|
|
|
run_x = ME_PointFromCharContext( &c, run, cursor->nOffset, TRUE );
|
2009-02-07 19:21:03 +01:00
|
|
|
|
2020-10-12 14:09:08 +02:00
|
|
|
*height = size_run->nAscent + size_run->nDescent;
|
|
|
|
*x = c.rcView.left + run->pt.x + run_x - editor->horz_si.nPos;
|
2020-10-26 09:46:42 +01:00
|
|
|
*y = c.rcView.top + para->pt.y + row->nBaseline
|
2020-10-12 14:09:08 +02:00
|
|
|
+ run->pt.y - size_run->nAscent - editor->vert_si.nPos;
|
2009-02-07 19:21:03 +01:00
|
|
|
ME_DestroyContext(&c);
|
|
|
|
return;
|
2006-01-10 20:23:41 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 15:23:04 +02:00
|
|
|
void create_caret(ME_TextEditor *editor)
|
2006-01-10 20:23:41 +01:00
|
|
|
{
|
|
|
|
int x, y, height;
|
|
|
|
|
2020-10-26 09:46:42 +01:00
|
|
|
cursor_coords( editor, &editor->pCursors[0], &x, &y, &height );
|
2019-04-03 15:23:04 +02:00
|
|
|
ITextHost_TxCreateCaret(editor->texthost, NULL, 0, height);
|
|
|
|
editor->caret_height = height;
|
|
|
|
editor->caret_hidden = TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 15:23:04 +02:00
|
|
|
void show_caret(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
ITextHost_TxShowCaret(editor->texthost, TRUE);
|
|
|
|
editor->caret_hidden = FALSE;
|
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2019-04-03 15:23:04 +02:00
|
|
|
void hide_caret(ME_TextEditor *editor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2019-04-03 15:23:04 +02:00
|
|
|
/* calls to HideCaret are cumulative; do so only once */
|
|
|
|
if (!editor->caret_hidden)
|
|
|
|
{
|
|
|
|
ITextHost_TxShowCaret(editor->texthost, FALSE);
|
|
|
|
editor->caret_hidden = TRUE;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 15:23:04 +02:00
|
|
|
void update_caret(ME_TextEditor *editor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2019-04-03 15:23:04 +02:00
|
|
|
int x, y, height;
|
|
|
|
|
|
|
|
if (!editor->bHaveFocus) return;
|
|
|
|
if (!ME_IsSelection(editor))
|
2007-06-05 14:56:55 +02:00
|
|
|
{
|
2020-10-26 09:46:42 +01:00
|
|
|
cursor_coords( editor, &editor->pCursors[0], &x, &y, &height );
|
2019-04-03 15:23:04 +02:00
|
|
|
if (height != editor->caret_height) create_caret(editor);
|
|
|
|
x = min(x, editor->rcFormat.right-1);
|
|
|
|
ITextHost_TxSetCaretPos(editor->texthost, x, y);
|
|
|
|
show_caret(editor);
|
2007-06-05 14:56:55 +02:00
|
|
|
}
|
2019-04-03 15:23:04 +02:00
|
|
|
else
|
|
|
|
hide_caret(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2009-08-13 14:44:18 +02:00
|
|
|
BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
|
|
|
|
int nChars, BOOL bForce)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_Cursor c = *start;
|
2013-11-04 15:23:53 +01:00
|
|
|
int nOfs = ME_GetCursorOfs(start), text_len = ME_GetTextLength( editor );
|
2005-03-05 12:19:14 +01:00
|
|
|
int shift = 0;
|
2008-08-05 01:19:01 +02:00
|
|
|
int totalChars = nChars;
|
2020-10-12 14:09:09 +02:00
|
|
|
ME_Paragraph *start_para;
|
2013-11-04 15:23:53 +01:00
|
|
|
BOOL delete_all = FALSE;
|
2008-08-07 18:31:37 +02:00
|
|
|
|
2009-02-06 07:09:30 +01:00
|
|
|
/* Prevent deletion past last end of paragraph run. */
|
2013-11-04 15:23:53 +01:00
|
|
|
nChars = min(nChars, text_len - nOfs);
|
|
|
|
if (nChars == text_len) delete_all = TRUE;
|
2020-10-12 14:09:09 +02:00
|
|
|
start_para = &c.pPara->member.para;
|
2008-08-05 18:10:51 +02:00
|
|
|
|
|
|
|
if (!bForce)
|
|
|
|
{
|
2020-10-29 11:49:11 +01:00
|
|
|
table_protect_partial_deletion( editor, &c, &nChars );
|
|
|
|
if (nChars == 0) return FALSE;
|
2008-08-05 18:10:51 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 11:49:11 +01:00
|
|
|
while (nChars > 0)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_Run *run;
|
2020-10-15 11:39:38 +02:00
|
|
|
cursor_from_char_ofs( editor, nOfs + nChars, &c );
|
2020-10-21 11:05:53 +02:00
|
|
|
if (!c.nOffset)
|
2008-08-07 18:31:37 +02:00
|
|
|
{
|
|
|
|
/* We aren't deleting anything in this run, so we will go back to the
|
|
|
|
* last run we are deleting text in. */
|
2020-10-21 11:05:52 +02:00
|
|
|
c.pRun = run_get_di( run_prev_all_paras( &c.pRun->member.run ) );
|
|
|
|
c.pPara = para_get_di( c.pRun->member.run.para );
|
2013-01-31 14:48:00 +01:00
|
|
|
c.nOffset = c.pRun->member.run.len;
|
2008-08-07 18:31:37 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
run = &c.pRun->member.run;
|
2020-10-21 11:05:52 +02:00
|
|
|
if (run->nFlags & MERF_ENDPARA)
|
|
|
|
{
|
2013-01-31 14:48:00 +01:00
|
|
|
int eollen = c.pRun->member.run.len;
|
2008-08-05 01:19:01 +02:00
|
|
|
BOOL keepFirstParaFormat;
|
2008-04-26 22:48:24 +02:00
|
|
|
|
2020-10-21 11:05:52 +02:00
|
|
|
if (!para_next( para_next( &c.pPara->member.para ) )) return TRUE;
|
|
|
|
|
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 */
|
|
|
|
{
|
2020-10-12 14:09:09 +02:00
|
|
|
ME_Paragraph *this_para = run->para;
|
|
|
|
ME_Paragraph *next_para = para_next( this_para );
|
2008-08-07 18:31:41 +02:00
|
|
|
|
|
|
|
/* The end of paragraph before a table row is only deleted if there
|
|
|
|
* is nothing else on the line before it. */
|
2020-10-12 14:09:09 +02:00
|
|
|
if (this_para == start_para && next_para->nFlags & MEPF_ROWSTART)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
/* 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. */
|
2020-10-12 14:09:09 +02:00
|
|
|
if (nOfs > this_para->nCharOfs)
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
/* Skip this end of line. */
|
|
|
|
nChars -= (eollen < nChars) ? eollen : nChars;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
keepFirstParaFormat = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2020-10-16 13:08:10 +02:00
|
|
|
para_join( editor, &c.pPara->member.para, 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;
|
|
|
|
|
2020-10-12 14:09:09 +02:00
|
|
|
para_mark_rewrap( editor, c.pRun->member.run.para );
|
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;
|
2016-05-16 15:37:05 +02:00
|
|
|
TRACE("Deleting %d (remaining %d) chars at %d in %s (%d)\n",
|
2008-08-07 18:31:37 +02:00
|
|
|
nCharsToDelete, nChars, c.nOffset,
|
2013-01-31 14:48:00 +01:00
|
|
|
debugstr_run( run ), run->len);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2013-01-29 14:41:48 +01:00
|
|
|
/* nOfs is a character offset (from the start of the document
|
|
|
|
to the current (deleted) run */
|
2013-01-30 16:10:20 +01:00
|
|
|
add_undo_insert_run( editor, nOfs + nChars, get_text( run, c.nOffset ), nCharsToDelete, run->nFlags, run->style );
|
2013-01-22 15:04:08 +01:00
|
|
|
|
2013-02-05 14:19:41 +01:00
|
|
|
ME_StrDeleteV(run->para->text, run->nCharOfs + c.nOffset, nCharsToDelete);
|
2013-01-31 14:48:00 +01:00
|
|
|
run->len -= nCharsToDelete;
|
|
|
|
TRACE("Post deletion string: %s (%d)\n", debugstr_run( run ), run->len);
|
|
|
|
TRACE("Shift value: %d\n", shift);
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* update cursors (including c) */
|
|
|
|
for (i=-1; i<editor->nCursors; i++) {
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_Cursor *pThisCur = editor->pCursors + i;
|
2005-03-05 12:19:14 +01:00
|
|
|
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);
|
2013-01-31 14:48:00 +01:00
|
|
|
assert(pThisCur->nOffset <= run->len);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2013-01-31 14:48:00 +01:00
|
|
|
if (pThisCur->nOffset == run->len)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-27 09:23:27 +01:00
|
|
|
pThisCur->pRun = run_get_di( run_next( &pThisCur->pRun->member.run ) );
|
|
|
|
assert( pThisCur->pRun );
|
2005-03-05 12:19:14 +01:00
|
|
|
pThisCur->nOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* c = updated data now */
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (c.pRun == cursor.pRun)
|
|
|
|
ME_SkipAndPropagateCharOffset(c.pRun, shift);
|
|
|
|
else
|
|
|
|
ME_PropagateCharOffset(c.pRun, shift);
|
|
|
|
|
2013-01-31 14:48:00 +01:00
|
|
|
if (!cursor.pRun->member.run.len)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2013-01-31 14:48:00 +01:00
|
|
|
TRACE("Removing empty run\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_Remove(cursor.pRun);
|
|
|
|
ME_DestroyDisplayItem(cursor.pRun);
|
|
|
|
}
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
shift = 0;
|
|
|
|
/*
|
|
|
|
ME_CheckCharOffsets(editor);
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-10-28 09:43:49 +01:00
|
|
|
if (delete_all) editor_set_default_para_fmt( editor, &start_para->fmt );
|
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)
|
2009-08-13 14:44:18 +02:00
|
|
|
{
|
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;
|
2009-08-13 14:44:18 +02:00
|
|
|
return ME_InternalDeleteText(editor, &editor->pCursors[nCursor],
|
2009-08-12 15:05:42 +02:00
|
|
|
nChars, FALSE);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2018-04-13 09:56:54 +02:00
|
|
|
static struct re_object* create_re_object(const REOBJECT *reo)
|
|
|
|
{
|
|
|
|
struct re_object *reobj = heap_alloc(sizeof(*reobj));
|
|
|
|
|
|
|
|
if (!reobj)
|
|
|
|
{
|
|
|
|
WARN("Fail to allocate re_object.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-04-13 09:57:15 +02:00
|
|
|
ME_CopyReObject(&reobj->obj, reo, REO_GETOBJ_ALL_INTERFACES);
|
2018-04-13 09:56:54 +02:00
|
|
|
return reobj;
|
|
|
|
}
|
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
|
|
|
{
|
2020-10-15 11:39:40 +02:00
|
|
|
ME_Run *run, *prev;
|
|
|
|
const WCHAR space = ' ';
|
|
|
|
struct re_object *reobj_prev = NULL;
|
|
|
|
ME_Cursor *cursor = editor->pCursors + nCursor;
|
2020-10-21 11:05:54 +02:00
|
|
|
ME_Style *style = style_get_insert_style( editor, cursor );
|
2020-10-15 11:39:40 +02:00
|
|
|
|
2006-02-04 16:59:48 +01:00
|
|
|
/* FIXME no no no */
|
|
|
|
if (ME_IsSelection(editor))
|
|
|
|
ME_DeleteSelection(editor);
|
|
|
|
|
2020-10-15 11:39:40 +02:00
|
|
|
run = run_insert( editor, cursor, style, &space, 1, MERF_GRAPHICS );
|
|
|
|
|
|
|
|
run->reobj = create_re_object( reo );
|
2018-04-13 09:56:54 +02:00
|
|
|
|
2020-10-15 11:39:40 +02:00
|
|
|
prev = run;
|
|
|
|
while ((prev = run_prev_all_paras( prev )))
|
2018-04-13 09:56:54 +02:00
|
|
|
{
|
2020-10-15 11:39:40 +02:00
|
|
|
if (prev->reobj)
|
2018-04-13 09:56:54 +02:00
|
|
|
{
|
2020-10-15 11:39:40 +02:00
|
|
|
reobj_prev = prev->reobj;
|
2018-04-13 09:56:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (reobj_prev)
|
2020-10-15 11:39:40 +02:00
|
|
|
list_add_after(&reobj_prev->entry, &run->reobj->entry);
|
2018-04-13 09:56:54 +02:00
|
|
|
else
|
2020-10-15 11:39:40 +02:00
|
|
|
list_add_head(&editor->reobj_list, &run->reobj->entry);
|
2018-04-13 09:56:54 +02:00
|
|
|
|
2020-10-15 11:39:40 +02:00
|
|
|
ME_ReleaseStyle( style );
|
2006-02-04 16:59:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-16 21:46:51 +01:00
|
|
|
void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor)
|
|
|
|
{
|
2020-10-15 11:39:40 +02:00
|
|
|
const WCHAR space = ' ';
|
|
|
|
ME_Cursor *cursor = editor->pCursors + nCursor;
|
2020-10-21 11:05:54 +02:00
|
|
|
ME_Style *style = style_get_insert_style( editor, cursor );
|
2008-03-16 21:46:51 +01:00
|
|
|
|
|
|
|
/* FIXME no no no */
|
|
|
|
if (ME_IsSelection(editor))
|
|
|
|
ME_DeleteSelection(editor);
|
|
|
|
|
2020-10-15 11:39:40 +02:00
|
|
|
run_insert( editor, cursor, style, &space, 1, MERF_ENDROW );
|
|
|
|
|
|
|
|
ME_ReleaseStyle( style );
|
2008-03-16 21:46:51 +01:00
|
|
|
}
|
|
|
|
|
2006-02-04 17:01:01 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
|
2020-10-15 11:39:40 +02:00
|
|
|
const WCHAR *str, int len, ME_Style *style)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
const WCHAR *pos;
|
2020-10-15 11:39:40 +02:00
|
|
|
ME_Cursor *cursor = editor->pCursors + nCursor;
|
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);
|
|
|
|
|
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);
|
|
|
|
|
2020-10-15 11:39:40 +02:00
|
|
|
if (len == -1) len = lstrlenW( str );
|
2007-09-20 23:58:02 +02:00
|
|
|
|
|
|
|
/* grow the text limit to fit our text */
|
2020-10-15 11:39:40 +02:00
|
|
|
if (editor->nTextLimit < oldLen + len) editor->nTextLimit = oldLen + len;
|
2007-09-20 23:58:02 +02:00
|
|
|
|
2009-01-27 09:38:49 +01:00
|
|
|
pos = str;
|
|
|
|
|
2005-08-23 20:16:15 +02:00
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
/* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */
|
2020-10-15 11:39:40 +02:00
|
|
|
while (pos - str < len && *pos != '\r' && *pos != '\n' && *pos != '\t')
|
2005-08-23 20:16:15 +02:00
|
|
|
pos++;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-15 11:39:40 +02:00
|
|
|
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 );
|
2005-08-23 20:16:15 +02:00
|
|
|
pos++;
|
2020-10-15 11:39:40 +02:00
|
|
|
}
|
|
|
|
else /* handle EOLs */
|
|
|
|
{
|
2020-10-13 12:16:33 +02:00
|
|
|
ME_Run *end_run, *run, *prev;
|
|
|
|
ME_Paragraph *new_para;
|
2009-01-28 07:34:56 +01:00
|
|
|
int eol_len = 0;
|
2008-04-27 05:49:35 +02:00
|
|
|
|
2017-11-15 02:18:53 +01:00
|
|
|
/* Check if new line is allowed for this control */
|
|
|
|
if (!(editor->styleFlags & ES_MULTILINE))
|
|
|
|
break;
|
|
|
|
|
2009-01-27 09:38:49 +01:00
|
|
|
/* Find number of CR and LF in end of paragraph run */
|
|
|
|
if (*pos =='\r')
|
|
|
|
{
|
|
|
|
if (len > 1 && pos[1] == '\n')
|
2009-01-28 07:34:56 +01:00
|
|
|
eol_len = 2;
|
2009-01-27 09:38:49 +01:00
|
|
|
else if (len > 2 && pos[1] == '\r' && pos[2] == '\n')
|
2009-01-28 07:34:56 +01:00
|
|
|
eol_len = 3;
|
|
|
|
else
|
|
|
|
eol_len = 1;
|
2020-10-15 11:39:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-27 09:38:49 +01:00
|
|
|
assert(*pos == '\n');
|
2009-01-28 07:34:56 +01:00
|
|
|
eol_len = 1;
|
2008-04-21 17:10:05 +02:00
|
|
|
}
|
2009-01-28 07:34:56 +01:00
|
|
|
pos += eol_len;
|
2009-01-27 09:38:49 +01:00
|
|
|
|
2009-01-28 07:34:56 +01:00
|
|
|
if (!editor->bEmulateVersion10 && eol_len == 3)
|
2009-01-27 09:38:49 +01:00
|
|
|
{
|
|
|
|
/* handle special \r\r\n sequence (richedit 2.x and higher only) */
|
2020-10-15 11:39:40 +02:00
|
|
|
const WCHAR space = ' ';
|
|
|
|
run_insert( editor, cursor, style, &space, 1, 0 );
|
2020-10-14 12:17:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-05 14:19:39 +01:00
|
|
|
const WCHAR cr = '\r', *eol_str = str;
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2013-02-05 14:19:39 +01:00
|
|
|
if (!editor->bEmulateVersion10)
|
|
|
|
{
|
|
|
|
eol_str = &cr;
|
|
|
|
eol_len = 1;
|
2009-01-28 07:34:56 +01:00
|
|
|
}
|
2009-01-27 09:38:49 +01:00
|
|
|
|
2020-10-15 11:39:40 +02:00
|
|
|
if (cursor->nOffset == cursor->pRun->member.run.len)
|
2014-01-07 13:44:23 +01:00
|
|
|
{
|
2020-10-15 11:39:40 +02:00
|
|
|
run = run_next( &cursor->pRun->member.run );
|
|
|
|
if (!run) run = &cursor->pRun->member.run;
|
2014-01-07 13:44:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-15 11:39:40 +02:00
|
|
|
if (cursor->nOffset) run_split( editor, cursor );
|
|
|
|
run = &cursor->pRun->member.run;
|
2014-01-07 13:44:23 +01:00
|
|
|
}
|
|
|
|
|
2020-10-16 13:08:09 +02:00
|
|
|
new_para = para_split( editor, run, style, eol_str, eol_len, 0 );
|
2020-10-13 12:16:33 +02:00
|
|
|
end_run = para_end_run( para_prev( new_para ) );
|
2014-01-07 13:44:23 +01:00
|
|
|
|
|
|
|
/* Move any cursors that were at the end of the previous run to the beginning of the new para */
|
2020-10-13 12:16:33 +02:00
|
|
|
prev = run_prev( end_run );
|
2014-01-07 13:44:23 +01:00
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < editor->nCursors; i++)
|
|
|
|
{
|
2020-10-13 12:16:33 +02:00
|
|
|
if (editor->pCursors[i].pRun == run_get_di( prev ) &&
|
|
|
|
editor->pCursors[i].nOffset == prev->len)
|
2014-01-07 13:44:23 +01:00
|
|
|
{
|
2020-10-13 12:16:33 +02:00
|
|
|
editor->pCursors[i].pPara = para_get_di( new_para );
|
|
|
|
editor->pCursors[i].pRun = run_get_di( run );
|
2014-01-07 13:44:23 +01:00
|
|
|
editor->pCursors[i].nOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-23 20:16:15 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2009-01-27 09:38:49 +01:00
|
|
|
len -= pos - str;
|
|
|
|
str = pos;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-13 14:43:57 +02:00
|
|
|
/* Move the cursor nRelOfs characters (either forwards or backwards)
|
2016-10-04 14:07:33 +02:00
|
|
|
* If final_eop is TRUE, allow moving the cursor to the end of the final eop.
|
2009-08-13 14:43:57 +02:00
|
|
|
*
|
|
|
|
* returns the actual number of characters moved.
|
|
|
|
**/
|
2016-10-04 14:07:33 +02:00
|
|
|
int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BOOL final_eop)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2009-08-13 14:43:57 +02:00
|
|
|
cursor->nOffset += nRelOfs;
|
|
|
|
if (cursor->nOffset < 0)
|
2006-01-10 20:23:41 +01:00
|
|
|
{
|
2009-08-13 14:43:57 +02:00
|
|
|
cursor->nOffset += cursor->pRun->member.run.nCharOfs;
|
|
|
|
if (cursor->nOffset >= 0)
|
2006-01-10 20:23:41 +01:00
|
|
|
{
|
2009-08-13 14:43:57 +02:00
|
|
|
/* new offset in the same paragraph */
|
2006-01-31 13:01:26 +01:00
|
|
|
do {
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pRun = run_get_di( run_prev( &cursor->pRun->member.run ) );
|
2009-08-13 14:43:57 +02:00
|
|
|
} while (cursor->nOffset < cursor->pRun->member.run.nCharOfs);
|
|
|
|
cursor->nOffset -= cursor->pRun->member.run.nCharOfs;
|
|
|
|
return nRelOfs;
|
2006-01-10 20:23:41 +01:00
|
|
|
}
|
2009-02-07 19:21:29 +01:00
|
|
|
|
2009-08-13 14:43:57 +02:00
|
|
|
cursor->nOffset += cursor->pPara->member.para.nCharOfs;
|
|
|
|
if (cursor->nOffset <= 0)
|
2006-01-10 20:23:41 +01:00
|
|
|
{
|
2009-08-13 14:43:57 +02:00
|
|
|
/* moved to the start of the text */
|
|
|
|
nRelOfs -= cursor->nOffset;
|
|
|
|
ME_SetCursorToStart(editor, cursor);
|
|
|
|
return nRelOfs;
|
|
|
|
}
|
2009-02-07 19:21:29 +01:00
|
|
|
|
2009-08-13 14:43:57 +02:00
|
|
|
/* new offset in a previous paragraph */
|
|
|
|
do {
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pPara = para_get_di( para_prev( &cursor->pPara->member.para ) );
|
2009-08-13 14:43:57 +02:00
|
|
|
} while (cursor->nOffset < cursor->pPara->member.para.nCharOfs);
|
|
|
|
cursor->nOffset -= cursor->pPara->member.para.nCharOfs;
|
|
|
|
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pRun = run_get_di( para_end_run( &cursor->pPara->member.para ) );
|
2009-08-13 14:43:57 +02:00
|
|
|
while (cursor->nOffset < cursor->pRun->member.run.nCharOfs) {
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pRun = run_get_di( run_prev( &cursor->pRun->member.run ) );
|
2009-08-13 14:43:57 +02:00
|
|
|
}
|
|
|
|
cursor->nOffset -= cursor->pRun->member.run.nCharOfs;
|
2020-10-13 12:16:34 +02:00
|
|
|
}
|
|
|
|
else if (cursor->nOffset >= cursor->pRun->member.run.len)
|
|
|
|
{
|
|
|
|
ME_Paragraph *next_para;
|
2009-08-13 14:43:57 +02:00
|
|
|
int new_offset;
|
|
|
|
|
|
|
|
new_offset = ME_GetCursorOfs(cursor);
|
2020-10-13 12:16:34 +02:00
|
|
|
next_para = para_next( &cursor->pPara->member.para );
|
|
|
|
if (new_offset < next_para->nCharOfs)
|
2009-08-13 14:43:57 +02:00
|
|
|
{
|
|
|
|
/* new offset in the same paragraph */
|
|
|
|
do {
|
2013-01-31 14:48:00 +01:00
|
|
|
cursor->nOffset -= cursor->pRun->member.run.len;
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pRun = run_get_di( run_next( &cursor->pRun->member.run ) );
|
2013-01-31 14:48:00 +01:00
|
|
|
} while (cursor->nOffset >= cursor->pRun->member.run.len);
|
2009-08-13 14:43:57 +02:00
|
|
|
return nRelOfs;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2009-08-13 14:43:57 +02:00
|
|
|
|
2016-10-04 14:07:33 +02:00
|
|
|
if (new_offset >= ME_GetTextLength(editor) + (final_eop ? 1 : 0))
|
2009-08-13 14:43:57 +02:00
|
|
|
{
|
|
|
|
/* new offset at the end of the text */
|
2016-10-04 14:07:33 +02:00
|
|
|
ME_SetCursorToEnd(editor, cursor, final_eop);
|
|
|
|
nRelOfs -= new_offset - (ME_GetTextLength(editor) + (final_eop ? 1 : 0));
|
2009-08-13 14:43:57 +02:00
|
|
|
return nRelOfs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* new offset in a following paragraph */
|
2006-01-31 13:01:26 +01:00
|
|
|
do {
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pPara = para_get_di( next_para );
|
|
|
|
next_para = para_next( next_para );
|
|
|
|
} while (new_offset >= next_para->nCharOfs);
|
2009-08-13 14:43:57 +02:00
|
|
|
|
|
|
|
cursor->nOffset = new_offset - cursor->pPara->member.para.nCharOfs;
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pRun = run_get_di( para_first_run( &cursor->pPara->member.para ) );
|
2013-01-31 14:48:00 +01:00
|
|
|
while (cursor->nOffset >= cursor->pRun->member.run.len)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2013-01-31 14:48:00 +01:00
|
|
|
cursor->nOffset -= cursor->pRun->member.run.len;
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pRun = run_get_di( run_next( &cursor->pRun->member.run ) );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2009-08-13 14:43:57 +02:00
|
|
|
} /* else new offset is in the same run */
|
|
|
|
return nRelOfs;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2015-03-29 22:07:50 +02:00
|
|
|
BOOL
|
2006-01-12 11:54:57 +01:00
|
|
|
ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
|
|
|
|
{
|
2020-10-13 12:16:34 +02:00
|
|
|
ME_Run *run = &cursor->pRun->member.run, *other_run;
|
|
|
|
ME_Paragraph *para = &cursor->pPara->member.para;
|
2006-01-12 11:54:57 +01:00
|
|
|
int nOffset = cursor->nOffset;
|
2009-08-12 15:06:00 +02:00
|
|
|
|
2006-01-12 11:54:57 +01:00
|
|
|
if (nRelOfs == -1)
|
|
|
|
{
|
|
|
|
/* Backward movement */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2020-10-13 12:16:34 +02:00
|
|
|
nOffset = ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, nOffset, WB_MOVEWORDLEFT );
|
|
|
|
if (nOffset) break;
|
|
|
|
other_run = run_prev( run );
|
|
|
|
if (other_run)
|
2006-01-12 11:54:57 +01:00
|
|
|
{
|
2020-10-13 12:16:34 +02:00
|
|
|
if (ME_CallWordBreakProc( editor, get_text( other_run, 0 ), other_run->len, other_run->len - 1, WB_ISDELIMITER )
|
|
|
|
&& !(run->nFlags & MERF_ENDPARA)
|
|
|
|
&& !(&cursor->pRun->member.run == run && cursor->nOffset == 0)
|
|
|
|
&& !ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, 0, WB_ISDELIMITER ))
|
2006-01-12 11:54:57 +01:00
|
|
|
break;
|
2020-10-13 12:16:34 +02:00
|
|
|
run = other_run;
|
|
|
|
nOffset = other_run->len;
|
2006-01-12 11:54:57 +01:00
|
|
|
}
|
2020-10-13 12:16:34 +02:00
|
|
|
else
|
2006-01-12 11:54:57 +01:00
|
|
|
{
|
2020-10-13 12:16:34 +02:00
|
|
|
if (&cursor->pRun->member.run == run && cursor->nOffset == 0)
|
2006-01-12 11:54:57 +01:00
|
|
|
{
|
2020-10-13 12:16:34 +02:00
|
|
|
para = run->para;
|
2008-08-07 18:31:41 +02:00
|
|
|
/* Skip empty start of table row paragraph */
|
2020-10-14 12:17:16 +02:00
|
|
|
if (para_prev( para ) && para_prev( para )->nFlags & MEPF_ROWSTART)
|
2020-10-13 12:16:34 +02:00
|
|
|
para = para_prev( para );
|
2006-01-12 11:54:57 +01:00
|
|
|
/* Paragraph breaks are treated as separate words */
|
2020-10-14 12:17:16 +02:00
|
|
|
if (!para_prev( para )) return FALSE;
|
2020-10-13 12:16:34 +02:00
|
|
|
para = para_prev( para );
|
|
|
|
run = para_end_run( para );
|
2006-01-12 11:54:57 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Forward movement */
|
|
|
|
BOOL last_delim = FALSE;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2020-10-13 12:16:34 +02:00
|
|
|
if (last_delim && !ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, nOffset, WB_ISDELIMITER ))
|
2006-01-12 11:54:57 +01:00
|
|
|
break;
|
2020-10-13 12:16:34 +02:00
|
|
|
nOffset = ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, nOffset, WB_MOVEWORDRIGHT );
|
|
|
|
if (nOffset < run->len) break;
|
|
|
|
other_run = run_next( run );
|
|
|
|
if (other_run)
|
2006-01-12 11:54:57 +01:00
|
|
|
{
|
2020-10-13 12:16:34 +02:00
|
|
|
last_delim = ME_CallWordBreakProc( editor, get_text( run, 0 ), run->len, nOffset - 1, WB_ISDELIMITER );
|
|
|
|
run = other_run;
|
2006-01-12 11:54:57 +01:00
|
|
|
nOffset = 0;
|
|
|
|
}
|
2020-10-13 12:16:34 +02:00
|
|
|
else
|
2006-01-12 11:54:57 +01:00
|
|
|
{
|
2020-10-13 12:16:34 +02:00
|
|
|
para = para_next( para );
|
|
|
|
if (para_get_di( para )->type == diTextEnd)
|
|
|
|
{
|
|
|
|
if (&cursor->pRun->member.run == run) return FALSE;
|
|
|
|
nOffset = 0;
|
|
|
|
break;
|
2009-08-12 15:06:00 +02:00
|
|
|
}
|
2020-10-13 12:16:34 +02:00
|
|
|
if (para->nFlags & MEPF_ROWSTART) para = para_next( para );
|
|
|
|
if (&cursor->pRun->member.run == run) run = para_first_run( para );
|
2006-01-12 11:54:57 +01:00
|
|
|
nOffset = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-13 12:16:34 +02:00
|
|
|
cursor->pPara = para_get_di( para );
|
|
|
|
cursor->pRun = run_get_di( run );
|
2006-01-12 11:54:57 +01:00
|
|
|
cursor->nOffset = nOffset;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2009-01-12 22:48:01 +01:00
|
|
|
static 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 stParagraph:
|
2020-10-26 09:46:40 +01:00
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
2008-08-05 18:10:43 +02:00
|
|
|
|
2020-10-26 09:46:40 +01:00
|
|
|
editor->pCursors[0].pRun = run_get_di( para_end_run( &editor->pCursors[0].pPara->member.para ) );
|
|
|
|
editor->pCursors[0].pPara = para_get_di( editor->pCursors[0].pRun->member.run.para );
|
|
|
|
editor->pCursors[0].nOffset = editor->pCursors[0].pRun->member.run.len;
|
|
|
|
|
|
|
|
editor->pCursors[1].pRun = run_get_di( para_first_run( &editor->pCursors[1].pPara->member.para ) );
|
2008-07-07 17:03:59 +02:00
|
|
|
editor->pCursors[1].nOffset = 0;
|
|
|
|
break;
|
2020-10-26 09:46:40 +01:00
|
|
|
case stLine:
|
|
|
|
{
|
|
|
|
ME_Row *row = row_from_cursor( editor->pCursors );
|
|
|
|
|
|
|
|
row_first_cursor( row, editor->pCursors + 1 );
|
|
|
|
row_end_cursor( row, editor->pCursors, TRUE );
|
|
|
|
break;
|
2008-07-07 17:03:59 +02:00
|
|
|
}
|
2008-07-07 17:04:02 +02:00
|
|
|
case stDocument:
|
|
|
|
/* Select everything with cursor anchored from the start of the text */
|
2009-08-12 15:06:05 +02:00
|
|
|
ME_SetCursorToStart(editor, &editor->pCursors[1]);
|
2020-10-26 09:46:40 +01:00
|
|
|
ME_SetCursorToEnd(editor, &editor->pCursors[0], TRUE);
|
2008-07-07 17:04:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-08-12 15:05:42 +02:00
|
|
|
int ME_GetCursorOfs(const ME_Cursor *cursor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2009-08-12 15:05:42 +02:00
|
|
|
return cursor->pPara->member.para.nCharOfs
|
|
|
|
+ cursor->pRun->member.run.nCharOfs + cursor->nOffset;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-23 11:25:06 +02:00
|
|
|
/* Helper function for cursor_from_virtual_coords() to find paragraph within tables */
|
2020-10-13 12:16:35 +02:00
|
|
|
static ME_Paragraph *pixel_pos_in_table_row( int x, int y, ME_Paragraph *para )
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2020-10-23 11:25:04 +02:00
|
|
|
ME_Cell *cell, *next_cell;
|
2020-10-13 12:16:35 +02:00
|
|
|
|
|
|
|
assert( para->nFlags & MEPF_ROWSTART );
|
2020-10-23 11:25:04 +02:00
|
|
|
cell = table_row_first_cell( para );
|
|
|
|
assert( cell );
|
2008-08-07 18:31:41 +02:00
|
|
|
|
|
|
|
/* find the cell we are in */
|
2020-10-23 11:25:04 +02:00
|
|
|
while ((next_cell = cell_next( cell )) != NULL)
|
2020-10-13 12:16:35 +02:00
|
|
|
{
|
2020-10-23 11:25:04 +02:00
|
|
|
if (x < next_cell->pt.x)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2020-10-23 11:25:04 +02:00
|
|
|
para = cell_first_para( cell );
|
2008-08-07 18:31:41 +02:00
|
|
|
/* Found the cell, but there might be multiple paragraphs in
|
|
|
|
* the cell, so need to search down the cell for the paragraph. */
|
2020-10-23 11:25:04 +02:00
|
|
|
while (cell == para_cell( para ))
|
2020-10-13 12:16:35 +02:00
|
|
|
{
|
|
|
|
if (y < para->pt.y + para->nHeight)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2020-10-13 12:16:35 +02:00
|
|
|
if (para->nFlags & MEPF_ROWSTART) return pixel_pos_in_table_row( x, y, para );
|
|
|
|
else return para;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2020-10-13 12:16:35 +02:00
|
|
|
para = para_next( para );
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
/* Past the end of the cell, so go back to the last cell paragraph */
|
2020-10-13 12:16:35 +02:00
|
|
|
return para_prev( para );
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
cell = next_cell;
|
|
|
|
}
|
|
|
|
/* Return table row delimiter */
|
2020-10-13 12:16:35 +02:00
|
|
|
para = table_row_end( para );
|
|
|
|
assert( para->nFlags & MEPF_ROWEND );
|
|
|
|
assert( para->fmt.dwMask & PFM_TABLEROWDELIMITER );
|
|
|
|
assert( para->fmt.wEffects & PFE_TABLEROWDELIMITER );
|
2008-08-07 18:31:41 +02:00
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
2020-10-26 09:46:38 +01:00
|
|
|
static BOOL row_cursor( ME_TextEditor *editor, ME_Row *row, int x,
|
|
|
|
ME_Cursor *cursor )
|
2008-09-10 20:08:46 +02:00
|
|
|
{
|
2020-10-26 09:46:38 +01:00
|
|
|
ME_Run *run, *last;
|
|
|
|
BOOL exact = TRUE;
|
2013-02-26 14:19:51 +01:00
|
|
|
|
2020-10-26 09:46:38 +01:00
|
|
|
if (x < row->pt.x)
|
2013-02-25 13:59:27 +01:00
|
|
|
{
|
2020-10-26 09:46:38 +01:00
|
|
|
x = row->pt.x;
|
|
|
|
exact = FALSE;
|
2013-02-25 13:59:27 +01:00
|
|
|
}
|
|
|
|
|
2020-10-26 09:46:38 +01:00
|
|
|
run = row_first_run( row );
|
|
|
|
assert( run );
|
|
|
|
cursor->nOffset = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (x >= run->pt.x && x < run->pt.x + run->nWidth)
|
|
|
|
{
|
|
|
|
cursor->nOffset = ME_CharFromPoint( editor, x - run->pt.x, run, TRUE, TRUE );
|
|
|
|
cursor->pRun = run_get_di( run );
|
|
|
|
cursor->pPara = para_get_di( run->para );
|
|
|
|
return exact;
|
|
|
|
}
|
|
|
|
last = run;
|
|
|
|
run = row_next_run( row, run );
|
|
|
|
} while (run);
|
|
|
|
|
|
|
|
run = last;
|
|
|
|
|
|
|
|
cursor->pRun = run_get_di( run );
|
|
|
|
cursor->pPara = para_get_di( run->para );
|
|
|
|
return FALSE;
|
2008-09-10 20:08:46 +02:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
2016-10-04 14:07:35 +02:00
|
|
|
* If final_eop is TRUE consider the final end-of-paragraph.
|
|
|
|
*
|
2008-07-09 15:36:12 +02:00
|
|
|
* returns TRUE if the result was exactly under the cursor, otherwise returns
|
|
|
|
* FALSE, and result is set to the closest position to the coordinates.
|
|
|
|
*/
|
2020-10-23 11:25:06 +02:00
|
|
|
static BOOL cursor_from_virtual_coords( ME_TextEditor *editor, int x, int y,
|
|
|
|
ME_Cursor *result, BOOL final_eop )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-13 12:16:35 +02:00
|
|
|
ME_Paragraph *para = editor_first_para( editor );
|
2020-10-26 09:46:39 +01:00
|
|
|
ME_Row *row = NULL, *next_row;
|
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;
|
|
|
|
|
2008-01-01 22:05:05 +01:00
|
|
|
/* find paragraph */
|
2020-10-13 12:16:35 +02:00
|
|
|
for (; para_next( para ); para = para_next( para ))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-13 12:16:35 +02:00
|
|
|
if (y < para->pt.y + para->nHeight)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-13 12:16:35 +02:00
|
|
|
if (para->nFlags & MEPF_ROWSTART)
|
|
|
|
para = pixel_pos_in_table_row( x, y, para );
|
|
|
|
y -= para->pt.y;
|
2020-10-26 09:46:39 +01:00
|
|
|
row = para_first_row( para );
|
2008-01-01 22:05:05 +01:00
|
|
|
break;
|
2020-10-07 14:20:38 +02:00
|
|
|
}
|
2020-10-13 12:16:35 +02:00
|
|
|
else if (para->nFlags & MEPF_ROWSTART)
|
2020-10-07 14:20:38 +02:00
|
|
|
{
|
2020-10-13 12:16:35 +02:00
|
|
|
para = table_row_end( para );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-01-01 22:05:05 +01:00
|
|
|
}
|
|
|
|
/* find row */
|
2020-10-07 14:20:38 +02:00
|
|
|
while (row)
|
2008-01-01 22:05:05 +01:00
|
|
|
{
|
2020-10-26 09:46:39 +01:00
|
|
|
if (y < row->pt.y + row->nHeight) break;
|
|
|
|
next_row = row_next( row );
|
2020-10-07 14:20:38 +02:00
|
|
|
if (!next_row) break;
|
|
|
|
row = next_row;
|
2008-01-01 22:05:05 +01:00
|
|
|
}
|
2020-10-07 14:20:38 +02:00
|
|
|
|
2020-10-26 09:46:39 +01:00
|
|
|
if (!row && !final_eop && para_prev( para ))
|
2008-06-27 15:18:39 +02:00
|
|
|
{
|
|
|
|
/* 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;
|
2020-10-26 09:46:39 +01:00
|
|
|
row = para_end_row( para_prev( para ) );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2013-02-25 13:59:27 +01:00
|
|
|
|
2020-10-26 09:46:39 +01:00
|
|
|
if (row) return row_cursor( editor, row, x, result ) && isExact;
|
2013-02-25 13:59:27 +01:00
|
|
|
|
2016-10-04 14:07:35 +02:00
|
|
|
ME_SetCursorToEnd(editor, result, TRUE);
|
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
|
|
|
|
2009-08-13 14:44:09 +02:00
|
|
|
/* Sets the cursor to the position closest to the pixel position
|
2008-07-09 15:36:12 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-08-13 14:44:09 +02:00
|
|
|
*
|
|
|
|
* return FALSE if outside client area and the cursor is not set,
|
|
|
|
* otherwise TRUE is returned.
|
2008-07-09 15:36:12 +02:00
|
|
|
*/
|
2009-08-13 14:44:09 +02:00
|
|
|
BOOL ME_CharFromPos(ME_TextEditor *editor, int x, int y,
|
|
|
|
ME_Cursor *cursor, BOOL *isExact)
|
2005-07-26 12:33:00 +02:00
|
|
|
{
|
|
|
|
RECT rc;
|
2008-07-09 15:36:12 +02:00
|
|
|
BOOL bResult;
|
2005-07-26 12:33:00 +02:00
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxGetClientRect(editor->texthost, &rc);
|
2008-07-09 15:36:12 +02:00
|
|
|
if (x < 0 || y < 0 || x >= rc.right || y >= rc.bottom) {
|
|
|
|
if (isExact) *isExact = FALSE;
|
2009-08-13 14:44:09 +02:00
|
|
|
return FALSE;
|
2008-07-09 15:36:12 +02:00
|
|
|
}
|
2009-01-14 19:24:02 +01:00
|
|
|
x += editor->horz_si.nPos;
|
|
|
|
y += editor->vert_si.nPos;
|
2020-10-23 11:25:06 +02:00
|
|
|
bResult = cursor_from_virtual_coords( editor, x, y, cursor, FALSE );
|
2008-07-09 15:36:12 +02:00
|
|
|
if (isExact) *isExact = bResult;
|
2009-08-13 14:44:09 +02:00
|
|
|
return TRUE;
|
2005-07-26 12:33:00 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2009-08-12 15:05:42 +02:00
|
|
|
curOfs = ME_GetCursorOfs(&editor->pCursors[0]);
|
|
|
|
anchorStartOfs = ME_GetCursorOfs(&editor->pCursors[3]);
|
|
|
|
anchorEndOfs = ME_GetCursorOfs(&editor->pCursors[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;
|
2020-10-27 09:23:26 +01:00
|
|
|
switch (editor->nSelectionType)
|
|
|
|
{
|
|
|
|
case stWord:
|
2008-08-05 18:10:43 +02:00
|
|
|
ME_MoveCursorWords(editor, &editor->pCursors[1], -1);
|
2020-10-27 09:23:26 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case stLine:
|
2008-07-07 17:03:53 +02:00
|
|
|
{
|
2020-10-27 09:23:26 +01:00
|
|
|
ME_Row *row = row_from_cursor( editor->pCursors + 1 );
|
|
|
|
row_first_cursor( row, editor->pCursors + 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case stParagraph:
|
|
|
|
editor->pCursors[1].pRun = run_get_di( para_first_run( &editor->pCursors[1].pPara->member.para ) );
|
2008-08-05 18:10:43 +02:00
|
|
|
editor->pCursors[1].nOffset = 0;
|
2020-10-27 09:23:26 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
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;
|
2020-10-27 09:23:26 +01:00
|
|
|
switch (editor->nSelectionType)
|
2008-07-07 17:03:53 +02:00
|
|
|
{
|
2020-10-27 09:23:26 +01:00
|
|
|
case stWord:
|
|
|
|
ME_MoveCursorWords( editor, &editor->pCursors[0], +1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stLine:
|
|
|
|
{
|
|
|
|
ME_Row *row = row_from_cursor( editor->pCursors );
|
|
|
|
row_end_cursor( row, editor->pCursors, TRUE );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case stParagraph:
|
|
|
|
editor->pCursors[0].pRun = run_get_di( para_end_run( &editor->pCursors[0].pPara->member.para ) );
|
|
|
|
editor->pCursors[0].pPara = para_get_di( editor->pCursors[0].pRun->member.run.para );
|
|
|
|
editor->pCursors[0].nOffset = editor->pCursors[0].pRun->member.run.len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
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;
|
2014-03-19 09:14:53 +01:00
|
|
|
BOOL is_selection = FALSE, is_shift;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->nUDArrowX = -1;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
|
|
|
x += editor->horz_si.nPos;
|
|
|
|
y += editor->vert_si.nPos;
|
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
|
|
|
|
2020-10-23 11:25:06 +02:00
|
|
|
cursor_from_virtual_coords( editor, x, y, &editor->pCursors[0], FALSE );
|
2008-07-07 17:03:53 +02:00
|
|
|
|
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);
|
2019-04-03 15:23:04 +02:00
|
|
|
update_caret(editor);
|
2008-07-05 10:23:53 +02:00
|
|
|
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;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2008-07-07 17:04:02 +02:00
|
|
|
if (editor->nSelectionType == stDocument)
|
|
|
|
return;
|
2009-01-14 19:24:02 +01:00
|
|
|
x += editor->horz_si.nPos;
|
|
|
|
y += editor->vert_si.nPos;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
tmp_cursor = editor->pCursors[0];
|
2020-10-23 11:25:06 +02:00
|
|
|
/* FIXME: do something with the return value of cursor_from_virtual_coords */
|
|
|
|
cursor_from_virtual_coords( editor, x, y, &tmp_cursor, TRUE );
|
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)))
|
|
|
|
/* 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 */
|
2020-10-27 09:23:29 +01:00
|
|
|
editor_ensure_visible( editor, &editor->pCursors[1] );
|
|
|
|
else
|
|
|
|
editor_ensure_visible( editor, &editor->pCursors[0] );
|
2007-12-14 21:29:37 +01:00
|
|
|
|
2006-01-31 12:58:59 +01:00
|
|
|
ME_InvalidateSelection(editor);
|
2019-04-03 15:23:04 +02:00
|
|
|
update_caret(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SendSelChange(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ME_GetXForArrow(ME_TextEditor *editor, ME_Cursor *pCursor)
|
|
|
|
{
|
2020-10-15 11:39:41 +02:00
|
|
|
ME_Run *run = &pCursor->pRun->member.run;
|
2005-03-05 12:19:14 +01:00
|
|
|
int x;
|
|
|
|
|
|
|
|
if (editor->nUDArrowX != -1)
|
|
|
|
x = editor->nUDArrowX;
|
2020-10-15 11:39:41 +02:00
|
|
|
else
|
|
|
|
{
|
2020-10-23 11:25:06 +02:00
|
|
|
x = run->pt.x;
|
|
|
|
x += ME_PointFromChar( editor, run, pCursor->nOffset, TRUE );
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->nUDArrowX = x;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
static void
|
2016-10-04 14:07:34 +02:00
|
|
|
ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs, BOOL extend)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pRun = pCursor->pRun;
|
2020-10-23 11:25:05 +02:00
|
|
|
ME_Paragraph *old_para = &pCursor->pPara->member.para, *new_para;
|
|
|
|
ME_DisplayItem *pItem;
|
2005-03-05 12:19:14 +01:00
|
|
|
int x = ME_GetXForArrow(editor, pCursor);
|
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);
|
2016-10-04 14:07:34 +02:00
|
|
|
if (!pItem) /* row not found */
|
|
|
|
{
|
|
|
|
if (extend)
|
|
|
|
ME_SetCursorToStart(editor, pCursor);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-23 11:25:05 +02:00
|
|
|
new_para = &ME_GetParagraph(pItem)->member.para;
|
|
|
|
if (old_para->nFlags & MEPF_ROWEND ||
|
|
|
|
(para_cell( old_para ) && para_cell( old_para ) != para_cell( new_para )))
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
/* Brought out of a cell */
|
2020-10-23 11:25:05 +02:00
|
|
|
new_para = para_prev( table_row_start( old_para ));
|
|
|
|
if (!new_para) return; /* At the top, so don't go anywhere. */
|
|
|
|
pItem = ME_FindItemFwd( para_get_di( new_para ), diStartRow);
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2020-10-23 11:25:05 +02:00
|
|
|
if (new_para->nFlags & MEPF_ROWEND)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
/* Brought into a table row */
|
2020-10-23 11:25:05 +02:00
|
|
|
ME_Cell *cell = table_row_end_cell( new_para );
|
|
|
|
while (x < cell->pt.x && cell_prev( cell ))
|
|
|
|
cell = cell_prev( cell );
|
|
|
|
if (cell_next( cell )) /* else - we are still at the end of the row */
|
|
|
|
pItem = ME_FindItemBack( cell_get_di( cell_next( cell ) ), diStartRow );
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* start of the next row */
|
|
|
|
pItem = ME_FindItemFwd(pRun, diStartRow);
|
2016-10-04 14:07:34 +02:00
|
|
|
if (!pItem) /* row not found */
|
|
|
|
{
|
|
|
|
if (extend)
|
|
|
|
ME_SetCursorToEnd(editor, pCursor, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-23 11:25:05 +02:00
|
|
|
new_para = &ME_GetParagraph(pItem)->member.para;
|
|
|
|
if (old_para->nFlags & MEPF_ROWSTART ||
|
|
|
|
(para_cell( old_para ) && para_cell( old_para ) != para_cell( new_para )))
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
/* Brought out of a cell */
|
2020-10-23 11:25:05 +02:00
|
|
|
new_para = para_next( table_row_end( old_para ) );
|
|
|
|
if (!para_next( new_para )) return; /* At the bottom, so don't go anywhere. */
|
|
|
|
pItem = ME_FindItemFwd( para_get_di( new_para ), diStartRow );
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2020-10-23 11:25:05 +02:00
|
|
|
if (new_para->nFlags & MEPF_ROWSTART)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
/* Brought into a table row */
|
2020-10-23 11:25:05 +02:00
|
|
|
ME_Cell *cell = table_row_first_cell( new_para );
|
|
|
|
while (cell_next( cell ) && x >= cell_next( cell )->pt.x)
|
|
|
|
cell = cell_next( cell );
|
|
|
|
pItem = ME_FindItemFwd( cell_get_di( cell ), diStartRow );
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
2020-10-26 09:46:38 +01:00
|
|
|
row_cursor( editor, &pItem->member.row, x, pCursor );
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(pCursor->pRun);
|
|
|
|
assert(pCursor->pRun->type == diRun);
|
|
|
|
}
|
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor)
|
2009-01-12 22:48:01 +01:00
|
|
|
{
|
2009-01-15 17:03:49 +01:00
|
|
|
ME_DisplayItem *p = ME_FindItemFwd(editor->pBuffer->pFirst, diStartRow);
|
2009-01-12 22:48:01 +01:00
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
if (editor->vert_si.nPos < p->member.row.nHeight)
|
2009-01-12 22:48:01 +01:00
|
|
|
{
|
2009-08-12 15:06:05 +02:00
|
|
|
ME_SetCursorToStart(editor, pCursor);
|
2009-01-15 17:03:49 +01:00
|
|
|
/* Native clears seems to clear this x value on page up at the top
|
|
|
|
* of the text, but not on page down at the end of the text.
|
|
|
|
* Doesn't make sense, but we try to be bug for bug compatible. */
|
|
|
|
editor->nUDArrowX = -1;
|
|
|
|
} else {
|
|
|
|
ME_DisplayItem *pRun = pCursor->pRun;
|
|
|
|
ME_DisplayItem *pLast;
|
2010-05-14 22:04:32 +02:00
|
|
|
int x, y, yd, yp;
|
2009-01-15 17:03:49 +01:00
|
|
|
int yOldScrollPos = editor->vert_si.nPos;
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
x = ME_GetXForArrow(editor, pCursor);
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
p = ME_FindItemBack(pRun, diStartRowOrParagraph);
|
|
|
|
assert(p->type == diStartRow);
|
|
|
|
yp = ME_FindItemBack(p, diParagraph)->member.para.pt.y;
|
2010-05-14 22:04:32 +02:00
|
|
|
y = yp + p->member.row.pt.y;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
ME_ScrollUp(editor, editor->sizeWindow.cy);
|
|
|
|
/* Only move the cursor by the amount scrolled. */
|
|
|
|
yd = y + editor->vert_si.nPos - yOldScrollPos;
|
|
|
|
pLast = p;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
do {
|
|
|
|
p = ME_FindItemBack(p, diStartRowOrParagraph);
|
|
|
|
if (!p)
|
2005-03-21 11:27:24 +01:00
|
|
|
break;
|
2009-01-15 17:03:49 +01:00
|
|
|
if (p->type == diParagraph) { /* crossing paragraphs */
|
|
|
|
if (p->member.para.prev_para == NULL)
|
|
|
|
break;
|
|
|
|
yp = p->member.para.prev_para->member.para.pt.y;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
y = yp + p->member.row.pt.y;
|
|
|
|
if (y < yd)
|
|
|
|
break;
|
|
|
|
pLast = p;
|
|
|
|
} while(1);
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2020-10-26 09:46:38 +01:00
|
|
|
row_cursor( editor, &pLast->member.row, x, pCursor );
|
2005-03-21 11:27:24 +01:00
|
|
|
}
|
|
|
|
assert(pCursor->pRun);
|
|
|
|
assert(pCursor->pRun->type == diRun);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-01-15 17:03:49 +01:00
|
|
|
ME_DisplayItem *pLast;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* Find y position of the last row */
|
|
|
|
pLast = editor->pBuffer->pLast;
|
|
|
|
y = pLast->member.para.prev_para->member.para.pt.y
|
|
|
|
+ ME_FindItemBack(pLast, diStartRow)->member.row.pt.y;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2005-03-19 18:06:17 +01:00
|
|
|
x = ME_GetXForArrow(editor, pCursor);
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
if (editor->vert_si.nPos >= y - editor->sizeWindow.cy)
|
|
|
|
{
|
2016-10-04 14:07:32 +02:00
|
|
|
ME_SetCursorToEnd(editor, pCursor, FALSE);
|
2009-01-15 17:03:49 +01:00
|
|
|
} else {
|
|
|
|
ME_DisplayItem *pRun = pCursor->pRun;
|
|
|
|
ME_DisplayItem *p;
|
2010-05-07 21:32:26 +02:00
|
|
|
int yd, yp;
|
2009-01-15 17:03:49 +01:00
|
|
|
int yOldScrollPos = editor->vert_si.nPos;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
p = ME_FindItemBack(pRun, diStartRowOrParagraph);
|
|
|
|
assert(p->type == diStartRow);
|
|
|
|
yp = ME_FindItemBack(p, diParagraph)->member.para.pt.y;
|
2010-05-07 21:32:26 +02:00
|
|
|
y = yp + p->member.row.pt.y;
|
2009-01-15 17:03:49 +01:00
|
|
|
|
|
|
|
/* For native richedit controls:
|
|
|
|
* v1.0 - v3.1 can only scroll down as far as the scrollbar lets us
|
|
|
|
* v4.1 can scroll past this position here. */
|
|
|
|
ME_ScrollDown(editor, editor->sizeWindow.cy);
|
|
|
|
/* Only move the cursor by the amount scrolled. */
|
|
|
|
yd = y + editor->vert_si.nPos - yOldScrollPos;
|
2005-03-19 18:06:17 +01:00
|
|
|
pLast = p;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2009-01-15 17:03:49 +01:00
|
|
|
do {
|
|
|
|
p = ME_FindItemFwd(p, diStartRowOrParagraph);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
if (p->type == diParagraph) {
|
|
|
|
yp = p->member.para.pt.y;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
y = yp + p->member.row.pt.y;
|
|
|
|
if (y >= yd)
|
|
|
|
break;
|
|
|
|
pLast = p;
|
|
|
|
} while(1);
|
|
|
|
|
2020-10-26 09:46:38 +01:00
|
|
|
row_cursor( editor, &pLast->member.row, x, pCursor );
|
2005-03-19 18:06:17 +01:00
|
|
|
}
|
|
|
|
assert(pCursor->pRun);
|
|
|
|
assert(pCursor->pRun->type == diRun);
|
|
|
|
}
|
|
|
|
|
2020-10-26 09:46:41 +01:00
|
|
|
static void ME_ArrowHome( ME_TextEditor *editor, ME_Cursor *cursor )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-26 09:46:41 +01:00
|
|
|
ME_Row *row = row_from_cursor( cursor );
|
|
|
|
|
|
|
|
row_first_cursor( row, cursor );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-08-12 15:06:05 +02:00
|
|
|
ME_SetCursorToStart(editor, pCursor);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-26 09:46:41 +01:00
|
|
|
static void ME_ArrowEnd( ME_TextEditor *editor, ME_Cursor *cursor )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-26 09:46:41 +01:00
|
|
|
ME_Row *row = row_from_cursor( cursor );
|
2009-02-07 19:20:31 +01:00
|
|
|
|
2020-10-26 09:46:41 +01:00
|
|
|
row_end_cursor( row, cursor, FALSE );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2009-02-07 19:20:31 +01:00
|
|
|
|
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
|
|
|
{
|
2016-10-04 14:07:32 +02:00
|
|
|
ME_SetCursorToEnd(editor, pCursor, FALSE);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ME_IsSelection(ME_TextEditor *editor)
|
|
|
|
{
|
2009-08-07 07:56:50 +02:00
|
|
|
return editor->pCursors[0].pRun != editor->pCursors[1].pRun ||
|
|
|
|
editor->pCursors[0].nOffset != editor->pCursors[1].nOffset;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_DeleteSelection(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
int from, to;
|
2009-08-12 15:05:46 +02:00
|
|
|
int nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
|
2014-01-07 13:44:24 +01:00
|
|
|
int nEndCursor = nStartCursor ^ 1;
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_DeleteTextAtCursor(editor, nStartCursor, to - from);
|
2014-01-07 13:44:24 +01:00
|
|
|
editor->pCursors[nEndCursor] = editor->pCursors[nStartCursor];
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2005-03-08 20:03:01 +01:00
|
|
|
ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor)
|
|
|
|
{
|
2020-10-21 11:05:54 +02:00
|
|
|
return style_get_insert_style( editor, editor->pCursors );
|
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
|
|
|
|
2009-09-28 09:44:19 +02:00
|
|
|
sc.nmhdr.hwndFrom = NULL;
|
|
|
|
sc.nmhdr.idFrom = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
sc.nmhdr.code = EN_SELCHANGE;
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_GetSelectionOfs(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;
|
2009-08-12 15:05:46 +02:00
|
|
|
if (sc.chrg.cpMin < sc.chrg.cpMax+1) /* what were RICHEDIT authors thinking ? */
|
2005-03-05 12:19:14 +01:00
|
|
|
sc.seltyp |= SEL_MULTICHAR;
|
2016-10-04 14:07:36 +02:00
|
|
|
|
2008-04-27 20:08:55 +02:00
|
|
|
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;
|
2016-10-04 14:07:36 +02:00
|
|
|
|
|
|
|
if (editor->nEventMask & ENM_SELCHANGE)
|
|
|
|
{
|
|
|
|
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" : "");
|
|
|
|
ITextHost_TxNotify(editor->texthost, sc.nmhdr.code, &sc);
|
|
|
|
}
|
2008-04-27 20:08:55 +02:00
|
|
|
}
|
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;
|
2009-01-14 19:24:02 +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:
|
2006-01-12 11:54:57 +01:00
|
|
|
if (ctrl)
|
|
|
|
success = ME_MoveCursorWords(editor, &tmp_curs, -1);
|
|
|
|
else
|
2016-10-04 14:07:33 +02:00
|
|
|
success = ME_MoveCursorChars(editor, &tmp_curs, -1, extend);
|
2006-01-10 20:23:41 +01:00
|
|
|
break;
|
|
|
|
case VK_RIGHT:
|
2006-01-12 11:54:57 +01:00
|
|
|
if (ctrl)
|
|
|
|
success = ME_MoveCursorWords(editor, &tmp_curs, +1);
|
|
|
|
else
|
2016-10-04 14:07:33 +02:00
|
|
|
success = ME_MoveCursorChars(editor, &tmp_curs, +1, extend);
|
2006-01-10 20:23:41 +01:00
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case VK_UP:
|
2016-10-04 14:07:34 +02:00
|
|
|
ME_MoveCursorLines(editor, &tmp_curs, -1, extend);
|
2006-01-10 20:23:41 +01:00
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case VK_DOWN:
|
2016-10-04 14:07:34 +02:00
|
|
|
ME_MoveCursorLines(editor, &tmp_curs, +1, extend);
|
2006-01-10 20:23:41 +01:00
|
|
|
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);
|
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2009-01-14 19:24:02 +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
|
|
|
}
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
if (!extend)
|
|
|
|
editor->pCursors[1] = tmp_curs;
|
|
|
|
*p = tmp_curs;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_InvalidateSelection(editor);
|
|
|
|
ME_Repaint(editor);
|
2019-04-03 15:23:04 +02:00
|
|
|
hide_caret(editor);
|
2020-10-27 09:23:29 +01:00
|
|
|
editor_ensure_visible( editor, &tmp_curs );
|
2019-04-03 15:23:04 +02:00
|
|
|
update_caret(editor);
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_SendSelChange(editor);
|
|
|
|
return success;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|