msi: Handle features installed as source in MsiQueryFeatureState.
[wine/multimedia.git] / dlls / riched20 / wrap.c
bloba3c5d544ff682151a128250e5f47c5bcfa89f856
1 /*
2 * RichEdit - Paragraph wrapping. Don't try to understand it. You've been
3 * warned !
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
23 #include "editor.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
28 * Unsolved problems:
30 * - center and right align in WordPad omits all spaces at the start, we don't
31 * - objects/images are not handled yet
32 * - no tabs
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;
42 return item;
45 static void ME_BeginRow(ME_WrapContext *wc, ME_DisplayItem *para)
47 PARAFORMAT2 *pFmt;
48 assert(para && para->type == diParagraph);
49 pFmt = para->member.para.pFmt;
50 wc->pRowStart = NULL;
51 wc->bOverflown = FALSE;
52 wc->pLastSplittableRun = NULL;
53 if (para->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND)) {
54 wc->nAvailWidth = 0;
55 if (para->member.para.nFlags & MEPF_ROWEND)
57 ME_Cell *cell = &ME_FindItemBack(para, diCell)->member.cell;
58 cell->nWidth = 0;
60 } else if (para->member.para.pCell) {
61 ME_Cell *cell = &para->member.para.pCell->member.cell;
62 int width;
64 width = cell->nRightBoundary;
65 if (cell->prev_cell)
66 width -= cell->prev_cell->member.cell.nRightBoundary;
67 if (!cell->prev_cell)
69 int rowIndent = ME_GetTableRowEnd(para)->member.para.pFmt->dxStartIndent;
70 width -= rowIndent;
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;
79 } else {
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. */
86 wc->pt.y++;
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;
94 PARAFORMAT2 *pFmt;
95 /* wrap text */
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;
107 if (bSkippingSpaces)
109 /* Exclude space characters from run width.
110 * Other whitespace or delimiters are not treated this way. */
111 SIZE sz;
112 int len = p->member.run.strText->nLen;
113 WCHAR *text = p->member.run.strText->szData + len - 1;
115 assert (len);
116 while (len && *(text--) == ' ')
117 len--;
118 if (len)
120 if (len == p->member.run.strText->nLen)
122 width += p->member.run.nWidth;
123 } else {
124 sz = ME_GetRunSize(wc->context, &para->member.para,
125 &p->member.run, len, p->member.run.pt.x);
126 width += sz.cx;
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. */
141 wc->pt.y--;
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);
161 wc->nRow++;
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;
170 if (wc->pRowStart)
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. */
177 wc->pt.y--;
181 p = p->member.para.prev_para->next;
182 while(p) {
183 if (p->type == diParagraph || p->type == diTextEnd)
184 return;
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);
190 p = p->next;
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;
208 int j;
209 if (!i)
210 return NULL;
211 j = ME_ReverseFindNonWhitespaceV(p->member.run.strText, i);
212 if (j>0) {
213 pp = ME_SplitRun(wc, piter, j);
214 wc->pt.x += piter->member.run.nWidth;
215 return pp;
217 else
219 pp = piter;
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)
226 pp = piter;
227 continue;
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;
234 return pp;
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));
240 return pp;
242 wc->pt = piter->member.run.pt;
243 return piter;
247 static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem *p, int loc)
249 ME_DisplayItem *piter = p, *pp;
250 int i, idesp, len;
251 ME_Run *run = &p->member.run;
253 idesp = i = ME_CharFromPoint(wc->context, loc, run);
254 len = ME_StrVLen(run->strText);
255 assert(len>0);
256 assert(i<len);
257 if (i) {
258 /* don't split words */
259 i = ME_ReverseFindWhitespaceV(run->strText, i);
260 pp = ME_MaximizeSplit(wc, p, i);
261 if (pp)
262 return pp;
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);
284 if (i == len)
285 i = ME_ReverseFindNonWhitespaceV(run->strText, len);
286 if (i) {
287 ME_DisplayItem *piter2 = ME_SplitRun(wc, piter, i);
288 wc->pt = piter2->member.run.pt;
289 return piter2;
291 /* splittable = must have whitespaces */
292 assert(0 == "Splittable, but no whitespaces");
294 else
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*/
303 if (idesp)
304 return ME_SplitRun(wc, piter, idesp);
305 else
306 if (wc->pRowStart && piter != wc->pRowStart)
308 /* don't need to break current run, because it's possible to split
309 before this run */
310 wc->bOverflown = TRUE;
311 return piter;
313 else
315 /* split point inside first character - no choice but split after that char */
316 int chars = 1;
317 int pos2 = ME_StrRelPos(run->strText, 0, &chars);
318 if (pos2 != len) {
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 */
323 return piter;
327 static ME_DisplayItem *ME_WrapHandleRun(ME_WrapContext *wc, ME_DisplayItem *p)
329 ME_DisplayItem *pp;
330 ME_Run *run;
331 int len;
333 assert(p->type == diRun);
334 if (!wc->pRowStart)
335 wc->pRowStart = p;
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)
346 return p->next;
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 */
352 return p->next;
355 if (run->nFlags & MERF_STARTWHITE) {
356 /* try to split the run at the first non-white char */
357 int black;
358 black = ME_FindNonWhitespaceV(run->strText, 0);
359 if (black) {
360 wc->bOverflown = FALSE;
361 pp = ME_SplitRun(wc, p, black);
362 p->member.run.nFlags |= MERF_SKIPPED;
363 ME_InsertRowStart(wc, pp);
364 return pp;
367 /* black run: the row goes from pRowStart to the previous run */
368 ME_InsertRowStart(wc, p);
369 return p;
371 /* simply end the current row and move on to next one */
372 if (run->nFlags & MERF_ENDROW)
374 p = p->next;
375 ME_InsertRowStart(wc, p);
376 return 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;
387 return p;
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
394 * endless loop. */
395 return p->next;
396 else
397 return p;
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;
402 return p;
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 */
411 return p;
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. */
421 assert(!wc->nRow);
422 /* The lines will only contain spaces, and the rest of the run will
423 * overflow onto the next line. */
424 wc->bOverflown = TRUE;
425 return p;
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;
431 return p->next;
433 if (p != pp) /* found a suitable split point */
435 wc->bOverflown = TRUE;
436 return pp;
438 /* we detected that it's best to split on start of this run */
439 if (wc->bOverflown)
440 return pp;
441 ERR("failure!\n");
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;
451 return p->next;
454 static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp);
456 static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD beginofs) {
457 ME_DisplayItem *p;
458 ME_WrapContext wc;
459 int border = 0;
460 int linespace = 0;
461 PARAFORMAT2 *pFmt;
463 assert(tp->type == diParagraph);
464 if (!(tp->member.para.nFlags & MEPF_REWRAP)) {
465 return;
467 ME_PrepareParagraphForWrapping(c, tp);
468 pFmt = tp->member.para.pFmt;
470 wc.context = c;
471 /* wc.para_style = tp->member.para.style; */
472 wc.style = NULL;
473 if (tp->member.para.nFlags & MEPF_ROWEND) {
474 wc.nFirstMargin = wc.nLeftMargin = wc.nRightMargin = 0;
475 } else {
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);
489 wc.nRow = 0;
490 wc.pt.y = 0;
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)
504 wc.pt.y += border;
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);
515 else p = p->next;
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))
522 wc.pt.y += border;
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) {
538 switch(p->type) {
539 case diStartRow:
540 pRow = p;
541 p = p->prev;
542 ME_Remove(pRow);
543 ME_DestroyDisplayItem(pRow);
544 break;
545 default:
546 break;
549 /* join runs that can be joined, set up flags */
550 for (p = tp->next; p!=tp->member.para.next_para; p = p->next) {
551 int changed = 0;
552 switch(p->type) {
553 case diStartRow: assert(0); break; /* should have deleted it */
554 case diRun:
555 while (p->next->type == diRun) { /* FIXME */
556 if (ME_CanJoinRuns(&p->member.run, &p->next->member.run)) {
557 ME_JoinRuns(c->editor, p);
558 changed = 1;
560 else
561 break;
563 p->member.run.nFlags &= ~MERF_CALCBYWRAP;
564 break;
565 default:
566 break;
571 BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
572 ME_DisplayItem *item;
573 ME_Context c;
574 BOOL bModified = FALSE;
575 int yStart = -1;
576 int yLastPos = 0;
578 ME_InitContext(&c, editor, GetDC(editor->hWnd));
579 c.pt.x = editor->selofs;
580 editor->nHeight = 0;
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))
589 bRedraw = TRUE;
590 item->member.para.pt = c.pt;
592 ME_WrapTextParagraph(&c, item, editor->selofs);
594 if (bRedraw)
596 item->member.para.nFlags |= MEPF_REPAINT;
597 if (yStart == -1)
598 yStart = c.pt.y;
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;
609 int borderWidth = 0;
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);
618 if (borderWidth > 0)
620 borderWidth = max(ME_twips2pointsY(&c, borderWidth), 1);
621 while (cell) {
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;
645 while (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
672 * the cells. */
673 item->member.para.nFlags |= MEPF_REPAINT;
674 cell = ME_FindItemBack(item, diCell);
675 while (cell) {
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. */
690 if (cell->prev_cell)
691 cell->nHeight = max(cell->nHeight, cell->prev_cell->member.cell.nHeight);
693 c.pt.x = cell->pt.x + cell->nWidth;
694 c.pt.y = cell->pt.y;
695 cell->next_cell->member.cell.pt = c.pt;
696 c.pt.y += cell->yTextOffset;
698 else
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;
703 } else {
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);
730 return bModified;
733 void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) {
734 ME_Context c;
736 ME_InitContext(&c, editor, GetDC(editor->hWnd));
737 if (editor->bRedraw)
739 RECT rc = c.rcView;
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);
762 void
763 ME_SendRequestResize(ME_TextEditor *editor, BOOL force)
765 if (editor->nEventMask & ENM_REQUESTRESIZE)
767 RECT rc;
769 GetClientRect(editor->hWnd, &rc);
771 if (force || rc.bottom != editor->nTotalLength)
773 REQRESIZE info;
775 info.nmhdr.hwndFrom = editor->hWnd;
776 info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
777 info.nmhdr.code = EN_REQUESTRESIZE;
778 info.rc = rc;
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;