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 (!editor
->bEmulateVersion10
|| (editor
->nEventMask
& ENM_UPDATE
))
151 ME_SendOldNotify(editor
, EN_UPDATE
);
152 UpdateWindow(editor
->hWnd
);
155 void ME_UpdateRepaint(ME_TextEditor
*editor
)
157 /* Should be called whenever the contents of the control have changed */
159 BOOL wrappedParagraphs
;
161 wrappedParagraphs
= ME_WrapMarkedParagraphs(editor
);
162 if (!editor
->bRedraw
) return;
163 if (wrappedParagraphs
)
164 ME_UpdateScrollBar(editor
);
166 /* Ensure that the cursor is visible */
167 pCursor
= &editor
->pCursors
[0];
168 ME_EnsureVisible(editor
, pCursor
->pRun
);
170 /* send EN_CHANGE if the event mask asks for it */
171 if(editor
->nEventMask
& ENM_CHANGE
)
173 editor
->nEventMask
&= ~ENM_CHANGE
;
174 ME_SendOldNotify(editor
, EN_CHANGE
);
175 editor
->nEventMask
|= ENM_CHANGE
;
178 ME_SendSelChange(editor
);
182 ME_RewrapRepaint(ME_TextEditor
*editor
)
184 /* RewrapRepaint should be called whenever the control has changed in
185 * looks, but not content. Like resizing. */
187 ME_MarkAllForWrapping(editor
);
190 ME_WrapMarkedParagraphs(editor
);
191 ME_UpdateScrollBar(editor
);
196 int ME_twips2pointsX(ME_Context
*c
, int x
)
198 if (c
->editor
->nZoomNumerator
== 0)
199 return x
* c
->dpi
.cx
/ 1440;
201 return x
* c
->dpi
.cx
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
204 int ME_twips2pointsY(ME_Context
*c
, int y
)
206 if (c
->editor
->nZoomNumerator
== 0)
207 return y
* c
->dpi
.cy
/ 1440;
209 return y
* c
->dpi
.cy
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
212 static void ME_HighlightSpace(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
213 int nChars
, ME_Style
*s
, int width
,
214 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
217 HGDIOBJ hOldFont
= NULL
;
220 /* Only highlight if there is a selection in the run and when
221 * EM_HIDESELECTION is not being used to hide the selection. */
222 if (nSelFrom
>= nChars
|| nSelTo
< 0 || nSelFrom
>= nSelTo
223 || c
->editor
->bHideSelection
)
225 hOldFont
= ME_SelectStyleFont(c
, s
);
228 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
231 if (nSelFrom
< 0) nSelFrom
= 0;
232 if (nSelTo
> nChars
) nSelTo
= nChars
;
233 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
235 if (nSelTo
!= nChars
)
237 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
240 selWidth
= width
- sz
.cx
;
242 ME_UnselectStyleFont(c
, s
, hOldFont
);
244 if (c
->editor
->bEmulateVersion10
)
245 PatBlt(hDC
, x
, ymin
, selWidth
, cy
, DSTINVERT
);
252 rect
.right
= x
+ selWidth
;
253 rect
.bottom
= ymin
+ cy
;
254 hBrush
= CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT
));
255 FillRect(hDC
, &rect
, hBrush
);
256 DeleteObject(hBrush
);
260 static void ME_DrawTextWithStyle(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
261 int nChars
, ME_Style
*s
, int width
,
262 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
267 int yOffset
= 0, yTwipsOffset
= 0;
270 HPEN hPen
= NULL
, hOldPen
= NULL
;
271 BOOL bHighlightedText
= (nSelFrom
< nChars
&& nSelTo
>= 0
272 && nSelFrom
< nSelTo
&& !c
->editor
->bHideSelection
);
273 int xSelStart
= x
, xSelEnd
= x
;
275 /* lpDx is only needed for tabs to make sure the underline done automatically
276 * by the font extends to the end of the tab. Tabs are always stored as
277 * a single character run, so we can handle this case separately, since
278 * otherwise lpDx would need to specify the lengths of each character. */
279 if (width
&& nChars
== 1)
280 lpDx
= &width
; /* Make sure underline for tab extends across tab space */
282 hOldFont
= ME_SelectStyleFont(c
, s
);
283 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & CFM_OFFSET
) {
284 yTwipsOffset
= s
->fmt
.yOffset
;
286 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & (CFM_SUPERSCRIPT
| CFM_SUBSCRIPT
)) {
287 if (s
->fmt
.dwEffects
& CFE_SUPERSCRIPT
) yTwipsOffset
= s
->fmt
.yHeight
/3;
288 if (s
->fmt
.dwEffects
& CFE_SUBSCRIPT
) yTwipsOffset
= -s
->fmt
.yHeight
/12;
291 yOffset
= ME_twips2pointsY(c
, yTwipsOffset
);
293 if ((s
->fmt
.dwMask
& CFM_LINK
) && (s
->fmt
.dwEffects
& CFE_LINK
))
295 else if ((s
->fmt
.dwMask
& CFM_COLOR
) && (s
->fmt
.dwEffects
& CFE_AUTOCOLOR
))
296 rgb
= GetSysColor(COLOR_WINDOWTEXT
);
298 rgb
= s
->fmt
.crTextColor
;
300 /* Determine the area that is selected in the run. */
301 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
302 /* Treat width as an optional parameter. We can get the width from the
303 * text extent of the string if it isn't specified. */
304 if (!width
) width
= sz
.cx
;
305 if (bHighlightedText
)
313 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
314 xSelStart
= x
+ sz
.cx
;
316 if (nSelTo
>= nChars
)
323 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
324 xSelEnd
= xSelStart
+ sz
.cx
;
328 /* Choose the pen type for underlining the text. */
329 if (s
->fmt
.dwMask
& CFM_UNDERLINETYPE
)
331 switch (s
->fmt
.bUnderlineType
)
334 case CFU_UNDERLINEWORD
: /* native seems to map it to simple underline (MSDN) */
335 case CFU_UNDERLINEDOUBLE
: /* native seems to map it to simple underline (MSDN) */
336 hPen
= CreatePen(PS_SOLID
, 1, rgb
);
338 case CFU_UNDERLINEDOTTED
:
339 hPen
= CreatePen(PS_DOT
, 1, rgb
);
342 WINE_FIXME("Unknown underline type (%u)\n", s
->fmt
.bUnderlineType
);
344 case CFU_CF1UNDERLINE
: /* this type is supported in the font, do nothing */
345 case CFU_UNDERLINENONE
:
351 hOldPen
= SelectObject(hDC
, hPen
);
355 rgbOld
= SetTextColor(hDC
, rgb
);
356 if (bHighlightedText
&& !c
->editor
->bEmulateVersion10
)
360 /* FIXME: should use textmetrics info for Descent info */
362 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
365 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nSelFrom
, NULL
);
367 LineTo(hDC
, xSelStart
, y
- yOffset
+ 1);
370 dim
.bottom
= ymin
+ cy
;
371 dim
.left
= xSelStart
;
373 SetTextColor(hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
374 rgbBackOld
= SetBkColor(hDC
, GetSysColor(COLOR_HIGHLIGHT
));
375 ExtTextOutW(hDC
, xSelStart
, y
-yOffset
, ETO_OPAQUE
, &dim
,
376 szText
+nSelFrom
, nSelTo
-nSelFrom
, lpDx
);
378 LineTo(hDC
, xSelEnd
, y
- yOffset
+ 1);
379 SetBkColor(hDC
, rgbBackOld
);
380 if (xSelEnd
< x
+ width
)
382 SetTextColor(hDC
, rgb
);
383 ExtTextOutW(hDC
, xSelEnd
, y
-yOffset
, 0, NULL
, szText
+nSelTo
,
384 nChars
-nSelTo
, NULL
);
386 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
391 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nChars
, lpDx
);
393 /* FIXME: should use textmetrics info for Descent info */
396 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
397 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
400 if (bHighlightedText
) /* v1.0 inverts the selection */
402 PatBlt(hDC
, xSelStart
, ymin
, xSelEnd
-xSelStart
, cy
, DSTINVERT
);
408 SelectObject(hDC
, hOldPen
);
411 SetTextColor(hDC
, rgbOld
);
412 ME_UnselectStyleFont(c
, s
, hOldFont
);
415 static void ME_DebugWrite(HDC hDC
, const POINT
*pt
, LPCWSTR szText
) {
416 int align
= SetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
417 HGDIOBJ hFont
= SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
418 COLORREF color
= SetTextColor(hDC
, RGB(128,128,128));
419 TextOutW(hDC
, pt
->x
, pt
->y
, szText
, lstrlenW(szText
));
420 SelectObject(hDC
, hFont
);
421 SetTextAlign(hDC
, align
);
422 SetTextColor(hDC
, color
);
425 static void ME_DrawRun(ME_Context
*c
, int x
, int y
, ME_DisplayItem
*rundi
, ME_Paragraph
*para
)
427 ME_Run
*run
= &rundi
->member
.run
;
428 ME_DisplayItem
*start
;
429 int runofs
= run
->nCharOfs
+para
->nCharOfs
;
430 int nSelFrom
, nSelTo
;
431 const WCHAR wszSpace
[] = {' ', 0};
433 if (run
->nFlags
& MERF_HIDDEN
)
436 start
= ME_FindItemBack(rundi
, diStartRow
);
437 ME_GetSelection(c
->editor
, &nSelFrom
, &nSelTo
);
439 /* Draw selected end-of-paragraph mark */
440 /* you can always comment it out if you need visible paragraph marks */
441 if (run
->nFlags
& MERF_ENDPARA
)
443 if (runofs
>= nSelFrom
&& runofs
< nSelTo
)
445 ME_HighlightSpace(c
, x
, y
, wszSpace
, 1, run
->style
, 0, 0, 1,
446 c
->pt
.y
+ start
->member
.row
.pt
.y
,
447 start
->member
.row
.nHeight
);
452 if (run
->nFlags
& (MERF_TAB
| MERF_ENDCELL
))
454 /* wszSpace is used instead of the tab character because otherwise
455 * an unwanted symbol can be inserted instead. */
456 ME_DrawTextWithStyle(c
, x
, y
, wszSpace
, 1, run
->style
, run
->nWidth
,
457 nSelFrom
-runofs
,nSelTo
-runofs
,
458 c
->pt
.y
+ start
->member
.row
.pt
.y
,
459 start
->member
.row
.nHeight
);
463 if (run
->nFlags
& MERF_GRAPHICS
)
464 ME_DrawOLE(c
, x
, y
, run
, para
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
));
467 if (c
->editor
->cPasswordMask
)
469 ME_String
*szMasked
= ME_MakeStringR(c
->editor
->cPasswordMask
,ME_StrVLen(run
->strText
));
470 ME_DrawTextWithStyle(c
, x
, y
,
471 szMasked
->szData
, ME_StrVLen(szMasked
), run
->style
, run
->nWidth
,
472 nSelFrom
-runofs
,nSelTo
-runofs
, c
->pt
.y
+start
->member
.row
.pt
.y
, start
->member
.row
.nHeight
);
473 ME_DestroyString(szMasked
);
476 ME_DrawTextWithStyle(c
, x
, y
,
477 run
->strText
->szData
, ME_StrVLen(run
->strText
), run
->style
, run
->nWidth
,
478 nSelFrom
-runofs
,nSelTo
-runofs
, c
->pt
.y
+start
->member
.row
.pt
.y
, start
->member
.row
.nHeight
);
482 static const struct {unsigned width_num
: 4, width_den
: 4, pen_style
: 4, dble
: 1;} border_details
[] = {
483 /* none */ {0, 1, PS_SOLID
, FALSE
},
484 /* 3/4 */ {3, 4, PS_SOLID
, FALSE
},
485 /* 1 1/2 */ {3, 2, PS_SOLID
, FALSE
},
486 /* 2 1/4 */ {9, 4, PS_SOLID
, FALSE
},
487 /* 3 */ {3, 1, PS_SOLID
, FALSE
},
488 /* 4 1/2 */ {9, 2, PS_SOLID
, FALSE
},
489 /* 6 */ {6, 1, PS_SOLID
, FALSE
},
490 /* 3/4 double */ {3, 4, PS_SOLID
, TRUE
},
491 /* 1 1/2 double */ {3, 2, PS_SOLID
, TRUE
},
492 /* 2 1/4 double */ {9, 4, PS_SOLID
, TRUE
},
493 /* 3/4 gray */ {3, 4, PS_DOT
/* FIXME */, FALSE
},
494 /* 1 1/2 dashed */ {3, 2, PS_DASH
, FALSE
},
497 static const COLORREF pen_colors
[16] = {
498 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
499 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
500 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
501 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
502 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
503 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
504 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
505 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
508 static int ME_GetBorderPenWidth(ME_TextEditor
* editor
, int idx
)
512 if (editor
->nZoomNumerator
== 0)
514 width
= border_details
[idx
].width_num
+ border_details
[idx
].width_den
/ 2;
515 width
/= border_details
[idx
].width_den
;
519 width
= border_details
[idx
].width_num
* editor
->nZoomNumerator
;
520 width
+= border_details
[idx
].width_den
* editor
->nZoomNumerator
/ 2;
521 width
/= border_details
[idx
].width_den
* editor
->nZoomDenominator
;
526 int ME_GetParaBorderWidth(ME_TextEditor
* editor
, int flags
)
528 int idx
= (flags
>> 8) & 0xF;
531 if (idx
>= sizeof(border_details
) / sizeof(border_details
[0]))
533 FIXME("Unsupported border value %d\n", idx
);
536 width
= ME_GetBorderPenWidth(editor
, idx
);
537 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
541 int ME_GetParaLineSpace(ME_Context
* c
, ME_Paragraph
* para
)
544 if (!(para
->pFmt
->dwMask
& PFM_LINESPACING
)) return 0;
546 /* FIXME: how to compute simply the line space in ls ??? */
547 /* FIXME: does line spacing include the line itself ??? */
548 switch (para
->pFmt
->bLineSpacingRule
)
550 case 0: sp
= ls
; break;
551 case 1: sp
= (3 * ls
) / 2; break;
552 case 2: sp
= 2 * ls
; break;
553 case 3: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); if (sp
< ls
) sp
= ls
; break;
554 case 4: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); break;
555 case 5: sp
= para
->pFmt
->dyLineSpacing
/ 20; break;
556 default: FIXME("Unsupported spacing rule value %d\n", para
->pFmt
->bLineSpacingRule
);
558 if (c
->editor
->nZoomNumerator
== 0)
561 return sp
* c
->editor
->nZoomNumerator
/ c
->editor
->nZoomDenominator
;
564 static void ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
, RECT
* bounds
)
566 int idx
, border_width
, top_border
, bottom_border
;
570 SetRectEmpty(bounds
);
571 if (!(para
->pFmt
->dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return;
573 border_width
= top_border
= bottom_border
= 0;
574 idx
= (para
->pFmt
->wBorders
>> 8) & 0xF;
575 hasParaBorder
= (!(c
->editor
->bEmulateVersion10
&&
576 para
->pFmt
->dwMask
& PFM_TABLE
&&
577 para
->pFmt
->wEffects
& PFE_TABLE
) &&
578 (para
->pFmt
->dwMask
& PFM_BORDER
) &&
580 (para
->pFmt
->wBorders
& 0xF));
583 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
584 * controls. It actually stores the paragraph or row border style. Although
585 * the value isn't used for drawing, it is used for streaming out rich text.
587 * wBorders stores the border style for each side (top, left, bottom, right)
588 * using nibble (4 bits) to store each border style. The rich text format
589 * control words, and their associated value are the following:
599 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
600 * The mask corresponding to each side for the version are the following:
604 * 0x0F00 bottom right
605 * 0xF000 right bottom
607 if (para
->pFmt
->wBorders
& 0x00B0)
608 FIXME("Unsupported border flags %x\n", para
->pFmt
->wBorders
);
609 border_width
= ME_GetParaBorderWidth(c
->editor
, para
->pFmt
->wBorders
);
610 if (para
->pFmt
->wBorders
& 4) top_border
= border_width
;
611 if (para
->pFmt
->wBorders
& 8) bottom_border
= border_width
;
614 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
616 rc
.left
= c
->rcView
.left
;
617 rc
.right
= c
->rcView
.right
;
619 bounds
->top
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
620 rc
.bottom
= y
+ bounds
->top
+ top_border
;
621 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
624 if (para
->pFmt
->dwMask
& PFM_SPACEAFTER
)
626 rc
.left
= c
->rcView
.left
;
627 rc
.right
= c
->rcView
.right
;
628 rc
.bottom
= y
+ para
->nHeight
;
629 bounds
->bottom
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceAfter
);
630 rc
.top
= rc
.bottom
- bounds
->bottom
- bottom_border
;
631 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
634 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
635 * but might support it in later versions. */
639 HPEN pen
= NULL
, oldpen
= NULL
;
642 if (para
->pFmt
->wBorders
& 64) /* autocolor */
643 pencr
= GetSysColor(COLOR_WINDOWTEXT
);
645 pencr
= pen_colors
[(para
->pFmt
->wBorders
>> 12) & 0xF];
647 pen_width
= ME_GetBorderPenWidth(c
->editor
, idx
);
648 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
649 oldpen
= SelectObject(c
->hDC
, pen
);
650 MoveToEx(c
->hDC
, 0, 0, &pt
);
652 /* before & after spaces are not included in border */
654 /* helper to draw the double lines in case of corner */
655 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
657 if (para
->pFmt
->wBorders
& 1)
659 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ bounds
->top
, NULL
);
660 LineTo(c
->hDC
, c
->rcView
.left
, y
+ para
->nHeight
- bounds
->bottom
);
661 if (border_details
[idx
].dble
) {
662 rc
.left
= c
->rcView
.left
+ 1;
663 rc
.right
= rc
.left
+ border_width
;
664 rc
.top
= y
+ bounds
->top
;
665 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
666 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
667 MoveToEx(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ bounds
->top
+ DD(4), NULL
);
668 LineTo(c
->hDC
, c
->rcView
.left
+ pen_width
+ 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
670 bounds
->left
+= border_width
;
672 if (para
->pFmt
->wBorders
& 2)
674 MoveToEx(c
->hDC
, c
->rcView
.right
- 1, y
+ bounds
->top
, NULL
);
675 LineTo(c
->hDC
, c
->rcView
.right
- 1, y
+ para
->nHeight
- bounds
->bottom
);
676 if (border_details
[idx
].dble
) {
677 rc
.left
= c
->rcView
.right
- pen_width
- 1;
678 rc
.right
= c
->rcView
.right
- 1;
679 rc
.top
= y
+ bounds
->top
;
680 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
681 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
682 MoveToEx(c
->hDC
, c
->rcView
.right
- 1 - pen_width
- 1, y
+ bounds
->top
+ DD(4), NULL
);
683 LineTo(c
->hDC
, c
->rcView
.right
- 1 - pen_width
- 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
685 bounds
->right
+= border_width
;
687 if (para
->pFmt
->wBorders
& 4)
689 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ bounds
->top
, NULL
);
690 LineTo(c
->hDC
, c
->rcView
.right
, y
+ bounds
->top
);
691 if (border_details
[idx
].dble
) {
692 MoveToEx(c
->hDC
, c
->rcView
.left
+ DD(1), y
+ bounds
->top
+ pen_width
+ 1, NULL
);
693 LineTo(c
->hDC
, c
->rcView
.right
- DD(2), y
+ bounds
->top
+ pen_width
+ 1);
695 bounds
->top
+= border_width
;
697 if (para
->pFmt
->wBorders
& 8)
699 MoveToEx(c
->hDC
, c
->rcView
.left
, y
+ para
->nHeight
- bounds
->bottom
- 1, NULL
);
700 LineTo(c
->hDC
, c
->rcView
.right
, y
+ para
->nHeight
- bounds
->bottom
- 1);
701 if (border_details
[idx
].dble
) {
702 MoveToEx(c
->hDC
, c
->rcView
.left
+ DD(1), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1, NULL
);
703 LineTo(c
->hDC
, c
->rcView
.right
- DD(2), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1);
705 bounds
->bottom
+= border_width
;
709 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
710 SelectObject(c
->hDC
, oldpen
);
715 static void ME_DrawTableBorders(ME_Context
*c
, ME_DisplayItem
*paragraph
)
717 ME_Paragraph
*para
= ¶graph
->member
.para
;
718 if (!c
->editor
->bEmulateVersion10
) /* v4.1 */
723 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
724 ME_DisplayItem
*paraAfterRow
;
731 BOOL atTop
= (para
->pCell
!= para
->prev_para
->member
.para
.pCell
);
732 BOOL atBottom
= (para
->pCell
!= para
->next_para
->member
.para
.pCell
);
733 int top
= (atTop
? cell
->pt
.y
: para
->pt
.y
) - ME_GetYScrollPos(c
->editor
);
734 int bottom
= (atBottom
?
735 cell
->pt
.y
+ cell
->nHeight
- ME_GetYScrollPos(c
->editor
):
736 top
+ para
->nHeight
+ (atTop
? cell
->yTextOffset
: 0));
737 rc
.left
= cell
->pt
.x
;
738 rc
.right
= rc
.left
+ cell
->nWidth
;
740 /* Erase gap before text if not all borders are the same height. */
741 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
742 rc
.top
= top
+ width
;
743 width
= cell
->yTextOffset
- width
;
744 rc
.bottom
= rc
.top
+ width
;
746 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
749 /* Draw cell borders.
750 * The borders borders are draw in is left, top, bottom, right in order
751 * to be consistent with native richedit. This is noticeable from the
752 * overlap of borders of different colours. */
753 if (!(para
->nFlags
& MEPF_ROWEND
)) {
756 if (cell
->border
.left
.width
> 0)
758 color
= cell
->border
.left
.colorRef
;
759 width
= max(ME_twips2pointsX(c
, cell
->border
.left
.width
), 1);
761 color
= RGB(192,192,192);
764 logBrush
.lbStyle
= BS_SOLID
;
765 logBrush
.lbColor
= color
;
766 logBrush
.lbHatch
= 0;
767 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
768 width
, &logBrush
, 0, NULL
);
769 oldPen
= SelectObject(c
->hDC
, pen
);
770 MoveToEx(c
->hDC
, rc
.left
, rc
.top
, &oldPt
);
771 LineTo(c
->hDC
, rc
.left
, rc
.bottom
);
772 SelectObject(c
->hDC
, oldPen
);
774 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
778 if (cell
->border
.top
.width
> 0)
780 brush
= CreateSolidBrush(cell
->border
.top
.colorRef
);
781 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
783 brush
= GetStockObject(LTGRAY_BRUSH
);
787 rc
.bottom
= rc
.top
+ width
;
788 FillRect(c
->hDC
, &rc
, brush
);
789 if (cell
->border
.top
.width
> 0)
793 /* Draw the bottom border if at the last paragraph in the cell, and when
794 * in the last row of the table. */
796 int oldLeft
= rc
.left
;
797 width
= max(ME_twips2pointsY(c
, cell
->border
.bottom
.width
), 1);
798 paraAfterRow
= ME_GetTableRowEnd(paragraph
)->member
.para
.next_para
;
799 if (paraAfterRow
->member
.para
.nFlags
& MEPF_ROWSTART
) {
800 ME_DisplayItem
*nextEndCell
;
801 nextEndCell
= ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow
), diCell
);
802 assert(nextEndCell
&& !nextEndCell
->member
.cell
.next_cell
);
803 rc
.left
= nextEndCell
->member
.cell
.pt
.x
;
804 /* FIXME: Native draws FROM the bottom of the table rather than
805 * TO the bottom of the table in this case, but just doing so here
806 * will case the next row to erase the border. */
809 rc.bottom = rc.top + width;
812 if (rc
.left
< rc
.right
) {
813 if (cell
->border
.bottom
.width
> 0) {
814 brush
= CreateSolidBrush(cell
->border
.bottom
.colorRef
);
816 brush
= GetStockObject(LTGRAY_BRUSH
);
819 rc
.top
= rc
.bottom
- width
;
820 FillRect(c
->hDC
, &rc
, brush
);
821 if (cell
->border
.bottom
.width
> 0)
827 /* Right border only drawn if at the end of the table row. */
828 if (!cell
->next_cell
->member
.cell
.next_cell
&&
829 !(para
->nFlags
& MEPF_ROWSTART
))
833 if (cell
->border
.right
.width
> 0) {
834 color
= cell
->border
.right
.colorRef
;
835 width
= max(ME_twips2pointsX(c
, cell
->border
.right
.width
), 1);
837 color
= RGB(192,192,192);
840 logBrush
.lbStyle
= BS_SOLID
;
841 logBrush
.lbColor
= color
;
842 logBrush
.lbHatch
= 0;
843 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
844 width
, &logBrush
, 0, NULL
);
845 oldPen
= SelectObject(c
->hDC
, pen
);
846 MoveToEx(c
->hDC
, rc
.right
- 1, rc
.top
, &oldPt
);
847 LineTo(c
->hDC
, rc
.right
- 1, rc
.bottom
);
848 SelectObject(c
->hDC
, oldPen
);
850 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
853 } else { /* v1.0 - 3.0 */
854 /* Draw simple table border */
855 if (para
->pFmt
->dwMask
& PFM_TABLE
&& para
->pFmt
->wEffects
& PFE_TABLE
) {
856 HPEN pen
= NULL
, oldpen
= NULL
;
857 int i
, firstX
, startX
, endX
, rowY
, rowBottom
, nHeight
;
859 PARAFORMAT2
*pNextFmt
;
861 pen
= CreatePen(PS_SOLID
, 0, para
->border
.top
.colorRef
);
862 oldpen
= SelectObject(c
->hDC
, pen
);
864 /* Find the start relative to the text */
865 firstX
= ME_FindItemFwd(paragraph
, diRun
)->member
.run
.pt
.x
;
866 /* Go back by the horizontal gap, which is stored in dxOffset */
867 firstX
-= ME_twips2pointsX(c
, para
->pFmt
->dxOffset
);
868 /* The left edge, stored in dxStartIndent affected just the first edge */
869 startX
= firstX
- ME_twips2pointsX(c
, para
->pFmt
->dxStartIndent
);
871 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
872 rowY
+= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
873 nHeight
= ME_FindItemFwd(paragraph
, diStartRow
)->member
.row
.nHeight
;
874 rowBottom
= rowY
+ nHeight
;
876 /* Draw horizontal lines */
877 MoveToEx(c
->hDC
, firstX
, rowY
, &oldPt
);
878 i
= para
->pFmt
->cTabCount
- 1;
879 endX
= startX
+ ME_twips2pointsX(c
, para
->pFmt
->rgxTabs
[i
] & 0x00ffffff) + 1;
880 LineTo(c
->hDC
, endX
, rowY
);
881 pNextFmt
= para
->next_para
->member
.para
.pFmt
;
882 /* The bottom of the row only needs to be drawn if the next row is
884 if (!(pNextFmt
&& pNextFmt
->dwMask
& PFM_TABLE
&& pNextFmt
->wEffects
&&
887 /* Decrement rowBottom to draw the bottom line within the row, and
888 * to not draw over this line when drawing the vertical lines. */
890 MoveToEx(c
->hDC
, firstX
, rowBottom
, NULL
);
891 LineTo(c
->hDC
, endX
, rowBottom
);
894 /* Draw vertical lines */
895 MoveToEx(c
->hDC
, firstX
, rowY
, NULL
);
896 LineTo(c
->hDC
, firstX
, rowBottom
);
897 for (i
= 0; i
< para
->pFmt
->cTabCount
; i
++)
899 int rightBoundary
= para
->pFmt
->rgxTabs
[i
] & 0x00ffffff;
900 endX
= startX
+ ME_twips2pointsX(c
, rightBoundary
);
901 MoveToEx(c
->hDC
, endX
, rowY
, NULL
);
902 LineTo(c
->hDC
, endX
, rowBottom
);
905 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
906 SelectObject(c
->hDC
, oldpen
);
912 void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
) {
913 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
916 ME_Paragraph
*para
= NULL
;
919 int height
= 0, baseline
= 0, no
=0;
920 BOOL visible
= FALSE
;
922 c
->pt
.x
= c
->rcView
.left
;
923 rc
.left
= c
->rcView
.left
;
924 rc
.right
= c
->rcView
.right
;
925 for (p
= paragraph
; p
!=paragraph
->member
.para
.next_para
; p
= p
->next
) {
928 para
= &p
->member
.para
;
932 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
933 rc
.left
= cell
->pt
.x
;
934 rc
.right
= rc
.left
+ cell
->nWidth
;
936 if (para
->nFlags
& MEPF_ROWSTART
) {
937 ME_Cell
*cell
= ¶
->next_para
->member
.para
.pCell
->member
.cell
;
938 rc
.right
= cell
->pt
.x
;
939 } else if (para
->nFlags
& MEPF_ROWEND
) {
940 ME_Cell
*cell
= ¶
->prev_para
->member
.para
.pCell
->member
.cell
;
941 rc
.left
= cell
->pt
.x
+ cell
->nWidth
;
943 ME_DrawParaDecoration(c
, para
, y
, &bounds
);
947 /* we should have seen a diParagraph before */
951 if (para
->nFlags
& MEPF_ROWSTART
) {
952 ME_Cell
*cell
= ¶
->next_para
->member
.para
.pCell
->member
.cell
;
953 rc
.bottom
= y
+ cell
->nHeight
;
954 } else if (para
->nFlags
& MEPF_ROWEND
) {
955 ME_Cell
*cell
= ¶
->prev_para
->member
.para
.pCell
->member
.cell
;
956 rc
.bottom
= y
+ cell
->nHeight
;
958 rc
.bottom
= y
+p
->member
.row
.nHeight
;
960 visible
= RectVisible(c
->hDC
, &rc
);
962 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
966 const WCHAR wszRowDebug
[] = {'r','o','w','[','%','d',']',0};
969 wsprintfW(buf
, wszRowDebug
, no
);
971 ME_DebugWrite(c
->hDC
, &pt
, buf
);
974 height
= p
->member
.row
.nHeight
;
975 baseline
= p
->member
.row
.nBaseline
;
979 run
= &p
->member
.run
;
980 if (visible
&& me_debug
) {
981 rc
.left
= c
->rcView
.left
+run
->pt
.x
;
982 rc
.right
= c
->rcView
.left
+run
->pt
.x
+run
->nWidth
;
983 rc
.top
= c
->pt
.y
+run
->pt
.y
;
984 rc
.bottom
= c
->pt
.y
+run
->pt
.y
+height
;
985 TRACE("rc = (%d, %d, %d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
986 if (run
->nFlags
& MERF_SKIPPED
)
987 DrawFocusRect(c
->hDC
, &rc
);
989 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
992 ME_DrawRun(c
, run
->pt
.x
, c
->pt
.y
+run
->pt
.y
+baseline
, p
, ¶graph
->member
.para
);
995 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
996 const WCHAR wszRunDebug
[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
1000 pt
.y
= c
->pt
.y
+ run
->pt
.y
;
1001 wsprintfW(buf
, wszRunDebug
, no
, p
->member
.run
.nFlags
, p
->member
.run
.strText
->szData
);
1002 ME_DebugWrite(c
->hDC
, &pt
, buf
);
1004 /* c->pt.x += p->member.run.nWidth; */
1007 /* Clear any space at the bottom of the cell after the text. */
1008 if (para
->nFlags
& MEPF_ROWSTART
)
1012 rc
.bottom
= p
->member
.cell
.pt
.y
+ p
->member
.cell
.nHeight
1013 - ME_GetYScrollPos(c
->editor
);
1014 if (RectVisible(c
->hDC
, &rc
))
1016 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
1025 ME_DrawTableBorders(c
, paragraph
);
1027 SetTextAlign(c
->hDC
, align
);
1030 void ME_ScrollAbs(ME_TextEditor
*editor
, int absY
)
1032 ME_Scroll(editor
, absY
, 1);
1035 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
1037 ME_Scroll(editor
, cy
, 2);
1040 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
1042 ME_Scroll(editor
, cy
, 3);
1045 void ME_Scroll(ME_TextEditor
*editor
, int value
, int type
)
1048 int nOrigPos
, nNewPos
, nActualScroll
;
1051 BOOL bScrollBarIsVisible
, bScrollBarWillBeVisible
;
1053 nOrigPos
= ME_GetYScrollPos(editor
);
1055 si
.cbSize
= sizeof(SCROLLINFO
);
1061 /*Scroll absolutely*/
1065 /* Scroll up - towards the beginning of the document */
1066 si
.nPos
= nOrigPos
- value
;
1069 /* Scroll down - towards the end of the document */
1070 si
.nPos
= nOrigPos
+ value
;
1073 FIXME("ME_Scroll called incorrectly\n");
1077 nNewPos
= SetScrollInfo(editor
->hWnd
, SB_VERT
, &si
, editor
->bRedraw
);
1078 editor
->vert_si
.nPos
= nNewPos
;
1079 nActualScroll
= nOrigPos
- nNewPos
;
1080 if (editor
->bRedraw
)
1082 if (abs(nActualScroll
) > editor
->sizeWindow
.cy
)
1083 InvalidateRect(editor
->hWnd
, NULL
, TRUE
);
1085 ScrollWindowEx(editor
->hWnd
, 0, nActualScroll
, NULL
, NULL
, NULL
, NULL
, SW_INVALIDATE
);
1089 hWnd
= editor
->hWnd
;
1090 winStyle
= GetWindowLongW(hWnd
, GWL_STYLE
);
1091 bScrollBarIsVisible
= (winStyle
& WS_VSCROLL
) != 0;
1092 bScrollBarWillBeVisible
= (editor
->nHeight
> editor
->sizeWindow
.cy
)
1093 || (winStyle
& ES_DISABLENOSCROLL
);
1094 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1096 ShowScrollBar(hWnd
, SB_VERT
, bScrollBarWillBeVisible
);
1098 ME_UpdateScrollBar(editor
);
1102 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
1104 /* Note that this is the only function that should ever call SetScrolLInfo
1105 * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
1106 * be used at all. */
1110 BOOL bScrollBarWasVisible
,bScrollBarWillBeVisible
;
1112 if (ME_WrapMarkedParagraphs(editor
))
1113 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1115 hWnd
= editor
->hWnd
;
1116 si
.cbSize
= sizeof(si
);
1117 bScrollBarWasVisible
= ME_GetYScrollVisible(editor
);
1118 bScrollBarWillBeVisible
= editor
->nHeight
> editor
->sizeWindow
.cy
;
1120 si
.fMask
= SIF_PAGE
| SIF_RANGE
| SIF_POS
;
1121 if (GetWindowLongW(hWnd
, GWL_STYLE
) & ES_DISABLENOSCROLL
)
1123 si
.fMask
|= SIF_DISABLENOSCROLL
;
1124 bScrollBarWillBeVisible
= TRUE
;
1127 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1129 ShowScrollBar(hWnd
, SB_VERT
, bScrollBarWillBeVisible
);
1130 ME_MarkAllForWrapping(editor
);
1131 ME_WrapMarkedParagraphs(editor
);
1135 si
.nMax
= editor
->nTotalLength
;
1136 si
.nPos
= editor
->vert_si
.nPos
;
1137 si
.nPage
= editor
->sizeWindow
.cy
;
1139 if (!(si
.nMin
== editor
->vert_si
.nMin
&& si
.nMax
== editor
->vert_si
.nMax
&& si
.nPage
== editor
->vert_si
.nPage
))
1141 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1142 editor
->vert_si
.nMin
= si
.nMin
;
1143 editor
->vert_si
.nMax
= si
.nMax
;
1144 editor
->vert_si
.nPage
= si
.nPage
;
1145 if (bScrollBarWillBeVisible
)
1147 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
1151 if (bScrollBarWasVisible
&& !(si
.fMask
& SIF_DISABLENOSCROLL
))
1153 SetScrollInfo(hWnd
, SB_VERT
, &si
, TRUE
);
1154 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
1155 ME_ScrollAbs(editor
, 0);
1161 int ME_GetYScrollPos(ME_TextEditor
*editor
)
1163 return editor
->vert_si
.nPos
;
1166 BOOL
ME_GetYScrollVisible(ME_TextEditor
*editor
)
1167 { /* Returns true if the scrollbar is visible */
1168 return (editor
->vert_si
.nMax
- editor
->vert_si
.nMin
>= max(editor
->vert_si
.nPage
- 1, 0));
1171 void ME_EnsureVisible(ME_TextEditor
*editor
, ME_DisplayItem
*pRun
)
1173 ME_DisplayItem
*pRow
= ME_FindItemBack(pRun
, diStartRow
);
1174 ME_DisplayItem
*pPara
= ME_FindItemBack(pRun
, diParagraph
);
1175 int y
, yrel
, yheight
, yold
;
1180 y
= pPara
->member
.para
.pt
.y
+pRow
->member
.row
.pt
.y
;
1181 yheight
= pRow
->member
.row
.nHeight
;
1182 yold
= ME_GetYScrollPos(editor
);
1186 ME_ScrollAbs(editor
,y
);
1187 else if (yrel
+ yheight
> editor
->sizeWindow
.cy
)
1188 ME_ScrollAbs(editor
,y
+yheight
-editor
->sizeWindow
.cy
);
1193 ME_InvalidateFromOfs(ME_TextEditor
*editor
, int nCharOfs
)
1199 ME_RunOfsFromCharOfs(editor
, nCharOfs
, &tmp
.pRun
, &tmp
.nOffset
);
1200 ME_GetCursorCoordinates(editor
, &tmp
, &x
, &y
, &height
);
1204 rc
.bottom
= y
+ height
;
1205 rc
.right
= editor
->rcFormat
.right
;
1206 InvalidateRect(editor
->hWnd
, &rc
, FALSE
);
1211 ME_InvalidateSelection(ME_TextEditor
*editor
)
1213 ME_DisplayItem
*para1
, *para2
;
1215 int len
= ME_GetTextLength(editor
);
1217 ME_GetSelection(editor
, &nStart
, &nEnd
);
1218 /* if both old and new selection are 0-char (= caret only), then
1219 there's no (inverted) area to be repainted, neither old nor new */
1220 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
1222 ME_WrapMarkedParagraphs(editor
);
1223 ME_GetSelectionParas(editor
, ¶1
, ¶2
);
1224 assert(para1
->type
== diParagraph
);
1225 assert(para2
->type
== diParagraph
);
1226 /* last selection markers aren't always updated, which means
1227 they can point past the end of the document */
1228 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
) {
1229 ME_MarkForPainting(editor
,
1230 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
),
1231 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diTextEnd
));
1233 /* if the start part of selection is being expanded or contracted... */
1234 if (nStart
< editor
->nLastSelStart
) {
1235 ME_MarkForPainting(editor
, para1
, ME_FindItemFwd(editor
->pLastSelStartPara
, diParagraphOrEnd
));
1237 if (nStart
> editor
->nLastSelStart
) {
1238 ME_MarkForPainting(editor
, editor
->pLastSelStartPara
, ME_FindItemFwd(para1
, diParagraphOrEnd
));
1241 /* if the end part of selection is being contracted or expanded... */
1242 if (nEnd
< editor
->nLastSelEnd
) {
1243 ME_MarkForPainting(editor
, para2
, ME_FindItemFwd(editor
->pLastSelEndPara
, diParagraphOrEnd
));
1245 if (nEnd
> editor
->nLastSelEnd
) {
1246 ME_MarkForPainting(editor
, editor
->pLastSelEndPara
, ME_FindItemFwd(para2
, diParagraphOrEnd
));
1250 ME_InvalidateMarkedParagraphs(editor
);
1251 /* remember the last invalidated position */
1252 ME_GetSelection(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
1253 ME_GetSelectionParas(editor
, &editor
->pLastSelStartPara
, &editor
->pLastSelEndPara
);
1254 assert(editor
->pLastSelStartPara
->type
== diParagraph
);
1255 assert(editor
->pLastSelEndPara
->type
== diParagraph
);
1259 ME_QueueInvalidateFromCursor(ME_TextEditor
*editor
, int nCursor
)
1261 editor
->nInvalidOfs
= ME_GetCursorOfs(editor
, nCursor
);
1266 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
1268 /* TODO: Zoom images and objects */
1272 if (denominator
== 0)
1274 if (1.0 / 64.0 > (float)numerator
/ (float)denominator
1275 || (float)numerator
/ (float)denominator
> 64.0)
1279 editor
->nZoomNumerator
= numerator
;
1280 editor
->nZoomDenominator
= denominator
;
1282 ME_RewrapRepaint(editor
);