2 * RichEdit - Paragraph wrapping. Don't try to understand it. You've been
5 * Copyright 2004 by Krzysztof Foltman
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
30 * - center and right align in WordPad omits all spaces at the start, we don't
31 * - objects/images are not handled yet
35 static ME_DisplayItem *ME_MakeRow(int height, int baseline, int width)
37 ME_DisplayItem *item = ME_MakeDI(diStartRow);
39 item->member.row.nHeight = height;
40 item->member.row.nBaseline = baseline;
41 item->member.row.nWidth = width;
45 static void ME_BeginRow(ME_WrapContext *wc, ME_DisplayItem *para)
48 assert(para && para->type == diParagraph);
49 pFmt = para->member.para.pFmt;
51 wc->bOverflown = FALSE;
52 wc->pLastSplittableRun = NULL;
53 wc->bWordWrap = wc->context->editor->bWordWrap;
54 if (para->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND)) {
56 wc->bWordWrap = FALSE;
57 if (para->member.para.nFlags & MEPF_ROWEND)
59 ME_Cell *cell = &ME_FindItemBack(para, diCell)->member.cell;
62 } else if (para->member.para.pCell) {
63 ME_Cell *cell = ¶->member.para.pCell->member.cell;
66 width = cell->nRightBoundary;
68 width -= cell->prev_cell->member.cell.nRightBoundary;
71 int rowIndent = ME_GetTableRowEnd(para)->member.para.pFmt->dxStartIndent;
74 cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0);
76 wc->nAvailWidth = cell->nWidth
77 - (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
80 wc->nAvailWidth = wc->context->rcView.right - wc->context->rcView.left
81 - (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
83 wc->pt.x = wc->context->pt.x;
84 if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
85 pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
86 /* Shift the text down because of the border. */
90 static void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd)
92 ME_DisplayItem *p, *row, *para;
93 BOOL bSkippingSpaces = TRUE;
94 int ascent = 0, descent = 0, width=0, shift = 0, align = 0;
97 para = ME_GetParagraph(wc->pRowStart);
98 pFmt = para->member.para.pFmt;
100 for (p = pEnd->prev; p!=wc->pRowStart->prev; p = p->prev)
102 /* ENDPARA run shouldn't affect row height, except if it's the only run in the paragraph */
103 if (p->type==diRun && ((p==wc->pRowStart) || !(p->member.run.nFlags & MERF_ENDPARA))) { /* FIXME add more run types */
104 if (p->member.run.nAscent>ascent)
105 ascent = p->member.run.nAscent;
106 if (p->member.run.nDescent>descent)
107 descent = p->member.run.nDescent;
110 /* Exclude space characters from run width.
111 * Other whitespace or delimiters are not treated this way. */
113 int len = p->member.run.strText->nLen;
114 WCHAR *text = p->member.run.strText->szData + len - 1;
117 while (len && *(text--) == ' ')
121 if (len == p->member.run.strText->nLen)
123 width += p->member.run.nWidth;
125 sz = ME_GetRunSize(wc->context, ¶->member.para,
126 &p->member.run, len, p->member.run.pt.x);
130 bSkippingSpaces = !len;
131 } else if (!(p->member.run.nFlags & MERF_ENDPARA))
132 width += p->member.run.nWidth;
136 para->member.para.nWidth = max(para->member.para.nWidth, width);
137 row = ME_MakeRow(ascent+descent, ascent, width);
138 if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
139 pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
141 /* The text was shifted down in ME_BeginRow so move the wrap context
142 * back to where it should be. */
144 /* The height of the row is increased by the borders. */
145 row->member.row.nHeight += 2;
147 row->member.row.pt = wc->pt;
148 row->member.row.nLMargin = (!wc->nRow ? wc->nFirstMargin : wc->nLeftMargin);
149 row->member.row.nRMargin = wc->nRightMargin;
150 assert(para->member.para.pFmt->dwMask & PFM_ALIGNMENT);
151 align = para->member.para.pFmt->wAlignment;
152 if (align == PFA_CENTER)
153 shift = max((wc->nAvailWidth-width)/2, 0);
154 if (align == PFA_RIGHT)
155 shift = max(wc->nAvailWidth-width, 0);
156 for (p = wc->pRowStart; p!=pEnd; p = p->next)
158 if (p->type==diRun) { /* FIXME add more run types */
159 p->member.run.pt.x += row->member.row.nLMargin+shift;
162 ME_InsertBefore(wc->pRowStart, row);
164 wc->pt.y += row->member.row.nHeight;
165 ME_BeginRow(wc, para);
168 static void ME_WrapEndParagraph(ME_WrapContext *wc, ME_DisplayItem *p)
170 ME_DisplayItem *para = p->member.para.prev_para;
171 PARAFORMAT2 *pFmt = para->member.para.pFmt;
173 ME_InsertRowStart(wc, p);
174 if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
175 pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
177 /* ME_BeginRow was called an extra time for the paragraph, and it shifts the
178 * text down by one pixel for the border, so fix up the wrap context. */
183 p = p->member.para.prev_para->next;
185 if (p->type == diParagraph || p->type == diTextEnd)
187 if (p->type == diRun)
189 ME_Run *run = &p->member.run;
190 TRACE("%s - (%d, %d)\n", debugstr_w(run->strText->szData), run->pt.x, run->pt.y);
197 static void ME_WrapSizeRun(ME_WrapContext *wc, ME_DisplayItem *p)
199 /* FIXME compose style (out of character and paragraph styles) here */
201 ME_UpdateRunFlags(wc->context->editor, &p->member.run);
203 ME_CalcRunExtent(wc->context, &ME_GetParagraph(p)->member.para,
204 wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, &p->member.run);
207 static ME_DisplayItem *ME_MaximizeSplit(ME_WrapContext *wc, ME_DisplayItem *p, int i)
209 ME_DisplayItem *pp, *piter = p;
213 j = ME_ReverseFindNonWhitespaceV(p->member.run.strText, i);
215 pp = ME_SplitRun(wc, piter, j);
216 wc->pt.x += piter->member.run.nWidth;
222 /* omit all spaces before split point */
223 while(piter != wc->pRowStart)
225 piter = ME_FindItemBack(piter, diRun);
226 if (piter->member.run.nFlags & MERF_WHITESPACE)
231 if (piter->member.run.nFlags & MERF_ENDWHITE)
233 j = ME_ReverseFindNonWhitespaceV(piter->member.run.strText, i);
234 pp = ME_SplitRun(wc, piter, i);
235 wc->pt = pp->member.run.pt;
238 /* this run is the end of spaces, so the run edge is a good point to split */
239 wc->pt = pp->member.run.pt;
240 wc->bOverflown = TRUE;
241 TRACE("Split point is: %s|%s\n", debugstr_w(piter->member.run.strText->szData), debugstr_w(pp->member.run.strText->szData));
244 wc->pt = piter->member.run.pt;
249 static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem *p, int loc)
251 ME_DisplayItem *piter = p, *pp;
253 ME_Run *run = &p->member.run;
255 idesp = i = ME_CharFromPoint(wc->context, loc, run);
256 len = ME_StrVLen(run->strText);
260 /* don't split words */
261 i = ME_ReverseFindWhitespaceV(run->strText, i);
262 pp = ME_MaximizeSplit(wc, p, i);
266 TRACE("Must backtrack to split at: %s\n", debugstr_w(p->member.run.strText->szData));
267 if (wc->pLastSplittableRun)
269 if (wc->pLastSplittableRun->member.run.nFlags & (MERF_GRAPHICS|MERF_TAB))
271 wc->pt = wc->ptLastSplittableRun;
272 return wc->pLastSplittableRun;
274 else if (wc->pLastSplittableRun->member.run.nFlags & MERF_SPLITTABLE)
276 /* the following two lines are just to check if we forgot to call UpdateRunFlags earlier,
277 they serve no other purpose */
278 ME_UpdateRunFlags(wc->context->editor, run);
279 assert((wc->pLastSplittableRun->member.run.nFlags & MERF_SPLITTABLE));
281 piter = wc->pLastSplittableRun;
282 run = &piter->member.run;
283 len = ME_StrVLen(run->strText);
284 /* don't split words */
285 i = ME_ReverseFindWhitespaceV(run->strText, len);
287 i = ME_ReverseFindNonWhitespaceV(run->strText, len);
289 ME_DisplayItem *piter2 = ME_SplitRun(wc, piter, i);
290 wc->pt = piter2->member.run.pt;
293 /* splittable = must have whitespaces */
294 assert(0 == "Splittable, but no whitespaces");
298 /* restart from the first run beginning with spaces */
299 wc->pt = wc->ptLastSplittableRun;
300 return wc->pLastSplittableRun;
303 TRACE("Backtracking failed, trying desperate: %s\n", debugstr_w(p->member.run.strText->szData));
304 /* OK, no better idea, so assume we MAY split words if we can split at all*/
306 return ME_SplitRun(wc, piter, idesp);
308 if (wc->pRowStart && piter != wc->pRowStart)
310 /* don't need to break current run, because it's possible to split
312 wc->bOverflown = TRUE;
317 /* split point inside first character - no choice but split after that char */
319 int pos2 = ME_StrRelPos(run->strText, 0, &chars);
321 /* the run is more than 1 char, so we may split */
322 return ME_SplitRun(wc, piter, pos2);
324 /* the run is one char, can't split it */
329 static ME_DisplayItem *ME_WrapHandleRun(ME_WrapContext *wc, ME_DisplayItem *p)
335 assert(p->type == diRun);
338 run = &p->member.run;
339 run->pt.x = wc->pt.x;
340 run->pt.y = wc->pt.y;
341 ME_WrapSizeRun(wc, p);
342 len = ME_StrVLen(run->strText);
344 if (wc->bOverflown) /* just skipping final whitespaces */
346 /* End paragraph run can't overflow to the next line by itself. */
347 if (run->nFlags & MERF_ENDPARA)
350 if (run->nFlags & MERF_WHITESPACE) {
351 p->member.run.nFlags |= MERF_SKIPPED;
352 wc->pt.x += run->nWidth;
353 /* skip runs consisting of only whitespaces */
357 if (run->nFlags & MERF_STARTWHITE) {
358 /* try to split the run at the first non-white char */
360 black = ME_FindNonWhitespaceV(run->strText, 0);
362 wc->bOverflown = FALSE;
363 pp = ME_SplitRun(wc, p, black);
364 p->member.run.nFlags |= MERF_SKIPPED;
365 ME_InsertRowStart(wc, pp);
369 /* black run: the row goes from pRowStart to the previous run */
370 ME_InsertRowStart(wc, p);
373 /* simply end the current row and move on to next one */
374 if (run->nFlags & MERF_ENDROW)
377 ME_InsertRowStart(wc, p);
381 /* will current run fit? */
383 wc->pt.x + run->nWidth - wc->context->pt.x > wc->nAvailWidth)
385 int loc = wc->context->pt.x + wc->nAvailWidth - wc->pt.x;
386 /* total white run ? */
387 if (run->nFlags & MERF_WHITESPACE) {
388 /* let the overflow logic handle it */
389 wc->bOverflown = TRUE;
392 /* TAB: we can split before */
393 if (run->nFlags & MERF_TAB) {
394 wc->bOverflown = TRUE;
395 if (wc->pRowStart == p)
396 /* Don't split before the start of the run, or we will get an
402 /* graphics: we can split before, if run's width is smaller than row's width */
403 if ((run->nFlags & MERF_GRAPHICS) && run->nWidth <= wc->nAvailWidth) {
404 wc->bOverflown = TRUE;
407 /* can we separate out the last spaces ? (to use overflow logic later) */
408 if (run->nFlags & MERF_ENDWHITE)
410 /* we aren't sure if it's *really* necessary, it's a good start however */
411 int black = ME_ReverseFindNonWhitespaceV(run->strText, len);
412 ME_SplitRun(wc, p, black);
413 /* handle both parts again */
416 /* determine the split point by backtracking */
417 pp = ME_SplitByBacktracking(wc, p, loc);
418 if (pp == wc->pRowStart)
420 if (run->nFlags & MERF_STARTWHITE)
422 /* We had only spaces so far, so we must be on the first line of the
423 * paragraph (or the first line after MERF_ENDROW forced the line
424 * break within the paragraph), since no other lines of the paragraph
425 * start with spaces. */
427 /* The lines will only contain spaces, and the rest of the run will
428 * overflow onto the next line. */
429 wc->bOverflown = TRUE;
432 /* Couldn't split the first run, possible because we have a large font
433 * with a single character that caused an overflow.
435 wc->pt.x += run->nWidth;
438 if (p != pp) /* found a suitable split point */
440 wc->bOverflown = TRUE;
443 /* we detected that it's best to split on start of this run */
447 /* not found anything - writing over margins is the only option left */
449 if ((run->nFlags & (MERF_SPLITTABLE | MERF_STARTWHITE))
450 || ((run->nFlags & (MERF_GRAPHICS|MERF_TAB)) && (p != wc->pRowStart)))
452 wc->pLastSplittableRun = p;
453 wc->ptLastSplittableRun = wc->pt;
455 wc->pt.x += run->nWidth;
459 static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp);
461 static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp) {
468 assert(tp->type == diParagraph);
469 if (!(tp->member.para.nFlags & MEPF_REWRAP)) {
472 ME_PrepareParagraphForWrapping(c, tp);
473 pFmt = tp->member.para.pFmt;
476 /* wc.para_style = tp->member.para.style; */
478 if (tp->member.para.nFlags & MEPF_ROWEND) {
479 wc.nFirstMargin = wc.nLeftMargin = wc.nRightMargin = 0;
481 int dxStartIndent = pFmt->dxStartIndent;
482 if (tp->member.para.pCell) {
483 dxStartIndent += ME_GetTableRowEnd(tp)->member.para.pFmt->dxOffset;
485 wc.nFirstMargin = ME_twips2pointsX(c, dxStartIndent);
486 wc.nLeftMargin = wc.nFirstMargin + ME_twips2pointsX(c, pFmt->dxOffset);
487 wc.nRightMargin = ME_twips2pointsX(c, pFmt->dxRightIndent);
489 if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
490 pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
492 wc.nFirstMargin += ME_twips2pointsX(c, pFmt->dxOffset * 2);
496 if (pFmt->dwMask & PFM_SPACEBEFORE)
497 wc.pt.y += ME_twips2pointsY(c, pFmt->dySpaceBefore);
498 if (!(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) &&
499 pFmt->dwMask & PFM_BORDER)
501 border = ME_GetParaBorderWidth(c->editor, tp->member.para.pFmt->wBorders);
502 if (pFmt->wBorders & 1) {
503 wc.nFirstMargin += border;
504 wc.nLeftMargin += border;
506 if (pFmt->wBorders & 2)
507 wc.nRightMargin -= border;
508 if (pFmt->wBorders & 4)
512 linespace = ME_GetParaLineSpace(c, &tp->member.para);
514 ME_BeginRow(&wc, tp);
515 for (p = tp->next; p!=tp->member.para.next_para; ) {
516 assert(p->type != diStartRow);
517 if (p->type == diRun) {
518 p = ME_WrapHandleRun(&wc, p);
521 if (wc.nRow && p == wc.pRowStart)
522 wc.pt.y += linespace;
524 ME_WrapEndParagraph(&wc, p);
525 if (!(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) &&
526 (pFmt->dwMask & PFM_BORDER) && (pFmt->wBorders & 8))
528 if (tp->member.para.pFmt->dwMask & PFM_SPACEAFTER)
529 wc.pt.y += ME_twips2pointsY(c, pFmt->dySpaceAfter);
531 tp->member.para.nFlags &= ~MEPF_REWRAP;
532 tp->member.para.nHeight = wc.pt.y;
533 tp->member.para.nRows = wc.nRow;
537 static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp) {
538 ME_DisplayItem *p, *pRow;
540 tp->member.para.nWidth = 0;
541 /* remove all items that will be reinserted by paragraph wrapper anyway */
542 tp->member.para.nRows = 0;
543 for (p = tp->next; p!=tp->member.para.next_para; p = p->next) {
549 ME_DestroyDisplayItem(pRow);
555 /* join runs that can be joined, set up flags */
556 for (p = tp->next; p!=tp->member.para.next_para; p = p->next) {
559 case diStartRow: assert(0); break; /* should have deleted it */
561 while (p->next->type == diRun) { /* FIXME */
562 if (ME_CanJoinRuns(&p->member.run, &p->next->member.run)) {
563 ME_JoinRuns(c->editor, p);
569 p->member.run.nFlags &= ~MERF_CALCBYWRAP;
577 BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
579 ME_DisplayItem *item;
581 BOOL bModified = FALSE;
585 ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
587 item = editor->pBuffer->pFirst->next;
588 while(item != editor->pBuffer->pLast) {
589 BOOL bRedraw = FALSE;
591 assert(item->type == diParagraph);
592 if ((item->member.para.nFlags & MEPF_REWRAP)
593 || (item->member.para.pt.y != c.pt.y))
595 item->member.para.pt = c.pt;
597 ME_WrapTextParagraph(&c, item);
601 item->member.para.nFlags |= MEPF_REPAINT;
606 bModified = bModified | bRedraw;
608 if (item->member.para.nFlags & MEPF_ROWSTART)
610 ME_DisplayItem *cell = ME_FindItemFwd(item, diCell);
611 ME_DisplayItem *endRowPara;
613 cell->member.cell.pt = c.pt;
614 /* Offset the text by the largest top border width. */
615 while (cell->member.cell.next_cell) {
616 borderWidth = max(borderWidth, cell->member.cell.border.top.width);
617 cell = cell->member.cell.next_cell;
619 endRowPara = ME_FindItemFwd(cell, diParagraph);
620 assert(endRowPara->member.para.nFlags & MEPF_ROWEND);
623 borderWidth = max(ME_twips2pointsY(&c, borderWidth), 1);
625 cell->member.cell.yTextOffset = borderWidth;
626 cell = cell->member.cell.prev_cell;
628 c.pt.y += borderWidth;
630 if (endRowPara->member.para.pFmt->dxStartIndent > 0)
632 int dxStartIndent = endRowPara->member.para.pFmt->dxStartIndent;
633 cell = ME_FindItemFwd(item, diCell);
634 cell->member.cell.pt.x += ME_twips2pointsX(&c, dxStartIndent);
635 c.pt.x = cell->member.cell.pt.x;
638 else if (item->member.para.nFlags & MEPF_ROWEND)
640 /* Set all the cells to the height of the largest cell */
641 ME_DisplayItem *startRowPara;
642 int prevHeight, nHeight, bottomBorder = 0;
643 ME_DisplayItem *cell = ME_FindItemBack(item, diCell);
644 item->member.para.nWidth = cell->member.cell.pt.x + cell->member.cell.nWidth;
645 if (!(item->member.para.next_para->member.para.nFlags & MEPF_ROWSTART))
647 /* Last row, the bottom border is added to the height. */
648 cell = cell->member.cell.prev_cell;
651 bottomBorder = max(bottomBorder, cell->member.cell.border.bottom.width);
652 cell = cell->member.cell.prev_cell;
654 bottomBorder = ME_twips2pointsY(&c, bottomBorder);
655 cell = ME_FindItemBack(item, diCell);
657 prevHeight = cell->member.cell.nHeight;
658 nHeight = cell->member.cell.prev_cell->member.cell.nHeight + bottomBorder;
659 cell->member.cell.nHeight = nHeight;
660 item->member.para.nHeight = nHeight;
661 cell = cell->member.cell.prev_cell;
662 cell->member.cell.nHeight = nHeight;
663 while (cell->member.cell.prev_cell)
665 cell = cell->member.cell.prev_cell;
666 cell->member.cell.nHeight = nHeight;
668 /* Also set the height of the start row paragraph */
669 startRowPara = ME_FindItemBack(cell, diParagraph);
670 startRowPara->member.para.nHeight = nHeight;
671 c.pt.x = startRowPara->member.para.pt.x;
672 c.pt.y = cell->member.cell.pt.y + nHeight;
673 if (prevHeight < nHeight)
675 /* The height of the cells has grown, so invalidate the bottom of
677 item->member.para.nFlags |= MEPF_REPAINT;
678 cell = ME_FindItemBack(item, diCell);
680 ME_FindItemBack(cell, diParagraph)->member.para.nFlags |= MEPF_REPAINT;
681 cell = cell->member.cell.prev_cell;
685 else if (item->member.para.pCell &&
686 item->member.para.pCell != item->member.para.next_para->member.para.pCell)
688 /* The next paragraph is in the next cell in the table row. */
689 ME_Cell *cell = &item->member.para.pCell->member.cell;
690 cell->nHeight = c.pt.y + item->member.para.nHeight - cell->pt.y;
692 /* Propagate the largest height to the end so that it can be easily
693 * sent back to all the cells at the end of the row. */
695 cell->nHeight = max(cell->nHeight, cell->prev_cell->member.cell.nHeight);
697 c.pt.x = cell->pt.x + cell->nWidth;
699 cell->next_cell->member.cell.pt = c.pt;
700 if (!(item->member.para.next_para->member.para.nFlags & MEPF_ROWEND))
701 c.pt.y += cell->yTextOffset;
705 if (item->member.para.pCell) {
706 /* Next paragraph in the same cell. */
707 c.pt.x = item->member.para.pCell->member.cell.pt.x;
709 /* Normal paragraph */
712 c.pt.y += item->member.para.nHeight;
715 totalWidth = max(totalWidth, item->member.para.nWidth);
716 item = item->member.para.next_para;
718 editor->sizeWindow.cx = c.rcView.right-c.rcView.left;
719 editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top;
721 editor->nTotalLength = c.pt.y;
722 editor->nTotalWidth = totalWidth;
723 editor->pBuffer->pLast->member.para.pt.x = 0;
724 editor->pBuffer->pLast->member.para.pt.y = c.pt.y;
726 ME_DestroyContext(&c);
728 if (bModified || editor->nTotalLength < editor->nLastTotalLength)
729 ME_InvalidateMarkedParagraphs(editor);
733 void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor)
738 ME_DisplayItem *item;
740 ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
742 ofs = editor->vert_si.nPos;
744 item = editor->pBuffer->pFirst;
745 while(item != editor->pBuffer->pLast) {
746 if (item->member.para.nFlags & MEPF_REPAINT) {
747 rc.top = c.rcView.top + item->member.para.pt.y - ofs;
748 rc.bottom = max(c.rcView.top + item->member.para.pt.y
749 + item->member.para.nHeight - ofs,
751 ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
753 item = item->member.para.next_para;
755 if (editor->nTotalLength < editor->nLastTotalLength)
757 rc.top = c.rcView.top + editor->nTotalLength - ofs;
758 rc.bottom = c.rcView.top + editor->nLastTotalLength - ofs;
759 ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
761 ME_DestroyContext(&c);
766 ME_SendRequestResize(ME_TextEditor *editor, BOOL force)
768 if (editor->nEventMask & ENM_REQUESTRESIZE)
772 ITextHost_TxGetClientRect(editor->texthost, &rc);
774 if (force || rc.bottom != editor->nTotalLength)
778 info.nmhdr.code = EN_REQUESTRESIZE;
780 info.rc.right = editor->nTotalWidth;
781 info.rc.bottom = editor->nTotalLength;
783 editor->nEventMask &= ~ENM_REQUESTRESIZE;
784 ITextHost_TxNotify(editor->texthost, info.nmhdr.code, &info);
785 editor->nEventMask |= ENM_REQUESTRESIZE;