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 ITextHost_TxViewChange(editor->texthost, TRUE);
135 void ME_UpdateRepaint(ME_TextEditor *editor)
137 /* Should be called whenever the contents of the control have changed */
138 BOOL wrappedParagraphs;
140 wrappedParagraphs = ME_WrapMarkedParagraphs(editor);
141 if (wrappedParagraphs)
142 ME_UpdateScrollBar(editor);
144 /* Ensure that the cursor is visible */
145 ME_EnsureVisible(editor, &editor->pCursors[0]);
147 ME_SendSelChange(editor);
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;
160 ME_RewrapRepaint(ME_TextEditor *editor)
162 /* RewrapRepaint should be called whenever the control has changed in
163 * looks, but not content. Like resizing. */
165 ME_MarkAllForWrapping(editor);
166 ME_WrapMarkedParagraphs(editor);
167 ME_UpdateScrollBar(editor);
171 int ME_twips2pointsX(ME_Context *c, int x)
173 if (c->editor->nZoomNumerator == 0)
174 return x * c->dpi.cx / 1440;
176 return x * c->dpi.cx * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
179 int ME_twips2pointsY(ME_Context *c, int y)
181 if (c->editor->nZoomNumerator == 0)
182 return y * c->dpi.cy / 1440;
184 return y * c->dpi.cy * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
187 static void ME_HighlightSpace(ME_Context *c, int x, int y, LPCWSTR szText,
188 int nChars, ME_Style *s, int width,
189 int nSelFrom, int nSelTo, int ymin, int cy)
192 HGDIOBJ hOldFont = NULL;
195 /* Only highlight if there is a selection in the run and when
196 * EM_HIDESELECTION is not being used to hide the selection. */
197 if (nSelFrom >= nChars || nSelTo < 0 || nSelFrom >= nSelTo
198 || c->editor->bHideSelection)
200 hOldFont = ME_SelectStyleFont(c, s);
203 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
206 if (nSelFrom < 0) nSelFrom = 0;
207 if (nSelTo > nChars) nSelTo = nChars;
208 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
210 if (nSelTo != nChars)
212 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
215 selWidth = width - sz.cx;
217 ME_UnselectStyleFont(c, s, hOldFont);
219 if (c->editor->bEmulateVersion10)
220 PatBlt(hDC, x, ymin, selWidth, cy, DSTINVERT);
227 rect.right = x + selWidth;
228 rect.bottom = ymin + cy;
229 hBrush = CreateSolidBrush(ITextHost_TxGetSysColor(c->editor->texthost,
231 FillRect(hDC, &rect, hBrush);
232 DeleteObject(hBrush);
236 static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText,
237 int nChars, ME_Style *s, int width,
238 int nSelFrom, int nSelTo, int ymin, int cy)
243 int yOffset = 0, yTwipsOffset = 0;
246 HPEN hPen = NULL, hOldPen = NULL;
247 BOOL bHighlightedText = (nSelFrom < nChars && nSelTo >= 0
248 && nSelFrom < nSelTo && !c->editor->bHideSelection);
249 int xSelStart = x, xSelEnd = x;
251 /* lpDx is only needed for tabs to make sure the underline done automatically
252 * by the font extends to the end of the tab. Tabs are always stored as
253 * a single character run, so we can handle this case separately, since
254 * otherwise lpDx would need to specify the lengths of each character. */
255 if (width && nChars == 1)
256 lpDx = &width; /* Make sure underline for tab extends across tab space */
258 hOldFont = ME_SelectStyleFont(c, s);
259 if ((s->fmt.dwMask & s->fmt.dwEffects) & CFM_OFFSET) {
260 yTwipsOffset = s->fmt.yOffset;
262 if ((s->fmt.dwMask & s->fmt.dwEffects) & (CFM_SUPERSCRIPT | CFM_SUBSCRIPT)) {
263 if (s->fmt.dwEffects & CFE_SUPERSCRIPT) yTwipsOffset = s->fmt.yHeight/3;
264 if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
267 yOffset = ME_twips2pointsY(c, yTwipsOffset);
269 if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
271 else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
272 rgb = ITextHost_TxGetSysColor(c->editor->texthost, COLOR_WINDOWTEXT);
274 rgb = s->fmt.crTextColor;
276 /* Determine the area that is selected in the run. */
277 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
278 /* Treat width as an optional parameter. We can get the width from the
279 * text extent of the string if it isn't specified. */
280 if (!width) width = sz.cx;
281 if (bHighlightedText)
289 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
290 xSelStart = x + sz.cx;
292 if (nSelTo >= nChars)
299 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
300 xSelEnd = xSelStart + sz.cx;
304 /* Choose the pen type for underlining the text. */
305 if (s->fmt.dwMask & CFM_UNDERLINETYPE)
307 switch (s->fmt.bUnderlineType)
310 case CFU_UNDERLINEWORD: /* native seems to map it to simple underline (MSDN) */
311 case CFU_UNDERLINEDOUBLE: /* native seems to map it to simple underline (MSDN) */
312 hPen = CreatePen(PS_SOLID, 1, rgb);
314 case CFU_UNDERLINEDOTTED:
315 hPen = CreatePen(PS_DOT, 1, rgb);
318 WINE_FIXME("Unknown underline type (%u)\n", s->fmt.bUnderlineType);
320 case CFU_CF1UNDERLINE: /* this type is supported in the font, do nothing */
321 case CFU_UNDERLINENONE:
327 hOldPen = SelectObject(hDC, hPen);
331 rgbOld = SetTextColor(hDC, rgb);
332 if (bHighlightedText && !c->editor->bEmulateVersion10)
336 /* FIXME: should use textmetrics info for Descent info */
338 MoveToEx(hDC, x, y - yOffset + 1, NULL);
341 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nSelFrom, NULL);
343 LineTo(hDC, xSelStart, y - yOffset + 1);
346 dim.bottom = ymin + cy;
347 dim.left = xSelStart;
349 SetTextColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
350 COLOR_HIGHLIGHTTEXT));
351 rgbBackOld = SetBkColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
353 ExtTextOutW(hDC, xSelStart, y-yOffset, ETO_OPAQUE, &dim,
354 szText+nSelFrom, nSelTo-nSelFrom, lpDx);
356 LineTo(hDC, xSelEnd, y - yOffset + 1);
357 SetBkColor(hDC, rgbBackOld);
358 if (xSelEnd < x + width)
360 SetTextColor(hDC, rgb);
361 ExtTextOutW(hDC, xSelEnd, y-yOffset, 0, NULL, szText+nSelTo,
362 nChars-nSelTo, NULL);
364 LineTo(hDC, x + width, y - yOffset + 1);
369 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, lpDx);
371 /* FIXME: should use textmetrics info for Descent info */
374 MoveToEx(hDC, x, y - yOffset + 1, NULL);
375 LineTo(hDC, x + width, y - yOffset + 1);
378 if (bHighlightedText) /* v1.0 inverts the selection */
380 PatBlt(hDC, xSelStart, ymin, xSelEnd-xSelStart, cy, DSTINVERT);
386 SelectObject(hDC, hOldPen);
389 SetTextColor(hDC, rgbOld);
390 ME_UnselectStyleFont(c, s, hOldFont);
393 static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) {
394 int align = SetTextAlign(hDC, TA_LEFT|TA_TOP);
395 HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
396 COLORREF color = SetTextColor(hDC, RGB(128,128,128));
397 TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText));
398 SelectObject(hDC, hFont);
399 SetTextAlign(hDC, align);
400 SetTextColor(hDC, color);
403 static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para)
405 ME_Run *run = &rundi->member.run;
406 ME_DisplayItem *start;
407 int runofs = run->nCharOfs+para->nCharOfs;
408 int nSelFrom, nSelTo;
409 const WCHAR wszSpace[] = {' ', 0};
411 if (run->nFlags & MERF_HIDDEN)
414 start = ME_FindItemBack(rundi, diStartRow);
415 ME_GetSelectionOfs(c->editor, &nSelFrom, &nSelTo);
417 /* Draw selected end-of-paragraph mark */
418 if (run->nFlags & MERF_ENDPARA)
420 if (runofs >= nSelFrom && runofs < nSelTo)
422 ME_HighlightSpace(c, x, y, wszSpace, 1, run->style, 0, 0, 1,
423 c->pt.y + para->pt.y + start->member.row.pt.y,
424 start->member.row.nHeight);
429 if (run->nFlags & (MERF_TAB | MERF_ENDCELL))
431 /* wszSpace is used instead of the tab character because otherwise
432 * an unwanted symbol can be inserted instead. */
433 ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, run->nWidth,
434 nSelFrom-runofs, nSelTo-runofs,
435 c->pt.y + para->pt.y + start->member.row.pt.y,
436 start->member.row.nHeight);
440 if (run->nFlags & MERF_GRAPHICS)
441 ME_DrawOLE(c, x, y, run, para, (runofs >= nSelFrom) && (runofs < nSelTo));
444 if (c->editor->cPasswordMask)
446 ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask, run->strText->nLen);
447 ME_DrawTextWithStyle(c, x, y,
448 szMasked->szData, szMasked->nLen, run->style, run->nWidth,
449 nSelFrom-runofs,nSelTo-runofs,
450 c->pt.y + para->pt.y + start->member.row.pt.y,
451 start->member.row.nHeight);
452 ME_DestroyString(szMasked);
455 ME_DrawTextWithStyle(c, x, y,
456 run->strText->szData, run->strText->nLen, run->style, run->nWidth,
457 nSelFrom-runofs,nSelTo-runofs,
458 c->pt.y + para->pt.y + start->member.row.pt.y,
459 start->member.row.nHeight);
463 /* The documented widths are in points (72 dpi), but converting them to
464 * 96 dpi (standard display resolution) avoids dealing with fractions. */
465 static const struct {unsigned width : 8, pen_style : 4, dble : 1;} border_details[] = {
466 /* none */ {0, PS_SOLID, FALSE},
467 /* 3/4 */ {1, PS_SOLID, FALSE},
468 /* 1 1/2 */ {2, PS_SOLID, FALSE},
469 /* 2 1/4 */ {3, PS_SOLID, FALSE},
470 /* 3 */ {4, PS_SOLID, FALSE},
471 /* 4 1/2 */ {6, PS_SOLID, FALSE},
472 /* 6 */ {8, PS_SOLID, FALSE},
473 /* 3/4 double */ {1, PS_SOLID, TRUE},
474 /* 1 1/2 double */ {2, PS_SOLID, TRUE},
475 /* 2 1/4 double */ {3, PS_SOLID, TRUE},
476 /* 3/4 gray */ {1, PS_DOT /* FIXME */, FALSE},
477 /* 1 1/2 dashed */ {2, PS_DASH, FALSE},
480 static const COLORREF pen_colors[16] = {
481 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
482 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
483 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
484 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
485 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
486 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
487 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
488 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
491 static int ME_GetBorderPenWidth(ME_Context* c, int idx)
493 int width = border_details[idx].width;
496 width = MulDiv(width, c->dpi.cx, 96);
498 if (c->editor->nZoomNumerator != 0)
499 width = MulDiv(width, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
504 int ME_GetParaBorderWidth(ME_Context* c, int flags)
506 int idx = (flags >> 8) & 0xF;
509 if (idx >= sizeof(border_details) / sizeof(border_details[0]))
511 FIXME("Unsupported border value %d\n", idx);
514 width = ME_GetBorderPenWidth(c, idx);
515 if (border_details[idx].dble) width = width * 2 + 1;
519 static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT* bounds)
521 int idx, border_width, top_border, bottom_border;
525 SetRectEmpty(bounds);
526 if (!(para->pFmt->dwMask & (PFM_BORDER | PFM_SPACEBEFORE | PFM_SPACEAFTER))) return;
528 border_width = top_border = bottom_border = 0;
529 idx = (para->pFmt->wBorders >> 8) & 0xF;
530 hasParaBorder = (!(c->editor->bEmulateVersion10 &&
531 para->pFmt->dwMask & PFM_TABLE &&
532 para->pFmt->wEffects & PFE_TABLE) &&
533 (para->pFmt->dwMask & PFM_BORDER) &&
535 (para->pFmt->wBorders & 0xF));
538 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
539 * controls. It actually stores the paragraph or row border style. Although
540 * the value isn't used for drawing, it is used for streaming out rich text.
542 * wBorders stores the border style for each side (top, left, bottom, right)
543 * using nibble (4 bits) to store each border style. The rich text format
544 * control words, and their associated value are the following:
554 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
555 * The mask corresponding to each side for the version are the following:
559 * 0x0F00 bottom right
560 * 0xF000 right bottom
562 if (para->pFmt->wBorders & 0x00B0)
563 FIXME("Unsupported border flags %x\n", para->pFmt->wBorders);
564 border_width = ME_GetParaBorderWidth(c, para->pFmt->wBorders);
565 if (para->pFmt->wBorders & 4) top_border = border_width;
566 if (para->pFmt->wBorders & 8) bottom_border = border_width;
569 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
571 rc.left = c->rcView.left;
572 rc.right = c->rcView.right;
574 bounds->top = ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
575 rc.bottom = y + bounds->top + top_border;
576 FillRect(c->hDC, &rc, c->editor->hbrBackground);
579 if (para->pFmt->dwMask & PFM_SPACEAFTER)
581 rc.left = c->rcView.left;
582 rc.right = c->rcView.right;
583 rc.bottom = y + para->nHeight;
584 bounds->bottom = ME_twips2pointsY(c, para->pFmt->dySpaceAfter);
585 rc.top = rc.bottom - bounds->bottom - bottom_border;
586 FillRect(c->hDC, &rc, c->editor->hbrBackground);
589 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
590 * but might support it in later versions. */
592 int pen_width, rightEdge;
594 HPEN pen = NULL, oldpen = NULL;
597 if (para->pFmt->wBorders & 64) /* autocolor */
598 pencr = ITextHost_TxGetSysColor(c->editor->texthost,
601 pencr = pen_colors[(para->pFmt->wBorders >> 12) & 0xF];
603 rightEdge = c->pt.x + max(c->editor->sizeWindow.cx,
604 c->editor->nTotalWidth);
606 pen_width = ME_GetBorderPenWidth(c, idx);
607 pen = CreatePen(border_details[idx].pen_style, pen_width, pencr);
608 oldpen = SelectObject(c->hDC, pen);
609 MoveToEx(c->hDC, 0, 0, &pt);
611 /* before & after spaces are not included in border */
613 /* helper to draw the double lines in case of corner */
614 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
616 if (para->pFmt->wBorders & 1)
618 MoveToEx(c->hDC, c->pt.x, y + bounds->top, NULL);
619 LineTo(c->hDC, c->pt.x, y + para->nHeight - bounds->bottom);
620 if (border_details[idx].dble) {
621 rc.left = c->pt.x + 1;
622 rc.right = rc.left + border_width;
623 rc.top = y + bounds->top;
624 rc.bottom = y + para->nHeight - bounds->bottom;
625 FillRect(c->hDC, &rc, c->editor->hbrBackground);
626 MoveToEx(c->hDC, c->pt.x + pen_width + 1, y + bounds->top + DD(4), NULL);
627 LineTo(c->hDC, c->pt.x + pen_width + 1, y + para->nHeight - bounds->bottom - DD(8));
629 bounds->left += border_width;
631 if (para->pFmt->wBorders & 2)
633 MoveToEx(c->hDC, rightEdge - 1, y + bounds->top, NULL);
634 LineTo(c->hDC, rightEdge - 1, y + para->nHeight - bounds->bottom);
635 if (border_details[idx].dble) {
636 rc.left = rightEdge - pen_width - 1;
637 rc.right = rc.left + pen_width;
638 rc.top = y + bounds->top;
639 rc.bottom = y + para->nHeight - bounds->bottom;
640 FillRect(c->hDC, &rc, c->editor->hbrBackground);
641 MoveToEx(c->hDC, rightEdge - 1 - pen_width - 1, y + bounds->top + DD(4), NULL);
642 LineTo(c->hDC, rightEdge - 1 - pen_width - 1, y + para->nHeight - bounds->bottom - DD(8));
644 bounds->right += border_width;
646 if (para->pFmt->wBorders & 4)
648 MoveToEx(c->hDC, c->pt.x, y + bounds->top, NULL);
649 LineTo(c->hDC, rightEdge, y + bounds->top);
650 if (border_details[idx].dble) {
651 MoveToEx(c->hDC, c->pt.x + DD(1), y + bounds->top + pen_width + 1, NULL);
652 LineTo(c->hDC, rightEdge - DD(2), y + bounds->top + pen_width + 1);
654 bounds->top += border_width;
656 if (para->pFmt->wBorders & 8)
658 MoveToEx(c->hDC, c->pt.x, y + para->nHeight - bounds->bottom - 1, NULL);
659 LineTo(c->hDC, rightEdge, y + para->nHeight - bounds->bottom - 1);
660 if (border_details[idx].dble) {
661 MoveToEx(c->hDC, c->pt.x + DD(1), y + para->nHeight - bounds->bottom - 1 - pen_width - 1, NULL);
662 LineTo(c->hDC, rightEdge - DD(2), y + para->nHeight - bounds->bottom - 1 - pen_width - 1);
664 bounds->bottom += border_width;
668 MoveToEx(c->hDC, pt.x, pt.y, NULL);
669 SelectObject(c->hDC, oldpen);
674 static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
676 ME_Paragraph *para = ¶graph->member.para;
677 if (!c->editor->bEmulateVersion10) /* v4.1 */
682 ME_Cell *cell = ¶->pCell->member.cell;
683 ME_DisplayItem *paraAfterRow;
690 BOOL atTop = (para->pCell != para->prev_para->member.para.pCell);
691 BOOL atBottom = (para->pCell != para->next_para->member.para.pCell);
692 int top = c->pt.y + (atTop ? cell->pt.y : para->pt.y);
693 int bottom = (atBottom ?
694 c->pt.y + cell->pt.y + cell->nHeight :
695 top + para->nHeight + (atTop ? cell->yTextOffset : 0));
696 rc.left = c->pt.x + cell->pt.x;
697 rc.right = rc.left + cell->nWidth;
699 /* Erase gap before text if not all borders are the same height. */
700 width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
701 rc.top = top + width;
702 width = cell->yTextOffset - width;
703 rc.bottom = rc.top + width;
705 FillRect(c->hDC, &rc, c->editor->hbrBackground);
708 /* Draw cell borders.
709 * The order borders are draw in is left, top, bottom, right in order
710 * to be consistent with native richedit. This is noticeable from the
711 * overlap of borders of different colours. */
712 if (!(para->nFlags & MEPF_ROWEND)) {
715 if (cell->border.left.width > 0)
717 color = cell->border.left.colorRef;
718 width = max(ME_twips2pointsX(c, cell->border.left.width), 1);
720 color = RGB(192,192,192);
723 logBrush.lbStyle = BS_SOLID;
724 logBrush.lbColor = color;
725 logBrush.lbHatch = 0;
726 pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
727 width, &logBrush, 0, NULL);
728 oldPen = SelectObject(c->hDC, pen);
729 MoveToEx(c->hDC, rc.left, rc.top, &oldPt);
730 LineTo(c->hDC, rc.left, rc.bottom);
731 SelectObject(c->hDC, oldPen);
733 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
737 if (cell->border.top.width > 0)
739 brush = CreateSolidBrush(cell->border.top.colorRef);
740 width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
742 brush = GetStockObject(LTGRAY_BRUSH);
746 rc.bottom = rc.top + width;
747 FillRect(c->hDC, &rc, brush);
748 if (cell->border.top.width > 0)
752 /* Draw the bottom border if at the last paragraph in the cell, and when
753 * in the last row of the table. */
755 int oldLeft = rc.left;
756 width = max(ME_twips2pointsY(c, cell->border.bottom.width), 1);
757 paraAfterRow = ME_GetTableRowEnd(paragraph)->member.para.next_para;
758 if (paraAfterRow->member.para.nFlags & MEPF_ROWSTART) {
759 ME_DisplayItem *nextEndCell;
760 nextEndCell = ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow), diCell);
761 assert(nextEndCell && !nextEndCell->member.cell.next_cell);
762 rc.left = c->pt.x + nextEndCell->member.cell.pt.x;
763 /* FIXME: Native draws FROM the bottom of the table rather than
764 * TO the bottom of the table in this case, but just doing so here
765 * will cause the next row to erase the border. */
768 rc.bottom = rc.top + width;
771 if (rc.left < rc.right) {
772 if (cell->border.bottom.width > 0) {
773 brush = CreateSolidBrush(cell->border.bottom.colorRef);
775 brush = GetStockObject(LTGRAY_BRUSH);
778 rc.top = rc.bottom - width;
779 FillRect(c->hDC, &rc, brush);
780 if (cell->border.bottom.width > 0)
786 /* Right border only drawn if at the end of the table row. */
787 if (!cell->next_cell->member.cell.next_cell &&
788 !(para->nFlags & MEPF_ROWSTART))
792 if (cell->border.right.width > 0) {
793 color = cell->border.right.colorRef;
794 width = max(ME_twips2pointsX(c, cell->border.right.width), 1);
796 color = RGB(192,192,192);
799 logBrush.lbStyle = BS_SOLID;
800 logBrush.lbColor = color;
801 logBrush.lbHatch = 0;
802 pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
803 width, &logBrush, 0, NULL);
804 oldPen = SelectObject(c->hDC, pen);
805 MoveToEx(c->hDC, rc.right - 1, rc.top, &oldPt);
806 LineTo(c->hDC, rc.right - 1, rc.bottom);
807 SelectObject(c->hDC, oldPen);
809 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
812 } else { /* v1.0 - 3.0 */
813 /* Draw simple table border */
814 if (para->pFmt->dwMask & PFM_TABLE && para->pFmt->wEffects & PFE_TABLE) {
815 HPEN pen = NULL, oldpen = NULL;
816 int i, firstX, startX, endX, rowY, rowBottom, nHeight;
818 PARAFORMAT2 *pNextFmt;
820 pen = CreatePen(PS_SOLID, 0, para->border.top.colorRef);
821 oldpen = SelectObject(c->hDC, pen);
823 /* Find the start relative to the text */
824 firstX = c->pt.x + ME_FindItemFwd(paragraph, diRun)->member.run.pt.x;
825 /* Go back by the horizontal gap, which is stored in dxOffset */
826 firstX -= ME_twips2pointsX(c, para->pFmt->dxOffset);
827 /* The left edge, stored in dxStartIndent affected just the first edge */
828 startX = firstX - ME_twips2pointsX(c, para->pFmt->dxStartIndent);
829 rowY = c->pt.y + para->pt.y;
830 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
831 rowY += ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
832 nHeight = ME_FindItemFwd(paragraph, diStartRow)->member.row.nHeight;
833 rowBottom = rowY + nHeight;
835 /* Draw horizontal lines */
836 MoveToEx(c->hDC, firstX, rowY, &oldPt);
837 i = para->pFmt->cTabCount - 1;
838 endX = startX + ME_twips2pointsX(c, para->pFmt->rgxTabs[i] & 0x00ffffff) + 1;
839 LineTo(c->hDC, endX, rowY);
840 pNextFmt = para->next_para->member.para.pFmt;
841 /* The bottom of the row only needs to be drawn if the next row is
843 if (!(pNextFmt && pNextFmt->dwMask & PFM_TABLE && pNextFmt->wEffects &&
846 /* Decrement rowBottom to draw the bottom line within the row, and
847 * to not draw over this line when drawing the vertical lines. */
849 MoveToEx(c->hDC, firstX, rowBottom, NULL);
850 LineTo(c->hDC, endX, rowBottom);
853 /* Draw vertical lines */
854 MoveToEx(c->hDC, firstX, rowY, NULL);
855 LineTo(c->hDC, firstX, rowBottom);
856 for (i = 0; i < para->pFmt->cTabCount; i++)
858 int rightBoundary = para->pFmt->rgxTabs[i] & 0x00ffffff;
859 endX = startX + ME_twips2pointsX(c, rightBoundary);
860 MoveToEx(c->hDC, endX, rowY, NULL);
861 LineTo(c->hDC, endX, rowBottom);
864 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
865 SelectObject(c->hDC, oldpen);
871 static void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph)
873 int align = SetTextAlign(c->hDC, TA_BASELINE);
876 ME_Paragraph *para = NULL;
879 int height = 0, baseline = 0, no=0;
880 BOOL visible = FALSE;
883 rc.right = c->rcView.right;
886 para = ¶graph->member.para;
887 y = c->pt.y + para->pt.y;
890 ME_Cell *cell = ¶->pCell->member.cell;
891 rc.left = c->pt.x + cell->pt.x;
892 rc.right = rc.left + cell->nWidth;
894 if (para->nFlags & MEPF_ROWSTART) {
895 ME_Cell *cell = ¶->next_para->member.para.pCell->member.cell;
896 rc.right = c->pt.x + cell->pt.x;
897 } else if (para->nFlags & MEPF_ROWEND) {
898 ME_Cell *cell = ¶->prev_para->member.para.pCell->member.cell;
899 rc.left = c->pt.x + cell->pt.x + cell->nWidth;
901 ME_DrawParaDecoration(c, para, y, &bounds);
903 if (bounds.left || bounds.right) {
904 rc.left = max(rc.left, c->pt.x + bounds.left);
905 rc.right = min(rc.right, c->pt.x - bounds.right
906 + max(c->editor->sizeWindow.cx,
907 c->editor->nTotalWidth));
910 for (p = paragraph->next; p != para->next_para; p = p->next)
919 if (para->nFlags & (MEPF_ROWSTART|MEPF_ROWEND)) {
920 rc.bottom = y + para->nHeight;
922 rc.bottom = y + p->member.row.nHeight;
924 visible = RectVisible(c->hDC, &rc);
926 FillRect(c->hDC, &rc, c->editor->hbrBackground);
930 /* If scrolled to the right past the end of the text, then
931 * there may be space to the right of the paragraph border. */
932 RECT rcAfterBrdr = rc;
933 rcAfterBrdr.left = rc.right + bounds.right;
934 rcAfterBrdr.right = c->rcView.right;
935 if (RectVisible(c->hDC, &rcAfterBrdr))
936 FillRect(c->hDC, &rcAfterBrdr, c->editor->hbrBackground);
940 const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
943 wsprintfW(buf, wszRowDebug, no);
945 ME_DebugWrite(c->hDC, &pt, buf);
948 height = p->member.row.nHeight;
949 baseline = p->member.row.nBaseline;
953 run = &p->member.run;
954 if (visible && me_debug) {
956 rc.left = c->pt.x + run->pt.x;
957 rc.right = rc.left + run->nWidth;
958 rc.top = c->pt.y + para->pt.y + run->pt.y;
959 rc.bottom = rc.bottom + height;
960 TRACE("rc = (%d, %d, %d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
961 if (run->nFlags & MERF_SKIPPED)
962 DrawFocusRect(c->hDC, &rc);
964 FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
967 ME_DrawRun(c, c->pt.x + run->pt.x,
968 c->pt.y + para->pt.y + run->pt.y + baseline, p, para);
971 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
972 const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
975 pt.x = c->pt.x + run->pt.x;
976 pt.y = c->pt.y + para->pt.y + run->pt.y;
977 wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
978 ME_DebugWrite(c->hDC, &pt, buf);
982 /* Clear any space at the bottom of the cell after the text. */
983 if (para->nFlags & (MEPF_ROWSTART|MEPF_ROWEND))
986 rc.top = c->pt.y + para->pt.y + para->nHeight;
987 rc.bottom = c->pt.y + p->member.cell.pt.y + p->member.cell.nHeight;
988 if (RectVisible(c->hDC, &rc))
990 FillRect(c->hDC, &rc, c->editor->hbrBackground);
999 ME_DrawTableBorders(c, paragraph);
1001 SetTextAlign(c->hDC, align);
1004 void ME_ScrollAbs(ME_TextEditor *editor, int x, int y)
1006 BOOL bScrollBarIsVisible, bScrollBarWillBeVisible;
1007 int scrollX = 0, scrollY = 0;
1009 if (editor->horz_si.nPos != x) {
1010 x = min(x, editor->horz_si.nMax);
1011 x = max(x, editor->horz_si.nMin);
1012 scrollX = editor->horz_si.nPos - x;
1013 editor->horz_si.nPos = x;
1014 if (editor->horz_si.nMax > 0xFFFF) /* scale to 16-bit value */
1015 x = MulDiv(x, 0xFFFF, editor->horz_si.nMax);
1016 ITextHost_TxSetScrollPos(editor->texthost, SB_HORZ, x, TRUE);
1019 if (editor->vert_si.nPos != y) {
1020 y = min(y, editor->vert_si.nMax - (int)editor->vert_si.nPage);
1021 y = max(y, editor->vert_si.nMin);
1022 scrollY = editor->vert_si.nPos - y;
1023 editor->vert_si.nPos = y;
1024 if (editor->vert_si.nMax > 0xFFFF) /* scale to 16-bit value */
1025 y = MulDiv(y, 0xFFFF, editor->vert_si.nMax);
1026 ITextHost_TxSetScrollPos(editor->texthost, SB_VERT, y, TRUE);
1029 if (abs(scrollX) > editor->sizeWindow.cx ||
1030 abs(scrollY) > editor->sizeWindow.cy)
1031 ITextHost_TxInvalidateRect(editor->texthost, NULL, TRUE);
1033 ITextHost_TxScrollWindowEx(editor->texthost, scrollX, scrollY,
1034 &editor->rcFormat, &editor->rcFormat,
1035 NULL, NULL, SW_INVALIDATE);
1040 LONG winStyle = GetWindowLongW(editor->hWnd, GWL_STYLE);
1041 if (editor->styleFlags & WS_HSCROLL)
1043 bScrollBarIsVisible = (winStyle & WS_HSCROLL) != 0;
1044 bScrollBarWillBeVisible = (editor->nTotalWidth > editor->sizeWindow.cx
1045 && (editor->styleFlags & WS_HSCROLL))
1046 || (editor->styleFlags & ES_DISABLENOSCROLL);
1047 if (bScrollBarIsVisible != bScrollBarWillBeVisible)
1048 ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ,
1049 bScrollBarWillBeVisible);
1052 if (editor->styleFlags & WS_VSCROLL)
1054 bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0;
1055 bScrollBarWillBeVisible = (editor->nTotalLength > editor->sizeWindow.cy
1056 && (editor->styleFlags & WS_VSCROLL)
1057 && (editor->styleFlags & ES_MULTILINE))
1058 || (editor->styleFlags & ES_DISABLENOSCROLL);
1059 if (bScrollBarIsVisible != bScrollBarWillBeVisible)
1060 ITextHost_TxShowScrollBar(editor->texthost, SB_VERT,
1061 bScrollBarWillBeVisible);
1064 ME_UpdateScrollBar(editor);
1067 void ME_HScrollAbs(ME_TextEditor *editor, int x)
1069 ME_ScrollAbs(editor, x, editor->vert_si.nPos);
1072 void ME_VScrollAbs(ME_TextEditor *editor, int y)
1074 ME_ScrollAbs(editor, editor->horz_si.nPos, y);
1077 void ME_ScrollUp(ME_TextEditor *editor, int cy)
1079 ME_VScrollAbs(editor, editor->vert_si.nPos - cy);
1082 void ME_ScrollDown(ME_TextEditor *editor, int cy)
1084 ME_VScrollAbs(editor, editor->vert_si.nPos + cy);
1087 void ME_ScrollLeft(ME_TextEditor *editor, int cx)
1089 ME_HScrollAbs(editor, editor->horz_si.nPos - cx);
1092 void ME_ScrollRight(ME_TextEditor *editor, int cx)
1094 ME_HScrollAbs(editor, editor->horz_si.nPos + cx);
1097 /* Calculates the visiblity after a call to SetScrollRange or
1098 * SetScrollInfo with SIF_RANGE. */
1099 static BOOL ME_PostSetScrollRangeVisibility(SCROLLINFO *si)
1101 if (si->fMask & SIF_DISABLENOSCROLL)
1104 /* This must match the check in SetScrollInfo to determine whether
1105 * to show or hide the scrollbars. */
1106 return si->nMin < si->nMax - max(si->nPage - 1, 0);
1109 void ME_UpdateScrollBar(ME_TextEditor *editor)
1111 /* Note that this is the only function that should ever call
1112 * SetScrollInfo with SIF_PAGE or SIF_RANGE. */
1115 BOOL bScrollBarWasVisible, bScrollBarWillBeVisible;
1117 if (ME_WrapMarkedParagraphs(editor))
1118 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1120 si.cbSize = sizeof(si);
1121 si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
1123 if (editor->styleFlags & ES_DISABLENOSCROLL)
1124 si.fMask |= SIF_DISABLENOSCROLL;
1126 /* Update horizontal scrollbar */
1127 bScrollBarWasVisible = editor->horz_si.nMax > editor->horz_si.nPage;
1128 bScrollBarWillBeVisible = editor->nTotalWidth > editor->sizeWindow.cx;
1129 if (editor->horz_si.nPos && !bScrollBarWillBeVisible)
1131 ME_HScrollAbs(editor, 0);
1132 /* ME_HScrollAbs will call this function,
1133 * so nothing else needs to be done here. */
1137 si.nMax = editor->nTotalWidth;
1138 si.nPos = editor->horz_si.nPos;
1139 si.nPage = editor->sizeWindow.cx;
1141 if (si.nMax != editor->horz_si.nMax ||
1142 si.nPage != editor->horz_si.nPage)
1144 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
1145 editor->horz_si.nMax = si.nMax;
1146 editor->horz_si.nPage = si.nPage;
1147 if ((bScrollBarWillBeVisible || bScrollBarWasVisible) &&
1148 editor->styleFlags & WS_HSCROLL)
1150 if (si.nMax > 0xFFFF)
1152 /* Native scales the scrollbar info to 16-bit external values. */
1153 si.nPos = MulDiv(si.nPos, 0xFFFF, si.nMax);
1157 SetScrollInfo(editor->hWnd, SB_HORZ, &si, TRUE);
1159 ITextHost_TxSetScrollRange(editor->texthost, SB_HORZ, si.nMin, si.nMax, FALSE);
1160 ITextHost_TxSetScrollPos(editor->texthost, SB_HORZ, si.nPos, TRUE);
1162 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1163 bScrollBarWasVisible = ME_PostSetScrollRangeVisibility(&si);
1167 if (editor->styleFlags & WS_HSCROLL)
1169 if (si.fMask & SIF_DISABLENOSCROLL) {
1170 bScrollBarWillBeVisible = TRUE;
1171 } else if (!(editor->styleFlags & WS_HSCROLL)) {
1172 bScrollBarWillBeVisible = FALSE;
1175 if (bScrollBarWasVisible != bScrollBarWillBeVisible)
1176 ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ, bScrollBarWillBeVisible);
1179 /* Update vertical scrollbar */
1180 bScrollBarWasVisible = editor->vert_si.nMax > editor->vert_si.nPage;
1181 bScrollBarWillBeVisible = editor->nTotalLength > editor->sizeWindow.cy &&
1182 (editor->styleFlags & ES_MULTILINE);
1184 if (editor->vert_si.nPos && !bScrollBarWillBeVisible)
1186 ME_VScrollAbs(editor, 0);
1187 /* ME_VScrollAbs will call this function,
1188 * so nothing else needs to be done here. */
1192 si.nMax = editor->nTotalLength;
1193 si.nPos = editor->vert_si.nPos;
1194 si.nPage = editor->sizeWindow.cy;
1196 if (si.nMax != editor->vert_si.nMax ||
1197 si.nPage != editor->vert_si.nPage)
1199 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
1200 editor->vert_si.nMax = si.nMax;
1201 editor->vert_si.nPage = si.nPage;
1202 if ((bScrollBarWillBeVisible || bScrollBarWasVisible) &&
1203 editor->styleFlags & WS_VSCROLL)
1205 if (si.nMax > 0xFFFF)
1207 /* Native scales the scrollbar info to 16-bit external values. */
1208 si.nPos = MulDiv(si.nPos, 0xFFFF, si.nMax);
1212 SetScrollInfo(editor->hWnd, SB_VERT, &si, TRUE);
1214 ITextHost_TxSetScrollRange(editor->texthost, SB_VERT, si.nMin, si.nMax, FALSE);
1215 ITextHost_TxSetScrollPos(editor->texthost, SB_VERT, si.nPos, TRUE);
1217 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1218 bScrollBarWasVisible = ME_PostSetScrollRangeVisibility(&si);
1222 if (editor->styleFlags & WS_VSCROLL)
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);
1236 void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor)
1238 ME_Run *pRun = &pCursor->pRun->member.run;
1239 ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow);
1240 ME_DisplayItem *pPara = pCursor->pPara;
1246 if (editor->styleFlags & ES_AUTOHSCROLL)
1248 x = pRun->pt.x + ME_PointFromChar(editor, pRun, pCursor->nOffset);
1249 if (x > editor->horz_si.nPos + editor->sizeWindow.cx)
1250 x = x + 1 - editor->sizeWindow.cx;
1251 else if (x > editor->horz_si.nPos)
1252 x = editor->horz_si.nPos;
1254 if (~editor->styleFlags & ES_AUTOVSCROLL)
1256 ME_HScrollAbs(editor, x);
1260 if (~editor->styleFlags & ES_AUTOVSCROLL)
1262 x = editor->horz_si.nPos;
1265 y = pPara->member.para.pt.y + pRow->member.row.pt.y;
1266 yheight = pRow->member.row.nHeight;
1268 if (y < editor->vert_si.nPos)
1269 ME_ScrollAbs(editor, x, y);
1270 else if (y + yheight > editor->vert_si.nPos + editor->sizeWindow.cy)
1271 ME_ScrollAbs(editor, x, y + yheight - editor->sizeWindow.cy);
1272 else if (x != editor->horz_si.nPos)
1273 ME_ScrollAbs(editor, x, editor->vert_si.nPos);
1278 ME_InvalidateSelection(ME_TextEditor *editor)
1280 ME_DisplayItem *para1, *para2;
1282 int len = ME_GetTextLength(editor);
1284 ME_GetSelectionOfs(editor, &nStart, &nEnd);
1285 /* if both old and new selection are 0-char (= caret only), then
1286 there's no (inverted) area to be repainted, neither old nor new */
1287 if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
1289 ME_WrapMarkedParagraphs(editor);
1290 ME_GetSelectionParas(editor, ¶1, ¶2);
1291 assert(para1->type == diParagraph);
1292 assert(para2->type == diParagraph);
1293 /* last selection markers aren't always updated, which means
1294 * they can point past the end of the document */
1295 if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
1296 ME_MarkForPainting(editor,
1297 ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph),
1298 editor->pBuffer->pLast);
1300 /* if the start part of selection is being expanded or contracted... */
1301 if (nStart < editor->nLastSelStart) {
1302 ME_MarkForPainting(editor, para1, editor->pLastSelStartPara->member.para.next_para);
1303 } else if (nStart > editor->nLastSelStart) {
1304 ME_MarkForPainting(editor, editor->pLastSelStartPara, para1->member.para.next_para);
1307 /* if the end part of selection is being contracted or expanded... */
1308 if (nEnd < editor->nLastSelEnd) {
1309 ME_MarkForPainting(editor, para2, editor->pLastSelEndPara->member.para.next_para);
1310 } else if (nEnd > editor->nLastSelEnd) {
1311 ME_MarkForPainting(editor, editor->pLastSelEndPara, para2->member.para.next_para);
1315 ME_InvalidateMarkedParagraphs(editor);
1316 /* remember the last invalidated position */
1317 ME_GetSelectionOfs(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
1318 ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
1319 assert(editor->pLastSelStartPara->type == diParagraph);
1320 assert(editor->pLastSelEndPara->type == diParagraph);
1324 ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
1326 /* TODO: Zoom images and objects */
1328 if (numerator == 0 && denominator == 0)
1330 editor->nZoomNumerator = editor->nZoomDenominator = 0;
1333 if (numerator <= 0 || denominator <= 0)
1335 if (numerator * 64 <= denominator || numerator / denominator >= 64)
1338 editor->nZoomNumerator = numerator;
1339 editor->nZoomDenominator = denominator;
1341 ME_RewrapRepaint(editor);