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
);
47 ME_MoveCaret(editor
); /* Calls ME_WrapMarkedParagraphs */
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 */
141 BOOL wrappedParagraphs
;
143 wrappedParagraphs
= ME_WrapMarkedParagraphs(editor
);
144 if (wrappedParagraphs
)
145 ME_UpdateScrollBar(editor
);
147 /* Ensure that the cursor is visible */
148 pCursor
= &editor
->pCursors
[0];
149 ME_EnsureVisible(editor
, pCursor
);
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
;
159 ME_SendSelChange(editor
);
163 ME_RewrapRepaint(ME_TextEditor
*editor
)
165 /* RewrapRepaint should be called whenever the control has changed in
166 * looks, but not content. Like resizing. */
168 ME_MarkAllForWrapping(editor
);
169 ME_WrapMarkedParagraphs(editor
);
170 ME_UpdateScrollBar(editor
);
174 int ME_twips2pointsX(ME_Context
*c
, int x
)
176 if (c
->editor
->nZoomNumerator
== 0)
177 return x
* c
->dpi
.cx
/ 1440;
179 return x
* c
->dpi
.cx
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
182 int ME_twips2pointsY(ME_Context
*c
, int y
)
184 if (c
->editor
->nZoomNumerator
== 0)
185 return y
* c
->dpi
.cy
/ 1440;
187 return y
* c
->dpi
.cy
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
190 static void ME_HighlightSpace(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
191 int nChars
, ME_Style
*s
, int width
,
192 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
195 HGDIOBJ hOldFont
= NULL
;
198 /* Only highlight if there is a selection in the run and when
199 * EM_HIDESELECTION is not being used to hide the selection. */
200 if (nSelFrom
>= nChars
|| nSelTo
< 0 || nSelFrom
>= nSelTo
201 || c
->editor
->bHideSelection
)
203 hOldFont
= ME_SelectStyleFont(c
, s
);
206 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
209 if (nSelFrom
< 0) nSelFrom
= 0;
210 if (nSelTo
> nChars
) nSelTo
= nChars
;
211 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
213 if (nSelTo
!= nChars
)
215 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
218 selWidth
= width
- sz
.cx
;
220 ME_UnselectStyleFont(c
, s
, hOldFont
);
222 if (c
->editor
->bEmulateVersion10
)
223 PatBlt(hDC
, x
, ymin
, selWidth
, cy
, DSTINVERT
);
230 rect
.right
= x
+ selWidth
;
231 rect
.bottom
= ymin
+ cy
;
232 hBrush
= CreateSolidBrush(ITextHost_TxGetSysColor(c
->editor
->texthost
,
234 FillRect(hDC
, &rect
, hBrush
);
235 DeleteObject(hBrush
);
239 static void ME_DrawTextWithStyle(ME_Context
*c
, int x
, int y
, LPCWSTR szText
,
240 int nChars
, ME_Style
*s
, int width
,
241 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
246 int yOffset
= 0, yTwipsOffset
= 0;
249 HPEN hPen
= NULL
, hOldPen
= NULL
;
250 BOOL bHighlightedText
= (nSelFrom
< nChars
&& nSelTo
>= 0
251 && nSelFrom
< nSelTo
&& !c
->editor
->bHideSelection
);
252 int xSelStart
= x
, xSelEnd
= x
;
254 /* lpDx is only needed for tabs to make sure the underline done automatically
255 * by the font extends to the end of the tab. Tabs are always stored as
256 * a single character run, so we can handle this case separately, since
257 * otherwise lpDx would need to specify the lengths of each character. */
258 if (width
&& nChars
== 1)
259 lpDx
= &width
; /* Make sure underline for tab extends across tab space */
261 hOldFont
= ME_SelectStyleFont(c
, s
);
262 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & CFM_OFFSET
) {
263 yTwipsOffset
= s
->fmt
.yOffset
;
265 if ((s
->fmt
.dwMask
& s
->fmt
.dwEffects
) & (CFM_SUPERSCRIPT
| CFM_SUBSCRIPT
)) {
266 if (s
->fmt
.dwEffects
& CFE_SUPERSCRIPT
) yTwipsOffset
= s
->fmt
.yHeight
/3;
267 if (s
->fmt
.dwEffects
& CFE_SUBSCRIPT
) yTwipsOffset
= -s
->fmt
.yHeight
/12;
270 yOffset
= ME_twips2pointsY(c
, yTwipsOffset
);
272 if ((s
->fmt
.dwMask
& CFM_LINK
) && (s
->fmt
.dwEffects
& CFE_LINK
))
274 else if ((s
->fmt
.dwMask
& CFM_COLOR
) && (s
->fmt
.dwEffects
& CFE_AUTOCOLOR
))
275 rgb
= ITextHost_TxGetSysColor(c
->editor
->texthost
, COLOR_WINDOWTEXT
);
277 rgb
= s
->fmt
.crTextColor
;
279 /* Determine the area that is selected in the run. */
280 GetTextExtentPoint32W(hDC
, szText
, nChars
, &sz
);
281 /* Treat width as an optional parameter. We can get the width from the
282 * text extent of the string if it isn't specified. */
283 if (!width
) width
= sz
.cx
;
284 if (bHighlightedText
)
292 GetTextExtentPoint32W(hDC
, szText
, nSelFrom
, &sz
);
293 xSelStart
= x
+ sz
.cx
;
295 if (nSelTo
>= nChars
)
302 GetTextExtentPoint32W(hDC
, szText
+nSelFrom
, nSelTo
-nSelFrom
, &sz
);
303 xSelEnd
= xSelStart
+ sz
.cx
;
307 /* Choose the pen type for underlining the text. */
308 if (s
->fmt
.dwMask
& CFM_UNDERLINETYPE
)
310 switch (s
->fmt
.bUnderlineType
)
313 case CFU_UNDERLINEWORD
: /* native seems to map it to simple underline (MSDN) */
314 case CFU_UNDERLINEDOUBLE
: /* native seems to map it to simple underline (MSDN) */
315 hPen
= CreatePen(PS_SOLID
, 1, rgb
);
317 case CFU_UNDERLINEDOTTED
:
318 hPen
= CreatePen(PS_DOT
, 1, rgb
);
321 WINE_FIXME("Unknown underline type (%u)\n", s
->fmt
.bUnderlineType
);
323 case CFU_CF1UNDERLINE
: /* this type is supported in the font, do nothing */
324 case CFU_UNDERLINENONE
:
330 hOldPen
= SelectObject(hDC
, hPen
);
334 rgbOld
= SetTextColor(hDC
, rgb
);
335 if (bHighlightedText
&& !c
->editor
->bEmulateVersion10
)
339 /* FIXME: should use textmetrics info for Descent info */
341 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
344 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nSelFrom
, NULL
);
346 LineTo(hDC
, xSelStart
, y
- yOffset
+ 1);
349 dim
.bottom
= ymin
+ cy
;
350 dim
.left
= xSelStart
;
352 SetTextColor(hDC
, ITextHost_TxGetSysColor(c
->editor
->texthost
,
353 COLOR_HIGHLIGHTTEXT
));
354 rgbBackOld
= SetBkColor(hDC
, ITextHost_TxGetSysColor(c
->editor
->texthost
,
356 ExtTextOutW(hDC
, xSelStart
, y
-yOffset
, ETO_OPAQUE
, &dim
,
357 szText
+nSelFrom
, nSelTo
-nSelFrom
, lpDx
);
359 LineTo(hDC
, xSelEnd
, y
- yOffset
+ 1);
360 SetBkColor(hDC
, rgbBackOld
);
361 if (xSelEnd
< x
+ width
)
363 SetTextColor(hDC
, rgb
);
364 ExtTextOutW(hDC
, xSelEnd
, y
-yOffset
, 0, NULL
, szText
+nSelTo
,
365 nChars
-nSelTo
, NULL
);
367 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
372 ExtTextOutW(hDC
, x
, y
-yOffset
, 0, NULL
, szText
, nChars
, lpDx
);
374 /* FIXME: should use textmetrics info for Descent info */
377 MoveToEx(hDC
, x
, y
- yOffset
+ 1, NULL
);
378 LineTo(hDC
, x
+ width
, y
- yOffset
+ 1);
381 if (bHighlightedText
) /* v1.0 inverts the selection */
383 PatBlt(hDC
, xSelStart
, ymin
, xSelEnd
-xSelStart
, cy
, DSTINVERT
);
389 SelectObject(hDC
, hOldPen
);
392 SetTextColor(hDC
, rgbOld
);
393 ME_UnselectStyleFont(c
, s
, hOldFont
);
396 static void ME_DebugWrite(HDC hDC
, const POINT
*pt
, LPCWSTR szText
) {
397 int align
= SetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
398 HGDIOBJ hFont
= SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
399 COLORREF color
= SetTextColor(hDC
, RGB(128,128,128));
400 TextOutW(hDC
, pt
->x
, pt
->y
, szText
, lstrlenW(szText
));
401 SelectObject(hDC
, hFont
);
402 SetTextAlign(hDC
, align
);
403 SetTextColor(hDC
, color
);
406 static void ME_DrawRun(ME_Context
*c
, int x
, int y
, ME_DisplayItem
*rundi
, ME_Paragraph
*para
)
408 ME_Run
*run
= &rundi
->member
.run
;
409 ME_DisplayItem
*start
;
410 int runofs
= run
->nCharOfs
+para
->nCharOfs
;
411 int nSelFrom
, nSelTo
;
412 const WCHAR wszSpace
[] = {' ', 0};
414 if (run
->nFlags
& MERF_HIDDEN
)
417 start
= ME_FindItemBack(rundi
, diStartRow
);
418 ME_GetSelection(c
->editor
, &nSelFrom
, &nSelTo
);
420 /* Draw selected end-of-paragraph mark */
421 if (run
->nFlags
& MERF_ENDPARA
)
423 if (runofs
>= nSelFrom
&& runofs
< nSelTo
)
425 ME_HighlightSpace(c
, x
, y
, wszSpace
, 1, run
->style
, 0, 0, 1,
426 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
427 start
->member
.row
.nHeight
);
432 if (run
->nFlags
& (MERF_TAB
| MERF_ENDCELL
))
434 /* wszSpace is used instead of the tab character because otherwise
435 * an unwanted symbol can be inserted instead. */
436 ME_DrawTextWithStyle(c
, x
, y
, wszSpace
, 1, run
->style
, run
->nWidth
,
437 nSelFrom
-runofs
, nSelTo
-runofs
,
438 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
439 start
->member
.row
.nHeight
);
443 if (run
->nFlags
& MERF_GRAPHICS
)
444 ME_DrawOLE(c
, x
, y
, run
, para
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
));
447 if (c
->editor
->cPasswordMask
)
449 ME_String
*szMasked
= ME_MakeStringR(c
->editor
->cPasswordMask
,ME_StrVLen(run
->strText
));
450 ME_DrawTextWithStyle(c
, x
, y
,
451 szMasked
->szData
, ME_StrVLen(szMasked
), run
->style
, run
->nWidth
,
452 nSelFrom
-runofs
,nSelTo
-runofs
,
453 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
454 start
->member
.row
.nHeight
);
455 ME_DestroyString(szMasked
);
458 ME_DrawTextWithStyle(c
, x
, y
,
459 run
->strText
->szData
, ME_StrVLen(run
->strText
), run
->style
, run
->nWidth
,
460 nSelFrom
-runofs
,nSelTo
-runofs
,
461 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
462 start
->member
.row
.nHeight
);
466 static const struct {unsigned width_num
: 4, width_den
: 4, pen_style
: 4, dble
: 1;} border_details
[] = {
467 /* none */ {0, 1, PS_SOLID
, FALSE
},
468 /* 3/4 */ {3, 4, PS_SOLID
, FALSE
},
469 /* 1 1/2 */ {3, 2, PS_SOLID
, FALSE
},
470 /* 2 1/4 */ {9, 4, PS_SOLID
, FALSE
},
471 /* 3 */ {3, 1, PS_SOLID
, FALSE
},
472 /* 4 1/2 */ {9, 2, PS_SOLID
, FALSE
},
473 /* 6 */ {6, 1, PS_SOLID
, FALSE
},
474 /* 3/4 double */ {3, 4, PS_SOLID
, TRUE
},
475 /* 1 1/2 double */ {3, 2, PS_SOLID
, TRUE
},
476 /* 2 1/4 double */ {9, 4, PS_SOLID
, TRUE
},
477 /* 3/4 gray */ {3, 4, PS_DOT
/* FIXME */, FALSE
},
478 /* 1 1/2 dashed */ {3, 2, PS_DASH
, FALSE
},
481 static const COLORREF pen_colors
[16] = {
482 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
483 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
484 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
485 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
486 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
487 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
488 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
489 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
492 static int ME_GetBorderPenWidth(ME_TextEditor
* editor
, int idx
)
496 if (editor
->nZoomNumerator
== 0)
498 width
= border_details
[idx
].width_num
+ border_details
[idx
].width_den
/ 2;
499 width
/= border_details
[idx
].width_den
;
503 width
= border_details
[idx
].width_num
* editor
->nZoomNumerator
;
504 width
+= border_details
[idx
].width_den
* editor
->nZoomNumerator
/ 2;
505 width
/= border_details
[idx
].width_den
* editor
->nZoomDenominator
;
510 int ME_GetParaBorderWidth(ME_TextEditor
* editor
, int flags
)
512 int idx
= (flags
>> 8) & 0xF;
515 if (idx
>= sizeof(border_details
) / sizeof(border_details
[0]))
517 FIXME("Unsupported border value %d\n", idx
);
520 width
= ME_GetBorderPenWidth(editor
, idx
);
521 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
525 int ME_GetParaLineSpace(ME_Context
* c
, ME_Paragraph
* para
)
528 if (!(para
->pFmt
->dwMask
& PFM_LINESPACING
)) return 0;
530 /* FIXME: how to compute simply the line space in ls ??? */
531 /* FIXME: does line spacing include the line itself ??? */
532 switch (para
->pFmt
->bLineSpacingRule
)
534 case 0: sp
= ls
; break;
535 case 1: sp
= (3 * ls
) / 2; break;
536 case 2: sp
= 2 * ls
; break;
537 case 3: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); if (sp
< ls
) sp
= ls
; break;
538 case 4: sp
= ME_twips2pointsY(c
, para
->pFmt
->dyLineSpacing
); break;
539 case 5: sp
= para
->pFmt
->dyLineSpacing
/ 20; break;
540 default: FIXME("Unsupported spacing rule value %d\n", para
->pFmt
->bLineSpacingRule
);
542 if (c
->editor
->nZoomNumerator
== 0)
545 return sp
* c
->editor
->nZoomNumerator
/ c
->editor
->nZoomDenominator
;
548 static void ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
, RECT
* bounds
)
550 int idx
, border_width
, top_border
, bottom_border
;
554 SetRectEmpty(bounds
);
555 if (!(para
->pFmt
->dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return;
557 border_width
= top_border
= bottom_border
= 0;
558 idx
= (para
->pFmt
->wBorders
>> 8) & 0xF;
559 hasParaBorder
= (!(c
->editor
->bEmulateVersion10
&&
560 para
->pFmt
->dwMask
& PFM_TABLE
&&
561 para
->pFmt
->wEffects
& PFE_TABLE
) &&
562 (para
->pFmt
->dwMask
& PFM_BORDER
) &&
564 (para
->pFmt
->wBorders
& 0xF));
567 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
568 * controls. It actually stores the paragraph or row border style. Although
569 * the value isn't used for drawing, it is used for streaming out rich text.
571 * wBorders stores the border style for each side (top, left, bottom, right)
572 * using nibble (4 bits) to store each border style. The rich text format
573 * control words, and their associated value are the following:
583 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
584 * The mask corresponding to each side for the version are the following:
588 * 0x0F00 bottom right
589 * 0xF000 right bottom
591 if (para
->pFmt
->wBorders
& 0x00B0)
592 FIXME("Unsupported border flags %x\n", para
->pFmt
->wBorders
);
593 border_width
= ME_GetParaBorderWidth(c
->editor
, para
->pFmt
->wBorders
);
594 if (para
->pFmt
->wBorders
& 4) top_border
= border_width
;
595 if (para
->pFmt
->wBorders
& 8) bottom_border
= border_width
;
598 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
600 rc
.left
= c
->rcView
.left
;
601 rc
.right
= c
->rcView
.right
;
603 bounds
->top
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
604 rc
.bottom
= y
+ bounds
->top
+ top_border
;
605 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
608 if (para
->pFmt
->dwMask
& PFM_SPACEAFTER
)
610 rc
.left
= c
->rcView
.left
;
611 rc
.right
= c
->rcView
.right
;
612 rc
.bottom
= y
+ para
->nHeight
;
613 bounds
->bottom
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceAfter
);
614 rc
.top
= rc
.bottom
- bounds
->bottom
- bottom_border
;
615 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
618 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
619 * but might support it in later versions. */
621 int pen_width
, rightEdge
;
623 HPEN pen
= NULL
, oldpen
= NULL
;
626 if (para
->pFmt
->wBorders
& 64) /* autocolor */
627 pencr
= ITextHost_TxGetSysColor(c
->editor
->texthost
,
630 pencr
= pen_colors
[(para
->pFmt
->wBorders
>> 12) & 0xF];
632 rightEdge
= c
->pt
.x
+ max(c
->editor
->sizeWindow
.cx
,
633 c
->editor
->nTotalWidth
);
635 pen_width
= ME_GetBorderPenWidth(c
->editor
, idx
);
636 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
637 oldpen
= SelectObject(c
->hDC
, pen
);
638 MoveToEx(c
->hDC
, 0, 0, &pt
);
640 /* before & after spaces are not included in border */
642 /* helper to draw the double lines in case of corner */
643 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
645 if (para
->pFmt
->wBorders
& 1)
647 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
648 LineTo(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
);
649 if (border_details
[idx
].dble
) {
650 rc
.left
= c
->pt
.x
+ 1;
651 rc
.right
= rc
.left
+ border_width
;
652 rc
.top
= y
+ bounds
->top
;
653 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
654 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
655 MoveToEx(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ bounds
->top
+ DD(4), NULL
);
656 LineTo(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
658 bounds
->left
+= border_width
;
660 if (para
->pFmt
->wBorders
& 2)
662 MoveToEx(c
->hDC
, rightEdge
- 1, y
+ bounds
->top
, NULL
);
663 LineTo(c
->hDC
, rightEdge
- 1, y
+ para
->nHeight
- bounds
->bottom
);
664 if (border_details
[idx
].dble
) {
665 rc
.left
= rightEdge
- pen_width
- 1;
666 rc
.right
= rc
.left
+ pen_width
;
667 rc
.top
= y
+ bounds
->top
;
668 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
669 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
670 MoveToEx(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ bounds
->top
+ DD(4), NULL
);
671 LineTo(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
673 bounds
->right
+= border_width
;
675 if (para
->pFmt
->wBorders
& 4)
677 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
678 LineTo(c
->hDC
, rightEdge
, y
+ bounds
->top
);
679 if (border_details
[idx
].dble
) {
680 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ bounds
->top
+ pen_width
+ 1, NULL
);
681 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ bounds
->top
+ pen_width
+ 1);
683 bounds
->top
+= border_width
;
685 if (para
->pFmt
->wBorders
& 8)
687 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
- 1, NULL
);
688 LineTo(c
->hDC
, rightEdge
, y
+ para
->nHeight
- bounds
->bottom
- 1);
689 if (border_details
[idx
].dble
) {
690 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1, NULL
);
691 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1);
693 bounds
->bottom
+= border_width
;
697 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
698 SelectObject(c
->hDC
, oldpen
);
703 static void ME_DrawTableBorders(ME_Context
*c
, ME_DisplayItem
*paragraph
)
705 ME_Paragraph
*para
= ¶graph
->member
.para
;
706 if (!c
->editor
->bEmulateVersion10
) /* v4.1 */
711 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
712 ME_DisplayItem
*paraAfterRow
;
719 BOOL atTop
= (para
->pCell
!= para
->prev_para
->member
.para
.pCell
);
720 BOOL atBottom
= (para
->pCell
!= para
->next_para
->member
.para
.pCell
);
721 int top
= c
->pt
.y
+ (atTop
? cell
->pt
.y
: para
->pt
.y
);
722 int bottom
= (atBottom
?
723 c
->pt
.y
+ cell
->pt
.y
+ cell
->nHeight
:
724 top
+ para
->nHeight
+ (atTop
? cell
->yTextOffset
: 0));
725 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
726 rc
.right
= rc
.left
+ cell
->nWidth
;
728 /* Erase gap before text if not all borders are the same height. */
729 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
730 rc
.top
= top
+ width
;
731 width
= cell
->yTextOffset
- width
;
732 rc
.bottom
= rc
.top
+ width
;
734 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
737 /* Draw cell borders.
738 * The order borders are draw in is left, top, bottom, right in order
739 * to be consistent with native richedit. This is noticeable from the
740 * overlap of borders of different colours. */
741 if (!(para
->nFlags
& MEPF_ROWEND
)) {
744 if (cell
->border
.left
.width
> 0)
746 color
= cell
->border
.left
.colorRef
;
747 width
= max(ME_twips2pointsX(c
, cell
->border
.left
.width
), 1);
749 color
= RGB(192,192,192);
752 logBrush
.lbStyle
= BS_SOLID
;
753 logBrush
.lbColor
= color
;
754 logBrush
.lbHatch
= 0;
755 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
756 width
, &logBrush
, 0, NULL
);
757 oldPen
= SelectObject(c
->hDC
, pen
);
758 MoveToEx(c
->hDC
, rc
.left
, rc
.top
, &oldPt
);
759 LineTo(c
->hDC
, rc
.left
, rc
.bottom
);
760 SelectObject(c
->hDC
, oldPen
);
762 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
766 if (cell
->border
.top
.width
> 0)
768 brush
= CreateSolidBrush(cell
->border
.top
.colorRef
);
769 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
771 brush
= GetStockObject(LTGRAY_BRUSH
);
775 rc
.bottom
= rc
.top
+ width
;
776 FillRect(c
->hDC
, &rc
, brush
);
777 if (cell
->border
.top
.width
> 0)
781 /* Draw the bottom border if at the last paragraph in the cell, and when
782 * in the last row of the table. */
784 int oldLeft
= rc
.left
;
785 width
= max(ME_twips2pointsY(c
, cell
->border
.bottom
.width
), 1);
786 paraAfterRow
= ME_GetTableRowEnd(paragraph
)->member
.para
.next_para
;
787 if (paraAfterRow
->member
.para
.nFlags
& MEPF_ROWSTART
) {
788 ME_DisplayItem
*nextEndCell
;
789 nextEndCell
= ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow
), diCell
);
790 assert(nextEndCell
&& !nextEndCell
->member
.cell
.next_cell
);
791 rc
.left
= c
->pt
.x
+ nextEndCell
->member
.cell
.pt
.x
;
792 /* FIXME: Native draws FROM the bottom of the table rather than
793 * TO the bottom of the table in this case, but just doing so here
794 * will cause the next row to erase the border. */
797 rc.bottom = rc.top + width;
800 if (rc
.left
< rc
.right
) {
801 if (cell
->border
.bottom
.width
> 0) {
802 brush
= CreateSolidBrush(cell
->border
.bottom
.colorRef
);
804 brush
= GetStockObject(LTGRAY_BRUSH
);
807 rc
.top
= rc
.bottom
- width
;
808 FillRect(c
->hDC
, &rc
, brush
);
809 if (cell
->border
.bottom
.width
> 0)
815 /* Right border only drawn if at the end of the table row. */
816 if (!cell
->next_cell
->member
.cell
.next_cell
&&
817 !(para
->nFlags
& MEPF_ROWSTART
))
821 if (cell
->border
.right
.width
> 0) {
822 color
= cell
->border
.right
.colorRef
;
823 width
= max(ME_twips2pointsX(c
, cell
->border
.right
.width
), 1);
825 color
= RGB(192,192,192);
828 logBrush
.lbStyle
= BS_SOLID
;
829 logBrush
.lbColor
= color
;
830 logBrush
.lbHatch
= 0;
831 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
832 width
, &logBrush
, 0, NULL
);
833 oldPen
= SelectObject(c
->hDC
, pen
);
834 MoveToEx(c
->hDC
, rc
.right
- 1, rc
.top
, &oldPt
);
835 LineTo(c
->hDC
, rc
.right
- 1, rc
.bottom
);
836 SelectObject(c
->hDC
, oldPen
);
838 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
841 } else { /* v1.0 - 3.0 */
842 /* Draw simple table border */
843 if (para
->pFmt
->dwMask
& PFM_TABLE
&& para
->pFmt
->wEffects
& PFE_TABLE
) {
844 HPEN pen
= NULL
, oldpen
= NULL
;
845 int i
, firstX
, startX
, endX
, rowY
, rowBottom
, nHeight
;
847 PARAFORMAT2
*pNextFmt
;
849 pen
= CreatePen(PS_SOLID
, 0, para
->border
.top
.colorRef
);
850 oldpen
= SelectObject(c
->hDC
, pen
);
852 /* Find the start relative to the text */
853 firstX
= c
->pt
.x
+ ME_FindItemFwd(paragraph
, diRun
)->member
.run
.pt
.x
;
854 /* Go back by the horizontal gap, which is stored in dxOffset */
855 firstX
-= ME_twips2pointsX(c
, para
->pFmt
->dxOffset
);
856 /* The left edge, stored in dxStartIndent affected just the first edge */
857 startX
= firstX
- ME_twips2pointsX(c
, para
->pFmt
->dxStartIndent
);
858 rowY
= c
->pt
.y
+ para
->pt
.y
;
859 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
860 rowY
+= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
861 nHeight
= ME_FindItemFwd(paragraph
, diStartRow
)->member
.row
.nHeight
;
862 rowBottom
= rowY
+ nHeight
;
864 /* Draw horizontal lines */
865 MoveToEx(c
->hDC
, firstX
, rowY
, &oldPt
);
866 i
= para
->pFmt
->cTabCount
- 1;
867 endX
= startX
+ ME_twips2pointsX(c
, para
->pFmt
->rgxTabs
[i
] & 0x00ffffff) + 1;
868 LineTo(c
->hDC
, endX
, rowY
);
869 pNextFmt
= para
->next_para
->member
.para
.pFmt
;
870 /* The bottom of the row only needs to be drawn if the next row is
872 if (!(pNextFmt
&& pNextFmt
->dwMask
& PFM_TABLE
&& pNextFmt
->wEffects
&&
875 /* Decrement rowBottom to draw the bottom line within the row, and
876 * to not draw over this line when drawing the vertical lines. */
878 MoveToEx(c
->hDC
, firstX
, rowBottom
, NULL
);
879 LineTo(c
->hDC
, endX
, rowBottom
);
882 /* Draw vertical lines */
883 MoveToEx(c
->hDC
, firstX
, rowY
, NULL
);
884 LineTo(c
->hDC
, firstX
, rowBottom
);
885 for (i
= 0; i
< para
->pFmt
->cTabCount
; i
++)
887 int rightBoundary
= para
->pFmt
->rgxTabs
[i
] & 0x00ffffff;
888 endX
= startX
+ ME_twips2pointsX(c
, rightBoundary
);
889 MoveToEx(c
->hDC
, endX
, rowY
, NULL
);
890 LineTo(c
->hDC
, endX
, rowBottom
);
893 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
894 SelectObject(c
->hDC
, oldpen
);
900 static void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
)
902 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
905 ME_Paragraph
*para
= NULL
;
908 int height
= 0, baseline
= 0, no
=0;
909 BOOL visible
= FALSE
;
912 rc
.right
= c
->rcView
.right
;
915 para
= ¶graph
->member
.para
;
916 y
= c
->pt
.y
+ para
->pt
.y
;
919 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
920 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
921 rc
.right
= rc
.left
+ cell
->nWidth
;
923 if (para
->nFlags
& MEPF_ROWSTART
) {
924 ME_Cell
*cell
= ¶
->next_para
->member
.para
.pCell
->member
.cell
;
925 rc
.right
= c
->pt
.x
+ cell
->pt
.x
;
926 } else if (para
->nFlags
& MEPF_ROWEND
) {
927 ME_Cell
*cell
= ¶
->prev_para
->member
.para
.pCell
->member
.cell
;
928 rc
.left
= c
->pt
.x
+ cell
->pt
.x
+ cell
->nWidth
;
930 ME_DrawParaDecoration(c
, para
, y
, &bounds
);
932 if (bounds
.left
|| bounds
.right
) {
933 rc
.left
= max(rc
.left
, c
->pt
.x
+ bounds
.left
);
934 rc
.right
= min(rc
.right
, c
->pt
.x
- bounds
.right
935 + max(c
->editor
->sizeWindow
.cx
,
936 c
->editor
->nTotalWidth
));
939 for (p
= paragraph
->next
; p
!= para
->next_para
; p
= p
->next
)
948 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
)) {
949 rc
.bottom
= y
+ para
->nHeight
;
951 rc
.bottom
= y
+ p
->member
.row
.nHeight
;
953 visible
= RectVisible(c
->hDC
, &rc
);
955 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
959 /* If scrolled to the right past the end of the text, then
960 * there may be space to the right of the paragraph border. */
961 RECT rcAfterBrdr
= rc
;
962 rcAfterBrdr
.left
= rc
.right
+ bounds
.right
;
963 rcAfterBrdr
.right
= c
->rcView
.right
;
964 if (RectVisible(c
->hDC
, &rcAfterBrdr
))
965 FillRect(c
->hDC
, &rcAfterBrdr
, c
->editor
->hbrBackground
);
969 const WCHAR wszRowDebug
[] = {'r','o','w','[','%','d',']',0};
972 wsprintfW(buf
, wszRowDebug
, no
);
974 ME_DebugWrite(c
->hDC
, &pt
, buf
);
977 height
= p
->member
.row
.nHeight
;
978 baseline
= p
->member
.row
.nBaseline
;
982 run
= &p
->member
.run
;
983 if (visible
&& me_debug
) {
985 rc
.left
= c
->pt
.x
+ run
->pt
.x
;
986 rc
.right
= rc
.left
+ run
->nWidth
;
987 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
988 rc
.bottom
= rc
.bottom
+ height
;
989 TRACE("rc = (%d, %d, %d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
990 if (run
->nFlags
& MERF_SKIPPED
)
991 DrawFocusRect(c
->hDC
, &rc
);
993 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
996 ME_DrawRun(c
, c
->pt
.x
+ run
->pt
.x
,
997 c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
+ baseline
, p
, para
);
1000 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
1001 const WCHAR wszRunDebug
[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
1004 pt
.x
= c
->pt
.x
+ run
->pt
.x
;
1005 pt
.y
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
1006 wsprintfW(buf
, wszRunDebug
, no
, p
->member
.run
.nFlags
, p
->member
.run
.strText
->szData
);
1007 ME_DebugWrite(c
->hDC
, &pt
, buf
);
1011 /* Clear any space at the bottom of the cell after the text. */
1012 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
))
1015 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ para
->nHeight
;
1016 rc
.bottom
= c
->pt
.y
+ p
->member
.cell
.pt
.y
+ p
->member
.cell
.nHeight
;
1017 if (RectVisible(c
->hDC
, &rc
))
1019 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
1028 ME_DrawTableBorders(c
, paragraph
);
1030 SetTextAlign(c
->hDC
, align
);
1033 void ME_ScrollAbs(ME_TextEditor
*editor
, int x
, int y
)
1035 BOOL bScrollBarIsVisible
, bScrollBarWillBeVisible
;
1036 int scrollX
= 0, scrollY
= 0;
1038 if (editor
->horz_si
.nPos
!= x
) {
1039 x
= min(x
, editor
->horz_si
.nMax
);
1040 x
= max(x
, editor
->horz_si
.nMin
);
1041 ITextHost_TxSetScrollPos(editor
->texthost
, SB_HORZ
, x
, TRUE
);
1042 scrollX
= editor
->horz_si
.nPos
- x
;
1043 editor
->horz_si
.nPos
= x
;
1046 if (editor
->vert_si
.nPos
!= y
) {
1047 y
= min(y
, editor
->vert_si
.nMax
- (int)editor
->vert_si
.nPage
);
1048 y
= max(y
, editor
->vert_si
.nMin
);
1049 ITextHost_TxSetScrollPos(editor
->texthost
, SB_VERT
, y
, TRUE
);
1050 scrollY
= editor
->vert_si
.nPos
- y
;
1051 editor
->vert_si
.nPos
= y
;
1054 if (abs(scrollX
) > editor
->sizeWindow
.cx
||
1055 abs(scrollY
) > editor
->sizeWindow
.cy
)
1056 ITextHost_TxInvalidateRect(editor
->texthost
, NULL
, TRUE
);
1058 ITextHost_TxScrollWindowEx(editor
->texthost
, scrollX
, scrollY
,
1059 &editor
->rcFormat
, &editor
->rcFormat
,
1060 NULL
, NULL
, SW_INVALIDATE
);
1065 LONG winStyle
= GetWindowLongW(editor
->hWnd
, GWL_STYLE
);
1066 bScrollBarIsVisible
= (winStyle
& WS_HSCROLL
) != 0;
1067 bScrollBarWillBeVisible
= (editor
->nTotalWidth
> editor
->sizeWindow
.cx
1068 && (editor
->styleFlags
& WS_HSCROLL
))
1069 || (editor
->styleFlags
& ES_DISABLENOSCROLL
);
1070 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1071 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
,
1072 bScrollBarWillBeVisible
);
1074 bScrollBarIsVisible
= (winStyle
& WS_VSCROLL
) != 0;
1075 bScrollBarWillBeVisible
= (editor
->nTotalLength
> editor
->sizeWindow
.cy
1076 && (editor
->styleFlags
& WS_VSCROLL
))
1077 || (editor
->styleFlags
& ES_DISABLENOSCROLL
);
1078 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1079 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
1080 bScrollBarWillBeVisible
);
1082 ME_UpdateScrollBar(editor
);
1085 void ME_HScrollAbs(ME_TextEditor
*editor
, int x
)
1087 ME_ScrollAbs(editor
, x
, editor
->vert_si
.nPos
);
1090 void ME_VScrollAbs(ME_TextEditor
*editor
, int y
)
1092 ME_ScrollAbs(editor
, editor
->horz_si
.nPos
, y
);
1095 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
1097 ME_VScrollAbs(editor
, editor
->vert_si
.nPos
- cy
);
1100 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
1102 ME_VScrollAbs(editor
, editor
->vert_si
.nPos
+ cy
);
1105 void ME_ScrollLeft(ME_TextEditor
*editor
, int cx
)
1107 ME_HScrollAbs(editor
, editor
->horz_si
.nPos
- cx
);
1110 void ME_ScrollRight(ME_TextEditor
*editor
, int cx
)
1112 ME_HScrollAbs(editor
, editor
->horz_si
.nPos
+ cx
);
1115 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
1117 /* Note that this is the only function that should ever call
1118 * SetScrollInfo with SIF_PAGE or SIF_RANGE. */
1121 BOOL bScrollBarWasVisible
, bScrollBarWillBeVisible
;
1123 if (ME_WrapMarkedParagraphs(editor
))
1124 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1126 si
.cbSize
= sizeof(si
);
1127 si
.fMask
= SIF_PAGE
| SIF_RANGE
| SIF_POS
;
1128 if (editor
->styleFlags
& ES_DISABLENOSCROLL
)
1129 si
.fMask
|= SIF_DISABLENOSCROLL
;
1131 /* Update horizontal scrollbar */
1132 bScrollBarWasVisible
= editor
->horz_si
.nMax
> editor
->horz_si
.nPage
;
1133 bScrollBarWillBeVisible
= editor
->nTotalWidth
> editor
->sizeWindow
.cx
;
1134 if (editor
->horz_si
.nPos
&& !bScrollBarWillBeVisible
)
1136 ME_HScrollAbs(editor
, 0);
1137 /* ME_HScrollAbs will call this function,
1138 * so nothing else needs to be done here. */
1143 si
.nMax
= editor
->nTotalWidth
;
1144 si
.nPos
= editor
->horz_si
.nPos
;
1145 si
.nPage
= editor
->sizeWindow
.cx
;
1147 if (si
.nMin
!= editor
->horz_si
.nMin
||
1148 si
.nMax
!= editor
->horz_si
.nMax
||
1149 si
.nPage
!= editor
->horz_si
.nPage
)
1151 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1152 editor
->horz_si
.nMin
= si
.nMin
;
1153 editor
->horz_si
.nMax
= si
.nMax
;
1154 editor
->horz_si
.nPage
= si
.nPage
;
1155 if (bScrollBarWillBeVisible
|| bScrollBarWasVisible
) {
1157 SetScrollInfo(editor
->hWnd
, SB_HORZ
, &si
, TRUE
);
1159 ITextHost_TxSetScrollRange(editor
->texthost
, SB_HORZ
, si
.nMin
, si
.nMax
, FALSE
);
1160 ITextHost_TxSetScrollPos(editor
->texthost
, SB_HORZ
, si
.nPos
, TRUE
);
1165 if (si
.fMask
& SIF_DISABLENOSCROLL
) {
1166 bScrollBarWillBeVisible
= TRUE
;
1167 } else if (!(editor
->styleFlags
& WS_HSCROLL
)) {
1168 /* SetScrollInfo or SetScrollRange may cause the scrollbar to be
1169 * shown, so hide the scrollbar if necessary. */
1170 bScrollBarWasVisible
= bScrollBarWillBeVisible
;
1171 bScrollBarWillBeVisible
= FALSE
;
1174 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1175 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
, bScrollBarWillBeVisible
);
1177 /* Update vertical scrollbar */
1178 bScrollBarWasVisible
= editor
->vert_si
.nMax
> editor
->vert_si
.nPage
;
1179 bScrollBarWillBeVisible
= editor
->nTotalLength
> editor
->sizeWindow
.cy
;
1181 if (editor
->vert_si
.nPos
&& !bScrollBarWillBeVisible
)
1183 ME_VScrollAbs(editor
, 0);
1184 /* ME_VScrollAbs will call this function,
1185 * so nothing else needs to be done here. */
1189 si
.nMax
= editor
->nTotalLength
;
1190 si
.nPos
= editor
->vert_si
.nPos
;
1191 si
.nPage
= editor
->sizeWindow
.cy
;
1193 if (si
.nMin
!= editor
->vert_si
.nMin
||
1194 si
.nMax
!= editor
->vert_si
.nMax
||
1195 si
.nPage
!= editor
->vert_si
.nPage
)
1197 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1198 editor
->vert_si
.nMin
= si
.nMin
;
1199 editor
->vert_si
.nMax
= si
.nMax
;
1200 editor
->vert_si
.nPage
= si
.nPage
;
1201 if (bScrollBarWillBeVisible
|| bScrollBarWasVisible
) {
1203 SetScrollInfo(editor
->hWnd
, SB_VERT
, &si
, TRUE
);
1205 ITextHost_TxSetScrollRange(editor
->texthost
, SB_VERT
, si
.nMin
, si
.nMax
, FALSE
);
1206 ITextHost_TxSetScrollPos(editor
->texthost
, SB_VERT
, si
.nPos
, TRUE
);
1211 if (si
.fMask
& SIF_DISABLENOSCROLL
) {
1212 bScrollBarWillBeVisible
= TRUE
;
1213 } else if (!(editor
->styleFlags
& WS_VSCROLL
)) {
1214 /* SetScrollInfo or SetScrollRange may cause the scrollbar to be
1215 * shown, so hide the scrollbar if necessary. */
1216 bScrollBarWasVisible
= bScrollBarWillBeVisible
;
1217 bScrollBarWillBeVisible
= FALSE
;
1220 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1221 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
1222 bScrollBarWillBeVisible
);
1225 void ME_EnsureVisible(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1227 ME_Run
*pRun
= &pCursor
->pRun
->member
.run
;
1228 ME_DisplayItem
*pRow
= ME_FindItemBack(pCursor
->pRun
, diStartRow
);
1229 ME_DisplayItem
*pPara
= ME_FindItemBack(pCursor
->pRun
, diParagraph
);
1235 x
= pRun
->pt
.x
+ ME_PointFromChar(editor
, pRun
, pCursor
->nOffset
);
1236 if (x
> editor
->horz_si
.nPos
+ editor
->sizeWindow
.cx
)
1237 x
= x
+ 1 - editor
->sizeWindow
.cx
;
1238 else if (x
> editor
->horz_si
.nPos
)
1239 x
= editor
->horz_si
.nPos
;
1241 y
= pPara
->member
.para
.pt
.y
+ pRow
->member
.row
.pt
.y
;
1242 yheight
= pRow
->member
.row
.nHeight
;
1244 if (y
< editor
->vert_si
.nPos
)
1245 ME_ScrollAbs(editor
, x
, y
);
1246 else if (y
+ yheight
> editor
->vert_si
.nPos
+ editor
->sizeWindow
.cy
)
1247 ME_ScrollAbs(editor
, x
, y
+ yheight
- editor
->sizeWindow
.cy
);
1248 else if (x
!= editor
->horz_si
.nPos
)
1249 ME_ScrollAbs(editor
, x
, editor
->vert_si
.nPos
);
1254 ME_InvalidateSelection(ME_TextEditor
*editor
)
1256 ME_DisplayItem
*para1
, *para2
;
1258 int len
= ME_GetTextLength(editor
);
1260 ME_GetSelection(editor
, &nStart
, &nEnd
);
1261 /* if both old and new selection are 0-char (= caret only), then
1262 there's no (inverted) area to be repainted, neither old nor new */
1263 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
1265 ME_WrapMarkedParagraphs(editor
);
1266 ME_GetSelectionParas(editor
, ¶1
, ¶2
);
1267 assert(para1
->type
== diParagraph
);
1268 assert(para2
->type
== diParagraph
);
1269 /* last selection markers aren't always updated, which means
1270 they can point past the end of the document */
1271 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
) {
1272 ME_MarkForPainting(editor
,
1273 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
),
1274 ME_FindItemFwd(editor
->pBuffer
->pFirst
, diTextEnd
));
1276 /* if the start part of selection is being expanded or contracted... */
1277 if (nStart
< editor
->nLastSelStart
) {
1278 ME_MarkForPainting(editor
, para1
, ME_FindItemFwd(editor
->pLastSelStartPara
, diParagraphOrEnd
));
1280 if (nStart
> editor
->nLastSelStart
) {
1281 ME_MarkForPainting(editor
, editor
->pLastSelStartPara
, ME_FindItemFwd(para1
, diParagraphOrEnd
));
1284 /* if the end part of selection is being contracted or expanded... */
1285 if (nEnd
< editor
->nLastSelEnd
) {
1286 ME_MarkForPainting(editor
, para2
, ME_FindItemFwd(editor
->pLastSelEndPara
, diParagraphOrEnd
));
1288 if (nEnd
> editor
->nLastSelEnd
) {
1289 ME_MarkForPainting(editor
, editor
->pLastSelEndPara
, ME_FindItemFwd(para2
, diParagraphOrEnd
));
1293 ME_InvalidateMarkedParagraphs(editor
);
1294 /* remember the last invalidated position */
1295 ME_GetSelection(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
1296 ME_GetSelectionParas(editor
, &editor
->pLastSelStartPara
, &editor
->pLastSelEndPara
);
1297 assert(editor
->pLastSelStartPara
->type
== diParagraph
);
1298 assert(editor
->pLastSelEndPara
->type
== diParagraph
);
1302 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
1304 /* TODO: Zoom images and objects */
1306 if (numerator
== 0 && denominator
== 0)
1308 editor
->nZoomNumerator
= editor
->nZoomDenominator
= 0;
1311 if (numerator
<= 0 || denominator
<= 0)
1313 if (numerator
* 64 <= denominator
|| numerator
/ denominator
>= 64)
1316 editor
->nZoomNumerator
= numerator
;
1317 editor
->nZoomDenominator
= denominator
;
1319 ME_RewrapRepaint(editor
);