2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - functions working on paragraphs of text (diParagraph).
|
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
|
2020-10-09 13:59:18 +02:00
|
|
|
void para_mark_rewrap( ME_TextEditor *editor, ME_Paragraph *para )
|
2018-11-29 14:44:51 +01:00
|
|
|
{
|
2020-10-09 13:59:18 +02:00
|
|
|
para->nFlags |= MEPF_REWRAP;
|
|
|
|
para_mark_add( editor, para );
|
2018-11-29 14:44:51 +01:00
|
|
|
}
|
|
|
|
|
2020-10-16 13:08:07 +02:00
|
|
|
static ME_Paragraph *para_create( ME_TextEditor *editor )
|
2015-11-06 10:34:37 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *item = ME_MakeDI(diParagraph);
|
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
editor_set_default_para_fmt( editor, &item->member.para.fmt );
|
2015-11-06 10:34:37 +01:00
|
|
|
item->member.para.nFlags = MEPF_REWRAP;
|
2018-11-29 14:44:53 +01:00
|
|
|
|
2020-10-16 13:08:07 +02:00
|
|
|
return &item->member.para;
|
2015-11-06 10:34:37 +01:00
|
|
|
}
|
|
|
|
|
2020-10-19 13:21:16 +02:00
|
|
|
void para_destroy( ME_TextEditor *editor, ME_Paragraph *para )
|
2018-11-29 14:44:48 +01:00
|
|
|
{
|
2020-10-19 13:21:16 +02:00
|
|
|
if (para->nWidth == editor->nTotalWidth)
|
2018-11-29 14:44:49 +01:00
|
|
|
{
|
2020-10-19 13:21:16 +02:00
|
|
|
para->nWidth = 0;
|
2018-11-29 14:44:49 +01:00
|
|
|
editor->nTotalWidth = get_total_width(editor);
|
|
|
|
}
|
2020-10-19 13:21:16 +02:00
|
|
|
editor->total_rows -= para->nRows;
|
|
|
|
ME_DestroyString( para->text );
|
|
|
|
para_num_clear( ¶->para_num );
|
|
|
|
para_mark_remove( editor, para );
|
|
|
|
ME_DestroyDisplayItem( para_get_di( para ) );
|
2018-11-29 14:44:48 +01:00
|
|
|
}
|
|
|
|
|
2020-10-09 13:59:22 +02:00
|
|
|
/* Note para_next/prev will return the start and end doc nodes */
|
|
|
|
ME_Paragraph *para_next( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
if (para->next_para) return ¶->next_para->member.para;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_Paragraph *para_prev( ME_Paragraph *para )
|
|
|
|
{
|
2020-10-14 12:17:16 +02:00
|
|
|
if (para->prev_para && para->prev_para->type == diParagraph) return ¶->prev_para->member.para;
|
2020-10-09 13:59:22 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-29 14:44:49 +01:00
|
|
|
int get_total_width(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
ME_Paragraph *para;
|
|
|
|
int total_width = 0;
|
|
|
|
|
|
|
|
if (editor->pBuffer->pFirst && editor->pBuffer->pLast)
|
|
|
|
{
|
|
|
|
para = &editor->pBuffer->pFirst->next->member.para;
|
|
|
|
while (para != &editor->pBuffer->pLast->member.para && para->next_para)
|
|
|
|
{
|
|
|
|
total_width = max(total_width, para->nWidth);
|
|
|
|
para = ¶->next_para->member.para;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return total_width;
|
|
|
|
}
|
|
|
|
|
2020-10-09 13:59:20 +02:00
|
|
|
static int para_mark_compare( const void *key, const struct wine_rb_entry *entry )
|
2018-11-29 14:44:53 +01:00
|
|
|
{
|
2020-10-09 13:59:20 +02:00
|
|
|
ME_Paragraph *para = WINE_RB_ENTRY_VALUE( entry, ME_Paragraph, marked_entry );
|
2018-11-29 14:44:53 +01:00
|
|
|
|
2020-10-09 13:59:20 +02:00
|
|
|
return *(int *)key - para->nCharOfs;
|
2018-11-29 14:44:53 +01:00
|
|
|
}
|
|
|
|
|
2020-10-09 13:59:20 +02:00
|
|
|
void para_mark_remove( ME_TextEditor *editor, ME_Paragraph *para )
|
2018-11-29 14:44:53 +01:00
|
|
|
{
|
2020-10-09 13:59:20 +02:00
|
|
|
wine_rb_remove_key( &editor->marked_paras, ¶->nCharOfs );
|
|
|
|
}
|
2018-11-29 14:44:53 +01:00
|
|
|
|
2020-10-09 13:59:20 +02:00
|
|
|
void para_mark_add( ME_TextEditor *editor, ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
wine_rb_put( &editor->marked_paras, ¶->nCharOfs, ¶->marked_entry );
|
2018-11-29 14:44:53 +01:00
|
|
|
}
|
|
|
|
|
2020-10-08 12:10:48 +02:00
|
|
|
ME_Run *para_first_run( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *di;
|
|
|
|
|
|
|
|
for (di = para_get_di( para ); di != para->next_para; di = di->next )
|
|
|
|
{
|
|
|
|
if (di->type != diRun) continue;
|
|
|
|
return &di->member.run;
|
|
|
|
}
|
|
|
|
ERR( "failed to find run in paragraph\n" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-10-13 12:16:33 +02:00
|
|
|
ME_Run *para_end_run( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
return para->eop_run;
|
|
|
|
}
|
|
|
|
|
2020-10-20 13:50:37 +02:00
|
|
|
BOOL para_in_table( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
return para->fmt.wEffects & PFE_TABLE;
|
|
|
|
}
|
|
|
|
|
2020-10-22 13:46:48 +02:00
|
|
|
ME_Cell *para_cell( ME_Paragraph *para )
|
|
|
|
{
|
2020-11-06 09:32:22 +01:00
|
|
|
return para->cell;
|
2020-10-22 13:46:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-26 09:46:39 +01:00
|
|
|
ME_Row *para_first_row( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
|
|
|
item = ME_FindItemFwd( para_get_di( para ), diStartRowOrParagraph );
|
|
|
|
if (!item || item->type != diStartRow) return NULL;
|
|
|
|
return &item->member.row;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_Row *para_end_row( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item;
|
|
|
|
|
|
|
|
para = para_next( para );
|
|
|
|
item = ME_FindItemBack( para_get_di( para ), diStartRowOrParagraph );
|
|
|
|
if (!item || item->type != diStartRow) return NULL;
|
|
|
|
return &item->member.row;
|
|
|
|
}
|
|
|
|
|
2008-01-01 22:05:46 +01:00
|
|
|
void ME_MakeFirstParagraph(ME_TextEditor *editor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-01-01 22:05:46 +01:00
|
|
|
ME_Context c;
|
2005-03-05 12:19:14 +01:00
|
|
|
CHARFORMAT2W cf;
|
2018-08-20 16:03:49 +02:00
|
|
|
const CHARFORMATW *host_cf;
|
2005-03-05 12:19:14 +01:00
|
|
|
LOGFONTW lf;
|
|
|
|
HFONT hf;
|
2008-01-01 22:05:46 +01:00
|
|
|
ME_TextBuffer *text = editor->pBuffer;
|
2020-10-16 13:08:07 +02:00
|
|
|
ME_Paragraph *para = para_create( editor );
|
2020-10-13 12:16:37 +02:00
|
|
|
ME_Run *run;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_Style *style;
|
2013-02-05 14:19:41 +01:00
|
|
|
int eol_len;
|
2021-03-23 14:04:03 +01:00
|
|
|
HDC hdc = ITextHost_TxGetDC( editor->texthost );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2021-03-23 14:04:03 +01:00
|
|
|
ME_InitContext( &c, editor, hdc );
|
2008-01-01 22:05:46 +01:00
|
|
|
|
2008-11-03 22:36:03 +01:00
|
|
|
hf = GetStockObject(SYSTEM_FONT);
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(hf);
|
|
|
|
GetObjectW(hf, sizeof(LOGFONTW), &lf);
|
|
|
|
ZeroMemory(&cf, sizeof(cf));
|
|
|
|
cf.cbSize = sizeof(cf);
|
2016-10-14 11:05:02 +02:00
|
|
|
cf.dwMask = CFM_ANIMATION|CFM_BACKCOLOR|CFM_CHARSET|CFM_COLOR|CFM_FACE|CFM_KERNING|CFM_LCID|CFM_OFFSET;
|
|
|
|
cf.dwMask |= CFM_REVAUTHOR|CFM_SIZE|CFM_SPACING|CFM_STYLE|CFM_UNDERLINETYPE|CFM_WEIGHT;
|
2005-03-05 12:19:14 +01:00
|
|
|
cf.dwMask |= CFM_ALLCAPS|CFM_BOLD|CFM_DISABLED|CFM_EMBOSS|CFM_HIDDEN;
|
|
|
|
cf.dwMask |= CFM_IMPRINT|CFM_ITALIC|CFM_LINK|CFM_OUTLINE|CFM_PROTECTED;
|
|
|
|
cf.dwMask |= CFM_REVISED|CFM_SHADOW|CFM_SMALLCAPS|CFM_STRIKEOUT;
|
2016-10-14 11:05:02 +02:00
|
|
|
cf.dwMask |= CFM_SUBSCRIPT|CFM_UNDERLINE;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
cf.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
|
|
|
|
lstrcpyW(cf.szFaceName, lf.lfFaceName);
|
2008-06-25 17:40:39 +02:00
|
|
|
/* Convert system font height from logical units to twips for cf.yHeight */
|
|
|
|
cf.yHeight = (lf.lfHeight * 72 * 1440) / (c.dpi.cy * c.dpi.cy);
|
2008-03-16 21:47:39 +01:00
|
|
|
if (lf.lfWeight > FW_NORMAL) cf.dwEffects |= CFE_BOLD;
|
2005-03-05 12:19:14 +01:00
|
|
|
cf.wWeight = lf.lfWeight;
|
|
|
|
if (lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
|
2016-10-14 11:05:03 +02:00
|
|
|
if (lf.lfUnderline) cf.dwEffects |= CFE_UNDERLINE;
|
|
|
|
cf.bUnderlineType = CFU_UNDERLINE;
|
2005-03-05 12:19:14 +01:00
|
|
|
if (lf.lfStrikeOut) cf.dwEffects |= CFE_STRIKEOUT;
|
2008-01-01 22:03:40 +01:00
|
|
|
cf.bPitchAndFamily = lf.lfPitchAndFamily;
|
|
|
|
cf.bCharSet = lf.lfCharSet;
|
2016-10-14 11:05:02 +02:00
|
|
|
cf.lcid = GetSystemDefaultLCID();
|
2008-01-01 22:03:40 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
style = ME_MakeStyle(&cf);
|
|
|
|
text->pDefaultStyle = style;
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2018-08-20 16:03:49 +02:00
|
|
|
if (ITextHost_TxGetCharFormat(editor->texthost, &host_cf) == S_OK)
|
|
|
|
{
|
|
|
|
ZeroMemory(&cf, sizeof(cf));
|
|
|
|
cf.cbSize = sizeof(cf);
|
|
|
|
cfany_to_cf2w(&cf, (CHARFORMAT2W *)host_cf);
|
|
|
|
ME_SetDefaultCharFormat(editor, &cf);
|
|
|
|
}
|
|
|
|
|
2013-02-05 14:19:41 +01:00
|
|
|
eol_len = editor->bEmulateVersion10 ? 2 : 1;
|
2020-11-15 23:11:14 +01:00
|
|
|
para->text = ME_MakeStringN( L"\r\n", eol_len );
|
2013-02-05 14:19:41 +01:00
|
|
|
|
2020-10-13 12:16:37 +02:00
|
|
|
run = run_create( style, MERF_ENDPARA );
|
|
|
|
run->nCharOfs = 0;
|
|
|
|
run->len = eol_len;
|
2020-10-16 13:08:07 +02:00
|
|
|
run->para = para;
|
|
|
|
para->eop_run = run;
|
2016-10-07 11:49:34 +02:00
|
|
|
|
2020-10-16 13:08:07 +02:00
|
|
|
ME_InsertBefore( text->pLast, para_get_di( para) );
|
|
|
|
ME_InsertBefore( text->pLast, run_get_di( run ) );
|
|
|
|
para->prev_para = text->pFirst;
|
|
|
|
para->next_para = text->pLast;
|
|
|
|
text->pFirst->member.para.next_para = para_get_di( para );
|
|
|
|
text->pLast->member.para.prev_para = para_get_di( para );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2009-01-11 08:59:31 +01:00
|
|
|
text->pLast->member.para.nCharOfs = editor->bEmulateVersion10 ? 2 : 1;
|
2008-01-01 22:05:46 +01:00
|
|
|
|
2020-10-09 13:59:20 +02:00
|
|
|
wine_rb_init( &editor->marked_paras, para_mark_compare );
|
2020-10-16 13:08:07 +02:00
|
|
|
para_mark_add( editor, para );
|
2009-01-20 07:41:32 +01:00
|
|
|
ME_DestroyContext(&c);
|
2021-03-23 14:04:03 +01:00
|
|
|
ITextHost_TxReleaseDC( editor->texthost, hdc );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 07:56:26 +01:00
|
|
|
static void para_mark_rewrap_paras( ME_TextEditor *editor, ME_Paragraph *first, const ME_Paragraph *end )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-11-04 07:56:26 +01:00
|
|
|
while (first != end)
|
|
|
|
{
|
|
|
|
para_mark_rewrap( editor, first );
|
|
|
|
first = para_next( first );
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 07:56:26 +01:00
|
|
|
void editor_mark_rewrap_all( ME_TextEditor *editor )
|
2009-01-14 00:25:51 +01:00
|
|
|
{
|
2020-11-04 07:56:26 +01:00
|
|
|
para_mark_rewrap_paras( editor, editor_first_para( editor ), editor_end_para( editor ) );
|
2009-01-14 00:25:51 +01:00
|
|
|
}
|
|
|
|
|
2020-10-16 13:08:06 +02:00
|
|
|
static void table_update_flags( ME_Paragraph *para )
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2020-10-16 13:08:06 +02:00
|
|
|
para->fmt.dwMask |= PFM_TABLE | PFM_TABLEROWDELIMITER;
|
|
|
|
|
2020-11-06 09:32:21 +01:00
|
|
|
if (para_cell( para )) para->nFlags |= MEPF_CELL;
|
2020-10-16 13:08:06 +02:00
|
|
|
else para->nFlags &= ~MEPF_CELL;
|
|
|
|
|
|
|
|
if (para->nFlags & MEPF_ROWEND) para->fmt.wEffects |= PFE_TABLEROWDELIMITER;
|
|
|
|
else para->fmt.wEffects &= ~PFE_TABLEROWDELIMITER;
|
|
|
|
|
|
|
|
if (para->nFlags & (MEPF_ROWSTART | MEPF_CELL | MEPF_ROWEND))
|
|
|
|
para->fmt.wEffects |= PFE_TABLE;
|
|
|
|
else
|
|
|
|
para->fmt.wEffects &= ~PFE_TABLE;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
|
2016-10-10 14:13:02 +02:00
|
|
|
static inline BOOL para_num_same_list( const PARAFORMAT2 *item, const PARAFORMAT2 *base )
|
|
|
|
{
|
|
|
|
return item->wNumbering == base->wNumbering &&
|
|
|
|
item->wNumberingStart == base->wNumberingStart &&
|
|
|
|
item->wNumberingStyle == base->wNumberingStyle &&
|
|
|
|
!(item->wNumberingStyle & PFNS_NEWNUMBER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int para_num_get_num( ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
ME_DisplayItem *prev;
|
|
|
|
int num = para->fmt.wNumberingStart;
|
|
|
|
|
|
|
|
for (prev = para->prev_para; prev->type == diParagraph;
|
|
|
|
para = &prev->member.para, prev = prev->member.para.prev_para, num++)
|
|
|
|
{
|
|
|
|
if (!para_num_same_list( &prev->member.para.fmt, ¶->fmt )) break;
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ME_String *para_num_get_str( ME_Paragraph *para, WORD num )
|
|
|
|
{
|
2016-10-10 14:13:04 +02:00
|
|
|
/* max 4 Roman letters (representing '8') / decade + '(' + ')' */
|
|
|
|
ME_String *str = ME_MakeStringEmpty( 20 + 2 );
|
2016-10-19 09:26:00 +02:00
|
|
|
WCHAR *p;
|
2016-10-10 14:13:03 +02:00
|
|
|
static const WORD letter_base[] = { 1, 26, 26 * 26, 26 * 26 * 26 };
|
2016-10-10 14:13:04 +02:00
|
|
|
/* roman_base should start on a '5' not a '1', otherwise the 'total' code will need adjusting.
|
|
|
|
'N' and 'O' are what MS uses for 5000 and 10000, their version doesn't work well above 30000,
|
|
|
|
but we'll use 'P' as the obvious extension, this gets us up to 2^16, which is all we care about. */
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
int base;
|
|
|
|
char letter;
|
|
|
|
}
|
|
|
|
roman_base[] =
|
|
|
|
{
|
|
|
|
{50000, 'P'}, {10000, 'O'}, {5000, 'N'}, {1000, 'M'},
|
|
|
|
{500, 'D'}, {100, 'C'}, {50, 'L'}, {10, 'X'}, {5, 'V'}, {1, 'I'}
|
|
|
|
};
|
2016-10-10 14:13:03 +02:00
|
|
|
int i, len;
|
|
|
|
WORD letter, total, char_offset = 0;
|
2016-10-10 14:13:02 +02:00
|
|
|
|
|
|
|
if (!str) return NULL;
|
|
|
|
|
2016-10-19 09:26:00 +02:00
|
|
|
p = str->szData;
|
|
|
|
|
2016-10-10 14:13:02 +02:00
|
|
|
if ((para->fmt.wNumberingStyle & 0xf00) == PFNS_PARENS)
|
|
|
|
*p++ = '(';
|
|
|
|
|
2016-10-10 14:13:03 +02:00
|
|
|
switch (para->fmt.wNumbering)
|
|
|
|
{
|
|
|
|
case PFN_ARABIC:
|
|
|
|
default:
|
2020-11-15 23:11:14 +01:00
|
|
|
p += swprintf( p, 20, L"%d", num );
|
2016-10-10 14:13:03 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PFN_LCLETTER:
|
|
|
|
char_offset = 'a' - 'A';
|
|
|
|
/* fall through */
|
|
|
|
case PFN_UCLETTER:
|
|
|
|
if (!num) num = 1;
|
|
|
|
|
|
|
|
/* This is not base-26 (or 27) as zeros don't count unless they are leading zeros.
|
|
|
|
It's simplest to start with the least significant letter, so first calculate how many letters are needed. */
|
2018-09-10 22:49:39 +02:00
|
|
|
for (i = 0, total = 0; i < ARRAY_SIZE( letter_base ); i++)
|
2016-10-10 14:13:03 +02:00
|
|
|
{
|
|
|
|
total += letter_base[i];
|
|
|
|
if (num < total) break;
|
|
|
|
}
|
|
|
|
len = i;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
num -= letter_base[i];
|
|
|
|
letter = (num / letter_base[i]) % 26;
|
|
|
|
p[len - i - 1] = letter + 'A' + char_offset;
|
|
|
|
}
|
|
|
|
p += len;
|
|
|
|
*p = 0;
|
|
|
|
break;
|
2016-10-10 14:13:04 +02:00
|
|
|
|
|
|
|
case PFN_LCROMAN:
|
|
|
|
char_offset = 'a' - 'A';
|
|
|
|
/* fall through */
|
|
|
|
case PFN_UCROMAN:
|
|
|
|
if (!num) num = 1;
|
|
|
|
|
2018-09-10 22:49:39 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE( roman_base ); i++)
|
2016-10-10 14:13:04 +02:00
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
if (i % 2 == 0) /* eg 5000, check for 9000 */
|
|
|
|
total = roman_base[i].base + 4 * roman_base[i + 1].base;
|
|
|
|
else /* eg 1000, check for 4000 */
|
|
|
|
total = 4 * roman_base[i].base;
|
|
|
|
|
|
|
|
if (num / total)
|
|
|
|
{
|
|
|
|
*p++ = roman_base[(i & ~1) + 1].letter + char_offset;
|
|
|
|
*p++ = roman_base[i - 1].letter + char_offset;
|
|
|
|
num -= total;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = num / roman_base[i].base;
|
|
|
|
while (len--)
|
|
|
|
{
|
|
|
|
*p++ = roman_base[i].letter + char_offset;
|
|
|
|
num -= roman_base[i].base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
break;
|
2016-10-10 14:13:03 +02:00
|
|
|
}
|
2016-10-10 14:13:02 +02:00
|
|
|
|
|
|
|
switch (para->fmt.wNumberingStyle & 0xf00)
|
|
|
|
{
|
|
|
|
case PFNS_PARENS:
|
|
|
|
case PFNS_PAREN:
|
|
|
|
*p++ = ')';
|
|
|
|
*p = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PFNS_PERIOD:
|
|
|
|
*p++ = '.';
|
|
|
|
*p = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
str->nLen = p - str->szData;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2016-10-07 11:49:35 +02:00
|
|
|
void para_num_init( ME_Context *c, ME_Paragraph *para )
|
|
|
|
{
|
|
|
|
ME_Style *style;
|
|
|
|
CHARFORMAT2W cf;
|
|
|
|
SIZE sz;
|
|
|
|
|
2019-08-19 11:55:30 +02:00
|
|
|
if (!para->fmt.wNumbering) return;
|
2016-10-07 11:49:35 +02:00
|
|
|
if (para->para_num.style && para->para_num.text) return;
|
|
|
|
|
|
|
|
if (!para->para_num.style)
|
|
|
|
{
|
|
|
|
style = para->eop_run->style;
|
|
|
|
|
2016-10-10 14:13:02 +02:00
|
|
|
if (para->fmt.wNumbering == PFN_BULLET)
|
|
|
|
{
|
|
|
|
cf.cbSize = sizeof(cf);
|
|
|
|
cf.dwMask = CFM_FACE | CFM_CHARSET;
|
2020-11-15 23:11:14 +01:00
|
|
|
lstrcpyW( cf.szFaceName, L"Symbol" );
|
2016-10-10 14:13:02 +02:00
|
|
|
cf.bCharSet = SYMBOL_CHARSET;
|
|
|
|
style = ME_ApplyStyle( c->editor, style, &cf );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_AddRefStyle( style );
|
|
|
|
}
|
2016-10-07 11:49:35 +02:00
|
|
|
|
|
|
|
para->para_num.style = style;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!para->para_num.text)
|
|
|
|
{
|
2016-10-10 14:13:02 +02:00
|
|
|
if (para->fmt.wNumbering != PFN_BULLET)
|
|
|
|
para->para_num.text = para_num_get_str( para, para_num_get_num( para ) );
|
|
|
|
else
|
2020-11-15 23:11:14 +01:00
|
|
|
para->para_num.text = ME_MakeStringConst( L"\x00b7", 1 );
|
2016-10-07 11:49:35 +02:00
|
|
|
}
|
|
|
|
|
2019-08-19 11:55:28 +02:00
|
|
|
select_style( c, para->para_num.style );
|
2016-10-07 11:49:35 +02:00
|
|
|
GetTextExtentPointW( c->hDC, para->para_num.text->szData, para->para_num.text->nLen, &sz );
|
|
|
|
para->para_num.width = sz.cx;
|
2020-11-15 23:11:14 +01:00
|
|
|
GetTextExtentPointW( c->hDC, L" ", 1, &sz );
|
2016-10-07 11:49:35 +02:00
|
|
|
para->para_num.width += sz.cx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void para_num_clear( struct para_num *pn )
|
|
|
|
{
|
|
|
|
if (pn->style)
|
|
|
|
{
|
|
|
|
ME_ReleaseStyle( pn->style );
|
|
|
|
pn->style = NULL;
|
|
|
|
}
|
|
|
|
ME_DestroyString( pn->text );
|
|
|
|
pn->text = NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-29 14:44:51 +01:00
|
|
|
static void para_num_clear_list( ME_TextEditor *editor, ME_Paragraph *para, const PARAFORMAT2 *orig_fmt )
|
2016-10-10 14:13:02 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2020-10-09 13:59:18 +02:00
|
|
|
para_mark_rewrap( editor, para );
|
2016-10-10 14:13:02 +02:00
|
|
|
para_num_clear( ¶->para_num );
|
|
|
|
if (para->next_para->type != diParagraph) break;
|
|
|
|
para = ¶->next_para->member.para;
|
|
|
|
} while (para_num_same_list( ¶->fmt, orig_fmt ));
|
|
|
|
}
|
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
static BOOL para_set_fmt( ME_TextEditor *editor, ME_Paragraph *para, const PARAFORMAT2 *pFmt )
|
2009-01-14 00:25:51 +01:00
|
|
|
{
|
|
|
|
PARAFORMAT2 copy;
|
2009-01-16 05:07:15 +01:00
|
|
|
DWORD dwMask;
|
|
|
|
|
2016-09-29 11:13:11 +02:00
|
|
|
assert(para->fmt.cbSize == sizeof(PARAFORMAT2));
|
2009-01-16 05:07:15 +01:00
|
|
|
dwMask = pFmt->dwMask;
|
|
|
|
if (pFmt->cbSize < sizeof(PARAFORMAT))
|
|
|
|
return FALSE;
|
|
|
|
else if (pFmt->cbSize < sizeof(PARAFORMAT2))
|
|
|
|
dwMask &= PFM_ALL;
|
|
|
|
else
|
|
|
|
dwMask &= PFM_ALL2;
|
|
|
|
|
2016-09-27 10:57:18 +02:00
|
|
|
add_undo_set_para_fmt( editor, para );
|
2009-01-14 00:25:51 +01:00
|
|
|
|
2016-09-29 11:13:11 +02:00
|
|
|
copy = para->fmt;
|
2009-01-14 00:25:51 +01:00
|
|
|
|
|
|
|
#define COPY_FIELD(m, f) \
|
2009-01-16 05:07:15 +01:00
|
|
|
if (dwMask & (m)) { \
|
2016-09-29 11:13:11 +02:00
|
|
|
para->fmt.dwMask |= m; \
|
|
|
|
para->fmt.f = pFmt->f; \
|
2009-01-14 00:25:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
COPY_FIELD(PFM_NUMBERING, wNumbering);
|
|
|
|
COPY_FIELD(PFM_STARTINDENT, dxStartIndent);
|
2009-01-16 05:07:15 +01:00
|
|
|
if (dwMask & PFM_OFFSETINDENT)
|
2016-09-29 11:13:11 +02:00
|
|
|
para->fmt.dxStartIndent += pFmt->dxStartIndent;
|
2009-01-14 00:25:51 +01:00
|
|
|
COPY_FIELD(PFM_RIGHTINDENT, dxRightIndent);
|
|
|
|
COPY_FIELD(PFM_OFFSET, dxOffset);
|
|
|
|
COPY_FIELD(PFM_ALIGNMENT, wAlignment);
|
2009-01-16 05:07:15 +01:00
|
|
|
if (dwMask & PFM_TABSTOPS)
|
2009-01-14 00:25:51 +01:00
|
|
|
{
|
2016-09-29 11:13:11 +02:00
|
|
|
para->fmt.cTabCount = pFmt->cTabCount;
|
|
|
|
memcpy(para->fmt.rgxTabs, pFmt->rgxTabs, pFmt->cTabCount*sizeof(LONG));
|
2009-01-14 00:25:51 +01:00
|
|
|
}
|
2009-01-16 05:07:15 +01:00
|
|
|
|
|
|
|
#define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \
|
|
|
|
PFM_NOLINENUMBER|PFM_NOWIDOWCONTROL|PFM_DONOTHYPHEN|PFM_SIDEBYSIDE| \
|
|
|
|
PFM_TABLE)
|
2013-03-25 12:05:54 +01:00
|
|
|
/* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
|
|
|
|
if (dwMask & EFFECTS_MASK)
|
|
|
|
{
|
2016-09-29 11:13:11 +02:00
|
|
|
para->fmt.dwMask |= dwMask & EFFECTS_MASK;
|
|
|
|
para->fmt.wEffects &= ~HIWORD(dwMask);
|
|
|
|
para->fmt.wEffects |= pFmt->wEffects & HIWORD(dwMask);
|
2013-03-25 12:05:54 +01:00
|
|
|
}
|
2009-01-16 05:07:15 +01:00
|
|
|
#undef EFFECTS_MASK
|
|
|
|
|
2013-03-25 12:05:54 +01:00
|
|
|
COPY_FIELD(PFM_SPACEBEFORE, dySpaceBefore);
|
|
|
|
COPY_FIELD(PFM_SPACEAFTER, dySpaceAfter);
|
|
|
|
COPY_FIELD(PFM_LINESPACING, dyLineSpacing);
|
|
|
|
COPY_FIELD(PFM_STYLE, sStyle);
|
|
|
|
COPY_FIELD(PFM_LINESPACING, bLineSpacingRule);
|
|
|
|
COPY_FIELD(PFM_SHADING, wShadingWeight);
|
|
|
|
COPY_FIELD(PFM_SHADING, wShadingStyle);
|
|
|
|
COPY_FIELD(PFM_NUMBERINGSTART, wNumberingStart);
|
|
|
|
COPY_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle);
|
|
|
|
COPY_FIELD(PFM_NUMBERINGTAB, wNumberingTab);
|
|
|
|
COPY_FIELD(PFM_BORDER, wBorderSpace);
|
|
|
|
COPY_FIELD(PFM_BORDER, wBorderWidth);
|
|
|
|
COPY_FIELD(PFM_BORDER, wBorders);
|
2009-01-16 05:07:15 +01:00
|
|
|
|
2016-09-29 11:13:11 +02:00
|
|
|
para->fmt.dwMask |= dwMask;
|
2009-01-14 00:25:51 +01:00
|
|
|
#undef COPY_FIELD
|
|
|
|
|
2016-09-29 11:13:11 +02:00
|
|
|
if (memcmp(©, ¶->fmt, sizeof(PARAFORMAT2)))
|
2016-10-10 14:13:02 +02:00
|
|
|
{
|
2020-10-09 13:59:18 +02:00
|
|
|
para_mark_rewrap( editor, para );
|
2016-10-10 14:13:02 +02:00
|
|
|
if (((dwMask & PFM_NUMBERING) && (copy.wNumbering != para->fmt.wNumbering)) ||
|
|
|
|
((dwMask & PFM_NUMBERINGSTART) && (copy.wNumberingStart != para->fmt.wNumberingStart)) ||
|
|
|
|
((dwMask & PFM_NUMBERINGSTYLE) && (copy.wNumberingStyle != para->fmt.wNumberingStyle)))
|
|
|
|
{
|
2018-11-29 14:44:51 +01:00
|
|
|
para_num_clear_list( editor, para, © );
|
2016-10-10 14:13:02 +02:00
|
|
|
}
|
|
|
|
}
|
2009-01-14 00:25:51 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* split paragraph at the beginning of the run */
|
2020-10-16 13:08:09 +02:00
|
|
|
ME_Paragraph *para_split( ME_TextEditor *editor, ME_Run *run, ME_Style *style,
|
|
|
|
const WCHAR *eol_str, int eol_len, int paraFlags )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-16 13:08:08 +02:00
|
|
|
ME_Paragraph *new_para = para_create( editor ), *old_para, *next_para;
|
|
|
|
ME_Run *end_run, *next_run;
|
2009-02-09 18:01:35 +01:00
|
|
|
int ofs, i;
|
2008-08-07 18:31:41 +02:00
|
|
|
int run_flags = MERF_ENDPARA;
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2020-10-16 13:08:09 +02:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
/* At most 1 of MEPF_CELL, MEPF_ROWSTART, or MEPF_ROWEND should be set. */
|
2020-10-16 13:08:09 +02:00
|
|
|
assert( !(paraFlags & ~(MEPF_CELL | MEPF_ROWSTART | MEPF_ROWEND)) );
|
|
|
|
assert( !(paraFlags & (paraFlags-1)) );
|
2008-08-07 18:31:41 +02:00
|
|
|
if (paraFlags == MEPF_CELL)
|
2020-10-16 13:08:09 +02:00
|
|
|
run_flags |= MERF_ENDCELL;
|
2008-08-07 18:31:41 +02:00
|
|
|
else if (paraFlags == MEPF_ROWSTART)
|
2020-10-16 13:08:09 +02:00
|
|
|
run_flags |= MERF_TABLESTART | MERF_HIDDEN;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2020-10-16 13:08:09 +02:00
|
|
|
else /* v1.0 - v3.0 */
|
|
|
|
assert( !(paraFlags & (MEPF_CELL |MEPF_ROWSTART | MEPF_ROWEND)) );
|
|
|
|
|
|
|
|
old_para = run->para;
|
2020-10-16 13:08:08 +02:00
|
|
|
assert( old_para->fmt.cbSize == sizeof(PARAFORMAT2) );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2016-10-10 14:13:02 +02:00
|
|
|
/* Clear any cached para numbering following this paragraph */
|
2020-10-16 13:08:08 +02:00
|
|
|
if (old_para->fmt.wNumbering)
|
|
|
|
para_num_clear_list( editor, old_para, &old_para->fmt );
|
2016-10-10 14:13:02 +02:00
|
|
|
|
2020-10-16 13:08:09 +02:00
|
|
|
new_para->text = ME_VSplitString( old_para->text, run->nCharOfs );
|
2013-02-05 14:19:41 +01:00
|
|
|
|
2020-10-13 12:16:37 +02:00
|
|
|
end_run = run_create( style, run_flags );
|
2020-10-16 13:08:09 +02:00
|
|
|
ofs = end_run->nCharOfs = run->nCharOfs;
|
2020-10-13 12:16:37 +02:00
|
|
|
end_run->len = eol_len;
|
2020-10-16 13:08:09 +02:00
|
|
|
end_run->para = run->para;
|
2020-10-16 13:08:08 +02:00
|
|
|
ME_AppendString( old_para->text, eol_str, eol_len );
|
|
|
|
next_para = &old_para->next_para->member.para;
|
2013-01-30 16:10:18 +01:00
|
|
|
|
2020-10-16 13:08:08 +02:00
|
|
|
add_undo_join_paras( editor, old_para->nCharOfs + ofs );
|
2009-02-09 18:01:35 +01:00
|
|
|
|
|
|
|
/* Update selection cursors to point to the correct paragraph. */
|
2020-10-16 13:08:08 +02:00
|
|
|
for (i = 0; i < editor->nCursors; i++)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (editor->pCursors[i].para == old_para &&
|
|
|
|
run->nCharOfs <= editor->pCursors[i].run->nCharOfs)
|
2009-02-09 18:01:35 +01:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
editor->pCursors[i].para = new_para;
|
2009-02-09 18:01:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-16 13:08:08 +02:00
|
|
|
/* the new paragraph will have a different starting offset, so update its runs */
|
2020-10-16 13:08:09 +02:00
|
|
|
for (next_run = run; next_run; next_run = run_next( next_run ))
|
2020-10-16 13:08:08 +02:00
|
|
|
{
|
|
|
|
next_run->nCharOfs -= ofs;
|
|
|
|
next_run->para = new_para;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2020-10-16 13:08:08 +02:00
|
|
|
|
|
|
|
new_para->nCharOfs = old_para->nCharOfs + ofs;
|
2020-10-16 13:08:07 +02:00
|
|
|
new_para->nCharOfs += eol_len;
|
|
|
|
new_para->nFlags = 0;
|
|
|
|
para_mark_rewrap( editor, new_para );
|
2008-08-07 18:31:41 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* FIXME initialize format style and call ME_SetParaFormat blah blah */
|
2020-10-16 13:08:08 +02:00
|
|
|
new_para->fmt = old_para->fmt;
|
|
|
|
new_para->border = old_para->border;
|
2008-08-07 18:31:41 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* insert paragraph into paragraph double linked list */
|
2020-10-16 13:08:08 +02:00
|
|
|
new_para->prev_para = para_get_di( old_para );
|
|
|
|
new_para->next_para = para_get_di( next_para );
|
|
|
|
old_para->next_para = para_get_di( new_para );
|
|
|
|
next_para->prev_para = para_get_di( new_para );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
/* insert end run of the old paragraph, and new paragraph, into DI double linked list */
|
2020-10-16 13:08:09 +02:00
|
|
|
ME_InsertBefore( run_get_di( run ), para_get_di( new_para ) );
|
2020-10-16 13:08:07 +02:00
|
|
|
ME_InsertBefore( para_get_di( new_para ), run_get_di( end_run ) );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2016-10-07 11:49:34 +02:00
|
|
|
/* Fix up the paras' eop_run ptrs */
|
2020-10-16 13:08:08 +02:00
|
|
|
new_para->eop_run = old_para->eop_run;
|
|
|
|
old_para->eop_run = end_run;
|
2016-10-07 11:49:34 +02:00
|
|
|
|
2020-10-16 13:08:08 +02:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
|
|
|
if (paraFlags & (MEPF_ROWSTART | MEPF_CELL))
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2020-11-06 09:32:21 +01:00
|
|
|
ME_Cell *cell = cell_create();
|
|
|
|
ME_InsertBefore( para_get_di( new_para ), cell_get_di( cell ) );
|
2020-11-06 09:32:22 +01:00
|
|
|
new_para->cell = cell;
|
2020-11-06 09:32:21 +01:00
|
|
|
cell->next_cell = NULL;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (paraFlags & MEPF_ROWSTART)
|
|
|
|
{
|
2020-10-16 13:08:08 +02:00
|
|
|
old_para->nFlags |= MEPF_ROWSTART;
|
2020-11-06 09:32:21 +01:00
|
|
|
cell->prev_cell = NULL;
|
2020-11-06 09:32:22 +01:00
|
|
|
cell->parent_cell = old_para->cell;
|
2020-11-06 09:32:21 +01:00
|
|
|
if (para_cell( old_para ))
|
|
|
|
cell->nNestingLevel = para_cell( old_para )->nNestingLevel + 1;
|
2008-08-07 18:31:41 +02:00
|
|
|
else
|
2020-11-06 09:32:21 +01:00
|
|
|
cell->nNestingLevel = 1;
|
2020-10-16 13:08:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-06 09:32:22 +01:00
|
|
|
cell->prev_cell = old_para->cell;
|
|
|
|
cell_prev( cell )->next_cell = cell;
|
2020-10-16 13:08:08 +02:00
|
|
|
assert( old_para->nFlags & MEPF_CELL );
|
|
|
|
assert( !(old_para->nFlags & MEPF_ROWSTART) );
|
2020-11-06 09:32:21 +01:00
|
|
|
cell->nNestingLevel = cell_prev( cell )->nNestingLevel;
|
|
|
|
cell->parent_cell = cell_prev( cell )->parent_cell;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2020-10-16 13:08:07 +02:00
|
|
|
}
|
|
|
|
else if (paraFlags & MEPF_ROWEND)
|
|
|
|
{
|
2020-10-16 13:08:08 +02:00
|
|
|
old_para->nFlags |= MEPF_ROWEND;
|
2020-11-06 09:32:22 +01:00
|
|
|
old_para->cell = old_para->cell->parent_cell;
|
|
|
|
new_para->cell = old_para->cell;
|
2020-11-06 09:32:21 +01:00
|
|
|
assert( para_prev( old_para )->nFlags & MEPF_CELL );
|
|
|
|
assert( !(para_prev( old_para )->nFlags & MEPF_ROWSTART) );
|
2020-11-06 09:32:22 +01:00
|
|
|
if (new_para->cell != para_next( new_para )->cell
|
|
|
|
&& para_next( new_para )->cell
|
|
|
|
&& !cell_prev( para_next( new_para )->cell ))
|
2008-09-11 18:45:47 +02:00
|
|
|
{
|
|
|
|
/* Row starts just after the row that was ended. */
|
2020-10-16 13:08:07 +02:00
|
|
|
new_para->nFlags |= MEPF_ROWSTART;
|
2008-09-11 18:45:47 +02:00
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2020-11-06 09:32:22 +01:00
|
|
|
else new_para->cell = old_para->cell;
|
2020-10-16 13:08:07 +02:00
|
|
|
|
2020-10-16 13:08:08 +02:00
|
|
|
table_update_flags( old_para );
|
2020-10-16 13:08:07 +02:00
|
|
|
table_update_flags( new_para );
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* force rewrap of the */
|
2020-10-16 13:08:08 +02:00
|
|
|
if (old_para->prev_para->type == diParagraph)
|
|
|
|
para_mark_rewrap( editor, &old_para->prev_para->member.para );
|
2018-11-29 14:44:52 +01:00
|
|
|
|
2020-10-16 13:08:07 +02:00
|
|
|
para_mark_rewrap( editor, &new_para->prev_para->member.para );
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* we've added the end run, so we need to modify nCharOfs in the next paragraphs */
|
2020-11-09 09:45:03 +01:00
|
|
|
editor_propagate_char_ofs( next_para, NULL, eol_len );
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->nParagraphs++;
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2020-10-16 13:08:09 +02:00
|
|
|
return new_para;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
/* join para with the next para keeping para's style using the paragraph fmt
|
|
|
|
specified in use_first_fmt */
|
|
|
|
ME_Paragraph *para_join( ME_TextEditor *editor, ME_Paragraph *para, BOOL use_first_fmt )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-16 13:08:10 +02:00
|
|
|
ME_Paragraph *next = para_next( para );
|
|
|
|
ME_Run *end_run, *next_first_run, *tmp_run;
|
2020-11-06 09:32:21 +01:00
|
|
|
ME_Cell *cell = NULL;
|
2020-11-09 09:45:03 +01:00
|
|
|
int i, end_len;
|
2009-08-12 15:06:13 +02:00
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
ME_Cursor startCur, endCur;
|
2013-02-05 14:19:41 +01:00
|
|
|
ME_String *eol_str;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
assert( next && para_next( next ) );
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2016-10-10 14:13:02 +02:00
|
|
|
/* Clear any cached para numbering following this paragraph */
|
2020-10-16 13:08:10 +02:00
|
|
|
if (para->fmt.wNumbering) para_num_clear_list( editor, para, ¶->fmt );
|
2016-10-10 14:13:02 +02:00
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
end_run = para_end_run( para );
|
|
|
|
next_first_run = para_first_run( next );
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
end_len = end_run->len;
|
|
|
|
eol_str = ME_VSplitString( para->text, end_run->nCharOfs );
|
|
|
|
ME_AppendString( para->text, next->text->szData, next->text->nLen );
|
2008-04-26 20:29:53 +02:00
|
|
|
|
2009-08-12 15:06:13 +02:00
|
|
|
/* null char format operation to store the original char format for the ENDPARA run */
|
|
|
|
ME_InitCharFormat2W(&fmt);
|
2020-11-06 09:32:24 +01:00
|
|
|
startCur.para = para;
|
|
|
|
startCur.run = end_run;
|
|
|
|
endCur.para = next;
|
|
|
|
endCur.run = next_first_run;
|
2020-10-16 13:08:10 +02:00
|
|
|
startCur.nOffset = endCur.nOffset = 0;
|
|
|
|
|
2009-08-12 15:06:13 +02:00
|
|
|
ME_SetCharFormat(editor, &startCur, &endCur, &fmt);
|
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
if (!editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
2020-11-09 09:45:06 +01:00
|
|
|
/* Remove cell boundary if it is between the end paragraph run and the next
|
|
|
|
* paragraph display item. */
|
|
|
|
if (para->cell != next->cell) cell = next->cell;
|
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
/* Table cell/row properties are always moved over from the removed para. */
|
2020-10-16 13:08:10 +02:00
|
|
|
para->nFlags = next->nFlags;
|
2020-11-06 09:32:22 +01:00
|
|
|
para->cell = next->cell;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2020-11-06 09:32:21 +01:00
|
|
|
add_undo_split_para( editor, next, eol_str, cell );
|
2013-01-25 14:56:29 +01:00
|
|
|
|
2020-11-06 09:32:21 +01:00
|
|
|
if (cell)
|
2013-01-25 14:56:29 +01:00
|
|
|
{
|
2020-11-06 09:32:21 +01:00
|
|
|
ME_Remove( cell_get_di( cell ) );
|
2020-11-06 09:32:22 +01:00
|
|
|
if (cell_prev( cell )) cell_prev( cell )->next_cell = cell_next( cell );
|
|
|
|
if (cell_next( cell )) cell_next( cell )->prev_cell = cell_prev( cell );
|
2020-11-06 09:32:21 +01:00
|
|
|
ME_DestroyDisplayItem( cell_get_di( cell ) );
|
2013-01-25 14:56:29 +01:00
|
|
|
}
|
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
if (!use_first_fmt)
|
2013-01-25 14:56:29 +01:00
|
|
|
{
|
2020-10-16 13:08:10 +02:00
|
|
|
add_undo_set_para_fmt( editor, para );
|
|
|
|
para->fmt = next->fmt;
|
|
|
|
para->border = next->border;
|
2013-01-25 14:56:29 +01:00
|
|
|
}
|
|
|
|
|
2009-02-09 18:01:35 +01:00
|
|
|
/* Update selection cursors so they don't point to the removed end
|
|
|
|
* paragraph run, and point to the correct paragraph. */
|
2020-10-16 13:08:10 +02:00
|
|
|
for (i = 0; i < editor->nCursors; i++)
|
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
if (editor->pCursors[i].run == end_run)
|
2020-10-16 13:08:10 +02:00
|
|
|
{
|
2020-11-06 09:32:24 +01:00
|
|
|
editor->pCursors[i].run = next_first_run;
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->pCursors[i].nOffset = 0;
|
|
|
|
}
|
2020-11-06 09:32:24 +01:00
|
|
|
else if (editor->pCursors[i].para == next)
|
|
|
|
editor->pCursors[i].para = para;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
for (tmp_run = next_first_run; tmp_run; tmp_run = run_next( tmp_run ))
|
|
|
|
{
|
2020-11-09 09:45:03 +01:00
|
|
|
tmp_run->nCharOfs += next->nCharOfs - para->nCharOfs - end_len;
|
2020-10-16 13:08:10 +02:00
|
|
|
tmp_run->para = para;
|
|
|
|
}
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2016-10-07 11:49:34 +02:00
|
|
|
/* Fix up the para's eop_run ptr */
|
2020-10-16 13:08:10 +02:00
|
|
|
para->eop_run = next->eop_run;
|
2016-10-07 11:49:34 +02:00
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
ME_Remove( run_get_di( end_run ) );
|
|
|
|
ME_DestroyDisplayItem( run_get_di( end_run) );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
if (editor->last_sel_start_para == next)
|
|
|
|
editor->last_sel_start_para = para;
|
|
|
|
if (editor->last_sel_end_para == next)
|
|
|
|
editor->last_sel_end_para = para;
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2020-10-16 13:08:10 +02:00
|
|
|
para->next_para = next->next_para;
|
|
|
|
next->next_para->member.para.prev_para = para_get_di( para );
|
|
|
|
ME_Remove( para_get_di(next) );
|
2020-10-19 13:21:16 +02:00
|
|
|
para_destroy( editor, next );
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2020-11-09 09:45:03 +01:00
|
|
|
editor_propagate_char_ofs( para_next( para ), NULL, -end_len );
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CheckCharOffsets(editor);
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->nParagraphs--;
|
2020-10-16 13:08:10 +02:00
|
|
|
para_mark_rewrap( editor, para );
|
|
|
|
return para;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2007-08-13 23:41:55 +02:00
|
|
|
void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048])
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
p = buf;
|
|
|
|
|
2008-01-01 22:04:22 +01:00
|
|
|
#define DUMP(mask, name, fmt, field) \
|
|
|
|
if (pFmt->dwMask & (mask)) p += sprintf(p, "%-22s" fmt "\n", name, pFmt->field); \
|
|
|
|
else p += sprintf(p, "%-22sN/A\n", name);
|
|
|
|
|
|
|
|
/* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
|
|
|
|
#define DUMP_EFFECT(mask, name) \
|
2011-05-05 17:52:52 +02:00
|
|
|
p += sprintf(p, "%-22s%s\n", name, (pFmt->dwMask & (mask)) ? ((pFmt->wEffects & ((mask) >> 16)) ? "yes" : "no") : "N/A");
|
2008-01-01 22:04:22 +01:00
|
|
|
|
|
|
|
DUMP(PFM_NUMBERING, "Numbering:", "%u", wNumbering);
|
|
|
|
DUMP_EFFECT(PFM_DONOTHYPHEN, "Disable auto-hyphen:");
|
|
|
|
DUMP_EFFECT(PFM_KEEP, "No page break in para:");
|
|
|
|
DUMP_EFFECT(PFM_KEEPNEXT, "No page break in para & next:");
|
|
|
|
DUMP_EFFECT(PFM_NOLINENUMBER, "No line number:");
|
|
|
|
DUMP_EFFECT(PFM_NOWIDOWCONTROL, "No widow & orphan:");
|
|
|
|
DUMP_EFFECT(PFM_PAGEBREAKBEFORE, "Page break before:");
|
|
|
|
DUMP_EFFECT(PFM_RTLPARA, "RTL para:");
|
|
|
|
DUMP_EFFECT(PFM_SIDEBYSIDE, "Side by side:");
|
|
|
|
DUMP_EFFECT(PFM_TABLE, "Table:");
|
2022-02-17 07:11:43 +01:00
|
|
|
DUMP(PFM_OFFSETINDENT, "Offset indent:", "%ld", dxStartIndent);
|
|
|
|
DUMP(PFM_STARTINDENT, "Start indent:", "%ld", dxStartIndent);
|
|
|
|
DUMP(PFM_RIGHTINDENT, "Right indent:", "%ld", dxRightIndent);
|
|
|
|
DUMP(PFM_OFFSET, "Offset:", "%ld", dxOffset);
|
2008-01-01 22:04:22 +01:00
|
|
|
if (pFmt->dwMask & PFM_ALIGNMENT) {
|
|
|
|
switch (pFmt->wAlignment) {
|
|
|
|
case PFA_LEFT : p += sprintf(p, "Alignment: left\n"); break;
|
|
|
|
case PFA_RIGHT : p += sprintf(p, "Alignment: right\n"); break;
|
|
|
|
case PFA_CENTER : p += sprintf(p, "Alignment: center\n"); break;
|
|
|
|
case PFA_JUSTIFY: p += sprintf(p, "Alignment: justify\n"); break;
|
|
|
|
default : p += sprintf(p, "Alignment: incorrect %d\n", pFmt->wAlignment); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else p += sprintf(p, "Alignment: N/A\n");
|
|
|
|
DUMP(PFM_TABSTOPS, "Tab Stops:", "%d", cTabCount);
|
|
|
|
if (pFmt->dwMask & PFM_TABSTOPS) {
|
|
|
|
int i;
|
|
|
|
p += sprintf(p, "\t");
|
2022-02-17 07:11:43 +01:00
|
|
|
for (i = 0; i < pFmt->cTabCount; i++) p += sprintf(p, "%lx ", pFmt->rgxTabs[i]);
|
2008-01-01 22:04:22 +01:00
|
|
|
p += sprintf(p, "\n");
|
|
|
|
}
|
2022-02-17 07:11:43 +01:00
|
|
|
DUMP(PFM_SPACEBEFORE, "Space Before:", "%ld", dySpaceBefore);
|
|
|
|
DUMP(PFM_SPACEAFTER, "Space After:", "%ld", dySpaceAfter);
|
|
|
|
DUMP(PFM_LINESPACING, "Line spacing:", "%ld", dyLineSpacing);
|
2008-01-01 22:04:22 +01:00
|
|
|
DUMP(PFM_STYLE, "Text style:", "%d", sStyle);
|
|
|
|
DUMP(PFM_LINESPACING, "Line spacing rule:", "%u", bLineSpacingRule);
|
|
|
|
/* bOutlineLevel should be 0 */
|
2016-04-23 07:48:39 +02:00
|
|
|
DUMP(PFM_SHADING, "Shading Weight:", "%u", wShadingWeight);
|
2008-01-01 22:04:22 +01:00
|
|
|
DUMP(PFM_SHADING, "Shading Style:", "%u", wShadingStyle);
|
|
|
|
DUMP(PFM_NUMBERINGSTART, "Numbering Start:", "%u", wNumberingStart);
|
|
|
|
DUMP(PFM_NUMBERINGSTYLE, "Numbering Style:", "0x%x", wNumberingStyle);
|
|
|
|
DUMP(PFM_NUMBERINGTAB, "Numbering Tab:", "%u", wNumberingStyle);
|
|
|
|
DUMP(PFM_BORDER, "Border Space:", "%u", wBorderSpace);
|
|
|
|
DUMP(PFM_BORDER, "Border Width:", "%u", wBorderWidth);
|
|
|
|
DUMP(PFM_BORDER, "Borders:", "%u", wBorders);
|
|
|
|
|
|
|
|
#undef DUMP
|
|
|
|
#undef DUMP_EFFECT
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
void editor_get_selection_paras( ME_TextEditor *editor, ME_Paragraph **para, ME_Paragraph **para_end )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-01-10 12:10:49 +01:00
|
|
|
ME_Cursor *pEndCursor = &editor->pCursors[1];
|
2009-02-06 07:10:06 +01:00
|
|
|
|
2020-11-06 09:32:24 +01:00
|
|
|
*para = editor->pCursors[0].para;
|
|
|
|
*para_end = editor->pCursors[1].para;
|
2009-02-06 07:10:06 +01:00
|
|
|
if (*para == *para_end)
|
|
|
|
return;
|
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
if ((*para_end)->nCharOfs < (*para)->nCharOfs)
|
|
|
|
{
|
|
|
|
ME_Paragraph *tmp = *para;
|
2006-01-10 12:10:49 +01:00
|
|
|
|
|
|
|
*para = *para_end;
|
|
|
|
*para_end = tmp;
|
|
|
|
pEndCursor = &editor->pCursors[0];
|
|
|
|
}
|
2009-02-06 07:10:06 +01:00
|
|
|
|
|
|
|
/* The paragraph at the end of a non-empty selection isn't included
|
|
|
|
* if the selection ends at the start of the paragraph. */
|
2020-11-06 09:32:24 +01:00
|
|
|
if (!pEndCursor->run->nCharOfs && !pEndCursor->nOffset)
|
2020-10-28 09:43:49 +01:00
|
|
|
*para_end = para_prev( *para_end );
|
2006-01-10 12:10:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
BOOL editor_set_selection_para_fmt( ME_TextEditor *editor, const PARAFORMAT2 *fmt )
|
2006-01-10 12:10:49 +01:00
|
|
|
{
|
2020-10-28 09:43:49 +01:00
|
|
|
ME_Paragraph *para, *para_end;
|
2009-02-06 07:10:06 +01:00
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
editor_get_selection_paras( editor, ¶, ¶_end );
|
2009-02-06 07:10:06 +01:00
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
para_set_fmt( editor, para, fmt );
|
|
|
|
if (para == para_end) break;
|
|
|
|
para = para_next( para );
|
|
|
|
} while(1);
|
2008-08-13 05:15:15 +02:00
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
static void para_copy_fmt( const ME_Paragraph *para, PARAFORMAT2 *fmt )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-28 09:43:49 +01:00
|
|
|
UINT size = fmt->cbSize;
|
|
|
|
|
|
|
|
if (fmt->cbSize >= sizeof(PARAFORMAT2))
|
|
|
|
*fmt = para->fmt;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy( fmt, ¶->fmt, fmt->cbSize );
|
|
|
|
fmt->dwMask &= PFM_ALL;
|
|
|
|
}
|
|
|
|
fmt->cbSize = size;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
void editor_get_selection_para_fmt( ME_TextEditor *editor, PARAFORMAT2 *fmt )
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2020-10-28 09:43:49 +01:00
|
|
|
ME_Paragraph *para, *para_end;
|
2009-01-16 05:50:20 +01:00
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
if (fmt->cbSize < sizeof(PARAFORMAT))
|
2020-10-27 09:23:30 +01:00
|
|
|
{
|
2020-10-28 09:43:49 +01:00
|
|
|
fmt->dwMask = 0;
|
2009-01-16 05:50:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
editor_get_selection_paras( editor, ¶, ¶_end );
|
2009-01-16 05:50:20 +01:00
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
para_copy_fmt( para, fmt );
|
2009-01-16 05:50:20 +01:00
|
|
|
|
2008-07-08 19:39:01 +02:00
|
|
|
/* Invalidate values that change across the selected paragraphs. */
|
2009-01-16 05:50:20 +01:00
|
|
|
while (para != para_end)
|
|
|
|
{
|
2020-10-28 09:43:49 +01:00
|
|
|
para = para_next( para );
|
2008-01-01 22:04:28 +01:00
|
|
|
|
|
|
|
#define CHECK_FIELD(m, f) \
|
2020-10-28 09:43:49 +01:00
|
|
|
if (fmt->f != para->fmt.f) fmt->dwMask &= ~(m);
|
2008-01-01 22:04:28 +01:00
|
|
|
|
|
|
|
CHECK_FIELD(PFM_NUMBERING, wNumbering);
|
|
|
|
CHECK_FIELD(PFM_STARTINDENT, dxStartIndent);
|
|
|
|
CHECK_FIELD(PFM_RIGHTINDENT, dxRightIndent);
|
|
|
|
CHECK_FIELD(PFM_OFFSET, dxOffset);
|
|
|
|
CHECK_FIELD(PFM_ALIGNMENT, wAlignment);
|
2020-10-28 09:43:49 +01:00
|
|
|
if (fmt->dwMask & PFM_TABSTOPS)
|
2020-10-27 09:23:30 +01:00
|
|
|
{
|
2020-10-28 09:43:49 +01:00
|
|
|
if (fmt->cTabCount != para->fmt.cTabCount ||
|
|
|
|
memcmp(fmt->rgxTabs, para->fmt.rgxTabs, para->fmt.cTabCount * sizeof(int) ))
|
|
|
|
fmt->dwMask &= ~PFM_TABSTOPS;
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2008-01-01 22:04:28 +01:00
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
if (fmt->cbSize >= sizeof(PARAFORMAT2))
|
2009-01-16 05:50:20 +01:00
|
|
|
{
|
2020-10-28 09:43:49 +01:00
|
|
|
fmt->dwMask &= ~((fmt->wEffects ^ para->fmt.wEffects) << 16);
|
2009-01-16 05:50:20 +01:00
|
|
|
CHECK_FIELD(PFM_SPACEBEFORE, dySpaceBefore);
|
|
|
|
CHECK_FIELD(PFM_SPACEAFTER, dySpaceAfter);
|
|
|
|
CHECK_FIELD(PFM_LINESPACING, dyLineSpacing);
|
|
|
|
CHECK_FIELD(PFM_STYLE, sStyle);
|
|
|
|
CHECK_FIELD(PFM_SPACEAFTER, bLineSpacingRule);
|
|
|
|
CHECK_FIELD(PFM_SHADING, wShadingWeight);
|
|
|
|
CHECK_FIELD(PFM_SHADING, wShadingStyle);
|
|
|
|
CHECK_FIELD(PFM_NUMBERINGSTART, wNumberingStart);
|
|
|
|
CHECK_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle);
|
|
|
|
CHECK_FIELD(PFM_NUMBERINGTAB, wNumberingTab);
|
|
|
|
CHECK_FIELD(PFM_BORDER, wBorderSpace);
|
|
|
|
CHECK_FIELD(PFM_BORDER, wBorderWidth);
|
|
|
|
CHECK_FIELD(PFM_BORDER, wBorders);
|
|
|
|
}
|
2008-01-01 22:04:28 +01:00
|
|
|
#undef CHECK_FIELD
|
2009-01-16 05:50:20 +01:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-07-08 19:38:58 +02:00
|
|
|
|
2020-10-28 09:43:49 +01:00
|
|
|
void editor_set_default_para_fmt( ME_TextEditor *editor, PARAFORMAT2 *pFmt )
|
2008-07-08 19:38:58 +02:00
|
|
|
{
|
2017-08-21 13:31:45 +02:00
|
|
|
const PARAFORMAT2 *host_fmt;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2008-07-08 19:38:58 +02:00
|
|
|
ZeroMemory(pFmt, sizeof(PARAFORMAT2));
|
|
|
|
pFmt->cbSize = sizeof(PARAFORMAT2);
|
|
|
|
pFmt->dwMask = PFM_ALL2;
|
2017-08-21 13:31:45 +02:00
|
|
|
pFmt->wAlignment = PFA_LEFT;
|
2008-07-08 19:38:58 +02:00
|
|
|
pFmt->sStyle = -1;
|
|
|
|
pFmt->bOutlineLevel = TRUE;
|
2017-08-21 13:31:45 +02:00
|
|
|
|
|
|
|
hr = ITextHost_TxGetParaFormat( editor->texthost, (const PARAFORMAT **)&host_fmt );
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
/* Just use the alignment for now */
|
|
|
|
if (host_fmt->dwMask & PFM_ALIGNMENT)
|
|
|
|
pFmt->wAlignment = host_fmt->wAlignment;
|
|
|
|
ITextHost_OnTxParaFormatChange( editor->texthost, (PARAFORMAT *)pFmt );
|
|
|
|
}
|
2008-07-08 19:38:58 +02:00
|
|
|
}
|