riched20: Pass para ptrs to the various para selection functions.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-10-28 08:43:49 +00:00 committed by Alexandre Julliard
parent 2148167f25
commit da50829128
7 changed files with 90 additions and 86 deletions

View file

@ -433,7 +433,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
continue;
}
}
if (delete_all) ME_SetDefaultParaFormat( editor, &start_para->fmt );
if (delete_all) editor_set_default_para_fmt( editor, &start_para->fmt );
return TRUE;
}

View file

@ -678,7 +678,7 @@ void ME_RTFParAttrHook(RTF_Info *info)
{
PARAFORMAT2 fmt;
fmt.cbSize = sizeof(fmt);
ME_GetSelectionParaFormat(info->editor, &fmt);
editor_get_selection_para_fmt( info->editor, &fmt );
info->fmt.dwMask |= PFM_STARTINDENT | PFM_OFFSET;
info->fmt.dxStartIndent = fmt.dxStartIndent;
info->fmt.dxOffset = fmt.dxOffset;
@ -713,7 +713,7 @@ void ME_RTFParAttrHook(RTF_Info *info)
{
PARAFORMAT2 fmt;
fmt.cbSize = sizeof(fmt);
ME_GetSelectionParaFormat(info->editor, &fmt);
editor_get_selection_para_fmt( info->editor, &fmt );
memcpy(info->fmt.rgxTabs, fmt.rgxTabs,
fmt.cTabCount * sizeof(fmt.rgxTabs[0]));
info->fmt.cTabCount = fmt.cTabCount;
@ -1637,7 +1637,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
ME_GetTextLength(editor), FALSE);
from = to = 0;
ME_ClearTempStyle(editor);
ME_SetDefaultParaFormat(editor, &editor->pCursors[0].pPara->member.para.fmt);
editor_set_default_para_fmt( editor, &editor->pCursors[0].pPara->member.para.fmt );
}
@ -2533,7 +2533,7 @@ static BOOL handle_enter(ME_TextEditor *editor)
ME_InsertTextFromCursor(editor, 0, &endl, 1,
editor->pCursors[0].pRun->member.run.style);
para = editor->pBuffer->pFirst->member.para.next_para;
ME_SetDefaultParaFormat(editor, &para->member.para.fmt);
editor_set_default_para_fmt( editor, &para->member.para.fmt );
para->member.para.nFlags = 0;
para_mark_rewrap( editor, &para->member.para );
editor->pCursors[0].pPara = para;
@ -3131,7 +3131,7 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
ed->nUndoMode = umAddToUndo;
ed->nParagraphs = 1;
ed->nLastSelStart = ed->nLastSelEnd = 0;
ed->pLastSelStartPara = ed->pLastSelEndPara = ed->pCursors[0].pPara;
ed->last_sel_start_para = ed->last_sel_end_para = &ed->pCursors[0].pPara->member.para;
ed->bHideSelection = FALSE;
ed->pfnWordBreak = NULL;
ed->lpOleCallback = NULL;
@ -4027,14 +4027,14 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
case EM_SETPARAFORMAT:
{
BOOL result = ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
BOOL result = editor_set_selection_para_fmt( editor, (PARAFORMAT2 *)lParam );
ME_WrapMarkedParagraphs(editor);
ME_UpdateScrollBar(editor);
ME_CommitUndo(editor);
return result;
}
case EM_GETPARAFORMAT:
ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
editor_get_selection_para_fmt( editor, (PARAFORMAT2 *)lParam );
return ((PARAFORMAT2 *)lParam)->dwMask;
case EM_GETFIRSTVISIBLELINE:
{

View file

@ -204,15 +204,15 @@ void para_range_invalidate( ME_TextEditor *editor, ME_Paragraph *start_para, ME_
void ME_SendRequestResize(ME_TextEditor *editor, BOOL force) DECLSPEC_HIDDEN;
/* para.c */
void editor_get_selection_paras(ME_TextEditor *editor, ME_Paragraph **para, ME_Paragraph **para_end ) DECLSPEC_HIDDEN;
void editor_get_selection_para_fmt( ME_TextEditor *editor, PARAFORMAT2 *fmt ) DECLSPEC_HIDDEN;
void editor_set_default_para_fmt(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
BOOL editor_set_selection_para_fmt( ME_TextEditor *editor, const PARAFORMAT2 *fmt ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run) DECLSPEC_HIDDEN;
void ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end) DECLSPEC_HIDDEN;
void ME_MakeFirstParagraph(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_DumpParaStyle(ME_Paragraph *s) DECLSPEC_HIDDEN;
void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]) DECLSPEC_HIDDEN;
BOOL ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
void ME_MarkAllForWrapping(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
int get_total_width(ME_TextEditor *editor) DECLSPEC_HIDDEN;
ME_Cell *para_cell( ME_Paragraph *para ) DECLSPEC_HIDDEN;
void para_destroy( ME_TextEditor *editor, ME_Paragraph *item ) DECLSPEC_HIDDEN;

View file

@ -407,7 +407,7 @@ typedef struct tagME_TextEditor
ME_UndoMode nUndoMode;
int nParagraphs;
int nLastSelStart, nLastSelEnd;
ME_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
ME_Paragraph *last_sel_start_para, *last_sel_end_para;
ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
int nZoomNumerator, nZoomDenominator;
RECT prevClientRect;

View file

@ -1312,8 +1312,8 @@ void editor_ensure_visible( ME_TextEditor *editor, ME_Cursor *cursor )
void
ME_InvalidateSelection(ME_TextEditor *editor)
{
ME_DisplayItem *sel_start, *sel_end;
ME_DisplayItem *repaint_start = NULL, *repaint_end = NULL;
ME_Paragraph *sel_start, *sel_end;
ME_Paragraph *repaint_start = NULL, *repaint_end = NULL;
int nStart, nEnd;
int len = ME_GetTextLength(editor);
@ -1323,41 +1323,47 @@ ME_InvalidateSelection(ME_TextEditor *editor)
if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
return;
ME_WrapMarkedParagraphs(editor);
ME_GetSelectionParas(editor, &sel_start, &sel_end);
assert(sel_start->type == diParagraph);
assert(sel_end->type == diParagraph);
editor_get_selection_paras( editor, &sel_start, &sel_end );
/* last selection markers aren't always updated, which means
* they can point past the end of the document */
if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
repaint_start = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
repaint_end = editor->pBuffer->pLast->member.para.prev_para;
} else {
if (editor->nLastSelStart > len || editor->nLastSelEnd > len)
{
repaint_start = editor_first_para( editor );
repaint_end = para_prev( editor_end_para( editor ) );
}
else
{
/* if the start part of selection is being expanded or contracted... */
if (nStart < editor->nLastSelStart) {
if (nStart < editor->nLastSelStart)
{
repaint_start = sel_start;
repaint_end = editor->pLastSelStartPara;
} else if (nStart > editor->nLastSelStart) {
repaint_start = editor->pLastSelStartPara;
repaint_end = editor->last_sel_start_para;
}
else if (nStart > editor->nLastSelStart)
{
repaint_start = editor->last_sel_start_para;
repaint_end = sel_start;
}
/* if the end part of selection is being contracted or expanded... */
if (nEnd < editor->nLastSelEnd) {
if (nEnd < editor->nLastSelEnd)
{
if (!repaint_start) repaint_start = sel_end;
repaint_end = editor->pLastSelEndPara;
} else if (nEnd > editor->nLastSelEnd) {
if (!repaint_start) repaint_start = editor->pLastSelEndPara;
repaint_end = editor->last_sel_end_para;
}
else if (nEnd > editor->nLastSelEnd)
{
if (!repaint_start) repaint_start = editor->last_sel_end_para;
repaint_end = sel_end;
}
}
if (repaint_start)
para_range_invalidate( editor, &repaint_start->member.para, &repaint_end->member.para );
para_range_invalidate( editor, repaint_start, repaint_end );
/* remember the last invalidated position */
ME_GetSelectionOfs(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
assert(editor->pLastSelStartPara->type == diParagraph);
assert(editor->pLastSelEndPara->type == diParagraph);
editor_get_selection_paras( editor, &editor->last_sel_start_para, &editor->last_sel_end_para );
}
BOOL

View file

@ -33,7 +33,7 @@ static ME_Paragraph *para_create( ME_TextEditor *editor )
{
ME_DisplayItem *item = ME_MakeDI(diParagraph);
ME_SetDefaultParaFormat(editor, &item->member.para.fmt);
editor_set_default_para_fmt( editor, &item->member.para.fmt );
item->member.para.nFlags = MEPF_REWRAP;
return &item->member.para;
@ -459,7 +459,7 @@ static void para_num_clear_list( ME_TextEditor *editor, ME_Paragraph *para, cons
} while (para_num_same_list( &para->fmt, orig_fmt ));
}
static BOOL ME_SetParaFormat(ME_TextEditor *editor, ME_Paragraph *para, const PARAFORMAT2 *pFmt)
static BOOL para_set_fmt( ME_TextEditor *editor, ME_Paragraph *para, const PARAFORMAT2 *pFmt )
{
PARAFORMAT2 copy;
DWORD dwMask;
@ -782,10 +782,10 @@ ME_Paragraph *para_join( ME_TextEditor *editor, ME_Paragraph *para, BOOL use_fir
ME_Remove( run_get_di( end_run ) );
ME_DestroyDisplayItem( run_get_di( end_run) );
if (editor->pLastSelStartPara == para_get_di( next ))
editor->pLastSelStartPara = para_get_di( para );
if (editor->pLastSelEndPara == para_get_di( next ))
editor->pLastSelEndPara = para_get_di( para );
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;
para->next_para = next->next_para;
next->next_para->member.para.prev_para = para_get_di( para );
@ -868,18 +868,18 @@ void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048])
#undef DUMP_EFFECT
}
void
ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end)
void editor_get_selection_paras( ME_TextEditor *editor, ME_Paragraph **para, ME_Paragraph **para_end )
{
ME_Cursor *pEndCursor = &editor->pCursors[1];
*para = editor->pCursors[0].pPara;
*para_end = editor->pCursors[1].pPara;
*para = &editor->pCursors[0].pPara->member.para;
*para_end = &editor->pCursors[1].pPara->member.para;
if (*para == *para_end)
return;
if ((*para_end)->member.para.nCharOfs < (*para)->member.para.nCharOfs) {
ME_DisplayItem *tmp = *para;
if ((*para_end)->nCharOfs < (*para)->nCharOfs)
{
ME_Paragraph *tmp = *para;
*para = *para_end;
*para_end = tmp;
@ -889,79 +889,77 @@ ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayIte
/* The paragraph at the end of a non-empty selection isn't included
* if the selection ends at the start of the paragraph. */
if (!pEndCursor->pRun->member.run.nCharOfs && !pEndCursor->nOffset)
*para_end = (*para_end)->member.para.prev_para;
*para_end = para_prev( *para_end );
}
BOOL ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt)
BOOL editor_set_selection_para_fmt( ME_TextEditor *editor, const PARAFORMAT2 *fmt )
{
ME_DisplayItem *para, *para_end;
ME_Paragraph *para, *para_end;
ME_GetSelectionParas(editor, &para, &para_end);
editor_get_selection_paras( editor, &para, &para_end );
do {
ME_SetParaFormat(editor, &para->member.para, pFmt);
if (para == para_end)
break;
para = para->member.para.next_para;
} while(1);
do
{
para_set_fmt( editor, para, fmt );
if (para == para_end) break;
para = para_next( para );
} while(1);
return TRUE;
return TRUE;
}
static void ME_GetParaFormat(ME_TextEditor *editor,
const ME_DisplayItem *para,
PARAFORMAT2 *pFmt)
static void para_copy_fmt( const ME_Paragraph *para, PARAFORMAT2 *fmt )
{
UINT cbSize = pFmt->cbSize;
if (pFmt->cbSize >= sizeof(PARAFORMAT2)) {
*pFmt = para->member.para.fmt;
} else {
CopyMemory(pFmt, &para->member.para.fmt, pFmt->cbSize);
pFmt->dwMask &= PFM_ALL;
}
pFmt->cbSize = cbSize;
UINT size = fmt->cbSize;
if (fmt->cbSize >= sizeof(PARAFORMAT2))
*fmt = para->fmt;
else
{
memcpy( fmt, &para->fmt, fmt->cbSize );
fmt->dwMask &= PFM_ALL;
}
fmt->cbSize = size;
}
void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt)
void editor_get_selection_para_fmt( ME_TextEditor *editor, PARAFORMAT2 *fmt )
{
ME_DisplayItem *para, *para_end;
PARAFORMAT2 *curFmt;
ME_Paragraph *para, *para_end;
if (pFmt->cbSize < sizeof(PARAFORMAT))
if (fmt->cbSize < sizeof(PARAFORMAT))
{
pFmt->dwMask = 0;
fmt->dwMask = 0;
return;
}
ME_GetSelectionParas(editor, &para, &para_end);
editor_get_selection_paras( editor, &para, &para_end );
ME_GetParaFormat(editor, para, pFmt);
para_copy_fmt( para, fmt );
/* Invalidate values that change across the selected paragraphs. */
while (para != para_end)
{
para = para->member.para.next_para;
curFmt = &para->member.para.fmt;
para = para_next( para );
#define CHECK_FIELD(m, f) \
if (pFmt->f != curFmt->f) pFmt->dwMask &= ~(m);
if (fmt->f != para->fmt.f) fmt->dwMask &= ~(m);
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);
if (pFmt->dwMask & PFM_TABSTOPS)
if (fmt->dwMask & PFM_TABSTOPS)
{
if (pFmt->cTabCount != para->member.para.fmt.cTabCount ||
memcmp(pFmt->rgxTabs, curFmt->rgxTabs, curFmt->cTabCount*sizeof(int)))
pFmt->dwMask &= ~PFM_TABSTOPS;
if (fmt->cTabCount != para->fmt.cTabCount ||
memcmp(fmt->rgxTabs, para->fmt.rgxTabs, para->fmt.cTabCount * sizeof(int) ))
fmt->dwMask &= ~PFM_TABSTOPS;
}
if (pFmt->cbSize >= sizeof(PARAFORMAT2))
if (fmt->cbSize >= sizeof(PARAFORMAT2))
{
pFmt->dwMask &= ~((pFmt->wEffects ^ curFmt->wEffects) << 16);
fmt->dwMask &= ~((fmt->wEffects ^ para->fmt.wEffects) << 16);
CHECK_FIELD(PFM_SPACEBEFORE, dySpaceBefore);
CHECK_FIELD(PFM_SPACEAFTER, dySpaceAfter);
CHECK_FIELD(PFM_LINESPACING, dyLineSpacing);
@ -980,7 +978,7 @@ void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt)
}
}
void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt)
void editor_set_default_para_fmt( ME_TextEditor *editor, PARAFORMAT2 *pFmt )
{
const PARAFORMAT2 *host_fmt;
HRESULT hr;

View file

@ -2519,7 +2519,7 @@ static void SpecialChar (RTF_Info *info)
case rtfSect:
case rtfPar:
RTFFlushOutputBuffer(info);
ME_SetSelectionParaFormat(info->editor, &info->fmt);
editor_set_selection_para_fmt( info->editor, &info->fmt );
memset(&info->fmt, 0, sizeof(info->fmt));
info->fmt.cbSize = sizeof(info->fmt);
RTFPutUnicodeChar (info, '\r');