2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - operations on runs (diRun, rectangular pieces of paragraphs).
|
|
|
|
* Splitting/joining runs. Adjusting offsets after deleting/adding content.
|
|
|
|
* Character/pixel conversions.
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
2006-02-04 17:01:01 +01:00
|
|
|
* Copyright 2006 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);
|
2005-10-08 12:33:44 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(richedit_check);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(richedit_lists);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-11-06 09:32:23 +01:00
|
|
|
BOOL cursor_next_run( ME_Cursor *cursor, BOOL all_para )
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
ME_DisplayItem *p = run_get_di( cursor->run )->next;
|
2020-11-06 09:32:23 +01:00
|
|
|
|
|
|
|
while (p->type != diTextEnd)
|
|
|
|
{
|
|
|
|
if (p->type == diParagraph && !all_para) return FALSE;
|
|
|
|
else if (p->type == diRun)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor->run = &p->member.run;
|
|
|
|
cursor->para = cursor->run->para;
|
2020-11-06 09:32:23 +01:00
|
|
|
cursor->nOffset = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL cursor_prev_run( ME_Cursor *cursor, BOOL all_para )
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
ME_DisplayItem *p = run_get_di( cursor->run )->prev;
|
2020-11-06 09:32:23 +01:00
|
|
|
|
|
|
|
while (p->type != diTextStart)
|
|
|
|
{
|
|
|
|
if (p->type == diParagraph && !all_para) return FALSE;
|
|
|
|
else if (p->type == diRun)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor->run = &p->member.run;
|
|
|
|
cursor->para = cursor->run->para;
|
2020-11-06 09:32:23 +01:00
|
|
|
cursor->nOffset = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
p = p->prev;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:45 +02:00
|
|
|
ME_Run *run_next( ME_Run *run )
|
|
|
|
{
|
2020-11-06 09:32:23 +01:00
|
|
|
ME_Cursor cursor;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor.run = run;
|
|
|
|
cursor.para = run->para;
|
2020-11-06 09:32:23 +01:00
|
|
|
cursor.nOffset = 0;
|
2020-10-08 12:10:45 +02:00
|
|
|
|
2020-11-06 09:32:23 +01:00
|
|
|
if (cursor_next_run( &cursor, FALSE ))
|
2020-11-06 09:32:24 +01:00
|
|
|
return cursor.run;
|
2020-10-08 12:10:45 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_Run *run_prev( ME_Run *run )
|
|
|
|
{
|
2020-11-06 09:32:23 +01:00
|
|
|
ME_Cursor cursor;
|
2020-10-08 12:10:45 +02:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor.run = run;
|
|
|
|
cursor.para = run->para;
|
2020-11-06 09:32:23 +01:00
|
|
|
cursor.nOffset = 0;
|
|
|
|
|
|
|
|
if (cursor_prev_run( &cursor, FALSE ))
|
2020-11-06 09:32:24 +01:00
|
|
|
return cursor.run;
|
2020-10-08 12:10:45 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-10-14 12:17:17 +02:00
|
|
|
ME_Run *run_next_all_paras( ME_Run *run )
|
|
|
|
{
|
2020-11-06 09:32:23 +01:00
|
|
|
ME_Cursor cursor;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor.run = run;
|
|
|
|
cursor.para = run->para;
|
2020-11-06 09:32:23 +01:00
|
|
|
cursor.nOffset = 0;
|
2020-10-14 12:17:17 +02:00
|
|
|
|
2020-11-06 09:32:23 +01:00
|
|
|
if (cursor_next_run( &cursor, TRUE ))
|
2020-11-06 09:32:24 +01:00
|
|
|
return cursor.run;
|
2020-10-14 12:17:17 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-10-14 12:17:18 +02:00
|
|
|
ME_Run *run_prev_all_paras( ME_Run *run )
|
|
|
|
{
|
2020-11-06 09:32:23 +01:00
|
|
|
ME_Cursor cursor;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor.run = run;
|
|
|
|
cursor.para = run->para;
|
2020-11-06 09:32:23 +01:00
|
|
|
cursor.nOffset = 0;
|
2020-10-14 12:17:18 +02:00
|
|
|
|
2020-11-06 09:32:23 +01:00
|
|
|
if (cursor_prev_run( &cursor, TRUE ))
|
2020-11-06 09:32:24 +01:00
|
|
|
return cursor.run;
|
2020-10-14 12:17:18 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_CanJoinRuns
|
|
|
|
*
|
2013-11-20 01:26:24 +01:00
|
|
|
* Returns TRUE if two runs can be safely merged into one, FALSE otherwise.
|
|
|
|
*/
|
|
|
|
BOOL ME_CanJoinRuns(const ME_Run *run1, const ME_Run *run2)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2005-04-16 12:48:35 +02:00
|
|
|
if ((run1->nFlags | run2->nFlags) & MERF_NOJOIN)
|
2013-11-20 01:26:24 +01:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
if (run1->style != run2->style)
|
2013-11-20 01:26:24 +01:00
|
|
|
return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
if ((run1->nFlags & MERF_STYLEFLAGS) != (run2->nFlags & MERF_STYLEFLAGS))
|
2013-11-20 01:26:24 +01:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2020-11-09 09:45:03 +01:00
|
|
|
* editor_propagate_char_ofs
|
2006-08-02 20:33:26 +02:00
|
|
|
*
|
|
|
|
* Shifts (increases or decreases) character offset (relative to beginning of
|
2020-11-09 09:45:03 +01:00
|
|
|
* the document) of the part of the text starting from given place.
|
|
|
|
* Call with only one of para or run non-NULL.
|
2006-08-02 20:33:26 +02:00
|
|
|
*/
|
2020-11-09 09:45:03 +01:00
|
|
|
void editor_propagate_char_ofs( ME_Paragraph *para, ME_Run *run, int shift )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-11-09 09:45:03 +01:00
|
|
|
assert( !para ^ !run );
|
|
|
|
|
|
|
|
if (run)
|
|
|
|
{
|
|
|
|
para = para_next( run->para );
|
|
|
|
do
|
|
|
|
{
|
|
|
|
run->nCharOfs += shift;
|
|
|
|
run = run_next( run );
|
|
|
|
} while (run);
|
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
para->nCharOfs += shift;
|
|
|
|
para = para_next( para );
|
|
|
|
} while (para);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_CheckCharOffsets
|
|
|
|
*
|
|
|
|
* Checks if editor lists' validity and optionally dumps the document structure
|
|
|
|
*/
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_CheckCharOffsets(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *p = editor->pBuffer->pFirst;
|
|
|
|
int ofs = 0, ofsp = 0;
|
2016-01-04 09:09:53 +01:00
|
|
|
|
2018-11-29 14:44:55 +01:00
|
|
|
if (!TRACE_ON(richedit_check))
|
|
|
|
return;
|
|
|
|
|
2016-01-04 09:09:53 +01:00
|
|
|
TRACE_(richedit_check)("Checking begin\n");
|
2005-10-08 12:33:44 +02:00
|
|
|
if(TRACE_ON(richedit_lists))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2005-10-08 12:33:44 +02:00
|
|
|
TRACE_(richedit_lists)("---\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_DumpDocument(editor->pBuffer);
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
p = ME_FindItemFwd(p, diRunOrParagraphOrEnd);
|
|
|
|
switch(p->type) {
|
|
|
|
case diTextEnd:
|
2005-10-08 12:33:44 +02:00
|
|
|
TRACE_(richedit_check)("tend, real ofsp = %d, counted = %d\n", p->member.para.nCharOfs, ofsp+ofs);
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(ofsp+ofs == p->member.para.nCharOfs);
|
2016-01-04 09:09:53 +01:00
|
|
|
TRACE_(richedit_check)("Checking finished\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
return;
|
|
|
|
case diParagraph:
|
2005-10-08 12:33:44 +02:00
|
|
|
TRACE_(richedit_check)("para, real ofsp = %d, counted = %d\n", p->member.para.nCharOfs, ofsp+ofs);
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(ofsp+ofs == p->member.para.nCharOfs);
|
|
|
|
ofsp = p->member.para.nCharOfs;
|
|
|
|
ofs = 0;
|
|
|
|
break;
|
|
|
|
case diRun:
|
2013-01-30 16:10:19 +01:00
|
|
|
TRACE_(richedit_check)("run, real ofs = %d (+ofsp = %d), counted = %d, len = %d, txt = %s, flags=%08x, fx&mask = %08x\n",
|
2005-04-16 12:48:35 +02:00
|
|
|
p->member.run.nCharOfs, p->member.run.nCharOfs+ofsp, ofsp+ofs,
|
2013-01-31 14:48:00 +01:00
|
|
|
p->member.run.len, debugstr_run( &p->member.run ),
|
2005-03-05 12:19:14 +01:00
|
|
|
p->member.run.nFlags,
|
|
|
|
p->member.run.style->fmt.dwMask & p->member.run.style->fmt.dwEffects);
|
|
|
|
assert(ofs == p->member.run.nCharOfs);
|
2013-01-31 14:48:00 +01:00
|
|
|
assert(p->member.run.len);
|
|
|
|
ofs += p->member.run.len;
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
2008-08-07 18:31:41 +02:00
|
|
|
case diCell:
|
|
|
|
TRACE_(richedit_check)("cell\n");
|
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
} while(1);
|
2016-01-04 09:09:53 +01:00
|
|
|
TRACE_(richedit_check)("Checking finished\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2020-10-15 11:39:39 +02:00
|
|
|
* run_char_ofs
|
2009-02-06 07:09:51 +01:00
|
|
|
*
|
2020-10-15 11:39:39 +02:00
|
|
|
* Converts a character position relative to the start of the run to a
|
2006-08-02 20:33:26 +02:00
|
|
|
* character position relative to the start of the document.
|
2009-02-06 07:09:51 +01:00
|
|
|
*/
|
2020-10-15 11:39:39 +02:00
|
|
|
|
|
|
|
int run_char_ofs( ME_Run *run, int ofs )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-15 11:39:39 +02:00
|
|
|
return run->para->nCharOfs + run->nCharOfs + ofs;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2020-10-15 11:39:38 +02:00
|
|
|
* cursor_from_char_ofs
|
2009-01-27 09:39:23 +01:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Converts a character offset (relative to the start of the document) to
|
2009-02-06 07:09:47 +01:00
|
|
|
* a cursor structure (which contains a run and a position relative to that
|
2009-01-27 09:39:23 +01:00
|
|
|
* run).
|
|
|
|
*/
|
2020-10-15 11:39:38 +02:00
|
|
|
void cursor_from_char_ofs( ME_TextEditor *editor, int char_ofs, ME_Cursor *cursor )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-15 11:39:38 +02:00
|
|
|
ME_Paragraph *para;
|
|
|
|
ME_Run *run;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-10-15 11:39:38 +02:00
|
|
|
char_ofs = min( max( char_ofs, 0 ), ME_GetTextLength( editor ) );
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-15 11:39:38 +02:00
|
|
|
/* Find the paragraph at the offset. */
|
|
|
|
for (para = editor_first_para( editor );
|
|
|
|
para_next( para )->nCharOfs <= char_ofs;
|
|
|
|
para = para_next( para ))
|
|
|
|
;
|
2009-01-27 09:39:23 +01:00
|
|
|
|
2020-10-15 11:39:38 +02:00
|
|
|
char_ofs -= para->nCharOfs;
|
|
|
|
|
|
|
|
/* Find the run at the offset. */
|
|
|
|
for (run = para_first_run( para );
|
|
|
|
run_next( run ) && run_next( run )->nCharOfs <= char_ofs;
|
|
|
|
run = run_next( run ))
|
|
|
|
;
|
|
|
|
|
|
|
|
char_ofs -= run->nCharOfs;
|
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor->para = para;
|
|
|
|
cursor->run = run;
|
2020-10-15 11:39:38 +02:00
|
|
|
cursor->nOffset = char_ofs;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2020-10-13 12:16:36 +02:00
|
|
|
* run_join
|
2006-08-02 20:33:26 +02:00
|
|
|
*
|
|
|
|
* Merges two adjacent runs, the one given as a parameter and the next one.
|
|
|
|
*/
|
2020-10-13 12:16:36 +02:00
|
|
|
void run_join( ME_TextEditor *editor, ME_Run *run )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-13 12:16:36 +02:00
|
|
|
ME_Run *next = run_next( run );
|
2005-03-05 12:19:14 +01:00
|
|
|
int i;
|
2020-10-13 12:16:36 +02:00
|
|
|
|
|
|
|
assert( run );
|
|
|
|
assert( run->nCharOfs != -1 );
|
|
|
|
para_mark_rewrap( editor, run->para );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2008-06-23 23:09:58 +02:00
|
|
|
/* Update all cursors so that they don't contain the soon deleted run */
|
2020-10-13 12:16:36 +02:00
|
|
|
for (i = 0; i < editor->nCursors; i++)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (editor->pCursors[i].run == next)
|
2020-10-13 12:16:36 +02:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
editor->pCursors[i].run = run;
|
2020-10-13 12:16:36 +02:00
|
|
|
editor->pCursors[i].nOffset += run->len;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-13 12:16:36 +02:00
|
|
|
run->len += next->len;
|
|
|
|
ME_Remove( run_get_di( next ) );
|
|
|
|
ME_DestroyDisplayItem( run_get_di( next ) );
|
|
|
|
ME_UpdateRunFlags( editor, run );
|
|
|
|
ME_CheckCharOffsets( editor );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2020-10-14 12:17:14 +02:00
|
|
|
* run_split
|
2010-07-29 20:07:40 +02:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Does the most basic job of splitting a run into two - it does not
|
2010-07-29 20:07:40 +02:00
|
|
|
* update the positions and extents.
|
|
|
|
*/
|
2020-10-14 12:17:14 +02:00
|
|
|
ME_Run *run_split( ME_TextEditor *editor, ME_Cursor *cursor )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
ME_Run *run = cursor->run, *new_run;
|
2020-10-13 12:16:37 +02:00
|
|
|
int i;
|
|
|
|
int nOffset = cursor->nOffset;
|
|
|
|
|
|
|
|
assert( !(run->nFlags & MERF_NONTEXT) );
|
|
|
|
|
|
|
|
new_run = run_create( run->style, run->nFlags & MERF_SPLITMASK );
|
|
|
|
new_run->nCharOfs = run->nCharOfs + nOffset;
|
|
|
|
new_run->len = run->len - nOffset;
|
|
|
|
new_run->para = run->para;
|
|
|
|
run->len = nOffset;
|
2020-11-06 09:32:24 +01:00
|
|
|
cursor->run = new_run;
|
2020-10-13 12:16:37 +02:00
|
|
|
cursor->nOffset = 0;
|
|
|
|
|
|
|
|
ME_InsertBefore( run_get_di( run )->next, run_get_di( new_run ) );
|
|
|
|
|
|
|
|
ME_UpdateRunFlags( editor, run );
|
|
|
|
ME_UpdateRunFlags( editor, new_run );
|
|
|
|
for (i = 0; i < editor->nCursors; i++)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (editor->pCursors[i].run == run &&
|
2020-10-13 12:16:37 +02:00
|
|
|
editor->pCursors[i].nOffset >= nOffset)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
editor->pCursors[i].run = new_run;
|
2020-10-13 12:16:37 +02:00
|
|
|
editor->pCursors[i].nOffset -= nOffset;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2020-10-13 12:16:37 +02:00
|
|
|
para_mark_rewrap( editor, run->para );
|
2020-10-14 12:17:14 +02:00
|
|
|
return run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2020-10-13 12:16:37 +02:00
|
|
|
* run_create
|
2006-08-02 20:33:26 +02:00
|
|
|
*
|
|
|
|
* A helper function to create run structures quickly.
|
|
|
|
*/
|
2020-10-13 12:16:37 +02:00
|
|
|
ME_Run *run_create( ME_Style *s, int flags )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-13 12:16:37 +02:00
|
|
|
ME_DisplayItem *item = ME_MakeDI( diRun );
|
|
|
|
ME_Run *run = &item->member.run;
|
|
|
|
|
|
|
|
if (!item) return NULL;
|
|
|
|
|
|
|
|
ME_AddRefStyle( s );
|
|
|
|
run->style = s;
|
|
|
|
run->reobj = NULL;
|
|
|
|
run->nFlags = flags;
|
|
|
|
run->nCharOfs = -1;
|
|
|
|
run->len = 0;
|
|
|
|
run->para = NULL;
|
|
|
|
run->num_glyphs = 0;
|
|
|
|
run->max_glyphs = 0;
|
|
|
|
run->glyphs = NULL;
|
|
|
|
run->vis_attrs = NULL;
|
|
|
|
run->advances = NULL;
|
|
|
|
run->offsets = NULL;
|
|
|
|
run->max_clusters = 0;
|
|
|
|
run->clusters = NULL;
|
|
|
|
return run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2020-10-14 12:17:18 +02:00
|
|
|
* run_insert
|
2009-02-09 18:01:35 +01:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Inserts a new run with given style, flags and content at a given position,
|
|
|
|
* which is passed as a cursor structure (which consists of a run and
|
2009-02-09 18:01:35 +01:00
|
|
|
* a run-relative character offset).
|
|
|
|
*/
|
2020-10-14 12:17:18 +02:00
|
|
|
ME_Run *run_insert( ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
|
|
|
|
const WCHAR *str, int len, int flags )
|
2006-01-10 12:10:49 +01:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
ME_Run *insert_before = cursor->run, *run, *prev;
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2010-07-29 20:07:40 +02:00
|
|
|
if (cursor->nOffset)
|
2014-01-07 13:44:22 +01:00
|
|
|
{
|
2020-10-14 12:17:18 +02:00
|
|
|
if (cursor->nOffset == insert_before->len)
|
2014-01-07 13:44:22 +01:00
|
|
|
{
|
2020-10-14 12:17:18 +02:00
|
|
|
insert_before = run_next_all_paras( insert_before );
|
2020-11-06 09:32:24 +01:00
|
|
|
if (!insert_before) insert_before = cursor->run; /* Always insert before the final eop run */
|
2014-01-07 13:44:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-14 12:17:14 +02:00
|
|
|
run_split( editor, cursor );
|
2020-11-06 09:32:24 +01:00
|
|
|
insert_before = cursor->run;
|
2014-01-07 13:44:22 +01:00
|
|
|
}
|
|
|
|
}
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2020-10-14 12:17:18 +02:00
|
|
|
add_undo_delete_run( editor, insert_before->para->nCharOfs + insert_before->nCharOfs, len );
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2020-10-13 12:16:37 +02:00
|
|
|
run = run_create( style, flags );
|
2020-10-14 12:17:18 +02:00
|
|
|
run->nCharOfs = insert_before->nCharOfs;
|
2020-10-13 12:16:37 +02:00
|
|
|
run->len = len;
|
2020-10-14 12:17:18 +02:00
|
|
|
run->para = insert_before->para;
|
2020-10-13 12:16:37 +02:00
|
|
|
ME_InsertString( run->para->text, run->nCharOfs, str, len );
|
2020-10-14 12:17:18 +02:00
|
|
|
ME_InsertBefore( run_get_di( insert_before ), run_get_di( run ) );
|
2006-01-10 12:10:49 +01:00
|
|
|
TRACE("Shift length:%d\n", len);
|
2020-11-09 09:45:03 +01:00
|
|
|
editor_propagate_char_ofs( NULL, insert_before, len );
|
2020-10-14 12:17:18 +02:00
|
|
|
para_mark_rewrap( editor, insert_before->para );
|
2014-01-07 13:44:22 +01:00
|
|
|
|
|
|
|
/* Move any cursors that were at the end of the previous run to the end of the inserted run */
|
2020-10-14 12:17:18 +02:00
|
|
|
prev = run_prev_all_paras( run );
|
2014-01-07 13:44:22 +01:00
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < editor->nCursors; i++)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (editor->pCursors[i].run == prev &&
|
2020-10-14 12:17:18 +02:00
|
|
|
editor->pCursors[i].nOffset == prev->len)
|
2014-01-07 13:44:22 +01:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
editor->pCursors[i].run = run;
|
2014-01-07 13:44:22 +01:00
|
|
|
editor->pCursors[i].nOffset = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 12:17:18 +02:00
|
|
|
return run;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2013-01-31 14:47:57 +01:00
|
|
|
static BOOL run_is_splittable( const ME_Run *run )
|
|
|
|
{
|
|
|
|
WCHAR *str = get_text( run, 0 ), *p;
|
2013-01-31 14:48:00 +01:00
|
|
|
int i;
|
2013-01-31 14:47:57 +01:00
|
|
|
BOOL found_ink = FALSE;
|
|
|
|
|
2013-01-31 14:48:00 +01:00
|
|
|
for (i = 0, p = str; i < run->len; i++, p++)
|
2013-01-31 14:47:57 +01:00
|
|
|
{
|
|
|
|
if (ME_IsWSpace( *p ))
|
|
|
|
{
|
|
|
|
if (found_ink) return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
found_ink = TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-31 14:47:58 +01:00
|
|
|
static BOOL run_is_entirely_ws( const ME_Run *run )
|
|
|
|
{
|
|
|
|
WCHAR *str = get_text( run, 0 ), *p;
|
2013-01-31 14:48:00 +01:00
|
|
|
int i;
|
2013-01-31 14:47:58 +01:00
|
|
|
|
2013-01-31 14:48:00 +01:00
|
|
|
for (i = 0, p = str; i < run->len; i++, p++)
|
2013-01-31 14:47:58 +01:00
|
|
|
if (!ME_IsWSpace( *p )) return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_UpdateRunFlags
|
2009-02-07 19:21:23 +01:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Determine some of run attributes given its content (style, text content).
|
2009-02-07 19:21:23 +01:00
|
|
|
* Some flags cannot be determined by this function (MERF_GRAPHICS,
|
|
|
|
* MERF_ENDPARA)
|
|
|
|
*/
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run)
|
|
|
|
{
|
2009-02-07 19:21:23 +01:00
|
|
|
assert(run->nCharOfs >= 0);
|
2006-01-31 13:01:26 +01:00
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
if (RUN_IS_HIDDEN(run) || run->nFlags & MERF_TABLESTART)
|
2006-01-31 13:01:26 +01:00
|
|
|
run->nFlags |= MERF_HIDDEN;
|
|
|
|
else
|
|
|
|
run->nFlags &= ~MERF_HIDDEN;
|
|
|
|
|
2013-01-31 14:47:57 +01:00
|
|
|
if (run_is_splittable( run ))
|
2005-03-05 12:19:14 +01:00
|
|
|
run->nFlags |= MERF_SPLITTABLE;
|
|
|
|
else
|
|
|
|
run->nFlags &= ~MERF_SPLITTABLE;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2013-01-31 14:47:58 +01:00
|
|
|
if (!(run->nFlags & MERF_NOTEXT))
|
|
|
|
{
|
|
|
|
if (run_is_entirely_ws( run ))
|
2005-03-05 12:19:14 +01:00
|
|
|
run->nFlags |= MERF_WHITESPACE | MERF_STARTWHITE | MERF_ENDWHITE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
run->nFlags &= ~MERF_WHITESPACE;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2013-01-31 14:47:59 +01:00
|
|
|
if (ME_IsWSpace( *get_text( run, 0 ) ))
|
2005-03-05 12:19:14 +01:00
|
|
|
run->nFlags |= MERF_STARTWHITE;
|
|
|
|
else
|
|
|
|
run->nFlags &= ~MERF_STARTWHITE;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2013-01-31 14:48:00 +01:00
|
|
|
if (ME_IsWSpace( *get_text( run, run->len - 1 ) ))
|
2005-03-05 12:19:14 +01:00
|
|
|
run->nFlags |= MERF_ENDWHITE;
|
|
|
|
else
|
|
|
|
run->nFlags &= ~MERF_ENDWHITE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
run->nFlags &= ~(MERF_WHITESPACE | MERF_STARTWHITE | MERF_ENDWHITE);
|
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2013-02-18 14:43:48 +01:00
|
|
|
* ME_CharFromPointContext
|
2009-02-07 19:21:29 +01:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Returns a character position inside the run given a run-relative
|
2013-02-18 14:43:48 +01:00
|
|
|
* pixel horizontal position.
|
2009-02-07 19:21:29 +01:00
|
|
|
*
|
2013-02-18 14:43:48 +01:00
|
|
|
* If closest is FALSE return the actual character
|
|
|
|
* If closest is TRUE will round to the closest leading edge.
|
|
|
|
* ie. if the second character is at pixel position 8 and third at 16 then for:
|
|
|
|
* closest = FALSE cx = 0..7 return 0, cx = 8..15 return 1
|
|
|
|
* closest = TRUE cx = 0..3 return 0, cx = 4..11 return 1.
|
2009-02-07 19:21:29 +01:00
|
|
|
*/
|
2013-04-17 13:56:37 +02:00
|
|
|
int ME_CharFromPointContext(ME_Context *c, int cx, ME_Run *run, BOOL closest, BOOL visual_order)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2013-01-30 16:10:20 +01:00
|
|
|
ME_String *mask_text = NULL;
|
|
|
|
WCHAR *str;
|
2013-01-31 14:48:00 +01:00
|
|
|
int fit = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
SIZE sz, sz2, sz3;
|
2013-01-31 14:48:00 +01:00
|
|
|
if (!run->len || cx <= 0)
|
2005-03-05 12:19:14 +01:00
|
|
|
return 0;
|
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
if (run->nFlags & (MERF_TAB | MERF_ENDCELL))
|
2005-04-16 12:48:35 +02:00
|
|
|
{
|
2013-02-18 14:43:48 +01:00
|
|
|
if (!closest || cx < run->nWidth / 2) return 0;
|
2005-04-16 12:48:35 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2013-02-18 14:43:48 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (run->nFlags & MERF_GRAPHICS)
|
|
|
|
{
|
|
|
|
SIZE sz;
|
2013-02-18 14:43:48 +01:00
|
|
|
ME_GetOLEObjectSize(c, run, &sz);
|
|
|
|
if (!closest || cx < sz.cx / 2) return 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2008-01-27 19:02:34 +01:00
|
|
|
|
2014-01-15 14:06:43 +01:00
|
|
|
if (run->para->nFlags & MEPF_COMPLEX)
|
|
|
|
{
|
|
|
|
int cp, trailing;
|
|
|
|
if (visual_order && run->script_analysis.fRTL) cx = run->nWidth - cx - 1;
|
|
|
|
|
|
|
|
ScriptXtoCP( cx, run->len, run->num_glyphs, run->clusters, run->vis_attrs, run->advances, &run->script_analysis,
|
|
|
|
&cp, &trailing );
|
|
|
|
TRACE("x %d cp %d trailing %d (run width %d) rtl %d log order %d\n", cx, cp, trailing, run->nWidth,
|
|
|
|
run->script_analysis.fRTL, run->script_analysis.fLogicalOrder);
|
|
|
|
return closest ? cp + trailing : cp;
|
|
|
|
}
|
|
|
|
|
2021-03-18 09:30:07 +01:00
|
|
|
if (c->editor->password_char)
|
2013-01-30 16:10:20 +01:00
|
|
|
{
|
2021-03-18 09:30:07 +01:00
|
|
|
mask_text = ME_MakeStringR( c->editor->password_char, run->len );
|
2013-01-30 16:10:20 +01:00
|
|
|
str = mask_text->szData;
|
|
|
|
}
|
2006-08-04 21:47:44 +02:00
|
|
|
else
|
2013-01-30 16:10:20 +01:00
|
|
|
str = get_text( run, 0 );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2019-08-19 11:55:28 +02:00
|
|
|
select_style(c, run->style);
|
2013-02-18 14:43:48 +01:00
|
|
|
GetTextExtentExPointW(c->hDC, str, run->len,
|
2008-01-01 22:05:33 +01:00
|
|
|
cx, &fit, NULL, &sz);
|
2013-02-18 14:43:48 +01:00
|
|
|
if (closest && fit != run->len)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2013-02-18 14:43:48 +01:00
|
|
|
GetTextExtentPoint32W(c->hDC, str, fit, &sz2);
|
|
|
|
GetTextExtentPoint32W(c->hDC, str, fit + 1, &sz3);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (cx >= (sz2.cx+sz3.cx)/2)
|
2009-02-07 19:21:29 +01:00
|
|
|
fit = fit + 1;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2009-02-07 19:21:29 +01:00
|
|
|
|
2013-01-30 16:10:20 +01:00
|
|
|
ME_DestroyString( mask_text );
|
2009-02-07 19:21:29 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
return fit;
|
|
|
|
}
|
|
|
|
|
2013-04-17 13:56:37 +02:00
|
|
|
int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run, BOOL closest, BOOL visual_order)
|
2013-02-18 14:43:48 +01:00
|
|
|
{
|
|
|
|
ME_Context c;
|
|
|
|
int ret;
|
2021-03-23 14:04:03 +01:00
|
|
|
HDC hdc = ITextHost_TxGetDC( editor->texthost );
|
2013-02-18 14:43:48 +01:00
|
|
|
|
2021-03-23 14:04:03 +01:00
|
|
|
ME_InitContext( &c, editor, hdc );
|
2013-04-17 13:56:37 +02:00
|
|
|
ret = ME_CharFromPointContext( &c, cx, run, closest, visual_order );
|
2013-02-18 14:43:48 +01:00
|
|
|
ME_DestroyContext(&c);
|
2021-03-23 14:04:03 +01:00
|
|
|
ITextHost_TxReleaseDC( editor->texthost, hdc );
|
2013-02-18 14:43:48 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-01 22:05:33 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_GetTextExtent
|
|
|
|
*
|
|
|
|
* Finds a width and a height of the text using a specified style
|
|
|
|
*/
|
|
|
|
static void ME_GetTextExtent(ME_Context *c, LPCWSTR szText, int nChars, ME_Style *s, SIZE *size)
|
|
|
|
{
|
2019-08-19 11:55:28 +02:00
|
|
|
if (c->hDC)
|
|
|
|
{
|
|
|
|
select_style( c, s );
|
|
|
|
GetTextExtentPoint32W( c->hDC, szText, nChars, size );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size->cx = 0;
|
|
|
|
size->cy = 0;
|
|
|
|
}
|
2008-01-01 22:05:33 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
2013-02-14 15:16:20 +01:00
|
|
|
* ME_PointFromCharContext
|
2009-02-09 18:01:35 +01:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Returns a run-relative pixel position given a run-relative character
|
|
|
|
* position (character offset)
|
2009-02-09 18:01:35 +01:00
|
|
|
*/
|
2013-04-17 13:56:37 +02:00
|
|
|
int ME_PointFromCharContext(ME_Context *c, ME_Run *pRun, int nOffset, BOOL visual_order)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
SIZE size;
|
2013-01-30 16:10:20 +01:00
|
|
|
ME_String *mask_text = NULL;
|
|
|
|
WCHAR *str;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (pRun->nFlags & MERF_GRAPHICS)
|
|
|
|
{
|
2008-01-27 19:02:34 +01:00
|
|
|
if (nOffset)
|
2013-02-14 15:16:20 +01:00
|
|
|
ME_GetOLEObjectSize(c, pRun, &size);
|
2008-01-27 19:02:34 +01:00
|
|
|
return nOffset != 0;
|
2009-01-27 09:39:23 +01:00
|
|
|
} else if (pRun->nFlags & MERF_ENDPARA) {
|
|
|
|
nOffset = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2009-01-27 09:39:23 +01:00
|
|
|
|
2014-01-15 14:06:43 +01:00
|
|
|
if (pRun->para->nFlags & MEPF_COMPLEX)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
ScriptCPtoX( nOffset, FALSE, pRun->len, pRun->num_glyphs, pRun->clusters,
|
|
|
|
pRun->vis_attrs, pRun->advances, &pRun->script_analysis, &x );
|
|
|
|
if (visual_order && pRun->script_analysis.fRTL) x = pRun->nWidth - x - 1;
|
|
|
|
return x;
|
|
|
|
}
|
2021-03-18 09:30:07 +01:00
|
|
|
if (c->editor->password_char)
|
2013-01-30 16:10:20 +01:00
|
|
|
{
|
2021-03-18 09:30:07 +01:00
|
|
|
mask_text = ME_MakeStringR( c->editor->password_char, pRun->len );
|
2013-01-30 16:10:20 +01:00
|
|
|
str = mask_text->szData;
|
|
|
|
}
|
2006-08-04 21:47:44 +02:00
|
|
|
else
|
2013-01-30 16:10:20 +01:00
|
|
|
str = get_text( pRun, 0 );
|
2008-01-27 19:02:34 +01:00
|
|
|
|
2013-02-14 15:16:20 +01:00
|
|
|
ME_GetTextExtent(c, str, nOffset, pRun->style, &size);
|
2013-01-30 16:10:20 +01:00
|
|
|
ME_DestroyString( mask_text );
|
2005-03-05 12:19:14 +01:00
|
|
|
return size.cx;
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:16:20 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_PointFromChar
|
|
|
|
*
|
|
|
|
* Calls ME_PointFromCharContext after first creating a context.
|
|
|
|
*/
|
2013-04-17 13:56:37 +02:00
|
|
|
int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset, BOOL visual_order)
|
2013-02-14 15:16:20 +01:00
|
|
|
{
|
|
|
|
ME_Context c;
|
|
|
|
int ret;
|
2021-03-23 14:04:03 +01:00
|
|
|
HDC hdc = ITextHost_TxGetDC( editor->texthost );
|
2013-02-14 15:16:20 +01:00
|
|
|
|
2021-03-23 14:04:03 +01:00
|
|
|
ME_InitContext( &c, editor, hdc );
|
2013-04-17 13:56:37 +02:00
|
|
|
ret = ME_PointFromCharContext( &c, pRun, nOffset, visual_order );
|
2013-02-14 15:16:20 +01:00
|
|
|
ME_DestroyContext(&c);
|
2021-03-23 14:04:03 +01:00
|
|
|
ITextHost_TxReleaseDC( editor->texthost, hdc );
|
2013-02-14 15:16:20 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_GetRunSizeCommon
|
|
|
|
*
|
2007-01-23 22:00:27 +01:00
|
|
|
* Finds width, height, ascent and descent of a run, up to given character
|
|
|
|
* (nLen).
|
|
|
|
*/
|
2013-02-12 16:48:14 +01:00
|
|
|
SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen,
|
|
|
|
int startx, int *pAscent, int *pDescent)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
SIZE size;
|
|
|
|
|
2016-10-04 14:07:31 +02:00
|
|
|
nLen = min( nLen, run->len );
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2016-10-04 14:07:31 +02:00
|
|
|
if (run->nFlags & MERF_ENDPARA)
|
|
|
|
{
|
|
|
|
nLen = min( nLen, 1 );
|
2020-11-15 23:11:14 +01:00
|
|
|
ME_GetTextExtent( c, L" ", nLen, run->style, &size );
|
2016-10-04 14:07:31 +02:00
|
|
|
}
|
|
|
|
else if (para->nFlags & MEPF_COMPLEX)
|
2014-01-15 14:06:43 +01:00
|
|
|
{
|
|
|
|
size.cx = run->nWidth;
|
|
|
|
}
|
2021-03-18 09:30:07 +01:00
|
|
|
else if (c->editor->password_char)
|
2006-08-04 21:47:44 +02:00
|
|
|
{
|
2021-03-18 09:30:07 +01:00
|
|
|
ME_String *szMasked = ME_MakeStringR( c->editor->password_char, nLen );
|
2006-08-04 21:47:44 +02:00
|
|
|
ME_GetTextExtent(c, szMasked->szData, nLen,run->style, &size);
|
|
|
|
ME_DestroyString(szMasked);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-30 16:10:20 +01:00
|
|
|
ME_GetTextExtent(c, get_text( run, 0 ), nLen, run->style, &size);
|
2006-08-04 21:47:44 +02:00
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
*pAscent = run->style->tm.tmAscent;
|
|
|
|
*pDescent = run->style->tm.tmDescent;
|
|
|
|
size.cy = *pAscent + *pDescent;
|
|
|
|
|
|
|
|
if (run->nFlags & MERF_TAB)
|
|
|
|
{
|
2008-08-13 05:15:29 +02:00
|
|
|
int pos = 0, i = 0, ppos, shift = 0;
|
2016-09-29 11:13:11 +02:00
|
|
|
const PARAFORMAT2 *pFmt = ¶->fmt;
|
2008-03-16 21:47:08 +01:00
|
|
|
|
2008-08-13 05:15:29 +02:00
|
|
|
if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
|
|
pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
|
|
|
|
/* The horizontal gap shifts the tab positions to leave the gap. */
|
|
|
|
shift = pFmt->dxOffset * 2;
|
2005-04-16 12:48:35 +02:00
|
|
|
do {
|
|
|
|
if (i < pFmt->cTabCount)
|
|
|
|
{
|
2008-08-13 05:15:29 +02:00
|
|
|
/* Only one side of the horizontal gap is needed at the end of
|
|
|
|
* the table row. */
|
|
|
|
if (i == pFmt->cTabCount -1)
|
|
|
|
shift = shift >> 1;
|
|
|
|
pos = shift + (pFmt->rgxTabs[i]&0x00FFFFFF);
|
2005-04-16 12:48:35 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-27 15:18:50 +02:00
|
|
|
pos += lDefaultTab - (pos % lDefaultTab);
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2008-12-18 07:56:49 +01:00
|
|
|
ppos = ME_twips2pointsX(c, pos);
|
2008-03-16 21:47:08 +01:00
|
|
|
if (ppos > startx + run->pt.x) {
|
|
|
|
size.cx = ppos - startx - run->pt.x;
|
2005-04-16 12:48:35 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(1);
|
|
|
|
size.cy = *pAscent + *pDescent;
|
|
|
|
return size;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
if (run->nFlags & MERF_GRAPHICS)
|
|
|
|
{
|
2008-01-27 19:02:34 +01:00
|
|
|
ME_GetOLEObjectSize(c, run, &size);
|
2005-04-16 12:48:35 +02:00
|
|
|
if (size.cy > *pAscent)
|
|
|
|
*pAscent = size.cy;
|
|
|
|
/* descent is unchanged */
|
2005-03-05 12:19:14 +01:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_SetSelectionCharFormat
|
2009-08-12 15:06:13 +02:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Applies a style change, either to a current selection, or to insert cursor
|
|
|
|
* (ie. the style next typed characters will use).
|
2009-08-12 15:06:13 +02:00
|
|
|
*/
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
|
|
|
|
{
|
2009-08-12 15:06:13 +02:00
|
|
|
if (!ME_IsSelection(editor))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_Style *s;
|
|
|
|
if (!editor->pBuffer->pCharStyle)
|
2020-10-21 11:05:54 +02:00
|
|
|
editor->pBuffer->pCharStyle = style_get_insert_style( editor, editor->pCursors );
|
2015-11-09 17:11:43 +01:00
|
|
|
s = ME_ApplyStyle(editor, editor->pBuffer->pCharStyle, pFmt);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_ReleaseStyle(editor->pBuffer->pCharStyle);
|
|
|
|
editor->pBuffer->pCharStyle = s;
|
2009-08-12 15:06:13 +02:00
|
|
|
} else {
|
|
|
|
ME_Cursor *from, *to;
|
|
|
|
ME_GetSelection(editor, &from, &to);
|
|
|
|
ME_SetCharFormat(editor, from, to, pFmt);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_SetCharFormat
|
2009-08-12 15:06:13 +02:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Applies a style change to the specified part of the text
|
2009-08-12 15:06:13 +02:00
|
|
|
*
|
|
|
|
* The start and end cursors specify the part of the text. These cursors will
|
|
|
|
* be updated to stay valid, but this function may invalidate other
|
|
|
|
* non-selection cursors. The end cursor may be NULL to specify all the text
|
|
|
|
* following the start cursor.
|
|
|
|
*
|
|
|
|
* If no text is selected, then nothing is done.
|
|
|
|
*/
|
2020-10-14 12:17:17 +02:00
|
|
|
void ME_SetCharFormat( ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, CHARFORMAT2W *fmt )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
ME_Run *run, *start_run = start->run, *end_run = NULL;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
if (end && start->run == end->run && start->nOffset == end->nOffset)
|
2009-08-12 15:06:13 +02:00
|
|
|
return;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
if (start->nOffset == start->run->len)
|
|
|
|
start_run = run_next_all_paras( start->run );
|
2014-01-07 13:44:21 +01:00
|
|
|
else if (start->nOffset)
|
2009-08-12 15:06:13 +02:00
|
|
|
{
|
2020-10-14 12:17:14 +02:00
|
|
|
/* run_split() may or may not update the cursors, depending on whether they
|
2009-08-12 15:06:13 +02:00
|
|
|
* are selection cursors, but we need to make sure they are valid. */
|
|
|
|
int split_offset = start->nOffset;
|
2020-10-14 12:17:14 +02:00
|
|
|
ME_Run *split_run = run_split( editor, start );
|
2020-11-06 09:32:24 +01:00
|
|
|
start_run = start->run;
|
|
|
|
if (end && end->run == split_run)
|
2009-08-12 15:06:13 +02:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
end->run = start->run;
|
2009-08-12 15:06:13 +02:00
|
|
|
end->nOffset -= split_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-07 13:44:21 +01:00
|
|
|
if (end)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (end->nOffset == end->run->len)
|
|
|
|
end_run = run_next_all_paras( end->run );
|
2014-01-07 13:44:21 +01:00
|
|
|
else
|
|
|
|
{
|
2020-10-14 12:17:14 +02:00
|
|
|
if (end->nOffset) run_split( editor, end );
|
2020-11-06 09:32:24 +01:00
|
|
|
end_run = end->run;
|
2014-01-07 13:44:21 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-10-14 12:17:17 +02:00
|
|
|
for (run = start_run; run != end_run; run = run_next_all_paras( run ))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-14 12:17:17 +02:00
|
|
|
ME_Style *new_style = ME_ApplyStyle( editor, run->style, fmt );
|
|
|
|
ME_Paragraph *para = run->para;
|
2013-01-29 14:41:48 +01:00
|
|
|
|
2020-10-14 12:17:17 +02:00
|
|
|
add_undo_set_char_fmt( editor, para->nCharOfs + run->nCharOfs,
|
|
|
|
run->len, &run->style->fmt );
|
|
|
|
ME_ReleaseStyle( run->style );
|
|
|
|
run->style = new_style;
|
2016-10-07 11:49:36 +02:00
|
|
|
|
|
|
|
/* The para numbering style depends on the eop style */
|
2020-10-14 12:17:17 +02:00
|
|
|
if ((run->nFlags & MERF_ENDPARA) && para->para_num.style)
|
2016-10-07 11:49:36 +02:00
|
|
|
{
|
|
|
|
ME_ReleaseStyle(para->para_num.style);
|
|
|
|
para->para_num.style = NULL;
|
|
|
|
}
|
2020-10-09 13:59:18 +02:00
|
|
|
para_mark_rewrap( editor, para );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-15 11:39:37 +02:00
|
|
|
static void run_copy_char_fmt( ME_Run *run, CHARFORMAT2W *fmt )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-15 11:39:37 +02:00
|
|
|
ME_CopyCharFormat( fmt, &run->style->fmt );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_GetDefaultCharFormat
|
|
|
|
*
|
|
|
|
* Retrieves the current default character style (the one applied where no
|
|
|
|
* other style was applied) .
|
|
|
|
*/
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_GetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
|
|
|
|
{
|
|
|
|
ME_CopyCharFormat(pFmt, &editor->pBuffer->pDefaultStyle->fmt);
|
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_GetSelectionCharFormat
|
2009-08-12 15:06:09 +02:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* If selection exists, it returns all style elements that are set consistently
|
2009-08-12 15:06:09 +02:00
|
|
|
* in the whole selection. If not, it just returns the current style.
|
|
|
|
*/
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_GetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt)
|
|
|
|
{
|
2009-08-12 15:06:09 +02:00
|
|
|
ME_Cursor *from, *to;
|
|
|
|
if (!ME_IsSelection(editor) && editor->pBuffer->pCharStyle)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_CopyCharFormat(pFmt, &editor->pBuffer->pCharStyle->fmt);
|
|
|
|
return;
|
|
|
|
}
|
2009-08-12 15:06:09 +02:00
|
|
|
ME_GetSelection(editor, &from, &to);
|
|
|
|
ME_GetCharFormat(editor, from, to, pFmt);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2006-08-02 20:33:26 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* ME_GetCharFormat
|
2009-02-06 07:09:47 +01:00
|
|
|
*
|
2006-08-02 20:33:26 +02:00
|
|
|
* Returns the style consisting of those attributes which are consistently set
|
2009-02-06 07:09:47 +01:00
|
|
|
* in the whole character range.
|
|
|
|
*/
|
2020-10-15 11:39:37 +02:00
|
|
|
void ME_GetCharFormat( ME_TextEditor *editor, const ME_Cursor *from,
|
|
|
|
const ME_Cursor *to, CHARFORMAT2W *fmt )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-15 11:39:37 +02:00
|
|
|
ME_Run *run, *run_end, *prev_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
CHARFORMAT2W tmp;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
run = from->run;
|
2009-08-12 15:06:09 +02:00
|
|
|
/* special case - if selection is empty, take previous char's formatting */
|
2020-11-06 09:32:24 +01:00
|
|
|
if (from->run == to->run && from->nOffset == to->nOffset)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-15 11:39:37 +02:00
|
|
|
if (!from->nOffset && (prev_run = run_prev( run ))) run = prev_run;
|
|
|
|
run_copy_char_fmt( run, fmt );
|
2005-03-05 12:19:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2009-08-12 15:06:09 +02:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
run_end = to->run;
|
2020-10-15 11:39:37 +02:00
|
|
|
if (!to->nOffset) run_end = run_prev_all_paras( run_end );
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-15 11:39:37 +02:00
|
|
|
run_copy_char_fmt( run, fmt );
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (run == run_end) return;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
do {
|
|
|
|
/* FIXME add more style feature comparisons */
|
2011-07-31 22:13:13 +02:00
|
|
|
DWORD dwAttribs = CFM_SIZE | CFM_FACE | CFM_COLOR | CFM_UNDERLINETYPE;
|
|
|
|
DWORD dwEffects = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_LINK | CFM_SUPERSCRIPT;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-10-15 11:39:37 +02:00
|
|
|
run = run_next_all_paras( run );
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-15 11:39:37 +02:00
|
|
|
memset( &tmp, 0, sizeof(tmp) );
|
2005-03-05 12:19:14 +01:00
|
|
|
tmp.cbSize = sizeof(tmp);
|
2020-10-15 11:39:37 +02:00
|
|
|
run_copy_char_fmt( run, &tmp );
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2011-07-31 22:13:13 +02:00
|
|
|
assert((tmp.dwMask & dwAttribs) == dwAttribs);
|
2005-03-05 12:19:14 +01:00
|
|
|
/* reset flags that differ */
|
|
|
|
|
2020-10-15 11:39:37 +02:00
|
|
|
if (fmt->yHeight != tmp.yHeight) fmt->dwMask &= ~CFM_SIZE;
|
|
|
|
if (fmt->dwMask & CFM_FACE)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
if (!(tmp.dwMask & CFM_FACE))
|
2020-10-15 11:39:37 +02:00
|
|
|
fmt->dwMask &= ~CFM_FACE;
|
|
|
|
else if (wcscmp( fmt->szFaceName, tmp.szFaceName ) ||
|
|
|
|
fmt->bPitchAndFamily != tmp.bPitchAndFamily)
|
|
|
|
fmt->dwMask &= ~CFM_FACE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2020-10-15 11:39:37 +02:00
|
|
|
if (fmt->yHeight != tmp.yHeight) fmt->dwMask &= ~CFM_SIZE;
|
|
|
|
if (fmt->bUnderlineType != tmp.bUnderlineType) fmt->dwMask &= ~CFM_UNDERLINETYPE;
|
|
|
|
if (fmt->dwMask & CFM_COLOR)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-15 11:39:37 +02:00
|
|
|
if (!((fmt->dwEffects&CFE_AUTOCOLOR) & (tmp.dwEffects&CFE_AUTOCOLOR)))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-15 11:39:37 +02:00
|
|
|
if (fmt->crTextColor != tmp.crTextColor)
|
|
|
|
fmt->dwMask &= ~CFM_COLOR;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2020-10-15 11:39:37 +02:00
|
|
|
fmt->dwMask &= ~((fmt->dwEffects ^ tmp.dwEffects) & dwEffects);
|
|
|
|
fmt->dwEffects = tmp.dwEffects;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
} while(run != run_end);
|
|
|
|
}
|