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
&& ye
>rcUpdate
->top
;
49 ME_DrawParagraph(&c
, item
);
50 if (!rcUpdate
|| (rcUpdate
->top
<=c
.pt
.y
&& rcUpdate
->bottom
>=ye
))
51 item
->member
.para
.nFlags
&= ~MEPF_REPAINT
;
55 item
= item
->member
.para
.next_para
;
57 if (c
.pt
.y
<c
.rcView
.bottom
) {
59 int xs
= c
.rcView
.left
, xe
= c
.rcView
.right
;
60 int ys
= c
.pt
.y
, ye
= c
.rcView
.bottom
;
64 int y1
= editor
->nTotalLength
-yoffset
, y2
= editor
->nLastTotalLength
-yoffset
;
71 if (rcUpdate
&& ys
!=ye
)
73 xs
= rcUpdate
->left
, xe
= rcUpdate
->right
;
74 if (rcUpdate
->top
> ys
)
76 if (rcUpdate
->bottom
< ye
)
77 ye
= rcUpdate
->bottom
;
85 FillRect(hDC
, &rc
, c
.editor
->hbrBackground
);
88 if (editor
->nTotalLength
!= editor
->nLastTotalLength
)
89 ME_SendRequestResize(editor
, FALSE
);
90 editor
->nLastTotalLength
= editor
->nTotalLength
;
91 ME_DestroyContext(&c
, NULL
);
94 void ME_Repaint(ME_TextEditor
*editor
)
96 if (ME_WrapMarkedParagraphs(editor
))
98 ME_UpdateScrollBar(editor
);
99 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
101 ME_SendOldNotify(editor
, EN_UPDATE
);
102 UpdateWindow(editor
->hWnd
);
105 void ME_UpdateRepaint(ME_TextEditor
*editor
)
107 /* Should be called whenever the contents of the control have changed */
109 BOOL wrappedParagraphs
;
111 wrappedParagraphs
= ME_WrapMarkedParagraphs(editor
);
112 if (!editor
->bRedraw
) return;
113 if (wrappedParagraphs
)
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
;
128 ME_SendSelChange(editor
);
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
);
140 ME_WrapMarkedParagraphs(editor
);
141 ME_UpdateScrollBar(editor
);
146 int ME_twips2pointsX(ME_Context
*c
, int x
)
148 if (c
->editor
->nZoomNumerator
== 0)
149 return x
* c
->dpi
.cx
/ 1440;
151 return x
* c
->dpi
.cx
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
154 int ME_twips2pointsY(ME_Context
*c
, int y
)
156 if (c
->editor
->nZoomNumerator
== 0)
157 return y
* c
->dpi
.cy
/ 1440;
159 return y
* c
->dpi
.cy
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
162 static void ME_DrawTextWithStyle(ME_Context
*c
, int x
, int y
, LPCWSTR szText
, int nChars
,
163 ME_Style
*s
, int *width
, int nSelFrom
, int nSelTo
, int ymin
, int cy
) {
167 int yOffset
= 0, yTwipsOffset
= 0;
171 hOldFont
= ME_SelectStyleFont(c
, s
);
172 if ((s
->fmt
.dwMask
& CFM_LINK
) && (s
->fmt
.dwEffects
& CFE_LINK
))
174 else if ((s
->fmt
.dwMask
& CFM_COLOR
) && (s
->fmt
.dwEffects
& CFE_AUTOCOLOR
))
175 rgb
= GetSysColor(COLOR_WINDOWTEXT
);
177 rgb
= s
->fmt
.crTextColor
;
178 rgbOld
= SetTextColor(hDC
, rgb
);
179 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & CFM_OFFSET
) {
180 yTwipsOffset
= s
->fmt
.yOffset
;
182 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & (CFM_SUPERSCRIPT
| CFM_SUBSCRIPT
)) {
183 if (s
->fmt
.dwEffects
& CFE_SUPERSCRIPT
) yTwipsOffset
= s
->fmt
.yHeight
/3;
184 if (s
->fmt
.dwEffects
& CFE_SUBSCRIPT
) yTwipsOffset
= -s
->fmt
.yHeight
/12;
187 yOffset
= ME_twips2pointsY(c
, yTwipsOffset
);
188 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nChars
, NULL
);
189 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
190 if (width
) *width
= sz
.cx
;
191 if (s
->fmt
.dwMask
& CFM_UNDERLINETYPE
)
194 switch (s
->fmt
.bUnderlineType
)
197 case CFU_UNDERLINEWORD
: /* native seems to map it to simple underline (MSDN) */
198 case CFU_UNDERLINEDOUBLE
: /* native seems to map it to simple underline (MSDN) */
199 hPen
= CreatePen(PS_SOLID
, 1, rgb
);
201 case CFU_UNDERLINEDOTTED
:
202 hPen
= CreatePen(PS_DOT
, 1, rgb
);
205 WINE_FIXME("Unknown underline type (%u)\n", s
->fmt
.bUnderlineType
);
207 case CFU_CF1UNDERLINE
: /* this type is supported in the font, do nothing */
208 case CFU_UNDERLINENONE
:
214 HPEN hOldPen
= SelectObject(hDC
, hPen
);
215 /* FIXME: should use textmetrics info for Descent info */
216 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
217 LineTo(hDC
, x
+ sz
.cx
, y
- yOffset
+ 1);
218 SelectObject(hDC
, hOldPen
);
222 if (nSelFrom
< nChars
&& nSelTo
>= 0 && nSelFrom
<nSelTo
)
224 if (nSelFrom
< 0) nSelFrom
= 0;
225 if (nSelTo
> nChars
) nSelTo
= nChars
;
226 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
228 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
230 /* Invert selection if not hidden by EM_HIDESELECTION */
231 if (c
->editor
->bHideSelection
== FALSE
)
232 PatBlt(hDC
, x
, ymin
, sz
.cx
, cy
, DSTINVERT
);
234 SetTextColor(hDC
, rgbOld
);
235 ME_UnselectStyleFont(c
, s
, hOldFont
);
238 static void ME_DebugWrite(HDC hDC
, const POINT
*pt
, LPCWSTR szText
) {
239 int align
= SetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
240 HGDIOBJ hFont
= SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
241 COLORREF color
= SetTextColor(hDC
, RGB(128,128,128));
242 TextOutW(hDC
, pt
->x
, pt
->y
, szText
, lstrlenW(szText
));
243 SelectObject(hDC
, hFont
);
244 SetTextAlign(hDC
, align
);
245 SetTextColor(hDC
, color
);
248 static void ME_DrawRun(ME_Context
*c
, int x
, int y
, ME_DisplayItem
*rundi
, ME_Paragraph
*para
)
250 ME_Run
*run
= &rundi
->member
.run
;
251 ME_DisplayItem
*start
;
252 int runofs
= run
->nCharOfs
+para
->nCharOfs
;
253 int nSelFrom
, nSelTo
;
254 const WCHAR wszSpace
[] = {' ', 0};
256 if (run
->nFlags
& MERF_HIDDEN
)
259 start
= ME_FindItemBack(rundi
, diStartRow
);
260 ME_GetSelection(c
->editor
, &nSelFrom
, &nSelTo
);
262 /* Draw selected end-of-paragraph mark */
263 if (run
->nFlags
& MERF_ENDPARA
&& runofs
>= nSelFrom
&& runofs
< nSelTo
)
264 ME_DrawTextWithStyle(c
, x
, y
, wszSpace
, 1, run
->style
, NULL
, 0, 1,
265 c
->pt
.y
+ start
->member
.row
.nYPos
,
266 start
->member
.row
.nHeight
);
268 /* you can always comment it out if you need visible paragraph marks */
269 if (run
->nFlags
& (MERF_ENDPARA
| MERF_TAB
| MERF_CELL
))
272 if (run
->nFlags
& MERF_GRAPHICS
)
273 ME_DrawOLE(c
, x
, y
, run
, para
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
));
276 if (c
->editor
->cPasswordMask
)
278 ME_String
*szMasked
= ME_MakeStringR(c
->editor
->cPasswordMask
,ME_StrVLen(run
->strText
));
279 ME_DrawTextWithStyle(c
, x
, y
,
280 szMasked
->szData
, ME_StrVLen(szMasked
), run
->style
, NULL
,
281 nSelFrom
-runofs
,nSelTo
-runofs
, c
->pt
.y
+start
->member
.row
.nYPos
, start
->member
.row
.nHeight
);
282 ME_DestroyString(szMasked
);
285 ME_DrawTextWithStyle(c
, x
, y
,
286 run
->strText
->szData
, ME_StrVLen(run
->strText
), run
->style
, NULL
,
287 nSelFrom
-runofs
,nSelTo
-runofs
, c
->pt
.y
+start
->member
.row
.nYPos
, start
->member
.row
.nHeight
);
291 static struct {unsigned width_num
: 4, width_den
: 4, pen_style
: 4, dble
: 1;} border_details
[] = {
292 /* none */ {0, 1, PS_SOLID
, FALSE
},
293 /* 3/4 */ {3, 4, PS_SOLID
, FALSE
},
294 /* 1 1/2 */ {3, 2, PS_SOLID
, FALSE
},
295 /* 2 1/4 */ {9, 4, PS_SOLID
, FALSE
},
296 /* 3 */ {3, 1, PS_SOLID
, FALSE
},
297 /* 4 1/2 */ {9, 2, PS_SOLID
, FALSE
},
298 /* 6 */ {6, 1, PS_SOLID
, FALSE
},
299 /* 3/4 double */ {3, 4, PS_SOLID
, TRUE
},
300 /* 1 1/2 double */ {3, 2, PS_SOLID
, TRUE
},
301 /* 2 1/4 double */ {9, 4, PS_SOLID
, TRUE
},
302 /* 3/4 gray */ {3, 4, PS_DOT
/* FIXME */, FALSE
},
303 /* 1 1/2 dashed */ {3, 2, PS_DASH
, FALSE
},
306 static COLORREF pen_colors
[16] = {
307 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
308 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
309 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
310 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
311 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
312 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
313 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
314 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
317 static int ME_GetBorderPenWidth(ME_TextEditor
* editor
, int idx
)
321 if (editor
->nZoomNumerator
== 0)
323 width
= border_details
[idx
].width_num
+ border_details
[idx
].width_den
/ 2;
324 width
/= border_details
[idx
].width_den
;
328 width
= border_details
[idx
].width_num
* editor
->nZoomNumerator
;
329 width
+= border_details
[idx
].width_den
* editor
->nZoomNumerator
/ 2;
330 width
/= border_details
[idx
].width_den
* editor
->nZoomDenominator
;
335 int ME_GetParaBorderWidth(ME_TextEditor
* editor
, int flags
)
337 int idx
= (flags
>> 8) & 0xF;
340 if (idx
>= sizeof(border_details
) / sizeof(border_details
[0]))
342 FIXME("Unsupported border value %d\n", idx
);
345 width
= ME_GetBorderPenWidth(editor
, idx
);
346 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
350 int ME_GetParaLineSpace(ME_Context
* c
, ME_Paragraph
* para
)
353 if (!(para
->pFmt
->dwMask
& PFM_LINESPACING
)) return 0;
355 /* FIXME: how to compute simply the line space in ls ??? */
356 /* FIXME: does line spacing include the line itself ??? */
357 switch (para
->pFmt
->bLineSpacingRule
)
359 case 0: sp
= ls
; break;
360 case 1: sp
= (3 * ls
) / 2; break;
361 case 2: sp
= 2 * ls
; break;
362 case 3: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); if (sp
< ls
) sp
= ls
; break;
363 case 4: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); break;
364 case 5: sp
= para
->pFmt
->dyLineSpacing
/ 20; break;
365 default: FIXME("Unsupported spacing rule value %d\n", para
->pFmt
->bLineSpacingRule
);
367 if (c
->editor
->nZoomNumerator
== 0)
370 return sp
* c
->editor
->nZoomNumerator
/ c
->editor
->nZoomDenominator
;
373 static void ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
, RECT
* bounds
)
375 int idx
, border_width
, top_border
, bottom_border
;
378 SetRectEmpty(bounds
);
379 if (!(para
->pFmt
->dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return;
381 border_width
= top_border
= bottom_border
= 0;
382 idx
= (para
->pFmt
->wBorders
>> 8) & 0xF;
383 if ((para
->pFmt
->dwMask
& PFM_BORDER
) && idx
!= 0 && (para
->pFmt
->wBorders
& 0xF))
385 if (para
->pFmt
->wBorders
& 0x00B0)
386 FIXME("Unsupported border flags %x\n", para
->pFmt
->wBorders
);
387 border_width
= ME_GetParaBorderWidth(c
->editor
, para
->pFmt
->wBorders
);
388 if (para
->pFmt
->wBorders
& 4) top_border
= border_width
;
389 if (para
->pFmt
->wBorders
& 8) bottom_border
= border_width
;
392 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
394 rc
.left
= c
->rcView
.left
;
395 rc
.right
= c
->rcView
.right
;
397 bounds
->top
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
398 rc
.bottom
= y
+ bounds
->top
+ top_border
;
399 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
402 if (para
->pFmt
->dwMask
& PFM_SPACEAFTER
)
404 rc
.left
= c
->rcView
.left
;
405 rc
.right
= c
->rcView
.right
;
406 rc
.bottom
= y
+ para
->nHeight
;
407 bounds
->bottom
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceAfter
);
408 rc
.top
= rc
.bottom
- bounds
->bottom
- bottom_border
;
409 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
412 if ((para
->pFmt
->dwMask
& PFM_BORDER
) && idx
!= 0 && (para
->pFmt
->wBorders
& 0xF)) {
415 HPEN pen
= NULL
, oldpen
= NULL
;
418 if (para
->pFmt
->wBorders
& 64) /* autocolor */
419 pencr
= GetSysColor(COLOR_WINDOWTEXT
);
421 pencr
= pen_colors
[(para
->pFmt
->wBorders
>> 12) & 0xF];
423 pen_width
= ME_GetBorderPenWidth(c
->editor
, idx
);
424 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
425 oldpen
= SelectObject(c
->hDC
, pen
);
426 MoveToEx(c
->hDC
, 0, 0, &pt
);
428 /* before & after spaces are not included in border */
430 /* helper to draw the double lines in case of corner */
431 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
433 if (para
->pFmt
->wBorders
& 1)
435 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ bounds
->top
, NULL
);
436 LineTo(c
->hDC
, c
->rcView
.left
, y
+ para
->nHeight
- bounds
->bottom
);
437 if (border_details
[idx
].dble
) {
438 rc
.left
= c
->rcView
.left
+ 1;
439 rc
.right
= rc
.left
+ border_width
;
440 rc
.top
= y
+ bounds
->top
;
441 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
442 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
443 MoveToEx(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ bounds
->top
+ DD(4), NULL
);
444 LineTo(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
446 bounds
->left
+= border_width
;
448 if (para
->pFmt
->wBorders
& 2)
450 MoveToEx(c
->hDC
, c
->rcView
.right
- 1, y
+ bounds
->top
, NULL
);
451 LineTo(c
->hDC
, c
->rcView
.right
- 1, y
+ para
->nHeight
- bounds
->bottom
);
452 if (border_details
[idx
].dble
) {
453 rc
.left
= c
->rcView
.right
- pen_width
- 1;
454 rc
.right
= c
->rcView
.right
- 1;
455 rc
.top
= y
+ bounds
->top
;
456 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
457 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
458 MoveToEx(c
->hDC
, c
->rcView
.right
- 1 - pen_width
- 1, y
+ bounds
->top
+ DD(4), NULL
);
459 LineTo(c
->hDC
, c
->rcView
.right
- 1 - pen_width
- 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
461 bounds
->right
+= border_width
;
463 if (para
->pFmt
->wBorders
& 4)
465 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ bounds
->top
, NULL
);
466 LineTo(c
->hDC
, c
->rcView
.right
, y
+ bounds
->top
);
467 if (border_details
[idx
].dble
) {
468 MoveToEx(c
->hDC
, c
->rcView
.left
+ DD(1), y
+ bounds
->top
+ pen_width
+ 1, NULL
);
469 LineTo(c
->hDC
, c
->rcView
.right
- DD(2), y
+ bounds
->top
+ pen_width
+ 1);
471 bounds
->top
+= border_width
;
473 if (para
->pFmt
->wBorders
& 8)
475 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ para
->nHeight
- bounds
->bottom
- 1, NULL
);
476 LineTo(c
->hDC
, c
->rcView
.right
, y
+ para
->nHeight
- bounds
->bottom
- 1);
477 if (border_details
[idx
].dble
) {
478 MoveToEx(c
->hDC
, c
->rcView
.left
+ DD(1), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1, NULL
);
479 LineTo(c
->hDC
, c
->rcView
.right
- DD(2), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1);
481 bounds
->bottom
+= border_width
;
485 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
486 SelectObject(c
->hDC
, oldpen
);
491 void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
) {
492 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
495 ME_Paragraph
*para
= NULL
;
496 RECT rc
, rcPara
, bounds
;
498 int height
= 0, baseline
= 0, no
=0, pno
= 0;
500 BOOL visible
= FALSE
;
502 c
->pt
.x
= c
->rcView
.left
;
503 rcPara
.left
= c
->rcView
.left
;
504 rcPara
.right
= c
->rcView
.right
;
505 for (p
= paragraph
; p
!=paragraph
->member
.para
.next_para
; p
= p
->next
) {
508 para
= &p
->member
.para
;
511 xs
= c
->rcView
.left
+ ME_twips2pointsX(c
, para
->pFmt
->dxStartIndent
);
512 xe
= c
->rcView
.right
- ME_twips2pointsX(c
, para
->pFmt
->dxRightIndent
);
513 ME_DrawParaDecoration(c
, para
, y
, &bounds
);
519 rcPara
.bottom
= y
+p
->member
.row
.nHeight
;
520 visible
= RectVisible(c
->hDC
, &rcPara
);
523 rc
.left
= c
->rcView
.left
+ bounds
.left
;
526 rc
.bottom
= y
+p
->member
.row
.nHeight
;
527 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
530 rc
.right
= c
->rcView
.right
- bounds
.right
;
531 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
534 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
538 const WCHAR wszRowDebug
[] = {'r','o','w','[','%','d',']',0};
541 wsprintfW(buf
, wszRowDebug
, no
);
543 ME_DebugWrite(c
->hDC
, &pt
, buf
);
546 height
= p
->member
.row
.nHeight
;
547 baseline
= p
->member
.row
.nBaseline
;
549 xe
+= ME_twips2pointsX(c
, para
->pFmt
->dxOffset
);
553 run
= &p
->member
.run
;
554 if (visible
&& me_debug
) {
555 rc
.left
= c
->rcView
.left
+run
->pt
.x
;
556 rc
.right
= c
->rcView
.left
+run
->pt
.x
+run
->nWidth
;
557 rc
.top
= c
->pt
.y
+run
->pt
.y
;
558 rc
.bottom
= c
->pt
.y
+run
->pt
.y
+height
;
559 TRACE("rc = (%d, %d, %d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
560 if (run
->nFlags
& MERF_SKIPPED
)
561 DrawFocusRect(c
->hDC
, &rc
);
563 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
566 ME_DrawRun(c
, run
->pt
.x
, c
->pt
.y
+run
->pt
.y
+baseline
, p
, ¶graph
->member
.para
);
569 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
570 const WCHAR wszRunDebug
[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
574 pt
.y
= c
->pt
.y
+ run
->pt
.y
;
575 wsprintfW(buf
, wszRunDebug
, no
, p
->member
.run
.nFlags
, p
->member
.run
.strText
->szData
);
576 ME_DebugWrite(c
->hDC
, &pt
, buf
);
578 /* c->pt.x += p->member.run.nWidth; */
585 SetTextAlign(c
->hDC
, align
);
588 void ME_ScrollAbs(ME_TextEditor
*editor
, int absY
)
590 ME_Scroll(editor
, absY
, 1);
593 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
595 ME_Scroll(editor
, cy
, 2);
598 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
600 ME_Scroll(editor
, cy
, 3);
603 void ME_Scroll(ME_TextEditor
*editor
, int value
, int type
)
606 int nOrigPos
, nNewPos
, nActualScroll
;
608 nOrigPos
= ME_GetYScrollPos(editor
);
610 si
.cbSize
= sizeof(SCROLLINFO
);
616 /*Scroll absolutely*/
620 /* Scroll up - towards the beginning of the document */
621 si
.nPos
= nOrigPos
- value
;
624 /* Scroll down - towards the end of the document */
625 si
.nPos
= nOrigPos
+ value
;
628 FIXME("ME_Scroll called incorrectly\n");
632 nNewPos
= SetScrollInfo(editor
->hWnd
, SB_VERT
, &si
, editor
->bRedraw
);
633 nActualScroll
= nOrigPos
- nNewPos
;
636 if (abs(nActualScroll
) > editor
->sizeWindow
.cy
)
637 InvalidateRect(editor
->hWnd
, NULL
, TRUE
);
639 ScrollWindowEx(editor
->hWnd
, 0, nActualScroll
, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
643 ME_UpdateScrollBar(editor
);
647 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
649 /* Note that this is the only function that should ever call SetScrolLInfo
650 * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
655 BOOL bScrollBarWasVisible
,bScrollBarWillBeVisible
;
657 if (ME_WrapMarkedParagraphs(editor
))
658 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
661 si
.cbSize
= sizeof(si
);
662 bScrollBarWasVisible
= ME_GetYScrollVisible(editor
);
663 bScrollBarWillBeVisible
= editor
->nHeight
> editor
->sizeWindow
.cy
;
665 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
667 ShowScrollBar(hWnd
, SB_VERT
, bScrollBarWillBeVisible
);
668 ME_MarkAllForWrapping(editor
);
669 ME_WrapMarkedParagraphs(editor
);
672 si
.fMask
= SIF_PAGE
| SIF_RANGE
;
673 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_DISABLENOSCROLL
)
674 si
.fMask
|= SIF_DISABLENOSCROLL
;
678 if (ME_GetTextLength(editor
) > 0)
680 si
.nMax
= editor
->nTotalLength
;
681 si
.nPage
= editor
->sizeWindow
.cy
;
683 si
.nMax
= si
.nPage
= 0;
686 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
687 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
690 int ME_GetYScrollPos(ME_TextEditor
*editor
)
693 si
.cbSize
= sizeof(si
);
695 return GetScrollInfo(editor
->hWnd
, SB_VERT
, &si
) ? si
.nPos
: 0;
698 BOOL
ME_GetYScrollVisible(ME_TextEditor
*editor
)
699 { /* Returns true if the scrollbar is visible */
701 sbi
.cbSize
= sizeof(sbi
);
702 GetScrollBarInfo(editor
->hWnd
, OBJID_VSCROLL
, &sbi
);
703 return ((sbi
.rgstate
[0] & STATE_SYSTEM_INVISIBLE
) == 0);
706 void ME_EnsureVisible(ME_TextEditor
*editor
, ME_DisplayItem
*pRun
)
708 ME_DisplayItem
*pRow
= ME_FindItemBack(pRun
, diStartRow
);
709 ME_DisplayItem
*pPara
= ME_FindItemBack(pRun
, diParagraph
);
710 int y
, yrel
, yheight
, yold
;
715 y
= pPara
->member
.para
.nYPos
+pRow
->member
.row
.nYPos
;
716 yheight
= pRow
->member
.row
.nHeight
;
717 yold
= ME_GetYScrollPos(editor
);
721 ME_ScrollAbs(editor
,y
);
722 else if (yrel
+ yheight
> editor
->sizeWindow
.cy
)
723 ME_ScrollAbs(editor
,y
+yheight
-editor
->sizeWindow
.cy
);
728 ME_InvalidateFromOfs(ME_TextEditor
*editor
, int nCharOfs
)
734 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &tmp
.pRun
, &tmp
.nOffset
);
735 ME_GetCursorCoordinates(editor
, &tmp
, &x
, &y
, &height
);
739 rc
.bottom
= y
+ height
;
740 rc
.right
= editor
->rcFormat
.right
;
741 InvalidateRect(editor
->hWnd
, &rc
, FALSE
);
746 ME_InvalidateSelection(ME_TextEditor
*editor
)
748 ME_DisplayItem
*para1
, *para2
;
750 int len
= ME_GetTextLength(editor
);
752 ME_GetSelection(editor
, &nStart
, &nEnd
);
753 /* if both old and new selection are 0-char (= caret only), then
754 there's no (inverted) area to be repainted, neither old nor new */
755 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
757 ME_WrapMarkedParagraphs(editor
);
758 ME_GetSelectionParas(editor
, ¶1
, ¶2
);
759 assert(para1
->type
== diParagraph
);
760 assert(para2
->type
== diParagraph
);
761 /* last selection markers aren't always updated, which means
762 they can point past the end of the document */
763 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
) {
764 ME_MarkForPainting(editor
,
765 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
),
766 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diTextEnd
));
768 /* if the start part of selection is being expanded or contracted... */
769 if (nStart
< editor
->nLastSelStart
) {
770 ME_MarkForPainting(editor
, para1
, ME_FindItemFwd(editor
->pLastSelStartPara
, diParagraphOrEnd
));
772 if (nStart
> editor
->nLastSelStart
) {
773 ME_MarkForPainting(editor
, editor
->pLastSelStartPara
, ME_FindItemFwd(para1
, diParagraphOrEnd
));
776 /* if the end part of selection is being contracted or expanded... */
777 if (nEnd
< editor
->nLastSelEnd
) {
778 ME_MarkForPainting(editor
, para2
, ME_FindItemFwd(editor
->pLastSelEndPara
, diParagraphOrEnd
));
780 if (nEnd
> editor
->nLastSelEnd
) {
781 ME_MarkForPainting(editor
, editor
->pLastSelEndPara
, ME_FindItemFwd(para2
, diParagraphOrEnd
));
785 ME_InvalidateMarkedParagraphs(editor
);
786 /* remember the last invalidated position */
787 ME_GetSelection(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
788 ME_GetSelectionParas(editor
, &editor
->pLastSelStartPara
, &editor
->pLastSelEndPara
);
789 assert(editor
->pLastSelStartPara
->type
== diParagraph
);
790 assert(editor
->pLastSelEndPara
->type
== diParagraph
);
794 ME_QueueInvalidateFromCursor(ME_TextEditor
*editor
, int nCursor
)
796 editor
->nInvalidOfs
= ME_GetCursorOfs(editor
, nCursor
);
801 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
803 /* TODO: Zoom images and objects */
807 if (denominator
== 0)
809 if (1.0 / 64.0 > (float)numerator
/ (float)denominator
810 || (float)numerator
/ (float)denominator
> 64.0)
814 editor
->nZoomNumerator
= numerator
;
815 editor
->nZoomDenominator
= denominator
;
817 ME_RewrapRepaint(editor
);