richedit: Fix the para computation when zoom is used.
[wine/wine64.git] / dlls / riched20 / paint.c
blob8f71fa531a0f59b9880bc32daf08bd704c1609e5
1 /*
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
22 #include "editor.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
26 void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *rcUpdate) {
27 ME_DisplayItem *item;
28 ME_Context c;
29 int yoffset;
31 editor->nSequence++;
32 yoffset = ME_GetYScrollPos(editor);
33 ME_InitContext(&c, editor, hDC);
34 SetBkMode(hDC, TRANSPARENT);
35 ME_MoveCaret(editor);
36 item = editor->pBuffer->pFirst->next;
37 c.pt.y -= yoffset;
38 while(item != editor->pBuffer->pLast) {
39 int ye;
40 assert(item->type == diParagraph);
41 ye = c.pt.y + item->member.para.nHeight;
42 if (!bOnlyNew || (item->member.para.nFlags & MEPF_REPAINT))
44 BOOL bPaint = (rcUpdate == NULL);
45 if (rcUpdate)
46 bPaint = c.pt.y<rcUpdate->bottom &&
47 c.pt.y+item->member.para.nHeight>rcUpdate->top;
48 if (bPaint)
50 ME_DrawParagraph(&c, item);
51 if (!rcUpdate || (rcUpdate->top<=c.pt.y && rcUpdate->bottom>=ye))
52 item->member.para.nFlags &= ~MEPF_REPAINT;
55 c.pt.y = ye;
56 item = item->member.para.next_para;
58 if (c.pt.y<c.rcView.bottom) {
59 RECT rc;
60 int xs = c.rcView.left, xe = c.rcView.right;
61 int ys = c.pt.y, ye = c.rcView.bottom;
63 if (bOnlyNew)
65 int y1 = editor->nTotalLength-yoffset, y2 = editor->nLastTotalLength-yoffset;
66 if (y1<y2)
67 ys = y1, ye = y2+1;
68 else
69 ys = ye;
72 if (rcUpdate && ys!=ye)
74 xs = rcUpdate->left, xe = rcUpdate->right;
75 if (rcUpdate->top > ys)
76 ys = rcUpdate->top;
77 if (rcUpdate->bottom < ye)
78 ye = rcUpdate->bottom;
81 if (ye>ys) {
82 rc.left = xs;
83 rc.top = ys;
84 rc.right = xe;
85 rc.bottom = ye;
86 FillRect(hDC, &rc, c.editor->hbrBackground);
88 if (ys == c.pt.y) /* don't overwrite the top bar */
89 ys++;
91 if (editor->nTotalLength != editor->nLastTotalLength)
92 ME_SendRequestResize(editor, FALSE);
93 editor->nLastTotalLength = editor->nTotalLength;
94 ME_DestroyContext(&c);
97 void ME_Repaint(ME_TextEditor *editor)
99 if (ME_WrapMarkedParagraphs(editor))
101 ME_UpdateScrollBar(editor);
102 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
104 ME_SendOldNotify(editor, EN_UPDATE);
105 UpdateWindow(editor->hWnd);
108 void ME_UpdateRepaint(ME_TextEditor *editor)
110 /* Should be called whenever the contents of the control have changed */
111 ME_Cursor *pCursor;
113 if (ME_WrapMarkedParagraphs(editor))
114 ME_UpdateScrollBar(editor);
116 /* Ensure that the cursor is visible */
117 pCursor = &editor->pCursors[0];
118 ME_EnsureVisible(editor, pCursor->pRun);
120 /* send EN_CHANGE if the event mask asks for it */
121 if(editor->nEventMask & ENM_CHANGE)
123 editor->nEventMask &= ~ENM_CHANGE;
124 ME_SendOldNotify(editor, EN_CHANGE);
125 editor->nEventMask |= ENM_CHANGE;
127 ME_Repaint(editor);
128 ME_SendSelChange(editor);
131 void
132 ME_RewrapRepaint(ME_TextEditor *editor)
134 /* RewrapRepaint should be called whenever the control has changed in
135 * looks, but not content. Like resizing. */
137 ME_MarkAllForWrapping(editor);
138 ME_WrapMarkedParagraphs(editor);
139 ME_UpdateScrollBar(editor);
141 ME_Repaint(editor);
144 int ME_twips2points(ME_Context *c, int x, int dpi)
146 if (c->editor->nZoomNumerator == 0)
147 return x * dpi / 1440;
148 else
149 return x * dpi * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
152 static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, int nChars,
153 ME_Style *s, int *width, int nSelFrom, int nSelTo, int ymin, int cy) {
154 HDC hDC = c->hDC;
155 HGDIOBJ hOldFont;
156 COLORREF rgbOld;
157 int yOffset = 0, yTwipsOffset = 0;
158 SIZE sz;
159 COLORREF rgb;
161 hOldFont = ME_SelectStyleFont(c->editor, hDC, s);
162 if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
163 rgb = RGB(0,0,255);
164 else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
165 rgb = GetSysColor(COLOR_WINDOWTEXT);
166 else
167 rgb = s->fmt.crTextColor;
168 rgbOld = SetTextColor(hDC, rgb);
169 if ((s->fmt.dwMask & s->fmt.dwEffects) & CFM_OFFSET) {
170 yTwipsOffset = s->fmt.yOffset;
172 if ((s->fmt.dwMask & s->fmt.dwEffects) & (CFM_SUPERSCRIPT | CFM_SUBSCRIPT)) {
173 if (s->fmt.dwEffects & CFE_SUPERSCRIPT) yTwipsOffset = s->fmt.yHeight/3;
174 if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
176 if (yTwipsOffset)
177 yOffset = ME_twips2points(c, yTwipsOffset, GetDeviceCaps(hDC, LOGPIXELSY));
179 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, NULL);
180 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
181 if (width) *width = sz.cx;
182 if (s->fmt.dwMask & CFM_UNDERLINETYPE)
184 HPEN hPen;
185 switch (s->fmt.bUnderlineType)
187 case CFU_UNDERLINE:
188 case CFU_UNDERLINEWORD: /* native seems to map it to simple underline (MSDN) */
189 case CFU_UNDERLINEDOUBLE: /* native seems to map it to simple underline (MSDN) */
190 hPen = CreatePen(PS_SOLID, 1, rgb);
191 break;
192 case CFU_UNDERLINEDOTTED:
193 hPen = CreatePen(PS_DOT, 1, rgb);
194 break;
195 default:
196 WINE_FIXME("Unknown underline type (%u)\n", s->fmt.bUnderlineType);
197 /* fall through */
198 case CFU_CF1UNDERLINE: /* this type is supported in the font, do nothing */
199 case CFU_UNDERLINENONE:
200 hPen = NULL;
201 break;
203 if (hPen != NULL)
205 HPEN hOldPen = SelectObject(hDC, hPen);
206 /* FIXME: should use textmetrics info for Descent info */
207 MoveToEx(hDC, x, y - yOffset + 1, NULL);
208 LineTo(hDC, x + sz.cx, y - yOffset + 1);
209 SelectObject(hDC, hOldPen);
210 DeleteObject(hPen);
213 if (nSelFrom < nChars && nSelTo >= 0 && nSelFrom<nSelTo)
215 if (nSelFrom < 0) nSelFrom = 0;
216 if (nSelTo > nChars) nSelTo = nChars;
217 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
218 x += sz.cx;
219 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
221 /* Invert selection if not hidden by EM_HIDESELECTION */
222 if (c->editor->bHideSelection == FALSE)
223 PatBlt(hDC, x, ymin, sz.cx, cy, DSTINVERT);
225 SetTextColor(hDC, rgbOld);
226 ME_UnselectStyleFont(c->editor, hDC, s, hOldFont);
229 static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) {
230 int align = SetTextAlign(hDC, TA_LEFT|TA_TOP);
231 HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
232 COLORREF color = SetTextColor(hDC, RGB(128,128,128));
233 TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText));
234 SelectObject(hDC, hFont);
235 SetTextAlign(hDC, align);
236 SetTextColor(hDC, color);
239 static void ME_DrawGraphics(ME_Context *c, int x, int y, ME_Run *run,
240 ME_Paragraph *para, BOOL selected) {
241 SIZE sz;
242 int xs, ys, xe, ye, h, ym, width, eyes;
243 ME_GetGraphicsSize(c->editor, run, &sz);
244 xs = run->pt.x;
245 ys = y-sz.cy;
246 xe = xs+sz.cx;
247 ye = y;
248 h = ye-ys;
249 ym = ys+h/4;
250 width = sz.cx;
251 eyes = width/8;
252 /* draw a smiling face :) */
253 Ellipse(c->hDC, xs, ys, xe, ye);
254 Ellipse(c->hDC, xs+width/8, ym, x+width/8+eyes, ym+eyes);
255 Ellipse(c->hDC, xs+7*width/8-eyes, ym, xs+7*width/8, ym+eyes);
256 MoveToEx(c->hDC, xs+width/8, ys+3*h/4-eyes, NULL);
257 LineTo(c->hDC, xs+width/8, ys+3*h/4);
258 LineTo(c->hDC, xs+7*width/8, ys+3*h/4);
259 LineTo(c->hDC, xs+7*width/8, ys+3*h/4-eyes);
260 if (selected)
262 /* descent is usually (always?) 0 for graphics */
263 PatBlt(c->hDC, x, y-run->nAscent, sz.cx, run->nAscent+run->nDescent, DSTINVERT);
267 static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para)
269 ME_Run *run = &rundi->member.run;
270 ME_DisplayItem *start = ME_FindItemBack(rundi, diStartRow);
271 int runofs = run->nCharOfs+para->nCharOfs;
272 int nSelFrom, nSelTo;
273 const WCHAR wszSpace[] = {' ', 0};
275 if (run->nFlags & MERF_HIDDEN)
276 return;
278 ME_GetSelection(c->editor, &nSelFrom, &nSelTo);
280 /* Draw selected end-of-paragraph mark */
281 if (run->nFlags & MERF_ENDPARA && runofs >= nSelFrom && runofs < nSelTo)
282 ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, NULL, 0, 1,
283 c->pt.y + start->member.row.nYPos,
284 start->member.row.nHeight);
286 /* you can always comment it out if you need visible paragraph marks */
287 if (run->nFlags & (MERF_ENDPARA | MERF_TAB | MERF_CELL))
288 return;
290 if (run->nFlags & MERF_GRAPHICS)
291 ME_DrawGraphics(c, x, y, run, para, (runofs >= nSelFrom) && (runofs < nSelTo));
292 else
294 if (c->editor->cPasswordMask)
296 ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText));
297 ME_DrawTextWithStyle(c, x, y,
298 szMasked->szData, ME_StrVLen(szMasked), run->style, NULL,
299 nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.nYPos, start->member.row.nHeight);
300 ME_DestroyString(szMasked);
302 else
303 ME_DrawTextWithStyle(c, x, y,
304 run->strText->szData, ME_StrVLen(run->strText), run->style, NULL,
305 nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.nYPos, start->member.row.nHeight);
309 void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
310 int align = SetTextAlign(c->hDC, TA_BASELINE);
311 int dpi = GetDeviceCaps(c->hDC, LOGPIXELSX);
312 ME_DisplayItem *p;
313 ME_Run *run;
314 ME_Paragraph *para = NULL;
315 RECT rc, rcPara;
316 int y = c->pt.y;
317 int height = 0, baseline = 0, no=0, pno = 0;
318 int xs = 0, xe = 0;
319 BOOL visible = FALSE;
320 int nMargWidth = 0;
322 c->pt.x = c->rcView.left;
323 rcPara.left = c->rcView.left;
324 rcPara.right = c->rcView.right;
325 for (p = paragraph; p!=paragraph->member.para.next_para; p = p->next) {
326 switch(p->type) {
327 case diParagraph:
328 para = &p->member.para;
329 assert(para);
330 nMargWidth = ME_twips2points(c, para->pFmt->dxStartIndent, dpi);
331 if (pno != 0)
332 nMargWidth += ME_twips2points(c, para->pFmt->dxOffset, dpi);
333 xs = c->rcView.left+nMargWidth;
334 xe = c->rcView.right - ME_twips2points(c, para->pFmt->dxRightIndent, dpi);
335 break;
336 case diStartRow:
337 y += height;
338 rcPara.top = y;
339 rcPara.bottom = y+p->member.row.nHeight;
340 visible = RectVisible(c->hDC, &rcPara);
341 if (visible) {
342 /* left margin */
343 rc.left = c->rcView.left;
344 rc.right = c->rcView.left+nMargWidth;
345 rc.top = y;
346 rc.bottom = y+p->member.row.nHeight;
347 FillRect(c->hDC, &rc, c->editor->hbrBackground);
348 /* right margin */
349 rc.left = xe;
350 rc.right = c->rcView.right;
351 FillRect(c->hDC, &rc, c->editor->hbrBackground);
352 rc.left = c->rcView.left+nMargWidth;
353 rc.right = xe;
354 FillRect(c->hDC, &rc, c->editor->hbrBackground);
356 if (me_debug)
358 const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
359 WCHAR buf[128];
360 POINT pt = c->pt;
361 wsprintfW(buf, wszRowDebug, no);
362 pt.y = 12+y;
363 ME_DebugWrite(c->hDC, &pt, buf);
366 height = p->member.row.nHeight;
367 baseline = p->member.row.nBaseline;
368 pno++;
369 break;
370 case diRun:
371 assert(para);
372 run = &p->member.run;
373 if (visible && me_debug) {
374 rc.left = c->rcView.left+run->pt.x;
375 rc.right = c->rcView.left+run->pt.x+run->nWidth;
376 rc.top = c->pt.y+run->pt.y;
377 rc.bottom = c->pt.y+run->pt.y+height;
378 TRACE("rc = (%d, %d, %d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
379 if (run->nFlags & MERF_SKIPPED)
380 DrawFocusRect(c->hDC, &rc);
381 else
382 FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
384 if (visible)
385 ME_DrawRun(c, run->pt.x, c->pt.y+run->pt.y+baseline, p, &paragraph->member.para);
386 if (me_debug)
388 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
389 const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
390 WCHAR buf[2560];
391 POINT pt;
392 pt.x = run->pt.x;
393 pt.y = c->pt.y + run->pt.y;
394 wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
395 ME_DebugWrite(c->hDC, &pt, buf);
397 /* c->pt.x += p->member.run.nWidth; */
398 break;
399 default:
400 break;
402 no++;
404 SetTextAlign(c->hDC, align);
407 void ME_ScrollAbs(ME_TextEditor *editor, int absY)
409 ME_Scroll(editor, absY, 1);
412 void ME_ScrollUp(ME_TextEditor *editor, int cy)
414 ME_Scroll(editor, cy, 2);
417 void ME_ScrollDown(ME_TextEditor *editor, int cy)
419 ME_Scroll(editor, cy, 3);
422 void ME_Scroll(ME_TextEditor *editor, int value, int type)
424 SCROLLINFO si;
425 int nOrigPos, nNewPos, nActualScroll;
427 nOrigPos = ME_GetYScrollPos(editor);
429 si.cbSize = sizeof(SCROLLINFO);
430 si.fMask = SIF_POS;
432 switch (type)
434 case 1:
435 /*Scroll absolutly*/
436 si.nPos = value;
437 break;
438 case 2:
439 /* Scroll up - towards the beginning of the document */
440 si.nPos = nOrigPos - value;
441 break;
442 case 3:
443 /* Scroll down - towards the end of the document */
444 si.nPos = nOrigPos + value;
445 break;
446 default:
447 FIXME("ME_Scroll called incorrectly\n");
448 si.nPos = 0;
451 nNewPos = SetScrollInfo(editor->hWnd, SB_VERT, &si, editor->bRedraw);
452 nActualScroll = nOrigPos - nNewPos;
453 if (editor->bRedraw)
455 if (abs(nActualScroll) > editor->sizeWindow.cy)
456 InvalidateRect(editor->hWnd, NULL, TRUE);
457 else
458 ScrollWindowEx(editor->hWnd, 0, nActualScroll, NULL, NULL, NULL, NULL, SW_INVALIDATE);
459 ME_Repaint(editor);
462 ME_UpdateScrollBar(editor);
466 void ME_UpdateScrollBar(ME_TextEditor *editor)
468 /* Note that this is the only funciton that should ever call SetScrolLInfo
469 * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
470 * be used at all. */
472 HWND hWnd;
473 SCROLLINFO si;
474 BOOL bScrollBarWasVisible,bScrollBarWillBeVisible;
476 if (ME_WrapMarkedParagraphs(editor))
477 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
479 hWnd = editor->hWnd;
480 si.cbSize = sizeof(si);
481 bScrollBarWasVisible = ME_GetYScrollVisible(editor);
482 bScrollBarWillBeVisible = editor->nHeight > editor->sizeWindow.cy;
484 if (bScrollBarWasVisible != bScrollBarWillBeVisible)
486 ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible);
487 ME_MarkAllForWrapping(editor);
488 ME_WrapMarkedParagraphs(editor);
491 si.fMask = SIF_PAGE | SIF_RANGE;
492 if (GetWindowLongW(hWnd, GWL_STYLE) & ES_DISABLENOSCROLL)
493 si.fMask |= SIF_DISABLENOSCROLL;
495 si.nMin = 0;
496 si.nMax = editor->nTotalLength;
498 si.nPage = editor->sizeWindow.cy;
500 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
501 SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
504 int ME_GetYScrollPos(ME_TextEditor *editor)
506 SCROLLINFO si;
507 si.cbSize = sizeof(si);
508 si.fMask = SIF_POS;
509 GetScrollInfo(editor->hWnd, SB_VERT, &si);
510 return si.nPos;
513 BOOL ME_GetYScrollVisible(ME_TextEditor *editor)
514 { /* Returns true if the scrollbar is visible */
515 SCROLLBARINFO sbi;
516 sbi.cbSize = sizeof(sbi);
517 GetScrollBarInfo(editor->hWnd, OBJID_VSCROLL, &sbi);
518 return ((sbi.rgstate[0] & STATE_SYSTEM_INVISIBLE) == 0);
521 void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun)
523 ME_DisplayItem *pRow = ME_FindItemBack(pRun, diStartRow);
524 ME_DisplayItem *pPara = ME_FindItemBack(pRun, diParagraph);
525 int y, yrel, yheight, yold;
527 assert(pRow);
528 assert(pPara);
530 y = pPara->member.para.nYPos+pRow->member.row.nYPos;
531 yheight = pRow->member.row.nHeight;
532 yold = ME_GetYScrollPos(editor);
533 yrel = y - yold;
535 if (y < yold)
536 ME_ScrollAbs(editor,y);
537 else if (yrel + yheight > editor->sizeWindow.cy)
538 ME_ScrollAbs(editor,y+yheight-editor->sizeWindow.cy);
542 void
543 ME_InvalidateFromOfs(ME_TextEditor *editor, int nCharOfs)
545 RECT rc;
546 int x, y, height;
547 ME_Cursor tmp;
549 ME_RunOfsFromCharOfs(editor, nCharOfs, &tmp.pRun, &tmp.nOffset);
550 ME_GetCursorCoordinates(editor, &tmp, &x, &y, &height);
552 rc.left = 0;
553 rc.top = y;
554 rc.bottom = y + height;
555 rc.right = editor->rcFormat.right;
556 InvalidateRect(editor->hWnd, &rc, FALSE);
560 void
561 ME_InvalidateSelection(ME_TextEditor *editor)
563 ME_DisplayItem *para1, *para2;
564 int nStart, nEnd;
565 int len = ME_GetTextLength(editor);
567 ME_GetSelection(editor, &nStart, &nEnd);
568 /* if both old and new selection are 0-char (= caret only), then
569 there's no (inverted) area to be repainted, neither old nor new */
570 if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
571 return;
572 ME_WrapMarkedParagraphs(editor);
573 ME_GetSelectionParas(editor, &para1, &para2);
574 assert(para1->type == diParagraph);
575 assert(para2->type == diParagraph);
576 /* last selection markers aren't always updated, which means
577 they can point past the end of the document */
578 if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
579 ME_MarkForPainting(editor,
580 ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph),
581 ME_FindItemFwd(editor->pBuffer->pFirst, diTextEnd));
582 } else {
583 /* if the start part of selection is being expanded or contracted... */
584 if (nStart < editor->nLastSelStart) {
585 ME_MarkForPainting(editor, para1, ME_FindItemFwd(editor->pLastSelStartPara, diParagraphOrEnd));
586 } else
587 if (nStart > editor->nLastSelStart) {
588 ME_MarkForPainting(editor, editor->pLastSelStartPara, ME_FindItemFwd(para1, diParagraphOrEnd));
591 /* if the end part of selection is being contracted or expanded... */
592 if (nEnd < editor->nLastSelEnd) {
593 ME_MarkForPainting(editor, para2, ME_FindItemFwd(editor->pLastSelEndPara, diParagraphOrEnd));
594 } else
595 if (nEnd > editor->nLastSelEnd) {
596 ME_MarkForPainting(editor, editor->pLastSelEndPara, ME_FindItemFwd(para2, diParagraphOrEnd));
600 ME_InvalidateMarkedParagraphs(editor);
601 /* remember the last invalidated position */
602 ME_GetSelection(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
603 ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
604 assert(editor->pLastSelStartPara->type == diParagraph);
605 assert(editor->pLastSelEndPara->type == diParagraph);
608 void
609 ME_QueueInvalidateFromCursor(ME_TextEditor *editor, int nCursor)
611 editor->nInvalidOfs = ME_GetCursorOfs(editor, nCursor);
615 BOOL
616 ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
618 /* TODO: Zoom images and objects */
620 if (numerator != 0)
622 if (denominator == 0)
623 return FALSE;
624 if (1.0 / 64.0 > (float)numerator / (float)denominator
625 || (float)numerator / (float)denominator > 64.0)
626 return FALSE;
629 editor->nZoomNumerator = numerator;
630 editor->nZoomDenominator = denominator;
632 ME_RewrapRepaint(editor);
633 return TRUE;