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
, 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 /* Draw the paragraph if any of the paragraph is in the update region. */
75 if (ys
< rcUpdate
->bottom
&& ye
> rcUpdate
->top
)
76 ME_DrawParagraph(&c
, item
);
77 item
= item
->member
.para
.next_para
;
79 if (c
.pt
.y
+ editor
->nTotalLength
< c
.rcView
.bottom
)
81 /* Fill space after the end of the text. */
83 rc
.top
= c
.pt
.y
+ editor
->nTotalLength
;
84 rc
.left
= c
.rcView
.left
;
85 rc
.bottom
= c
.rcView
.bottom
;
86 rc
.right
= c
.rcView
.right
;
88 IntersectRect(&rc
, &rc
, rcUpdate
);
90 if (!IsRectEmpty(&rc
))
91 FillRect(hDC
, &rc
, c
.editor
->hbrBackground
);
93 if (editor
->nTotalLength
!= editor
->nLastTotalLength
||
94 editor
->nTotalWidth
!= editor
->nLastTotalWidth
)
95 ME_SendRequestResize(editor
, FALSE
);
96 editor
->nLastTotalLength
= editor
->nTotalLength
;
97 editor
->nLastTotalWidth
= editor
->nTotalWidth
;
99 SelectClipRgn(hDC
, oldRgn
);
101 DeleteObject(oldRgn
);
104 ME_DestroyContext(&c
);
107 void ME_Repaint(ME_TextEditor
*editor
)
109 if (ME_WrapMarkedParagraphs(editor
))
111 ME_UpdateScrollBar(editor
);
112 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
114 ITextHost_TxViewChange(editor
->texthost
, TRUE
);
117 void ME_UpdateRepaint(ME_TextEditor
*editor
, BOOL update_now
)
119 /* Should be called whenever the contents of the control have changed */
120 BOOL wrappedParagraphs
;
122 wrappedParagraphs
= ME_WrapMarkedParagraphs(editor
);
123 if (wrappedParagraphs
)
124 ME_UpdateScrollBar(editor
);
126 /* Ensure that the cursor is visible */
127 ME_EnsureVisible(editor
, &editor
->pCursors
[0]);
129 ITextHost_TxViewChange(editor
->texthost
, update_now
);
131 ME_SendSelChange(editor
);
133 /* send EN_CHANGE if the event mask asks for it */
134 if(editor
->nEventMask
& ENM_CHANGE
)
136 editor
->nEventMask
&= ~ENM_CHANGE
;
137 ME_SendOldNotify(editor
, EN_CHANGE
);
138 editor
->nEventMask
|= ENM_CHANGE
;
143 ME_RewrapRepaint(ME_TextEditor
*editor
)
145 /* RewrapRepaint should be called whenever the control has changed in
146 * looks, but not content. Like resizing. */
148 ME_MarkAllForWrapping(editor
);
149 ME_WrapMarkedParagraphs(editor
);
150 ME_UpdateScrollBar(editor
);
154 int ME_twips2pointsX(const ME_Context
*c
, int x
)
156 if (c
->editor
->nZoomNumerator
== 0)
157 return x
* c
->dpi
.cx
/ 1440;
159 return x
* c
->dpi
.cx
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
162 int ME_twips2pointsY(const ME_Context
*c
, int y
)
164 if (c
->editor
->nZoomNumerator
== 0)
165 return y
* c
->dpi
.cy
/ 1440;
167 return y
* c
->dpi
.cy
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
170 static void ME_HighlightSpace(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
171 int nChars
, ME_Style
*s
, int width
,
172 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
175 HGDIOBJ hOldFont
= NULL
;
178 /* Only highlight if there is a selection in the run and when
179 * EM_HIDESELECTION is not being used to hide the selection. */
180 if (nSelFrom
>= nChars
|| nSelTo
< 0 || nSelFrom
>= nSelTo
181 || c
->editor
->bHideSelection
)
183 hOldFont
= ME_SelectStyleFont(c
, s
);
186 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
189 if (nSelFrom
< 0) nSelFrom
= 0;
190 if (nSelTo
> nChars
) nSelTo
= nChars
;
191 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
193 if (nSelTo
!= nChars
)
195 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
198 selWidth
= width
- sz
.cx
;
200 ME_UnselectStyleFont(c
, s
, hOldFont
);
202 if (c
->editor
->bEmulateVersion10
)
203 PatBlt(hDC
, x
, ymin
, selWidth
, cy
, DSTINVERT
);
210 rect
.right
= x
+ selWidth
;
211 rect
.bottom
= ymin
+ cy
;
212 hBrush
= CreateSolidBrush(ITextHost_TxGetSysColor(c
->editor
->texthost
,
214 FillRect(hDC
, &rect
, hBrush
);
215 DeleteObject(hBrush
);
219 static void ME_DrawTextWithStyle(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
220 int nChars
, ME_Style
*s
, int width
,
221 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
226 int yOffset
= 0, yTwipsOffset
= 0;
229 HPEN hPen
= NULL
, hOldPen
= NULL
;
230 BOOL bHighlightedText
= (nSelFrom
< nChars
&& nSelTo
>= 0
231 && nSelFrom
< nSelTo
&& !c
->editor
->bHideSelection
);
232 int xSelStart
= x
, xSelEnd
= x
;
234 /* lpDx is only needed for tabs to make sure the underline done automatically
235 * by the font extends to the end of the tab. Tabs are always stored as
236 * a single character run, so we can handle this case separately, since
237 * otherwise lpDx would need to specify the lengths of each character. */
238 if (width
&& nChars
== 1)
239 lpDx
= &width
; /* Make sure underline for tab extends across tab space */
241 hOldFont
= ME_SelectStyleFont(c
, s
);
242 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & CFM_OFFSET
) {
243 yTwipsOffset
= s
->fmt
.yOffset
;
245 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & (CFM_SUPERSCRIPT
| CFM_SUBSCRIPT
)) {
246 if (s
->fmt
.dwEffects
& CFE_SUPERSCRIPT
) yTwipsOffset
= s
->fmt
.yHeight
/3;
247 if (s
->fmt
.dwEffects
& CFE_SUBSCRIPT
) yTwipsOffset
= -s
->fmt
.yHeight
/12;
250 yOffset
= ME_twips2pointsY(c
, yTwipsOffset
);
252 if ((s
->fmt
.dwMask
& CFM_LINK
) && (s
->fmt
.dwEffects
& CFE_LINK
))
254 else if ((s
->fmt
.dwMask
& CFM_COLOR
) && (s
->fmt
.dwEffects
& CFE_AUTOCOLOR
))
255 rgb
= ITextHost_TxGetSysColor(c
->editor
->texthost
, COLOR_WINDOWTEXT
);
257 rgb
= s
->fmt
.crTextColor
;
259 /* Determine the area that is selected in the run. */
260 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
261 /* Treat width as an optional parameter. We can get the width from the
262 * text extent of the string if it isn't specified. */
263 if (!width
) width
= sz
.cx
;
264 if (bHighlightedText
)
272 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
273 xSelStart
= x
+ sz
.cx
;
275 if (nSelTo
>= nChars
)
282 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
283 xSelEnd
= xSelStart
+ sz
.cx
;
287 /* Choose the pen type for underlining the text. */
288 if (s
->fmt
.dwMask
& CFM_UNDERLINETYPE
)
290 switch (s
->fmt
.bUnderlineType
)
293 case CFU_UNDERLINEWORD
: /* native seems to map it to simple underline (MSDN) */
294 case CFU_UNDERLINEDOUBLE
: /* native seems to map it to simple underline (MSDN) */
295 hPen
= CreatePen(PS_SOLID
, 1, rgb
);
297 case CFU_UNDERLINEDOTTED
:
298 hPen
= CreatePen(PS_DOT
, 1, rgb
);
301 FIXME("Unknown underline type (%u)\n", s
->fmt
.bUnderlineType
);
303 case CFU_CF1UNDERLINE
: /* this type is supported in the font, do nothing */
304 case CFU_UNDERLINENONE
:
310 hOldPen
= SelectObject(hDC
, hPen
);
314 rgbOld
= SetTextColor(hDC
, rgb
);
315 if (bHighlightedText
&& !c
->editor
->bEmulateVersion10
)
319 /* FIXME: should use textmetrics info for Descent info */
321 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
324 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nSelFrom
, NULL
);
326 LineTo(hDC
, xSelStart
, y
- yOffset
+ 1);
329 dim
.bottom
= ymin
+ cy
;
330 dim
.left
= xSelStart
;
332 SetTextColor(hDC
, ITextHost_TxGetSysColor(c
->editor
->texthost
,
333 COLOR_HIGHLIGHTTEXT
));
334 rgbBackOld
= SetBkColor(hDC
, ITextHost_TxGetSysColor(c
->editor
->texthost
,
336 ExtTextOutW(hDC
, xSelStart
, y
-yOffset
, ETO_OPAQUE
, &dim
,
337 szText
+nSelFrom
, nSelTo
-nSelFrom
, lpDx
);
339 LineTo(hDC
, xSelEnd
, y
- yOffset
+ 1);
340 SetBkColor(hDC
, rgbBackOld
);
341 if (xSelEnd
< x
+ width
)
343 SetTextColor(hDC
, rgb
);
344 ExtTextOutW(hDC
, xSelEnd
, y
-yOffset
, 0, NULL
, szText
+nSelTo
,
345 nChars
-nSelTo
, NULL
);
347 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
352 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nChars
, lpDx
);
354 /* FIXME: should use textmetrics info for Descent info */
357 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
358 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
361 if (bHighlightedText
) /* v1.0 inverts the selection */
363 PatBlt(hDC
, xSelStart
, ymin
, xSelEnd
-xSelStart
, cy
, DSTINVERT
);
369 SelectObject(hDC
, hOldPen
);
372 SetTextColor(hDC
, rgbOld
);
373 ME_UnselectStyleFont(c
, s
, hOldFont
);
376 static void ME_DebugWrite(HDC hDC
, const POINT
*pt
, LPCWSTR szText
) {
377 int align
= SetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
378 HGDIOBJ hFont
= SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
379 COLORREF color
= SetTextColor(hDC
, RGB(128,128,128));
380 TextOutW(hDC
, pt
->x
, pt
->y
, szText
, lstrlenW(szText
));
381 SelectObject(hDC
, hFont
);
382 SetTextAlign(hDC
, align
);
383 SetTextColor(hDC
, color
);
386 static void ME_DrawRun(ME_Context
*c
, int x
, int y
, ME_DisplayItem
*rundi
, ME_Paragraph
*para
)
388 ME_Run
*run
= &rundi
->member
.run
;
389 ME_DisplayItem
*start
;
390 int runofs
= run
->nCharOfs
+para
->nCharOfs
;
391 int nSelFrom
, nSelTo
;
392 const WCHAR wszSpace
[] = {' ', 0};
394 if (run
->nFlags
& MERF_HIDDEN
)
397 start
= ME_FindItemBack(rundi
, diStartRow
);
398 ME_GetSelectionOfs(c
->editor
, &nSelFrom
, &nSelTo
);
400 /* Draw selected end-of-paragraph mark */
401 if (run
->nFlags
& MERF_ENDPARA
)
403 if (runofs
>= nSelFrom
&& runofs
< nSelTo
)
405 ME_HighlightSpace(c
, x
, y
, wszSpace
, 1, run
->style
, 0, 0, 1,
406 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
407 start
->member
.row
.nHeight
);
412 if (run
->nFlags
& (MERF_TAB
| MERF_ENDCELL
))
414 /* wszSpace is used instead of the tab character because otherwise
415 * an unwanted symbol can be inserted instead. */
416 ME_DrawTextWithStyle(c
, x
, y
, wszSpace
, 1, run
->style
, run
->nWidth
,
417 nSelFrom
-runofs
, nSelTo
-runofs
,
418 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
419 start
->member
.row
.nHeight
);
423 if (run
->nFlags
& MERF_GRAPHICS
)
424 ME_DrawOLE(c
, x
, y
, run
, para
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
));
427 if (c
->editor
->cPasswordMask
)
429 ME_String
*szMasked
= ME_MakeStringR(c
->editor
->cPasswordMask
, run
->strText
->nLen
);
430 ME_DrawTextWithStyle(c
, x
, y
,
431 szMasked
->szData
, szMasked
->nLen
, run
->style
, run
->nWidth
,
432 nSelFrom
-runofs
,nSelTo
-runofs
,
433 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
434 start
->member
.row
.nHeight
);
435 ME_DestroyString(szMasked
);
438 ME_DrawTextWithStyle(c
, x
, y
,
439 run
->strText
->szData
, run
->strText
->nLen
, run
->style
, run
->nWidth
,
440 nSelFrom
-runofs
,nSelTo
-runofs
,
441 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
442 start
->member
.row
.nHeight
);
446 /* The documented widths are in points (72 dpi), but converting them to
447 * 96 dpi (standard display resolution) avoids dealing with fractions. */
448 static const struct {unsigned width
: 8, pen_style
: 4, dble
: 1;} border_details
[] = {
449 /* none */ {0, PS_SOLID
, FALSE
},
450 /* 3/4 */ {1, PS_SOLID
, FALSE
},
451 /* 1 1/2 */ {2, PS_SOLID
, FALSE
},
452 /* 2 1/4 */ {3, PS_SOLID
, FALSE
},
453 /* 3 */ {4, PS_SOLID
, FALSE
},
454 /* 4 1/2 */ {6, PS_SOLID
, FALSE
},
455 /* 6 */ {8, PS_SOLID
, FALSE
},
456 /* 3/4 double */ {1, PS_SOLID
, TRUE
},
457 /* 1 1/2 double */ {2, PS_SOLID
, TRUE
},
458 /* 2 1/4 double */ {3, PS_SOLID
, TRUE
},
459 /* 3/4 gray */ {1, PS_DOT
/* FIXME */, FALSE
},
460 /* 1 1/2 dashed */ {2, PS_DASH
, FALSE
},
463 static const COLORREF pen_colors
[16] = {
464 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
465 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
466 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
467 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
468 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
469 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
470 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
471 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
474 static int ME_GetBorderPenWidth(const ME_Context
* c
, int idx
)
476 int width
= border_details
[idx
].width
;
479 width
= MulDiv(width
, c
->dpi
.cx
, 96);
481 if (c
->editor
->nZoomNumerator
!= 0)
482 width
= MulDiv(width
, c
->editor
->nZoomNumerator
, c
->editor
->nZoomDenominator
);
487 int ME_GetParaBorderWidth(const ME_Context
* c
, int flags
)
489 int idx
= (flags
>> 8) & 0xF;
492 if (idx
>= sizeof(border_details
) / sizeof(border_details
[0]))
494 FIXME("Unsupported border value %d\n", idx
);
497 width
= ME_GetBorderPenWidth(c
, idx
);
498 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
502 static void ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
, RECT
* bounds
)
504 int idx
, border_width
, top_border
, bottom_border
;
508 SetRectEmpty(bounds
);
509 if (!(para
->pFmt
->dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return;
511 border_width
= top_border
= bottom_border
= 0;
512 idx
= (para
->pFmt
->wBorders
>> 8) & 0xF;
513 hasParaBorder
= (!(c
->editor
->bEmulateVersion10
&&
514 para
->pFmt
->dwMask
& PFM_TABLE
&&
515 para
->pFmt
->wEffects
& PFE_TABLE
) &&
516 (para
->pFmt
->dwMask
& PFM_BORDER
) &&
518 (para
->pFmt
->wBorders
& 0xF));
521 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
522 * controls. It actually stores the paragraph or row border style. Although
523 * the value isn't used for drawing, it is used for streaming out rich text.
525 * wBorders stores the border style for each side (top, left, bottom, right)
526 * using nibble (4 bits) to store each border style. The rich text format
527 * control words, and their associated value are the following:
537 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
538 * The mask corresponding to each side for the version are the following:
542 * 0x0F00 bottom right
543 * 0xF000 right bottom
545 if (para
->pFmt
->wBorders
& 0x00B0)
546 FIXME("Unsupported border flags %x\n", para
->pFmt
->wBorders
);
547 border_width
= ME_GetParaBorderWidth(c
, para
->pFmt
->wBorders
);
548 if (para
->pFmt
->wBorders
& 4) top_border
= border_width
;
549 if (para
->pFmt
->wBorders
& 8) bottom_border
= border_width
;
552 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
554 rc
.left
= c
->rcView
.left
;
555 rc
.right
= c
->rcView
.right
;
557 bounds
->top
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
558 rc
.bottom
= y
+ bounds
->top
+ top_border
;
559 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
562 if (para
->pFmt
->dwMask
& PFM_SPACEAFTER
)
564 rc
.left
= c
->rcView
.left
;
565 rc
.right
= c
->rcView
.right
;
566 rc
.bottom
= y
+ para
->nHeight
;
567 bounds
->bottom
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceAfter
);
568 rc
.top
= rc
.bottom
- bounds
->bottom
- bottom_border
;
569 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
572 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
573 * but might support it in later versions. */
575 int pen_width
, rightEdge
;
577 HPEN pen
= NULL
, oldpen
= NULL
;
580 if (para
->pFmt
->wBorders
& 64) /* autocolor */
581 pencr
= ITextHost_TxGetSysColor(c
->editor
->texthost
,
584 pencr
= pen_colors
[(para
->pFmt
->wBorders
>> 12) & 0xF];
586 rightEdge
= c
->pt
.x
+ max(c
->editor
->sizeWindow
.cx
,
587 c
->editor
->nTotalWidth
);
589 pen_width
= ME_GetBorderPenWidth(c
, idx
);
590 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
591 oldpen
= SelectObject(c
->hDC
, pen
);
592 MoveToEx(c
->hDC
, 0, 0, &pt
);
594 /* before & after spaces are not included in border */
596 /* helper to draw the double lines in case of corner */
597 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
599 if (para
->pFmt
->wBorders
& 1)
601 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
602 LineTo(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
);
603 if (border_details
[idx
].dble
) {
604 rc
.left
= c
->pt
.x
+ 1;
605 rc
.right
= rc
.left
+ border_width
;
606 rc
.top
= y
+ bounds
->top
;
607 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
608 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
609 MoveToEx(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ bounds
->top
+ DD(4), NULL
);
610 LineTo(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
612 bounds
->left
+= border_width
;
614 if (para
->pFmt
->wBorders
& 2)
616 MoveToEx(c
->hDC
, rightEdge
- 1, y
+ bounds
->top
, NULL
);
617 LineTo(c
->hDC
, rightEdge
- 1, y
+ para
->nHeight
- bounds
->bottom
);
618 if (border_details
[idx
].dble
) {
619 rc
.left
= rightEdge
- pen_width
- 1;
620 rc
.right
= rc
.left
+ pen_width
;
621 rc
.top
= y
+ bounds
->top
;
622 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
623 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
624 MoveToEx(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ bounds
->top
+ DD(4), NULL
);
625 LineTo(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
627 bounds
->right
+= border_width
;
629 if (para
->pFmt
->wBorders
& 4)
631 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
632 LineTo(c
->hDC
, rightEdge
, y
+ bounds
->top
);
633 if (border_details
[idx
].dble
) {
634 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ bounds
->top
+ pen_width
+ 1, NULL
);
635 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ bounds
->top
+ pen_width
+ 1);
637 bounds
->top
+= border_width
;
639 if (para
->pFmt
->wBorders
& 8)
641 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
- 1, NULL
);
642 LineTo(c
->hDC
, rightEdge
, y
+ para
->nHeight
- bounds
->bottom
- 1);
643 if (border_details
[idx
].dble
) {
644 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1, NULL
);
645 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1);
647 bounds
->bottom
+= border_width
;
651 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
652 SelectObject(c
->hDC
, oldpen
);
657 static void ME_DrawTableBorders(ME_Context
*c
, ME_DisplayItem
*paragraph
)
659 ME_Paragraph
*para
= ¶graph
->member
.para
;
660 if (!c
->editor
->bEmulateVersion10
) /* v4.1 */
665 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
666 ME_DisplayItem
*paraAfterRow
;
673 BOOL atTop
= (para
->pCell
!= para
->prev_para
->member
.para
.pCell
);
674 BOOL atBottom
= (para
->pCell
!= para
->next_para
->member
.para
.pCell
);
675 int top
= c
->pt
.y
+ (atTop
? cell
->pt
.y
: para
->pt
.y
);
676 int bottom
= (atBottom
?
677 c
->pt
.y
+ cell
->pt
.y
+ cell
->nHeight
:
678 top
+ para
->nHeight
+ (atTop
? cell
->yTextOffset
: 0));
679 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
680 rc
.right
= rc
.left
+ cell
->nWidth
;
682 /* Erase gap before text if not all borders are the same height. */
683 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
684 rc
.top
= top
+ width
;
685 width
= cell
->yTextOffset
- width
;
686 rc
.bottom
= rc
.top
+ width
;
688 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
691 /* Draw cell borders.
692 * The order borders are draw in is left, top, bottom, right in order
693 * to be consistent with native richedit. This is noticeable from the
694 * overlap of borders of different colours. */
695 if (!(para
->nFlags
& MEPF_ROWEND
)) {
698 if (cell
->border
.left
.width
> 0)
700 color
= cell
->border
.left
.colorRef
;
701 width
= max(ME_twips2pointsX(c
, cell
->border
.left
.width
), 1);
703 color
= RGB(192,192,192);
706 logBrush
.lbStyle
= BS_SOLID
;
707 logBrush
.lbColor
= color
;
708 logBrush
.lbHatch
= 0;
709 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
710 width
, &logBrush
, 0, NULL
);
711 oldPen
= SelectObject(c
->hDC
, pen
);
712 MoveToEx(c
->hDC
, rc
.left
, rc
.top
, &oldPt
);
713 LineTo(c
->hDC
, rc
.left
, rc
.bottom
);
714 SelectObject(c
->hDC
, oldPen
);
716 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
720 if (cell
->border
.top
.width
> 0)
722 brush
= CreateSolidBrush(cell
->border
.top
.colorRef
);
723 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
725 brush
= GetStockObject(LTGRAY_BRUSH
);
729 rc
.bottom
= rc
.top
+ width
;
730 FillRect(c
->hDC
, &rc
, brush
);
731 if (cell
->border
.top
.width
> 0)
735 /* Draw the bottom border if at the last paragraph in the cell, and when
736 * in the last row of the table. */
738 int oldLeft
= rc
.left
;
739 width
= max(ME_twips2pointsY(c
, cell
->border
.bottom
.width
), 1);
740 paraAfterRow
= ME_GetTableRowEnd(paragraph
)->member
.para
.next_para
;
741 if (paraAfterRow
->member
.para
.nFlags
& MEPF_ROWSTART
) {
742 ME_DisplayItem
*nextEndCell
;
743 nextEndCell
= ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow
), diCell
);
744 assert(nextEndCell
&& !nextEndCell
->member
.cell
.next_cell
);
745 rc
.left
= c
->pt
.x
+ nextEndCell
->member
.cell
.pt
.x
;
746 /* FIXME: Native draws FROM the bottom of the table rather than
747 * TO the bottom of the table in this case, but just doing so here
748 * will cause the next row to erase the border. */
751 rc.bottom = rc.top + width;
754 if (rc
.left
< rc
.right
) {
755 if (cell
->border
.bottom
.width
> 0) {
756 brush
= CreateSolidBrush(cell
->border
.bottom
.colorRef
);
758 brush
= GetStockObject(LTGRAY_BRUSH
);
761 rc
.top
= rc
.bottom
- width
;
762 FillRect(c
->hDC
, &rc
, brush
);
763 if (cell
->border
.bottom
.width
> 0)
769 /* Right border only drawn if at the end of the table row. */
770 if (!cell
->next_cell
->member
.cell
.next_cell
&&
771 !(para
->nFlags
& MEPF_ROWSTART
))
775 if (cell
->border
.right
.width
> 0) {
776 color
= cell
->border
.right
.colorRef
;
777 width
= max(ME_twips2pointsX(c
, cell
->border
.right
.width
), 1);
779 color
= RGB(192,192,192);
782 logBrush
.lbStyle
= BS_SOLID
;
783 logBrush
.lbColor
= color
;
784 logBrush
.lbHatch
= 0;
785 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
786 width
, &logBrush
, 0, NULL
);
787 oldPen
= SelectObject(c
->hDC
, pen
);
788 MoveToEx(c
->hDC
, rc
.right
- 1, rc
.top
, &oldPt
);
789 LineTo(c
->hDC
, rc
.right
- 1, rc
.bottom
);
790 SelectObject(c
->hDC
, oldPen
);
792 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
795 } else { /* v1.0 - 3.0 */
796 /* Draw simple table border */
797 if (para
->pFmt
->dwMask
& PFM_TABLE
&& para
->pFmt
->wEffects
& PFE_TABLE
) {
798 HPEN pen
= NULL
, oldpen
= NULL
;
799 int i
, firstX
, startX
, endX
, rowY
, rowBottom
, nHeight
;
801 PARAFORMAT2
*pNextFmt
;
803 pen
= CreatePen(PS_SOLID
, 0, para
->border
.top
.colorRef
);
804 oldpen
= SelectObject(c
->hDC
, pen
);
806 /* Find the start relative to the text */
807 firstX
= c
->pt
.x
+ ME_FindItemFwd(paragraph
, diRun
)->member
.run
.pt
.x
;
808 /* Go back by the horizontal gap, which is stored in dxOffset */
809 firstX
-= ME_twips2pointsX(c
, para
->pFmt
->dxOffset
);
810 /* The left edge, stored in dxStartIndent affected just the first edge */
811 startX
= firstX
- ME_twips2pointsX(c
, para
->pFmt
->dxStartIndent
);
812 rowY
= c
->pt
.y
+ para
->pt
.y
;
813 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
814 rowY
+= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
815 nHeight
= ME_FindItemFwd(paragraph
, diStartRow
)->member
.row
.nHeight
;
816 rowBottom
= rowY
+ nHeight
;
818 /* Draw horizontal lines */
819 MoveToEx(c
->hDC
, firstX
, rowY
, &oldPt
);
820 i
= para
->pFmt
->cTabCount
- 1;
821 endX
= startX
+ ME_twips2pointsX(c
, para
->pFmt
->rgxTabs
[i
] & 0x00ffffff) + 1;
822 LineTo(c
->hDC
, endX
, rowY
);
823 pNextFmt
= para
->next_para
->member
.para
.pFmt
;
824 /* The bottom of the row only needs to be drawn if the next row is
826 if (!(pNextFmt
&& pNextFmt
->dwMask
& PFM_TABLE
&& pNextFmt
->wEffects
&&
829 /* Decrement rowBottom to draw the bottom line within the row, and
830 * to not draw over this line when drawing the vertical lines. */
832 MoveToEx(c
->hDC
, firstX
, rowBottom
, NULL
);
833 LineTo(c
->hDC
, endX
, rowBottom
);
836 /* Draw vertical lines */
837 MoveToEx(c
->hDC
, firstX
, rowY
, NULL
);
838 LineTo(c
->hDC
, firstX
, rowBottom
);
839 for (i
= 0; i
< para
->pFmt
->cTabCount
; i
++)
841 int rightBoundary
= para
->pFmt
->rgxTabs
[i
] & 0x00ffffff;
842 endX
= startX
+ ME_twips2pointsX(c
, rightBoundary
);
843 MoveToEx(c
->hDC
, endX
, rowY
, NULL
);
844 LineTo(c
->hDC
, endX
, rowBottom
);
847 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
848 SelectObject(c
->hDC
, oldpen
);
854 static void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
)
856 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
859 ME_Paragraph
*para
= NULL
;
862 int height
= 0, baseline
= 0, no
=0;
863 BOOL visible
= FALSE
;
866 rc
.right
= c
->rcView
.right
;
869 para
= ¶graph
->member
.para
;
870 y
= c
->pt
.y
+ para
->pt
.y
;
873 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
874 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
875 rc
.right
= rc
.left
+ cell
->nWidth
;
877 if (para
->nFlags
& MEPF_ROWSTART
) {
878 ME_Cell
*cell
= ¶
->next_para
->member
.para
.pCell
->member
.cell
;
879 rc
.right
= c
->pt
.x
+ cell
->pt
.x
;
880 } else if (para
->nFlags
& MEPF_ROWEND
) {
881 ME_Cell
*cell
= ¶
->prev_para
->member
.para
.pCell
->member
.cell
;
882 rc
.left
= c
->pt
.x
+ cell
->pt
.x
+ cell
->nWidth
;
884 ME_DrawParaDecoration(c
, para
, y
, &bounds
);
886 if (bounds
.left
|| bounds
.right
) {
887 rc
.left
= max(rc
.left
, c
->pt
.x
+ bounds
.left
);
888 rc
.right
= min(rc
.right
, c
->pt
.x
- bounds
.right
889 + max(c
->editor
->sizeWindow
.cx
,
890 c
->editor
->nTotalWidth
));
893 for (p
= paragraph
->next
; p
!= para
->next_para
; p
= p
->next
)
902 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
)) {
903 rc
.bottom
= y
+ para
->nHeight
;
905 rc
.bottom
= y
+ p
->member
.row
.nHeight
;
907 visible
= RectVisible(c
->hDC
, &rc
);
909 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
913 /* If scrolled to the right past the end of the text, then
914 * there may be space to the right of the paragraph border. */
915 RECT rcAfterBrdr
= rc
;
916 rcAfterBrdr
.left
= rc
.right
+ bounds
.right
;
917 rcAfterBrdr
.right
= c
->rcView
.right
;
918 if (RectVisible(c
->hDC
, &rcAfterBrdr
))
919 FillRect(c
->hDC
, &rcAfterBrdr
, c
->editor
->hbrBackground
);
923 const WCHAR wszRowDebug
[] = {'r','o','w','[','%','d',']',0};
926 wsprintfW(buf
, wszRowDebug
, no
);
928 ME_DebugWrite(c
->hDC
, &pt
, buf
);
931 height
= p
->member
.row
.nHeight
;
932 baseline
= p
->member
.row
.nBaseline
;
936 run
= &p
->member
.run
;
937 if (visible
&& me_debug
) {
939 rc
.left
= c
->pt
.x
+ run
->pt
.x
;
940 rc
.right
= rc
.left
+ run
->nWidth
;
941 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
942 rc
.bottom
= rc
.top
+ height
;
943 TRACE("rc = (%d, %d, %d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
944 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
947 ME_DrawRun(c
, c
->pt
.x
+ run
->pt
.x
,
948 c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
+ baseline
, p
, para
);
951 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
952 const WCHAR wszRunDebug
[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
955 pt
.x
= c
->pt
.x
+ run
->pt
.x
;
956 pt
.y
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
957 wsprintfW(buf
, wszRunDebug
, no
, p
->member
.run
.nFlags
, p
->member
.run
.strText
->szData
);
958 ME_DebugWrite(c
->hDC
, &pt
, buf
);
962 /* Clear any space at the bottom of the cell after the text. */
963 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
))
966 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ para
->nHeight
;
967 rc
.bottom
= c
->pt
.y
+ p
->member
.cell
.pt
.y
+ p
->member
.cell
.nHeight
;
968 if (RectVisible(c
->hDC
, &rc
))
970 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
979 ME_DrawTableBorders(c
, paragraph
);
981 SetTextAlign(c
->hDC
, align
);
984 void ME_ScrollAbs(ME_TextEditor
*editor
, int x
, int y
)
986 BOOL bScrollBarIsVisible
, bScrollBarWillBeVisible
;
987 int scrollX
= 0, scrollY
= 0;
989 if (editor
->horz_si
.nPos
!= x
) {
990 x
= min(x
, editor
->horz_si
.nMax
);
991 x
= max(x
, editor
->horz_si
.nMin
);
992 scrollX
= editor
->horz_si
.nPos
- x
;
993 editor
->horz_si
.nPos
= x
;
994 if (editor
->horz_si
.nMax
> 0xFFFF) /* scale to 16-bit value */
995 x
= MulDiv(x
, 0xFFFF, editor
->horz_si
.nMax
);
996 ITextHost_TxSetScrollPos(editor
->texthost
, SB_HORZ
, x
, TRUE
);
999 if (editor
->vert_si
.nPos
!= y
) {
1000 y
= min(y
, editor
->vert_si
.nMax
- (int)editor
->vert_si
.nPage
);
1001 y
= max(y
, editor
->vert_si
.nMin
);
1002 scrollY
= editor
->vert_si
.nPos
- y
;
1003 editor
->vert_si
.nPos
= y
;
1004 if (editor
->vert_si
.nMax
> 0xFFFF) /* scale to 16-bit value */
1005 y
= MulDiv(y
, 0xFFFF, editor
->vert_si
.nMax
);
1006 ITextHost_TxSetScrollPos(editor
->texthost
, SB_VERT
, y
, TRUE
);
1009 if (abs(scrollX
) > editor
->sizeWindow
.cx
||
1010 abs(scrollY
) > editor
->sizeWindow
.cy
)
1011 ITextHost_TxInvalidateRect(editor
->texthost
, NULL
, TRUE
);
1013 ITextHost_TxScrollWindowEx(editor
->texthost
, scrollX
, scrollY
,
1014 &editor
->rcFormat
, &editor
->rcFormat
,
1015 NULL
, NULL
, SW_INVALIDATE
);
1020 LONG winStyle
= GetWindowLongW(editor
->hWnd
, GWL_STYLE
);
1021 if (editor
->styleFlags
& WS_HSCROLL
)
1023 bScrollBarIsVisible
= (winStyle
& WS_HSCROLL
) != 0;
1024 bScrollBarWillBeVisible
= (editor
->nTotalWidth
> editor
->sizeWindow
.cx
1025 && (editor
->styleFlags
& WS_HSCROLL
))
1026 || (editor
->styleFlags
& ES_DISABLENOSCROLL
);
1027 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1028 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
,
1029 bScrollBarWillBeVisible
);
1032 if (editor
->styleFlags
& WS_VSCROLL
)
1034 bScrollBarIsVisible
= (winStyle
& WS_VSCROLL
) != 0;
1035 bScrollBarWillBeVisible
= (editor
->nTotalLength
> editor
->sizeWindow
.cy
1036 && (editor
->styleFlags
& WS_VSCROLL
)
1037 && (editor
->styleFlags
& ES_MULTILINE
))
1038 || (editor
->styleFlags
& ES_DISABLENOSCROLL
);
1039 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1040 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
1041 bScrollBarWillBeVisible
);
1044 ME_UpdateScrollBar(editor
);
1047 void ME_HScrollAbs(ME_TextEditor
*editor
, int x
)
1049 ME_ScrollAbs(editor
, x
, editor
->vert_si
.nPos
);
1052 void ME_VScrollAbs(ME_TextEditor
*editor
, int y
)
1054 ME_ScrollAbs(editor
, editor
->horz_si
.nPos
, y
);
1057 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
1059 ME_VScrollAbs(editor
, editor
->vert_si
.nPos
- cy
);
1062 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
1064 ME_VScrollAbs(editor
, editor
->vert_si
.nPos
+ cy
);
1067 void ME_ScrollLeft(ME_TextEditor
*editor
, int cx
)
1069 ME_HScrollAbs(editor
, editor
->horz_si
.nPos
- cx
);
1072 void ME_ScrollRight(ME_TextEditor
*editor
, int cx
)
1074 ME_HScrollAbs(editor
, editor
->horz_si
.nPos
+ cx
);
1077 /* Calculates the visibility after a call to SetScrollRange or
1078 * SetScrollInfo with SIF_RANGE. */
1079 static BOOL
ME_PostSetScrollRangeVisibility(SCROLLINFO
*si
)
1081 if (si
->fMask
& SIF_DISABLENOSCROLL
)
1084 /* This must match the check in SetScrollInfo to determine whether
1085 * to show or hide the scrollbars. */
1086 return si
->nMin
< si
->nMax
- max(si
->nPage
- 1, 0);
1089 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
1091 /* Note that this is the only function that should ever call
1092 * SetScrollInfo with SIF_PAGE or SIF_RANGE. */
1095 BOOL bScrollBarWasVisible
, bScrollBarWillBeVisible
;
1097 if (ME_WrapMarkedParagraphs(editor
))
1098 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1100 si
.cbSize
= sizeof(si
);
1101 si
.fMask
= SIF_PAGE
| SIF_RANGE
| SIF_POS
;
1103 if (editor
->styleFlags
& ES_DISABLENOSCROLL
)
1104 si
.fMask
|= SIF_DISABLENOSCROLL
;
1106 /* Update horizontal scrollbar */
1107 bScrollBarWasVisible
= editor
->horz_si
.nMax
> editor
->horz_si
.nPage
;
1108 bScrollBarWillBeVisible
= editor
->nTotalWidth
> editor
->sizeWindow
.cx
;
1109 if (editor
->horz_si
.nPos
&& !bScrollBarWillBeVisible
)
1111 ME_HScrollAbs(editor
, 0);
1112 /* ME_HScrollAbs will call this function,
1113 * so nothing else needs to be done here. */
1117 si
.nMax
= editor
->nTotalWidth
;
1118 si
.nPos
= editor
->horz_si
.nPos
;
1119 si
.nPage
= editor
->sizeWindow
.cx
;
1121 if (si
.nMax
!= editor
->horz_si
.nMax
||
1122 si
.nPage
!= editor
->horz_si
.nPage
)
1124 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1125 editor
->horz_si
.nMax
= si
.nMax
;
1126 editor
->horz_si
.nPage
= si
.nPage
;
1127 if ((bScrollBarWillBeVisible
|| bScrollBarWasVisible
) &&
1128 editor
->styleFlags
& WS_HSCROLL
)
1130 if (si
.nMax
> 0xFFFF)
1132 /* Native scales the scrollbar info to 16-bit external values. */
1133 si
.nPos
= MulDiv(si
.nPos
, 0xFFFF, si
.nMax
);
1137 SetScrollInfo(editor
->hWnd
, SB_HORZ
, &si
, TRUE
);
1139 ITextHost_TxSetScrollRange(editor
->texthost
, SB_HORZ
, si
.nMin
, si
.nMax
, FALSE
);
1140 ITextHost_TxSetScrollPos(editor
->texthost
, SB_HORZ
, si
.nPos
, TRUE
);
1142 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1143 bScrollBarWasVisible
= ME_PostSetScrollRangeVisibility(&si
);
1147 if (editor
->styleFlags
& WS_HSCROLL
)
1149 if (si
.fMask
& SIF_DISABLENOSCROLL
) {
1150 bScrollBarWillBeVisible
= TRUE
;
1151 } else if (!(editor
->styleFlags
& WS_HSCROLL
)) {
1152 bScrollBarWillBeVisible
= FALSE
;
1155 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1156 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
, bScrollBarWillBeVisible
);
1159 /* Update vertical scrollbar */
1160 bScrollBarWasVisible
= editor
->vert_si
.nMax
> editor
->vert_si
.nPage
;
1161 bScrollBarWillBeVisible
= editor
->nTotalLength
> editor
->sizeWindow
.cy
&&
1162 (editor
->styleFlags
& ES_MULTILINE
);
1164 if (editor
->vert_si
.nPos
&& !bScrollBarWillBeVisible
)
1166 ME_VScrollAbs(editor
, 0);
1167 /* ME_VScrollAbs will call this function,
1168 * so nothing else needs to be done here. */
1172 si
.nMax
= editor
->nTotalLength
;
1173 si
.nPos
= editor
->vert_si
.nPos
;
1174 si
.nPage
= editor
->sizeWindow
.cy
;
1176 if (si
.nMax
!= editor
->vert_si
.nMax
||
1177 si
.nPage
!= editor
->vert_si
.nPage
)
1179 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1180 editor
->vert_si
.nMax
= si
.nMax
;
1181 editor
->vert_si
.nPage
= si
.nPage
;
1182 if ((bScrollBarWillBeVisible
|| bScrollBarWasVisible
) &&
1183 editor
->styleFlags
& WS_VSCROLL
)
1185 if (si
.nMax
> 0xFFFF)
1187 /* Native scales the scrollbar info to 16-bit external values. */
1188 si
.nPos
= MulDiv(si
.nPos
, 0xFFFF, si
.nMax
);
1192 SetScrollInfo(editor
->hWnd
, SB_VERT
, &si
, TRUE
);
1194 ITextHost_TxSetScrollRange(editor
->texthost
, SB_VERT
, si
.nMin
, si
.nMax
, FALSE
);
1195 ITextHost_TxSetScrollPos(editor
->texthost
, SB_VERT
, si
.nPos
, TRUE
);
1197 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1198 bScrollBarWasVisible
= ME_PostSetScrollRangeVisibility(&si
);
1202 if (editor
->styleFlags
& WS_VSCROLL
)
1204 if (si
.fMask
& SIF_DISABLENOSCROLL
) {
1205 bScrollBarWillBeVisible
= TRUE
;
1206 } else if (!(editor
->styleFlags
& WS_VSCROLL
)) {
1207 bScrollBarWillBeVisible
= FALSE
;
1210 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1211 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
1212 bScrollBarWillBeVisible
);
1216 void ME_EnsureVisible(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1218 ME_Run
*pRun
= &pCursor
->pRun
->member
.run
;
1219 ME_DisplayItem
*pRow
= ME_FindItemBack(pCursor
->pRun
, diStartRow
);
1220 ME_DisplayItem
*pPara
= pCursor
->pPara
;
1226 if (editor
->styleFlags
& ES_AUTOHSCROLL
)
1228 x
= pRun
->pt
.x
+ ME_PointFromChar(editor
, pRun
, pCursor
->nOffset
);
1229 if (x
> editor
->horz_si
.nPos
+ editor
->sizeWindow
.cx
)
1230 x
= x
+ 1 - editor
->sizeWindow
.cx
;
1231 else if (x
> editor
->horz_si
.nPos
)
1232 x
= editor
->horz_si
.nPos
;
1234 if (~editor
->styleFlags
& ES_AUTOVSCROLL
)
1236 ME_HScrollAbs(editor
, x
);
1240 if (~editor
->styleFlags
& ES_AUTOVSCROLL
)
1242 x
= editor
->horz_si
.nPos
;
1245 y
= pPara
->member
.para
.pt
.y
+ pRow
->member
.row
.pt
.y
;
1246 yheight
= pRow
->member
.row
.nHeight
;
1248 if (y
< editor
->vert_si
.nPos
)
1249 ME_ScrollAbs(editor
, x
, y
);
1250 else if (y
+ yheight
> editor
->vert_si
.nPos
+ editor
->sizeWindow
.cy
)
1251 ME_ScrollAbs(editor
, x
, y
+ yheight
- editor
->sizeWindow
.cy
);
1252 else if (x
!= editor
->horz_si
.nPos
)
1253 ME_ScrollAbs(editor
, x
, editor
->vert_si
.nPos
);
1258 ME_InvalidateSelection(ME_TextEditor
*editor
)
1260 ME_DisplayItem
*sel_start
, *sel_end
;
1261 ME_DisplayItem
*repaint_start
= NULL
, *repaint_end
= NULL
;
1263 int len
= ME_GetTextLength(editor
);
1265 ME_GetSelectionOfs(editor
, &nStart
, &nEnd
);
1266 /* if both old and new selection are 0-char (= caret only), then
1267 there's no (inverted) area to be repainted, neither old nor new */
1268 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
1270 ME_WrapMarkedParagraphs(editor
);
1271 ME_GetSelectionParas(editor
, &sel_start
, &sel_end
);
1272 assert(sel_start
->type
== diParagraph
);
1273 assert(sel_end
->type
== diParagraph
);
1274 /* last selection markers aren't always updated, which means
1275 * they can point past the end of the document */
1276 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
) {
1277 repaint_start
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
1278 repaint_end
= editor
->pBuffer
->pLast
;
1279 ME_MarkForPainting(editor
, repaint_start
, repaint_end
);
1281 /* if the start part of selection is being expanded or contracted... */
1282 if (nStart
< editor
->nLastSelStart
) {
1283 repaint_start
= sel_start
;
1284 repaint_end
= editor
->pLastSelStartPara
->member
.para
.next_para
;
1285 } else if (nStart
> editor
->nLastSelStart
) {
1286 repaint_start
= editor
->pLastSelStartPara
;
1287 repaint_end
= sel_start
->member
.para
.next_para
;
1289 ME_MarkForPainting(editor
, repaint_start
, repaint_end
);
1291 /* if the end part of selection is being contracted or expanded... */
1292 if (nEnd
< editor
->nLastSelEnd
) {
1293 if (!repaint_start
) repaint_start
= sel_end
;
1294 repaint_end
= editor
->pLastSelEndPara
->member
.para
.next_para
;
1295 ME_MarkForPainting(editor
, sel_end
, repaint_end
);
1296 } else if (nEnd
> editor
->nLastSelEnd
) {
1297 if (!repaint_start
) repaint_start
= editor
->pLastSelEndPara
;
1298 repaint_end
= sel_end
->member
.para
.next_para
;
1299 ME_MarkForPainting(editor
, editor
->pLastSelEndPara
, repaint_end
);
1303 ME_InvalidateMarkedParagraphs(editor
, repaint_start
, repaint_end
);
1304 /* remember the last invalidated position */
1305 ME_GetSelectionOfs(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
1306 ME_GetSelectionParas(editor
, &editor
->pLastSelStartPara
, &editor
->pLastSelEndPara
);
1307 assert(editor
->pLastSelStartPara
->type
== diParagraph
);
1308 assert(editor
->pLastSelEndPara
->type
== diParagraph
);
1312 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
1314 /* TODO: Zoom images and objects */
1316 if (numerator
== 0 && denominator
== 0)
1318 editor
->nZoomNumerator
= editor
->nZoomDenominator
= 0;
1321 if (numerator
<= 0 || denominator
<= 0)
1323 if (numerator
* 64 <= denominator
|| numerator
/ denominator
>= 64)
1326 editor
->nZoomNumerator
= numerator
;
1327 editor
->nZoomDenominator
= denominator
;
1329 ME_RewrapRepaint(editor
);