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
);
35 ME_MoveCaret(editor
); /* Calls ME_WrapMarkedParagraphs */
36 item
= editor
->pBuffer
->pFirst
->next
;
38 while(item
!= editor
->pBuffer
->pLast
) {
41 assert(item
->type
== diParagraph
);
42 if (item
->member
.para
.pCell
43 != item
->member
.para
.next_para
->member
.para
.pCell
)
46 cell
= &ME_FindItemBack(item
->member
.para
.next_para
, diCell
)->member
.cell
;
47 ye
= cell
->pt
.y
+ cell
->nHeight
- yoffset
;
49 ye
= c
.pt
.y
+ item
->member
.para
.nHeight
;
51 if (!(item
->member
.para
.nFlags
& MEPF_ROWEND
) &&
52 item
->member
.para
.pCell
!= item
->member
.para
.prev_para
->member
.para
.pCell
)
55 if (item
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_ROWSTART
)
56 cell
= item
->member
.para
.pCell
;
58 cell
= item
->member
.para
.prev_para
->member
.para
.pCell
;
60 /* the border shifts the text down */
61 yTextOffset
= cell
->member
.cell
.yTextOffset
;
64 if (!bOnlyNew
|| (item
->member
.para
.nFlags
& MEPF_REPAINT
))
66 BOOL bPaint
= (rcUpdate
== NULL
);
68 bPaint
= c
.pt
.y
<rcUpdate
->bottom
&& ye
>rcUpdate
->top
;
71 c
.pt
.y
+= yTextOffset
;
72 ME_DrawParagraph(&c
, item
);
73 if (!rcUpdate
|| (rcUpdate
->top
<=c
.pt
.y
-yTextOffset
&& rcUpdate
->bottom
>=ye
))
74 item
->member
.para
.nFlags
&= ~MEPF_REPAINT
;
77 if (item
->member
.para
.pCell
)
79 ME_Cell
*cell
= &item
->member
.para
.pCell
->member
.cell
;
80 ME_DisplayItem
*next_para
= item
->member
.para
.next_para
;
81 c
.pt
.x
= cell
->pt
.x
+ cell
->nWidth
;
82 if (item
->member
.para
.pCell
== next_para
->member
.para
.pCell
&&
83 !(next_para
->member
.para
.nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
)))
87 if (next_para
->member
.para
.nFlags
& MEPF_ROWSTART
)
89 cell
= &ME_FindItemFwd(next_para
, diCell
)->member
.cell
;
91 else if (next_para
->member
.para
.nFlags
& MEPF_ROWEND
)
93 cell
= &cell
->next_cell
->member
.cell
;
97 cell
= &next_para
->member
.para
.pCell
->member
.cell
;
99 c
.pt
.y
= cell
->pt
.y
- yoffset
;
101 } else if (!(item
->member
.para
.nFlags
& MEPF_ROWSTART
)) {
104 item
= item
->member
.para
.next_para
;
106 if (c
.pt
.y
<c
.rcView
.bottom
) {
108 int xs
= c
.rcView
.left
, xe
= c
.rcView
.right
;
109 int ys
= c
.pt
.y
, ye
= c
.rcView
.bottom
;
113 int y1
= editor
->nTotalLength
-yoffset
, y2
= editor
->nLastTotalLength
-yoffset
;
120 if (rcUpdate
&& ys
!=ye
)
122 xs
= rcUpdate
->left
, xe
= rcUpdate
->right
;
123 if (rcUpdate
->top
> ys
)
125 if (rcUpdate
->bottom
< ye
)
126 ye
= rcUpdate
->bottom
;
134 FillRect(hDC
, &rc
, c
.editor
->hbrBackground
);
137 if (editor
->nTotalLength
!= editor
->nLastTotalLength
)
138 ME_SendRequestResize(editor
, FALSE
);
139 editor
->nLastTotalLength
= editor
->nTotalLength
;
140 ME_DestroyContext(&c
, NULL
);
143 void ME_Repaint(ME_TextEditor
*editor
)
145 if (ME_WrapMarkedParagraphs(editor
))
147 ME_UpdateScrollBar(editor
);
148 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
150 if (!IsWindowVisible(editor
->hWnd
))
152 if (!editor
->bEmulateVersion10
|| (editor
->nEventMask
& ENM_UPDATE
))
153 ME_SendOldNotify(editor
, EN_UPDATE
);
154 UpdateWindow(editor
->hWnd
);
157 void ME_UpdateRepaint(ME_TextEditor
*editor
)
159 /* Should be called whenever the contents of the control have changed */
161 BOOL wrappedParagraphs
;
163 wrappedParagraphs
= ME_WrapMarkedParagraphs(editor
);
164 if (wrappedParagraphs
)
165 ME_UpdateScrollBar(editor
);
167 /* Ensure that the cursor is visible */
168 pCursor
= &editor
->pCursors
[0];
169 ME_EnsureVisible(editor
, pCursor
->pRun
);
171 /* send EN_CHANGE if the event mask asks for it */
172 if(editor
->nEventMask
& ENM_CHANGE
)
174 editor
->nEventMask
&= ~ENM_CHANGE
;
175 ME_SendOldNotify(editor
, EN_CHANGE
);
176 editor
->nEventMask
|= ENM_CHANGE
;
179 ME_SendSelChange(editor
);
183 ME_RewrapRepaint(ME_TextEditor
*editor
)
185 /* RewrapRepaint should be called whenever the control has changed in
186 * looks, but not content. Like resizing. */
188 ME_MarkAllForWrapping(editor
);
189 ME_WrapMarkedParagraphs(editor
);
190 ME_UpdateScrollBar(editor
);
194 int ME_twips2pointsX(ME_Context
*c
, int x
)
196 if (c
->editor
->nZoomNumerator
== 0)
197 return x
* c
->dpi
.cx
/ 1440;
199 return x
* c
->dpi
.cx
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
202 int ME_twips2pointsY(ME_Context
*c
, int y
)
204 if (c
->editor
->nZoomNumerator
== 0)
205 return y
* c
->dpi
.cy
/ 1440;
207 return y
* c
->dpi
.cy
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
210 static void ME_HighlightSpace(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
211 int nChars
, ME_Style
*s
, int width
,
212 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
215 HGDIOBJ hOldFont
= NULL
;
218 /* Only highlight if there is a selection in the run and when
219 * EM_HIDESELECTION is not being used to hide the selection. */
220 if (nSelFrom
>= nChars
|| nSelTo
< 0 || nSelFrom
>= nSelTo
221 || c
->editor
->bHideSelection
)
223 hOldFont
= ME_SelectStyleFont(c
, s
);
226 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
229 if (nSelFrom
< 0) nSelFrom
= 0;
230 if (nSelTo
> nChars
) nSelTo
= nChars
;
231 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
233 if (nSelTo
!= nChars
)
235 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
238 selWidth
= width
- sz
.cx
;
240 ME_UnselectStyleFont(c
, s
, hOldFont
);
242 if (c
->editor
->bEmulateVersion10
)
243 PatBlt(hDC
, x
, ymin
, selWidth
, cy
, DSTINVERT
);
250 rect
.right
= x
+ selWidth
;
251 rect
.bottom
= ymin
+ cy
;
252 hBrush
= CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT
));
253 FillRect(hDC
, &rect
, hBrush
);
254 DeleteObject(hBrush
);
258 static void ME_DrawTextWithStyle(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
259 int nChars
, ME_Style
*s
, int width
,
260 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
265 int yOffset
= 0, yTwipsOffset
= 0;
268 HPEN hPen
= NULL
, hOldPen
= NULL
;
269 BOOL bHighlightedText
= (nSelFrom
< nChars
&& nSelTo
>= 0
270 && nSelFrom
< nSelTo
&& !c
->editor
->bHideSelection
);
271 int xSelStart
= x
, xSelEnd
= x
;
273 /* lpDx is only needed for tabs to make sure the underline done automatically
274 * by the font extends to the end of the tab. Tabs are always stored as
275 * a single character run, so we can handle this case separately, since
276 * otherwise lpDx would need to specify the lengths of each character. */
277 if (width
&& nChars
== 1)
278 lpDx
= &width
; /* Make sure underline for tab extends across tab space */
280 hOldFont
= ME_SelectStyleFont(c
, s
);
281 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & CFM_OFFSET
) {
282 yTwipsOffset
= s
->fmt
.yOffset
;
284 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & (CFM_SUPERSCRIPT
| CFM_SUBSCRIPT
)) {
285 if (s
->fmt
.dwEffects
& CFE_SUPERSCRIPT
) yTwipsOffset
= s
->fmt
.yHeight
/3;
286 if (s
->fmt
.dwEffects
& CFE_SUBSCRIPT
) yTwipsOffset
= -s
->fmt
.yHeight
/12;
289 yOffset
= ME_twips2pointsY(c
, yTwipsOffset
);
291 if ((s
->fmt
.dwMask
& CFM_LINK
) && (s
->fmt
.dwEffects
& CFE_LINK
))
293 else if ((s
->fmt
.dwMask
& CFM_COLOR
) && (s
->fmt
.dwEffects
& CFE_AUTOCOLOR
))
294 rgb
= GetSysColor(COLOR_WINDOWTEXT
);
296 rgb
= s
->fmt
.crTextColor
;
298 /* Determine the area that is selected in the run. */
299 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
300 /* Treat width as an optional parameter. We can get the width from the
301 * text extent of the string if it isn't specified. */
302 if (!width
) width
= sz
.cx
;
303 if (bHighlightedText
)
311 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
312 xSelStart
= x
+ sz
.cx
;
314 if (nSelTo
>= nChars
)
321 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
322 xSelEnd
= xSelStart
+ sz
.cx
;
326 /* Choose the pen type for underlining the text. */
327 if (s
->fmt
.dwMask
& CFM_UNDERLINETYPE
)
329 switch (s
->fmt
.bUnderlineType
)
332 case CFU_UNDERLINEWORD
: /* native seems to map it to simple underline (MSDN) */
333 case CFU_UNDERLINEDOUBLE
: /* native seems to map it to simple underline (MSDN) */
334 hPen
= CreatePen(PS_SOLID
, 1, rgb
);
336 case CFU_UNDERLINEDOTTED
:
337 hPen
= CreatePen(PS_DOT
, 1, rgb
);
340 WINE_FIXME("Unknown underline type (%u)\n", s
->fmt
.bUnderlineType
);
342 case CFU_CF1UNDERLINE
: /* this type is supported in the font, do nothing */
343 case CFU_UNDERLINENONE
:
349 hOldPen
= SelectObject(hDC
, hPen
);
353 rgbOld
= SetTextColor(hDC
, rgb
);
354 if (bHighlightedText
&& !c
->editor
->bEmulateVersion10
)
358 /* FIXME: should use textmetrics info for Descent info */
360 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
363 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nSelFrom
, NULL
);
365 LineTo(hDC
, xSelStart
, y
- yOffset
+ 1);
368 dim
.bottom
= ymin
+ cy
;
369 dim
.left
= xSelStart
;
371 SetTextColor(hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
372 rgbBackOld
= SetBkColor(hDC
, GetSysColor(COLOR_HIGHLIGHT
));
373 ExtTextOutW(hDC
, xSelStart
, y
-yOffset
, ETO_OPAQUE
, &dim
,
374 szText
+nSelFrom
, nSelTo
-nSelFrom
, lpDx
);
376 LineTo(hDC
, xSelEnd
, y
- yOffset
+ 1);
377 SetBkColor(hDC
, rgbBackOld
);
378 if (xSelEnd
< x
+ width
)
380 SetTextColor(hDC
, rgb
);
381 ExtTextOutW(hDC
, xSelEnd
, y
-yOffset
, 0, NULL
, szText
+nSelTo
,
382 nChars
-nSelTo
, NULL
);
384 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
389 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nChars
, lpDx
);
391 /* FIXME: should use textmetrics info for Descent info */
394 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
395 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
398 if (bHighlightedText
) /* v1.0 inverts the selection */
400 PatBlt(hDC
, xSelStart
, ymin
, xSelEnd
-xSelStart
, cy
, DSTINVERT
);
406 SelectObject(hDC
, hOldPen
);
409 SetTextColor(hDC
, rgbOld
);
410 ME_UnselectStyleFont(c
, s
, hOldFont
);
413 static void ME_DebugWrite(HDC hDC
, const POINT
*pt
, LPCWSTR szText
) {
414 int align
= SetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
415 HGDIOBJ hFont
= SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
416 COLORREF color
= SetTextColor(hDC
, RGB(128,128,128));
417 TextOutW(hDC
, pt
->x
, pt
->y
, szText
, lstrlenW(szText
));
418 SelectObject(hDC
, hFont
);
419 SetTextAlign(hDC
, align
);
420 SetTextColor(hDC
, color
);
423 static void ME_DrawRun(ME_Context
*c
, int x
, int y
, ME_DisplayItem
*rundi
, ME_Paragraph
*para
)
425 ME_Run
*run
= &rundi
->member
.run
;
426 ME_DisplayItem
*start
;
427 int runofs
= run
->nCharOfs
+para
->nCharOfs
;
428 int nSelFrom
, nSelTo
;
429 const WCHAR wszSpace
[] = {' ', 0};
431 if (run
->nFlags
& MERF_HIDDEN
)
434 start
= ME_FindItemBack(rundi
, diStartRow
);
435 ME_GetSelection(c
->editor
, &nSelFrom
, &nSelTo
);
437 /* Draw selected end-of-paragraph mark */
438 /* you can always comment it out if you need visible paragraph marks */
439 if (run
->nFlags
& MERF_ENDPARA
)
441 if (runofs
>= nSelFrom
&& runofs
< nSelTo
)
443 ME_HighlightSpace(c
, x
, y
, wszSpace
, 1, run
->style
, 0, 0, 1,
444 c
->pt
.y
+ start
->member
.row
.pt
.y
,
445 start
->member
.row
.nHeight
);
450 if (run
->nFlags
& (MERF_TAB
| MERF_ENDCELL
))
452 /* wszSpace is used instead of the tab character because otherwise
453 * an unwanted symbol can be inserted instead. */
454 ME_DrawTextWithStyle(c
, x
, y
, wszSpace
, 1, run
->style
, run
->nWidth
,
455 nSelFrom
-runofs
,nSelTo
-runofs
,
456 c
->pt
.y
+ start
->member
.row
.pt
.y
,
457 start
->member
.row
.nHeight
);
461 if (run
->nFlags
& MERF_GRAPHICS
)
462 ME_DrawOLE(c
, x
, y
, run
, para
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
));
465 if (c
->editor
->cPasswordMask
)
467 ME_String
*szMasked
= ME_MakeStringR(c
->editor
->cPasswordMask
,ME_StrVLen(run
->strText
));
468 ME_DrawTextWithStyle(c
, x
, y
,
469 szMasked
->szData
, ME_StrVLen(szMasked
), run
->style
, run
->nWidth
,
470 nSelFrom
-runofs
,nSelTo
-runofs
, c
->pt
.y
+start
->member
.row
.pt
.y
, start
->member
.row
.nHeight
);
471 ME_DestroyString(szMasked
);
474 ME_DrawTextWithStyle(c
, x
, y
,
475 run
->strText
->szData
, ME_StrVLen(run
->strText
), run
->style
, run
->nWidth
,
476 nSelFrom
-runofs
,nSelTo
-runofs
, c
->pt
.y
+start
->member
.row
.pt
.y
, start
->member
.row
.nHeight
);
480 static const struct {unsigned width_num
: 4, width_den
: 4, pen_style
: 4, dble
: 1;} border_details
[] = {
481 /* none */ {0, 1, PS_SOLID
, FALSE
},
482 /* 3/4 */ {3, 4, PS_SOLID
, FALSE
},
483 /* 1 1/2 */ {3, 2, PS_SOLID
, FALSE
},
484 /* 2 1/4 */ {9, 4, PS_SOLID
, FALSE
},
485 /* 3 */ {3, 1, PS_SOLID
, FALSE
},
486 /* 4 1/2 */ {9, 2, PS_SOLID
, FALSE
},
487 /* 6 */ {6, 1, PS_SOLID
, FALSE
},
488 /* 3/4 double */ {3, 4, PS_SOLID
, TRUE
},
489 /* 1 1/2 double */ {3, 2, PS_SOLID
, TRUE
},
490 /* 2 1/4 double */ {9, 4, PS_SOLID
, TRUE
},
491 /* 3/4 gray */ {3, 4, PS_DOT
/* FIXME */, FALSE
},
492 /* 1 1/2 dashed */ {3, 2, PS_DASH
, FALSE
},
495 static const COLORREF pen_colors
[16] = {
496 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
497 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
498 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
499 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
500 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
501 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
502 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
503 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
506 static int ME_GetBorderPenWidth(ME_TextEditor
* editor
, int idx
)
510 if (editor
->nZoomNumerator
== 0)
512 width
= border_details
[idx
].width_num
+ border_details
[idx
].width_den
/ 2;
513 width
/= border_details
[idx
].width_den
;
517 width
= border_details
[idx
].width_num
* editor
->nZoomNumerator
;
518 width
+= border_details
[idx
].width_den
* editor
->nZoomNumerator
/ 2;
519 width
/= border_details
[idx
].width_den
* editor
->nZoomDenominator
;
524 int ME_GetParaBorderWidth(ME_TextEditor
* editor
, int flags
)
526 int idx
= (flags
>> 8) & 0xF;
529 if (idx
>= sizeof(border_details
) / sizeof(border_details
[0]))
531 FIXME("Unsupported border value %d\n", idx
);
534 width
= ME_GetBorderPenWidth(editor
, idx
);
535 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
539 int ME_GetParaLineSpace(ME_Context
* c
, ME_Paragraph
* para
)
542 if (!(para
->pFmt
->dwMask
& PFM_LINESPACING
)) return 0;
544 /* FIXME: how to compute simply the line space in ls ??? */
545 /* FIXME: does line spacing include the line itself ??? */
546 switch (para
->pFmt
->bLineSpacingRule
)
548 case 0: sp
= ls
; break;
549 case 1: sp
= (3 * ls
) / 2; break;
550 case 2: sp
= 2 * ls
; break;
551 case 3: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); if (sp
< ls
) sp
= ls
; break;
552 case 4: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); break;
553 case 5: sp
= para
->pFmt
->dyLineSpacing
/ 20; break;
554 default: FIXME("Unsupported spacing rule value %d\n", para
->pFmt
->bLineSpacingRule
);
556 if (c
->editor
->nZoomNumerator
== 0)
559 return sp
* c
->editor
->nZoomNumerator
/ c
->editor
->nZoomDenominator
;
562 static void ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
, RECT
* bounds
)
564 int idx
, border_width
, top_border
, bottom_border
;
568 SetRectEmpty(bounds
);
569 if (!(para
->pFmt
->dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return;
571 border_width
= top_border
= bottom_border
= 0;
572 idx
= (para
->pFmt
->wBorders
>> 8) & 0xF;
573 hasParaBorder
= (!(c
->editor
->bEmulateVersion10
&&
574 para
->pFmt
->dwMask
& PFM_TABLE
&&
575 para
->pFmt
->wEffects
& PFE_TABLE
) &&
576 (para
->pFmt
->dwMask
& PFM_BORDER
) &&
578 (para
->pFmt
->wBorders
& 0xF));
581 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
582 * controls. It actually stores the paragraph or row border style. Although
583 * the value isn't used for drawing, it is used for streaming out rich text.
585 * wBorders stores the border style for each side (top, left, bottom, right)
586 * using nibble (4 bits) to store each border style. The rich text format
587 * control words, and their associated value are the following:
597 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
598 * The mask corresponding to each side for the version are the following:
602 * 0x0F00 bottom right
603 * 0xF000 right bottom
605 if (para
->pFmt
->wBorders
& 0x00B0)
606 FIXME("Unsupported border flags %x\n", para
->pFmt
->wBorders
);
607 border_width
= ME_GetParaBorderWidth(c
->editor
, para
->pFmt
->wBorders
);
608 if (para
->pFmt
->wBorders
& 4) top_border
= border_width
;
609 if (para
->pFmt
->wBorders
& 8) bottom_border
= border_width
;
612 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
614 rc
.left
= c
->rcView
.left
;
615 rc
.right
= c
->rcView
.right
;
617 bounds
->top
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
618 rc
.bottom
= y
+ bounds
->top
+ top_border
;
619 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
622 if (para
->pFmt
->dwMask
& PFM_SPACEAFTER
)
624 rc
.left
= c
->rcView
.left
;
625 rc
.right
= c
->rcView
.right
;
626 rc
.bottom
= y
+ para
->nHeight
;
627 bounds
->bottom
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceAfter
);
628 rc
.top
= rc
.bottom
- bounds
->bottom
- bottom_border
;
629 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
632 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
633 * but might support it in later versions. */
637 HPEN pen
= NULL
, oldpen
= NULL
;
640 if (para
->pFmt
->wBorders
& 64) /* autocolor */
641 pencr
= GetSysColor(COLOR_WINDOWTEXT
);
643 pencr
= pen_colors
[(para
->pFmt
->wBorders
>> 12) & 0xF];
645 pen_width
= ME_GetBorderPenWidth(c
->editor
, idx
);
646 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
647 oldpen
= SelectObject(c
->hDC
, pen
);
648 MoveToEx(c
->hDC
, 0, 0, &pt
);
650 /* before & after spaces are not included in border */
652 /* helper to draw the double lines in case of corner */
653 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
655 if (para
->pFmt
->wBorders
& 1)
657 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ bounds
->top
, NULL
);
658 LineTo(c
->hDC
, c
->rcView
.left
, y
+ para
->nHeight
- bounds
->bottom
);
659 if (border_details
[idx
].dble
) {
660 rc
.left
= c
->rcView
.left
+ 1;
661 rc
.right
= rc
.left
+ border_width
;
662 rc
.top
= y
+ bounds
->top
;
663 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
664 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
665 MoveToEx(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ bounds
->top
+ DD(4), NULL
);
666 LineTo(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
668 bounds
->left
+= border_width
;
670 if (para
->pFmt
->wBorders
& 2)
672 MoveToEx(c
->hDC
, c
->rcView
.right
- 1, y
+ bounds
->top
, NULL
);
673 LineTo(c
->hDC
, c
->rcView
.right
- 1, y
+ para
->nHeight
- bounds
->bottom
);
674 if (border_details
[idx
].dble
) {
675 rc
.left
= c
->rcView
.right
- pen_width
- 1;
676 rc
.right
= c
->rcView
.right
- 1;
677 rc
.top
= y
+ bounds
->top
;
678 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
679 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
680 MoveToEx(c
->hDC
, c
->rcView
.right
- 1 - pen_width
- 1, y
+ bounds
->top
+ DD(4), NULL
);
681 LineTo(c
->hDC
, c
->rcView
.right
- 1 - pen_width
- 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
683 bounds
->right
+= border_width
;
685 if (para
->pFmt
->wBorders
& 4)
687 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ bounds
->top
, NULL
);
688 LineTo(c
->hDC
, c
->rcView
.right
, y
+ bounds
->top
);
689 if (border_details
[idx
].dble
) {
690 MoveToEx(c
->hDC
, c
->rcView
.left
+ DD(1), y
+ bounds
->top
+ pen_width
+ 1, NULL
);
691 LineTo(c
->hDC
, c
->rcView
.right
- DD(2), y
+ bounds
->top
+ pen_width
+ 1);
693 bounds
->top
+= border_width
;
695 if (para
->pFmt
->wBorders
& 8)
697 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ para
->nHeight
- bounds
->bottom
- 1, NULL
);
698 LineTo(c
->hDC
, c
->rcView
.right
, y
+ para
->nHeight
- bounds
->bottom
- 1);
699 if (border_details
[idx
].dble
) {
700 MoveToEx(c
->hDC
, c
->rcView
.left
+ DD(1), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1, NULL
);
701 LineTo(c
->hDC
, c
->rcView
.right
- DD(2), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1);
703 bounds
->bottom
+= border_width
;
707 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
708 SelectObject(c
->hDC
, oldpen
);
713 static void ME_DrawTableBorders(ME_Context
*c
, ME_DisplayItem
*paragraph
)
715 ME_Paragraph
*para
= ¶graph
->member
.para
;
716 if (!c
->editor
->bEmulateVersion10
) /* v4.1 */
721 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
722 ME_DisplayItem
*paraAfterRow
;
729 BOOL atTop
= (para
->pCell
!= para
->prev_para
->member
.para
.pCell
);
730 BOOL atBottom
= (para
->pCell
!= para
->next_para
->member
.para
.pCell
);
731 int top
= (atTop
? cell
->pt
.y
: para
->pt
.y
) - ME_GetYScrollPos(c
->editor
);
732 int bottom
= (atBottom
?
733 cell
->pt
.y
+ cell
->nHeight
- ME_GetYScrollPos(c
->editor
):
734 top
+ para
->nHeight
+ (atTop
? cell
->yTextOffset
: 0));
735 rc
.left
= cell
->pt
.x
;
736 rc
.right
= rc
.left
+ cell
->nWidth
;
738 /* Erase gap before text if not all borders are the same height. */
739 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
740 rc
.top
= top
+ width
;
741 width
= cell
->yTextOffset
- width
;
742 rc
.bottom
= rc
.top
+ width
;
744 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
747 /* Draw cell borders.
748 * The borders borders are draw in is left, top, bottom, right in order
749 * to be consistent with native richedit. This is noticeable from the
750 * overlap of borders of different colours. */
751 if (!(para
->nFlags
& MEPF_ROWEND
)) {
754 if (cell
->border
.left
.width
> 0)
756 color
= cell
->border
.left
.colorRef
;
757 width
= max(ME_twips2pointsX(c
, cell
->border
.left
.width
), 1);
759 color
= RGB(192,192,192);
762 logBrush
.lbStyle
= BS_SOLID
;
763 logBrush
.lbColor
= color
;
764 logBrush
.lbHatch
= 0;
765 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
766 width
, &logBrush
, 0, NULL
);
767 oldPen
= SelectObject(c
->hDC
, pen
);
768 MoveToEx(c
->hDC
, rc
.left
, rc
.top
, &oldPt
);
769 LineTo(c
->hDC
, rc
.left
, rc
.bottom
);
770 SelectObject(c
->hDC
, oldPen
);
772 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
776 if (cell
->border
.top
.width
> 0)
778 brush
= CreateSolidBrush(cell
->border
.top
.colorRef
);
779 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
781 brush
= GetStockObject(LTGRAY_BRUSH
);
785 rc
.bottom
= rc
.top
+ width
;
786 FillRect(c
->hDC
, &rc
, brush
);
787 if (cell
->border
.top
.width
> 0)
791 /* Draw the bottom border if at the last paragraph in the cell, and when
792 * in the last row of the table. */
794 int oldLeft
= rc
.left
;
795 width
= max(ME_twips2pointsY(c
, cell
->border
.bottom
.width
), 1);
796 paraAfterRow
= ME_GetTableRowEnd(paragraph
)->member
.para
.next_para
;
797 if (paraAfterRow
->member
.para
.nFlags
& MEPF_ROWSTART
) {
798 ME_DisplayItem
*nextEndCell
;
799 nextEndCell
= ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow
), diCell
);
800 assert(nextEndCell
&& !nextEndCell
->member
.cell
.next_cell
);
801 rc
.left
= nextEndCell
->member
.cell
.pt
.x
;
802 /* FIXME: Native draws FROM the bottom of the table rather than
803 * TO the bottom of the table in this case, but just doing so here
804 * will case the next row to erase the border. */
807 rc.bottom = rc.top + width;
810 if (rc
.left
< rc
.right
) {
811 if (cell
->border
.bottom
.width
> 0) {
812 brush
= CreateSolidBrush(cell
->border
.bottom
.colorRef
);
814 brush
= GetStockObject(LTGRAY_BRUSH
);
817 rc
.top
= rc
.bottom
- width
;
818 FillRect(c
->hDC
, &rc
, brush
);
819 if (cell
->border
.bottom
.width
> 0)
825 /* Right border only drawn if at the end of the table row. */
826 if (!cell
->next_cell
->member
.cell
.next_cell
&&
827 !(para
->nFlags
& MEPF_ROWSTART
))
831 if (cell
->border
.right
.width
> 0) {
832 color
= cell
->border
.right
.colorRef
;
833 width
= max(ME_twips2pointsX(c
, cell
->border
.right
.width
), 1);
835 color
= RGB(192,192,192);
838 logBrush
.lbStyle
= BS_SOLID
;
839 logBrush
.lbColor
= color
;
840 logBrush
.lbHatch
= 0;
841 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
842 width
, &logBrush
, 0, NULL
);
843 oldPen
= SelectObject(c
->hDC
, pen
);
844 MoveToEx(c
->hDC
, rc
.right
- 1, rc
.top
, &oldPt
);
845 LineTo(c
->hDC
, rc
.right
- 1, rc
.bottom
);
846 SelectObject(c
->hDC
, oldPen
);
848 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
851 } else { /* v1.0 - 3.0 */
852 /* Draw simple table border */
853 if (para
->pFmt
->dwMask
& PFM_TABLE
&& para
->pFmt
->wEffects
& PFE_TABLE
) {
854 HPEN pen
= NULL
, oldpen
= NULL
;
855 int i
, firstX
, startX
, endX
, rowY
, rowBottom
, nHeight
;
857 PARAFORMAT2
*pNextFmt
;
859 pen
= CreatePen(PS_SOLID
, 0, para
->border
.top
.colorRef
);
860 oldpen
= SelectObject(c
->hDC
, pen
);
862 /* Find the start relative to the text */
863 firstX
= ME_FindItemFwd(paragraph
, diRun
)->member
.run
.pt
.x
;
864 /* Go back by the horizontal gap, which is stored in dxOffset */
865 firstX
-= ME_twips2pointsX(c
, para
->pFmt
->dxOffset
);
866 /* The left edge, stored in dxStartIndent affected just the first edge */
867 startX
= firstX
- ME_twips2pointsX(c
, para
->pFmt
->dxStartIndent
);
869 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
870 rowY
+= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
871 nHeight
= ME_FindItemFwd(paragraph
, diStartRow
)->member
.row
.nHeight
;
872 rowBottom
= rowY
+ nHeight
;
874 /* Draw horizontal lines */
875 MoveToEx(c
->hDC
, firstX
, rowY
, &oldPt
);
876 i
= para
->pFmt
->cTabCount
- 1;
877 endX
= startX
+ ME_twips2pointsX(c
, para
->pFmt
->rgxTabs
[i
] & 0x00ffffff) + 1;
878 LineTo(c
->hDC
, endX
, rowY
);
879 pNextFmt
= para
->next_para
->member
.para
.pFmt
;
880 /* The bottom of the row only needs to be drawn if the next row is
882 if (!(pNextFmt
&& pNextFmt
->dwMask
& PFM_TABLE
&& pNextFmt
->wEffects
&&
885 /* Decrement rowBottom to draw the bottom line within the row, and
886 * to not draw over this line when drawing the vertical lines. */
888 MoveToEx(c
->hDC
, firstX
, rowBottom
, NULL
);
889 LineTo(c
->hDC
, endX
, rowBottom
);
892 /* Draw vertical lines */
893 MoveToEx(c
->hDC
, firstX
, rowY
, NULL
);
894 LineTo(c
->hDC
, firstX
, rowBottom
);
895 for (i
= 0; i
< para
->pFmt
->cTabCount
; i
++)
897 int rightBoundary
= para
->pFmt
->rgxTabs
[i
] & 0x00ffffff;
898 endX
= startX
+ ME_twips2pointsX(c
, rightBoundary
);
899 MoveToEx(c
->hDC
, endX
, rowY
, NULL
);
900 LineTo(c
->hDC
, endX
, rowBottom
);
903 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
904 SelectObject(c
->hDC
, oldpen
);
910 void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
) {
911 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
914 ME_Paragraph
*para
= NULL
;
917 int height
= 0, baseline
= 0, no
=0;
918 BOOL visible
= FALSE
;
920 c
->pt
.x
= c
->rcView
.left
;
921 rc
.left
= c
->rcView
.left
;
922 rc
.right
= c
->rcView
.right
;
923 for (p
= paragraph
; p
!=paragraph
->member
.para
.next_para
; p
= p
->next
) {
926 para
= &p
->member
.para
;
930 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
931 rc
.left
= cell
->pt
.x
;
932 rc
.right
= rc
.left
+ cell
->nWidth
;
934 if (para
->nFlags
& MEPF_ROWSTART
) {
935 ME_Cell
*cell
= ¶
->next_para
->member
.para
.pCell
->member
.cell
;
936 rc
.right
= cell
->pt
.x
;
937 } else if (para
->nFlags
& MEPF_ROWEND
) {
938 ME_Cell
*cell
= ¶
->prev_para
->member
.para
.pCell
->member
.cell
;
939 rc
.left
= cell
->pt
.x
+ cell
->nWidth
;
941 ME_DrawParaDecoration(c
, para
, y
, &bounds
);
945 /* we should have seen a diParagraph before */
949 if (para
->nFlags
& MEPF_ROWSTART
) {
950 ME_Cell
*cell
= ¶
->next_para
->member
.para
.pCell
->member
.cell
;
951 rc
.bottom
= y
+ cell
->nHeight
;
952 } else if (para
->nFlags
& MEPF_ROWEND
) {
953 ME_Cell
*cell
= ¶
->prev_para
->member
.para
.pCell
->member
.cell
;
954 rc
.bottom
= y
+ cell
->nHeight
;
956 rc
.bottom
= y
+p
->member
.row
.nHeight
;
958 visible
= RectVisible(c
->hDC
, &rc
);
960 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
964 const WCHAR wszRowDebug
[] = {'r','o','w','[','%','d',']',0};
967 wsprintfW(buf
, wszRowDebug
, no
);
969 ME_DebugWrite(c
->hDC
, &pt
, buf
);
972 height
= p
->member
.row
.nHeight
;
973 baseline
= p
->member
.row
.nBaseline
;
977 run
= &p
->member
.run
;
978 if (visible
&& me_debug
) {
979 rc
.left
= c
->rcView
.left
+run
->pt
.x
;
980 rc
.right
= c
->rcView
.left
+run
->pt
.x
+run
->nWidth
;
981 rc
.top
= c
->pt
.y
+run
->pt
.y
;
982 rc
.bottom
= c
->pt
.y
+run
->pt
.y
+height
;
983 TRACE("rc = (%d, %d, %d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
984 if (run
->nFlags
& MERF_SKIPPED
)
985 DrawFocusRect(c
->hDC
, &rc
);
987 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
990 ME_DrawRun(c
, run
->pt
.x
, c
->pt
.y
+run
->pt
.y
+baseline
, p
, ¶graph
->member
.para
);
993 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
994 const WCHAR wszRunDebug
[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
998 pt
.y
= c
->pt
.y
+ run
->pt
.y
;
999 wsprintfW(buf
, wszRunDebug
, no
, p
->member
.run
.nFlags
, p
->member
.run
.strText
->szData
);
1000 ME_DebugWrite(c
->hDC
, &pt
, buf
);
1002 /* c->pt.x += p->member.run.nWidth; */
1005 /* Clear any space at the bottom of the cell after the text. */
1006 if (para
->nFlags
& MEPF_ROWSTART
)
1010 rc
.bottom
= p
->member
.cell
.pt
.y
+ p
->member
.cell
.nHeight
1011 - ME_GetYScrollPos(c
->editor
);
1012 if (RectVisible(c
->hDC
, &rc
))
1014 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
1023 ME_DrawTableBorders(c
, paragraph
);
1025 SetTextAlign(c
->hDC
, align
);
1028 void ME_ScrollAbs(ME_TextEditor
*editor
, int absY
)
1030 ME_Scroll(editor
, absY
, 1);
1033 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
1035 ME_Scroll(editor
, cy
, 2);
1038 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
1040 ME_Scroll(editor
, cy
, 3);
1043 void ME_Scroll(ME_TextEditor
*editor
, int value
, int type
)
1046 int nOrigPos
, nNewPos
, nActualScroll
;
1049 BOOL bScrollBarIsVisible
, bScrollBarWillBeVisible
;
1051 nOrigPos
= ME_GetYScrollPos(editor
);
1053 si
.cbSize
= sizeof(SCROLLINFO
);
1059 /*Scroll absolutely*/
1063 /* Scroll up - towards the beginning of the document */
1064 si
.nPos
= nOrigPos
- value
;
1067 /* Scroll down - towards the end of the document */
1068 si
.nPos
= nOrigPos
+ value
;
1071 FIXME("ME_Scroll called incorrectly\n");
1075 nNewPos
= SetScrollInfo(editor
->hWnd
, SB_VERT
, &si
, TRUE
);
1076 editor
->vert_si
.nPos
= nNewPos
;
1077 nActualScroll
= nOrigPos
- nNewPos
;
1078 if (abs(nActualScroll
) > editor
->sizeWindow
.cy
)
1079 InvalidateRect(editor
->hWnd
, NULL
, TRUE
);
1081 ScrollWindowEx(editor
->hWnd
, 0, nActualScroll
, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
1084 hWnd
= editor
->hWnd
;
1085 winStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
1086 bScrollBarIsVisible
= (winStyle
& WS_VSCROLL
) != 0;
1087 bScrollBarWillBeVisible
= (editor
->nHeight
> editor
->sizeWindow
.cy
)
1088 || (winStyle
& ES_DISABLENOSCROLL
);
1089 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1091 ShowScrollBar(hWnd
, SB_VERT
, bScrollBarWillBeVisible
);
1093 ME_UpdateScrollBar(editor
);
1097 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
1099 /* Note that this is the only function that should ever call SetScrolLInfo
1100 * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
1101 * be used at all. */
1105 BOOL bScrollBarWasVisible
,bScrollBarWillBeVisible
;
1107 if (ME_WrapMarkedParagraphs(editor
))
1108 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1110 hWnd
= editor
->hWnd
;
1111 si
.cbSize
= sizeof(si
);
1112 bScrollBarWasVisible
= ME_GetYScrollVisible(editor
);
1113 bScrollBarWillBeVisible
= editor
->nHeight
> editor
->sizeWindow
.cy
;
1115 si
.fMask
= SIF_PAGE
| SIF_RANGE
| SIF_POS
;
1116 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_DISABLENOSCROLL
)
1118 si
.fMask
|= SIF_DISABLENOSCROLL
;
1119 bScrollBarWillBeVisible
= TRUE
;
1122 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1124 ShowScrollBar(hWnd
, SB_VERT
, bScrollBarWillBeVisible
);
1125 ME_MarkAllForWrapping(editor
);
1126 ME_WrapMarkedParagraphs(editor
);
1130 si
.nMax
= editor
->nTotalLength
;
1131 si
.nPos
= editor
->vert_si
.nPos
;
1132 si
.nPage
= editor
->sizeWindow
.cy
;
1134 if (!(si
.nMin
== editor
->vert_si
.nMin
&& si
.nMax
== editor
->vert_si
.nMax
&& si
.nPage
== editor
->vert_si
.nPage
))
1136 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1137 editor
->vert_si
.nMin
= si
.nMin
;
1138 editor
->vert_si
.nMax
= si
.nMax
;
1139 editor
->vert_si
.nPage
= si
.nPage
;
1140 if (bScrollBarWillBeVisible
)
1142 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
1146 if (bScrollBarWasVisible
&& !(si
.fMask
& SIF_DISABLENOSCROLL
))
1148 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
1149 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
1150 ME_ScrollAbs(editor
, 0);
1156 int ME_GetYScrollPos(ME_TextEditor
*editor
)
1158 return editor
->vert_si
.nPos
;
1161 BOOL
ME_GetYScrollVisible(ME_TextEditor
*editor
)
1162 { /* Returns true if the scrollbar is visible */
1163 return (editor
->vert_si
.nMax
- editor
->vert_si
.nMin
>= max(editor
->vert_si
.nPage
- 1, 0));
1166 void ME_EnsureVisible(ME_TextEditor
*editor
, ME_DisplayItem
*pRun
)
1168 ME_DisplayItem
*pRow
= ME_FindItemBack(pRun
, diStartRow
);
1169 ME_DisplayItem
*pPara
= ME_FindItemBack(pRun
, diParagraph
);
1170 int y
, yrel
, yheight
, yold
;
1175 y
= pPara
->member
.para
.pt
.y
+pRow
->member
.row
.pt
.y
;
1176 yheight
= pRow
->member
.row
.nHeight
;
1177 yold
= ME_GetYScrollPos(editor
);
1181 ME_ScrollAbs(editor
,y
);
1182 else if (yrel
+ yheight
> editor
->sizeWindow
.cy
)
1183 ME_ScrollAbs(editor
,y
+yheight
-editor
->sizeWindow
.cy
);
1188 ME_InvalidateFromOfs(ME_TextEditor
*editor
, int nCharOfs
)
1194 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &tmp
.pRun
, &tmp
.nOffset
);
1195 ME_GetCursorCoordinates(editor
, &tmp
, &x
, &y
, &height
);
1199 rc
.bottom
= y
+ height
;
1200 rc
.right
= editor
->rcFormat
.right
;
1201 InvalidateRect(editor
->hWnd
, &rc
, FALSE
);
1206 ME_InvalidateSelection(ME_TextEditor
*editor
)
1208 ME_DisplayItem
*para1
, *para2
;
1210 int len
= ME_GetTextLength(editor
);
1212 ME_GetSelection(editor
, &nStart
, &nEnd
);
1213 /* if both old and new selection are 0-char (= caret only), then
1214 there's no (inverted) area to be repainted, neither old nor new */
1215 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
1217 ME_WrapMarkedParagraphs(editor
);
1218 ME_GetSelectionParas(editor
, ¶1
, ¶2
);
1219 assert(para1
->type
== diParagraph
);
1220 assert(para2
->type
== diParagraph
);
1221 /* last selection markers aren't always updated, which means
1222 they can point past the end of the document */
1223 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
) {
1224 ME_MarkForPainting(editor
,
1225 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
),
1226 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diTextEnd
));
1228 /* if the start part of selection is being expanded or contracted... */
1229 if (nStart
< editor
->nLastSelStart
) {
1230 ME_MarkForPainting(editor
, para1
, ME_FindItemFwd(editor
->pLastSelStartPara
, diParagraphOrEnd
));
1232 if (nStart
> editor
->nLastSelStart
) {
1233 ME_MarkForPainting(editor
, editor
->pLastSelStartPara
, ME_FindItemFwd(para1
, diParagraphOrEnd
));
1236 /* if the end part of selection is being contracted or expanded... */
1237 if (nEnd
< editor
->nLastSelEnd
) {
1238 ME_MarkForPainting(editor
, para2
, ME_FindItemFwd(editor
->pLastSelEndPara
, diParagraphOrEnd
));
1240 if (nEnd
> editor
->nLastSelEnd
) {
1241 ME_MarkForPainting(editor
, editor
->pLastSelEndPara
, ME_FindItemFwd(para2
, diParagraphOrEnd
));
1245 ME_InvalidateMarkedParagraphs(editor
);
1246 /* remember the last invalidated position */
1247 ME_GetSelection(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
1248 ME_GetSelectionParas(editor
, &editor
->pLastSelStartPara
, &editor
->pLastSelEndPara
);
1249 assert(editor
->pLastSelStartPara
->type
== diParagraph
);
1250 assert(editor
->pLastSelEndPara
->type
== diParagraph
);
1254 ME_QueueInvalidateFromCursor(ME_TextEditor
*editor
, int nCursor
)
1256 editor
->nInvalidOfs
= ME_GetCursorOfs(editor
, nCursor
);
1261 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
1263 /* TODO: Zoom images and objects */
1267 if (denominator
== 0)
1269 if (1.0 / 64.0 > (float)numerator
/ (float)denominator
1270 || (float)numerator
/ (float)denominator
> 64.0)
1274 editor
->nZoomNumerator
= numerator
;
1275 editor
->nZoomDenominator
= denominator
;
1277 ME_RewrapRepaint(editor
);