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_DrawGraphics(ME_Context
*c
, int x
, int y
, ME_Run
*run
,
250 ME_Paragraph
*para
, BOOL selected
) {
252 int xs
, ys
, xe
, ye
, h
, ym
, width
, eyes
;
253 ME_GetGraphicsSize(c
->editor
, run
, &sz
);
262 /* draw a smiling face :) */
263 Ellipse(c
->hDC
, xs
, ys
, xe
, ye
);
264 Ellipse(c
->hDC
, xs
+width
/8, ym
, x
+width
/8+eyes
, ym
+eyes
);
265 Ellipse(c
->hDC
, xs
+7*width
/8-eyes
, ym
, xs
+7*width
/8, ym
+eyes
);
266 MoveToEx(c
->hDC
, xs
+width
/8, ys
+3*h
/4-eyes
, NULL
);
267 LineTo(c
->hDC
, xs
+width
/8, ys
+3*h
/4);
268 LineTo(c
->hDC
, xs
+7*width
/8, ys
+3*h
/4);
269 LineTo(c
->hDC
, xs
+7*width
/8, ys
+3*h
/4-eyes
);
272 /* descent is usually (always?) 0 for graphics */
273 PatBlt(c
->hDC
, x
, y
-run
->nAscent
, sz
.cx
, run
->nAscent
+run
->nDescent
, DSTINVERT
);
277 static void ME_DrawRun(ME_Context
*c
, int x
, int y
, ME_DisplayItem
*rundi
, ME_Paragraph
*para
)
279 ME_Run
*run
= &rundi
->member
.run
;
280 ME_DisplayItem
*start
;
281 int runofs
= run
->nCharOfs
+para
->nCharOfs
;
282 int nSelFrom
, nSelTo
;
283 const WCHAR wszSpace
[] = {' ', 0};
285 if (run
->nFlags
& MERF_HIDDEN
)
288 start
= ME_FindItemBack(rundi
, diStartRow
);
289 ME_GetSelection(c
->editor
, &nSelFrom
, &nSelTo
);
291 /* Draw selected end-of-paragraph mark */
292 if (run
->nFlags
& MERF_ENDPARA
&& runofs
>= nSelFrom
&& runofs
< nSelTo
)
293 ME_DrawTextWithStyle(c
, x
, y
, wszSpace
, 1, run
->style
, NULL
, 0, 1,
294 c
->pt
.y
+ start
->member
.row
.nYPos
,
295 start
->member
.row
.nHeight
);
297 /* you can always comment it out if you need visible paragraph marks */
298 if (run
->nFlags
& (MERF_ENDPARA
| MERF_TAB
| MERF_CELL
))
301 if (run
->nFlags
& MERF_GRAPHICS
)
302 ME_DrawGraphics(c
, x
, y
, run
, para
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
));
305 if (c
->editor
->cPasswordMask
)
307 ME_String
*szMasked
= ME_MakeStringR(c
->editor
->cPasswordMask
,ME_StrVLen(run
->strText
));
308 ME_DrawTextWithStyle(c
, x
, y
,
309 szMasked
->szData
, ME_StrVLen(szMasked
), run
->style
, NULL
,
310 nSelFrom
-runofs
,nSelTo
-runofs
, c
->pt
.y
+start
->member
.row
.nYPos
, start
->member
.row
.nHeight
);
311 ME_DestroyString(szMasked
);
314 ME_DrawTextWithStyle(c
, x
, y
,
315 run
->strText
->szData
, ME_StrVLen(run
->strText
), run
->style
, NULL
,
316 nSelFrom
-runofs
,nSelTo
-runofs
, c
->pt
.y
+start
->member
.row
.nYPos
, start
->member
.row
.nHeight
);
320 static struct {unsigned width_num
: 4, width_den
: 4, pen_style
: 4, dble
: 1;} border_details
[] = {
321 /* none */ {0, 0, PS_SOLID
, FALSE
},
322 /* 3/4 */ {3, 4, PS_SOLID
, FALSE
},
323 /* 1 1/2 */ {3, 2, PS_SOLID
, FALSE
},
324 /* 2 1/4 */ {9, 4, PS_SOLID
, FALSE
},
325 /* 3 */ {3, 1, PS_SOLID
, FALSE
},
326 /* 4 1/2 */ {9, 2, PS_SOLID
, FALSE
},
327 /* 6 */ {6, 1, PS_SOLID
, FALSE
},
328 /* 3/4 double */ {3, 4, PS_SOLID
, TRUE
},
329 /* 1 1/2 double */ {3, 2, PS_SOLID
, TRUE
},
330 /* 2 1/4 double */ {9, 4, PS_SOLID
, TRUE
},
331 /* 3/4 gray */ {3, 4, PS_DOT
/* FIXME */, FALSE
},
332 /* 1 1/2 dashed */ {3, 2, PS_DASH
, FALSE
},
335 static COLORREF pen_colors
[16] = {
336 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
337 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
338 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
339 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
340 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
341 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
342 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
343 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
346 static int ME_GetBorderPenWidth(ME_TextEditor
* editor
, int idx
)
350 if (editor
->nZoomNumerator
== 0)
352 width
= border_details
[idx
].width_num
+ border_details
[idx
].width_den
/ 2;
353 width
/= border_details
[idx
].width_den
;
357 width
= border_details
[idx
].width_num
* editor
->nZoomNumerator
;
358 width
+= border_details
[idx
].width_den
* editor
->nZoomNumerator
/ 2;
359 width
/= border_details
[idx
].width_den
* editor
->nZoomDenominator
;
364 int ME_GetParaBorderWidth(ME_TextEditor
* editor
, int flags
)
366 int idx
= (flags
>> 8) & 0xF;
369 if (idx
>= sizeof(border_details
) / sizeof(border_details
[0]))
371 FIXME("Unsupported border value %d\n", idx
);
374 width
= ME_GetBorderPenWidth(editor
, idx
);
375 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
379 int ME_GetParaLineSpace(ME_Context
* c
, ME_Paragraph
* para
)
382 if (!(para
->pFmt
->dwMask
& PFM_LINESPACING
)) return 0;
384 /* FIXME: how to compute simply the line space in ls ??? */
385 /* FIXME: does line spacing include the line itself ??? */
386 switch (para
->pFmt
->bLineSpacingRule
)
388 case 0: sp
= ls
; break;
389 case 1: sp
= (3 * ls
) / 2; break;
390 case 2: sp
= 2 * ls
; break;
391 case 3: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); if (sp
< ls
) sp
= ls
; break;
392 case 4: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); break;
393 case 5: sp
= para
->pFmt
->dyLineSpacing
/ 20; break;
394 default: FIXME("Unsupported spacing rule value %d\n", para
->pFmt
->bLineSpacingRule
);
396 if (c
->editor
->nZoomNumerator
== 0)
399 return sp
* c
->editor
->nZoomNumerator
/ c
->editor
->nZoomDenominator
;
402 static int ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
)
404 int idx
, border_width
;
408 if (!(para
->pFmt
->dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return 0;
410 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
412 rc
.left
= c
->rcView
.left
;
413 rc
.right
= c
->rcView
.right
;
415 ybefore
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
416 rc
.bottom
= y
+ ybefore
;
417 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
420 if (para
->pFmt
->dwMask
& PFM_SPACEAFTER
)
422 rc
.left
= c
->rcView
.left
;
423 rc
.right
= c
->rcView
.right
;
424 rc
.bottom
= y
+ para
->nHeight
;
425 yafter
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceAfter
);
426 rc
.top
= rc
.bottom
- yafter
;
427 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
432 idx
= (para
->pFmt
->wBorders
>> 8) & 0xF;
433 if ((para
->pFmt
->dwMask
& PFM_BORDER
) && idx
!= 0 && (para
->pFmt
->wBorders
& 0xF)) {
436 HPEN pen
= NULL
, oldpen
= NULL
;
439 if (para
->pFmt
->wBorders
& 0x00B0)
440 FIXME("Unsupported border flags %x\n", para
->pFmt
->wBorders
);
441 border_width
= ME_GetParaBorderWidth(c
->editor
, para
->pFmt
->wBorders
);
443 if (para
->pFmt
->wBorders
& 64) /* autocolor */
444 pencr
= GetSysColor(COLOR_WINDOWTEXT
);
446 pencr
= pen_colors
[(para
->pFmt
->wBorders
>> 12) & 0xF];
448 pen_width
= ME_GetBorderPenWidth(c
->editor
, idx
);
449 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
450 oldpen
= SelectObject(c
->hDC
, pen
);
451 MoveToEx(c
->hDC
, 0, 0, &pt
);
453 /* before & after spaces are not included in border */
454 if (para
->pFmt
->wBorders
& 1)
456 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ ybefore
, NULL
);
457 LineTo(c
->hDC
, c
->rcView
.left
, y
+ para
->nHeight
- yafter
);
458 if (border_details
[idx
].dble
) {
459 MoveToEx(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ ybefore
+ pen_width
+ 1, NULL
);
460 LineTo(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ para
->nHeight
- yafter
- pen_width
- 1);
463 if (para
->pFmt
->wBorders
& 2)
465 MoveToEx(c
->hDC
, c
->rcView
.right
, y
+ ybefore
, NULL
);
466 LineTo(c
->hDC
, c
->rcView
.right
, y
+ para
->nHeight
- yafter
);
467 if (border_details
[idx
].dble
) {
468 MoveToEx(c
->hDC
, c
->rcView
.right
- pen_width
- 1, y
+ ybefore
+ pen_width
+ 1, NULL
);
469 LineTo(c
->hDC
, c
->rcView
.right
- pen_width
- 1, y
+ para
->nHeight
- yafter
- pen_width
- 1);
472 if (para
->pFmt
->wBorders
& 4)
474 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ ybefore
, NULL
);
475 LineTo(c
->hDC
, c
->rcView
.right
, y
+ ybefore
);
476 if (border_details
[idx
].dble
) {
477 MoveToEx(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ ybefore
+ pen_width
+ 1, NULL
);
478 LineTo(c
->hDC
, c
->rcView
.right
- pen_width
- 1, y
+ ybefore
+ pen_width
+ 1);
481 if (para
->pFmt
->wBorders
& 8)
483 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ para
->nHeight
- yafter
- 1, NULL
);
484 LineTo(c
->hDC
, c
->rcView
.right
, y
+ para
->nHeight
- yafter
- 1);
485 if (border_details
[idx
].dble
) {
486 MoveToEx(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ para
->nHeight
- yafter
- 1 - pen_width
- 1, NULL
);
487 LineTo(c
->hDC
, c
->rcView
.right
- pen_width
- 1, y
+ para
->nHeight
- yafter
- 1 - pen_width
- 1);
491 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
492 SelectObject(c
->hDC
, oldpen
);
496 ((para
->pFmt
->dwMask
& PFM_BORDER
) && (para
->pFmt
->wBorders
& 4) ?
500 void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
) {
501 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
504 ME_Paragraph
*para
= NULL
;
507 int height
= 0, baseline
= 0, no
=0, pno
= 0;
509 BOOL visible
= FALSE
;
512 c
->pt
.x
= c
->rcView
.left
;
513 rcPara
.left
= c
->rcView
.left
;
514 rcPara
.right
= c
->rcView
.right
;
515 for (p
= paragraph
; p
!=paragraph
->member
.para
.next_para
; p
= p
->next
) {
518 para
= &p
->member
.para
;
520 nMargWidth
= ME_twips2pointsX(c
, para
->pFmt
->dxStartIndent
);
522 nMargWidth
+= ME_twips2pointsX(c
, para
->pFmt
->dxOffset
);
523 xs
= c
->rcView
.left
+nMargWidth
;
524 xe
= c
->rcView
.right
- ME_twips2pointsX(c
, para
->pFmt
->dxRightIndent
);
525 y
+= ME_DrawParaDecoration(c
, para
, y
);
530 rcPara
.bottom
= y
+p
->member
.row
.nHeight
;
531 visible
= RectVisible(c
->hDC
, &rcPara
);
534 rc
.left
= c
->rcView
.left
;
535 rc
.right
= c
->rcView
.left
+nMargWidth
;
537 rc
.bottom
= y
+p
->member
.row
.nHeight
;
538 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
541 rc
.right
= c
->rcView
.right
;
542 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
543 rc
.left
= c
->rcView
.left
+nMargWidth
;
545 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
549 const WCHAR wszRowDebug
[] = {'r','o','w','[','%','d',']',0};
552 wsprintfW(buf
, wszRowDebug
, no
);
554 ME_DebugWrite(c
->hDC
, &pt
, buf
);
557 height
= p
->member
.row
.nHeight
;
558 baseline
= p
->member
.row
.nBaseline
;
563 run
= &p
->member
.run
;
564 if (visible
&& me_debug
) {
565 rc
.left
= c
->rcView
.left
+run
->pt
.x
;
566 rc
.right
= c
->rcView
.left
+run
->pt
.x
+run
->nWidth
;
567 rc
.top
= c
->pt
.y
+run
->pt
.y
;
568 rc
.bottom
= c
->pt
.y
+run
->pt
.y
+height
;
569 TRACE("rc = (%d, %d, %d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
570 if (run
->nFlags
& MERF_SKIPPED
)
571 DrawFocusRect(c
->hDC
, &rc
);
573 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
576 ME_DrawRun(c
, run
->pt
.x
, c
->pt
.y
+run
->pt
.y
+baseline
, p
, ¶graph
->member
.para
);
579 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
580 const WCHAR wszRunDebug
[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
584 pt
.y
= c
->pt
.y
+ run
->pt
.y
;
585 wsprintfW(buf
, wszRunDebug
, no
, p
->member
.run
.nFlags
, p
->member
.run
.strText
->szData
);
586 ME_DebugWrite(c
->hDC
, &pt
, buf
);
588 /* c->pt.x += p->member.run.nWidth; */
595 SetTextAlign(c
->hDC
, align
);
598 void ME_ScrollAbs(ME_TextEditor
*editor
, int absY
)
600 ME_Scroll(editor
, absY
, 1);
603 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
605 ME_Scroll(editor
, cy
, 2);
608 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
610 ME_Scroll(editor
, cy
, 3);
613 void ME_Scroll(ME_TextEditor
*editor
, int value
, int type
)
616 int nOrigPos
, nNewPos
, nActualScroll
;
618 nOrigPos
= ME_GetYScrollPos(editor
);
620 si
.cbSize
= sizeof(SCROLLINFO
);
630 /* Scroll up - towards the beginning of the document */
631 si
.nPos
= nOrigPos
- value
;
634 /* Scroll down - towards the end of the document */
635 si
.nPos
= nOrigPos
+ value
;
638 FIXME("ME_Scroll called incorrectly\n");
642 nNewPos
= SetScrollInfo(editor
->hWnd
, SB_VERT
, &si
, editor
->bRedraw
);
643 nActualScroll
= nOrigPos
- nNewPos
;
646 if (abs(nActualScroll
) > editor
->sizeWindow
.cy
)
647 InvalidateRect(editor
->hWnd
, NULL
, TRUE
);
649 ScrollWindowEx(editor
->hWnd
, 0, nActualScroll
, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
653 ME_UpdateScrollBar(editor
);
657 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
659 /* Note that this is the only funciton that should ever call SetScrolLInfo
660 * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
665 BOOL bScrollBarWasVisible
,bScrollBarWillBeVisible
;
667 if (ME_WrapMarkedParagraphs(editor
))
668 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
671 si
.cbSize
= sizeof(si
);
672 bScrollBarWasVisible
= ME_GetYScrollVisible(editor
);
673 bScrollBarWillBeVisible
= editor
->nHeight
> editor
->sizeWindow
.cy
;
675 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
677 ShowScrollBar(hWnd
, SB_VERT
, bScrollBarWillBeVisible
);
678 ME_MarkAllForWrapping(editor
);
679 ME_WrapMarkedParagraphs(editor
);
682 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
683 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_DISABLENOSCROLL
)
684 si
.fMask
|= SIF_DISABLENOSCROLL
;
687 si
.nMax
= editor
->nTotalLength
;
689 si
.nPage
= editor
->sizeWindow
.cy
;
691 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
692 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
695 int ME_GetYScrollPos(ME_TextEditor
*editor
)
698 si
.cbSize
= sizeof(si
);
700 return GetScrollInfo(editor
->hWnd
, SB_VERT
, &si
) ? si
.nPos
: 0;
703 BOOL
ME_GetYScrollVisible(ME_TextEditor
*editor
)
704 { /* Returns true if the scrollbar is visible */
706 sbi
.cbSize
= sizeof(sbi
);
707 GetScrollBarInfo(editor
->hWnd
, OBJID_VSCROLL
, &sbi
);
708 return ((sbi
.rgstate
[0] & STATE_SYSTEM_INVISIBLE
) == 0);
711 void ME_EnsureVisible(ME_TextEditor
*editor
, ME_DisplayItem
*pRun
)
713 ME_DisplayItem
*pRow
= ME_FindItemBack(pRun
, diStartRow
);
714 ME_DisplayItem
*pPara
= ME_FindItemBack(pRun
, diParagraph
);
715 int y
, yrel
, yheight
, yold
;
720 y
= pPara
->member
.para
.nYPos
+pRow
->member
.row
.nYPos
;
721 yheight
= pRow
->member
.row
.nHeight
;
722 yold
= ME_GetYScrollPos(editor
);
726 ME_ScrollAbs(editor
,y
);
727 else if (yrel
+ yheight
> editor
->sizeWindow
.cy
)
728 ME_ScrollAbs(editor
,y
+yheight
-editor
->sizeWindow
.cy
);
733 ME_InvalidateFromOfs(ME_TextEditor
*editor
, int nCharOfs
)
739 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &tmp
.pRun
, &tmp
.nOffset
);
740 ME_GetCursorCoordinates(editor
, &tmp
, &x
, &y
, &height
);
744 rc
.bottom
= y
+ height
;
745 rc
.right
= editor
->rcFormat
.right
;
746 InvalidateRect(editor
->hWnd
, &rc
, FALSE
);
751 ME_InvalidateSelection(ME_TextEditor
*editor
)
753 ME_DisplayItem
*para1
, *para2
;
755 int len
= ME_GetTextLength(editor
);
757 ME_GetSelection(editor
, &nStart
, &nEnd
);
758 /* if both old and new selection are 0-char (= caret only), then
759 there's no (inverted) area to be repainted, neither old nor new */
760 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
762 ME_WrapMarkedParagraphs(editor
);
763 ME_GetSelectionParas(editor
, ¶1
, ¶2
);
764 assert(para1
->type
== diParagraph
);
765 assert(para2
->type
== diParagraph
);
766 /* last selection markers aren't always updated, which means
767 they can point past the end of the document */
768 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
) {
769 ME_MarkForPainting(editor
,
770 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
),
771 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diTextEnd
));
773 /* if the start part of selection is being expanded or contracted... */
774 if (nStart
< editor
->nLastSelStart
) {
775 ME_MarkForPainting(editor
, para1
, ME_FindItemFwd(editor
->pLastSelStartPara
, diParagraphOrEnd
));
777 if (nStart
> editor
->nLastSelStart
) {
778 ME_MarkForPainting(editor
, editor
->pLastSelStartPara
, ME_FindItemFwd(para1
, diParagraphOrEnd
));
781 /* if the end part of selection is being contracted or expanded... */
782 if (nEnd
< editor
->nLastSelEnd
) {
783 ME_MarkForPainting(editor
, para2
, ME_FindItemFwd(editor
->pLastSelEndPara
, diParagraphOrEnd
));
785 if (nEnd
> editor
->nLastSelEnd
) {
786 ME_MarkForPainting(editor
, editor
->pLastSelEndPara
, ME_FindItemFwd(para2
, diParagraphOrEnd
));
790 ME_InvalidateMarkedParagraphs(editor
);
791 /* remember the last invalidated position */
792 ME_GetSelection(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
793 ME_GetSelectionParas(editor
, &editor
->pLastSelStartPara
, &editor
->pLastSelEndPara
);
794 assert(editor
->pLastSelStartPara
->type
== diParagraph
);
795 assert(editor
->pLastSelEndPara
->type
== diParagraph
);
799 ME_QueueInvalidateFromCursor(ME_TextEditor
*editor
, int nCursor
)
801 editor
->nInvalidOfs
= ME_GetCursorOfs(editor
, nCursor
);
806 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
808 /* TODO: Zoom images and objects */
812 if (denominator
== 0)
814 if (1.0 / 64.0 > (float)numerator
/ (float)denominator
815 || (float)numerator
/ (float)denominator
> 64.0)
819 editor
->nZoomNumerator
= numerator
;
820 editor
->nZoomDenominator
= denominator
;
822 ME_RewrapRepaint(editor
);