2 * RichEdit - painting functions
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2005 by Phil Krylov
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
24 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
26 static void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph);
28 void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *rcUpdate)
35 oldRgn = CreateRectRgn(0, 0, 0, 0);
36 if (!GetClipRgn(hDC, oldRgn))
41 IntersectClipRect(hDC, rcUpdate->left, rcUpdate->top,
42 rcUpdate->right, rcUpdate->bottom);
45 ME_InitContext(&c, editor, hDC);
46 SetBkMode(hDC, TRANSPARENT);
48 item = editor->pBuffer->pFirst->next;
49 /* This context point is an offset for the paragraph positions stored
50 * during wrapping. It shouldn't be modified during painting. */
51 c.pt.x = c.rcView.left - editor->horz_si.nPos;
52 c.pt.y = c.rcView.top - editor->vert_si.nPos;
53 while(item != editor->pBuffer->pLast)
55 assert(item->type == diParagraph);
57 ys = c.pt.y + item->member.para.pt.y;
58 if (item->member.para.pCell
59 != item->member.para.next_para->member.para.pCell)
62 cell = &ME_FindItemBack(item->member.para.next_para, diCell)->member.cell;
63 ye = c.pt.y + cell->pt.y + cell->nHeight;
65 ye = ys + item->member.para.nHeight;
67 if (item->member.para.pCell && !(item->member.para.nFlags & MEPF_ROWEND) &&
68 item->member.para.pCell != item->member.para.prev_para->member.para.pCell)
70 /* the border shifts the text down */
71 ys -= item->member.para.pCell->member.cell.yTextOffset;
74 if (!bOnlyNew || (item->member.para.nFlags & MEPF_REPAINT))
76 /* Draw the pargraph if any of the paragraph is in the update region. */
77 if (ys < rcUpdate->bottom && ye > rcUpdate->top)
79 ME_DrawParagraph(&c, item);
80 /* Clear the repaint flag if the whole paragraph is in the
82 if (rcUpdate->top <= ys && rcUpdate->bottom >= ye)
83 item->member.para.nFlags &= ~MEPF_REPAINT;
86 item = item->member.para.next_para;
88 if (c.pt.y + editor->nTotalLength < c.rcView.bottom)
90 /* Fill space after the end of the text. */
92 rc.top = c.pt.y + editor->nTotalLength;
93 rc.left = c.rcView.left;
94 rc.bottom = c.rcView.bottom;
95 rc.right = c.rcView.right;
99 /* Only erase region drawn from previous call to ME_PaintContent */
100 if (editor->nTotalLength < editor->nLastTotalLength)
101 rc.bottom = c.pt.y + editor->nLastTotalLength;
106 IntersectRect(&rc, &rc, rcUpdate);
108 if (!IsRectEmpty(&rc))
109 FillRect(hDC, &rc, c.editor->hbrBackground);
111 if (editor->nTotalLength != editor->nLastTotalLength ||
112 editor->nTotalWidth != editor->nLastTotalWidth)
113 ME_SendRequestResize(editor, FALSE);
114 editor->nLastTotalLength = editor->nTotalLength;
115 editor->nLastTotalWidth = editor->nTotalWidth;
117 SelectClipRgn(hDC, oldRgn);
119 DeleteObject(oldRgn);
122 ME_DestroyContext(&c);
125 void ME_Repaint(ME_TextEditor *editor)
127 if (ME_WrapMarkedParagraphs(editor))
129 ME_UpdateScrollBar(editor);
130 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
132 if (!editor->bEmulateVersion10 || (editor->nEventMask & ENM_UPDATE))
133 ME_SendOldNotify(editor, EN_UPDATE);
134 ITextHost_TxViewChange(editor->texthost, TRUE);
137 void ME_UpdateRepaint(ME_TextEditor *editor)
139 /* Should be called whenever the contents of the control have changed */
140 BOOL wrappedParagraphs;
142 wrappedParagraphs = ME_WrapMarkedParagraphs(editor);
143 if (wrappedParagraphs)
144 ME_UpdateScrollBar(editor);
146 /* Ensure that the cursor is visible */
147 ME_EnsureVisible(editor, &editor->pCursors[0]);
149 /* send EN_CHANGE if the event mask asks for it */
150 if(editor->nEventMask & ENM_CHANGE)
152 editor->nEventMask &= ~ENM_CHANGE;
153 ME_SendOldNotify(editor, EN_CHANGE);
154 editor->nEventMask |= ENM_CHANGE;
157 ME_SendSelChange(editor);
161 ME_RewrapRepaint(ME_TextEditor *editor)
163 /* RewrapRepaint should be called whenever the control has changed in
164 * looks, but not content. Like resizing. */
166 ME_MarkAllForWrapping(editor);
167 ME_WrapMarkedParagraphs(editor);
168 ME_UpdateScrollBar(editor);
172 int ME_twips2pointsX(ME_Context *c, int x)
174 if (c->editor->nZoomNumerator == 0)
175 return x * c->dpi.cx / 1440;
177 return x * c->dpi.cx * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
180 int ME_twips2pointsY(ME_Context *c, int y)
182 if (c->editor->nZoomNumerator == 0)
183 return y * c->dpi.cy / 1440;
185 return y * c->dpi.cy * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
188 static void ME_HighlightSpace(ME_Context *c, int x, int y, LPCWSTR szText,
189 int nChars, ME_Style *s, int width,
190 int nSelFrom, int nSelTo, int ymin, int cy)
193 HGDIOBJ hOldFont = NULL;
196 /* Only highlight if there is a selection in the run and when
197 * EM_HIDESELECTION is not being used to hide the selection. */
198 if (nSelFrom >= nChars || nSelTo < 0 || nSelFrom >= nSelTo
199 || c->editor->bHideSelection)
201 hOldFont = ME_SelectStyleFont(c, s);
204 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
207 if (nSelFrom < 0) nSelFrom = 0;
208 if (nSelTo > nChars) nSelTo = nChars;
209 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
211 if (nSelTo != nChars)
213 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
216 selWidth = width - sz.cx;
218 ME_UnselectStyleFont(c, s, hOldFont);
220 if (c->editor->bEmulateVersion10)
221 PatBlt(hDC, x, ymin, selWidth, cy, DSTINVERT);
228 rect.right = x + selWidth;
229 rect.bottom = ymin + cy;
230 hBrush = CreateSolidBrush(ITextHost_TxGetSysColor(c->editor->texthost,
232 FillRect(hDC, &rect, hBrush);
233 DeleteObject(hBrush);
237 static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText,
238 int nChars, ME_Style *s, int width,
239 int nSelFrom, int nSelTo, int ymin, int cy)
244 int yOffset = 0, yTwipsOffset = 0;
247 HPEN hPen = NULL, hOldPen = NULL;
248 BOOL bHighlightedText = (nSelFrom < nChars && nSelTo >= 0
249 && nSelFrom < nSelTo && !c->editor->bHideSelection);
250 int xSelStart = x, xSelEnd = x;
252 /* lpDx is only needed for tabs to make sure the underline done automatically
253 * by the font extends to the end of the tab. Tabs are always stored as
254 * a single character run, so we can handle this case separately, since
255 * otherwise lpDx would need to specify the lengths of each character. */
256 if (width && nChars == 1)
257 lpDx = &width; /* Make sure underline for tab extends across tab space */
259 hOldFont = ME_SelectStyleFont(c, s);
260 if ((s->fmt.dwMask & s->fmt.dwEffects) & CFM_OFFSET) {
261 yTwipsOffset = s->fmt.yOffset;
263 if ((s->fmt.dwMask & s->fmt.dwEffects) & (CFM_SUPERSCRIPT | CFM_SUBSCRIPT)) {
264 if (s->fmt.dwEffects & CFE_SUPERSCRIPT) yTwipsOffset = s->fmt.yHeight/3;
265 if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
268 yOffset = ME_twips2pointsY(c, yTwipsOffset);
270 if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
272 else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
273 rgb = ITextHost_TxGetSysColor(c->editor->texthost, COLOR_WINDOWTEXT);
275 rgb = s->fmt.crTextColor;
277 /* Determine the area that is selected in the run. */
278 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
279 /* Treat width as an optional parameter. We can get the width from the
280 * text extent of the string if it isn't specified. */
281 if (!width) width = sz.cx;
282 if (bHighlightedText)
290 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
291 xSelStart = x + sz.cx;
293 if (nSelTo >= nChars)
300 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
301 xSelEnd = xSelStart + sz.cx;
305 /* Choose the pen type for underlining the text. */
306 if (s->fmt.dwMask & CFM_UNDERLINETYPE)
308 switch (s->fmt.bUnderlineType)
311 case CFU_UNDERLINEWORD: /* native seems to map it to simple underline (MSDN) */
312 case CFU_UNDERLINEDOUBLE: /* native seems to map it to simple underline (MSDN) */
313 hPen = CreatePen(PS_SOLID, 1, rgb);
315 case CFU_UNDERLINEDOTTED:
316 hPen = CreatePen(PS_DOT, 1, rgb);
319 WINE_FIXME("Unknown underline type (%u)\n", s->fmt.bUnderlineType);
321 case CFU_CF1UNDERLINE: /* this type is supported in the font, do nothing */
322 case CFU_UNDERLINENONE:
328 hOldPen = SelectObject(hDC, hPen);
332 rgbOld = SetTextColor(hDC, rgb);
333 if (bHighlightedText && !c->editor->bEmulateVersion10)
337 /* FIXME: should use textmetrics info for Descent info */
339 MoveToEx(hDC, x, y - yOffset + 1, NULL);
342 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nSelFrom, NULL);
344 LineTo(hDC, xSelStart, y - yOffset + 1);
347 dim.bottom = ymin + cy;
348 dim.left = xSelStart;
350 SetTextColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
351 COLOR_HIGHLIGHTTEXT));
352 rgbBackOld = SetBkColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
354 ExtTextOutW(hDC, xSelStart, y-yOffset, ETO_OPAQUE, &dim,
355 szText+nSelFrom, nSelTo-nSelFrom, lpDx);
357 LineTo(hDC, xSelEnd, y - yOffset + 1);
358 SetBkColor(hDC, rgbBackOld);
359 if (xSelEnd < x + width)
361 SetTextColor(hDC, rgb);
362 ExtTextOutW(hDC, xSelEnd, y-yOffset, 0, NULL, szText+nSelTo,
363 nChars-nSelTo, NULL);
365 LineTo(hDC, x + width, y - yOffset + 1);
370 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, lpDx);
372 /* FIXME: should use textmetrics info for Descent info */
375 MoveToEx(hDC, x, y - yOffset + 1, NULL);
376 LineTo(hDC, x + width, y - yOffset + 1);
379 if (bHighlightedText) /* v1.0 inverts the selection */
381 PatBlt(hDC, xSelStart, ymin, xSelEnd-xSelStart, cy, DSTINVERT);
387 SelectObject(hDC, hOldPen);
390 SetTextColor(hDC, rgbOld);
391 ME_UnselectStyleFont(c, s, hOldFont);
394 static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) {
395 int align = SetTextAlign(hDC, TA_LEFT|TA_TOP);
396 HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
397 COLORREF color = SetTextColor(hDC, RGB(128,128,128));
398 TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText));
399 SelectObject(hDC, hFont);
400 SetTextAlign(hDC, align);
401 SetTextColor(hDC, color);
404 static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para)
406 ME_Run *run = &rundi->member.run;
407 ME_DisplayItem *start;
408 int runofs = run->nCharOfs+para->nCharOfs;
409 int nSelFrom, nSelTo;
410 const WCHAR wszSpace[] = {' ', 0};
412 if (run->nFlags & MERF_HIDDEN)
415 start = ME_FindItemBack(rundi, diStartRow);
416 ME_GetSelection(c->editor, &nSelFrom, &nSelTo);
418 /* Draw selected end-of-paragraph mark */
419 if (run->nFlags & MERF_ENDPARA)
421 if (runofs >= nSelFrom && runofs < nSelTo)
423 ME_HighlightSpace(c, x, y, wszSpace, 1, run->style, 0, 0, 1,
424 c->pt.y + para->pt.y + start->member.row.pt.y,
425 start->member.row.nHeight);
430 if (run->nFlags & (MERF_TAB | MERF_ENDCELL))
432 /* wszSpace is used instead of the tab character because otherwise
433 * an unwanted symbol can be inserted instead. */
434 ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, run->nWidth,
435 nSelFrom-runofs, nSelTo-runofs,
436 c->pt.y + para->pt.y + start->member.row.pt.y,
437 start->member.row.nHeight);
441 if (run->nFlags & MERF_GRAPHICS)
442 ME_DrawOLE(c, x, y, run, para, (runofs >= nSelFrom) && (runofs < nSelTo));
445 if (c->editor->cPasswordMask)
447 ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask, run->strText->nLen);
448 ME_DrawTextWithStyle(c, x, y,
449 szMasked->szData, szMasked->nLen, run->style, run->nWidth,
450 nSelFrom-runofs,nSelTo-runofs,
451 c->pt.y + para->pt.y + start->member.row.pt.y,
452 start->member.row.nHeight);
453 ME_DestroyString(szMasked);
456 ME_DrawTextWithStyle(c, x, y,
457 run->strText->szData, run->strText->nLen, run->style, run->nWidth,
458 nSelFrom-runofs,nSelTo-runofs,
459 c->pt.y + para->pt.y + start->member.row.pt.y,
460 start->member.row.nHeight);
464 static const struct {unsigned width_num : 4, width_den : 4, pen_style : 4, dble : 1;} border_details[] = {
465 /* none */ {0, 1, PS_SOLID, FALSE},
466 /* 3/4 */ {3, 4, PS_SOLID, FALSE},
467 /* 1 1/2 */ {3, 2, PS_SOLID, FALSE},
468 /* 2 1/4 */ {9, 4, PS_SOLID, FALSE},
469 /* 3 */ {3, 1, PS_SOLID, FALSE},
470 /* 4 1/2 */ {9, 2, PS_SOLID, FALSE},
471 /* 6 */ {6, 1, PS_SOLID, FALSE},
472 /* 3/4 double */ {3, 4, PS_SOLID, TRUE},
473 /* 1 1/2 double */ {3, 2, PS_SOLID, TRUE},
474 /* 2 1/4 double */ {9, 4, PS_SOLID, TRUE},
475 /* 3/4 gray */ {3, 4, PS_DOT /* FIXME */, FALSE},
476 /* 1 1/2 dashed */ {3, 2, PS_DASH, FALSE},
479 static const COLORREF pen_colors[16] = {
480 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
481 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
482 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
483 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
484 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
485 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
486 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
487 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
490 static int ME_GetBorderPenWidth(ME_TextEditor* editor, int idx)
494 if (editor->nZoomNumerator == 0)
496 width = border_details[idx].width_num + border_details[idx].width_den / 2;
497 width /= border_details[idx].width_den;
501 width = border_details[idx].width_num * editor->nZoomNumerator;
502 width += border_details[idx].width_den * editor->nZoomNumerator / 2;
503 width /= border_details[idx].width_den * editor->nZoomDenominator;
508 int ME_GetParaBorderWidth(ME_TextEditor* editor, int flags)
510 int idx = (flags >> 8) & 0xF;
513 if (idx >= sizeof(border_details) / sizeof(border_details[0]))
515 FIXME("Unsupported border value %d\n", idx);
518 width = ME_GetBorderPenWidth(editor, idx);
519 if (border_details[idx].dble) width = width * 2 + 1;
523 int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
526 if (!(para->pFmt->dwMask & PFM_LINESPACING)) return 0;
528 /* FIXME: how to compute simply the line space in ls ??? */
529 /* FIXME: does line spacing include the line itself ??? */
530 switch (para->pFmt->bLineSpacingRule)
532 case 0: sp = ls; break;
533 case 1: sp = (3 * ls) / 2; break;
534 case 2: sp = 2 * ls; break;
535 case 3: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); if (sp < ls) sp = ls; break;
536 case 4: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); break;
537 case 5: sp = para->pFmt->dyLineSpacing / 20; break;
538 default: FIXME("Unsupported spacing rule value %d\n", para->pFmt->bLineSpacingRule);
540 if (c->editor->nZoomNumerator == 0)
543 return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
546 static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT* bounds)
548 int idx, border_width, top_border, bottom_border;
552 SetRectEmpty(bounds);
553 if (!(para->pFmt->dwMask & (PFM_BORDER | PFM_SPACEBEFORE | PFM_SPACEAFTER))) return;
555 border_width = top_border = bottom_border = 0;
556 idx = (para->pFmt->wBorders >> 8) & 0xF;
557 hasParaBorder = (!(c->editor->bEmulateVersion10 &&
558 para->pFmt->dwMask & PFM_TABLE &&
559 para->pFmt->wEffects & PFE_TABLE) &&
560 (para->pFmt->dwMask & PFM_BORDER) &&
562 (para->pFmt->wBorders & 0xF));
565 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
566 * controls. It actually stores the paragraph or row border style. Although
567 * the value isn't used for drawing, it is used for streaming out rich text.
569 * wBorders stores the border style for each side (top, left, bottom, right)
570 * using nibble (4 bits) to store each border style. The rich text format
571 * control words, and their associated value are the following:
581 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
582 * The mask corresponding to each side for the version are the following:
586 * 0x0F00 bottom right
587 * 0xF000 right bottom
589 if (para->pFmt->wBorders & 0x00B0)
590 FIXME("Unsupported border flags %x\n", para->pFmt->wBorders);
591 border_width = ME_GetParaBorderWidth(c->editor, para->pFmt->wBorders);
592 if (para->pFmt->wBorders & 4) top_border = border_width;
593 if (para->pFmt->wBorders & 8) bottom_border = border_width;
596 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
598 rc.left = c->rcView.left;
599 rc.right = c->rcView.right;
601 bounds->top = ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
602 rc.bottom = y + bounds->top + top_border;
603 FillRect(c->hDC, &rc, c->editor->hbrBackground);
606 if (para->pFmt->dwMask & PFM_SPACEAFTER)
608 rc.left = c->rcView.left;
609 rc.right = c->rcView.right;
610 rc.bottom = y + para->nHeight;
611 bounds->bottom = ME_twips2pointsY(c, para->pFmt->dySpaceAfter);
612 rc.top = rc.bottom - bounds->bottom - bottom_border;
613 FillRect(c->hDC, &rc, c->editor->hbrBackground);
616 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
617 * but might support it in later versions. */
619 int pen_width, rightEdge;
621 HPEN pen = NULL, oldpen = NULL;
624 if (para->pFmt->wBorders & 64) /* autocolor */
625 pencr = ITextHost_TxGetSysColor(c->editor->texthost,
628 pencr = pen_colors[(para->pFmt->wBorders >> 12) & 0xF];
630 rightEdge = c->pt.x + max(c->editor->sizeWindow.cx,
631 c->editor->nTotalWidth);
633 pen_width = ME_GetBorderPenWidth(c->editor, idx);
634 pen = CreatePen(border_details[idx].pen_style, pen_width, pencr);
635 oldpen = SelectObject(c->hDC, pen);
636 MoveToEx(c->hDC, 0, 0, &pt);
638 /* before & after spaces are not included in border */
640 /* helper to draw the double lines in case of corner */
641 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
643 if (para->pFmt->wBorders & 1)
645 MoveToEx(c->hDC, c->pt.x, y + bounds->top, NULL);
646 LineTo(c->hDC, c->pt.x, y + para->nHeight - bounds->bottom);
647 if (border_details[idx].dble) {
648 rc.left = c->pt.x + 1;
649 rc.right = rc.left + border_width;
650 rc.top = y + bounds->top;
651 rc.bottom = y + para->nHeight - bounds->bottom;
652 FillRect(c->hDC, &rc, c->editor->hbrBackground);
653 MoveToEx(c->hDC, c->pt.x + pen_width + 1, y + bounds->top + DD(4), NULL);
654 LineTo(c->hDC, c->pt.x + pen_width + 1, y + para->nHeight - bounds->bottom - DD(8));
656 bounds->left += border_width;
658 if (para->pFmt->wBorders & 2)
660 MoveToEx(c->hDC, rightEdge - 1, y + bounds->top, NULL);
661 LineTo(c->hDC, rightEdge - 1, y + para->nHeight - bounds->bottom);
662 if (border_details[idx].dble) {
663 rc.left = rightEdge - pen_width - 1;
664 rc.right = rc.left + pen_width;
665 rc.top = y + bounds->top;
666 rc.bottom = y + para->nHeight - bounds->bottom;
667 FillRect(c->hDC, &rc, c->editor->hbrBackground);
668 MoveToEx(c->hDC, rightEdge - 1 - pen_width - 1, y + bounds->top + DD(4), NULL);
669 LineTo(c->hDC, rightEdge - 1 - pen_width - 1, y + para->nHeight - bounds->bottom - DD(8));
671 bounds->right += border_width;
673 if (para->pFmt->wBorders & 4)
675 MoveToEx(c->hDC, c->pt.x, y + bounds->top, NULL);
676 LineTo(c->hDC, rightEdge, y + bounds->top);
677 if (border_details[idx].dble) {
678 MoveToEx(c->hDC, c->pt.x + DD(1), y + bounds->top + pen_width + 1, NULL);
679 LineTo(c->hDC, rightEdge - DD(2), y + bounds->top + pen_width + 1);
681 bounds->top += border_width;
683 if (para->pFmt->wBorders & 8)
685 MoveToEx(c->hDC, c->pt.x, y + para->nHeight - bounds->bottom - 1, NULL);
686 LineTo(c->hDC, rightEdge, y + para->nHeight - bounds->bottom - 1);
687 if (border_details[idx].dble) {
688 MoveToEx(c->hDC, c->pt.x + DD(1), y + para->nHeight - bounds->bottom - 1 - pen_width - 1, NULL);
689 LineTo(c->hDC, rightEdge - DD(2), y + para->nHeight - bounds->bottom - 1 - pen_width - 1);
691 bounds->bottom += border_width;
695 MoveToEx(c->hDC, pt.x, pt.y, NULL);
696 SelectObject(c->hDC, oldpen);
701 static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
703 ME_Paragraph *para = ¶graph->member.para;
704 if (!c->editor->bEmulateVersion10) /* v4.1 */
709 ME_Cell *cell = ¶->pCell->member.cell;
710 ME_DisplayItem *paraAfterRow;
717 BOOL atTop = (para->pCell != para->prev_para->member.para.pCell);
718 BOOL atBottom = (para->pCell != para->next_para->member.para.pCell);
719 int top = c->pt.y + (atTop ? cell->pt.y : para->pt.y);
720 int bottom = (atBottom ?
721 c->pt.y + cell->pt.y + cell->nHeight :
722 top + para->nHeight + (atTop ? cell->yTextOffset : 0));
723 rc.left = c->pt.x + cell->pt.x;
724 rc.right = rc.left + cell->nWidth;
726 /* Erase gap before text if not all borders are the same height. */
727 width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
728 rc.top = top + width;
729 width = cell->yTextOffset - width;
730 rc.bottom = rc.top + width;
732 FillRect(c->hDC, &rc, c->editor->hbrBackground);
735 /* Draw cell borders.
736 * The order borders are draw in is left, top, bottom, right in order
737 * to be consistent with native richedit. This is noticeable from the
738 * overlap of borders of different colours. */
739 if (!(para->nFlags & MEPF_ROWEND)) {
742 if (cell->border.left.width > 0)
744 color = cell->border.left.colorRef;
745 width = max(ME_twips2pointsX(c, cell->border.left.width), 1);
747 color = RGB(192,192,192);
750 logBrush.lbStyle = BS_SOLID;
751 logBrush.lbColor = color;
752 logBrush.lbHatch = 0;
753 pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
754 width, &logBrush, 0, NULL);
755 oldPen = SelectObject(c->hDC, pen);
756 MoveToEx(c->hDC, rc.left, rc.top, &oldPt);
757 LineTo(c->hDC, rc.left, rc.bottom);
758 SelectObject(c->hDC, oldPen);
760 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
764 if (cell->border.top.width > 0)
766 brush = CreateSolidBrush(cell->border.top.colorRef);
767 width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
769 brush = GetStockObject(LTGRAY_BRUSH);
773 rc.bottom = rc.top + width;
774 FillRect(c->hDC, &rc, brush);
775 if (cell->border.top.width > 0)
779 /* Draw the bottom border if at the last paragraph in the cell, and when
780 * in the last row of the table. */
782 int oldLeft = rc.left;
783 width = max(ME_twips2pointsY(c, cell->border.bottom.width), 1);
784 paraAfterRow = ME_GetTableRowEnd(paragraph)->member.para.next_para;
785 if (paraAfterRow->member.para.nFlags & MEPF_ROWSTART) {
786 ME_DisplayItem *nextEndCell;
787 nextEndCell = ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow), diCell);
788 assert(nextEndCell && !nextEndCell->member.cell.next_cell);
789 rc.left = c->pt.x + nextEndCell->member.cell.pt.x;
790 /* FIXME: Native draws FROM the bottom of the table rather than
791 * TO the bottom of the table in this case, but just doing so here
792 * will cause the next row to erase the border. */
795 rc.bottom = rc.top + width;
798 if (rc.left < rc.right) {
799 if (cell->border.bottom.width > 0) {
800 brush = CreateSolidBrush(cell->border.bottom.colorRef);
802 brush = GetStockObject(LTGRAY_BRUSH);
805 rc.top = rc.bottom - width;
806 FillRect(c->hDC, &rc, brush);
807 if (cell->border.bottom.width > 0)
813 /* Right border only drawn if at the end of the table row. */
814 if (!cell->next_cell->member.cell.next_cell &&
815 !(para->nFlags & MEPF_ROWSTART))
819 if (cell->border.right.width > 0) {
820 color = cell->border.right.colorRef;
821 width = max(ME_twips2pointsX(c, cell->border.right.width), 1);
823 color = RGB(192,192,192);
826 logBrush.lbStyle = BS_SOLID;
827 logBrush.lbColor = color;
828 logBrush.lbHatch = 0;
829 pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
830 width, &logBrush, 0, NULL);
831 oldPen = SelectObject(c->hDC, pen);
832 MoveToEx(c->hDC, rc.right - 1, rc.top, &oldPt);
833 LineTo(c->hDC, rc.right - 1, rc.bottom);
834 SelectObject(c->hDC, oldPen);
836 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
839 } else { /* v1.0 - 3.0 */
840 /* Draw simple table border */
841 if (para->pFmt->dwMask & PFM_TABLE && para->pFmt->wEffects & PFE_TABLE) {
842 HPEN pen = NULL, oldpen = NULL;
843 int i, firstX, startX, endX, rowY, rowBottom, nHeight;
845 PARAFORMAT2 *pNextFmt;
847 pen = CreatePen(PS_SOLID, 0, para->border.top.colorRef);
848 oldpen = SelectObject(c->hDC, pen);
850 /* Find the start relative to the text */
851 firstX = c->pt.x + ME_FindItemFwd(paragraph, diRun)->member.run.pt.x;
852 /* Go back by the horizontal gap, which is stored in dxOffset */
853 firstX -= ME_twips2pointsX(c, para->pFmt->dxOffset);
854 /* The left edge, stored in dxStartIndent affected just the first edge */
855 startX = firstX - ME_twips2pointsX(c, para->pFmt->dxStartIndent);
856 rowY = c->pt.y + para->pt.y;
857 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
858 rowY += ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
859 nHeight = ME_FindItemFwd(paragraph, diStartRow)->member.row.nHeight;
860 rowBottom = rowY + nHeight;
862 /* Draw horizontal lines */
863 MoveToEx(c->hDC, firstX, rowY, &oldPt);
864 i = para->pFmt->cTabCount - 1;
865 endX = startX + ME_twips2pointsX(c, para->pFmt->rgxTabs[i] & 0x00ffffff) + 1;
866 LineTo(c->hDC, endX, rowY);
867 pNextFmt = para->next_para->member.para.pFmt;
868 /* The bottom of the row only needs to be drawn if the next row is
870 if (!(pNextFmt && pNextFmt->dwMask & PFM_TABLE && pNextFmt->wEffects &&
873 /* Decrement rowBottom to draw the bottom line within the row, and
874 * to not draw over this line when drawing the vertical lines. */
876 MoveToEx(c->hDC, firstX, rowBottom, NULL);
877 LineTo(c->hDC, endX, rowBottom);
880 /* Draw vertical lines */
881 MoveToEx(c->hDC, firstX, rowY, NULL);
882 LineTo(c->hDC, firstX, rowBottom);
883 for (i = 0; i < para->pFmt->cTabCount; i++)
885 int rightBoundary = para->pFmt->rgxTabs[i] & 0x00ffffff;
886 endX = startX + ME_twips2pointsX(c, rightBoundary);
887 MoveToEx(c->hDC, endX, rowY, NULL);
888 LineTo(c->hDC, endX, rowBottom);
891 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
892 SelectObject(c->hDC, oldpen);
898 static void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph)
900 int align = SetTextAlign(c->hDC, TA_BASELINE);
903 ME_Paragraph *para = NULL;
906 int height = 0, baseline = 0, no=0;
907 BOOL visible = FALSE;
910 rc.right = c->rcView.right;
913 para = ¶graph->member.para;
914 y = c->pt.y + para->pt.y;
917 ME_Cell *cell = ¶->pCell->member.cell;
918 rc.left = c->pt.x + cell->pt.x;
919 rc.right = rc.left + cell->nWidth;
921 if (para->nFlags & MEPF_ROWSTART) {
922 ME_Cell *cell = ¶->next_para->member.para.pCell->member.cell;
923 rc.right = c->pt.x + cell->pt.x;
924 } else if (para->nFlags & MEPF_ROWEND) {
925 ME_Cell *cell = ¶->prev_para->member.para.pCell->member.cell;
926 rc.left = c->pt.x + cell->pt.x + cell->nWidth;
928 ME_DrawParaDecoration(c, para, y, &bounds);
930 if (bounds.left || bounds.right) {
931 rc.left = max(rc.left, c->pt.x + bounds.left);
932 rc.right = min(rc.right, c->pt.x - bounds.right
933 + max(c->editor->sizeWindow.cx,
934 c->editor->nTotalWidth));
937 for (p = paragraph->next; p != para->next_para; p = p->next)
946 if (para->nFlags & (MEPF_ROWSTART|MEPF_ROWEND)) {
947 rc.bottom = y + para->nHeight;
949 rc.bottom = y + p->member.row.nHeight;
951 visible = RectVisible(c->hDC, &rc);
953 FillRect(c->hDC, &rc, c->editor->hbrBackground);
957 /* If scrolled to the right past the end of the text, then
958 * there may be space to the right of the paragraph border. */
959 RECT rcAfterBrdr = rc;
960 rcAfterBrdr.left = rc.right + bounds.right;
961 rcAfterBrdr.right = c->rcView.right;
962 if (RectVisible(c->hDC, &rcAfterBrdr))
963 FillRect(c->hDC, &rcAfterBrdr, c->editor->hbrBackground);
967 const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
970 wsprintfW(buf, wszRowDebug, no);
972 ME_DebugWrite(c->hDC, &pt, buf);
975 height = p->member.row.nHeight;
976 baseline = p->member.row.nBaseline;
980 run = &p->member.run;
981 if (visible && me_debug) {
983 rc.left = c->pt.x + run->pt.x;
984 rc.right = rc.left + run->nWidth;
985 rc.top = c->pt.y + para->pt.y + run->pt.y;
986 rc.bottom = rc.bottom + height;
987 TRACE("rc = (%d, %d, %d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
988 if (run->nFlags & MERF_SKIPPED)
989 DrawFocusRect(c->hDC, &rc);
991 FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
994 ME_DrawRun(c, c->pt.x + run->pt.x,
995 c->pt.y + para->pt.y + run->pt.y + baseline, p, para);
998 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
999 const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
1002 pt.x = c->pt.x + run->pt.x;
1003 pt.y = c->pt.y + para->pt.y + run->pt.y;
1004 wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
1005 ME_DebugWrite(c->hDC, &pt, buf);
1009 /* Clear any space at the bottom of the cell after the text. */
1010 if (para->nFlags & (MEPF_ROWSTART|MEPF_ROWEND))
1013 rc.top = c->pt.y + para->pt.y + para->nHeight;
1014 rc.bottom = c->pt.y + p->member.cell.pt.y + p->member.cell.nHeight;
1015 if (RectVisible(c->hDC, &rc))
1017 FillRect(c->hDC, &rc, c->editor->hbrBackground);
1026 ME_DrawTableBorders(c, paragraph);
1028 SetTextAlign(c->hDC, align);
1031 void ME_ScrollAbs(ME_TextEditor *editor, int x, int y)
1033 BOOL bScrollBarIsVisible, bScrollBarWillBeVisible;
1034 int scrollX = 0, scrollY = 0;
1036 if (editor->horz_si.nPos != x) {
1037 x = min(x, editor->horz_si.nMax);
1038 x = max(x, editor->horz_si.nMin);
1039 ITextHost_TxSetScrollPos(editor->texthost, SB_HORZ, x, TRUE);
1040 scrollX = editor->horz_si.nPos - x;
1041 editor->horz_si.nPos = x;
1044 if (editor->vert_si.nPos != y) {
1045 y = min(y, editor->vert_si.nMax - (int)editor->vert_si.nPage);
1046 y = max(y, editor->vert_si.nMin);
1047 ITextHost_TxSetScrollPos(editor->texthost, SB_VERT, y, TRUE);
1048 scrollY = editor->vert_si.nPos - y;
1049 editor->vert_si.nPos = y;
1052 if (abs(scrollX) > editor->sizeWindow.cx ||
1053 abs(scrollY) > editor->sizeWindow.cy)
1054 ITextHost_TxInvalidateRect(editor->texthost, NULL, TRUE);
1056 ITextHost_TxScrollWindowEx(editor->texthost, scrollX, scrollY,
1057 &editor->rcFormat, &editor->rcFormat,
1058 NULL, NULL, SW_INVALIDATE);
1063 LONG winStyle = GetWindowLongW(editor->hWnd, GWL_STYLE);
1064 bScrollBarIsVisible = (winStyle & WS_HSCROLL) != 0;
1065 bScrollBarWillBeVisible = (editor->nTotalWidth > editor->sizeWindow.cx
1066 && (editor->styleFlags & WS_HSCROLL))
1067 || (editor->styleFlags & ES_DISABLENOSCROLL);
1068 if (bScrollBarIsVisible != bScrollBarWillBeVisible)
1069 ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ,
1070 bScrollBarWillBeVisible);
1072 bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0;
1073 bScrollBarWillBeVisible = (editor->nTotalLength > editor->sizeWindow.cy
1074 && (editor->styleFlags & WS_VSCROLL)
1075 && (editor->styleFlags & ES_MULTILINE))
1076 || (editor->styleFlags & ES_DISABLENOSCROLL);
1077 if (bScrollBarIsVisible != bScrollBarWillBeVisible)
1078 ITextHost_TxShowScrollBar(editor->texthost, SB_VERT,
1079 bScrollBarWillBeVisible);
1081 ME_UpdateScrollBar(editor);
1084 void ME_HScrollAbs(ME_TextEditor *editor, int x)
1086 ME_ScrollAbs(editor, x, editor->vert_si.nPos);
1089 void ME_VScrollAbs(ME_TextEditor *editor, int y)
1091 ME_ScrollAbs(editor, editor->horz_si.nPos, y);
1094 void ME_ScrollUp(ME_TextEditor *editor, int cy)
1096 ME_VScrollAbs(editor, editor->vert_si.nPos - cy);
1099 void ME_ScrollDown(ME_TextEditor *editor, int cy)
1101 ME_VScrollAbs(editor, editor->vert_si.nPos + cy);
1104 void ME_ScrollLeft(ME_TextEditor *editor, int cx)
1106 ME_HScrollAbs(editor, editor->horz_si.nPos - cx);
1109 void ME_ScrollRight(ME_TextEditor *editor, int cx)
1111 ME_HScrollAbs(editor, editor->horz_si.nPos + cx);
1114 /* Calculates the visiblity after a call to SetScrollRange or
1115 * SetScrollInfo with SIF_RANGE. */
1116 static BOOL ME_PostSetScrollRangeVisibility(SCROLLINFO *si)
1118 if (si->fMask & SIF_DISABLENOSCROLL)
1121 /* This must match the check in SetScrollInfo to determine whether
1122 * to show or hide the scrollbars. */
1123 return si->nMin < si->nMax - max(si->nPage - 1, 0);
1126 void ME_UpdateScrollBar(ME_TextEditor *editor)
1128 /* Note that this is the only function that should ever call
1129 * SetScrollInfo with SIF_PAGE or SIF_RANGE. */
1132 BOOL bScrollBarWasVisible, bScrollBarWillBeVisible;
1134 if (ME_WrapMarkedParagraphs(editor))
1135 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1137 si.cbSize = sizeof(si);
1138 si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
1139 if (editor->styleFlags & ES_DISABLENOSCROLL)
1140 si.fMask |= SIF_DISABLENOSCROLL;
1142 /* Update horizontal scrollbar */
1143 bScrollBarWasVisible = editor->horz_si.nMax > editor->horz_si.nPage;
1144 bScrollBarWillBeVisible = editor->nTotalWidth > editor->sizeWindow.cx;
1145 if (editor->horz_si.nPos && !bScrollBarWillBeVisible)
1147 ME_HScrollAbs(editor, 0);
1148 /* ME_HScrollAbs will call this function,
1149 * so nothing else needs to be done here. */
1154 si.nMax = editor->nTotalWidth;
1155 si.nPos = editor->horz_si.nPos;
1156 si.nPage = editor->sizeWindow.cx;
1158 if (si.nMin != editor->horz_si.nMin ||
1159 si.nMax != editor->horz_si.nMax ||
1160 si.nPage != editor->horz_si.nPage)
1162 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
1163 editor->horz_si.nMin = si.nMin;
1164 editor->horz_si.nMax = si.nMax;
1165 editor->horz_si.nPage = si.nPage;
1166 if (bScrollBarWillBeVisible || bScrollBarWasVisible) {
1168 SetScrollInfo(editor->hWnd, SB_HORZ, &si, TRUE);
1170 ITextHost_TxSetScrollRange(editor->texthost, SB_HORZ, si.nMin, si.nMax, FALSE);
1171 ITextHost_TxSetScrollPos(editor->texthost, SB_HORZ, si.nPos, TRUE);
1173 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1174 bScrollBarWasVisible = ME_PostSetScrollRangeVisibility(&si);
1178 if (si.fMask & SIF_DISABLENOSCROLL) {
1179 bScrollBarWillBeVisible = TRUE;
1180 } else if (!(editor->styleFlags & WS_HSCROLL)) {
1181 bScrollBarWillBeVisible = FALSE;
1184 if (bScrollBarWasVisible != bScrollBarWillBeVisible)
1185 ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ, bScrollBarWillBeVisible);
1187 /* Update vertical scrollbar */
1188 bScrollBarWasVisible = editor->vert_si.nMax > editor->vert_si.nPage;
1189 bScrollBarWillBeVisible = editor->nTotalLength > editor->sizeWindow.cy &&
1190 (editor->styleFlags & ES_MULTILINE);
1192 if (editor->vert_si.nPos && !bScrollBarWillBeVisible)
1194 ME_VScrollAbs(editor, 0);
1195 /* ME_VScrollAbs will call this function,
1196 * so nothing else needs to be done here. */
1200 si.nMax = editor->nTotalLength;
1201 si.nPos = editor->vert_si.nPos;
1202 si.nPage = editor->sizeWindow.cy;
1204 if (si.nMin != editor->vert_si.nMin ||
1205 si.nMax != editor->vert_si.nMax ||
1206 si.nPage != editor->vert_si.nPage)
1208 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
1209 editor->vert_si.nMin = si.nMin;
1210 editor->vert_si.nMax = si.nMax;
1211 editor->vert_si.nPage = si.nPage;
1212 if (bScrollBarWillBeVisible || bScrollBarWasVisible) {
1214 SetScrollInfo(editor->hWnd, SB_VERT, &si, TRUE);
1216 ITextHost_TxSetScrollRange(editor->texthost, SB_VERT, si.nMin, si.nMax, FALSE);
1217 ITextHost_TxSetScrollPos(editor->texthost, SB_VERT, si.nPos, TRUE);
1219 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1220 bScrollBarWasVisible = ME_PostSetScrollRangeVisibility(&si);
1224 if (si.fMask & SIF_DISABLENOSCROLL) {
1225 bScrollBarWillBeVisible = TRUE;
1226 } else if (!(editor->styleFlags & WS_VSCROLL)) {
1227 bScrollBarWillBeVisible = FALSE;
1230 if (bScrollBarWasVisible != bScrollBarWillBeVisible)
1231 ITextHost_TxShowScrollBar(editor->texthost, SB_VERT,
1232 bScrollBarWillBeVisible);
1235 void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor)
1237 ME_Run *pRun = &pCursor->pRun->member.run;
1238 ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow);
1239 ME_DisplayItem *pPara = pCursor->pPara;
1245 x = pRun->pt.x + ME_PointFromChar(editor, pRun, pCursor->nOffset);
1246 if (x > editor->horz_si.nPos + editor->sizeWindow.cx)
1247 x = x + 1 - editor->sizeWindow.cx;
1248 else if (x > editor->horz_si.nPos)
1249 x = editor->horz_si.nPos;
1251 y = pPara->member.para.pt.y + pRow->member.row.pt.y;
1252 yheight = pRow->member.row.nHeight;
1254 if (y < editor->vert_si.nPos)
1255 ME_ScrollAbs(editor, x, y);
1256 else if (y + yheight > editor->vert_si.nPos + editor->sizeWindow.cy)
1257 ME_ScrollAbs(editor, x, y + yheight - editor->sizeWindow.cy);
1258 else if (x != editor->horz_si.nPos)
1259 ME_ScrollAbs(editor, x, editor->vert_si.nPos);
1264 ME_InvalidateSelection(ME_TextEditor *editor)
1266 ME_DisplayItem *para1, *para2;
1268 int len = ME_GetTextLength(editor);
1270 ME_GetSelection(editor, &nStart, &nEnd);
1271 /* if both old and new selection are 0-char (= caret only), then
1272 there's no (inverted) area to be repainted, neither old nor new */
1273 if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
1275 ME_WrapMarkedParagraphs(editor);
1276 ME_GetSelectionParas(editor, ¶1, ¶2);
1277 assert(para1->type == diParagraph);
1278 assert(para2->type == diParagraph);
1279 /* last selection markers aren't always updated, which means
1280 * they can point past the end of the document */
1281 if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
1282 ME_MarkForPainting(editor,
1283 ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph),
1284 editor->pBuffer->pLast);
1286 /* if the start part of selection is being expanded or contracted... */
1287 if (nStart < editor->nLastSelStart) {
1288 ME_MarkForPainting(editor, para1, editor->pLastSelStartPara->member.para.next_para);
1289 } else if (nStart > editor->nLastSelStart) {
1290 ME_MarkForPainting(editor, editor->pLastSelStartPara, para1->member.para.next_para);
1293 /* if the end part of selection is being contracted or expanded... */
1294 if (nEnd < editor->nLastSelEnd) {
1295 ME_MarkForPainting(editor, para2, editor->pLastSelEndPara->member.para.next_para);
1296 } else if (nEnd > editor->nLastSelEnd) {
1297 ME_MarkForPainting(editor, editor->pLastSelEndPara, para2->member.para.next_para);
1301 ME_InvalidateMarkedParagraphs(editor);
1302 /* remember the last invalidated position */
1303 ME_GetSelection(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
1304 ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
1305 assert(editor->pLastSelStartPara->type == diParagraph);
1306 assert(editor->pLastSelEndPara->type == diParagraph);
1310 ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
1312 /* TODO: Zoom images and objects */
1314 if (numerator == 0 && denominator == 0)
1316 editor->nZoomNumerator = editor->nZoomDenominator = 0;
1319 if (numerator <= 0 || denominator <= 0)
1321 if (numerator * 64 <= denominator || numerator / denominator >= 64)
1324 editor->nZoomNumerator = numerator;
1325 editor->nZoomDenominator = denominator;
1327 ME_RewrapRepaint(editor);