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 if (para->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND)) {
55 if (para->member.para.nFlags & MEPF_ROWEND)
57 ME_Cell *cell = &ME_FindItemBack(para, diCell)->member.cell;
60 } else if (para->member.para.pCell) {
61 ME_Cell *cell = ¶->member.para.pCell->member.cell;
64 width = cell->nRightBoundary;
66 width -= cell->prev_cell->member.cell.nRightBoundary;
69 int rowIndent = ME_GetTableRowEnd(para)->member.para.pFmt->dxStartIndent;
72 cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0);
74 wc->nAvailWidth = cell->nWidth
75 - (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
76 } else if (wc->context->editor->bWordWrap) {
77 wc->nAvailWidth = wc->context->rcView.right - wc->context->rcView.left
78 - (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
80 wc->nAvailWidth = ~0u >> 1;
82 wc->pt.x = wc->context->pt.x;
83 if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
84 pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
85 /* Shift the text down because of the border. */
89 static void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd)
91 ME_DisplayItem *p, *row, *para;
92 BOOL bSkippingSpaces = TRUE;
93 int ascent = 0, descent = 0, width=0, shift = 0, align = 0;
96 para = ME_GetParagraph(wc->pRowStart);
97 pFmt = para->member.para.pFmt;
99 for (p = pEnd->prev; p!=wc->pRowStart->prev; p = p->prev)
101 /* ENDPARA run shouldn't affect row height, except if it's the only run in the paragraph */
102 if (p->type==diRun && ((p==wc->pRowStart) || !(p->member.run.nFlags & MERF_ENDPARA))) { /* FIXME add more run types */
103 if (p->member.run.nAscent>ascent)
104 ascent = p->member.run.nAscent;
105 if (p->member.run.nDescent>descent)
106 descent = p->member.run.nDescent;
109 /* Exclude space characters from run width.
110 * Other whitespace or delimiters are not treated this way. */
112 int len = p->member.run.strText->nLen;
113 WCHAR *text = p->member.run.strText->szData + len - 1;
116 while (len && *(text--) == ' ')
120 if (len == p->member.run.strText->nLen)
122 width += p->member.run.nWidth;
124 sz = ME_GetRunSize(wc->context, ¶->member.para,
125 &p->member.run, len, p->member.run.pt.x);
129 bSkippingSpaces = !len;
130 } else if (!(p->member.run.nFlags & MERF_ENDPARA))
131 width += p->member.run.nWidth;
135 row = ME_MakeRow(ascent+descent, ascent, width);
136 if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
137 pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
139 /* The text was shifted down in ME_BeginRow so move the wrap context
140 * back to where it should be. */
142 /* The height of the row is increased by the borders. */
143 row->member.row.nHeight += 2;
145 row->member.row.pt = wc->pt;
146 row->member.row.nLMargin = (!wc->nRow ? wc->nFirstMargin : wc->nLeftMargin);
147 row->member.row.nRMargin = wc->nRightMargin;
148 assert(para->member.para.pFmt->dwMask & PFM_ALIGNMENT);
149 align = para->member.para.pFmt->wAlignment;
150 if (align == PFA_CENTER)
151 shift = (wc->nAvailWidth-width)/2;
152 if (align == PFA_RIGHT)
153 shift = wc->nAvailWidth-width;
154 for (p = wc->pRowStart; p!=pEnd; p = p->next)
156 if (p->type==diRun) { /* FIXME add more run types */
157 p->member.run.pt.x += row->member.row.nLMargin+shift;
160 ME_InsertBefore(wc->pRowStart, row);
162 wc->pt.y += row->member.row.nHeight;
163 ME_BeginRow(wc, para);
166 static void ME_WrapEndParagraph(ME_WrapContext *wc, ME_DisplayItem *p)
168 ME_DisplayItem *para = p->member.para.prev_para;
169 PARAFORMAT2 *pFmt = para->member.para.pFmt;
171 ME_InsertRowStart(wc, p);
172 if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
173 pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
175 /* ME_BeginRow was called an extra time for the paragraph, and it shifts the
176 * text down by one pixel for the border, so fix up the wrap context. */
181 p = p->member.para.prev_para->next;
183 if (p->type == diParagraph || p->type == diTextEnd)
185 if (p->type == diRun)
187 ME_Run *run = &p->member.run;
188 TRACE("%s - (%d, %d)\n", debugstr_w(run->strText->szData), run->pt.x, run->pt.y);
195 static void ME_WrapSizeRun(ME_WrapContext *wc, ME_DisplayItem *p)
197 /* FIXME compose style (out of character and paragraph styles) here */
199 ME_UpdateRunFlags(wc->context->editor, &p->member.run);
201 ME_CalcRunExtent(wc->context, &ME_GetParagraph(p)->member.para,
202 wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, &p->member.run);
205 static ME_DisplayItem *ME_MaximizeSplit(ME_WrapContext *wc, ME_DisplayItem *p, int i)
207 ME_DisplayItem *pp, *piter = p;
211 j = ME_ReverseFindNonWhitespaceV(p->member.run.strText, i);
213 pp = ME_SplitRun(wc, piter, j);
214 wc->pt.x += piter->member.run.nWidth;
220 /* omit all spaces before split point */
221 while(piter != wc->pRowStart)
223 piter = ME_FindItemBack(piter, diRun);
224 if (piter->member.run.nFlags & MERF_WHITESPACE)
229 if (piter->member.run.nFlags & MERF_ENDWHITE)
231 j = ME_ReverseFindNonWhitespaceV(piter->member.run.strText, i);
232 pp = ME_SplitRun(wc, piter, i);
233 wc->pt = pp->member.run.pt;
236 /* this run is the end of spaces, so the run edge is a good point to split */
237 wc->pt = pp->member.run.pt;
238 wc->bOverflown = TRUE;
239 TRACE("Split point is: %s|%s\n", debugstr_w(piter->member.run.strText->szData), debugstr_w(pp->member.run.strText->szData));
242 wc->pt = piter->member.run.pt;
247 static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem *p, int loc)
249 ME_DisplayItem *piter = p, *pp;
251 ME_Run *run = &p->member.run;
253 idesp = i = ME_CharFromPoint(wc->context, loc, run);
254 len = ME_StrVLen(run->strText);
258 /* don't split words */
259 i = ME_ReverseFindWhitespaceV(run->strText, i);
260 pp = ME_MaximizeSplit(wc, p, i);
264 TRACE("Must backtrack to split at: %s\n", debugstr_w(p->member.run.strText->szData));
265 if (wc->pLastSplittableRun)
267 if (wc->pLastSplittableRun->member.run.nFlags & (MERF_GRAPHICS|MERF_TAB))
269 wc->pt = wc->ptLastSplittableRun;
270 return wc->pLastSplittableRun;
272 else if (wc->pLastSplittableRun->member.run.nFlags & MERF_SPLITTABLE)
274 /* the following two lines are just to check if we forgot to call UpdateRunFlags earlier,
275 they serve no other purpose */
276 ME_UpdateRunFlags(wc->context->editor, run);
277 assert((wc->pLastSplittableRun->member.run.nFlags & MERF_SPLITTABLE));
279 piter = wc->pLastSplittableRun;
280 run = &piter->member.run;
281 len = ME_StrVLen(run->strText);
282 /* don't split words */
283 i = ME_ReverseFindWhitespaceV(run->strText, len);
285 i = ME_ReverseFindNonWhitespaceV(run->strText, len);
287 ME_DisplayItem *piter2 = ME_SplitRun(wc, piter, i);
288 wc->pt = piter2->member.run.pt;
291 /* splittable = must have whitespaces */
292 assert(0 == "Splittable, but no whitespaces");
296 /* restart from the first run beginning with spaces */
297 wc->pt = wc->ptLastSplittableRun;
298 return wc->pLastSplittableRun;
301 TRACE("Backtracking failed, trying desperate: %s\n", debugstr_w(p->member.run.strText->szData));
302 /* OK, no better idea, so assume we MAY split words if we can split at all*/
304 return ME_SplitRun(wc, piter, idesp);
306 if (wc->pRowStart && piter != wc->pRowStart)
308 /* don't need to break current run, because it's possible to split
310 wc->bOverflown = TRUE;
315 /* split point inside first character - no choice but split after that char */
317 int pos2 = ME_StrRelPos(run->strText, 0, &chars);
319 /* the run is more than 1 char, so we may split */
320 return ME_SplitRun(wc, piter, pos2);
322 /* the run is one char, can't split it */
327 static ME_DisplayItem *ME_WrapHandleRun(ME_WrapContext *wc, ME_DisplayItem *p)
333 assert(p->type == diRun);
336 run = &p->member.run;
337 run->pt.x = wc->pt.x;
338 run->pt.y = wc->pt.y;
339 ME_WrapSizeRun(wc, p);
340 len = ME_StrVLen(run->strText);
342 if (wc->bOverflown) /* just skipping final whitespaces */
344 /* End paragraph run can't overflow to the next line by itself. */
345 if (run->nFlags & MERF_ENDPARA)
348 if (run->nFlags & MERF_WHITESPACE) {
349 p->member.run.nFlags |= MERF_SKIPPED;
350 wc->pt.x += run->nWidth;
351 /* skip runs consisting of only whitespaces */
355 if (run->nFlags & MERF_STARTWHITE) {
356 /* try to split the run at the first non-white char */
358 black = ME_FindNonWhitespaceV(run->strText, 0);
360 wc->bOverflown = FALSE;
361 pp = ME_SplitRun(wc, p, black);
362 p->member.run.nFlags |= MERF_SKIPPED;
363 ME_InsertRowStart(wc, pp);
367 /* black run: the row goes from pRowStart to the previous run */
368 ME_InsertRowStart(wc, p);
371 /* simply end the current row and move on to next one */
372 if (run->nFlags & MERF_ENDROW)
375 ME_InsertRowStart(wc, p);
379 /* will current run fit? */
380 if (wc->pt.x + run->nWidth - wc->context->pt.x > wc->nAvailWidth)
382 int loc = wc->context->pt.x + wc->nAvailWidth - wc->pt.x;
383 /* total white run ? */
384 if (run->nFlags & MERF_WHITESPACE) {
385 /* let the overflow logic handle it */
386 wc->bOverflown = TRUE;
389 /* TAB: we can split before */
390 if (run->nFlags & MERF_TAB) {
391 wc->bOverflown = TRUE;
392 if (wc->pRowStart == p)
393 /* Don't split before the start of the run, or we will get an
399 /* graphics: we can split before, if run's width is smaller than row's width */
400 if ((run->nFlags & MERF_GRAPHICS) && run->nWidth <= wc->nAvailWidth) {
401 wc->bOverflown = TRUE;
404 /* can we separate out the last spaces ? (to use overflow logic later) */
405 if (run->nFlags & MERF_ENDWHITE)
407 /* we aren't sure if it's *really* necessary, it's a good start however */
408 int black = ME_ReverseFindNonWhitespaceV(run->strText, len);
409 ME_SplitRun(wc, p, black);
410 /* handle both parts again */
413 /* determine the split point by backtracking */
414 pp = ME_SplitByBacktracking(wc, p, loc);
415 if (pp == wc->pRowStart)
417 if (run->nFlags & MERF_STARTWHITE)
419 /* we had only spaces so far, so we must be on the first line of the
420 * paragraph, since no other lines of the paragraph start with spaces. */
422 /* The lines will only contain spaces, and the rest of the run will
423 * overflow onto the next line. */
424 wc->bOverflown = TRUE;
427 /* Couldn't split the first run, possible because we have a large font
428 * with a single character that caused an overflow.
430 wc->pt.x += run->nWidth;
433 if (p != pp) /* found a suitable split point */
435 wc->bOverflown = TRUE;
438 /* we detected that it's best to split on start of this run */
442 /* not found anything - writing over margins is the only option left */
444 if ((run->nFlags & (MERF_SPLITTABLE | MERF_STARTWHITE))
445 || ((run->nFlags & (MERF_GRAPHICS|MERF_TAB)) && (p != wc->pRowStart)))
447 wc->pLastSplittableRun = p;
448 wc->ptLastSplittableRun = wc->pt;
450 wc->pt.x += run->nWidth;
454 static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp);
456 static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD beginofs) {
463 assert(tp->type == diParagraph);
464 if (!(tp->member.para.nFlags & MEPF_REWRAP)) {
467 ME_PrepareParagraphForWrapping(c, tp);
468 pFmt = tp->member.para.pFmt;
471 /* wc.para_style = tp->member.para.style; */
473 if (tp->member.para.nFlags & MEPF_ROWEND) {
474 wc.nFirstMargin = wc.nLeftMargin = wc.nRightMargin = 0;
476 int dxStartIndent = pFmt->dxStartIndent;
477 if (tp->member.para.pCell) {
478 dxStartIndent += ME_GetTableRowEnd(tp)->member.para.pFmt->dxOffset;
480 wc.nFirstMargin = ME_twips2pointsX(c, dxStartIndent);
481 wc.nLeftMargin = wc.nFirstMargin + ME_twips2pointsX(c, pFmt->dxOffset);
482 wc.nRightMargin = ME_twips2pointsX(c, pFmt->dxRightIndent);
484 if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
485 pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
487 wc.nFirstMargin += ME_twips2pointsX(c, pFmt->dxOffset * 2);
491 if (pFmt->dwMask & PFM_SPACEBEFORE)
492 wc.pt.y += ME_twips2pointsY(c, pFmt->dySpaceBefore);
493 if (!(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) &&
494 pFmt->dwMask & PFM_BORDER)
496 border = ME_GetParaBorderWidth(c->editor, tp->member.para.pFmt->wBorders);
497 if (pFmt->wBorders & 1) {
498 wc.nFirstMargin += border;
499 wc.nLeftMargin += border;
501 if (pFmt->wBorders & 2)
502 wc.nRightMargin -= border;
503 if (pFmt->wBorders & 4)
507 linespace = ME_GetParaLineSpace(c, &tp->member.para);
509 ME_BeginRow(&wc, tp);
510 for (p = tp->next; p!=tp->member.para.next_para; ) {
511 assert(p->type != diStartRow);
512 if (p->type == diRun) {
513 p = ME_WrapHandleRun(&wc, p);
516 if (wc.nRow && p == wc.pRowStart)
517 wc.pt.y += linespace;
519 ME_WrapEndParagraph(&wc, p);
520 if (!(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) &&
521 (pFmt->dwMask & PFM_BORDER) && (pFmt->wBorders & 8))
523 if (tp->member.para.pFmt->dwMask & PFM_SPACEAFTER)
524 wc.pt.y += ME_twips2pointsY(c, pFmt->dySpaceAfter);
526 tp->member.para.nFlags &= ~MEPF_REWRAP;
527 tp->member.para.nHeight = wc.pt.y;
528 tp->member.para.nRows = wc.nRow;
532 static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp) {
533 ME_DisplayItem *p, *pRow;
535 /* remove all items that will be reinserted by paragraph wrapper anyway */
536 tp->member.para.nRows = 0;
537 for (p = tp->next; p!=tp->member.para.next_para; p = p->next) {
543 ME_DestroyDisplayItem(pRow);
549 /* join runs that can be joined, set up flags */
550 for (p = tp->next; p!=tp->member.para.next_para; p = p->next) {
553 case diStartRow: assert(0); break; /* should have deleted it */
555 while (p->next->type == diRun) { /* FIXME */
556 if (ME_CanJoinRuns(&p->member.run, &p->next->member.run)) {
557 ME_JoinRuns(c->editor, p);
563 p->member.run.nFlags &= ~MERF_CALCBYWRAP;
571 BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
572 ME_DisplayItem *item;
574 BOOL bModified = FALSE;
578 ME_InitContext(&c, editor, GetDC(editor->hWnd));
579 c.pt.x = editor->selofs;
581 item = editor->pBuffer->pFirst->next;
582 while(item != editor->pBuffer->pLast) {
583 BOOL bRedraw = FALSE;
585 assert(item->type == diParagraph);
586 editor->nHeight = max(editor->nHeight, item->member.para.pt.y);
587 if ((item->member.para.nFlags & MEPF_REWRAP)
588 || (item->member.para.pt.y != c.pt.y))
590 item->member.para.pt = c.pt;
592 ME_WrapTextParagraph(&c, item, editor->selofs);
596 item->member.para.nFlags |= MEPF_REPAINT;
601 bModified = bModified | bRedraw;
603 yLastPos = max(yLastPos, c.pt.y);
605 if (item->member.para.nFlags & MEPF_ROWSTART)
607 ME_DisplayItem *cell = ME_FindItemFwd(item, diCell);
608 ME_DisplayItem *endRowPara;
610 cell->member.cell.pt = c.pt;
611 /* Offset the text by the largest top border width. */
612 while (cell->member.cell.next_cell) {
613 borderWidth = max(borderWidth, cell->member.cell.border.top.width);
614 cell = cell->member.cell.next_cell;
616 endRowPara = ME_FindItemFwd(cell, diParagraph);
617 assert(endRowPara->member.para.nFlags & MEPF_ROWEND);
620 borderWidth = max(ME_twips2pointsY(&c, borderWidth), 1);
622 cell->member.cell.yTextOffset = borderWidth;
623 cell = cell->member.cell.prev_cell;
625 c.pt.y += borderWidth;
627 if (endRowPara->member.para.pFmt->dxStartIndent > 0)
629 int dxStartIndent = endRowPara->member.para.pFmt->dxStartIndent;
630 cell = ME_FindItemFwd(item, diCell);
631 cell->member.cell.pt.x += ME_twips2pointsX(&c, dxStartIndent);
632 c.pt.x = cell->member.cell.pt.x;
635 else if (item->member.para.nFlags & MEPF_ROWEND)
637 /* Set all the cells to the height of the largest cell */
638 ME_DisplayItem *startRowPara;
639 int prevHeight, nHeight, bottomBorder = 0;
640 ME_DisplayItem *cell = ME_FindItemBack(item, diCell);
641 if (!(item->member.para.next_para->member.para.nFlags & MEPF_ROWSTART))
643 /* Last row, the bottom border is added to the height. */
644 cell = cell->member.cell.prev_cell;
647 bottomBorder = max(bottomBorder, cell->member.cell.border.bottom.width);
648 cell = cell->member.cell.prev_cell;
650 bottomBorder = ME_twips2pointsY(&c, bottomBorder);
651 cell = ME_FindItemBack(item, diCell);
653 prevHeight = cell->member.cell.nHeight;
654 nHeight = cell->member.cell.prev_cell->member.cell.nHeight + bottomBorder;
655 cell->member.cell.nHeight = nHeight;
656 item->member.para.nHeight = nHeight;
657 cell = cell->member.cell.prev_cell;
658 cell->member.cell.nHeight = nHeight;
659 while (cell->member.cell.prev_cell)
661 cell = cell->member.cell.prev_cell;
662 cell->member.cell.nHeight = nHeight;
664 /* Also set the height of the start row paragraph */
665 startRowPara = ME_FindItemBack(cell, diParagraph);
666 startRowPara->member.para.nHeight = nHeight;
667 c.pt.x = startRowPara->member.para.pt.x;
668 c.pt.y = cell->member.cell.pt.y + nHeight;
669 if (prevHeight < nHeight)
671 /* The height of the cells has grown, so invalidate the bottom of
673 item->member.para.nFlags |= MEPF_REPAINT;
674 cell = ME_FindItemBack(item, diCell);
676 ME_FindItemBack(cell, diParagraph)->member.para.nFlags |= MEPF_REPAINT;
677 cell = cell->member.cell.prev_cell;
681 else if (item->member.para.pCell &&
682 item->member.para.pCell != item->member.para.next_para->member.para.pCell)
684 /* The next paragraph is in the next cell in the table row. */
685 ME_Cell *cell = &item->member.para.pCell->member.cell;
686 cell->nHeight = c.pt.y + item->member.para.nHeight - cell->pt.y;
688 /* Propagate the largest height to the end so that it can be easily
689 * sent back to all the cells at the end of the row. */
691 cell->nHeight = max(cell->nHeight, cell->prev_cell->member.cell.nHeight);
693 c.pt.x = cell->pt.x + cell->nWidth;
695 cell->next_cell->member.cell.pt = c.pt;
696 c.pt.y += cell->yTextOffset;
700 if (item->member.para.pCell) {
701 /* Next paragraph in the same cell. */
702 c.pt.x = item->member.para.pCell->member.cell.pt.x;
704 /* Normal paragraph */
705 c.pt.x = editor->selofs;
707 c.pt.y += item->member.para.nHeight;
709 item = item->member.para.next_para;
711 editor->sizeWindow.cx = c.rcView.right-c.rcView.left;
712 editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top;
714 editor->nTotalLength = c.pt.y;
715 editor->pBuffer->pLast->member.para.pt.x = 0;
716 editor->pBuffer->pLast->member.para.pt.y = yLastPos;
718 ME_DestroyContext(&c, editor->hWnd);
720 /* Each paragraph may contain multiple rows, which should be scrollable, even
721 if the containing paragraph has pt.y == 0 */
722 item = editor->pBuffer->pFirst;
723 while ((item = ME_FindItemFwd(item, diStartRow)) != NULL) {
724 assert(item->type == diStartRow);
725 editor->nHeight = max(editor->nHeight, item->member.row.pt.y);
728 if (bModified || editor->nTotalLength < editor->nLastTotalLength)
729 ME_InvalidateMarkedParagraphs(editor);
733 void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) {
736 ME_InitContext(&c, editor, GetDC(editor->hWnd));
740 int ofs = ME_GetYScrollPos(editor);
742 ME_DisplayItem *item = editor->pBuffer->pFirst;
743 while(item != editor->pBuffer->pLast) {
744 if (item->member.para.nFlags & MEPF_REPAINT) {
745 rc.top = item->member.para.pt.y - ofs;
746 rc.bottom = item->member.para.pt.y + item->member.para.nHeight - ofs;
747 InvalidateRect(editor->hWnd, &rc, TRUE);
749 item = item->member.para.next_para;
751 if (editor->nTotalLength < editor->nLastTotalLength)
753 rc.top = editor->nTotalLength - ofs;
754 rc.bottom = editor->nLastTotalLength - ofs;
755 InvalidateRect(editor->hWnd, &rc, TRUE);
758 ME_DestroyContext(&c, editor->hWnd);
763 ME_SendRequestResize(ME_TextEditor *editor, BOOL force)
765 if (editor->nEventMask & ENM_REQUESTRESIZE)
769 GetClientRect(editor->hWnd, &rc);
771 if (force || rc.bottom != editor->nTotalLength)
775 info.nmhdr.hwndFrom = editor->hWnd;
776 info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
777 info.nmhdr.code = EN_REQUESTRESIZE;
779 info.rc.bottom = editor->nTotalLength;
781 editor->nEventMask &= ~ENM_REQUESTRESIZE;
782 SendMessageW(GetParent(editor->hWnd), WM_NOTIFY,
783 info.nmhdr.idFrom, (LPARAM)&info);
784 editor->nEventMask |= ENM_REQUESTRESIZE;