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 void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *rcUpdate) {
32 yoffset = ME_GetYScrollPos(editor);
33 ME_InitContext(&c, editor, hDC);
34 SetBkMode(hDC, TRANSPARENT);
36 item = editor->pBuffer->pFirst->next;
38 while(item != editor->pBuffer->pLast) {
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);
46 bPaint = c.pt.y<rcUpdate->bottom &&
47 c.pt.y+item->member.para.nHeight>rcUpdate->top;
50 ME_DrawParagraph(&c, item);
51 if (!rcUpdate || (rcUpdate->top<=c.pt.y && rcUpdate->bottom>=ye))
52 item->member.para.nFlags &= ~MEPF_REPAINT;
56 item = item->member.para.next_para;
58 if (c.pt.y<c.rcView.bottom) {
60 int xs = c.rcView.left, xe = c.rcView.right;
61 int ys = c.pt.y, ye = c.rcView.bottom;
65 int y1 = editor->nTotalLength-yoffset, y2 = editor->nLastTotalLength-yoffset;
72 if (rcUpdate && ys!=ye)
74 xs = rcUpdate->left, xe = rcUpdate->right;
75 if (rcUpdate->top > ys)
77 if (rcUpdate->bottom < ye)
78 ye = rcUpdate->bottom;
86 FillRect(hDC, &rc, c.editor->hbrBackground);
88 if (ys == c.pt.y) /* don't overwrite the top bar */
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 */
113 if (!editor->bRedraw) return;
114 if (ME_WrapMarkedParagraphs(editor))
115 ME_UpdateScrollBar(editor);
117 /* Ensure that the cursor is visible */
118 pCursor = &editor->pCursors[0];
119 ME_EnsureVisible(editor, pCursor->pRun);
121 /* send EN_CHANGE if the event mask asks for it */
122 if(editor->nEventMask & ENM_CHANGE)
124 editor->nEventMask &= ~ENM_CHANGE;
125 ME_SendOldNotify(editor, EN_CHANGE);
126 editor->nEventMask |= ENM_CHANGE;
129 ME_SendSelChange(editor);
133 ME_RewrapRepaint(ME_TextEditor *editor)
135 /* RewrapRepaint should be called whenever the control has changed in
136 * looks, but not content. Like resizing. */
138 ME_MarkAllForWrapping(editor);
141 ME_WrapMarkedParagraphs(editor);
142 ME_UpdateScrollBar(editor);
147 int ME_twips2pointsX(ME_Context *c, int x)
149 if (c->editor->nZoomNumerator == 0)
150 return x * c->dpi.cx / 1440;
152 return x * c->dpi.cx * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
155 int ME_twips2pointsY(ME_Context *c, int y)
157 if (c->editor->nZoomNumerator == 0)
158 return y * c->dpi.cy / 1440;
160 return y * c->dpi.cy * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
163 static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, int nChars,
164 ME_Style *s, int *width, int nSelFrom, int nSelTo, int ymin, int cy) {
168 int yOffset = 0, yTwipsOffset = 0;
172 hOldFont = ME_SelectStyleFont(c, s);
173 if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
175 else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
176 rgb = GetSysColor(COLOR_WINDOWTEXT);
178 rgb = s->fmt.crTextColor;
179 rgbOld = SetTextColor(hDC, rgb);
180 if ((s->fmt.dwMask & s->fmt.dwEffects) & CFM_OFFSET) {
181 yTwipsOffset = s->fmt.yOffset;
183 if ((s->fmt.dwMask & s->fmt.dwEffects) & (CFM_SUPERSCRIPT | CFM_SUBSCRIPT)) {
184 if (s->fmt.dwEffects & CFE_SUPERSCRIPT) yTwipsOffset = s->fmt.yHeight/3;
185 if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
188 yOffset = ME_twips2pointsY(c, yTwipsOffset);
189 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, NULL);
190 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
191 if (width) *width = sz.cx;
192 if (s->fmt.dwMask & CFM_UNDERLINETYPE)
195 switch (s->fmt.bUnderlineType)
198 case CFU_UNDERLINEWORD: /* native seems to map it to simple underline (MSDN) */
199 case CFU_UNDERLINEDOUBLE: /* native seems to map it to simple underline (MSDN) */
200 hPen = CreatePen(PS_SOLID, 1, rgb);
202 case CFU_UNDERLINEDOTTED:
203 hPen = CreatePen(PS_DOT, 1, rgb);
206 WINE_FIXME("Unknown underline type (%u)\n", s->fmt.bUnderlineType);
208 case CFU_CF1UNDERLINE: /* this type is supported in the font, do nothing */
209 case CFU_UNDERLINENONE:
215 HPEN hOldPen = SelectObject(hDC, hPen);
216 /* FIXME: should use textmetrics info for Descent info */
217 MoveToEx(hDC, x, y - yOffset + 1, NULL);
218 LineTo(hDC, x + sz.cx, y - yOffset + 1);
219 SelectObject(hDC, hOldPen);
223 if (nSelFrom < nChars && nSelTo >= 0 && nSelFrom<nSelTo)
225 if (nSelFrom < 0) nSelFrom = 0;
226 if (nSelTo > nChars) nSelTo = nChars;
227 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
229 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
231 /* Invert selection if not hidden by EM_HIDESELECTION */
232 if (c->editor->bHideSelection == FALSE)
233 PatBlt(hDC, x, ymin, sz.cx, cy, DSTINVERT);
235 SetTextColor(hDC, rgbOld);
236 ME_UnselectStyleFont(c, s, hOldFont);
239 static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) {
240 int align = SetTextAlign(hDC, TA_LEFT|TA_TOP);
241 HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
242 COLORREF color = SetTextColor(hDC, RGB(128,128,128));
243 TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText));
244 SelectObject(hDC, hFont);
245 SetTextAlign(hDC, align);
246 SetTextColor(hDC, color);
249 static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para)
251 ME_Run *run = &rundi->member.run;
252 ME_DisplayItem *start;
253 int runofs = run->nCharOfs+para->nCharOfs;
254 int nSelFrom, nSelTo;
255 const WCHAR wszSpace[] = {' ', 0};
257 if (run->nFlags & MERF_HIDDEN)
260 start = ME_FindItemBack(rundi, diStartRow);
261 ME_GetSelection(c->editor, &nSelFrom, &nSelTo);
263 /* Draw selected end-of-paragraph mark */
264 if (run->nFlags & MERF_ENDPARA && runofs >= nSelFrom && runofs < nSelTo)
265 ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, NULL, 0, 1,
266 c->pt.y + start->member.row.nYPos,
267 start->member.row.nHeight);
269 /* you can always comment it out if you need visible paragraph marks */
270 if (run->nFlags & (MERF_ENDPARA | MERF_TAB | MERF_CELL))
273 if (run->nFlags & MERF_GRAPHICS)
274 ME_DrawOLE(c, x, y, run, para, (runofs >= nSelFrom) && (runofs < nSelTo));
277 if (c->editor->cPasswordMask)
279 ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText));
280 ME_DrawTextWithStyle(c, x, y,
281 szMasked->szData, ME_StrVLen(szMasked), run->style, NULL,
282 nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.nYPos, start->member.row.nHeight);
283 ME_DestroyString(szMasked);
286 ME_DrawTextWithStyle(c, x, y,
287 run->strText->szData, ME_StrVLen(run->strText), run->style, NULL,
288 nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.nYPos, start->member.row.nHeight);
292 static struct {unsigned width_num : 4, width_den : 4, pen_style : 4, dble : 1;} border_details[] = {
293 /* none */ {0, 0, PS_SOLID, FALSE},
294 /* 3/4 */ {3, 4, PS_SOLID, FALSE},
295 /* 1 1/2 */ {3, 2, PS_SOLID, FALSE},
296 /* 2 1/4 */ {9, 4, PS_SOLID, FALSE},
297 /* 3 */ {3, 1, PS_SOLID, FALSE},
298 /* 4 1/2 */ {9, 2, PS_SOLID, FALSE},
299 /* 6 */ {6, 1, PS_SOLID, FALSE},
300 /* 3/4 double */ {3, 4, PS_SOLID, TRUE},
301 /* 1 1/2 double */ {3, 2, PS_SOLID, TRUE},
302 /* 2 1/4 double */ {9, 4, PS_SOLID, TRUE},
303 /* 3/4 gray */ {3, 4, PS_DOT /* FIXME */, FALSE},
304 /* 1 1/2 dashed */ {3, 2, PS_DASH, FALSE},
307 static COLORREF pen_colors[16] = {
308 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
309 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
310 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
311 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
312 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
313 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
314 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
315 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
318 static int ME_GetBorderPenWidth(ME_TextEditor* editor, int idx)
322 if (editor->nZoomNumerator == 0)
324 width = border_details[idx].width_num + border_details[idx].width_den / 2;
325 width /= border_details[idx].width_den;
329 width = border_details[idx].width_num * editor->nZoomNumerator;
330 width += border_details[idx].width_den * editor->nZoomNumerator / 2;
331 width /= border_details[idx].width_den * editor->nZoomDenominator;
336 int ME_GetParaBorderWidth(ME_TextEditor* editor, int flags)
338 int idx = (flags >> 8) & 0xF;
341 if (idx >= sizeof(border_details) / sizeof(border_details[0]))
343 FIXME("Unsupported border value %d\n", idx);
346 width = ME_GetBorderPenWidth(editor, idx);
347 if (border_details[idx].dble) width = width * 2 + 1;
351 int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
354 if (!(para->pFmt->dwMask & PFM_LINESPACING)) return 0;
356 /* FIXME: how to compute simply the line space in ls ??? */
357 /* FIXME: does line spacing include the line itself ??? */
358 switch (para->pFmt->bLineSpacingRule)
360 case 0: sp = ls; break;
361 case 1: sp = (3 * ls) / 2; break;
362 case 2: sp = 2 * ls; break;
363 case 3: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); if (sp < ls) sp = ls; break;
364 case 4: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); break;
365 case 5: sp = para->pFmt->dyLineSpacing / 20; break;
366 default: FIXME("Unsupported spacing rule value %d\n", para->pFmt->bLineSpacingRule);
368 if (c->editor->nZoomNumerator == 0)
371 return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
374 static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y)
376 int idx, border_width;
380 if (!(para->pFmt->dwMask & (PFM_BORDER | PFM_SPACEBEFORE | PFM_SPACEAFTER))) return 0;
382 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
384 rc.left = c->rcView.left;
385 rc.right = c->rcView.right;
387 ybefore = ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
388 rc.bottom = y + ybefore;
389 FillRect(c->hDC, &rc, c->editor->hbrBackground);
392 if (para->pFmt->dwMask & PFM_SPACEAFTER)
394 rc.left = c->rcView.left;
395 rc.right = c->rcView.right;
396 rc.bottom = y + para->nHeight;
397 yafter = ME_twips2pointsY(c, para->pFmt->dySpaceAfter);
398 rc.top = rc.bottom - yafter;
399 FillRect(c->hDC, &rc, c->editor->hbrBackground);
404 idx = (para->pFmt->wBorders >> 8) & 0xF;
405 if ((para->pFmt->dwMask & PFM_BORDER) && idx != 0 && (para->pFmt->wBorders & 0xF)) {
408 HPEN pen = NULL, oldpen = NULL;
411 if (para->pFmt->wBorders & 0x00B0)
412 FIXME("Unsupported border flags %x\n", para->pFmt->wBorders);
413 border_width = ME_GetParaBorderWidth(c->editor, para->pFmt->wBorders);
415 if (para->pFmt->wBorders & 64) /* autocolor */
416 pencr = GetSysColor(COLOR_WINDOWTEXT);
418 pencr = pen_colors[(para->pFmt->wBorders >> 12) & 0xF];
420 pen_width = ME_GetBorderPenWidth(c->editor, idx);
421 pen = CreatePen(border_details[idx].pen_style, pen_width, pencr);
422 oldpen = SelectObject(c->hDC, pen);
423 MoveToEx(c->hDC, 0, 0, &pt);
425 /* before & after spaces are not included in border */
426 if (para->pFmt->wBorders & 1)
428 MoveToEx(c->hDC, c->rcView.left, y + ybefore, NULL);
429 LineTo(c->hDC, c->rcView.left, y + para->nHeight - yafter);
430 if (border_details[idx].dble) {
431 MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + ybefore + pen_width + 1, NULL);
432 LineTo(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - yafter - pen_width - 1);
435 if (para->pFmt->wBorders & 2)
437 MoveToEx(c->hDC, c->rcView.right, y + ybefore, NULL);
438 LineTo(c->hDC, c->rcView.right, y + para->nHeight - yafter);
439 if (border_details[idx].dble) {
440 MoveToEx(c->hDC, c->rcView.right - pen_width - 1, y + ybefore + pen_width + 1, NULL);
441 LineTo(c->hDC, c->rcView.right - pen_width - 1, y + para->nHeight - yafter - pen_width - 1);
444 if (para->pFmt->wBorders & 4)
446 MoveToEx(c->hDC, c->rcView.left, y + ybefore, NULL);
447 LineTo(c->hDC, c->rcView.right, y + ybefore);
448 if (border_details[idx].dble) {
449 MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + ybefore + pen_width + 1, NULL);
450 LineTo(c->hDC, c->rcView.right - pen_width - 1, y + ybefore + pen_width + 1);
453 if (para->pFmt->wBorders & 8)
455 MoveToEx(c->hDC, c->rcView.left, y + para->nHeight - yafter - 1, NULL);
456 LineTo(c->hDC, c->rcView.right, y + para->nHeight - yafter - 1);
457 if (border_details[idx].dble) {
458 MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - yafter - 1 - pen_width - 1, NULL);
459 LineTo(c->hDC, c->rcView.right - pen_width - 1, y + para->nHeight - yafter - 1 - pen_width - 1);
463 MoveToEx(c->hDC, pt.x, pt.y, NULL);
464 SelectObject(c->hDC, oldpen);
468 ((para->pFmt->dwMask & PFM_BORDER) && (para->pFmt->wBorders & 4) ?
472 void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
473 int align = SetTextAlign(c->hDC, TA_BASELINE);
476 ME_Paragraph *para = NULL;
479 int height = 0, baseline = 0, no=0, pno = 0;
481 BOOL visible = FALSE;
484 c->pt.x = c->rcView.left;
485 rcPara.left = c->rcView.left;
486 rcPara.right = c->rcView.right;
487 for (p = paragraph; p!=paragraph->member.para.next_para; p = p->next) {
490 para = &p->member.para;
492 nMargWidth = ME_twips2pointsX(c, para->pFmt->dxStartIndent);
494 nMargWidth += ME_twips2pointsX(c, para->pFmt->dxOffset);
495 xs = c->rcView.left+nMargWidth;
496 xe = c->rcView.right - ME_twips2pointsX(c, para->pFmt->dxRightIndent);
497 y += ME_DrawParaDecoration(c, para, y);
502 rcPara.bottom = y+p->member.row.nHeight;
503 visible = RectVisible(c->hDC, &rcPara);
506 rc.left = c->rcView.left;
507 rc.right = c->rcView.left+nMargWidth;
509 rc.bottom = y+p->member.row.nHeight;
510 FillRect(c->hDC, &rc, c->editor->hbrBackground);
513 rc.right = c->rcView.right;
514 FillRect(c->hDC, &rc, c->editor->hbrBackground);
515 rc.left = c->rcView.left+nMargWidth;
517 FillRect(c->hDC, &rc, c->editor->hbrBackground);
521 const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
524 wsprintfW(buf, wszRowDebug, no);
526 ME_DebugWrite(c->hDC, &pt, buf);
529 height = p->member.row.nHeight;
530 baseline = p->member.row.nBaseline;
535 run = &p->member.run;
536 if (visible && me_debug) {
537 rc.left = c->rcView.left+run->pt.x;
538 rc.right = c->rcView.left+run->pt.x+run->nWidth;
539 rc.top = c->pt.y+run->pt.y;
540 rc.bottom = c->pt.y+run->pt.y+height;
541 TRACE("rc = (%d, %d, %d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
542 if (run->nFlags & MERF_SKIPPED)
543 DrawFocusRect(c->hDC, &rc);
545 FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
548 ME_DrawRun(c, run->pt.x, c->pt.y+run->pt.y+baseline, p, ¶graph->member.para);
551 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
552 const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
556 pt.y = c->pt.y + run->pt.y;
557 wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
558 ME_DebugWrite(c->hDC, &pt, buf);
560 /* c->pt.x += p->member.run.nWidth; */
567 SetTextAlign(c->hDC, align);
570 void ME_ScrollAbs(ME_TextEditor *editor, int absY)
572 ME_Scroll(editor, absY, 1);
575 void ME_ScrollUp(ME_TextEditor *editor, int cy)
577 ME_Scroll(editor, cy, 2);
580 void ME_ScrollDown(ME_TextEditor *editor, int cy)
582 ME_Scroll(editor, cy, 3);
585 void ME_Scroll(ME_TextEditor *editor, int value, int type)
588 int nOrigPos, nNewPos, nActualScroll;
590 nOrigPos = ME_GetYScrollPos(editor);
592 si.cbSize = sizeof(SCROLLINFO);
602 /* Scroll up - towards the beginning of the document */
603 si.nPos = nOrigPos - value;
606 /* Scroll down - towards the end of the document */
607 si.nPos = nOrigPos + value;
610 FIXME("ME_Scroll called incorrectly\n");
614 nNewPos = SetScrollInfo(editor->hWnd, SB_VERT, &si, editor->bRedraw);
615 nActualScroll = nOrigPos - nNewPos;
618 if (abs(nActualScroll) > editor->sizeWindow.cy)
619 InvalidateRect(editor->hWnd, NULL, TRUE);
621 ScrollWindowEx(editor->hWnd, 0, nActualScroll, NULL, NULL, NULL, NULL, SW_INVALIDATE);
625 ME_UpdateScrollBar(editor);
629 void ME_UpdateScrollBar(ME_TextEditor *editor)
631 /* Note that this is the only funciton that should ever call SetScrolLInfo
632 * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
637 BOOL bScrollBarWasVisible,bScrollBarWillBeVisible;
639 if (ME_WrapMarkedParagraphs(editor))
640 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
643 si.cbSize = sizeof(si);
644 bScrollBarWasVisible = ME_GetYScrollVisible(editor);
645 bScrollBarWillBeVisible = editor->nHeight > editor->sizeWindow.cy;
647 if (bScrollBarWasVisible != bScrollBarWillBeVisible)
649 ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible);
650 ME_MarkAllForWrapping(editor);
651 ME_WrapMarkedParagraphs(editor);
654 si.fMask = SIF_PAGE | SIF_RANGE;
655 if (GetWindowLongW(hWnd, GWL_STYLE) & ES_DISABLENOSCROLL)
656 si.fMask |= SIF_DISABLENOSCROLL;
659 si.nMax = editor->nTotalLength;
661 si.nPage = editor->sizeWindow.cy;
663 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
664 SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
667 int ME_GetYScrollPos(ME_TextEditor *editor)
670 si.cbSize = sizeof(si);
672 return GetScrollInfo(editor->hWnd, SB_VERT, &si) ? si.nPos : 0;
675 BOOL ME_GetYScrollVisible(ME_TextEditor *editor)
676 { /* Returns true if the scrollbar is visible */
678 sbi.cbSize = sizeof(sbi);
679 GetScrollBarInfo(editor->hWnd, OBJID_VSCROLL, &sbi);
680 return ((sbi.rgstate[0] & STATE_SYSTEM_INVISIBLE) == 0);
683 void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun)
685 ME_DisplayItem *pRow = ME_FindItemBack(pRun, diStartRow);
686 ME_DisplayItem *pPara = ME_FindItemBack(pRun, diParagraph);
687 int y, yrel, yheight, yold;
692 y = pPara->member.para.nYPos+pRow->member.row.nYPos;
693 yheight = pRow->member.row.nHeight;
694 yold = ME_GetYScrollPos(editor);
698 ME_ScrollAbs(editor,y);
699 else if (yrel + yheight > editor->sizeWindow.cy)
700 ME_ScrollAbs(editor,y+yheight-editor->sizeWindow.cy);
705 ME_InvalidateFromOfs(ME_TextEditor *editor, int nCharOfs)
711 ME_RunOfsFromCharOfs(editor, nCharOfs, &tmp.pRun, &tmp.nOffset);
712 ME_GetCursorCoordinates(editor, &tmp, &x, &y, &height);
716 rc.bottom = y + height;
717 rc.right = editor->rcFormat.right;
718 InvalidateRect(editor->hWnd, &rc, FALSE);
723 ME_InvalidateSelection(ME_TextEditor *editor)
725 ME_DisplayItem *para1, *para2;
727 int len = ME_GetTextLength(editor);
729 ME_GetSelection(editor, &nStart, &nEnd);
730 /* if both old and new selection are 0-char (= caret only), then
731 there's no (inverted) area to be repainted, neither old nor new */
732 if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
734 ME_WrapMarkedParagraphs(editor);
735 ME_GetSelectionParas(editor, ¶1, ¶2);
736 assert(para1->type == diParagraph);
737 assert(para2->type == diParagraph);
738 /* last selection markers aren't always updated, which means
739 they can point past the end of the document */
740 if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
741 ME_MarkForPainting(editor,
742 ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph),
743 ME_FindItemFwd(editor->pBuffer->pFirst, diTextEnd));
745 /* if the start part of selection is being expanded or contracted... */
746 if (nStart < editor->nLastSelStart) {
747 ME_MarkForPainting(editor, para1, ME_FindItemFwd(editor->pLastSelStartPara, diParagraphOrEnd));
749 if (nStart > editor->nLastSelStart) {
750 ME_MarkForPainting(editor, editor->pLastSelStartPara, ME_FindItemFwd(para1, diParagraphOrEnd));
753 /* if the end part of selection is being contracted or expanded... */
754 if (nEnd < editor->nLastSelEnd) {
755 ME_MarkForPainting(editor, para2, ME_FindItemFwd(editor->pLastSelEndPara, diParagraphOrEnd));
757 if (nEnd > editor->nLastSelEnd) {
758 ME_MarkForPainting(editor, editor->pLastSelEndPara, ME_FindItemFwd(para2, diParagraphOrEnd));
762 ME_InvalidateMarkedParagraphs(editor);
763 /* remember the last invalidated position */
764 ME_GetSelection(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
765 ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
766 assert(editor->pLastSelStartPara->type == diParagraph);
767 assert(editor->pLastSelEndPara->type == diParagraph);
771 ME_QueueInvalidateFromCursor(ME_TextEditor *editor, int nCursor)
773 editor->nInvalidOfs = ME_GetCursorOfs(editor, nCursor);
778 ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
780 /* TODO: Zoom images and objects */
784 if (denominator == 0)
786 if (1.0 / 64.0 > (float)numerator / (float)denominator
787 || (float)numerator / (float)denominator > 64.0)
791 editor->nZoomNumerator = numerator;
792 editor->nZoomDenominator = denominator;
794 ME_RewrapRepaint(editor);