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);
47 ME_MoveCaret(editor); /* Calls ME_WrapMarkedParagraphs */
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 BOOL bPaint = (rcUpdate == NULL);
79 bPaint = ys < rcUpdate->bottom && ye > rcUpdate->top;
82 ME_DrawParagraph(&c, item);
83 /* Clear the repaint flag if the whole paragraph is in the
85 if (!rcUpdate || (rcUpdate->top <= ys && rcUpdate->bottom >= ye))
86 item->member.para.nFlags &= ~MEPF_REPAINT;
89 item = item->member.para.next_para;
91 if (c.pt.y + editor->nTotalLength < c.rcView.bottom)
93 /* Fill space after the end of the text. */
95 rc.top = c.pt.y + editor->nTotalLength;
96 rc.left = c.rcView.left;
97 rc.bottom = c.rcView.bottom;
98 rc.right = c.rcView.right;
102 /* Only erase region drawn from previous call to ME_PaintContent */
103 if (editor->nTotalLength < editor->nLastTotalLength)
104 rc.bottom = c.pt.y + editor->nLastTotalLength;
109 IntersectRect(&rc, &rc, rcUpdate);
111 if (!IsRectEmpty(&rc))
112 FillRect(hDC, &rc, c.editor->hbrBackground);
114 if (editor->nTotalLength != editor->nLastTotalLength ||
115 editor->nTotalWidth != editor->nLastTotalWidth)
116 ME_SendRequestResize(editor, FALSE);
117 editor->nLastTotalLength = editor->nTotalLength;
118 editor->nLastTotalWidth = editor->nTotalWidth;
120 SelectClipRgn(hDC, oldRgn);
122 DeleteObject(oldRgn);
125 ME_DestroyContext(&c);
128 void ME_Repaint(ME_TextEditor *editor)
130 if (ME_WrapMarkedParagraphs(editor))
132 ME_UpdateScrollBar(editor);
133 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
135 if (!editor->bEmulateVersion10 || (editor->nEventMask & ENM_UPDATE))
136 ME_SendOldNotify(editor, EN_UPDATE);
137 ITextHost_TxViewChange(editor->texthost, TRUE);
140 void ME_UpdateRepaint(ME_TextEditor *editor)
142 /* Should be called whenever the contents of the control have changed */
144 BOOL wrappedParagraphs;
146 wrappedParagraphs = ME_WrapMarkedParagraphs(editor);
147 if (wrappedParagraphs)
148 ME_UpdateScrollBar(editor);
150 /* Ensure that the cursor is visible */
151 pCursor = &editor->pCursors[0];
152 ME_EnsureVisible(editor, pCursor);
154 /* send EN_CHANGE if the event mask asks for it */
155 if(editor->nEventMask & ENM_CHANGE)
157 editor->nEventMask &= ~ENM_CHANGE;
158 ME_SendOldNotify(editor, EN_CHANGE);
159 editor->nEventMask |= ENM_CHANGE;
162 ME_SendSelChange(editor);
166 ME_RewrapRepaint(ME_TextEditor *editor)
168 /* RewrapRepaint should be called whenever the control has changed in
169 * looks, but not content. Like resizing. */
171 ME_MarkAllForWrapping(editor);
172 ME_WrapMarkedParagraphs(editor);
173 ME_UpdateScrollBar(editor);
177 int ME_twips2pointsX(ME_Context *c, int x)
179 if (c->editor->nZoomNumerator == 0)
180 return x * c->dpi.cx / 1440;
182 return x * c->dpi.cx * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
185 int ME_twips2pointsY(ME_Context *c, int y)
187 if (c->editor->nZoomNumerator == 0)
188 return y * c->dpi.cy / 1440;
190 return y * c->dpi.cy * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
193 static void ME_HighlightSpace(ME_Context *c, int x, int y, LPCWSTR szText,
194 int nChars, ME_Style *s, int width,
195 int nSelFrom, int nSelTo, int ymin, int cy)
198 HGDIOBJ hOldFont = NULL;
201 /* Only highlight if there is a selection in the run and when
202 * EM_HIDESELECTION is not being used to hide the selection. */
203 if (nSelFrom >= nChars || nSelTo < 0 || nSelFrom >= nSelTo
204 || c->editor->bHideSelection)
206 hOldFont = ME_SelectStyleFont(c, s);
209 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
212 if (nSelFrom < 0) nSelFrom = 0;
213 if (nSelTo > nChars) nSelTo = nChars;
214 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
216 if (nSelTo != nChars)
218 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
221 selWidth = width - sz.cx;
223 ME_UnselectStyleFont(c, s, hOldFont);
225 if (c->editor->bEmulateVersion10)
226 PatBlt(hDC, x, ymin, selWidth, cy, DSTINVERT);
233 rect.right = x + selWidth;
234 rect.bottom = ymin + cy;
235 hBrush = CreateSolidBrush(ITextHost_TxGetSysColor(c->editor->texthost,
237 FillRect(hDC, &rect, hBrush);
238 DeleteObject(hBrush);
242 static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText,
243 int nChars, ME_Style *s, int width,
244 int nSelFrom, int nSelTo, int ymin, int cy)
249 int yOffset = 0, yTwipsOffset = 0;
252 HPEN hPen = NULL, hOldPen = NULL;
253 BOOL bHighlightedText = (nSelFrom < nChars && nSelTo >= 0
254 && nSelFrom < nSelTo && !c->editor->bHideSelection);
255 int xSelStart = x, xSelEnd = x;
257 /* lpDx is only needed for tabs to make sure the underline done automatically
258 * by the font extends to the end of the tab. Tabs are always stored as
259 * a single character run, so we can handle this case separately, since
260 * otherwise lpDx would need to specify the lengths of each character. */
261 if (width && nChars == 1)
262 lpDx = &width; /* Make sure underline for tab extends across tab space */
264 hOldFont = ME_SelectStyleFont(c, s);
265 if ((s->fmt.dwMask & s->fmt.dwEffects) & CFM_OFFSET) {
266 yTwipsOffset = s->fmt.yOffset;
268 if ((s->fmt.dwMask & s->fmt.dwEffects) & (CFM_SUPERSCRIPT | CFM_SUBSCRIPT)) {
269 if (s->fmt.dwEffects & CFE_SUPERSCRIPT) yTwipsOffset = s->fmt.yHeight/3;
270 if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
273 yOffset = ME_twips2pointsY(c, yTwipsOffset);
275 if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
277 else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
278 rgb = ITextHost_TxGetSysColor(c->editor->texthost, COLOR_WINDOWTEXT);
280 rgb = s->fmt.crTextColor;
282 /* Determine the area that is selected in the run. */
283 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
284 /* Treat width as an optional parameter. We can get the width from the
285 * text extent of the string if it isn't specified. */
286 if (!width) width = sz.cx;
287 if (bHighlightedText)
295 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
296 xSelStart = x + sz.cx;
298 if (nSelTo >= nChars)
305 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
306 xSelEnd = xSelStart + sz.cx;
310 /* Choose the pen type for underlining the text. */
311 if (s->fmt.dwMask & CFM_UNDERLINETYPE)
313 switch (s->fmt.bUnderlineType)
316 case CFU_UNDERLINEWORD: /* native seems to map it to simple underline (MSDN) */
317 case CFU_UNDERLINEDOUBLE: /* native seems to map it to simple underline (MSDN) */
318 hPen = CreatePen(PS_SOLID, 1, rgb);
320 case CFU_UNDERLINEDOTTED:
321 hPen = CreatePen(PS_DOT, 1, rgb);
324 WINE_FIXME("Unknown underline type (%u)\n", s->fmt.bUnderlineType);
326 case CFU_CF1UNDERLINE: /* this type is supported in the font, do nothing */
327 case CFU_UNDERLINENONE:
333 hOldPen = SelectObject(hDC, hPen);
337 rgbOld = SetTextColor(hDC, rgb);
338 if (bHighlightedText && !c->editor->bEmulateVersion10)
342 /* FIXME: should use textmetrics info for Descent info */
344 MoveToEx(hDC, x, y - yOffset + 1, NULL);
347 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nSelFrom, NULL);
349 LineTo(hDC, xSelStart, y - yOffset + 1);
352 dim.bottom = ymin + cy;
353 dim.left = xSelStart;
355 SetTextColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
356 COLOR_HIGHLIGHTTEXT));
357 rgbBackOld = SetBkColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
359 ExtTextOutW(hDC, xSelStart, y-yOffset, ETO_OPAQUE, &dim,
360 szText+nSelFrom, nSelTo-nSelFrom, lpDx);
362 LineTo(hDC, xSelEnd, y - yOffset + 1);
363 SetBkColor(hDC, rgbBackOld);
364 if (xSelEnd < x + width)
366 SetTextColor(hDC, rgb);
367 ExtTextOutW(hDC, xSelEnd, y-yOffset, 0, NULL, szText+nSelTo,
368 nChars-nSelTo, NULL);
370 LineTo(hDC, x + width, y - yOffset + 1);
375 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, lpDx);
377 /* FIXME: should use textmetrics info for Descent info */
380 MoveToEx(hDC, x, y - yOffset + 1, NULL);
381 LineTo(hDC, x + width, y - yOffset + 1);
384 if (bHighlightedText) /* v1.0 inverts the selection */
386 PatBlt(hDC, xSelStart, ymin, xSelEnd-xSelStart, cy, DSTINVERT);
392 SelectObject(hDC, hOldPen);
395 SetTextColor(hDC, rgbOld);
396 ME_UnselectStyleFont(c, s, hOldFont);
399 static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) {
400 int align = SetTextAlign(hDC, TA_LEFT|TA_TOP);
401 HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
402 COLORREF color = SetTextColor(hDC, RGB(128,128,128));
403 TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText));
404 SelectObject(hDC, hFont);
405 SetTextAlign(hDC, align);
406 SetTextColor(hDC, color);
409 static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para)
411 ME_Run *run = &rundi->member.run;
412 ME_DisplayItem *start;
413 int runofs = run->nCharOfs+para->nCharOfs;
414 int nSelFrom, nSelTo;
415 const WCHAR wszSpace[] = {' ', 0};
417 if (run->nFlags & MERF_HIDDEN)
420 start = ME_FindItemBack(rundi, diStartRow);
421 ME_GetSelection(c->editor, &nSelFrom, &nSelTo);
423 /* Draw selected end-of-paragraph mark */
424 if (run->nFlags & MERF_ENDPARA)
426 if (runofs >= nSelFrom && runofs < nSelTo)
428 ME_HighlightSpace(c, x, y, wszSpace, 1, run->style, 0, 0, 1,
429 c->pt.y + para->pt.y + start->member.row.pt.y,
430 start->member.row.nHeight);
435 if (run->nFlags & (MERF_TAB | MERF_ENDCELL))
437 /* wszSpace is used instead of the tab character because otherwise
438 * an unwanted symbol can be inserted instead. */
439 ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, run->nWidth,
440 nSelFrom-runofs, nSelTo-runofs,
441 c->pt.y + para->pt.y + start->member.row.pt.y,
442 start->member.row.nHeight);
446 if (run->nFlags & MERF_GRAPHICS)
447 ME_DrawOLE(c, x, y, run, para, (runofs >= nSelFrom) && (runofs < nSelTo));
450 if (c->editor->cPasswordMask)
452 ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText));
453 ME_DrawTextWithStyle(c, x, y,
454 szMasked->szData, ME_StrVLen(szMasked), run->style, run->nWidth,
455 nSelFrom-runofs,nSelTo-runofs,
456 c->pt.y + para->pt.y + start->member.row.pt.y,
457 start->member.row.nHeight);
458 ME_DestroyString(szMasked);
461 ME_DrawTextWithStyle(c, x, y,
462 run->strText->szData, ME_StrVLen(run->strText), run->style, run->nWidth,
463 nSelFrom-runofs,nSelTo-runofs,
464 c->pt.y + para->pt.y + start->member.row.pt.y,
465 start->member.row.nHeight);
469 static const struct {unsigned width_num : 4, width_den : 4, pen_style : 4, dble : 1;} border_details[] = {
470 /* none */ {0, 1, PS_SOLID, FALSE},
471 /* 3/4 */ {3, 4, PS_SOLID, FALSE},
472 /* 1 1/2 */ {3, 2, PS_SOLID, FALSE},
473 /* 2 1/4 */ {9, 4, PS_SOLID, FALSE},
474 /* 3 */ {3, 1, PS_SOLID, FALSE},
475 /* 4 1/2 */ {9, 2, PS_SOLID, FALSE},
476 /* 6 */ {6, 1, PS_SOLID, FALSE},
477 /* 3/4 double */ {3, 4, PS_SOLID, TRUE},
478 /* 1 1/2 double */ {3, 2, PS_SOLID, TRUE},
479 /* 2 1/4 double */ {9, 4, PS_SOLID, TRUE},
480 /* 3/4 gray */ {3, 4, PS_DOT /* FIXME */, FALSE},
481 /* 1 1/2 dashed */ {3, 2, PS_DASH, FALSE},
484 static const COLORREF pen_colors[16] = {
485 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
486 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
487 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
488 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
489 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
490 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
491 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
492 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
495 static int ME_GetBorderPenWidth(ME_TextEditor* editor, int idx)
499 if (editor->nZoomNumerator == 0)
501 width = border_details[idx].width_num + border_details[idx].width_den / 2;
502 width /= border_details[idx].width_den;
506 width = border_details[idx].width_num * editor->nZoomNumerator;
507 width += border_details[idx].width_den * editor->nZoomNumerator / 2;
508 width /= border_details[idx].width_den * editor->nZoomDenominator;
513 int ME_GetParaBorderWidth(ME_TextEditor* editor, int flags)
515 int idx = (flags >> 8) & 0xF;
518 if (idx >= sizeof(border_details) / sizeof(border_details[0]))
520 FIXME("Unsupported border value %d\n", idx);
523 width = ME_GetBorderPenWidth(editor, idx);
524 if (border_details[idx].dble) width = width * 2 + 1;
528 int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
531 if (!(para->pFmt->dwMask & PFM_LINESPACING)) return 0;
533 /* FIXME: how to compute simply the line space in ls ??? */
534 /* FIXME: does line spacing include the line itself ??? */
535 switch (para->pFmt->bLineSpacingRule)
537 case 0: sp = ls; break;
538 case 1: sp = (3 * ls) / 2; break;
539 case 2: sp = 2 * ls; break;
540 case 3: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); if (sp < ls) sp = ls; break;
541 case 4: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); break;
542 case 5: sp = para->pFmt->dyLineSpacing / 20; break;
543 default: FIXME("Unsupported spacing rule value %d\n", para->pFmt->bLineSpacingRule);
545 if (c->editor->nZoomNumerator == 0)
548 return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
551 static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT* bounds)
553 int idx, border_width, top_border, bottom_border;
557 SetRectEmpty(bounds);
558 if (!(para->pFmt->dwMask & (PFM_BORDER | PFM_SPACEBEFORE | PFM_SPACEAFTER))) return;
560 border_width = top_border = bottom_border = 0;
561 idx = (para->pFmt->wBorders >> 8) & 0xF;
562 hasParaBorder = (!(c->editor->bEmulateVersion10 &&
563 para->pFmt->dwMask & PFM_TABLE &&
564 para->pFmt->wEffects & PFE_TABLE) &&
565 (para->pFmt->dwMask & PFM_BORDER) &&
567 (para->pFmt->wBorders & 0xF));
570 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
571 * controls. It actually stores the paragraph or row border style. Although
572 * the value isn't used for drawing, it is used for streaming out rich text.
574 * wBorders stores the border style for each side (top, left, bottom, right)
575 * using nibble (4 bits) to store each border style. The rich text format
576 * control words, and their associated value are the following:
586 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
587 * The mask corresponding to each side for the version are the following:
591 * 0x0F00 bottom right
592 * 0xF000 right bottom
594 if (para->pFmt->wBorders & 0x00B0)
595 FIXME("Unsupported border flags %x\n", para->pFmt->wBorders);
596 border_width = ME_GetParaBorderWidth(c->editor, para->pFmt->wBorders);
597 if (para->pFmt->wBorders & 4) top_border = border_width;
598 if (para->pFmt->wBorders & 8) bottom_border = border_width;
601 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
603 rc.left = c->rcView.left;
604 rc.right = c->rcView.right;
606 bounds->top = ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
607 rc.bottom = y + bounds->top + top_border;
608 FillRect(c->hDC, &rc, c->editor->hbrBackground);
611 if (para->pFmt->dwMask & PFM_SPACEAFTER)
613 rc.left = c->rcView.left;
614 rc.right = c->rcView.right;
615 rc.bottom = y + para->nHeight;
616 bounds->bottom = ME_twips2pointsY(c, para->pFmt->dySpaceAfter);
617 rc.top = rc.bottom - bounds->bottom - bottom_border;
618 FillRect(c->hDC, &rc, c->editor->hbrBackground);
621 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
622 * but might support it in later versions. */
624 int pen_width, rightEdge;
626 HPEN pen = NULL, oldpen = NULL;
629 if (para->pFmt->wBorders & 64) /* autocolor */
630 pencr = ITextHost_TxGetSysColor(c->editor->texthost,
633 pencr = pen_colors[(para->pFmt->wBorders >> 12) & 0xF];
635 rightEdge = c->pt.x + max(c->editor->sizeWindow.cx,
636 c->editor->nTotalWidth);
638 pen_width = ME_GetBorderPenWidth(c->editor, idx);
639 pen = CreatePen(border_details[idx].pen_style, pen_width, pencr);
640 oldpen = SelectObject(c->hDC, pen);
641 MoveToEx(c->hDC, 0, 0, &pt);
643 /* before & after spaces are not included in border */
645 /* helper to draw the double lines in case of corner */
646 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
648 if (para->pFmt->wBorders & 1)
650 MoveToEx(c->hDC, c->pt.x, y + bounds->top, NULL);
651 LineTo(c->hDC, c->pt.x, y + para->nHeight - bounds->bottom);
652 if (border_details[idx].dble) {
653 rc.left = c->pt.x + 1;
654 rc.right = rc.left + border_width;
655 rc.top = y + bounds->top;
656 rc.bottom = y + para->nHeight - bounds->bottom;
657 FillRect(c->hDC, &rc, c->editor->hbrBackground);
658 MoveToEx(c->hDC, c->pt.x + pen_width + 1, y + bounds->top + DD(4), NULL);
659 LineTo(c->hDC, c->pt.x + pen_width + 1, y + para->nHeight - bounds->bottom - DD(8));
661 bounds->left += border_width;
663 if (para->pFmt->wBorders & 2)
665 MoveToEx(c->hDC, rightEdge - 1, y + bounds->top, NULL);
666 LineTo(c->hDC, rightEdge - 1, y + para->nHeight - bounds->bottom);
667 if (border_details[idx].dble) {
668 rc.left = rightEdge - pen_width - 1;
669 rc.right = rc.left + pen_width;
670 rc.top = y + bounds->top;
671 rc.bottom = y + para->nHeight - bounds->bottom;
672 FillRect(c->hDC, &rc, c->editor->hbrBackground);
673 MoveToEx(c->hDC, rightEdge - 1 - pen_width - 1, y + bounds->top + DD(4), NULL);
674 LineTo(c->hDC, rightEdge - 1 - pen_width - 1, y + para->nHeight - bounds->bottom - DD(8));
676 bounds->right += border_width;
678 if (para->pFmt->wBorders & 4)
680 MoveToEx(c->hDC, c->pt.x, y + bounds->top, NULL);
681 LineTo(c->hDC, rightEdge, y + bounds->top);
682 if (border_details[idx].dble) {
683 MoveToEx(c->hDC, c->pt.x + DD(1), y + bounds->top + pen_width + 1, NULL);
684 LineTo(c->hDC, rightEdge - DD(2), y + bounds->top + pen_width + 1);
686 bounds->top += border_width;
688 if (para->pFmt->wBorders & 8)
690 MoveToEx(c->hDC, c->pt.x, y + para->nHeight - bounds->bottom - 1, NULL);
691 LineTo(c->hDC, rightEdge, y + para->nHeight - bounds->bottom - 1);
692 if (border_details[idx].dble) {
693 MoveToEx(c->hDC, c->pt.x + DD(1), y + para->nHeight - bounds->bottom - 1 - pen_width - 1, NULL);
694 LineTo(c->hDC, rightEdge - DD(2), y + para->nHeight - bounds->bottom - 1 - pen_width - 1);
696 bounds->bottom += border_width;
700 MoveToEx(c->hDC, pt.x, pt.y, NULL);
701 SelectObject(c->hDC, oldpen);
706 static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
708 ME_Paragraph *para = ¶graph->member.para;
709 if (!c->editor->bEmulateVersion10) /* v4.1 */
714 ME_Cell *cell = ¶->pCell->member.cell;
715 ME_DisplayItem *paraAfterRow;
722 BOOL atTop = (para->pCell != para->prev_para->member.para.pCell);
723 BOOL atBottom = (para->pCell != para->next_para->member.para.pCell);
724 int top = c->pt.y + (atTop ? cell->pt.y : para->pt.y);
725 int bottom = (atBottom ?
726 c->pt.y + cell->pt.y + cell->nHeight :
727 top + para->nHeight + (atTop ? cell->yTextOffset : 0));
728 rc.left = c->pt.x + cell->pt.x;
729 rc.right = rc.left + cell->nWidth;
731 /* Erase gap before text if not all borders are the same height. */
732 width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
733 rc.top = top + width;
734 width = cell->yTextOffset - width;
735 rc.bottom = rc.top + width;
737 FillRect(c->hDC, &rc, c->editor->hbrBackground);
740 /* Draw cell borders.
741 * The order borders are draw in is left, top, bottom, right in order
742 * to be consistent with native richedit. This is noticeable from the
743 * overlap of borders of different colours. */
744 if (!(para->nFlags & MEPF_ROWEND)) {
747 if (cell->border.left.width > 0)
749 color = cell->border.left.colorRef;
750 width = max(ME_twips2pointsX(c, cell->border.left.width), 1);
752 color = RGB(192,192,192);
755 logBrush.lbStyle = BS_SOLID;
756 logBrush.lbColor = color;
757 logBrush.lbHatch = 0;
758 pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
759 width, &logBrush, 0, NULL);
760 oldPen = SelectObject(c->hDC, pen);
761 MoveToEx(c->hDC, rc.left, rc.top, &oldPt);
762 LineTo(c->hDC, rc.left, rc.bottom);
763 SelectObject(c->hDC, oldPen);
765 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
769 if (cell->border.top.width > 0)
771 brush = CreateSolidBrush(cell->border.top.colorRef);
772 width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
774 brush = GetStockObject(LTGRAY_BRUSH);
778 rc.bottom = rc.top + width;
779 FillRect(c->hDC, &rc, brush);
780 if (cell->border.top.width > 0)
784 /* Draw the bottom border if at the last paragraph in the cell, and when
785 * in the last row of the table. */
787 int oldLeft = rc.left;
788 width = max(ME_twips2pointsY(c, cell->border.bottom.width), 1);
789 paraAfterRow = ME_GetTableRowEnd(paragraph)->member.para.next_para;
790 if (paraAfterRow->member.para.nFlags & MEPF_ROWSTART) {
791 ME_DisplayItem *nextEndCell;
792 nextEndCell = ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow), diCell);
793 assert(nextEndCell && !nextEndCell->member.cell.next_cell);
794 rc.left = c->pt.x + nextEndCell->member.cell.pt.x;
795 /* FIXME: Native draws FROM the bottom of the table rather than
796 * TO the bottom of the table in this case, but just doing so here
797 * will cause the next row to erase the border. */
800 rc.bottom = rc.top + width;
803 if (rc.left < rc.right) {
804 if (cell->border.bottom.width > 0) {
805 brush = CreateSolidBrush(cell->border.bottom.colorRef);
807 brush = GetStockObject(LTGRAY_BRUSH);
810 rc.top = rc.bottom - width;
811 FillRect(c->hDC, &rc, brush);
812 if (cell->border.bottom.width > 0)
818 /* Right border only drawn if at the end of the table row. */
819 if (!cell->next_cell->member.cell.next_cell &&
820 !(para->nFlags & MEPF_ROWSTART))
824 if (cell->border.right.width > 0) {
825 color = cell->border.right.colorRef;
826 width = max(ME_twips2pointsX(c, cell->border.right.width), 1);
828 color = RGB(192,192,192);
831 logBrush.lbStyle = BS_SOLID;
832 logBrush.lbColor = color;
833 logBrush.lbHatch = 0;
834 pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
835 width, &logBrush, 0, NULL);
836 oldPen = SelectObject(c->hDC, pen);
837 MoveToEx(c->hDC, rc.right - 1, rc.top, &oldPt);
838 LineTo(c->hDC, rc.right - 1, rc.bottom);
839 SelectObject(c->hDC, oldPen);
841 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
844 } else { /* v1.0 - 3.0 */
845 /* Draw simple table border */
846 if (para->pFmt->dwMask & PFM_TABLE && para->pFmt->wEffects & PFE_TABLE) {
847 HPEN pen = NULL, oldpen = NULL;
848 int i, firstX, startX, endX, rowY, rowBottom, nHeight;
850 PARAFORMAT2 *pNextFmt;
852 pen = CreatePen(PS_SOLID, 0, para->border.top.colorRef);
853 oldpen = SelectObject(c->hDC, pen);
855 /* Find the start relative to the text */
856 firstX = c->pt.x + ME_FindItemFwd(paragraph, diRun)->member.run.pt.x;
857 /* Go back by the horizontal gap, which is stored in dxOffset */
858 firstX -= ME_twips2pointsX(c, para->pFmt->dxOffset);
859 /* The left edge, stored in dxStartIndent affected just the first edge */
860 startX = firstX - ME_twips2pointsX(c, para->pFmt->dxStartIndent);
861 rowY = c->pt.y + para->pt.y;
862 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
863 rowY += ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
864 nHeight = ME_FindItemFwd(paragraph, diStartRow)->member.row.nHeight;
865 rowBottom = rowY + nHeight;
867 /* Draw horizontal lines */
868 MoveToEx(c->hDC, firstX, rowY, &oldPt);
869 i = para->pFmt->cTabCount - 1;
870 endX = startX + ME_twips2pointsX(c, para->pFmt->rgxTabs[i] & 0x00ffffff) + 1;
871 LineTo(c->hDC, endX, rowY);
872 pNextFmt = para->next_para->member.para.pFmt;
873 /* The bottom of the row only needs to be drawn if the next row is
875 if (!(pNextFmt && pNextFmt->dwMask & PFM_TABLE && pNextFmt->wEffects &&
878 /* Decrement rowBottom to draw the bottom line within the row, and
879 * to not draw over this line when drawing the vertical lines. */
881 MoveToEx(c->hDC, firstX, rowBottom, NULL);
882 LineTo(c->hDC, endX, rowBottom);
885 /* Draw vertical lines */
886 MoveToEx(c->hDC, firstX, rowY, NULL);
887 LineTo(c->hDC, firstX, rowBottom);
888 for (i = 0; i < para->pFmt->cTabCount; i++)
890 int rightBoundary = para->pFmt->rgxTabs[i] & 0x00ffffff;
891 endX = startX + ME_twips2pointsX(c, rightBoundary);
892 MoveToEx(c->hDC, endX, rowY, NULL);
893 LineTo(c->hDC, endX, rowBottom);
896 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
897 SelectObject(c->hDC, oldpen);
903 static void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph)
905 int align = SetTextAlign(c->hDC, TA_BASELINE);
908 ME_Paragraph *para = NULL;
911 int height = 0, baseline = 0, no=0;
912 BOOL visible = FALSE;
915 rc.right = c->rcView.right;
918 para = ¶graph->member.para;
919 y = c->pt.y + para->pt.y;
922 ME_Cell *cell = ¶->pCell->member.cell;
923 rc.left = c->pt.x + cell->pt.x;
924 rc.right = rc.left + cell->nWidth;
926 if (para->nFlags & MEPF_ROWSTART) {
927 ME_Cell *cell = ¶->next_para->member.para.pCell->member.cell;
928 rc.right = c->pt.x + cell->pt.x;
929 } else if (para->nFlags & MEPF_ROWEND) {
930 ME_Cell *cell = ¶->prev_para->member.para.pCell->member.cell;
931 rc.left = c->pt.x + cell->pt.x + cell->nWidth;
933 ME_DrawParaDecoration(c, para, y, &bounds);
935 if (bounds.left || bounds.right) {
936 rc.left = max(rc.left, c->pt.x + bounds.left);
937 rc.right = min(rc.right, c->pt.x - bounds.right
938 + max(c->editor->sizeWindow.cx,
939 c->editor->nTotalWidth));
942 for (p = paragraph->next; p != para->next_para; p = p->next)
951 if (para->nFlags & (MEPF_ROWSTART|MEPF_ROWEND)) {
952 rc.bottom = y + para->nHeight;
954 rc.bottom = y + p->member.row.nHeight;
956 visible = RectVisible(c->hDC, &rc);
958 FillRect(c->hDC, &rc, c->editor->hbrBackground);
962 /* If scrolled to the right past the end of the text, then
963 * there may be space to the right of the paragraph border. */
964 RECT rcAfterBrdr = rc;
965 rcAfterBrdr.left = rc.right + bounds.right;
966 rcAfterBrdr.right = c->rcView.right;
967 if (RectVisible(c->hDC, &rcAfterBrdr))
968 FillRect(c->hDC, &rcAfterBrdr, c->editor->hbrBackground);
972 const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
975 wsprintfW(buf, wszRowDebug, no);
977 ME_DebugWrite(c->hDC, &pt, buf);
980 height = p->member.row.nHeight;
981 baseline = p->member.row.nBaseline;
985 run = &p->member.run;
986 if (visible && me_debug) {
988 rc.left = c->pt.x + run->pt.x;
989 rc.right = rc.left + run->nWidth;
990 rc.top = c->pt.y + para->pt.y + run->pt.y;
991 rc.bottom = rc.bottom + height;
992 TRACE("rc = (%d, %d, %d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
993 if (run->nFlags & MERF_SKIPPED)
994 DrawFocusRect(c->hDC, &rc);
996 FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
999 ME_DrawRun(c, c->pt.x + run->pt.x,
1000 c->pt.y + para->pt.y + run->pt.y + baseline, p, para);
1003 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
1004 const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
1007 pt.x = c->pt.x + run->pt.x;
1008 pt.y = c->pt.y + para->pt.y + run->pt.y;
1009 wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
1010 ME_DebugWrite(c->hDC, &pt, buf);
1014 /* Clear any space at the bottom of the cell after the text. */
1015 if (para->nFlags & (MEPF_ROWSTART|MEPF_ROWEND))
1018 rc.top = c->pt.y + para->pt.y + para->nHeight;
1019 rc.bottom = c->pt.y + p->member.cell.pt.y + p->member.cell.nHeight;
1020 if (RectVisible(c->hDC, &rc))
1022 FillRect(c->hDC, &rc, c->editor->hbrBackground);
1031 ME_DrawTableBorders(c, paragraph);
1033 SetTextAlign(c->hDC, align);
1036 void ME_ScrollAbs(ME_TextEditor *editor, int x, int y)
1038 BOOL bScrollBarIsVisible, bScrollBarWillBeVisible;
1039 int scrollX = 0, scrollY = 0;
1041 if (editor->horz_si.nPos != x) {
1042 x = min(x, editor->horz_si.nMax);
1043 x = max(x, editor->horz_si.nMin);
1044 ITextHost_TxSetScrollPos(editor->texthost, SB_HORZ, x, TRUE);
1045 scrollX = editor->horz_si.nPos - x;
1046 editor->horz_si.nPos = x;
1049 if (editor->vert_si.nPos != y) {
1050 y = min(y, editor->vert_si.nMax - (int)editor->vert_si.nPage);
1051 y = max(y, editor->vert_si.nMin);
1052 ITextHost_TxSetScrollPos(editor->texthost, SB_VERT, y, TRUE);
1053 scrollY = editor->vert_si.nPos - y;
1054 editor->vert_si.nPos = y;
1057 if (abs(scrollX) > editor->sizeWindow.cx ||
1058 abs(scrollY) > editor->sizeWindow.cy)
1059 ITextHost_TxInvalidateRect(editor->texthost, NULL, TRUE);
1061 ITextHost_TxScrollWindowEx(editor->texthost, scrollX, scrollY,
1062 &editor->rcFormat, &editor->rcFormat,
1063 NULL, NULL, SW_INVALIDATE);
1068 LONG winStyle = GetWindowLongW(editor->hWnd, GWL_STYLE);
1069 bScrollBarIsVisible = (winStyle & WS_HSCROLL) != 0;
1070 bScrollBarWillBeVisible = (editor->nTotalWidth > editor->sizeWindow.cx)
1071 || (editor->styleFlags & ES_DISABLENOSCROLL);
1072 if (bScrollBarIsVisible != bScrollBarWillBeVisible)
1073 ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ,
1074 bScrollBarWillBeVisible);
1076 bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0;
1077 bScrollBarWillBeVisible = (editor->nTotalLength > editor->sizeWindow.cy)
1078 || (editor->styleFlags & ES_DISABLENOSCROLL);
1079 if (bScrollBarIsVisible != bScrollBarWillBeVisible)
1080 ITextHost_TxShowScrollBar(editor->texthost, SB_VERT,
1081 bScrollBarWillBeVisible);
1083 ME_UpdateScrollBar(editor);
1086 void ME_HScrollAbs(ME_TextEditor *editor, int x)
1088 ME_ScrollAbs(editor, x, editor->vert_si.nPos);
1091 void ME_VScrollAbs(ME_TextEditor *editor, int y)
1093 ME_ScrollAbs(editor, editor->horz_si.nPos, y);
1096 void ME_ScrollUp(ME_TextEditor *editor, int cy)
1098 ME_VScrollAbs(editor, editor->vert_si.nPos - cy);
1101 void ME_ScrollDown(ME_TextEditor *editor, int cy)
1103 ME_VScrollAbs(editor, editor->vert_si.nPos + cy);
1106 void ME_ScrollLeft(ME_TextEditor *editor, int cx)
1108 ME_HScrollAbs(editor, editor->horz_si.nPos - cx);
1111 void ME_ScrollRight(ME_TextEditor *editor, int cx)
1113 ME_HScrollAbs(editor, editor->horz_si.nPos + cx);
1116 void ME_UpdateScrollBar(ME_TextEditor *editor)
1118 /* Note that this is the only function that should ever call
1119 * SetScrollInfo with SIF_PAGE or SIF_RANGE. */
1122 BOOL bScrollBarWasVisible, bScrollBarWillBeVisible;
1124 if (ME_WrapMarkedParagraphs(editor))
1125 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1127 si.cbSize = sizeof(si);
1128 si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
1129 if (editor->styleFlags & ES_DISABLENOSCROLL)
1130 si.fMask |= SIF_DISABLENOSCROLL;
1132 /* Update horizontal scrollbar */
1133 bScrollBarWasVisible = editor->horz_si.nMax > editor->horz_si.nPage;
1134 bScrollBarWillBeVisible = editor->nTotalWidth > editor->sizeWindow.cx;
1135 if (editor->horz_si.nPos && !bScrollBarWillBeVisible)
1137 ME_HScrollAbs(editor, 0);
1138 /* ME_HScrollAbs will call this function,
1139 * so nothing else needs to be done here. */
1144 si.nMax = editor->nTotalWidth;
1145 si.nPos = editor->horz_si.nPos;
1146 si.nPage = editor->sizeWindow.cx;
1148 if (si.nMin != editor->horz_si.nMin ||
1149 si.nMax != editor->horz_si.nMax ||
1150 si.nPage != editor->horz_si.nPage)
1152 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
1153 editor->horz_si.nMin = si.nMin;
1154 editor->horz_si.nMax = si.nMax;
1155 editor->horz_si.nPage = si.nPage;
1156 if (bScrollBarWillBeVisible || bScrollBarWasVisible) {
1158 SetScrollInfo(editor->hWnd, SB_HORZ, &si, TRUE);
1160 ITextHost_TxSetScrollRange(editor->texthost, SB_HORZ, si.nMin, si.nMax, FALSE);
1161 ITextHost_TxSetScrollPos(editor->texthost, SB_HORZ, si.nPos, TRUE);
1166 if (si.fMask & SIF_DISABLENOSCROLL)
1167 bScrollBarWillBeVisible = TRUE;
1169 if (bScrollBarWasVisible != bScrollBarWillBeVisible)
1170 ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ, bScrollBarWillBeVisible);
1172 /* Update vertical scrollbar */
1173 bScrollBarWasVisible = editor->vert_si.nMax > editor->vert_si.nPage;
1174 bScrollBarWillBeVisible = editor->nTotalLength > editor->sizeWindow.cy;
1176 if (editor->vert_si.nPos && !bScrollBarWillBeVisible)
1178 ME_VScrollAbs(editor, 0);
1179 /* ME_VScrollAbs will call this function,
1180 * so nothing else needs to be done here. */
1184 si.nMax = editor->nTotalLength;
1185 si.nPos = editor->vert_si.nPos;
1186 si.nPage = editor->sizeWindow.cy;
1188 if (si.nMin != editor->vert_si.nMin ||
1189 si.nMax != editor->vert_si.nMax ||
1190 si.nPage != editor->vert_si.nPage)
1192 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
1193 editor->vert_si.nMin = si.nMin;
1194 editor->vert_si.nMax = si.nMax;
1195 editor->vert_si.nPage = si.nPage;
1196 if (bScrollBarWillBeVisible || bScrollBarWasVisible) {
1198 SetScrollInfo(editor->hWnd, SB_VERT, &si, TRUE);
1200 ITextHost_TxSetScrollRange(editor->texthost, SB_VERT, si.nMin, si.nMax, FALSE);
1201 ITextHost_TxSetScrollPos(editor->texthost, SB_VERT, si.nPos, TRUE);
1206 if (si.fMask & SIF_DISABLENOSCROLL)
1207 bScrollBarWillBeVisible = TRUE;
1209 if (bScrollBarWasVisible != bScrollBarWillBeVisible)
1210 ITextHost_TxShowScrollBar(editor->texthost, SB_VERT,
1211 bScrollBarWillBeVisible);
1214 void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor)
1216 ME_Run *pRun = &pCursor->pRun->member.run;
1217 ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow);
1218 ME_DisplayItem *pPara = ME_FindItemBack(pCursor->pRun, diParagraph);
1224 x = pRun->pt.x + ME_PointFromChar(editor, pRun, pCursor->nOffset);
1225 if (x > editor->horz_si.nPos + editor->sizeWindow.cx)
1226 x = x + 1 - editor->sizeWindow.cx;
1227 else if (x > editor->horz_si.nPos)
1228 x = editor->horz_si.nPos;
1230 y = pPara->member.para.pt.y + pRow->member.row.pt.y;
1231 yheight = pRow->member.row.nHeight;
1233 if (y < editor->vert_si.nPos)
1234 ME_ScrollAbs(editor, x, y);
1235 else if (y + yheight > editor->vert_si.nPos + editor->sizeWindow.cy)
1236 ME_ScrollAbs(editor, x, y + yheight - editor->sizeWindow.cy);
1237 else if (x != editor->horz_si.nPos)
1238 ME_ScrollAbs(editor, x, editor->vert_si.nPos);
1243 ME_InvalidateSelection(ME_TextEditor *editor)
1245 ME_DisplayItem *para1, *para2;
1247 int len = ME_GetTextLength(editor);
1249 ME_GetSelection(editor, &nStart, &nEnd);
1250 /* if both old and new selection are 0-char (= caret only), then
1251 there's no (inverted) area to be repainted, neither old nor new */
1252 if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
1254 ME_WrapMarkedParagraphs(editor);
1255 ME_GetSelectionParas(editor, ¶1, ¶2);
1256 assert(para1->type == diParagraph);
1257 assert(para2->type == diParagraph);
1258 /* last selection markers aren't always updated, which means
1259 they can point past the end of the document */
1260 if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
1261 ME_MarkForPainting(editor,
1262 ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph),
1263 ME_FindItemFwd(editor->pBuffer->pFirst, diTextEnd));
1265 /* if the start part of selection is being expanded or contracted... */
1266 if (nStart < editor->nLastSelStart) {
1267 ME_MarkForPainting(editor, para1, ME_FindItemFwd(editor->pLastSelStartPara, diParagraphOrEnd));
1269 if (nStart > editor->nLastSelStart) {
1270 ME_MarkForPainting(editor, editor->pLastSelStartPara, ME_FindItemFwd(para1, diParagraphOrEnd));
1273 /* if the end part of selection is being contracted or expanded... */
1274 if (nEnd < editor->nLastSelEnd) {
1275 ME_MarkForPainting(editor, para2, ME_FindItemFwd(editor->pLastSelEndPara, diParagraphOrEnd));
1277 if (nEnd > editor->nLastSelEnd) {
1278 ME_MarkForPainting(editor, editor->pLastSelEndPara, ME_FindItemFwd(para2, diParagraphOrEnd));
1282 ME_InvalidateMarkedParagraphs(editor);
1283 /* remember the last invalidated position */
1284 ME_GetSelection(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
1285 ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
1286 assert(editor->pLastSelStartPara->type == diParagraph);
1287 assert(editor->pLastSelEndPara->type == diParagraph);
1291 ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
1293 /* TODO: Zoom images and objects */
1295 if (numerator == 0 && denominator == 0)
1297 editor->nZoomNumerator = editor->nZoomDenominator = 0;
1300 if (numerator <= 0 || denominator <= 0)
1302 if (numerator * 64 <= denominator || numerator / denominator >= 64)
1305 editor->nZoomNumerator = numerator;
1306 editor->nZoomDenominator = denominator;
1308 ME_RewrapRepaint(editor);