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 draw_paragraph( ME_Context
*c
, ME_Paragraph
*para
);
28 static inline BOOL
editor_opaque( ME_TextEditor
*editor
)
30 return editor
->back_style
!= TXTBACK_TRANSPARENT
;
33 void editor_draw( ME_TextEditor
*editor
, HDC hDC
, const RECT
*update
)
41 HBRUSH brush
= CreateSolidBrush( ITextHost_TxGetSysColor( editor
->texthost
, COLOR_WINDOW
) );
43 ME_InitContext( &c
, editor
, hDC
);
47 client
.left
-= editor
->selofs
;
51 oldRgn
= CreateRectRgn(0, 0, 0, 0);
52 if (!GetClipRgn(hDC
, oldRgn
))
57 IntersectClipRect( hDC
, update
->left
, update
->top
, update
->right
, update
->bottom
);
59 brush
= SelectObject( hDC
, brush
);
60 SetBkMode(hDC
, TRANSPARENT
);
62 para
= editor_first_para( editor
);
63 /* This context point is an offset for the paragraph positions stored
64 * during wrapping. It shouldn't be modified during painting. */
65 c
.pt
.x
= c
.rcView
.left
- editor
->horz_si
.nPos
;
66 c
.pt
.y
= c
.rcView
.top
- editor
->vert_si
.nPos
;
67 while (para_next( para
))
69 ys
= c
.pt
.y
+ para
->pt
.y
;
70 cell
= para_cell( para
);
71 if (cell
&& para
== cell_end_para( cell
))
72 ye
= c
.pt
.y
+ cell
->pt
.y
+ cell
->nHeight
;
73 else ye
= ys
+ para
->nHeight
;
75 if (cell
&& !(para
->nFlags
& MEPF_ROWEND
) && para
== cell_first_para( cell
))
77 /* the border shifts the text down */
78 ys
-= para_cell( para
)->yTextOffset
;
81 /* Draw the paragraph if any of the paragraph is in the update region. */
82 if (ys
< update
->bottom
&& ye
> update
->top
)
83 draw_paragraph( &c
, para
);
84 para
= para_next( para
);
86 if (editor_opaque( editor
))
88 if (c
.pt
.y
+ editor
->nTotalLength
< c
.rcView
.bottom
)
89 { /* space after the end of the text */
90 rc
.top
= c
.pt
.y
+ editor
->nTotalLength
;
91 rc
.left
= c
.rcView
.left
;
92 rc
.bottom
= c
.rcView
.bottom
;
93 rc
.right
= c
.rcView
.right
;
94 if (IntersectRect( &rc
, &rc
, update
))
95 PatBlt(hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
99 rc
.left
= c
.rcView
.left
- editor
->selofs
;
100 rc
.top
= c
.rcView
.top
;
101 rc
.right
= c
.rcView
.left
;
102 rc
.bottom
= c
.rcView
.bottom
;
103 if (IntersectRect( &rc
, &rc
, update
))
104 PatBlt( hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
108 DeleteObject( SelectObject( hDC
, brush
) );
109 SelectClipRgn( hDC
, oldRgn
);
110 if (oldRgn
) DeleteObject( oldRgn
);
111 ME_DestroyContext( &c
);
113 if (editor
->nTotalLength
!= editor
->nLastTotalLength
|| editor
->nTotalWidth
!= editor
->nLastTotalWidth
)
114 ME_SendRequestResize(editor
, FALSE
);
115 editor
->nLastTotalLength
= editor
->nTotalLength
;
116 editor
->nLastTotalWidth
= editor
->nTotalWidth
;
119 void ME_Repaint(ME_TextEditor
*editor
)
121 if (ME_WrapMarkedParagraphs(editor
))
123 ME_UpdateScrollBar(editor
);
124 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
126 ITextHost_TxViewChange(editor
->texthost
, TRUE
);
129 void ME_UpdateRepaint(ME_TextEditor
*editor
, BOOL update_now
)
131 /* Should be called whenever the contents of the control have changed */
132 BOOL wrappedParagraphs
;
134 wrappedParagraphs
= ME_WrapMarkedParagraphs(editor
);
135 if (wrappedParagraphs
)
136 ME_UpdateScrollBar(editor
);
138 /* Ensure that the cursor is visible */
139 editor_ensure_visible( editor
, &editor
->pCursors
[0] );
141 update_caret( editor
);
143 if (!editor
->bEmulateVersion10
|| (editor
->nEventMask
& ENM_UPDATE
))
144 ITextHost_TxNotify( editor
->texthost
, EN_UPDATE
, NULL
);
146 ITextHost_TxViewChange(editor
->texthost
, update_now
);
148 ME_SendSelChange(editor
);
150 if(editor
->nEventMask
& ENM_CHANGE
)
152 editor
->nEventMask
&= ~ENM_CHANGE
;
153 ITextHost_TxNotify( editor
->texthost
, EN_CHANGE
, NULL
);
154 editor
->nEventMask
|= ENM_CHANGE
;
159 ME_RewrapRepaint(ME_TextEditor
*editor
)
161 /* RewrapRepaint should be called whenever the control has changed in
162 * looks, but not content. Like resizing. */
164 editor_mark_rewrap_all( editor
);
165 ME_WrapMarkedParagraphs(editor
);
166 ME_UpdateScrollBar(editor
);
170 int ME_twips2pointsX(const ME_Context
*c
, int x
)
172 if (c
->editor
->nZoomNumerator
== 0)
173 return x
* c
->dpi
.cx
/ 1440;
175 return x
* c
->dpi
.cx
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
178 int ME_twips2pointsY(const ME_Context
*c
, int y
)
180 if (c
->editor
->nZoomNumerator
== 0)
181 return y
* c
->dpi
.cy
/ 1440;
183 return y
* c
->dpi
.cy
* c
->editor
->nZoomNumerator
/ 1440 / c
->editor
->nZoomDenominator
;
187 static int calc_y_offset( const ME_Context
*c
, ME_Style
*style
)
189 int offs
= 0, twips
= 0;
191 if ((style
->fmt
.dwMask
& style
->fmt
.dwEffects
) & CFM_OFFSET
)
192 twips
= style
->fmt
.yOffset
;
194 if ((style
->fmt
.dwMask
& style
->fmt
.dwEffects
) & (CFM_SUPERSCRIPT
| CFM_SUBSCRIPT
))
196 if (style
->fmt
.dwEffects
& CFE_SUPERSCRIPT
) twips
= style
->fmt
.yHeight
/3;
197 if (style
->fmt
.dwEffects
& CFE_SUBSCRIPT
) twips
= -style
->fmt
.yHeight
/12;
200 if (twips
) offs
= ME_twips2pointsY( c
, twips
);
205 static COLORREF
get_text_color( ME_Context
*c
, ME_Style
*style
, BOOL highlight
)
210 color
= ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_HIGHLIGHTTEXT
);
211 else if ((style
->fmt
.dwMask
& CFM_LINK
) && (style
->fmt
.dwEffects
& CFE_LINK
))
212 color
= RGB(0,0,255);
213 else if ((style
->fmt
.dwMask
& CFM_COLOR
) && (style
->fmt
.dwEffects
& CFE_AUTOCOLOR
))
214 color
= ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_WINDOWTEXT
);
216 color
= style
->fmt
.crTextColor
;
221 static COLORREF
get_back_color( ME_Context
*c
, ME_Style
*style
, BOOL highlight
)
226 color
= ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_HIGHLIGHT
);
227 else if ( (style
->fmt
.dwMask
& CFM_BACKCOLOR
)
228 && !(style
->fmt
.dwEffects
& CFE_AUTOBACKCOLOR
) )
229 color
= style
->fmt
.crBackColor
;
231 color
= ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_WINDOW
);
236 static HPEN
get_underline_pen( ME_Style
*style
, COLORREF color
)
238 if (style
->fmt
.dwEffects
& CFE_LINK
)
239 return CreatePen( PS_SOLID
, 1, color
);
241 /* Choose the pen type for underlining the text. */
242 if (style
->fmt
.dwEffects
& CFE_UNDERLINE
)
244 switch (style
->fmt
.bUnderlineType
)
247 case CFU_UNDERLINEWORD
: /* native seems to map it to simple underline (MSDN) */
248 case CFU_UNDERLINEDOUBLE
: /* native seems to map it to simple underline (MSDN) */
249 return CreatePen( PS_SOLID
, 1, color
);
250 case CFU_UNDERLINEDOTTED
:
251 return CreatePen( PS_DOT
, 1, color
);
253 FIXME( "Unknown underline type (%u)\n", style
->fmt
.bUnderlineType
);
255 case CFU_CF1UNDERLINE
: /* this type is supported in the font, do nothing */
256 case CFU_UNDERLINENONE
:
263 static void draw_underline( ME_Context
*c
, ME_Run
*run
, int x
, int y
, COLORREF color
)
267 pen
= get_underline_pen( run
->style
, color
);
270 HPEN old_pen
= SelectObject( c
->hDC
, pen
);
271 MoveToEx( c
->hDC
, x
, y
+ 1, NULL
);
272 LineTo( c
->hDC
, x
+ run
->nWidth
, y
+ 1 );
273 SelectObject( c
->hDC
, old_pen
);
279 /*********************************************************************
282 * Draw the end-of-paragraph or tab space.
284 * If actually_draw is TRUE then ensure any underline is drawn.
286 static void draw_space( ME_Context
*c
, ME_Run
*run
, int x
, int y
,
287 BOOL selected
, BOOL actually_draw
, int ymin
, int cy
)
290 BOOL old_style_selected
= FALSE
;
292 COLORREF back_color
= 0;
294 SetRect( &rect
, x
, ymin
, x
+ run
->nWidth
, ymin
+ cy
);
296 if (c
->editor
->bHideSelection
|| (!c
->editor
->bHaveFocus
&& (c
->editor
->props
& TXTBIT_HIDESELECTION
)))
298 if (c
->editor
->bEmulateVersion10
)
300 old_style_selected
= selected
;
305 back_color
= ITextHost_TxGetSysColor( c
->editor
->texthost
, COLOR_HIGHLIGHT
);
309 COLORREF text_color
= get_text_color( c
, run
->style
, selected
);
310 COLORREF old_text
, old_back
;
311 int y_offset
= calc_y_offset( c
, run
->style
);
312 static const WCHAR space
[1] = {' '};
314 select_style( c
, run
->style
);
315 old_text
= SetTextColor( hdc
, text_color
);
316 if (selected
) old_back
= SetBkColor( hdc
, back_color
);
318 ExtTextOutW( hdc
, x
, y
- y_offset
, selected
? ETO_OPAQUE
: 0, &rect
, space
, 1, &run
->nWidth
);
320 if (selected
) SetBkColor( hdc
, old_back
);
321 SetTextColor( hdc
, old_text
);
323 draw_underline( c
, run
, x
, y
- y_offset
, text_color
);
327 HBRUSH brush
= CreateSolidBrush( back_color
);
328 FillRect( hdc
, &rect
, brush
);
329 DeleteObject( brush
);
332 if (old_style_selected
)
333 PatBlt( hdc
, x
, ymin
, run
->nWidth
, cy
, DSTINVERT
);
336 static void get_selection_rect( ME_Context
*c
, ME_Run
*run
, int from
, int to
, int cy
, RECT
*r
)
338 from
= max( 0, from
);
339 to
= min( run
->len
, to
);
340 r
->left
= ME_PointFromCharContext( c
, run
, from
, TRUE
);
342 r
->right
= ME_PointFromCharContext( c
, run
, to
, TRUE
);
347 static void draw_text( ME_Context
*c
, ME_Run
*run
, int x
, int y
, BOOL selected
, RECT
*sel_rect
)
349 COLORREF text_color
= get_text_color( c
, run
->style
, selected
);
350 COLORREF back_color
= get_back_color( c
, run
->style
, selected
);
351 COLORREF old_text
, old_back
= 0;
352 const WCHAR
*text
= get_text( run
, 0 );
353 ME_String
*masked
= NULL
;
354 const BOOL paint_bg
= ( selected
355 || ( ( run
->style
->fmt
.dwMask
& CFM_BACKCOLOR
)
356 && !(CFE_AUTOBACKCOLOR
& run
->style
->fmt
.dwEffects
) )
359 if (c
->editor
->password_char
)
361 masked
= ME_MakeStringR( c
->editor
->password_char
, run
->len
);
362 text
= masked
->szData
;
365 old_text
= SetTextColor( c
->hDC
, text_color
);
366 if (paint_bg
) old_back
= SetBkColor( c
->hDC
, back_color
);
368 if (run
->para
->nFlags
& MEPF_COMPLEX
)
369 ScriptTextOut( c
->hDC
, &run
->style
->script_cache
, x
, y
, paint_bg
? ETO_OPAQUE
: 0, sel_rect
,
370 &run
->script_analysis
, NULL
, 0, run
->glyphs
, run
->num_glyphs
, run
->advances
,
371 NULL
, run
->offsets
);
373 ExtTextOutW( c
->hDC
, x
, y
, paint_bg
? ETO_OPAQUE
: 0, sel_rect
, text
, run
->len
, NULL
);
375 if (paint_bg
) SetBkColor( c
->hDC
, old_back
);
376 SetTextColor( c
->hDC
, old_text
);
378 draw_underline( c
, run
, x
, y
, text_color
);
380 ME_DestroyString( masked
);
385 static void draw_text_with_style( ME_Context
*c
, ME_Run
*run
, int x
, int y
,
386 int nSelFrom
, int nSelTo
, int ymin
, int cy
)
390 BOOL selected
= (nSelFrom
< run
->len
&& nSelTo
>= 0
391 && nSelFrom
< nSelTo
&& !c
->editor
->bHideSelection
&&
392 (c
->editor
->bHaveFocus
|| !(c
->editor
->props
& TXTBIT_HIDESELECTION
)));
393 BOOL old_style_selected
= FALSE
;
395 HRGN clip
= NULL
, sel_rgn
= NULL
;
397 yOffset
= calc_y_offset( c
, run
->style
);
401 get_selection_rect( c
, run
, nSelFrom
, nSelTo
, cy
, &sel_rect
);
402 OffsetRect( &sel_rect
, x
, ymin
);
404 if (c
->editor
->bEmulateVersion10
)
406 old_style_selected
= TRUE
;
411 sel_rgn
= CreateRectRgnIndirect( &sel_rect
);
412 clip
= CreateRectRgn( 0, 0, 0, 0 );
413 if (GetClipRgn( hDC
, clip
) != 1)
415 DeleteObject( clip
);
421 select_style( c
, run
->style
);
423 if (sel_rgn
) ExtSelectClipRgn( hDC
, sel_rgn
, RGN_DIFF
);
425 if (!(run
->style
->fmt
.dwEffects
& CFE_AUTOBACKCOLOR
)
426 && (run
->style
->fmt
.dwMask
& CFM_BACKCOLOR
) )
429 get_selection_rect( c
, run
, 0, run
->len
, cy
, &tmp_rect
);
430 OffsetRect( &tmp_rect
, x
, ymin
);
431 draw_text( c
, run
, x
, y
- yOffset
, FALSE
, &tmp_rect
);
434 draw_text( c
, run
, x
, y
- yOffset
, FALSE
, NULL
);
438 ExtSelectClipRgn( hDC
, clip
, RGN_COPY
);
439 ExtSelectClipRgn( hDC
, sel_rgn
, RGN_AND
);
440 draw_text( c
, run
, x
, y
- yOffset
, TRUE
, &sel_rect
);
441 ExtSelectClipRgn( hDC
, clip
, RGN_COPY
);
442 if (clip
) DeleteObject( clip
);
443 DeleteObject( sel_rgn
);
446 if (old_style_selected
)
447 PatBlt( hDC
, sel_rect
.left
, ymin
, sel_rect
.right
- sel_rect
.left
, cy
, DSTINVERT
);
450 static void ME_DebugWrite(HDC hDC
, const POINT
*pt
, LPCWSTR szText
) {
451 int align
= SetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
452 HGDIOBJ hFont
= SelectObject(hDC
, GetStockObject(DEFAULT_GUI_FONT
));
453 COLORREF color
= SetTextColor(hDC
, RGB(128,128,128));
454 TextOutW(hDC
, pt
->x
, pt
->y
, szText
, lstrlenW(szText
));
455 SelectObject(hDC
, hFont
);
456 SetTextAlign(hDC
, align
);
457 SetTextColor(hDC
, color
);
460 static void draw_run( ME_Context
*c
, int x
, int y
, ME_Cursor
*cursor
)
463 ME_Run
*run
= cursor
->run
;
464 int runofs
= run_char_ofs( run
, cursor
->nOffset
);
465 int nSelFrom
, nSelTo
;
467 if (run
->nFlags
& MERF_HIDDEN
) return;
469 row
= row_from_cursor( cursor
);
470 ME_GetSelectionOfs(c
->editor
, &nSelFrom
, &nSelTo
);
472 /* Draw selected end-of-paragraph mark */
473 if (run
->nFlags
& MERF_ENDPARA
)
475 if (runofs
>= nSelFrom
&& runofs
< nSelTo
)
477 draw_space( c
, run
, x
, y
, TRUE
, FALSE
,
478 c
->pt
.y
+ run
->para
->pt
.y
+ row
->pt
.y
, row
->nHeight
);
483 if (run
->nFlags
& (MERF_TAB
| MERF_ENDCELL
))
485 BOOL selected
= runofs
>= nSelFrom
&& runofs
< nSelTo
;
487 draw_space( c
, run
, x
, y
, selected
, TRUE
,
488 c
->pt
.y
+ run
->para
->pt
.y
+ row
->pt
.y
, row
->nHeight
);
492 if (run
->nFlags
& MERF_GRAPHICS
)
493 draw_ole( c
, x
, y
, run
, (runofs
>= nSelFrom
) && (runofs
< nSelTo
) );
495 draw_text_with_style( c
, run
, x
, y
, nSelFrom
- runofs
, nSelTo
- runofs
,
496 c
->pt
.y
+ run
->para
->pt
.y
+ row
->pt
.y
, row
->nHeight
);
499 /* The documented widths are in points (72 dpi), but converting them to
500 * 96 dpi (standard display resolution) avoids dealing with fractions. */
501 static const struct {unsigned width
: 8, pen_style
: 4, dble
: 1;} border_details
[] = {
502 /* none */ {0, PS_SOLID
, FALSE
},
503 /* 3/4 */ {1, PS_SOLID
, FALSE
},
504 /* 1 1/2 */ {2, PS_SOLID
, FALSE
},
505 /* 2 1/4 */ {3, PS_SOLID
, FALSE
},
506 /* 3 */ {4, PS_SOLID
, FALSE
},
507 /* 4 1/2 */ {6, PS_SOLID
, FALSE
},
508 /* 6 */ {8, PS_SOLID
, FALSE
},
509 /* 3/4 double */ {1, PS_SOLID
, TRUE
},
510 /* 1 1/2 double */ {2, PS_SOLID
, TRUE
},
511 /* 2 1/4 double */ {3, PS_SOLID
, TRUE
},
512 /* 3/4 gray */ {1, PS_DOT
/* FIXME */, FALSE
},
513 /* 1 1/2 dashed */ {2, PS_DASH
, FALSE
},
516 static const COLORREF pen_colors
[16] = {
517 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
518 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
519 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
520 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
521 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
522 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
523 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
524 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
527 static int ME_GetBorderPenWidth(const ME_Context
* c
, int idx
)
529 int width
= border_details
[idx
].width
;
532 width
= MulDiv(width
, c
->dpi
.cx
, 96);
534 if (c
->editor
->nZoomNumerator
!= 0)
535 width
= MulDiv(width
, c
->editor
->nZoomNumerator
, c
->editor
->nZoomDenominator
);
540 int ME_GetParaBorderWidth(const ME_Context
* c
, int flags
)
542 int idx
= (flags
>> 8) & 0xF;
545 if (idx
>= ARRAY_SIZE(border_details
))
547 FIXME("Unsupported border value %d\n", idx
);
550 width
= ME_GetBorderPenWidth(c
, idx
);
551 if (border_details
[idx
].dble
) width
= width
* 2 + 1;
555 static void ME_DrawParaDecoration(ME_Context
* c
, ME_Paragraph
* para
, int y
, RECT
* bounds
)
557 int idx
, border_width
, top_border
, bottom_border
;
561 SetRectEmpty(bounds
);
562 if (!(para
->fmt
.dwMask
& (PFM_BORDER
| PFM_SPACEBEFORE
| PFM_SPACEAFTER
))) return;
564 border_width
= top_border
= bottom_border
= 0;
565 idx
= (para
->fmt
.wBorders
>> 8) & 0xF;
566 hasParaBorder
= (!(c
->editor
->bEmulateVersion10
&&
567 para
->fmt
.dwMask
& PFM_TABLE
&&
568 para
->fmt
.wEffects
& PFE_TABLE
) &&
569 (para
->fmt
.dwMask
& PFM_BORDER
) &&
571 (para
->fmt
.wBorders
& 0xF));
574 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
575 * controls. It actually stores the paragraph or row border style. Although
576 * the value isn't used for drawing, it is used for streaming out rich text.
578 * wBorders stores the border style for each side (top, left, bottom, right)
579 * using nibble (4 bits) to store each border style. The rich text format
580 * control words, and their associated value are the following:
590 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
591 * The mask corresponding to each side for the version are the following:
595 * 0x0F00 bottom right
596 * 0xF000 right bottom
598 if (para
->fmt
.wBorders
& 0x00B0)
599 FIXME("Unsupported border flags %x\n", para
->fmt
.wBorders
);
600 border_width
= ME_GetParaBorderWidth(c
, para
->fmt
.wBorders
);
601 if (para
->fmt
.wBorders
& 4) top_border
= border_width
;
602 if (para
->fmt
.wBorders
& 8) bottom_border
= border_width
;
605 if (para
->fmt
.dwMask
& PFM_SPACEBEFORE
)
607 bounds
->top
= ME_twips2pointsY(c
, para
->fmt
.dySpaceBefore
);
608 if (editor_opaque( c
->editor
))
610 rc
.left
= c
->rcView
.left
;
611 rc
.right
= c
->rcView
.right
;
613 rc
.bottom
= y
+ bounds
->top
+ top_border
;
614 PatBlt(c
->hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
618 if (para
->fmt
.dwMask
& PFM_SPACEAFTER
)
620 bounds
->bottom
= ME_twips2pointsY(c
, para
->fmt
.dySpaceAfter
);
621 if (editor_opaque( c
->editor
))
623 rc
.left
= c
->rcView
.left
;
624 rc
.right
= c
->rcView
.right
;
625 rc
.bottom
= y
+ para
->nHeight
;
626 rc
.top
= rc
.bottom
- bounds
->bottom
- bottom_border
;
627 PatBlt(c
->hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
631 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
632 * but might support it in later versions. */
634 int pen_width
, rightEdge
;
636 HPEN pen
= NULL
, oldpen
= NULL
;
639 if (para
->fmt
.wBorders
& 64) /* autocolor */
640 pencr
= ITextHost_TxGetSysColor(c
->editor
->texthost
,
643 pencr
= pen_colors
[(para
->fmt
.wBorders
>> 12) & 0xF];
645 rightEdge
= c
->pt
.x
+ max(c
->editor
->sizeWindow
.cx
,
646 c
->editor
->nTotalWidth
);
648 pen_width
= ME_GetBorderPenWidth(c
, idx
);
649 pen
= CreatePen(border_details
[idx
].pen_style
, pen_width
, pencr
);
650 oldpen
= SelectObject(c
->hDC
, pen
);
651 MoveToEx(c
->hDC
, 0, 0, &pt
);
653 /* before & after spaces are not included in border */
655 /* helper to draw the double lines in case of corner */
656 #define DD(x) ((para->fmt.wBorders & (x)) ? (pen_width + 1) : 0)
658 if (para
->fmt
.wBorders
& 1)
660 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
661 LineTo(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
);
662 if (border_details
[idx
].dble
) {
663 rc
.left
= c
->pt
.x
+ 1;
664 rc
.right
= rc
.left
+ border_width
;
665 rc
.top
= y
+ bounds
->top
;
666 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
667 PatBlt(c
->hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
668 MoveToEx(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ bounds
->top
+ DD(4), NULL
);
669 LineTo(c
->hDC
, c
->pt
.x
+ pen_width
+ 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
671 bounds
->left
+= border_width
;
673 if (para
->fmt
.wBorders
& 2)
675 MoveToEx(c
->hDC
, rightEdge
- 1, y
+ bounds
->top
, NULL
);
676 LineTo(c
->hDC
, rightEdge
- 1, y
+ para
->nHeight
- bounds
->bottom
);
677 if (border_details
[idx
].dble
) {
678 rc
.left
= rightEdge
- pen_width
- 1;
679 rc
.right
= rc
.left
+ pen_width
;
680 rc
.top
= y
+ bounds
->top
;
681 rc
.bottom
= y
+ para
->nHeight
- bounds
->bottom
;
682 PatBlt(c
->hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
683 MoveToEx(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ bounds
->top
+ DD(4), NULL
);
684 LineTo(c
->hDC
, rightEdge
- 1 - pen_width
- 1, y
+ para
->nHeight
- bounds
->bottom
- DD(8));
686 bounds
->right
+= border_width
;
688 if (para
->fmt
.wBorders
& 4)
690 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ bounds
->top
, NULL
);
691 LineTo(c
->hDC
, rightEdge
, y
+ bounds
->top
);
692 if (border_details
[idx
].dble
) {
693 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ bounds
->top
+ pen_width
+ 1, NULL
);
694 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ bounds
->top
+ pen_width
+ 1);
696 bounds
->top
+= border_width
;
698 if (para
->fmt
.wBorders
& 8)
700 MoveToEx(c
->hDC
, c
->pt
.x
, y
+ para
->nHeight
- bounds
->bottom
- 1, NULL
);
701 LineTo(c
->hDC
, rightEdge
, y
+ para
->nHeight
- bounds
->bottom
- 1);
702 if (border_details
[idx
].dble
) {
703 MoveToEx(c
->hDC
, c
->pt
.x
+ DD(1), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1, NULL
);
704 LineTo(c
->hDC
, rightEdge
- DD(2), y
+ para
->nHeight
- bounds
->bottom
- 1 - pen_width
- 1);
706 bounds
->bottom
+= border_width
;
710 MoveToEx(c
->hDC
, pt
.x
, pt
.y
, NULL
);
711 SelectObject(c
->hDC
, oldpen
);
716 static void draw_table_borders( ME_Context
*c
, ME_Paragraph
*para
)
718 if (!c
->editor
->bEmulateVersion10
) /* v4.1 */
720 if (para_cell( para
))
723 ME_Cell
*cell
= para_cell( para
);
724 ME_Paragraph
*after_row
;
731 BOOL atTop
= (para
== cell_first_para( cell
));
732 BOOL atBottom
= (para
== cell_end_para( cell
));
733 int top
= c
->pt
.y
+ (atTop
? cell
->pt
.y
: para
->pt
.y
);
734 int bottom
= (atBottom
?
735 c
->pt
.y
+ cell
->pt
.y
+ cell
->nHeight
:
736 top
+ para
->nHeight
+ (atTop
? cell
->yTextOffset
: 0));
737 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
738 rc
.right
= rc
.left
+ cell
->nWidth
;
741 /* Erase gap before text if not all borders are the same height. */
742 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
743 rc
.top
= top
+ width
;
744 width
= cell
->yTextOffset
- width
;
745 rc
.bottom
= rc
.top
+ width
;
746 if (width
&& editor_opaque( c
->editor
))
747 PatBlt(c
->hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
749 /* Draw cell borders.
750 * The order borders are draw in is left, top, bottom, right in order
751 * to be consistent with native richedit. This is noticeable from the
752 * overlap of borders of different colours. */
753 if (!(para
->nFlags
& MEPF_ROWEND
))
757 if (cell
->border
.left
.width
> 0)
759 color
= cell
->border
.left
.colorRef
;
760 width
= max(ME_twips2pointsX(c
, cell
->border
.left
.width
), 1);
764 color
= RGB(192,192,192);
767 logBrush
.lbStyle
= BS_SOLID
;
768 logBrush
.lbColor
= color
;
769 logBrush
.lbHatch
= 0;
770 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
771 width
, &logBrush
, 0, NULL
);
772 oldPen
= SelectObject(c
->hDC
, pen
);
773 MoveToEx(c
->hDC
, rc
.left
, rc
.top
, &oldPt
);
774 LineTo(c
->hDC
, rc
.left
, rc
.bottom
);
775 SelectObject(c
->hDC
, oldPen
);
777 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
782 if (cell
->border
.top
.width
> 0)
784 brush
= CreateSolidBrush(cell
->border
.top
.colorRef
);
785 width
= max(ME_twips2pointsY(c
, cell
->border
.top
.width
), 1);
789 brush
= GetStockObject(LTGRAY_BRUSH
);
793 rc
.bottom
= rc
.top
+ width
;
794 FillRect(c
->hDC
, &rc
, brush
);
795 if (cell
->border
.top
.width
> 0)
799 /* Draw the bottom border if at the last paragraph in the cell, and when
800 * in the last row of the table. */
803 int oldLeft
= rc
.left
;
804 width
= max(ME_twips2pointsY(c
, cell
->border
.bottom
.width
), 1);
805 after_row
= para_next( table_row_end( para
) );
806 if (after_row
->nFlags
& MEPF_ROWSTART
)
809 next_end
= table_row_end_cell( after_row
);
810 assert( next_end
&& !cell_next( next_end
) );
811 rc
.left
= c
->pt
.x
+ next_end
->pt
.x
;
813 if (rc
.left
< rc
.right
)
815 if (cell
->border
.bottom
.width
> 0)
816 brush
= CreateSolidBrush(cell
->border
.bottom
.colorRef
);
818 brush
= GetStockObject(LTGRAY_BRUSH
);
820 rc
.top
= rc
.bottom
- width
;
821 FillRect(c
->hDC
, &rc
, brush
);
822 if (cell
->border
.bottom
.width
> 0)
828 /* Right border only drawn if at the end of the table row. */
829 if (!cell_next( cell_next( cell
) ) && !(para
->nFlags
& MEPF_ROWSTART
))
833 if (cell
->border
.right
.width
> 0)
835 color
= cell
->border
.right
.colorRef
;
836 width
= max(ME_twips2pointsX(c
, cell
->border
.right
.width
), 1);
840 color
= RGB(192,192,192);
843 logBrush
.lbStyle
= BS_SOLID
;
844 logBrush
.lbColor
= color
;
845 logBrush
.lbHatch
= 0;
846 pen
= ExtCreatePen(PS_GEOMETRIC
|PS_SOLID
|PS_ENDCAP_FLAT
|PS_JOIN_MITER
,
847 width
, &logBrush
, 0, NULL
);
848 oldPen
= SelectObject(c
->hDC
, pen
);
849 MoveToEx(c
->hDC
, rc
.right
- 1, rc
.top
, &oldPt
);
850 LineTo(c
->hDC
, rc
.right
- 1, rc
.bottom
);
851 SelectObject(c
->hDC
, oldPen
);
853 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
857 else /* v1.0 - 3.0 */
859 /* Draw simple table border */
860 if (para_in_table( para
))
862 HPEN pen
= NULL
, oldpen
= NULL
;
863 int i
, firstX
, startX
, endX
, rowY
, rowBottom
, nHeight
;
866 pen
= CreatePen(PS_SOLID
, 0, para
->border
.top
.colorRef
);
867 oldpen
= SelectObject(c
->hDC
, pen
);
869 /* Find the start relative to the text */
870 firstX
= c
->pt
.x
+ para_first_run( para
)->pt
.x
;
871 /* Go back by the horizontal gap, which is stored in dxOffset */
872 firstX
-= ME_twips2pointsX(c
, para
->fmt
.dxOffset
);
873 /* The left edge, stored in dxStartIndent affected just the first edge */
874 startX
= firstX
- ME_twips2pointsX(c
, para
->fmt
.dxStartIndent
);
875 rowY
= c
->pt
.y
+ para
->pt
.y
;
876 if (para
->fmt
.dwMask
& PFM_SPACEBEFORE
)
877 rowY
+= ME_twips2pointsY(c
, para
->fmt
.dySpaceBefore
);
878 nHeight
= para_first_row( para
)->nHeight
;
879 rowBottom
= rowY
+ nHeight
;
881 /* Draw horizontal lines */
882 MoveToEx(c
->hDC
, firstX
, rowY
, &oldPt
);
883 i
= para
->fmt
.cTabCount
- 1;
884 endX
= startX
+ ME_twips2pointsX(c
, para
->fmt
.rgxTabs
[i
] & 0x00ffffff) + 1;
885 LineTo(c
->hDC
, endX
, rowY
);
886 /* The bottom of the row only needs to be drawn if the next row is
888 if (!(para_next( para
) && para_in_table( para_next( para
) ) && para
->nRows
== 1))
890 /* Decrement rowBottom to draw the bottom line within the row, and
891 * to not draw over this line when drawing the vertical lines. */
893 MoveToEx(c
->hDC
, firstX
, rowBottom
, NULL
);
894 LineTo(c
->hDC
, endX
, rowBottom
);
897 /* Draw vertical lines */
898 MoveToEx(c
->hDC
, firstX
, rowY
, NULL
);
899 LineTo(c
->hDC
, firstX
, rowBottom
);
900 for (i
= 0; i
< para
->fmt
.cTabCount
; i
++)
902 int rightBoundary
= para
->fmt
.rgxTabs
[i
] & 0x00ffffff;
903 endX
= startX
+ ME_twips2pointsX(c
, rightBoundary
);
904 MoveToEx(c
->hDC
, endX
, rowY
, NULL
);
905 LineTo(c
->hDC
, endX
, rowBottom
);
908 MoveToEx(c
->hDC
, oldPt
.x
, oldPt
.y
, NULL
);
909 SelectObject(c
->hDC
, oldpen
);
915 static void draw_para_number( ME_Context
*c
, ME_Paragraph
*para
)
920 if (para
->fmt
.wNumbering
)
922 select_style( c
, para
->para_num
.style
);
923 old_text
= SetTextColor( c
->hDC
, get_text_color( c
, para
->para_num
.style
, FALSE
) );
925 x
= c
->pt
.x
+ para
->para_num
.pt
.x
;
926 y
= c
->pt
.y
+ para
->pt
.y
+ para
->para_num
.pt
.y
;
928 ExtTextOutW( c
->hDC
, x
, y
, 0, NULL
, para
->para_num
.text
->szData
, para
->para_num
.text
->nLen
, NULL
);
930 SetTextColor( c
->hDC
, old_text
);
934 static void draw_paragraph( ME_Context
*c
, ME_Paragraph
*para
)
936 int align
= SetTextAlign(c
->hDC
, TA_BASELINE
);
942 int height
= 0, baseline
= 0, no
=0;
943 BOOL visible
= FALSE
;
946 rc
.right
= c
->rcView
.right
;
948 y
= c
->pt
.y
+ para
->pt
.y
;
949 if ((cell
= para_cell( para
)))
951 rc
.left
= c
->pt
.x
+ cell
->pt
.x
;
952 rc
.right
= rc
.left
+ cell
->nWidth
;
954 if (para
->nFlags
& MEPF_ROWSTART
)
956 cell
= table_row_first_cell( para
);
957 rc
.right
= c
->pt
.x
+ cell
->pt
.x
;
959 else if (para
->nFlags
& MEPF_ROWEND
)
961 cell
= table_row_end_cell( para
);
962 rc
.left
= c
->pt
.x
+ cell
->pt
.x
+ cell
->nWidth
;
964 ME_DrawParaDecoration(c
, para
, y
, &bounds
);
966 if (bounds
.left
|| bounds
.right
)
968 rc
.left
= max(rc
.left
, c
->pt
.x
+ bounds
.left
);
969 rc
.right
= min(rc
.right
, c
->pt
.x
- bounds
.right
970 + max(c
->editor
->sizeWindow
.cx
,
971 c
->editor
->nTotalWidth
));
974 for (p
= para_get_di( para
)->next
; p
!= para_get_di( para_next( para
) ); p
= p
->next
)
983 if (para
->nFlags
& (MEPF_ROWSTART
|MEPF_ROWEND
)) {
984 rc
.bottom
= y
+ para
->nHeight
;
986 rc
.bottom
= y
+ p
->member
.row
.nHeight
;
988 visible
= RectVisible(c
->hDC
, &rc
);
989 if (editor_opaque( c
->editor
) && visible
)
990 PatBlt(c
->hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
993 /* If scrolled to the right past the end of the text, then
994 * there may be space to the right of the paragraph border. */
996 after_bdr
.left
= rc
.right
+ bounds
.right
;
997 after_bdr
.right
= c
->rcView
.right
;
998 if (editor_opaque( c
->editor
) && RectVisible( c
->hDC
, &after_bdr
))
999 PatBlt(c
->hDC
, after_bdr
.left
, after_bdr
.top
, after_bdr
.right
- after_bdr
.left
,
1000 after_bdr
.bottom
- after_bdr
.top
, PATCOPY
);
1006 wsprintfW( buf
, L
"row[%d]", no
);
1008 ME_DebugWrite(c
->hDC
, &pt
, buf
);
1011 height
= p
->member
.row
.nHeight
;
1012 baseline
= p
->member
.row
.nBaseline
;
1016 run
= &p
->member
.run
;
1017 if (visible
&& me_debug
) {
1019 rc
.left
= c
->pt
.x
+ run
->pt
.x
;
1020 rc
.right
= rc
.left
+ run
->nWidth
;
1021 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
1022 rc
.bottom
= rc
.top
+ height
;
1023 TRACE("rc = %s\n", wine_dbgstr_rect(&rc
));
1024 FrameRect(c
->hDC
, &rc
, GetSysColorBrush(COLOR_GRAYTEXT
));
1033 draw_run( c
, c
->pt
.x
+ run
->pt
.x
, c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
+ baseline
, &cursor
);
1039 pt
.x
= c
->pt
.x
+ run
->pt
.x
;
1040 pt
.y
= c
->pt
.y
+ para
->pt
.y
+ run
->pt
.y
;
1041 wsprintfW( buf
, L
"[%d:%x] %ls", no
, p
->member
.run
.nFlags
, get_text( &p
->member
.run
, 0 ));
1042 ME_DebugWrite(c
->hDC
, &pt
, buf
);
1051 if (editor_opaque( c
->editor
) && para_cell( para
))
1053 /* Clear any space at the bottom of the cell after the text. */
1054 rc
.top
= c
->pt
.y
+ para
->pt
.y
+ para
->nHeight
;
1055 rc
.bottom
= c
->pt
.y
+ cell
->pt
.y
+ cell
->nHeight
;
1056 PatBlt( c
->hDC
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, PATCOPY
);
1059 draw_table_borders( c
, para
);
1060 draw_para_number( c
, para
);
1062 SetTextAlign( c
->hDC
, align
);
1065 static void enable_show_scrollbar( ME_TextEditor
*editor
, INT bar
, BOOL enable
)
1067 if (enable
|| editor
->scrollbars
& ES_DISABLENOSCROLL
)
1068 ITextHost_TxEnableScrollBar( editor
->texthost
, bar
, enable
? 0 : ESB_DISABLE_BOTH
);
1069 if (!(editor
->scrollbars
& ES_DISABLENOSCROLL
))
1070 ITextHost_TxShowScrollBar( editor
->texthost
, bar
, enable
);
1073 static void set_scroll_range_pos( ME_TextEditor
*editor
, INT bar
, SCROLLINFO
*info
, BOOL set_range
, BOOL notify
)
1075 LONG max_pos
= info
->nMax
, pos
= info
->nPos
;
1077 /* Scale the scrollbar info to 16-bit values. */
1078 if (max_pos
> 0xffff)
1080 pos
= MulDiv( pos
, 0xffff, max_pos
);
1083 if (set_range
) ITextHost_TxSetScrollRange( editor
->texthost
, bar
, 0, max_pos
, FALSE
);
1084 ITextHost_TxSetScrollPos( editor
->texthost
, bar
, pos
, TRUE
);
1086 if (notify
&& editor
->nEventMask
& ENM_SCROLL
)
1087 ITextHost_TxNotify( editor
->texthost
, bar
== SB_VERT
? EN_VSCROLL
: EN_HSCROLL
, NULL
);
1090 void scroll_abs( ME_TextEditor
*editor
, int x
, int y
, BOOL notify
)
1092 int scrollX
= 0, scrollY
= 0;
1094 if (editor
->horz_si
.nPos
!= x
) {
1095 x
= min(x
, editor
->horz_si
.nMax
);
1096 x
= max(x
, editor
->horz_si
.nMin
);
1097 scrollX
= editor
->horz_si
.nPos
- x
;
1098 editor
->horz_si
.nPos
= x
;
1099 set_scroll_range_pos( editor
, SB_HORZ
, &editor
->horz_si
, FALSE
, notify
);
1102 if (editor
->vert_si
.nPos
!= y
) {
1103 y
= min(y
, editor
->vert_si
.nMax
- (int)editor
->vert_si
.nPage
);
1104 y
= max(y
, editor
->vert_si
.nMin
);
1105 scrollY
= editor
->vert_si
.nPos
- y
;
1106 editor
->vert_si
.nPos
= y
;
1107 set_scroll_range_pos( editor
, SB_VERT
, &editor
->vert_si
, FALSE
, notify
);
1110 if (abs(scrollX
) > editor
->sizeWindow
.cx
|| abs(scrollY
) > editor
->sizeWindow
.cy
)
1111 ITextHost_TxInvalidateRect(editor
->texthost
, NULL
, TRUE
);
1113 ITextHost_TxScrollWindowEx(editor
->texthost
, scrollX
, scrollY
,
1114 &editor
->rcFormat
, &editor
->rcFormat
,
1115 NULL
, NULL
, SW_INVALIDATE
);
1116 ME_UpdateScrollBar(editor
);
1120 void scroll_h_abs( ME_TextEditor
*editor
, int x
, BOOL notify
)
1122 scroll_abs( editor
, x
, editor
->vert_si
.nPos
, notify
);
1125 void scroll_v_abs( ME_TextEditor
*editor
, int y
, BOOL notify
)
1127 scroll_abs( editor
, editor
->horz_si
.nPos
, y
, notify
);
1130 void ME_ScrollUp(ME_TextEditor
*editor
, int cy
)
1132 scroll_v_abs( editor
, editor
->vert_si
.nPos
- cy
, TRUE
);
1135 void ME_ScrollDown(ME_TextEditor
*editor
, int cy
)
1137 scroll_v_abs( editor
, editor
->vert_si
.nPos
+ cy
, TRUE
);
1140 void ME_ScrollLeft(ME_TextEditor
*editor
, int cx
)
1142 scroll_h_abs( editor
, editor
->horz_si
.nPos
- cx
, TRUE
);
1145 void ME_ScrollRight(ME_TextEditor
*editor
, int cx
)
1147 scroll_h_abs( editor
, editor
->horz_si
.nPos
+ cx
, TRUE
);
1150 void ME_UpdateScrollBar(ME_TextEditor
*editor
)
1152 /* Note that this is the only function that should ever call
1153 * SetScrollInfo with SIF_PAGE or SIF_RANGE. */
1156 if (ME_WrapMarkedParagraphs(editor
))
1157 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1159 /* Update horizontal scrollbar */
1160 enable
= editor
->nTotalWidth
> editor
->sizeWindow
.cx
;
1161 if (editor
->horz_si
.nPos
&& !enable
)
1163 scroll_h_abs( editor
, 0, TRUE
);
1164 /* ME_HScrollAbs will call this function, so nothing else needs to be done here. */
1168 if (editor
->scrollbars
& WS_HSCROLL
&& !enable
^ !editor
->horz_sb_enabled
)
1170 editor
->horz_sb_enabled
= enable
;
1171 enable_show_scrollbar( editor
, SB_HORZ
, enable
);
1174 if (editor
->horz_si
.nMax
!= editor
->nTotalWidth
|| editor
->horz_si
.nPage
!= editor
->sizeWindow
.cx
)
1176 editor
->horz_si
.nMax
= editor
->nTotalWidth
;
1177 editor
->horz_si
.nPage
= editor
->sizeWindow
.cx
;
1178 TRACE( "min = %d max = %d page = %d\n", editor
->horz_si
.nMin
, editor
->horz_si
.nMax
, editor
->horz_si
.nPage
);
1179 if ((enable
|| editor
->horz_sb_enabled
) && editor
->scrollbars
& WS_HSCROLL
)
1180 set_scroll_range_pos( editor
, SB_HORZ
, &editor
->horz_si
, TRUE
, TRUE
);
1183 /* Update vertical scrollbar */
1184 enable
= editor
->nTotalLength
> editor
->sizeWindow
.cy
&& (editor
->props
& TXTBIT_MULTILINE
);
1186 if (editor
->vert_si
.nPos
&& !enable
)
1188 scroll_v_abs( editor
, 0, TRUE
);
1189 /* ME_VScrollAbs will call this function, so nothing else needs to be done here. */
1193 if (editor
->scrollbars
& WS_VSCROLL
&& !enable
^ !editor
->vert_sb_enabled
)
1195 editor
->vert_sb_enabled
= enable
;
1196 enable_show_scrollbar( editor
, SB_VERT
, enable
);
1199 if (editor
->vert_si
.nMax
!= editor
->nTotalLength
|| editor
->vert_si
.nPage
!= editor
->sizeWindow
.cy
)
1201 editor
->vert_si
.nMax
= editor
->nTotalLength
;
1202 editor
->vert_si
.nPage
= editor
->sizeWindow
.cy
;
1203 TRACE( "min = %d max = %d page = %d\n", editor
->vert_si
.nMin
, editor
->vert_si
.nMax
, editor
->vert_si
.nPage
);
1204 if ((enable
|| editor
->vert_sb_enabled
) && editor
->scrollbars
& WS_VSCROLL
)
1205 set_scroll_range_pos( editor
, SB_VERT
, &editor
->vert_si
, TRUE
, TRUE
);
1209 void editor_ensure_visible( ME_TextEditor
*editor
, ME_Cursor
*cursor
)
1211 ME_Run
*run
= cursor
->run
;
1212 ME_Row
*row
= row_from_cursor( cursor
);
1213 ME_Paragraph
*para
= cursor
->para
;
1217 if (editor
->scrollbars
& ES_AUTOHSCROLL
)
1219 x
= run
->pt
.x
+ ME_PointFromChar( editor
, run
, cursor
->nOffset
, TRUE
);
1220 if (x
> editor
->horz_si
.nPos
+ editor
->sizeWindow
.cx
)
1221 x
= x
+ 1 - editor
->sizeWindow
.cx
;
1222 else if (x
> editor
->horz_si
.nPos
)
1223 x
= editor
->horz_si
.nPos
;
1225 if (~editor
->scrollbars
& ES_AUTOVSCROLL
)
1227 scroll_h_abs( editor
, x
, TRUE
);
1233 if (~editor
->scrollbars
& ES_AUTOVSCROLL
) return;
1234 x
= editor
->horz_si
.nPos
;
1237 y
= para
->pt
.y
+ row
->pt
.y
;
1238 yheight
= row
->nHeight
;
1240 if (y
< editor
->vert_si
.nPos
)
1241 scroll_abs( editor
, x
, y
, TRUE
);
1242 else if (y
+ yheight
> editor
->vert_si
.nPos
+ editor
->sizeWindow
.cy
)
1243 scroll_abs( editor
, x
, y
+ yheight
- editor
->sizeWindow
.cy
, TRUE
);
1244 else if (x
!= editor
->horz_si
.nPos
)
1245 scroll_abs( editor
, x
, editor
->vert_si
.nPos
, TRUE
);
1250 ME_InvalidateSelection(ME_TextEditor
*editor
)
1252 ME_Paragraph
*sel_start
, *sel_end
;
1253 ME_Paragraph
*repaint_start
= NULL
, *repaint_end
= NULL
;
1255 int len
= ME_GetTextLength(editor
);
1257 ME_GetSelectionOfs(editor
, &nStart
, &nEnd
);
1258 /* if both old and new selection are 0-char (= caret only), then
1259 there's no (inverted) area to be repainted, neither old nor new */
1260 if (nStart
== nEnd
&& editor
->nLastSelStart
== editor
->nLastSelEnd
)
1262 ME_WrapMarkedParagraphs(editor
);
1263 editor_get_selection_paras( editor
, &sel_start
, &sel_end
);
1265 /* last selection markers aren't always updated, which means
1266 * they can point past the end of the document */
1267 if (editor
->nLastSelStart
> len
|| editor
->nLastSelEnd
> len
)
1269 repaint_start
= editor_first_para( editor
);
1270 repaint_end
= para_prev( editor_end_para( editor
) );
1274 /* if the start part of selection is being expanded or contracted... */
1275 if (nStart
< editor
->nLastSelStart
)
1277 repaint_start
= sel_start
;
1278 repaint_end
= editor
->last_sel_start_para
;
1280 else if (nStart
> editor
->nLastSelStart
)
1282 repaint_start
= editor
->last_sel_start_para
;
1283 repaint_end
= sel_start
;
1286 /* if the end part of selection is being contracted or expanded... */
1287 if (nEnd
< editor
->nLastSelEnd
)
1289 if (!repaint_start
) repaint_start
= sel_end
;
1290 repaint_end
= editor
->last_sel_end_para
;
1292 else if (nEnd
> editor
->nLastSelEnd
)
1294 if (!repaint_start
) repaint_start
= editor
->last_sel_end_para
;
1295 repaint_end
= sel_end
;
1300 para_range_invalidate( editor
, repaint_start
, repaint_end
);
1301 /* remember the last invalidated position */
1302 ME_GetSelectionOfs(editor
, &editor
->nLastSelStart
, &editor
->nLastSelEnd
);
1303 editor_get_selection_paras( editor
, &editor
->last_sel_start_para
, &editor
->last_sel_end_para
);
1307 ME_SetZoom(ME_TextEditor
*editor
, int numerator
, int denominator
)
1309 /* TODO: Zoom images and objects */
1311 if (numerator
== 0 && denominator
== 0)
1313 editor
->nZoomNumerator
= editor
->nZoomDenominator
= 0;
1316 if (numerator
<= 0 || denominator
<= 0)
1318 if (numerator
* 64 <= denominator
|| numerator
/ denominator
>= 64)
1321 editor
->nZoomNumerator
= numerator
;
1322 editor
->nZoomDenominator
= denominator
;
1324 ME_RewrapRepaint(editor
);