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
);
44 ME_InitContext(&c
, editor
, hDC
);
45 SetBkMode(hDC
, TRANSPARENT
);
47 item
= editor
->pBuffer
->pFirst
->next
;
48 /* This context point is an offset for the paragraph positions stored
49 * during wrapping. It shouldn't be modified during painting. */
50 c
.pt
.x
= c
.rcView
.left
- editor
->horz_si
.nPos
;
51 c
.pt
.y
= c
.rcView
.top
- editor
->vert_si
.nPos
;
52 while(item
!= editor
->pBuffer
->pLast
)
54 assert(item
->type
== diParagraph
);
56 ys
= c
.pt
.y
+ item
->member
.para
.pt
.y
;
57 if (item
->member
.para
.pCell
58 != item
->member
.para
.next_para
->member
.para
.pCell
)
61 cell
= &ME_FindItemBack(item
->member
.para
.next_para
, diCell
)->member
.cell
;
62 ye
= c
.pt
.y
+ cell
->pt
.y
+ cell
->nHeight
;
64 ye
= ys
+ item
->member
.para
.nHeight
;
66 if (item
->member
.para
.pCell
&& !(item
->member
.para
.nFlags
& MEPF_ROWEND
) &&
67 item
->member
.para
.pCell
!= item
->member
.para
.prev_para
->member
.para
.pCell
)
69 /* the border shifts the text down */
70 ys
-= item
->member
.para
.pCell
->member
.cell
.yTextOffset
;
73 /* Draw the paragraph if any of the paragraph is in the update region. */
74 if (ys
< rcUpdate
->bottom
&& ye
> rcUpdate
->top
)
75 ME_DrawParagraph(&c
, item
);
76 item
= item
->member
.para
.next_para
;
78 if (c
.pt
.y
+ editor
->nTotalLength
< c
.rcView
.bottom
)
80 /* Fill space after the end of the text. */
82 rc
.top
= c
.pt
.y
+ editor
->nTotalLength
;
83 rc
.left
= c
.rcView
.left
;
84 rc
.bottom
= c
.rcView
.bottom
;
85 rc
.right
= c
.rcView
.right
;
87 IntersectRect(&rc
, &rc
, rcUpdate
);
89 if (!IsRectEmpty(&rc
))
90 FillRect(hDC
, &rc
, c
.editor
->hbrBackground
);
92 if (editor
->nTotalLength
!= editor
->nLastTotalLength
||
93 editor
->nTotalWidth
!= editor
->nLastTotalWidth
)
94 ME_SendRequestResize(editor
, FALSE
);
95 editor
->nLastTotalLength
= editor
->nTotalLength
;
96 editor
->nLastTotalWidth
= editor
->nTotalWidth
;
98 SelectClipRgn(hDC
, oldRgn
);
100 DeleteObject(oldRgn
);
103 ME_DestroyContext(&c
);
106 void ME_Repaint(ME_TextEditor
*editor
)
108 if (ME_WrapMarkedParagraphs(editor
))
110 ME_UpdateScrollBar(editor
);
111 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
113 ITextHost_TxViewChange(editor
->texthost
, TRUE
);
116 void ME_UpdateRepaint(ME_TextEditor
*editor
, BOOL update_now
)
118 /* Should be called whenever the contents of the control have changed */
119 BOOL wrappedParagraphs
;
121 wrappedParagraphs
= ME_WrapMarkedParagraphs(editor
);
122 if (wrappedParagraphs
)
123 ME_UpdateScrollBar(editor
);
125 /* Ensure that the cursor is visible */
126 ME_EnsureVisible(editor
, &editor
->pCursors
[0]);
128 ITextHost_TxViewChange(editor
->texthost
, update_now
);
130 ME_SendSelChange(editor
);
132 /* send EN_CHANGE if the event mask asks for it */
133 if(editor
->nEventMask
& ENM_CHANGE
)
135 editor
->nEventMask
&= ~ENM_CHANGE
;
136 ME_SendOldNotify(editor
, EN_CHANGE
);
137 editor
->nEventMask
|= ENM_CHANGE
;
142 ME_RewrapRepaint(ME_TextEditor
*editor
)
144 /* RewrapRepaint should be called whenever the control has changed in
145 * looks, but not content. Like resizing. */
147 ME_MarkAllForWrapping(editor
);
148 ME_WrapMarkedParagraphs(editor
);
149 ME_UpdateScrollBar(editor
);
153 int ME_twips2pointsX(const ME_Context
*c
, int x
)
155 if (c
->editor
->nZoomNumerator
== 0)
156 return x
* c
->dpi
.cx
/ 1440;
158 return x
* c
->dpi
.cx
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
161 int ME_twips2pointsY(const ME_Context
*c
, int y
)
163 if (c
->editor
->nZoomNumerator
== 0)
164 return y
* c
->dpi
.cy
/ 1440;
166 return y
* c
->dpi
.cy
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
170 static int calc_y_offset( const ME_Context
*c
, ME_Style
*style
)
172 int offs
= 0, twips
= 0;
174 if ((style
->fmt
.dwMask
& style
->fmt
.dwEffects
) & CFM_OFFSET
)
175 twips
= style
->fmt
.yOffset
;
177 if ((style
->fmt
.dwMask
& style
->fmt
.dwEffects
) & (CFM_SUPERSCRIPT
| CFM_SUBSCRIPT
))
179 if (style
->fmt
.dwEffects
& CFE_SUPERSCRIPT
) twips
= style
->fmt
.yHeight
/3;
180 if (style
->fmt
.dwEffects
& CFE_SUBSCRIPT
) twips
= -style
->fmt
.yHeight
/12;
183 if (twips
) offs
= ME_twips2pointsY( c
, twips
);
188 static COLORREF
get_text_color( ME_Context
*c
, ME_Style
*style
, BOOL highlight
)
193 color
= ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_HIGHLIGHTTEXT
);
194 else if ((style
->fmt
.dwMask
& CFM_LINK
) && (style
->fmt
.dwEffects
& CFE_LINK
))
195 color
= RGB(0,0,255);
196 else if ((style
->fmt
.dwMask
& CFM_COLOR
) && (style
->fmt
.dwEffects
& CFE_AUTOCOLOR
))
197 color
= ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_WINDOWTEXT
);
199 color
= style
->fmt
.crTextColor
;
204 static void get_underline_pen( ME_Style
*style
, COLORREF color
, HPEN
*pen
)
207 /* Choose the pen type for underlining the text. */
208 if (style
->fmt
.dwMask
& CFM_UNDERLINETYPE
)
210 switch (style
->fmt
.bUnderlineType
)
213 case CFU_UNDERLINEWORD
: /* native seems to map it to simple underline (MSDN) */
214 case CFU_UNDERLINEDOUBLE
: /* native seems to map it to simple underline (MSDN) */
215 *pen
= CreatePen( PS_SOLID
, 1, color
);
217 case CFU_UNDERLINEDOTTED
:
218 *pen
= CreatePen( PS_DOT
, 1, color
);
221 FIXME( "Unknown underline type (%u)\n", style
->fmt
.bUnderlineType
);
223 case CFU_CF1UNDERLINE
: /* this type is supported in the font, do nothing */
224 case CFU_UNDERLINENONE
:
231 static void draw_underline( ME_Context
*c
, ME_Run
*run
, int x
, int y
, COLORREF color
)
235 get_underline_pen( run
->style
, color
, &pen
);
238 HPEN old_pen
= SelectObject( c
->hDC
, pen
);
239 MoveToEx( c
->hDC
, x
, y
+ 1, NULL
);
240 LineTo( c
->hDC
, x
+ run
->nWidth
, y
+ 1 );
241 SelectObject( c
->hDC
, old_pen
);
247 /*********************************************************************
250 * Draw the end-of-paragraph or tab space.
252 * If actually_draw is TRUE then ensure any underline is drawn.
254 static void draw_space( ME_Context
*c
, ME_Run
*run
, int x
, int y
,
255 BOOL selected
, BOOL actually_draw
, int ymin
, int cy
)
258 BOOL old_style_selected
= FALSE
;
260 COLORREF back_color
= 0;
262 SetRect( &rect
, x
, ymin
, x
+ run
->nWidth
, ymin
+ cy
);
264 if (c
->editor
->bHideSelection
) selected
= FALSE
;
265 if (c
->editor
->bEmulateVersion10
)
267 old_style_selected
= selected
;
272 back_color
= ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_HIGHLIGHT
);
276 COLORREF text_color
= get_text_color( c
, run
->style
, selected
);
277 COLORREF old_text
, old_back
;
278 HFONT old_font
= NULL
;
279 int y_offset
= calc_y_offset( c
, run
->style
);
280 static const WCHAR space
[1] = {' '};
282 old_font
= ME_SelectStyleFont( c
, run
->style
);
283 old_text
= SetTextColor( hdc
, text_color
);
284 if (selected
) old_back
= SetBkColor( hdc
, back_color
);
286 ExtTextOutW( hdc
, x
, y
- y_offset
, selected
? ETO_OPAQUE
: 0, &rect
, space
, 1, &run
->nWidth
);
288 if (selected
) SetBkColor( hdc
, old_back
);
289 SetTextColor( hdc
, old_text
);
290 ME_UnselectStyleFont( c
, run
->style
, old_font
);
292 draw_underline( c
, run
, x
, y
- y_offset
, text_color
);
296 HBRUSH brush
= CreateSolidBrush( back_color
);
297 FillRect( hdc
, &rect
, brush
);
298 DeleteObject( brush
);
301 if (old_style_selected
)
302 PatBlt( hdc
, x
, ymin
, run
->nWidth
, cy
, DSTINVERT
);
305 static void get_selection_rect( ME_Context
*c
, ME_Run
*run
, int from
, int to
, int cy
, RECT
*r
)
307 from
= max( 0, from
);
308 to
= min( run
->len
, to
);
309 r
->left
= ME_PointFromCharContext( c
, run
, from
, TRUE
);
311 r
->right
= ME_PointFromCharContext( c
, run
, to
, TRUE
);
317 static void draw_text( ME_Context
*c
, ME_Run
*run
, int x
, int y
, BOOL selected
, RECT
*sel_rect
)
319 COLORREF text_color
= get_text_color( c
, run
->style
, selected
);
320 COLORREF back_color
= selected
? ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_HIGHLIGHT
) : 0;
321 COLORREF old_text
, old_back
= 0;
322 const WCHAR
*text
= get_text( run
, 0 );
323 ME_String
*masked
= NULL
;
325 if (c
->editor
->cPasswordMask
)
327 masked
= ME_MakeStringR( c
->editor
->cPasswordMask
, run
->len
);
328 text
= masked
->szData
;
331 old_text
= SetTextColor( c
->hDC
, text_color
);
332 if (selected
) old_back
= SetBkColor( c
->hDC
, back_color
);
334 ExtTextOutW( c
->hDC
, x
, y
, selected
? ETO_OPAQUE
: 0, sel_rect
, text
, run
->len
, NULL
);
336 if (selected
) SetBkColor( c
->hDC
, old_back
);
337 SetTextColor( c
->hDC
, old_text
);
339 draw_underline( c
, run
, x
, y
, text_color
);
341 ME_DestroyString( masked
);
346 static void ME_DrawTextWithStyle(ME_Context
*c
, ME_Run
*run
, int x
, int y
,
347 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
352 BOOL selected
= (nSelFrom
< run
->len
&& nSelTo
>= 0
353 && nSelFrom
< nSelTo
&& !c
->editor
->bHideSelection
);
354 BOOL old_style_selected
= FALSE
;
356 HRGN clip
= NULL
, sel_rgn
= NULL
;
358 yOffset
= calc_y_offset( c
, run
->style
);
362 get_selection_rect( c
, run
, nSelFrom
, nSelTo
, cy
, &sel_rect
);
363 OffsetRect( &sel_rect
, x
, ymin
);
365 if (c
->editor
->bEmulateVersion10
)
367 old_style_selected
= TRUE
;
372 sel_rgn
= CreateRectRgnIndirect( &sel_rect
);
373 clip
= CreateRectRgn( 0, 0, 0, 0 );
374 if (GetClipRgn( hDC
, clip
) != 1)
376 DeleteObject( clip
);
382 hOldFont
= ME_SelectStyleFont( c
, run
->style
);
384 if (sel_rgn
) ExtSelectClipRgn( hDC
, sel_rgn
, RGN_DIFF
);
385 draw_text( c
, run
, x
, y
- yOffset
, FALSE
, NULL
);
388 ExtSelectClipRgn( hDC
, clip
, RGN_COPY
);
389 ExtSelectClipRgn( hDC
, sel_rgn
, RGN_AND
);
390 draw_text( c
, run
, x
, y
- yOffset
, TRUE
, &sel_rect
);
391 ExtSelectClipRgn( hDC
, clip
, RGN_COPY
);
392 if (clip
) DeleteObject( clip
);
393 DeleteObject( sel_rgn
);
396 if (old_style_selected
)
397 PatBlt( hDC
, sel_rect
.left
, ymin
, sel_rect
.right
- sel_rect
.left
, cy
, DSTINVERT
);
399 ME_UnselectStyleFont(c
, run
->style
, hOldFont
);
402 static void ME_DebugWrite(HDC hDC
, const POINT
*pt
, LPCWSTR szText
) {
403 int align
= SetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
404 HGDIOBJ hFont
= SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
405 COLORREF color
= SetTextColor(hDC
, RGB(128,128,128));
406 TextOutW(hDC
, pt
->x
, pt
->y
, szText
, lstrlenW(szText
));
407 SelectObject(hDC
, hFont
);
408 SetTextAlign(hDC
, align
);
409 SetTextColor(hDC
, color
);
412 static void ME_DrawRun(ME_Context
*c
, int x
, int y
, ME_DisplayItem
*rundi
, ME_Paragraph
*para
)
414 ME_Run
*run
= &rundi
->member
.run
;
415 ME_DisplayItem
*start
;
416 int runofs
= run
->nCharOfs
+para
->nCharOfs
;
417 int nSelFrom
, nSelTo
;
419 if (run
->nFlags
& MERF_HIDDEN
)
422 start
= ME_FindItemBack(rundi
, diStartRow
);
423 ME_GetSelectionOfs(c
->editor
, &nSelFrom
, &nSelTo
);
425 /* Draw selected end-of-paragraph mark */
426 if (run
->nFlags
& MERF_ENDPARA
)
428 if (runofs
>= nSelFrom
&& runofs
< nSelTo
)
430 draw_space( c
, run
, x
, y
, TRUE
, FALSE
,
431 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
432 start
->member
.row
.nHeight
);
437 if (run
->nFlags
& (MERF_TAB
| MERF_ENDCELL
))
439 BOOL selected
= runofs
>= nSelFrom
&& runofs
< nSelTo
;
441 draw_space( c
, run
, x
, y
, selected
, TRUE
,
442 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
443 start
->member
.row
.nHeight
);
447 if (run
->nFlags
& MERF_GRAPHICS
)
448 ME_DrawOLE(c
, x
, y
, run
, para
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
));
451 ME_DrawTextWithStyle(c
, run
, x
, y
, nSelFrom
- runofs
, nSelTo
- runofs
,
452 c
->pt
.y
+ para
->pt
.y
+ start
->member
.row
.pt
.y
,
453 start
->member
.row
.nHeight
);
457 /* The documented widths are in points (72 dpi), but converting them to
458 * 96 dpi (standard display resolution) avoids dealing with fractions. */
459 static const struct {unsigned width
: 8, pen_style
: 4, dble
: 1;} border_details
[] = {
460 /* none */ {0, PS_SOLID
, FALSE
},
461 /* 3/4 */ {1, PS_SOLID
, FALSE
},
462 /* 1 1/2 */ {2, PS_SOLID
, FALSE
},
463 /* 2 1/4 */ {3, PS_SOLID
, FALSE
},
464 /* 3 */ {4, PS_SOLID
, FALSE
},
465 /* 4 1/2 */ {6, PS_SOLID
, FALSE
},
466 /* 6 */ {8, PS_SOLID
, FALSE
},
467 /* 3/4 double */ {1, PS_SOLID
, TRUE
},
468 /* 1 1/2 double */ {2, PS_SOLID
, TRUE
},
469 /* 2 1/4 double */ {3, PS_SOLID
, TRUE
},
470 /* 3/4 gray */ {1, PS_DOT
/* FIXME */, FALSE
},
471 /* 1 1/2 dashed */ {2, PS_DASH
, FALSE
},
474 static const COLORREF pen_colors
[16] = {
475 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
476 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
477 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
478 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
479 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
480 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
481 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
482 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
485 static int ME_GetBorderPenWidth(const ME_Context
* c
, int idx
)
487 int width
= border_details
[idx
].width
;
490 width
= MulDiv(width
, c
->dpi
.cx
, 96);
492 if (c
->editor
->nZoomNumerator
!= 0)
493 width
= MulDiv(width
, c
->editor
->nZoomNumerator
, c
->editor
->nZoomDenominator
);
498 int ME_GetParaBorderWidth(const ME_Context
* c
, int flags
)
500 int idx
= (flags
>> 8) & 0xF;
503 if (idx
>= sizeof(border_details
) / sizeof(border_details
[0]))
505 FIXME("Unsupported border value %d\n", idx
);
508 width
= ME_GetBorderPenWidth(c
, idx
);
509 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
513 static void ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
, RECT
* bounds
)
515 int idx
, border_width
, top_border
, bottom_border
;
519 SetRectEmpty(bounds
);
520 if (!(para
->pFmt
->dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return;
522 border_width
= top_border
= bottom_border
= 0;
523 idx
= (para
->pFmt
->wBorders
>> 8) & 0xF;
524 hasParaBorder
= (!(c
->editor
->bEmulateVersion10
&&
525 para
->pFmt
->dwMask
& PFM_TABLE
&&
526 para
->pFmt
->wEffects
& PFE_TABLE
) &&
527 (para
->pFmt
->dwMask
& PFM_BORDER
) &&
529 (para
->pFmt
->wBorders
& 0xF));
532 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
533 * controls. It actually stores the paragraph or row border style. Although
534 * the value isn't used for drawing, it is used for streaming out rich text.
536 * wBorders stores the border style for each side (top, left, bottom, right)
537 * using nibble (4 bits) to store each border style. The rich text format
538 * control words, and their associated value are the following:
548 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
549 * The mask corresponding to each side for the version are the following:
553 * 0x0F00 bottom right
554 * 0xF000 right bottom
556 if (para
->pFmt
->wBorders
& 0x00B0)
557 FIXME("Unsupported border flags %x\n", para
->pFmt
->wBorders
);
558 border_width
= ME_GetParaBorderWidth(c
, para
->pFmt
->wBorders
);
559 if (para
->pFmt
->wBorders
& 4) top_border
= border_width
;
560 if (para
->pFmt
->wBorders
& 8) bottom_border
= border_width
;
563 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
565 rc
.left
= c
->rcView
.left
;
566 rc
.right
= c
->rcView
.right
;
568 bounds
->top
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
569 rc
.bottom
= y
+ bounds
->top
+ top_border
;
570 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
573 if (para
->pFmt
->dwMask
& PFM_SPACEAFTER
)
575 rc
.left
= c
->rcView
.left
;
576 rc
.right
= c
->rcView
.right
;
577 rc
.bottom
= y
+ para
->nHeight
;
578 bounds
->bottom
= ME_twips2pointsY(c
, para
->pFmt
->dySpaceAfter
);
579 rc
.top
= rc
.bottom
- bounds
->bottom
- bottom_border
;
580 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
583 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
584 * but might support it in later versions. */
586 int pen_width
, rightEdge
;
588 HPEN pen
= NULL
, oldpen
= NULL
;
591 if (para
->pFmt
->wBorders
& 64) /* autocolor */
592 pencr
= ITextHost_TxGetSysColor(c
->editor
->texthost
,
595 pencr
= pen_colors
[(para
->pFmt
->wBorders
>> 12) & 0xF];
597 rightEdge
= c
->pt
.x
+ max(c
->editor
->sizeWindow
.cx
,
598 c
->editor
->nTotalWidth
);
600 pen_width
= ME_GetBorderPenWidth(c
, idx
);
601 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
602 oldpen
= SelectObject(c
->hDC
, pen
);
603 MoveToEx(c
->hDC
, 0, 0, &pt
);
605 /* before & after spaces are not included in border */
607 /* helper to draw the double lines in case of corner */
608 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
610 if (para
->pFmt
->wBorders
& 1)
612 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
613 LineTo(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
);
614 if (border_details
[idx
].dble
) {
615 rc
.left
= c
->pt
.x
+ 1;
616 rc
.right
= rc
.left
+ border_width
;
617 rc
.top
= y
+ bounds
->top
;
618 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
619 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
620 MoveToEx(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ bounds
->top
+ DD(4), NULL
);
621 LineTo(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
623 bounds
->left
+= border_width
;
625 if (para
->pFmt
->wBorders
& 2)
627 MoveToEx(c
->hDC
, rightEdge
- 1, y
+ bounds
->top
, NULL
);
628 LineTo(c
->hDC
, rightEdge
- 1, y
+ para
->nHeight
- bounds
->bottom
);
629 if (border_details
[idx
].dble
) {
630 rc
.left
= rightEdge
- pen_width
- 1;
631 rc
.right
= rc
.left
+ pen_width
;
632 rc
.top
= y
+ bounds
->top
;
633 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
634 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
635 MoveToEx(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ bounds
->top
+ DD(4), NULL
);
636 LineTo(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
638 bounds
->right
+= border_width
;
640 if (para
->pFmt
->wBorders
& 4)
642 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
643 LineTo(c
->hDC
, rightEdge
, y
+ bounds
->top
);
644 if (border_details
[idx
].dble
) {
645 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ bounds
->top
+ pen_width
+ 1, NULL
);
646 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ bounds
->top
+ pen_width
+ 1);
648 bounds
->top
+= border_width
;
650 if (para
->pFmt
->wBorders
& 8)
652 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
- 1, NULL
);
653 LineTo(c
->hDC
, rightEdge
, y
+ para
->nHeight
- bounds
->bottom
- 1);
654 if (border_details
[idx
].dble
) {
655 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1, NULL
);
656 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1);
658 bounds
->bottom
+= border_width
;
662 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
663 SelectObject(c
->hDC
, oldpen
);
668 static void ME_DrawTableBorders(ME_Context
*c
, ME_DisplayItem
*paragraph
)
670 ME_Paragraph
*para
= ¶graph
->member
.para
;
671 if (!c
->editor
->bEmulateVersion10
) /* v4.1 */
676 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
677 ME_DisplayItem
*paraAfterRow
;
684 BOOL atTop
= (para
->pCell
!= para
->prev_para
->member
.para
.pCell
);
685 BOOL atBottom
= (para
->pCell
!= para
->next_para
->member
.para
.pCell
);
686 int top
= c
->pt
.y
+ (atTop
? cell
->pt
.y
: para
->pt
.y
);
687 int bottom
= (atBottom
?
688 c
->pt
.y
+ cell
->pt
.y
+ cell
->nHeight
:
689 top
+ para
->nHeight
+ (atTop
? cell
->yTextOffset
: 0));
690 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
691 rc
.right
= rc
.left
+ cell
->nWidth
;
693 /* Erase gap before text if not all borders are the same height. */
694 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
695 rc
.top
= top
+ width
;
696 width
= cell
->yTextOffset
- width
;
697 rc
.bottom
= rc
.top
+ width
;
699 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
702 /* Draw cell borders.
703 * The order borders are draw in is left, top, bottom, right in order
704 * to be consistent with native richedit. This is noticeable from the
705 * overlap of borders of different colours. */
706 if (!(para
->nFlags
& MEPF_ROWEND
)) {
709 if (cell
->border
.left
.width
> 0)
711 color
= cell
->border
.left
.colorRef
;
712 width
= max(ME_twips2pointsX(c
, cell
->border
.left
.width
), 1);
714 color
= RGB(192,192,192);
717 logBrush
.lbStyle
= BS_SOLID
;
718 logBrush
.lbColor
= color
;
719 logBrush
.lbHatch
= 0;
720 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
721 width
, &logBrush
, 0, NULL
);
722 oldPen
= SelectObject(c
->hDC
, pen
);
723 MoveToEx(c
->hDC
, rc
.left
, rc
.top
, &oldPt
);
724 LineTo(c
->hDC
, rc
.left
, rc
.bottom
);
725 SelectObject(c
->hDC
, oldPen
);
727 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
731 if (cell
->border
.top
.width
> 0)
733 brush
= CreateSolidBrush(cell
->border
.top
.colorRef
);
734 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
736 brush
= GetStockObject(LTGRAY_BRUSH
);
740 rc
.bottom
= rc
.top
+ width
;
741 FillRect(c
->hDC
, &rc
, brush
);
742 if (cell
->border
.top
.width
> 0)
746 /* Draw the bottom border if at the last paragraph in the cell, and when
747 * in the last row of the table. */
749 int oldLeft
= rc
.left
;
750 width
= max(ME_twips2pointsY(c
, cell
->border
.bottom
.width
), 1);
751 paraAfterRow
= ME_GetTableRowEnd(paragraph
)->member
.para
.next_para
;
752 if (paraAfterRow
->member
.para
.nFlags
& MEPF_ROWSTART
) {
753 ME_DisplayItem
*nextEndCell
;
754 nextEndCell
= ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow
), diCell
);
755 assert(nextEndCell
&& !nextEndCell
->member
.cell
.next_cell
);
756 rc
.left
= c
->pt
.x
+ nextEndCell
->member
.cell
.pt
.x
;
757 /* FIXME: Native draws FROM the bottom of the table rather than
758 * TO the bottom of the table in this case, but just doing so here
759 * will cause the next row to erase the border. */
762 rc.bottom = rc.top + width;
765 if (rc
.left
< rc
.right
) {
766 if (cell
->border
.bottom
.width
> 0) {
767 brush
= CreateSolidBrush(cell
->border
.bottom
.colorRef
);
769 brush
= GetStockObject(LTGRAY_BRUSH
);
772 rc
.top
= rc
.bottom
- width
;
773 FillRect(c
->hDC
, &rc
, brush
);
774 if (cell
->border
.bottom
.width
> 0)
780 /* Right border only drawn if at the end of the table row. */
781 if (!cell
->next_cell
->member
.cell
.next_cell
&&
782 !(para
->nFlags
& MEPF_ROWSTART
))
786 if (cell
->border
.right
.width
> 0) {
787 color
= cell
->border
.right
.colorRef
;
788 width
= max(ME_twips2pointsX(c
, cell
->border
.right
.width
), 1);
790 color
= RGB(192,192,192);
793 logBrush
.lbStyle
= BS_SOLID
;
794 logBrush
.lbColor
= color
;
795 logBrush
.lbHatch
= 0;
796 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
797 width
, &logBrush
, 0, NULL
);
798 oldPen
= SelectObject(c
->hDC
, pen
);
799 MoveToEx(c
->hDC
, rc
.right
- 1, rc
.top
, &oldPt
);
800 LineTo(c
->hDC
, rc
.right
- 1, rc
.bottom
);
801 SelectObject(c
->hDC
, oldPen
);
803 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
806 } else { /* v1.0 - 3.0 */
807 /* Draw simple table border */
808 if (para
->pFmt
->dwMask
& PFM_TABLE
&& para
->pFmt
->wEffects
& PFE_TABLE
) {
809 HPEN pen
= NULL
, oldpen
= NULL
;
810 int i
, firstX
, startX
, endX
, rowY
, rowBottom
, nHeight
;
812 PARAFORMAT2
*pNextFmt
;
814 pen
= CreatePen(PS_SOLID
, 0, para
->border
.top
.colorRef
);
815 oldpen
= SelectObject(c
->hDC
, pen
);
817 /* Find the start relative to the text */
818 firstX
= c
->pt
.x
+ ME_FindItemFwd(paragraph
, diRun
)->member
.run
.pt
.x
;
819 /* Go back by the horizontal gap, which is stored in dxOffset */
820 firstX
-= ME_twips2pointsX(c
, para
->pFmt
->dxOffset
);
821 /* The left edge, stored in dxStartIndent affected just the first edge */
822 startX
= firstX
- ME_twips2pointsX(c
, para
->pFmt
->dxStartIndent
);
823 rowY
= c
->pt
.y
+ para
->pt
.y
;
824 if (para
->pFmt
->dwMask
& PFM_SPACEBEFORE
)
825 rowY
+= ME_twips2pointsY(c
, para
->pFmt
->dySpaceBefore
);
826 nHeight
= ME_FindItemFwd(paragraph
, diStartRow
)->member
.row
.nHeight
;
827 rowBottom
= rowY
+ nHeight
;
829 /* Draw horizontal lines */
830 MoveToEx(c
->hDC
, firstX
, rowY
, &oldPt
);
831 i
= para
->pFmt
->cTabCount
- 1;
832 endX
= startX
+ ME_twips2pointsX(c
, para
->pFmt
->rgxTabs
[i
] & 0x00ffffff) + 1;
833 LineTo(c
->hDC
, endX
, rowY
);
834 pNextFmt
= para
->next_para
->member
.para
.pFmt
;
835 /* The bottom of the row only needs to be drawn if the next row is
837 if (!(pNextFmt
&& pNextFmt
->dwMask
& PFM_TABLE
&& pNextFmt
->wEffects
&&
840 /* Decrement rowBottom to draw the bottom line within the row, and
841 * to not draw over this line when drawing the vertical lines. */
843 MoveToEx(c
->hDC
, firstX
, rowBottom
, NULL
);
844 LineTo(c
->hDC
, endX
, rowBottom
);
847 /* Draw vertical lines */
848 MoveToEx(c
->hDC
, firstX
, rowY
, NULL
);
849 LineTo(c
->hDC
, firstX
, rowBottom
);
850 for (i
= 0; i
< para
->pFmt
->cTabCount
; i
++)
852 int rightBoundary
= para
->pFmt
->rgxTabs
[i
] & 0x00ffffff;
853 endX
= startX
+ ME_twips2pointsX(c
, rightBoundary
);
854 MoveToEx(c
->hDC
, endX
, rowY
, NULL
);
855 LineTo(c
->hDC
, endX
, rowBottom
);
858 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
859 SelectObject(c
->hDC
, oldpen
);
865 static void ME_DrawParagraph(ME_Context
*c
, ME_DisplayItem
*paragraph
)
867 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
870 ME_Paragraph
*para
= NULL
;
873 int height
= 0, baseline
= 0, no
=0;
874 BOOL visible
= FALSE
;
877 rc
.right
= c
->rcView
.right
;
880 para
= ¶graph
->member
.para
;
881 y
= c
->pt
.y
+ para
->pt
.y
;
884 ME_Cell
*cell
= ¶
->pCell
->member
.cell
;
885 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
886 rc
.right
= rc
.left
+ cell
->nWidth
;
888 if (para
->nFlags
& MEPF_ROWSTART
) {
889 ME_Cell
*cell
= ¶
->next_para
->member
.para
.pCell
->member
.cell
;
890 rc
.right
= c
->pt
.x
+ cell
->pt
.x
;
891 } else if (para
->nFlags
& MEPF_ROWEND
) {
892 ME_Cell
*cell
= ¶
->prev_para
->member
.para
.pCell
->member
.cell
;
893 rc
.left
= c
->pt
.x
+ cell
->pt
.x
+ cell
->nWidth
;
895 ME_DrawParaDecoration(c
, para
, y
, &bounds
);
897 if (bounds
.left
|| bounds
.right
) {
898 rc
.left
= max(rc
.left
, c
->pt
.x
+ bounds
.left
);
899 rc
.right
= min(rc
.right
, c
->pt
.x
- bounds
.right
900 + max(c
->editor
->sizeWindow
.cx
,
901 c
->editor
->nTotalWidth
));
904 for (p
= paragraph
->next
; p
!= para
->next_para
; p
= p
->next
)
913 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
)) {
914 rc
.bottom
= y
+ para
->nHeight
;
916 rc
.bottom
= y
+ p
->member
.row
.nHeight
;
918 visible
= RectVisible(c
->hDC
, &rc
);
920 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
924 /* If scrolled to the right past the end of the text, then
925 * there may be space to the right of the paragraph border. */
926 RECT rcAfterBrdr
= rc
;
927 rcAfterBrdr
.left
= rc
.right
+ bounds
.right
;
928 rcAfterBrdr
.right
= c
->rcView
.right
;
929 if (RectVisible(c
->hDC
, &rcAfterBrdr
))
930 FillRect(c
->hDC
, &rcAfterBrdr
, c
->editor
->hbrBackground
);
934 const WCHAR wszRowDebug
[] = {'r','o','w','[','%','d',']',0};
937 wsprintfW(buf
, wszRowDebug
, no
);
939 ME_DebugWrite(c
->hDC
, &pt
, buf
);
942 height
= p
->member
.row
.nHeight
;
943 baseline
= p
->member
.row
.nBaseline
;
947 run
= &p
->member
.run
;
948 if (visible
&& me_debug
) {
950 rc
.left
= c
->pt
.x
+ run
->pt
.x
;
951 rc
.right
= rc
.left
+ run
->nWidth
;
952 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
953 rc
.bottom
= rc
.top
+ height
;
954 TRACE("rc = (%d, %d, %d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
955 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
958 ME_DrawRun(c
, c
->pt
.x
+ run
->pt
.x
,
959 c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
+ baseline
, p
, para
);
962 const WCHAR wszRunDebug
[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
965 pt
.x
= c
->pt
.x
+ run
->pt
.x
;
966 pt
.y
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
967 wsprintfW(buf
, wszRunDebug
, no
, p
->member
.run
.nFlags
, get_text( &p
->member
.run
, 0 ));
968 ME_DebugWrite(c
->hDC
, &pt
, buf
);
972 /* Clear any space at the bottom of the cell after the text. */
973 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
))
976 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ para
->nHeight
;
977 rc
.bottom
= c
->pt
.y
+ p
->member
.cell
.pt
.y
+ p
->member
.cell
.nHeight
;
978 if (RectVisible(c
->hDC
, &rc
))
980 FillRect(c
->hDC
, &rc
, c
->editor
->hbrBackground
);
989 ME_DrawTableBorders(c
, paragraph
);
991 SetTextAlign(c
->hDC
, align
);
994 void ME_ScrollAbs(ME_TextEditor
*editor
, int x
, int y
)
996 BOOL bScrollBarIsVisible
, bScrollBarWillBeVisible
;
997 int scrollX
= 0, scrollY
= 0;
999 if (editor
->horz_si
.nPos
!= x
) {
1000 x
= min(x
, editor
->horz_si
.nMax
);
1001 x
= max(x
, editor
->horz_si
.nMin
);
1002 scrollX
= editor
->horz_si
.nPos
- x
;
1003 editor
->horz_si
.nPos
= x
;
1004 if (editor
->horz_si
.nMax
> 0xFFFF) /* scale to 16-bit value */
1005 x
= MulDiv(x
, 0xFFFF, editor
->horz_si
.nMax
);
1006 ITextHost_TxSetScrollPos(editor
->texthost
, SB_HORZ
, x
, TRUE
);
1009 if (editor
->vert_si
.nPos
!= y
) {
1010 y
= min(y
, editor
->vert_si
.nMax
- (int)editor
->vert_si
.nPage
);
1011 y
= max(y
, editor
->vert_si
.nMin
);
1012 scrollY
= editor
->vert_si
.nPos
- y
;
1013 editor
->vert_si
.nPos
= y
;
1014 if (editor
->vert_si
.nMax
> 0xFFFF) /* scale to 16-bit value */
1015 y
= MulDiv(y
, 0xFFFF, editor
->vert_si
.nMax
);
1016 ITextHost_TxSetScrollPos(editor
->texthost
, SB_VERT
, y
, TRUE
);
1019 if (abs(scrollX
) > editor
->sizeWindow
.cx
||
1020 abs(scrollY
) > editor
->sizeWindow
.cy
)
1021 ITextHost_TxInvalidateRect(editor
->texthost
, NULL
, TRUE
);
1023 ITextHost_TxScrollWindowEx(editor
->texthost
, scrollX
, scrollY
,
1024 &editor
->rcFormat
, &editor
->rcFormat
,
1025 NULL
, NULL
, SW_INVALIDATE
);
1030 LONG winStyle
= GetWindowLongW(editor
->hWnd
, GWL_STYLE
);
1031 if (editor
->styleFlags
& WS_HSCROLL
)
1033 bScrollBarIsVisible
= (winStyle
& WS_HSCROLL
) != 0;
1034 bScrollBarWillBeVisible
= (editor
->nTotalWidth
> editor
->sizeWindow
.cx
1035 && (editor
->styleFlags
& WS_HSCROLL
))
1036 || (editor
->styleFlags
& ES_DISABLENOSCROLL
);
1037 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1038 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
,
1039 bScrollBarWillBeVisible
);
1042 if (editor
->styleFlags
& WS_VSCROLL
)
1044 bScrollBarIsVisible
= (winStyle
& WS_VSCROLL
) != 0;
1045 bScrollBarWillBeVisible
= (editor
->nTotalLength
> editor
->sizeWindow
.cy
1046 && (editor
->styleFlags
& WS_VSCROLL
)
1047 && (editor
->styleFlags
& ES_MULTILINE
))
1048 || (editor
->styleFlags
& ES_DISABLENOSCROLL
);
1049 if (bScrollBarIsVisible
!= bScrollBarWillBeVisible
)
1050 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
1051 bScrollBarWillBeVisible
);
1054 ME_UpdateScrollBar(editor
);
1057 void ME_HScrollAbs(ME_TextEditor
*editor
, int x
)
1059 ME_ScrollAbs(editor
, x
, editor
->vert_si
.nPos
);
1062 void ME_VScrollAbs(ME_TextEditor
*editor
, int y
)
1064 ME_ScrollAbs(editor
, editor
->horz_si
.nPos
, y
);
1067 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
1069 ME_VScrollAbs(editor
, editor
->vert_si
.nPos
- cy
);
1072 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
1074 ME_VScrollAbs(editor
, editor
->vert_si
.nPos
+ cy
);
1077 void ME_ScrollLeft(ME_TextEditor
*editor
, int cx
)
1079 ME_HScrollAbs(editor
, editor
->horz_si
.nPos
- cx
);
1082 void ME_ScrollRight(ME_TextEditor
*editor
, int cx
)
1084 ME_HScrollAbs(editor
, editor
->horz_si
.nPos
+ cx
);
1087 /* Calculates the visibility after a call to SetScrollRange or
1088 * SetScrollInfo with SIF_RANGE. */
1089 static BOOL
ME_PostSetScrollRangeVisibility(SCROLLINFO
*si
)
1091 if (si
->fMask
& SIF_DISABLENOSCROLL
)
1094 /* This must match the check in SetScrollInfo to determine whether
1095 * to show or hide the scrollbars. */
1096 return si
->nMin
< si
->nMax
- max(si
->nPage
- 1, 0);
1099 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
1101 /* Note that this is the only function that should ever call
1102 * SetScrollInfo with SIF_PAGE or SIF_RANGE. */
1105 BOOL bScrollBarWasVisible
, bScrollBarWillBeVisible
;
1107 if (ME_WrapMarkedParagraphs(editor
))
1108 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1110 si
.cbSize
= sizeof(si
);
1111 si
.fMask
= SIF_PAGE
| SIF_RANGE
| SIF_POS
;
1113 if (editor
->styleFlags
& ES_DISABLENOSCROLL
)
1114 si
.fMask
|= SIF_DISABLENOSCROLL
;
1116 /* Update horizontal scrollbar */
1117 bScrollBarWasVisible
= editor
->horz_si
.nMax
> editor
->horz_si
.nPage
;
1118 bScrollBarWillBeVisible
= editor
->nTotalWidth
> editor
->sizeWindow
.cx
;
1119 if (editor
->horz_si
.nPos
&& !bScrollBarWillBeVisible
)
1121 ME_HScrollAbs(editor
, 0);
1122 /* ME_HScrollAbs will call this function,
1123 * so nothing else needs to be done here. */
1127 si
.nMax
= editor
->nTotalWidth
;
1128 si
.nPos
= editor
->horz_si
.nPos
;
1129 si
.nPage
= editor
->sizeWindow
.cx
;
1131 if (si
.nMax
!= editor
->horz_si
.nMax
||
1132 si
.nPage
!= editor
->horz_si
.nPage
)
1134 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1135 editor
->horz_si
.nMax
= si
.nMax
;
1136 editor
->horz_si
.nPage
= si
.nPage
;
1137 if ((bScrollBarWillBeVisible
|| bScrollBarWasVisible
) &&
1138 editor
->styleFlags
& WS_HSCROLL
)
1140 if (si
.nMax
> 0xFFFF)
1142 /* Native scales the scrollbar info to 16-bit external values. */
1143 si
.nPos
= MulDiv(si
.nPos
, 0xFFFF, si
.nMax
);
1147 SetScrollInfo(editor
->hWnd
, SB_HORZ
, &si
, TRUE
);
1149 ITextHost_TxSetScrollRange(editor
->texthost
, SB_HORZ
, si
.nMin
, si
.nMax
, FALSE
);
1150 ITextHost_TxSetScrollPos(editor
->texthost
, SB_HORZ
, si
.nPos
, TRUE
);
1152 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1153 bScrollBarWasVisible
= ME_PostSetScrollRangeVisibility(&si
);
1157 if (editor
->styleFlags
& WS_HSCROLL
)
1159 if (si
.fMask
& SIF_DISABLENOSCROLL
) {
1160 bScrollBarWillBeVisible
= TRUE
;
1161 } else if (!(editor
->styleFlags
& WS_HSCROLL
)) {
1162 bScrollBarWillBeVisible
= FALSE
;
1165 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1166 ITextHost_TxShowScrollBar(editor
->texthost
, SB_HORZ
, bScrollBarWillBeVisible
);
1169 /* Update vertical scrollbar */
1170 bScrollBarWasVisible
= editor
->vert_si
.nMax
> editor
->vert_si
.nPage
;
1171 bScrollBarWillBeVisible
= editor
->nTotalLength
> editor
->sizeWindow
.cy
&&
1172 (editor
->styleFlags
& ES_MULTILINE
);
1174 if (editor
->vert_si
.nPos
&& !bScrollBarWillBeVisible
)
1176 ME_VScrollAbs(editor
, 0);
1177 /* ME_VScrollAbs will call this function,
1178 * so nothing else needs to be done here. */
1182 si
.nMax
= editor
->nTotalLength
;
1183 si
.nPos
= editor
->vert_si
.nPos
;
1184 si
.nPage
= editor
->sizeWindow
.cy
;
1186 if (si
.nMax
!= editor
->vert_si
.nMax
||
1187 si
.nPage
!= editor
->vert_si
.nPage
)
1189 TRACE("min=%d max=%d page=%d\n", si
.nMin
, si
.nMax
, si
.nPage
);
1190 editor
->vert_si
.nMax
= si
.nMax
;
1191 editor
->vert_si
.nPage
= si
.nPage
;
1192 if ((bScrollBarWillBeVisible
|| bScrollBarWasVisible
) &&
1193 editor
->styleFlags
& WS_VSCROLL
)
1195 if (si
.nMax
> 0xFFFF)
1197 /* Native scales the scrollbar info to 16-bit external values. */
1198 si
.nPos
= MulDiv(si
.nPos
, 0xFFFF, si
.nMax
);
1202 SetScrollInfo(editor
->hWnd
, SB_VERT
, &si
, TRUE
);
1204 ITextHost_TxSetScrollRange(editor
->texthost
, SB_VERT
, si
.nMin
, si
.nMax
, FALSE
);
1205 ITextHost_TxSetScrollPos(editor
->texthost
, SB_VERT
, si
.nPos
, TRUE
);
1207 /* SetScrollInfo or SetScrollRange change scrollbar visibility. */
1208 bScrollBarWasVisible
= ME_PostSetScrollRangeVisibility(&si
);
1212 if (editor
->styleFlags
& WS_VSCROLL
)
1214 if (si
.fMask
& SIF_DISABLENOSCROLL
) {
1215 bScrollBarWillBeVisible
= TRUE
;
1216 } else if (!(editor
->styleFlags
& WS_VSCROLL
)) {
1217 bScrollBarWillBeVisible
= FALSE
;
1220 if (bScrollBarWasVisible
!= bScrollBarWillBeVisible
)
1221 ITextHost_TxShowScrollBar(editor
->texthost
, SB_VERT
,
1222 bScrollBarWillBeVisible
);
1226 void ME_EnsureVisible(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1228 ME_Run
*pRun
= &pCursor
->pRun
->member
.run
;
1229 ME_DisplayItem
*pRow
= ME_FindItemBack(pCursor
->pRun
, diStartRow
);
1230 ME_DisplayItem
*pPara
= pCursor
->pPara
;
1236 if (editor
->styleFlags
& ES_AUTOHSCROLL
)
1238 x
= pRun
->pt
.x
+ ME_PointFromChar(editor
, pRun
, pCursor
->nOffset
, TRUE
);
1239 if (x
> editor
->horz_si
.nPos
+ editor
->sizeWindow
.cx
)
1240 x
= x
+ 1 - editor
->sizeWindow
.cx
;
1241 else if (x
> editor
->horz_si
.nPos
)
1242 x
= editor
->horz_si
.nPos
;
1244 if (~editor
->styleFlags
& ES_AUTOVSCROLL
)
1246 ME_HScrollAbs(editor
, x
);
1250 if (~editor
->styleFlags
& ES_AUTOVSCROLL
)
1252 x
= editor
->horz_si
.nPos
;
1255 y
= pPara
->member
.para
.pt
.y
+ pRow
->member
.row
.pt
.y
;
1256 yheight
= pRow
->member
.row
.nHeight
;
1258 if (y
< editor
->vert_si
.nPos
)
1259 ME_ScrollAbs(editor
, x
, y
);
1260 else if (y
+ yheight
> editor
->vert_si
.nPos
+ editor
->sizeWindow
.cy
)
1261 ME_ScrollAbs(editor
, x
, y
+ yheight
- editor
->sizeWindow
.cy
);
1262 else if (x
!= editor
->horz_si
.nPos
)
1263 ME_ScrollAbs(editor
, x
, editor
->vert_si
.nPos
);
1268 ME_InvalidateSelection(ME_TextEditor
*editor
)
1270 ME_DisplayItem
*sel_start
, *sel_end
;
1271 ME_DisplayItem
*repaint_start
= NULL
, *repaint_end
= NULL
;
1273 int len
= ME_GetTextLength(editor
);
1275 ME_GetSelectionOfs(editor
, &nStart
, &nEnd
);
1276 /* if both old and new selection are 0-char (= caret only), then
1277 there's no (inverted) area to be repainted, neither old nor new */
1278 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
1280 ME_WrapMarkedParagraphs(editor
);
1281 ME_GetSelectionParas(editor
, &sel_start
, &sel_end
);
1282 assert(sel_start
->type
== diParagraph
);
1283 assert(sel_end
->type
== diParagraph
);
1284 /* last selection markers aren't always updated, which means
1285 * they can point past the end of the document */
1286 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
) {
1287 repaint_start
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diParagraph
);
1288 repaint_end
= editor
->pBuffer
->pLast
->member
.para
.prev_para
;
1290 /* if the start part of selection is being expanded or contracted... */
1291 if (nStart
< editor
->nLastSelStart
) {
1292 repaint_start
= sel_start
;
1293 repaint_end
= editor
->pLastSelStartPara
;
1294 } else if (nStart
> editor
->nLastSelStart
) {
1295 repaint_start
= editor
->pLastSelStartPara
;
1296 repaint_end
= sel_start
;
1299 /* if the end part of selection is being contracted or expanded... */
1300 if (nEnd
< editor
->nLastSelEnd
) {
1301 if (!repaint_start
) repaint_start
= sel_end
;
1302 repaint_end
= editor
->pLastSelEndPara
;
1303 } else if (nEnd
> editor
->nLastSelEnd
) {
1304 if (!repaint_start
) repaint_start
= editor
->pLastSelEndPara
;
1305 repaint_end
= sel_end
;
1310 ME_InvalidateParagraphRange(editor
, repaint_start
, repaint_end
);
1311 /* remember the last invalidated position */
1312 ME_GetSelectionOfs(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
1313 ME_GetSelectionParas(editor
, &editor
->pLastSelStartPara
, &editor
->pLastSelEndPara
);
1314 assert(editor
->pLastSelStartPara
->type
== diParagraph
);
1315 assert(editor
->pLastSelEndPara
->type
== diParagraph
);
1319 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
1321 /* TODO: Zoom images and objects */
1323 if (numerator
== 0 && denominator
== 0)
1325 editor
->nZoomNumerator
= editor
->nZoomDenominator
= 0;
1328 if (numerator
<= 0 || denominator
<= 0)
1330 if (numerator
* 64 <= denominator
|| numerator
/ denominator
>= 64)
1333 editor
->nZoomNumerator
= numerator
;
1334 editor
->nZoomDenominator
= denominator
;
1336 ME_RewrapRepaint(editor
);