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 static void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
);
28 void ME_PaintContent(ME_TextEditor
*editor
, HDC hDC
, BOOL bOnlyNew
, const RECT
*rcUpdate
)
35 oldRgn
= CreateRectRgn(0, 0, 0, 0);
36 if (!GetClipRgn(hDC
, oldRgn
))
41 IntersectClipRect(hDC
, rcUpdate
->left
, rcUpdate
->top
,
42 rcUpdate
->right
, rcUpdate
->bottom
);
45 ME_InitContext(&c
, editor
, hDC
);
46 SetBkMode(hDC
, TRANSPARENT
);
48 item
= editor
->pBuffer
->pFirst
->next
;
49 /* This context point is an offset for the paragraph positions stored
50 * during wrapping. It shouldn't be modified during painting. */
51 c
.pt
.x
= c
.rcView
.left
- editor
->horz_si
.nPos
;
52 c
.pt
.y
= c
.rcView
.top
- editor
->vert_si
.nPos
;
53 while(item
!= editor
->pBuffer
->pLast
)
55 assert(item
->type
== diParagraph
);
57 ys
= c
.pt
.y
+ item
->member
.para
.pt
.y
;
58 if (item
->member
.para
.pCell
59 != item
->member
.para
.next_para
->member
.para
.pCell
)
62 cell
= &ME_FindItemBack(item
->member
.para
.next_para
, diCell
)->member
.cell
;
63 ye
= c
.pt
.y
+ cell
->pt
.y
+ cell
->nHeight
;
65 ye
= ys
+ item
->member
.para
.nHeight
;
67 if (item
->member
.para
.pCell
&& !(item
->member
.para
.nFlags
& MEPF_ROWEND
) &&
68 item
->member
.para
.pCell
!= item
->member
.para
.prev_para
->member
.para
.pCell
)
70 /* the border shifts the text down */
71 ys
-= item
->member
.para
.pCell
->member
.cell
.yTextOffset
;
74 if (!bOnlyNew
|| (item
->member
.para
.nFlags
& MEPF_REPAINT
))
76 /* Draw the pargraph if any of the paragraph is in the update region. */
77 if (ys
< rcUpdate
->bottom
&& ye
> rcUpdate
->top
)
79 ME_DrawParagraph(&c
, item
);
80 /* Clear the repaint flag if the whole paragraph is in the
82 if (rcUpdate
->top
<= ys
&& rcUpdate
->bottom
>= ye
)
83 item
->member
.para
.nFlags
&= ~MEPF_REPAINT
;
86 item
= item
->member
.para
.next_para
;
88 if (c
.pt
.y
+ editor
->nTotalLength
< c
.rcView
.bottom
)
90 /* Fill space after the end of the text. */
92 rc
.top
= c
.pt
.y
+ editor
->nTotalLength
;
93 rc
.left
= c
.rcView
.left
;
94 rc
.bottom
= c
.rcView
.bottom
;
95 rc
.right
= c
.rcView
.right
;
99 /* Only erase region drawn from previous call to ME_PaintContent */
100 if (editor
->nTotalLength
< editor
->nLastTotalLength
)
101 rc
.bottom
= c
.pt
.y
+ editor
->nLastTotalLength
;
106 IntersectRect(&rc
, &rc
, rcUpdate
);
108 if (!IsRectEmpty(&rc
))
109 FillRect(hDC
, &rc
, c
.editor
->hbrBackground
);
111 if (editor
->nTotalLength
!= editor
->nLastTotalLength
||
112 editor
->nTotalWidth
!= editor
->nLastTotalWidth
)
113 ME_SendRequestResize(editor
, FALSE
);
114 editor
->nLastTotalLength
= editor
->nTotalLength
;
115 editor
->nLastTotalWidth
= editor
->nTotalWidth
;
117 SelectClipRgn(hDC
, oldRgn
);
119 DeleteObject(oldRgn
);
122 ME_DestroyContext(&c
);
125 void ME_Repaint(ME_TextEditor
*editor
)
127 if (ME_WrapMarkedParagraphs(editor
))
129 ME_UpdateScrollBar(editor
);
130 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
132 if (!editor
->bEmulateVersion10
|| (editor
->nEventMask
& ENM_UPDATE
))
133 ME_SendOldNotify(editor
, EN_UPDATE
);
134 ITextHost_TxViewChange(editor
->texthost
, TRUE
);
137 void ME_UpdateRepaint(ME_TextEditor
*editor
)
139 /* Should be called whenever the contents of the control have changed */
140 BOOL wrappedParagraphs
;
142 wrappedParagraphs
= ME_WrapMarkedParagraphs(editor
);
143 if (wrappedParagraphs
)
144 ME_UpdateScrollBar(editor
);
146 /* Ensure that the cursor is visible */
147 ME_EnsureVisible(editor
, &editor
->pCursors
[0]);
149 ME_SendSelChange(editor
);
151 /* send EN_CHANGE if the event mask asks for it */
152 if(editor
->nEventMask
& ENM_CHANGE
)
154 editor
->nEventMask
&= ~ENM_CHANGE
;
155 ME_SendOldNotify(editor
, EN_CHANGE
);
156 editor
->nEventMask
|= ENM_CHANGE
;
162 ME_RewrapRepaint(ME_TextEditor
*editor
)
164 /* RewrapRepaint should be called whenever the control has changed in
165 * looks, but not content. Like resizing. */
167 ME_MarkAllForWrapping(editor
);
168 ME_WrapMarkedParagraphs(editor
);
169 ME_UpdateScrollBar(editor
);
173 int ME_twips2pointsX(ME_Context
*c
, int x
)
175 if (c
->editor
->nZoomNumerator
== 0)
176 return x
* c
->dpi
.cx
/ 1440;
178 return x
* c
->dpi
.cx
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
181 int ME_twips2pointsY(ME_Context
*c
, int y
)
183 if (c
->editor
->nZoomNumerator
== 0)
184 return y
* c
->dpi
.cy
/ 1440;
186 return y
* c
->dpi
.cy
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
189 static void ME_HighlightSpace(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
190 int nChars
, ME_Style
*s
, int width
,
191 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
194 HGDIOBJ hOldFont
= NULL
;
197 /* Only highlight if there is a selection in the run and when
198 * EM_HIDESELECTION is not being used to hide the selection. */
199 if (nSelFrom
>= nChars
|| nSelTo
< 0 || nSelFrom
>= nSelTo
200 || c
->editor
->bHideSelection
)
202 hOldFont
= ME_SelectStyleFont(c
, s
);
205 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
208 if (nSelFrom
< 0) nSelFrom
= 0;
209 if (nSelTo
> nChars
) nSelTo
= nChars
;
210 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
212 if (nSelTo
!= nChars
)
214 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
217 selWidth
= width
- sz
.cx
;
219 ME_UnselectStyleFont(c
, s
, hOldFont
);
221 if (c
->editor
->bEmulateVersion10
)
222 PatBlt(hDC
, x
, ymin
, selWidth
, cy
, DSTINVERT
);
229 rect
.right
= x
+ selWidth
;
230 rect
.bottom
= ymin
+ cy
;
231 hBrush
= CreateSolidBrush(ITextHost_TxGetSysColor(c
->editor
->texthost
,
233 FillRect(hDC
, &rect
, hBrush
);
234 DeleteObject(hBrush
);
238 static void ME_DrawTextWithStyle(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
239 int nChars
, ME_Style
*s
, int width
,
240 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
245 int yOffset
= 0, yTwipsOffset
= 0;
248 HPEN hPen
= NULL
, hOldPen
= NULL
;
249 BOOL bHighlightedText
= (nSelFrom
< nChars
&& nSelTo
>= 0
250 && nSelFrom
< nSelTo
&& !c
->editor
->bHideSelection
);
251 int xSelStart
= x
, xSelEnd
= x
;
253 /* lpDx is only needed for tabs to make sure the underline done automatically
254 * by the font extends to the end of the tab. Tabs are always stored as
255 * a single character run, so we can handle this case separately, since
256 * otherwise lpDx would need to specify the lengths of each character. */
257 if (width
&& nChars
== 1)
258 lpDx
= &width
; /* Make sure underline for tab extends across tab space */
260 hOldFont
= ME_SelectStyleFont(c
, s
);
261 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & CFM_OFFSET
) {
262 yTwipsOffset
= s
->fmt
.yOffset
;
264 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & (CFM_SUPERSCRIPT
| CFM_SUBSCRIPT
)) {
265 if (s
->fmt
.dwEffects
& CFE_SUPERSCRIPT
) yTwipsOffset
= s
->fmt
.yHeight
/3;
266 if (s
->fmt
.dwEffects
& CFE_SUBSCRIPT
) yTwipsOffset
= -s
->fmt
.yHeight
/12;
269 yOffset
= ME_twips2pointsY(c
, yTwipsOffset
);
271 if ((s
->fmt
.dwMask
& CFM_LINK
) && (s
->fmt
.dwEffects
& CFE_LINK
))
273 else if ((s
->fmt
.dwMask
& CFM_COLOR
) && (s
->fmt
.dwEffects
& CFE_AUTOCOLOR
))
274 rgb
= ITextHost_TxGetSysColor(c
->editor
->texthost
, COLOR_WINDOWTEXT
);
276 rgb
= s
->fmt
.crTextColor
;
278 /* Determine the area that is selected in the run. */
279 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
280 /* Treat width as an optional parameter. We can get the width from the
281 * text extent of the string if it isn't specified. */
282 if (!width
) width
= sz
.cx
;
283 if (bHighlightedText
)
291 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
292 xSelStart
= x
+ sz
.cx
;
294 if (nSelTo
>= nChars
)
301 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
302 xSelEnd
= xSelStart
+ sz
.cx
;
306 /* Choose the pen type for underlining the text. */
307 if (s
->fmt
.dwMask
& CFM_UNDERLINETYPE
)
309 switch (s
->fmt
.bUnderlineType
)
312 case CFU_UNDERLINEWORD
: /* native seems to map it to simple underline (MSDN) */
313 case CFU_UNDERLINEDOUBLE
: /* native seems to map it to simple underline (MSDN) */
314 hPen
= CreatePen(PS_SOLID
, 1, rgb
);
316 case CFU_UNDERLINEDOTTED
:
317 hPen
= CreatePen(PS_DOT
, 1, rgb
);
320 WINE_FIXME("Unknown underline type (%u)\n", s
->fmt
.bUnderlineType
);
322 case CFU_CF1UNDERLINE
: /* this type is supported in the font, do nothing */
323 case CFU_UNDERLINENONE
:
329 hOldPen
= SelectObject(hDC
, hPen
);
333 rgbOld
= SetTextColor(hDC
, rgb
);
334 if (bHighlightedText
&& !c
->editor
->bEmulateVersion10
)
338 /* FIXME: should use textmetrics info for Descent info */
340 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
343 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nSelFrom
, NULL
);
345 LineTo(hDC
, xSelStart
, y
- yOffset
+ 1);
348 dim
.bottom
= ymin
+ cy
;
349 dim
.left
= xSelStart
;
351 SetTextColor(hDC
, ITextHost_TxGetSysColor(c
->editor
->texthost
,
352 COLOR_HIGHLIGHTTEXT
));
353 rgbBackOld
= SetBkColor(hDC
, ITextHost_TxGetSysColor(c
->editor
->texthost
,
355 ExtTextOutW(hDC
, xSelStart
, y
-yOffset
, ETO_OPAQUE
, &dim
,
356 szText
+nSelFrom
, nSelTo
-nSelFrom
, lpDx
);
358 LineTo(hDC
, xSelEnd
, y
- yOffset
+ 1);
359 SetBkColor(hDC
, rgbBackOld
);
360 if (xSelEnd
< x
+ width
)
362 SetTextColor(hDC
, rgb
);
363 ExtTextOutW(hDC
, xSelEnd
, y
-yOffset
, 0, NULL
, szText
+nSelTo
,
364 nChars
-nSelTo
, NULL
);
366 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
371 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nChars
, lpDx
);
373 /* FIXME: should use textmetrics info for Descent info */
376 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
377 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
380 if (bHighlightedText
) /* v1.0 inverts the selection */
382 PatBlt(hDC
, xSelStart
, ymin
, xSelEnd
-xSelStart
, cy
, DSTINVERT
);
388 SelectObject(hDC
, hOldPen
);
391 SetTextColor(hDC
, rgbOld
);
392 ME_UnselectStyleFont(c
, s
, hOldFont
);
395 static void ME_DebugWrite(HDC hDC
, const POINT
*pt
, LPCWSTR szText
) {
396 int align
= SetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
397 HGDIOBJ hFont
= SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
398 COLORREF color
= SetTextColor(hDC
, RGB(128,128,128));
399 TextOutW(hDC
, pt
->x
, pt
->y
, szText
, lstrlenW(szText
));
400 SelectObject(hDC
, hFont
);
401 SetTextAlign(hDC
, align
);
402 SetTextColor(hDC
, color
);
405 static void ME_DrawRun(ME_Context
*c
, int x
, int y
, ME_DisplayItem
*rundi
, ME_Paragraph
*para
)
407 ME_Run
*run
= &rundi
->member
.run
;
408 ME_DisplayItem
*start
;
409 int runofs
= run
->nCharOfs
+para
->nCharOfs
;
410 int nSelFrom
, nSelTo
;
411 const WCHAR wszSpace
[] = {' ', 0};
413 if (run
->nFlags
& MERF_HIDDEN
)
416 start
= ME_FindItemBack(rundi
, diStartRow
);
417 ME_GetSelectionOfs(c
->editor
, &nSelFrom
, &nSelTo
);
419 /* Draw selected end-of-paragraph mark */
420 if (run
->nFlags
& MERF_ENDPARA
)
422 if (runofs
>= nSelFrom
&& runofs
< nSelTo
)
424 ME_HighlightSpace(c
, x
, y
, wszSpace
, 1, run
->style
, 0, 0, 1,
425 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
426 start
->member
.row
.nHeight
);
431 if (run
->nFlags
& (MERF_TAB
| MERF_ENDCELL
))
433 /* wszSpace is used instead of the tab character because otherwise
434 * an unwanted symbol can be inserted instead. */
435 ME_DrawTextWithStyle(c
, x
, y
, wszSpace
, 1, run
->style
, run
->nWidth
,
436 nSelFrom
-runofs
, nSelTo
-runofs
,
437 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
438 start
->member
.row
.nHeight
);
442 if (run
->nFlags
& MERF_GRAPHICS
)
443 ME_DrawOLE(c
, x
, y
, run
, para
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
));
446 if (c
->editor
->cPasswordMask
)
448 ME_String
*szMasked
= ME_MakeStringR(c
->editor
->cPasswordMask
, run
->strText
->nLen
);
449 ME_DrawTextWithStyle(c
, x
, y
,
450 szMasked
->szData
, szMasked
->nLen
, run
->style
, run
->nWidth
,
451 nSelFrom
-runofs
,nSelTo
-runofs
,
452 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
453 start
->member
.row
.nHeight
);
454 ME_DestroyString(szMasked
);
457 ME_DrawTextWithStyle(c
, x
, y
,
458 run
->strText
->szData
, run
->strText
->nLen
, run
->style
, run
->nWidth
,
459 nSelFrom
-runofs
,nSelTo
-runofs
,
460 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
461 start
->member
.row
.nHeight
);
465 /* The documented widths are in points (72 dpi), but converting them to
466 * 96 dpi (standard display resolution) avoids dealing with fractions. */
467 static const struct {unsigned width
: 8, pen_style
: 4, dble
: 1;} border_details
[] = {
468 /* none */ {0, PS_SOLID
, FALSE
},
469 /* 3/4 */ {1, PS_SOLID
, FALSE
},
470 /* 1 1/2 */ {2, PS_SOLID
, FALSE
},
471 /* 2 1/4 */ {3, PS_SOLID
, FALSE
},
472 /* 3 */ {4, PS_SOLID
, FALSE
},
473 /* 4 1/2 */ {6, PS_SOLID
, FALSE
},
474 /* 6 */ {8, PS_SOLID
, FALSE
},
475 /* 3/4 double */ {1, PS_SOLID
, TRUE
},
476 /* 1 1/2 double */ {2, PS_SOLID
, TRUE
},
477 /* 2 1/4 double */ {3, PS_SOLID
, TRUE
},
478 /* 3/4 gray */ {1, PS_DOT
/* FIXME */, FALSE
},
479 /* 1 1/2 dashed */ {2, PS_DASH
, FALSE
},
482 static const COLORREF pen_colors
[16] = {
483 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
484 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
485 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
486 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
487 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
488 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
489 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
490 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
493 static int ME_GetBorderPenWidth(ME_Context
* c
, int idx
)
495 int width
= border_details
[idx
].width
;
498 width
= MulDiv(width
, c
->dpi
.cx
, 96);
500 if (c
->editor
->nZoomNumerator
!= 0)
501 width
= MulDiv(width
, c
->editor
->nZoomNumerator
, c
->editor
->nZoomDenominator
);
506 int ME_GetParaBorderWidth(ME_Context
* c
, int flags
)
508 int idx
= (flags
>> 8) & 0xF;
511 if (idx
>= sizeof(border_details
) / sizeof(border_details
[0]))
513 FIXME("Unsupported border value %d\n", idx
);
516 width
= ME_GetBorderPenWidth(c
, idx
);
517 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
521 static void ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
, RECT
* bounds
)
523 int idx
, border_width
, top_border
, bottom_border
;
527 SetRectEmpty(bounds
);
528 if (!(para
->pFmt
->dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return;
530 border_width
= top_border
= bottom_border
= 0;
531 idx
= (para
->pFmt
->wBorders
>> 8) & 0xF;
532 hasParaBorder
= (!(c
->editor
->bEmulateVersion10
&&
533 para
->pFmt
->dwMask
& PFM_TABLE
&&
534 para
->pFmt
->wEffects
& PFE_TABLE
) &&
535 (para
->pFmt
->dwMask
& PFM_BORDER
) &&
537 (para
->pFmt
->wBorders
& 0xF));
540 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
541 * controls. It actually stores the paragraph or row border style. Although
542 * the value isn't used for drawing, it is used for streaming out rich text.
544 * wBorders stores the border style for each side (top, left, bottom, right)
545 * using nibble (4 bits) to store each border style. The rich text format
546 * control words, and their associated value are the following:
556 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
557 * The mask corresponding to each side for the version are the following:
561 * 0x0F00 bottom right
562 * 0xF000 right bottom
564 if (para
->pFmt
->wBorders
& 0x00B0)
565 FIXME("Unsupported border flags %x\n", para
->pFmt
->wBorders
);
566 border_width
= ME_GetParaBorderWidth(c
, para
->pFmt
->wBorders
);
567 if (para
->pFmt
->wBorders
& 4) top_border
= border_width
;
568 if (para
->pFmt
->wBorders
& 8) bottom_border
= border_width
;
571 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
573 rc
.left
= c
->rcView
.left
;
574 rc
.right
= c
->rcView
.right
;
576 bounds
->top
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
577 rc
.bottom
= y
+ bounds
->top
+ top_border
;
578 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
581 if (para
->pFmt
->dwMask
& PFM_SPACEAFTER
)
583 rc
.left
= c
->rcView
.left
;
584 rc
.right
= c
->rcView
.right
;
585 rc
.bottom
= y
+ para
->nHeight
;
586 bounds
->bottom
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceAfter
);
587 rc
.top
= rc
.bottom
- bounds
->bottom
- bottom_border
;
588 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
591 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
592 * but might support it in later versions. */
594 int pen_width
, rightEdge
;
596 HPEN pen
= NULL
, oldpen
= NULL
;
599 if (para
->pFmt
->wBorders
& 64) /* autocolor */
600 pencr
= ITextHost_TxGetSysColor(c
->editor
->texthost
,
603 pencr
= pen_colors
[(para
->pFmt
->wBorders
>> 12) & 0xF];
605 rightEdge
= c
->pt
.x
+ max(c
->editor
->sizeWindow
.cx
,
606 c
->editor
->nTotalWidth
);
608 pen_width
= ME_GetBorderPenWidth(c
, idx
);
609 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
610 oldpen
= SelectObject(c
->hDC
, pen
);
611 MoveToEx(c
->hDC
, 0, 0, &pt
);
613 /* before & after spaces are not included in border */
615 /* helper to draw the double lines in case of corner */
616 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
618 if (para
->pFmt
->wBorders
& 1)
620 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
621 LineTo(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
);
622 if (border_details
[idx
].dble
) {
623 rc
.left
= c
->pt
.x
+ 1;
624 rc
.right
= rc
.left
+ border_width
;
625 rc
.top
= y
+ bounds
->top
;
626 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
627 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
628 MoveToEx(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ bounds
->top
+ DD(4), NULL
);
629 LineTo(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
631 bounds
->left
+= border_width
;
633 if (para
->pFmt
->wBorders
& 2)
635 MoveToEx(c
->hDC
, rightEdge
- 1, y
+ bounds
->top
, NULL
);
636 LineTo(c
->hDC
, rightEdge
- 1, y
+ para
->nHeight
- bounds
->bottom
);
637 if (border_details
[idx
].dble
) {
638 rc
.left
= rightEdge
- pen_width
- 1;
639 rc
.right
= rc
.left
+ pen_width
;
640 rc
.top
= y
+ bounds
->top
;
641 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
642 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
643 MoveToEx(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ bounds
->top
+ DD(4), NULL
);
644 LineTo(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
646 bounds
->right
+= border_width
;
648 if (para
->pFmt
->wBorders
& 4)
650 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
651 LineTo(c
->hDC
, rightEdge
, y
+ bounds
->top
);
652 if (border_details
[idx
].dble
) {
653 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ bounds
->top
+ pen_width
+ 1, NULL
);
654 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ bounds
->top
+ pen_width
+ 1);
656 bounds
->top
+= border_width
;
658 if (para
->pFmt
->wBorders
& 8)
660 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
- 1, NULL
);
661 LineTo(c
->hDC
, rightEdge
, y
+ para
->nHeight
- bounds
->bottom
- 1);
662 if (border_details
[idx
].dble
) {
663 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1, NULL
);
664 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1);
666 bounds
->bottom
+= border_width
;
670 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
671 SelectObject(c
->hDC
, oldpen
);
676 static void ME_DrawTableBorders(ME_Context
*c
, ME_DisplayItem
*paragraph
)
678 ME_Paragraph
*para
= ¶graph
->member
.para
;
679 if (!c
->editor
->bEmulateVersion10
) /* v4.1 */
684 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
685 ME_DisplayItem
*paraAfterRow
;
692 BOOL atTop
= (para
->pCell
!= para
->prev_para
->member
.para
.pCell
);
693 BOOL atBottom
= (para
->pCell
!= para
->next_para
->member
.para
.pCell
);
694 int top
= c
->pt
.y
+ (atTop
? cell
->pt
.y
: para
->pt
.y
);
695 int bottom
= (atBottom
?
696 c
->pt
.y
+ cell
->pt
.y
+ cell
->nHeight
:
697 top
+ para
->nHeight
+ (atTop
? cell
->yTextOffset
: 0));
698 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
699 rc
.right
= rc
.left
+ cell
->nWidth
;
701 /* Erase gap before text if not all borders are the same height. */
702 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
703 rc
.top
= top
+ width
;
704 width
= cell
->yTextOffset
- width
;
705 rc
.bottom
= rc
.top
+ width
;
707 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
710 /* Draw cell borders.
711 * The order borders are draw in is left, top, bottom, right in order
712 * to be consistent with native richedit. This is noticeable from the
713 * overlap of borders of different colours. */
714 if (!(para
->nFlags
& MEPF_ROWEND
)) {
717 if (cell
->border
.left
.width
> 0)
719 color
= cell
->border
.left
.colorRef
;
720 width
= max(ME_twips2pointsX(c
, cell
->border
.left
.width
), 1);
722 color
= RGB(192,192,192);
725 logBrush
.lbStyle
= BS_SOLID
;
726 logBrush
.lbColor
= color
;
727 logBrush
.lbHatch
= 0;
728 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
729 width
, &logBrush
, 0, NULL
);
730 oldPen
= SelectObject(c
->hDC
, pen
);
731 MoveToEx(c
->hDC
, rc
.left
, rc
.top
, &oldPt
);
732 LineTo(c
->hDC
, rc
.left
, rc
.bottom
);
733 SelectObject(c
->hDC
, oldPen
);
735 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
739 if (cell
->border
.top
.width
> 0)
741 brush
= CreateSolidBrush(cell
->border
.top
.colorRef
);
742 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
744 brush
= GetStockObject(LTGRAY_BRUSH
);
748 rc
.bottom
= rc
.top
+ width
;
749 FillRect(c
->hDC
, &rc
, brush
);
750 if (cell
->border
.top
.width
> 0)
754 /* Draw the bottom border if at the last paragraph in the cell, and when
755 * in the last row of the table. */
757 int oldLeft
= rc
.left
;
758 width
= max(ME_twips2pointsY(c
, cell
->border
.bottom
.width
), 1);
759 paraAfterRow
= ME_GetTableRowEnd(paragraph
)->member
.para
.next_para
;
760 if (paraAfterRow
->member
.para
.nFlags
& MEPF_ROWSTART
) {
761 ME_DisplayItem
*nextEndCell
;
762 nextEndCell
= ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow
), diCell
);
763 assert(nextEndCell
&& !nextEndCell
->member
.cell
.next_cell
);
764 rc
.left
= c
->pt
.x
+ nextEndCell
->member
.cell
.pt
.x
;
765 /* FIXME: Native draws FROM the bottom of the table rather than
766 * TO the bottom of the table in this case, but just doing so here
767 * will cause the next row to erase the border. */
770 rc.bottom = rc.top + width;
773 if (rc
.left
< rc
.right
) {
774 if (cell
->border
.bottom
.width
> 0) {
775 brush
= CreateSolidBrush(cell
->border
.bottom
.colorRef
);
777 brush
= GetStockObject(LTGRAY_BRUSH
);
780 rc
.top
= rc
.bottom
- width
;
781 FillRect(c
->hDC
, &rc
, brush
);
782 if (cell
->border
.bottom
.width
> 0)
788 /* Right border only drawn if at the end of the table row. */
789 if (!cell
->next_cell
->member
.cell
.next_cell
&&
790 !(para
->nFlags
& MEPF_ROWSTART
))
794 if (cell
->border
.right
.width
> 0) {
795 color
= cell
->border
.right
.colorRef
;
796 width
= max(ME_twips2pointsX(c
, cell
->border
.right
.width
), 1);
798 color
= RGB(192,192,192);
801 logBrush
.lbStyle
= BS_SOLID
;
802 logBrush
.lbColor
= color
;
803 logBrush
.lbHatch
= 0;
804 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
805 width
, &logBrush
, 0, NULL
);
806 oldPen
= SelectObject(c
->hDC
, pen
);
807 MoveToEx(c
->hDC
, rc
.right
- 1, rc
.top
, &oldPt
);
808 LineTo(c
->hDC
, rc
.right
- 1, rc
.bottom
);
809 SelectObject(c
->hDC
, oldPen
);
811 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
814 } else { /* v1.0 - 3.0 */
815 /* Draw simple table border */
816 if (para
->pFmt
->dwMask
& PFM_TABLE
&& para
->pFmt
->wEffects
& PFE_TABLE
) {
817 HPEN pen
= NULL
, oldpen
= NULL
;
818 int i
, firstX
, startX
, endX
, rowY
, rowBottom
, nHeight
;
820 PARAFORMAT2
*pNextFmt
;
822 pen
= CreatePen(PS_SOLID
, 0, para
->border
.top
.colorRef
);
823 oldpen
= SelectObject(c
->hDC
, pen
);
825 /* Find the start relative to the text */
826 firstX
= c
->pt
.x
+ ME_FindItemFwd(paragraph
, diRun
)->member
.run
.pt
.x
;
827 /* Go back by the horizontal gap, which is stored in dxOffset */
828 firstX
-= ME_twips2pointsX(c
, para
->pFmt
->dxOffset
);
829 /* The left edge, stored in dxStartIndent affected just the first edge */
830 startX
= firstX
- ME_twips2pointsX(c
, para
->pFmt
->dxStartIndent
);
831 rowY
= c
->pt
.y
+ para
->pt
.y
;
832 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
833 rowY
+= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
834 nHeight
= ME_FindItemFwd(paragraph
, diStartRow
)->member
.row
.nHeight
;
835 rowBottom
= rowY
+ nHeight
;
837 /* Draw horizontal lines */
838 MoveToEx(c
->hDC
, firstX
, rowY
, &oldPt
);
839 i
= para
->pFmt
->cTabCount
- 1;
840 endX
= startX
+ ME_twips2pointsX(c
, para
->pFmt
->rgxTabs
[i
] & 0x00ffffff) + 1;
841 LineTo(c
->hDC
, endX
, rowY
);
842 pNextFmt
= para
->next_para
->member
.para
.pFmt
;
843 /* The bottom of the row only needs to be drawn if the next row is
845 if (!(pNextFmt
&& pNextFmt
->dwMask
& PFM_TABLE
&& pNextFmt
->wEffects
&&
848 /* Decrement rowBottom to draw the bottom line within the row, and
849 * to not draw over this line when drawing the vertical lines. */
851 MoveToEx(c
->hDC
, firstX
, rowBottom
, NULL
);
852 LineTo(c
->hDC
, endX
, rowBottom
);
855 /* Draw vertical lines */
856 MoveToEx(c
->hDC
, firstX
, rowY
, NULL
);
857 LineTo(c
->hDC
, firstX
, rowBottom
);
858 for (i
= 0; i
< para
->pFmt
->cTabCount
; i
++)
860 int rightBoundary
= para
->pFmt
->rgxTabs
[i
] & 0x00ffffff;
861 endX
= startX
+ ME_twips2pointsX(c
, rightBoundary
);
862 MoveToEx(c
->hDC
, endX
, rowY
, NULL
);
863 LineTo(c
->hDC
, endX
, rowBottom
);
866 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
867 SelectObject(c
->hDC
, oldpen
);
873 static void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
)
875 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
878 ME_Paragraph
*para
= NULL
;
881 int height
= 0, baseline
= 0, no
=0;
882 BOOL visible
= FALSE
;
885 rc
.right
= c
->rcView
.right
;
888 para
= ¶graph
->member
.para
;
889 y
= c
->pt
.y
+ para
->pt
.y
;
892 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
893 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
894 rc
.right
= rc
.left
+ cell
->nWidth
;
896 if (para
->nFlags
& MEPF_ROWSTART
) {
897 ME_Cell
*cell
= ¶
->next_para
->member
.para
.pCell
->member
.cell
;
898 rc
.right
= c
->pt
.x
+ cell
->pt
.x
;
899 } else if (para
->nFlags
& MEPF_ROWEND
) {
900 ME_Cell
*cell
= ¶
->prev_para
->member
.para
.pCell
->member
.cell
;
901 rc
.left
= c
->pt
.x
+ cell
->pt
.x
+ cell
->nWidth
;
903 ME_DrawParaDecoration(c
, para
, y
, &bounds
);
905 if (bounds
.left
|| bounds
.right
) {
906 rc
.left
= max(rc
.left
, c
->pt
.x
+ bounds
.left
);
907 rc
.right
= min(rc
.right
, c
->pt
.x
- bounds
.right
908 + max(c
->editor
->sizeWindow
.cx
,
909 c
->editor
->nTotalWidth
));
912 for (p
= paragraph
->next
; p
!= para
->next_para
; p
= p
->next
)
921 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
)) {
922 rc
.bottom
= y
+ para
->nHeight
;
924 rc
.bottom
= y
+ p
->member
.row
.nHeight
;
926 visible
= RectVisible(c
->hDC
, &rc
);
928 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
932 /* If scrolled to the right past the end of the text, then
933 * there may be space to the right of the paragraph border. */
934 RECT rcAfterBrdr
= rc
;
935 rcAfterBrdr
.left
= rc
.right
+ bounds
.right
;
936 rcAfterBrdr
.right
= c
->rcView
.right
;
937 if (RectVisible(c
->hDC
, &rcAfterBrdr
))
938 FillRect(c
->hDC
, &rcAfterBrdr
, c
->editor
->hbrBackground
);
942 const WCHAR wszRowDebug
[] = {'r','o','w','[','%','d',']',0};
945 wsprintfW(buf
, wszRowDebug
, no
);
947 ME_DebugWrite(c
->hDC
, &pt
, buf
);
950 height
= p
->member
.row
.nHeight
;
951 baseline
= p
->member
.row
.nBaseline
;
955 run
= &p
->member
.run
;
956 if (visible
&& me_debug
) {
958 rc
.left
= c
->pt
.x
+ run
->pt
.x
;
959 rc
.right
= rc
.left
+ run
->nWidth
;
960 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
961 rc
.bottom
= rc
.bottom
+ height
;
962 TRACE("rc = (%d, %d, %d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
963 if (run
->nFlags
& MERF_SKIPPED
)
964 DrawFocusRect(c
->hDC
, &rc
);
966 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
969 ME_DrawRun(c
, c
->pt
.x
+ run
->pt
.x
,
970 c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
+ baseline
, p
, para
);
973 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
974 const WCHAR wszRunDebug
[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
977 pt
.x
= c
->pt
.x
+ run
->pt
.x
;
978 pt
.y
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
979 wsprintfW(buf
, wszRunDebug
, no
, p
->member
.run
.nFlags
, p
->member
.run
.strText
->szData
);
980 ME_DebugWrite(c
->hDC
, &pt
, buf
);
984 /* Clear any space at the bottom of the cell after the text. */
985 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
))
988 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ para
->nHeight
;
989 rc
.bottom
= c
->pt
.y
+ p
->member
.cell
.pt
.y
+ p
->member
.cell
.nHeight
;
990 if (RectVisible(c
->hDC
, &rc
))
992 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
1001 ME_DrawTableBorders(c
, paragraph
);
1003 SetTextAlign(c
->hDC
, align
);
1006 void ME_ScrollAbs(ME_TextEditor
*editor
, int x
, int y
)
1008 BOOL bScrollBarIsVisible
, bScrollBarWillBeVisible
;
1009 int scrollX
= 0, scrollY
= 0;
1011 if (editor
->horz_si
.nPos
!= x
) {
1012 x
= min(x
, editor
->horz_si
.nMax
);
1013 x
= max(x
, editor
->horz_si
.nMin
);
1014 scrollX
= editor
->horz_si
.nPos
- x
;
1015 editor
->horz_si
.nPos
= x
;
1016 if (editor
->horz_si
.nMax
> 0xFFFF) /* scale to 16-bit value */
1017 x
= MulDiv(x
, 0xFFFF, editor
->horz_si
.nMax
);
1018 ITextHost_TxSetScrollPos(editor
->texthost
, SB_HORZ
, x
, TRUE
);
1021 if (editor
->vert_si
.nPos
!= y
) {
1022 y
= min(y
, editor
->vert_si
.nMax
- (int)editor
->vert_si
.nPage
);
1023 y
= max(y
, editor
->vert_si
.nMin
);
1024 scrollY
= editor
->vert_si
.nPos
- y
;
1025 editor
->vert_si
.nPos
= y
;
1026 if (editor
->vert_si
.nMax
> 0xFFFF) /* scale to 16-bit value */
1027 y
= MulDiv(y
, 0xFFFF, editor
->vert_si
.nMax
);
1028 ITextHost_TxSetScrollPos(editor
->texthost
, SB_VERT
, y
, TRUE
);
1031 if (abs(scrollX
) > editor
->sizeWindow
.cx
||
1032 abs(scrollY
) > editor
->sizeWindow
.cy
)
1033 ITextHost_TxInvalidateRect(editor
->texthost
, NULL
, TRUE
);
1035 ITextHost_TxScrollWindowEx(editor
->texthost
, scrollX
, scrollY
,
1036 &editor
->rcFormat
, &editor
->rcFormat
,
1037 NULL
, NULL
, SW_INVALIDATE
);
1042 LONG winStyle
= GetWindowLongW(editor
->hWnd
, GWL_STYLE
);
1043 if (editor
->styleFlags
& WS_HSCROLL
)
1045 bScrollBarIsVisible
= (winStyle
& WS_HSCROLL
) != 0;
1046 bScrollBarWillBeVisible
= (editor
->nTotalWidth
> editor
->sizeWindow
.cx
1047 && (editor
->styleFlags
& WS_HSCROLL
))
1048 || (editor
->styleFlags
& ES_DISABLENOSCROLL
);
1049 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1050 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
,
1051 bScrollBarWillBeVisible
);
1054 if (editor
->styleFlags
& WS_VSCROLL
)
1056 bScrollBarIsVisible
= (winStyle
& WS_VSCROLL
) != 0;
1057 bScrollBarWillBeVisible
= (editor
->nTotalLength
> editor
->sizeWindow
.cy
1058 && (editor
->styleFlags
& WS_VSCROLL
)
1059 && (editor
->styleFlags
& ES_MULTILINE
))
1060 || (editor
->styleFlags
& ES_DISABLENOSCROLL
);
1061 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1062 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
1063 bScrollBarWillBeVisible
);
1066 ME_UpdateScrollBar(editor
);
1069 void ME_HScrollAbs(ME_TextEditor
*editor
, int x
)
1071 ME_ScrollAbs(editor
, x
, editor
->vert_si
.nPos
);
1074 void ME_VScrollAbs(ME_TextEditor
*editor
, int y
)
1076 ME_ScrollAbs(editor
, editor
->horz_si
.nPos
, y
);
1079 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
1081 ME_VScrollAbs(editor
, editor
->vert_si
.nPos
- cy
);
1084 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
1086 ME_VScrollAbs(editor
, editor
->vert_si
.nPos
+ cy
);
1089 void ME_ScrollLeft(ME_TextEditor
*editor
, int cx
)
1091 ME_HScrollAbs(editor
, editor
->horz_si
.nPos
- cx
);
1094 void ME_ScrollRight(ME_TextEditor
*editor
, int cx
)
1096 ME_HScrollAbs(editor
, editor
->horz_si
.nPos
+ cx
);
1099 /* Calculates the visiblity after a call to SetScrollRange or
1100 * SetScrollInfo with SIF_RANGE. */
1101 static BOOL
ME_PostSetScrollRangeVisibility(SCROLLINFO
*si
)
1103 if (si
->fMask
& SIF_DISABLENOSCROLL
)
1106 /* This must match the check in SetScrollInfo to determine whether
1107 * to show or hide the scrollbars. */
1108 return si
->nMin
< si
->nMax
- max(si
->nPage
- 1, 0);
1111 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
1113 /* Note that this is the only function that should ever call
1114 * SetScrollInfo with SIF_PAGE or SIF_RANGE. */
1117 BOOL bScrollBarWasVisible
, bScrollBarWillBeVisible
;
1119 if (ME_WrapMarkedParagraphs(editor
))
1120 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1122 si
.cbSize
= sizeof(si
);
1123 si
.fMask
= SIF_PAGE
| SIF_RANGE
| SIF_POS
;
1125 if (editor
->styleFlags
& ES_DISABLENOSCROLL
)
1126 si
.fMask
|= SIF_DISABLENOSCROLL
;
1128 /* Update horizontal scrollbar */
1129 bScrollBarWasVisible
= editor
->horz_si
.nMax
> editor
->horz_si
.nPage
;
1130 bScrollBarWillBeVisible
= editor
->nTotalWidth
> editor
->sizeWindow
.cx
;
1131 if (editor
->horz_si
.nPos
&& !bScrollBarWillBeVisible
)
1133 ME_HScrollAbs(editor
, 0);
1134 /* ME_HScrollAbs will call this function,
1135 * so nothing else needs to be done here. */
1139 si
.nMax
= editor
->nTotalWidth
;
1140 si
.nPos
= editor
->horz_si
.nPos
;
1141 si
.nPage
= editor
->sizeWindow
.cx
;
1143 if (si
.nMax
!= editor
->horz_si
.nMax
||
1144 si
.nPage
!= editor
->horz_si
.nPage
)
1146 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1147 editor
->horz_si
.nMax
= si
.nMax
;
1148 editor
->horz_si
.nPage
= si
.nPage
;
1149 if ((bScrollBarWillBeVisible
|| bScrollBarWasVisible
) &&
1150 editor
->styleFlags
& WS_HSCROLL
)
1152 if (si
.nMax
> 0xFFFF)
1154 /* Native scales the scrollbar info to 16-bit external values. */
1155 si
.nPos
= MulDiv(si
.nPos
, 0xFFFF, si
.nMax
);
1159 SetScrollInfo(editor
->hWnd
, SB_HORZ
, &si
, TRUE
);
1161 ITextHost_TxSetScrollRange(editor
->texthost
, SB_HORZ
, si
.nMin
, si
.nMax
, FALSE
);
1162 ITextHost_TxSetScrollPos(editor
->texthost
, SB_HORZ
, si
.nPos
, TRUE
);
1164 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1165 bScrollBarWasVisible
= ME_PostSetScrollRangeVisibility(&si
);
1169 if (editor
->styleFlags
& WS_HSCROLL
)
1171 if (si
.fMask
& SIF_DISABLENOSCROLL
) {
1172 bScrollBarWillBeVisible
= TRUE
;
1173 } else if (!(editor
->styleFlags
& WS_HSCROLL
)) {
1174 bScrollBarWillBeVisible
= FALSE
;
1177 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1178 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
, bScrollBarWillBeVisible
);
1181 /* Update vertical scrollbar */
1182 bScrollBarWasVisible
= editor
->vert_si
.nMax
> editor
->vert_si
.nPage
;
1183 bScrollBarWillBeVisible
= editor
->nTotalLength
> editor
->sizeWindow
.cy
&&
1184 (editor
->styleFlags
& ES_MULTILINE
);
1186 if (editor
->vert_si
.nPos
&& !bScrollBarWillBeVisible
)
1188 ME_VScrollAbs(editor
, 0);
1189 /* ME_VScrollAbs will call this function,
1190 * so nothing else needs to be done here. */
1194 si
.nMax
= editor
->nTotalLength
;
1195 si
.nPos
= editor
->vert_si
.nPos
;
1196 si
.nPage
= editor
->sizeWindow
.cy
;
1198 if (si
.nMax
!= editor
->vert_si
.nMax
||
1199 si
.nPage
!= editor
->vert_si
.nPage
)
1201 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1202 editor
->vert_si
.nMax
= si
.nMax
;
1203 editor
->vert_si
.nPage
= si
.nPage
;
1204 if ((bScrollBarWillBeVisible
|| bScrollBarWasVisible
) &&
1205 editor
->styleFlags
& WS_VSCROLL
)
1207 if (si
.nMax
> 0xFFFF)
1209 /* Native scales the scrollbar info to 16-bit external values. */
1210 si
.nPos
= MulDiv(si
.nPos
, 0xFFFF, si
.nMax
);
1214 SetScrollInfo(editor
->hWnd
, SB_VERT
, &si
, TRUE
);
1216 ITextHost_TxSetScrollRange(editor
->texthost
, SB_VERT
, si
.nMin
, si
.nMax
, FALSE
);
1217 ITextHost_TxSetScrollPos(editor
->texthost
, SB_VERT
, si
.nPos
, TRUE
);
1219 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1220 bScrollBarWasVisible
= ME_PostSetScrollRangeVisibility(&si
);
1224 if (editor
->styleFlags
& WS_VSCROLL
)
1226 if (si
.fMask
& SIF_DISABLENOSCROLL
) {
1227 bScrollBarWillBeVisible
= TRUE
;
1228 } else if (!(editor
->styleFlags
& WS_VSCROLL
)) {
1229 bScrollBarWillBeVisible
= FALSE
;
1232 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1233 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
1234 bScrollBarWillBeVisible
);
1238 void ME_EnsureVisible(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1240 ME_Run
*pRun
= &pCursor
->pRun
->member
.run
;
1241 ME_DisplayItem
*pRow
= ME_FindItemBack(pCursor
->pRun
, diStartRow
);
1242 ME_DisplayItem
*pPara
= pCursor
->pPara
;
1248 if (editor
->styleFlags
& ES_AUTOHSCROLL
)
1250 x
= pRun
->pt
.x
+ ME_PointFromChar(editor
, pRun
, pCursor
->nOffset
);
1251 if (x
> editor
->horz_si
.nPos
+ editor
->sizeWindow
.cx
)
1252 x
= x
+ 1 - editor
->sizeWindow
.cx
;
1253 else if (x
> editor
->horz_si
.nPos
)
1254 x
= editor
->horz_si
.nPos
;
1256 if (~editor
->styleFlags
& ES_AUTOVSCROLL
)
1258 ME_HScrollAbs(editor
, x
);
1262 if (~editor
->styleFlags
& ES_AUTOVSCROLL
)
1264 x
= editor
->horz_si
.nPos
;
1267 y
= pPara
->member
.para
.pt
.y
+ pRow
->member
.row
.pt
.y
;
1268 yheight
= pRow
->member
.row
.nHeight
;
1270 if (y
< editor
->vert_si
.nPos
)
1271 ME_ScrollAbs(editor
, x
, y
);
1272 else if (y
+ yheight
> editor
->vert_si
.nPos
+ editor
->sizeWindow
.cy
)
1273 ME_ScrollAbs(editor
, x
, y
+ yheight
- editor
->sizeWindow
.cy
);
1274 else if (x
!= editor
->horz_si
.nPos
)
1275 ME_ScrollAbs(editor
, x
, editor
->vert_si
.nPos
);
1280 ME_InvalidateSelection(ME_TextEditor
*editor
)
1282 ME_DisplayItem
*para1
, *para2
;
1284 int len
= ME_GetTextLength(editor
);
1286 ME_GetSelectionOfs(editor
, &nStart
, &nEnd
);
1287 /* if both old and new selection are 0-char (= caret only), then
1288 there's no (inverted) area to be repainted, neither old nor new */
1289 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
1291 ME_WrapMarkedParagraphs(editor
);
1292 ME_GetSelectionParas(editor
, ¶1
, ¶2
);
1293 assert(para1
->type
== diParagraph
);
1294 assert(para2
->type
== diParagraph
);
1295 /* last selection markers aren't always updated, which means
1296 * they can point past the end of the document */
1297 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
) {
1298 ME_MarkForPainting(editor
,
1299 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
),
1300 editor
->pBuffer
->pLast
);
1302 /* if the start part of selection is being expanded or contracted... */
1303 if (nStart
< editor
->nLastSelStart
) {
1304 ME_MarkForPainting(editor
, para1
, editor
->pLastSelStartPara
->member
.para
.next_para
);
1305 } else if (nStart
> editor
->nLastSelStart
) {
1306 ME_MarkForPainting(editor
, editor
->pLastSelStartPara
, para1
->member
.para
.next_para
);
1309 /* if the end part of selection is being contracted or expanded... */
1310 if (nEnd
< editor
->nLastSelEnd
) {
1311 ME_MarkForPainting(editor
, para2
, editor
->pLastSelEndPara
->member
.para
.next_para
);
1312 } else if (nEnd
> editor
->nLastSelEnd
) {
1313 ME_MarkForPainting(editor
, editor
->pLastSelEndPara
, para2
->member
.para
.next_para
);
1317 ME_InvalidateMarkedParagraphs(editor
);
1318 /* remember the last invalidated position */
1319 ME_GetSelectionOfs(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
1320 ME_GetSelectionParas(editor
, &editor
->pLastSelStartPara
, &editor
->pLastSelEndPara
);
1321 assert(editor
->pLastSelStartPara
->type
== diParagraph
);
1322 assert(editor
->pLastSelEndPara
->type
== diParagraph
);
1326 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
1328 /* TODO: Zoom images and objects */
1330 if (numerator
== 0 && denominator
== 0)
1332 editor
->nZoomNumerator
= editor
->nZoomDenominator
= 0;
1335 if (numerator
<= 0 || denominator
<= 0)
1337 if (numerator
* 64 <= denominator
|| numerator
/ denominator
>= 64)
1340 editor
->nZoomNumerator
= numerator
;
1341 editor
->nZoomDenominator
= denominator
;
1343 ME_RewrapRepaint(editor
);