2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - Paragraph wrapping. Don't try to understand it. You've been
|
|
|
|
* warned !
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unsolved problems:
|
2005-04-16 12:48:35 +02:00
|
|
|
*
|
2005-03-05 12:19:14 +01:00
|
|
|
* - center and right align in WordPad omits all spaces at the start, we don't
|
|
|
|
* - objects/images are not handled yet
|
2005-04-16 12:48:35 +02:00
|
|
|
* - no tabs
|
|
|
|
*/
|
|
|
|
|
2013-02-12 16:48:14 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* calc_run_extent
|
|
|
|
*
|
|
|
|
* Updates the size of the run (fills width, ascent and descent). The height
|
|
|
|
* is calculated based on whole row's ascent and descent anyway, so no need
|
|
|
|
* to use it here.
|
|
|
|
*/
|
|
|
|
static void calc_run_extent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Run *run)
|
|
|
|
{
|
|
|
|
if (run->nFlags & MERF_HIDDEN) run->nWidth = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SIZE size = ME_GetRunSizeCommon( c, para, run, run->len, startx, &run->nAscent, &run->nDescent );
|
|
|
|
run->nWidth = size.cx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 15:30:47 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* split_run_extents
|
|
|
|
*
|
|
|
|
* Splits a run into two in a given place. It also updates the screen position
|
|
|
|
* and size (extent) of the newly generated runs.
|
|
|
|
*/
|
|
|
|
static ME_DisplayItem *split_run_extents(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar)
|
|
|
|
{
|
|
|
|
ME_TextEditor *editor = wc->context->editor;
|
|
|
|
ME_Run *run, *run2;
|
|
|
|
ME_Paragraph *para = &wc->pPara->member.para;
|
|
|
|
ME_Cursor cursor = {wc->pPara, item, nVChar};
|
|
|
|
|
|
|
|
assert(item->member.run.nCharOfs != -1);
|
|
|
|
if(TRACE_ON(richedit))
|
|
|
|
{
|
|
|
|
TRACE("Before check before split\n");
|
|
|
|
ME_CheckCharOffsets(editor);
|
|
|
|
TRACE("After check before split\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
run = &item->member.run;
|
|
|
|
|
|
|
|
TRACE("Before split: %s(%d, %d)\n", debugstr_run( run ),
|
|
|
|
run->pt.x, run->pt.y);
|
|
|
|
|
|
|
|
ME_SplitRunSimple(editor, &cursor);
|
|
|
|
|
|
|
|
run2 = &cursor.pRun->member.run;
|
|
|
|
|
2013-02-12 16:48:14 +01:00
|
|
|
calc_run_extent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run);
|
2013-02-07 15:30:47 +01:00
|
|
|
|
|
|
|
run2->pt.x = run->pt.x+run->nWidth;
|
|
|
|
run2->pt.y = run->pt.y;
|
|
|
|
|
|
|
|
if(TRACE_ON(richedit))
|
|
|
|
{
|
|
|
|
TRACE("Before check after split\n");
|
|
|
|
ME_CheckCharOffsets(editor);
|
|
|
|
TRACE("After check after split\n");
|
|
|
|
TRACE("After split: %s(%d, %d), %s(%d, %d)\n",
|
|
|
|
debugstr_run( run ), run->pt.x, run->pt.y,
|
|
|
|
debugstr_run( run2 ), run2->pt.x, run2->pt.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cursor.pRun;
|
|
|
|
}
|
|
|
|
|
2013-02-08 12:45:03 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* find_split_point
|
|
|
|
*
|
|
|
|
* Returns a character position to split inside the run given a run-relative
|
|
|
|
* pixel horizontal position. This version rounds left (ie. if the second
|
|
|
|
* character is at pixel position 8, then for cx=0..7 it returns 0).
|
|
|
|
*/
|
|
|
|
static int find_split_point( ME_Context *c, int cx, ME_Run *run )
|
|
|
|
{
|
|
|
|
if (!run->len || cx <= 0) return 0;
|
2013-02-18 14:43:48 +01:00
|
|
|
return ME_CharFromPointContext( c, cx, run, FALSE );
|
2013-02-08 12:45:03 +01:00
|
|
|
}
|
2013-02-07 15:30:47 +01:00
|
|
|
|
2007-12-14 07:45:28 +01:00
|
|
|
static ME_DisplayItem *ME_MakeRow(int height, int baseline, int width)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *item = ME_MakeDI(diStartRow);
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
item->member.row.nHeight = height;
|
|
|
|
item->member.row.nBaseline = baseline;
|
|
|
|
item->member.row.nWidth = width;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2009-02-06 07:09:56 +01:00
|
|
|
static void ME_BeginRow(ME_WrapContext *wc)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-08-13 05:15:32 +02:00
|
|
|
PARAFORMAT2 *pFmt;
|
2009-02-06 07:09:56 +01:00
|
|
|
ME_DisplayItem *para = wc->pPara;
|
|
|
|
|
2008-08-13 05:15:32 +02:00
|
|
|
pFmt = para->member.para.pFmt;
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->pRowStart = NULL;
|
|
|
|
wc->bOverflown = FALSE;
|
|
|
|
wc->pLastSplittableRun = NULL;
|
2008-10-10 23:50:44 +02:00
|
|
|
wc->bWordWrap = wc->context->editor->bWordWrap;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (para->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND)) {
|
|
|
|
wc->nAvailWidth = 0;
|
2008-10-10 23:50:44 +02:00
|
|
|
wc->bWordWrap = FALSE;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (para->member.para.nFlags & MEPF_ROWEND)
|
|
|
|
{
|
|
|
|
ME_Cell *cell = &ME_FindItemBack(para, diCell)->member.cell;
|
|
|
|
cell->nWidth = 0;
|
|
|
|
}
|
|
|
|
} else if (para->member.para.pCell) {
|
|
|
|
ME_Cell *cell = ¶->member.para.pCell->member.cell;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
width = cell->nRightBoundary;
|
|
|
|
if (cell->prev_cell)
|
|
|
|
width -= cell->prev_cell->member.cell.nRightBoundary;
|
2008-08-13 05:15:29 +02:00
|
|
|
if (!cell->prev_cell)
|
|
|
|
{
|
|
|
|
int rowIndent = ME_GetTableRowEnd(para)->member.para.pFmt->dxStartIndent;
|
|
|
|
width -= rowIndent;
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0);
|
|
|
|
|
|
|
|
wc->nAvailWidth = cell->nWidth
|
|
|
|
- (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
|
2008-10-10 23:50:44 +02:00
|
|
|
wc->bWordWrap = TRUE;
|
|
|
|
} else {
|
2009-02-02 07:32:20 +01:00
|
|
|
wc->nAvailWidth = wc->context->nAvailWidth
|
2008-12-18 07:56:49 +01:00
|
|
|
- (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
wc->pt.x = wc->context->pt.x;
|
2008-08-13 05:15:32 +02:00
|
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
|
|
pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
|
|
|
|
/* Shift the text down because of the border. */
|
|
|
|
wc->pt.y++;
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2007-12-14 07:45:28 +01:00
|
|
|
static void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *p, *row, *para;
|
2008-06-23 23:09:53 +02:00
|
|
|
BOOL bSkippingSpaces = TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
int ascent = 0, descent = 0, width=0, shift = 0, align = 0;
|
2008-08-13 05:15:32 +02:00
|
|
|
PARAFORMAT2 *pFmt;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* wrap text */
|
2009-02-06 07:09:56 +01:00
|
|
|
para = wc->pPara;
|
2008-08-13 05:15:32 +02:00
|
|
|
pFmt = para->member.para.pFmt;
|
2008-06-23 23:09:53 +02:00
|
|
|
|
|
|
|
for (p = pEnd->prev; p!=wc->pRowStart->prev; p = p->prev)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-06-23 23:09:53 +02:00
|
|
|
/* ENDPARA run shouldn't affect row height, except if it's the only run in the paragraph */
|
|
|
|
if (p->type==diRun && ((p==wc->pRowStart) || !(p->member.run.nFlags & MERF_ENDPARA))) { /* FIXME add more run types */
|
|
|
|
if (p->member.run.nAscent>ascent)
|
|
|
|
ascent = p->member.run.nAscent;
|
|
|
|
if (p->member.run.nDescent>descent)
|
|
|
|
descent = p->member.run.nDescent;
|
|
|
|
if (bSkippingSpaces)
|
|
|
|
{
|
|
|
|
/* Exclude space characters from run width.
|
|
|
|
* Other whitespace or delimiters are not treated this way. */
|
|
|
|
SIZE sz;
|
2013-01-31 14:48:00 +01:00
|
|
|
int len = p->member.run.len;
|
2013-01-30 16:10:20 +01:00
|
|
|
WCHAR *text = get_text( &p->member.run, len - 1 );
|
2008-06-23 23:09:53 +02:00
|
|
|
|
|
|
|
assert (len);
|
2009-03-11 00:01:09 +01:00
|
|
|
if (~p->member.run.nFlags & MERF_GRAPHICS)
|
|
|
|
while (len && *(text--) == ' ')
|
2008-06-23 23:09:53 +02:00
|
|
|
len--;
|
|
|
|
if (len)
|
|
|
|
{
|
2013-01-31 14:48:00 +01:00
|
|
|
if (len == p->member.run.len)
|
2008-06-23 23:09:53 +02:00
|
|
|
{
|
|
|
|
width += p->member.run.nWidth;
|
|
|
|
} else {
|
|
|
|
sz = ME_GetRunSize(wc->context, ¶->member.para,
|
|
|
|
&p->member.run, len, p->member.run.pt.x);
|
|
|
|
width += sz.cx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bSkippingSpaces = !len;
|
|
|
|
} else if (!(p->member.run.nFlags & MERF_ENDPARA))
|
|
|
|
width += p->member.run.nWidth;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-06-23 23:09:53 +02:00
|
|
|
|
2009-01-14 19:24:02 +01:00
|
|
|
para->member.para.nWidth = max(para->member.para.nWidth, width);
|
2005-03-05 12:19:14 +01:00
|
|
|
row = ME_MakeRow(ascent+descent, ascent, width);
|
2008-08-13 05:15:32 +02:00
|
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
|
|
pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
|
|
|
|
{
|
|
|
|
/* The text was shifted down in ME_BeginRow so move the wrap context
|
|
|
|
* back to where it should be. */
|
|
|
|
wc->pt.y--;
|
|
|
|
/* The height of the row is increased by the borders. */
|
|
|
|
row->member.row.nHeight += 2;
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
row->member.row.pt = wc->pt;
|
2005-03-05 12:19:14 +01:00
|
|
|
row->member.row.nLMargin = (!wc->nRow ? wc->nFirstMargin : wc->nLeftMargin);
|
|
|
|
row->member.row.nRMargin = wc->nRightMargin;
|
|
|
|
assert(para->member.para.pFmt->dwMask & PFM_ALIGNMENT);
|
|
|
|
align = para->member.para.pFmt->wAlignment;
|
|
|
|
if (align == PFA_CENTER)
|
2008-10-10 23:50:44 +02:00
|
|
|
shift = max((wc->nAvailWidth-width)/2, 0);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (align == PFA_RIGHT)
|
2008-10-10 23:50:44 +02:00
|
|
|
shift = max(wc->nAvailWidth-width, 0);
|
2013-02-26 14:19:49 +01:00
|
|
|
row->member.row.pt.x = row->member.row.nLMargin + shift;
|
2005-03-05 12:19:14 +01:00
|
|
|
for (p = wc->pRowStart; p!=pEnd; p = p->next)
|
|
|
|
{
|
|
|
|
if (p->type==diRun) { /* FIXME add more run types */
|
|
|
|
p->member.run.pt.x += row->member.row.nLMargin+shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ME_InsertBefore(wc->pRowStart, row);
|
|
|
|
wc->nRow++;
|
2008-08-13 05:15:32 +02:00
|
|
|
wc->pt.y += row->member.row.nHeight;
|
2009-02-06 07:09:56 +01:00
|
|
|
ME_BeginRow(wc);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2005-07-06 17:53:04 +02:00
|
|
|
static void ME_WrapEndParagraph(ME_WrapContext *wc, ME_DisplayItem *p)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2009-02-06 07:09:56 +01:00
|
|
|
ME_DisplayItem *para = wc->pPara;
|
2008-08-13 05:15:32 +02:00
|
|
|
PARAFORMAT2 *pFmt = para->member.para.pFmt;
|
2005-03-05 12:19:14 +01:00
|
|
|
if (wc->pRowStart)
|
2008-06-23 23:09:53 +02:00
|
|
|
ME_InsertRowStart(wc, p);
|
2008-08-13 05:15:32 +02:00
|
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
|
|
pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
|
|
|
|
{
|
|
|
|
/* ME_BeginRow was called an extra time for the paragraph, and it shifts the
|
|
|
|
* text down by one pixel for the border, so fix up the wrap context. */
|
|
|
|
wc->pt.y--;
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/*
|
2009-02-06 07:09:56 +01:00
|
|
|
p = para->next;
|
2005-03-05 12:19:14 +01:00
|
|
|
while(p) {
|
|
|
|
if (p->type == diParagraph || p->type == diTextEnd)
|
|
|
|
return;
|
|
|
|
if (p->type == diRun)
|
|
|
|
{
|
|
|
|
ME_Run *run = &p->member.run;
|
2013-01-30 16:10:19 +01:00
|
|
|
TRACE("%s - (%d, %d)\n", debugstr_run(run), run->pt.x, run->pt.y);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
*/
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2005-07-06 17:53:04 +02:00
|
|
|
static void ME_WrapSizeRun(ME_WrapContext *wc, ME_DisplayItem *p)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
/* FIXME compose style (out of character and paragraph styles) here */
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_UpdateRunFlags(wc->context->editor, &p->member.run);
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2013-02-12 16:48:14 +01:00
|
|
|
calc_run_extent(wc->context, &wc->pPara->member.para,
|
|
|
|
wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, &p->member.run);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2013-02-05 14:19:40 +01:00
|
|
|
|
|
|
|
static int find_non_whitespace(const WCHAR *s, int len, int start)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = start; i < len && ME_IsWSpace( s[i] ); i++)
|
|
|
|
;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note: these two really return the first matching offset (starting from EOS)+1
|
|
|
|
* in other words, an offset of the first trailing white/black */
|
|
|
|
|
|
|
|
/* note: returns offset of the first trailing whitespace */
|
|
|
|
static int reverse_find_non_whitespace(const WCHAR *s, int start)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = start; i > 0 && ME_IsWSpace( s[i - 1] ); i--)
|
|
|
|
;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note: returns offset of the first trailing nonwhitespace */
|
|
|
|
static int reverse_find_whitespace(const WCHAR *s, int start)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = start; i > 0 && !ME_IsWSpace( s[i - 1] ); i--)
|
|
|
|
;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2005-07-06 17:53:04 +02:00
|
|
|
static ME_DisplayItem *ME_MaximizeSplit(ME_WrapContext *wc, ME_DisplayItem *p, int i)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pp, *piter = p;
|
|
|
|
int j;
|
|
|
|
if (!i)
|
|
|
|
return NULL;
|
2013-02-05 14:19:40 +01:00
|
|
|
j = reverse_find_non_whitespace( get_text( &p->member.run, 0 ), i);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (j>0) {
|
2013-02-07 15:30:47 +01:00
|
|
|
pp = split_run_extents(wc, piter, j);
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->pt.x += piter->member.run.nWidth;
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pp = piter;
|
|
|
|
/* omit all spaces before split point */
|
|
|
|
while(piter != wc->pRowStart)
|
|
|
|
{
|
|
|
|
piter = ME_FindItemBack(piter, diRun);
|
2005-04-16 12:48:35 +02:00
|
|
|
if (piter->member.run.nFlags & MERF_WHITESPACE)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
pp = piter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (piter->member.run.nFlags & MERF_ENDWHITE)
|
|
|
|
{
|
2013-02-05 14:19:40 +01:00
|
|
|
i = reverse_find_non_whitespace( get_text( &piter->member.run, 0 ),
|
|
|
|
piter->member.run.len );
|
2013-02-07 15:30:47 +01:00
|
|
|
pp = split_run_extents(wc, piter, i);
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->pt = pp->member.run.pt;
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
/* this run is the end of spaces, so the run edge is a good point to split */
|
|
|
|
wc->pt = pp->member.run.pt;
|
|
|
|
wc->bOverflown = TRUE;
|
2013-01-30 16:10:19 +01:00
|
|
|
TRACE("Split point is: %s|%s\n", debugstr_run( &piter->member.run ), debugstr_run( &pp->member.run ));
|
2005-03-05 12:19:14 +01:00
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
wc->pt = piter->member.run.pt;
|
|
|
|
return piter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-06 17:53:04 +02:00
|
|
|
static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem *p, int loc)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *piter = p, *pp;
|
|
|
|
int i, idesp, len;
|
|
|
|
ME_Run *run = &p->member.run;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2013-02-08 12:45:03 +01:00
|
|
|
idesp = i = find_split_point( wc->context, loc, run );
|
2013-01-31 14:48:00 +01:00
|
|
|
len = run->len;
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(len>0);
|
|
|
|
assert(i<len);
|
|
|
|
if (i) {
|
|
|
|
/* don't split words */
|
2013-02-05 14:19:40 +01:00
|
|
|
i = reverse_find_whitespace( get_text( run, 0 ), i );
|
2005-03-05 12:19:14 +01:00
|
|
|
pp = ME_MaximizeSplit(wc, p, i);
|
|
|
|
if (pp)
|
|
|
|
return pp;
|
|
|
|
}
|
2013-01-30 16:10:19 +01:00
|
|
|
TRACE("Must backtrack to split at: %s\n", debugstr_run( &p->member.run ));
|
2005-03-05 12:19:14 +01:00
|
|
|
if (wc->pLastSplittableRun)
|
|
|
|
{
|
2005-04-16 12:48:35 +02:00
|
|
|
if (wc->pLastSplittableRun->member.run.nFlags & (MERF_GRAPHICS|MERF_TAB))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2010-07-29 03:17:53 +02:00
|
|
|
wc->pt = wc->pLastSplittableRun->member.run.pt;
|
2005-03-05 12:19:14 +01:00
|
|
|
return wc->pLastSplittableRun;
|
|
|
|
}
|
|
|
|
else if (wc->pLastSplittableRun->member.run.nFlags & MERF_SPLITTABLE)
|
|
|
|
{
|
|
|
|
/* the following two lines are just to check if we forgot to call UpdateRunFlags earlier,
|
|
|
|
they serve no other purpose */
|
|
|
|
ME_UpdateRunFlags(wc->context->editor, run);
|
|
|
|
assert((wc->pLastSplittableRun->member.run.nFlags & MERF_SPLITTABLE));
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
piter = wc->pLastSplittableRun;
|
|
|
|
run = &piter->member.run;
|
2013-01-31 14:48:00 +01:00
|
|
|
len = run->len;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* don't split words */
|
2013-02-05 14:19:40 +01:00
|
|
|
i = reverse_find_whitespace( get_text( run, 0 ), len );
|
2005-03-05 12:19:14 +01:00
|
|
|
if (i == len)
|
2013-02-05 14:19:40 +01:00
|
|
|
i = reverse_find_non_whitespace( get_text( run, 0 ), len );
|
2005-04-16 12:48:35 +02:00
|
|
|
if (i) {
|
2013-02-07 15:30:47 +01:00
|
|
|
ME_DisplayItem *piter2 = split_run_extents(wc, piter, i);
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->pt = piter2->member.run.pt;
|
|
|
|
return piter2;
|
|
|
|
}
|
|
|
|
/* splittable = must have whitespaces */
|
|
|
|
assert(0 == "Splittable, but no whitespaces");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* restart from the first run beginning with spaces */
|
2010-07-29 03:17:53 +02:00
|
|
|
wc->pt = wc->pLastSplittableRun->member.run.pt;
|
2005-03-05 12:19:14 +01:00
|
|
|
return wc->pLastSplittableRun;
|
|
|
|
}
|
|
|
|
}
|
2013-01-30 16:10:19 +01:00
|
|
|
TRACE("Backtracking failed, trying desperate: %s\n", debugstr_run( &p->member.run ));
|
2005-03-05 12:19:14 +01:00
|
|
|
/* OK, no better idea, so assume we MAY split words if we can split at all*/
|
|
|
|
if (idesp)
|
2013-02-07 15:30:47 +01:00
|
|
|
return split_run_extents(wc, piter, idesp);
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
|
|
|
if (wc->pRowStart && piter != wc->pRowStart)
|
|
|
|
{
|
|
|
|
/* don't need to break current run, because it's possible to split
|
|
|
|
before this run */
|
|
|
|
wc->bOverflown = TRUE;
|
|
|
|
return piter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* split point inside first character - no choice but split after that char */
|
2009-02-07 19:21:29 +01:00
|
|
|
if (len != 1) {
|
2005-03-05 12:19:14 +01:00
|
|
|
/* the run is more than 1 char, so we may split */
|
2013-02-07 15:30:47 +01:00
|
|
|
return split_run_extents(wc, piter, 1);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
/* the run is one char, can't split it */
|
|
|
|
return piter;
|
2005-04-16 12:48:35 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2005-07-06 17:53:04 +02:00
|
|
|
static ME_DisplayItem *ME_WrapHandleRun(ME_WrapContext *wc, ME_DisplayItem *p)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pp;
|
|
|
|
ME_Run *run;
|
|
|
|
int len;
|
|
|
|
|
2005-04-16 12:48:35 +02:00
|
|
|
assert(p->type == diRun);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (!wc->pRowStart)
|
|
|
|
wc->pRowStart = p;
|
|
|
|
run = &p->member.run;
|
|
|
|
run->pt.x = wc->pt.x;
|
|
|
|
run->pt.y = wc->pt.y;
|
2005-04-16 12:48:35 +02:00
|
|
|
ME_WrapSizeRun(wc, p);
|
2013-01-31 14:48:00 +01:00
|
|
|
len = run->len;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (wc->bOverflown) /* just skipping final whitespaces */
|
2005-04-16 12:48:35 +02:00
|
|
|
{
|
2008-07-10 16:17:30 +02:00
|
|
|
/* End paragraph run can't overflow to the next line by itself. */
|
|
|
|
if (run->nFlags & MERF_ENDPARA)
|
|
|
|
return p->next;
|
|
|
|
|
|
|
|
if (run->nFlags & MERF_WHITESPACE) {
|
2008-07-10 16:17:39 +02:00
|
|
|
wc->pt.x += run->nWidth;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* skip runs consisting of only whitespaces */
|
|
|
|
return p->next;
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (run->nFlags & MERF_STARTWHITE) {
|
|
|
|
/* try to split the run at the first non-white char */
|
|
|
|
int black;
|
2013-02-05 14:19:40 +01:00
|
|
|
black = find_non_whitespace( get_text( run, 0 ), run->len, 0 );
|
2005-03-05 12:19:14 +01:00
|
|
|
if (black) {
|
|
|
|
wc->bOverflown = FALSE;
|
2013-02-07 15:30:47 +01:00
|
|
|
pp = split_run_extents(wc, p, black);
|
2013-02-12 16:48:14 +01:00
|
|
|
calc_run_extent(wc->context, &wc->pPara->member.para,
|
|
|
|
wc->nRow ? wc->nLeftMargin : wc->nFirstMargin,
|
|
|
|
&pp->member.run);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_InsertRowStart(wc, pp);
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* black run: the row goes from pRowStart to the previous run */
|
|
|
|
ME_InsertRowStart(wc, p);
|
|
|
|
return p;
|
|
|
|
}
|
2008-03-16 21:46:36 +01:00
|
|
|
/* simply end the current row and move on to next one */
|
|
|
|
if (run->nFlags & MERF_ENDROW)
|
|
|
|
{
|
|
|
|
p = p->next;
|
|
|
|
ME_InsertRowStart(wc, p);
|
|
|
|
return p;
|
|
|
|
}
|
2008-03-16 21:47:08 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* will current run fit? */
|
2008-10-10 23:50:44 +02:00
|
|
|
if (wc->bWordWrap &&
|
|
|
|
wc->pt.x + run->nWidth - wc->context->pt.x > wc->nAvailWidth)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
int loc = wc->context->pt.x + wc->nAvailWidth - wc->pt.x;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* total white run ? */
|
|
|
|
if (run->nFlags & MERF_WHITESPACE) {
|
|
|
|
/* let the overflow logic handle it */
|
|
|
|
wc->bOverflown = TRUE;
|
|
|
|
return p;
|
|
|
|
}
|
2008-01-27 19:01:58 +01:00
|
|
|
/* TAB: we can split before */
|
|
|
|
if (run->nFlags & MERF_TAB) {
|
|
|
|
wc->bOverflown = TRUE;
|
2008-07-17 17:55:19 +02:00
|
|
|
if (wc->pRowStart == p)
|
|
|
|
/* Don't split before the start of the run, or we will get an
|
|
|
|
* endless loop. */
|
|
|
|
return p->next;
|
|
|
|
else
|
|
|
|
return p;
|
2008-01-27 19:01:58 +01:00
|
|
|
}
|
|
|
|
/* graphics: we can split before, if run's width is smaller than row's width */
|
|
|
|
if ((run->nFlags & MERF_GRAPHICS) && run->nWidth <= wc->nAvailWidth) {
|
2005-03-05 12:19:14 +01:00
|
|
|
wc->bOverflown = TRUE;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
/* can we separate out the last spaces ? (to use overflow logic later) */
|
|
|
|
if (run->nFlags & MERF_ENDWHITE)
|
|
|
|
{
|
|
|
|
/* we aren't sure if it's *really* necessary, it's a good start however */
|
2013-02-05 14:19:40 +01:00
|
|
|
int black = reverse_find_non_whitespace( get_text( run, 0 ), len );
|
2013-02-07 15:30:47 +01:00
|
|
|
split_run_extents(wc, p, black);
|
2005-03-05 12:19:14 +01:00
|
|
|
/* handle both parts again */
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
/* determine the split point by backtracking */
|
|
|
|
pp = ME_SplitByBacktracking(wc, p, loc);
|
|
|
|
if (pp == wc->pRowStart)
|
|
|
|
{
|
2008-07-10 16:17:43 +02:00
|
|
|
if (run->nFlags & MERF_STARTWHITE)
|
|
|
|
{
|
2008-10-03 06:49:39 +02:00
|
|
|
/* We had only spaces so far, so we must be on the first line of the
|
|
|
|
* paragraph (or the first line after MERF_ENDROW forced the line
|
|
|
|
* break within the paragraph), since no other lines of the paragraph
|
|
|
|
* start with spaces. */
|
|
|
|
|
2008-07-10 16:17:43 +02:00
|
|
|
/* The lines will only contain spaces, and the rest of the run will
|
|
|
|
* overflow onto the next line. */
|
|
|
|
wc->bOverflown = TRUE;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
/* Couldn't split the first run, possible because we have a large font
|
|
|
|
* with a single character that caused an overflow.
|
|
|
|
*/
|
2008-07-10 16:17:39 +02:00
|
|
|
wc->pt.x += run->nWidth;
|
2005-03-05 12:19:14 +01:00
|
|
|
return p->next;
|
|
|
|
}
|
|
|
|
if (p != pp) /* found a suitable split point */
|
|
|
|
{
|
|
|
|
wc->bOverflown = TRUE;
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
/* we detected that it's best to split on start of this run */
|
|
|
|
if (wc->bOverflown)
|
|
|
|
return pp;
|
|
|
|
ERR("failure!\n");
|
|
|
|
/* not found anything - writing over margins is the only option left */
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
if ((run->nFlags & (MERF_SPLITTABLE | MERF_STARTWHITE))
|
|
|
|
|| ((run->nFlags & (MERF_GRAPHICS|MERF_TAB)) && (p != wc->pRowStart)))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
wc->pLastSplittableRun = p;
|
|
|
|
}
|
|
|
|
wc->pt.x += run->nWidth;
|
|
|
|
return p->next;
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2010-02-09 18:07:22 +01:00
|
|
|
static int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
|
|
|
|
{
|
|
|
|
int sp = 0, ls = 0;
|
|
|
|
if (!(para->pFmt->dwMask & PFM_LINESPACING)) return 0;
|
|
|
|
|
|
|
|
/* FIXME: how to compute simply the line space in ls ??? */
|
|
|
|
/* FIXME: does line spacing include the line itself ??? */
|
|
|
|
switch (para->pFmt->bLineSpacingRule)
|
|
|
|
{
|
|
|
|
case 0: sp = ls; break;
|
|
|
|
case 1: sp = (3 * ls) / 2; break;
|
|
|
|
case 2: sp = 2 * ls; break;
|
|
|
|
case 3: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); if (sp < ls) sp = ls; break;
|
|
|
|
case 4: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); break;
|
|
|
|
case 5: sp = para->pFmt->dyLineSpacing / 20; break;
|
|
|
|
default: FIXME("Unsupported spacing rule value %d\n", para->pFmt->bLineSpacingRule);
|
|
|
|
}
|
|
|
|
if (c->editor->nZoomNumerator == 0)
|
|
|
|
return sp;
|
|
|
|
else
|
|
|
|
return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
|
|
|
|
}
|
|
|
|
|
2011-10-22 20:17:04 +02:00
|
|
|
static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp) {
|
2011-10-22 20:30:13 +02:00
|
|
|
ME_DisplayItem *p;
|
2011-10-22 20:17:04 +02:00
|
|
|
|
|
|
|
tp->member.para.nWidth = 0;
|
2011-10-22 20:30:13 +02:00
|
|
|
/* remove row start items as they will be reinserted by the
|
|
|
|
* paragraph wrapper anyway */
|
2011-10-22 20:17:04 +02:00
|
|
|
tp->member.para.nRows = 0;
|
2011-10-22 20:30:13 +02:00
|
|
|
for (p = tp->next; p != tp->member.para.next_para; p = p->next) {
|
|
|
|
if (p->type == diStartRow) {
|
|
|
|
ME_DisplayItem *pRow = p;
|
|
|
|
p = p->prev;
|
|
|
|
ME_Remove(pRow);
|
|
|
|
ME_DestroyDisplayItem(pRow);
|
2011-10-22 20:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-22 20:30:13 +02:00
|
|
|
/* join runs that can be joined */
|
|
|
|
for (p = tp->next; p != tp->member.para.next_para; p = p->next) {
|
|
|
|
assert(p->type != diStartRow); /* should have been deleted above */
|
|
|
|
if (p->type == diRun) {
|
|
|
|
while (p->next->type == diRun && /* FIXME */
|
|
|
|
ME_CanJoinRuns(&p->member.run, &p->next->member.run)) {
|
|
|
|
ME_JoinRuns(c->editor, p);
|
|
|
|
}
|
2011-10-22 20:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-14 07:45:28 +01:00
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp) {
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_DisplayItem *p;
|
|
|
|
ME_WrapContext wc;
|
2008-01-01 22:04:46 +01:00
|
|
|
int border = 0;
|
2008-01-01 22:04:58 +01:00
|
|
|
int linespace = 0;
|
2008-08-13 05:15:29 +02:00
|
|
|
PARAFORMAT2 *pFmt;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2005-04-16 12:48:35 +02:00
|
|
|
assert(tp->type == diParagraph);
|
2005-03-09 12:48:59 +01:00
|
|
|
if (!(tp->member.para.nFlags & MEPF_REWRAP)) {
|
2005-03-05 12:19:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ME_PrepareParagraphForWrapping(c, tp);
|
2008-08-13 05:15:29 +02:00
|
|
|
pFmt = tp->member.para.pFmt;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
wc.context = c;
|
2009-02-06 07:09:56 +01:00
|
|
|
wc.pPara = tp;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* wc.para_style = tp->member.para.style; */
|
|
|
|
wc.style = NULL;
|
2008-08-13 05:15:29 +02:00
|
|
|
if (tp->member.para.nFlags & MEPF_ROWEND) {
|
|
|
|
wc.nFirstMargin = wc.nLeftMargin = wc.nRightMargin = 0;
|
|
|
|
} else {
|
|
|
|
int dxStartIndent = pFmt->dxStartIndent;
|
|
|
|
if (tp->member.para.pCell) {
|
|
|
|
dxStartIndent += ME_GetTableRowEnd(tp)->member.para.pFmt->dxOffset;
|
|
|
|
}
|
|
|
|
wc.nFirstMargin = ME_twips2pointsX(c, dxStartIndent);
|
|
|
|
wc.nLeftMargin = wc.nFirstMargin + ME_twips2pointsX(c, pFmt->dxOffset);
|
|
|
|
wc.nRightMargin = ME_twips2pointsX(c, pFmt->dxRightIndent);
|
|
|
|
}
|
|
|
|
if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
|
|
pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
|
|
|
|
{
|
|
|
|
wc.nFirstMargin += ME_twips2pointsX(c, pFmt->dxOffset * 2);
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
wc.nRow = 0;
|
|
|
|
wc.pt.y = 0;
|
2008-08-13 05:15:29 +02:00
|
|
|
if (pFmt->dwMask & PFM_SPACEBEFORE)
|
|
|
|
wc.pt.y += ME_twips2pointsY(c, pFmt->dySpaceBefore);
|
|
|
|
if (!(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) &&
|
|
|
|
pFmt->dwMask & PFM_BORDER)
|
2008-01-01 22:04:46 +01:00
|
|
|
{
|
2010-02-27 19:31:02 +01:00
|
|
|
border = ME_GetParaBorderWidth(c, tp->member.para.pFmt->wBorders);
|
2008-08-13 05:15:29 +02:00
|
|
|
if (pFmt->wBorders & 1) {
|
2008-01-01 22:04:46 +01:00
|
|
|
wc.nFirstMargin += border;
|
|
|
|
wc.nLeftMargin += border;
|
|
|
|
}
|
2008-08-13 05:15:29 +02:00
|
|
|
if (pFmt->wBorders & 2)
|
2008-01-01 22:04:46 +01:00
|
|
|
wc.nRightMargin -= border;
|
2008-08-13 05:15:29 +02:00
|
|
|
if (pFmt->wBorders & 4)
|
2008-01-01 22:04:46 +01:00
|
|
|
wc.pt.y += border;
|
|
|
|
}
|
|
|
|
|
2008-01-01 22:05:33 +01:00
|
|
|
linespace = ME_GetParaLineSpace(c, &tp->member.para);
|
2008-01-01 22:04:58 +01:00
|
|
|
|
2009-02-06 07:09:56 +01:00
|
|
|
ME_BeginRow(&wc);
|
2005-03-05 12:19:14 +01:00
|
|
|
for (p = tp->next; p!=tp->member.para.next_para; ) {
|
|
|
|
assert(p->type != diStartRow);
|
|
|
|
if (p->type == diRun) {
|
|
|
|
p = ME_WrapHandleRun(&wc, p);
|
|
|
|
}
|
2008-01-01 22:04:58 +01:00
|
|
|
else p = p->next;
|
|
|
|
if (wc.nRow && p == wc.pRowStart)
|
|
|
|
wc.pt.y += linespace;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
ME_WrapEndParagraph(&wc, p);
|
2008-08-13 05:15:29 +02:00
|
|
|
if (!(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) &&
|
|
|
|
(pFmt->dwMask & PFM_BORDER) && (pFmt->wBorders & 8))
|
2008-01-01 22:04:46 +01:00
|
|
|
wc.pt.y += border;
|
2008-01-01 22:04:52 +01:00
|
|
|
if (tp->member.para.pFmt->dwMask & PFM_SPACEAFTER)
|
2008-08-13 05:15:29 +02:00
|
|
|
wc.pt.y += ME_twips2pointsY(c, pFmt->dySpaceAfter);
|
2008-01-01 22:04:46 +01:00
|
|
|
|
2005-03-09 12:48:59 +01:00
|
|
|
tp->member.para.nFlags &= ~MEPF_REWRAP;
|
2005-03-05 12:19:14 +01:00
|
|
|
tp->member.para.nHeight = wc.pt.y;
|
2005-07-05 22:56:14 +02:00
|
|
|
tp->member.para.nRows = wc.nRow;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2012-05-09 09:13:31 +02:00
|
|
|
static void ME_MarkRepaintEnd(ME_DisplayItem *para,
|
|
|
|
ME_DisplayItem **repaint_start,
|
|
|
|
ME_DisplayItem **repaint_end)
|
|
|
|
{
|
|
|
|
if (!*repaint_start)
|
|
|
|
*repaint_start = para;
|
2012-05-18 06:30:03 +02:00
|
|
|
*repaint_end = para;
|
2012-05-09 09:13:31 +02:00
|
|
|
}
|
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
|
|
|
|
{
|
2005-03-09 12:48:59 +01:00
|
|
|
ME_DisplayItem *item;
|
|
|
|
ME_Context c;
|
2009-01-14 19:24:02 +01:00
|
|
|
int totalWidth = 0;
|
2012-05-09 09:13:31 +02:00
|
|
|
ME_DisplayItem *repaint_start = NULL, *repaint_end = NULL;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
|
2008-12-18 07:56:49 +01:00
|
|
|
c.pt.x = 0;
|
2005-03-09 12:48:59 +01:00
|
|
|
item = editor->pBuffer->pFirst->next;
|
|
|
|
while(item != editor->pBuffer->pLast) {
|
|
|
|
BOOL bRedraw = FALSE;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2005-03-09 12:48:59 +01:00
|
|
|
assert(item->type == diParagraph);
|
|
|
|
if ((item->member.para.nFlags & MEPF_REWRAP)
|
2008-08-07 18:31:41 +02:00
|
|
|
|| (item->member.para.pt.y != c.pt.y))
|
2005-03-09 12:48:59 +01:00
|
|
|
bRedraw = TRUE;
|
2008-08-07 18:31:41 +02:00
|
|
|
item->member.para.pt = c.pt;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
ME_WrapTextParagraph(&c, item);
|
2005-03-09 12:48:59 +01:00
|
|
|
|
|
|
|
if (bRedraw)
|
2012-05-09 09:13:31 +02:00
|
|
|
ME_MarkRepaintEnd(item, &repaint_start, &repaint_end);
|
2005-03-19 18:06:17 +01:00
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
if (item->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *cell = ME_FindItemFwd(item, diCell);
|
2008-08-13 05:15:29 +02:00
|
|
|
ME_DisplayItem *endRowPara;
|
2008-08-13 05:15:36 +02:00
|
|
|
int borderWidth = 0;
|
2008-08-07 18:31:41 +02:00
|
|
|
cell->member.cell.pt = c.pt;
|
2008-08-13 05:15:36 +02:00
|
|
|
/* Offset the text by the largest top border width. */
|
|
|
|
while (cell->member.cell.next_cell) {
|
|
|
|
borderWidth = max(borderWidth, cell->member.cell.border.top.width);
|
|
|
|
cell = cell->member.cell.next_cell;
|
|
|
|
}
|
|
|
|
endRowPara = ME_FindItemFwd(cell, diParagraph);
|
|
|
|
assert(endRowPara->member.para.nFlags & MEPF_ROWEND);
|
|
|
|
if (borderWidth > 0)
|
|
|
|
{
|
|
|
|
borderWidth = max(ME_twips2pointsY(&c, borderWidth), 1);
|
|
|
|
while (cell) {
|
|
|
|
cell->member.cell.yTextOffset = borderWidth;
|
|
|
|
cell = cell->member.cell.prev_cell;
|
|
|
|
}
|
|
|
|
c.pt.y += borderWidth;
|
|
|
|
}
|
2008-08-13 05:15:29 +02:00
|
|
|
if (endRowPara->member.para.pFmt->dxStartIndent > 0)
|
|
|
|
{
|
|
|
|
int dxStartIndent = endRowPara->member.para.pFmt->dxStartIndent;
|
|
|
|
cell = ME_FindItemFwd(item, diCell);
|
|
|
|
cell->member.cell.pt.x += ME_twips2pointsX(&c, dxStartIndent);
|
|
|
|
c.pt.x = cell->member.cell.pt.x;
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
else if (item->member.para.nFlags & MEPF_ROWEND)
|
|
|
|
{
|
|
|
|
/* Set all the cells to the height of the largest cell */
|
|
|
|
ME_DisplayItem *startRowPara;
|
2008-08-13 05:15:36 +02:00
|
|
|
int prevHeight, nHeight, bottomBorder = 0;
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_DisplayItem *cell = ME_FindItemBack(item, diCell);
|
2009-01-14 19:24:02 +01:00
|
|
|
item->member.para.nWidth = cell->member.cell.pt.x + cell->member.cell.nWidth;
|
2008-08-13 05:15:36 +02:00
|
|
|
if (!(item->member.para.next_para->member.para.nFlags & MEPF_ROWSTART))
|
|
|
|
{
|
|
|
|
/* Last row, the bottom border is added to the height. */
|
|
|
|
cell = cell->member.cell.prev_cell;
|
|
|
|
while (cell)
|
|
|
|
{
|
|
|
|
bottomBorder = max(bottomBorder, cell->member.cell.border.bottom.width);
|
|
|
|
cell = cell->member.cell.prev_cell;
|
|
|
|
}
|
|
|
|
bottomBorder = ME_twips2pointsY(&c, bottomBorder);
|
|
|
|
cell = ME_FindItemBack(item, diCell);
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
prevHeight = cell->member.cell.nHeight;
|
2008-08-13 05:15:36 +02:00
|
|
|
nHeight = cell->member.cell.prev_cell->member.cell.nHeight + bottomBorder;
|
2008-08-07 18:31:41 +02:00
|
|
|
cell->member.cell.nHeight = nHeight;
|
|
|
|
item->member.para.nHeight = nHeight;
|
|
|
|
cell = cell->member.cell.prev_cell;
|
2008-08-13 05:15:36 +02:00
|
|
|
cell->member.cell.nHeight = nHeight;
|
2008-08-07 18:31:41 +02:00
|
|
|
while (cell->member.cell.prev_cell)
|
|
|
|
{
|
|
|
|
cell = cell->member.cell.prev_cell;
|
|
|
|
cell->member.cell.nHeight = nHeight;
|
|
|
|
}
|
|
|
|
/* Also set the height of the start row paragraph */
|
|
|
|
startRowPara = ME_FindItemBack(cell, diParagraph);
|
|
|
|
startRowPara->member.para.nHeight = nHeight;
|
|
|
|
c.pt.x = startRowPara->member.para.pt.x;
|
|
|
|
c.pt.y = cell->member.cell.pt.y + nHeight;
|
|
|
|
if (prevHeight < nHeight)
|
|
|
|
{
|
|
|
|
/* The height of the cells has grown, so invalidate the bottom of
|
|
|
|
* the cells. */
|
2012-05-09 09:13:31 +02:00
|
|
|
ME_MarkRepaintEnd(item, &repaint_start, &repaint_end);
|
2008-08-07 18:31:41 +02:00
|
|
|
cell = ME_FindItemBack(item, diCell);
|
|
|
|
while (cell) {
|
2012-05-09 09:13:31 +02:00
|
|
|
ME_MarkRepaintEnd(ME_FindItemBack(cell, diParagraph), &repaint_start, &repaint_end);
|
2008-08-07 18:31:41 +02:00
|
|
|
cell = cell->member.cell.prev_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (item->member.para.pCell &&
|
|
|
|
item->member.para.pCell != item->member.para.next_para->member.para.pCell)
|
|
|
|
{
|
|
|
|
/* The next paragraph is in the next cell in the table row. */
|
|
|
|
ME_Cell *cell = &item->member.para.pCell->member.cell;
|
|
|
|
cell->nHeight = c.pt.y + item->member.para.nHeight - cell->pt.y;
|
|
|
|
|
|
|
|
/* Propagate the largest height to the end so that it can be easily
|
|
|
|
* sent back to all the cells at the end of the row. */
|
|
|
|
if (cell->prev_cell)
|
|
|
|
cell->nHeight = max(cell->nHeight, cell->prev_cell->member.cell.nHeight);
|
|
|
|
|
|
|
|
c.pt.x = cell->pt.x + cell->nWidth;
|
|
|
|
c.pt.y = cell->pt.y;
|
|
|
|
cell->next_cell->member.cell.pt = c.pt;
|
2008-12-19 15:54:58 +01:00
|
|
|
if (!(item->member.para.next_para->member.para.nFlags & MEPF_ROWEND))
|
|
|
|
c.pt.y += cell->yTextOffset;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (item->member.para.pCell) {
|
|
|
|
/* Next paragraph in the same cell. */
|
|
|
|
c.pt.x = item->member.para.pCell->member.cell.pt.x;
|
|
|
|
} else {
|
|
|
|
/* Normal paragraph */
|
2008-12-18 07:56:49 +01:00
|
|
|
c.pt.x = 0;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
c.pt.y += item->member.para.nHeight;
|
|
|
|
}
|
2009-01-14 19:24:02 +01:00
|
|
|
|
|
|
|
totalWidth = max(totalWidth, item->member.para.nWidth);
|
2005-03-09 12:48:59 +01:00
|
|
|
item = item->member.para.next_para;
|
|
|
|
}
|
|
|
|
editor->sizeWindow.cx = c.rcView.right-c.rcView.left;
|
|
|
|
editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2005-03-09 19:43:18 +01:00
|
|
|
editor->nTotalLength = c.pt.y;
|
2009-01-14 19:24:02 +01:00
|
|
|
editor->nTotalWidth = totalWidth;
|
2008-08-07 18:31:41 +02:00
|
|
|
editor->pBuffer->pLast->member.para.pt.x = 0;
|
2008-12-19 14:15:04 +01:00
|
|
|
editor->pBuffer->pLast->member.para.pt.y = c.pt.y;
|
2005-04-16 12:48:35 +02:00
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ME_DestroyContext(&c);
|
2008-03-16 21:48:13 +01:00
|
|
|
|
2012-05-09 09:13:31 +02:00
|
|
|
if (repaint_start || editor->nTotalLength < editor->nLastTotalLength)
|
2012-05-18 06:30:03 +02:00
|
|
|
ME_InvalidateParagraphRange(editor, repaint_start, repaint_end);
|
2012-05-09 09:13:31 +02:00
|
|
|
return !!repaint_start;
|
2006-08-07 17:27:16 +02:00
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2012-05-18 06:30:03 +02:00
|
|
|
void ME_InvalidateParagraphRange(ME_TextEditor *editor,
|
|
|
|
ME_DisplayItem *start_para,
|
|
|
|
ME_DisplayItem *last_para)
|
2008-10-19 10:43:17 +02:00
|
|
|
{
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_Context c;
|
2008-10-19 10:43:17 +02:00
|
|
|
RECT rc;
|
|
|
|
int ofs;
|
2006-08-07 17:27:16 +02:00
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
|
2008-10-19 10:43:17 +02:00
|
|
|
rc = c.rcView;
|
2009-01-14 19:24:02 +01:00
|
|
|
ofs = editor->vert_si.nPos;
|
2008-10-19 10:43:17 +02:00
|
|
|
|
2012-05-18 06:30:03 +02:00
|
|
|
if (start_para) {
|
|
|
|
start_para = ME_GetOuterParagraph(start_para);
|
|
|
|
last_para = ME_GetOuterParagraph(last_para);
|
|
|
|
rc.top = c.rcView.top + start_para->member.para.pt.y - ofs;
|
|
|
|
} else {
|
|
|
|
rc.top = c.rcView.top + editor->nTotalLength - ofs;
|
2008-10-19 10:43:17 +02:00
|
|
|
}
|
|
|
|
if (editor->nTotalLength < editor->nLastTotalLength)
|
2008-12-18 07:56:49 +01:00
|
|
|
rc.bottom = c.rcView.top + editor->nLastTotalLength - ofs;
|
2012-05-18 06:30:03 +02:00
|
|
|
else
|
|
|
|
rc.bottom = c.rcView.top + last_para->member.para.pt.y + last_para->member.para.nHeight - ofs;
|
|
|
|
ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
|
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ME_DestroyContext(&c);
|
2005-03-09 12:48:59 +01:00
|
|
|
}
|
2005-11-03 10:52:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ME_SendRequestResize(ME_TextEditor *editor, BOOL force)
|
|
|
|
{
|
|
|
|
if (editor->nEventMask & ENM_REQUESTRESIZE)
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxGetClientRect(editor->texthost, &rc);
|
2005-11-03 10:52:29 +01:00
|
|
|
|
|
|
|
if (force || rc.bottom != editor->nTotalLength)
|
|
|
|
{
|
|
|
|
REQRESIZE info;
|
|
|
|
|
2009-09-28 09:44:19 +02:00
|
|
|
info.nmhdr.hwndFrom = NULL;
|
|
|
|
info.nmhdr.idFrom = 0;
|
2005-11-03 10:52:29 +01:00
|
|
|
info.nmhdr.code = EN_REQUESTRESIZE;
|
|
|
|
info.rc = rc;
|
2009-01-14 19:24:02 +01:00
|
|
|
info.rc.right = editor->nTotalWidth;
|
2005-11-03 10:52:29 +01:00
|
|
|
info.rc.bottom = editor->nTotalLength;
|
2008-01-01 22:03:52 +01:00
|
|
|
|
|
|
|
editor->nEventMask &= ~ENM_REQUESTRESIZE;
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxNotify(editor->texthost, info.nmhdr.code, &info);
|
2008-01-01 22:03:52 +01:00
|
|
|
editor->nEventMask |= ENM_REQUESTRESIZE;
|
2005-11-03 10:52:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|