1 /*
2 * RichEdit - painting functions
3 *
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2005 by Phil Krylov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "editor.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
25
26 void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *rcUpdate) {
27 ME_DisplayItem *item;
28 ME_Context c;
29 int yoffset;
30
31 editor->nSequence++;
32 yoffset = ME_GetYScrollPos(editor);
33 ME_InitContext(&c, editor, hDC);
34 SetBkMode(hDC, TRANSPARENT);
35 ME_MoveCaret(editor); /* Calls ME_WrapMarkedParagraphs */
36 item = editor->pBuffer->pFirst->next;
37 c.pt.y -= yoffset;
38 while(item != editor->pBuffer->pLast) {
39 int yTextOffset = 0;
40 int ye;
41 assert(item->type == diParagraph);
42 if (item->member.para.pCell
43 != item->member.para.next_para->member.para.pCell)
44 {
45 ME_Cell *cell = NULL;
46 cell = &ME_FindItemBack(item->member.para.next_para, diCell)->member.cell;
47 ye = cell->pt.y + cell->nHeight - yoffset;
48 } else {
49 ye = c.pt.y + item->member.para.nHeight;
50 }
51 if (!(item->member.para.nFlags & MEPF_ROWEND) &&
52 item->member.para.pCell != item->member.para.prev_para->member.para.pCell)
53 {
54 ME_DisplayItem *cell;
55 if (item->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART)
56 cell = item->member.para.pCell;
57 else
58 cell = item->member.para.prev_para->member.para.pCell;
59 assert(cell);
60 /* the border shifts the text down */
61 yTextOffset = cell->member.cell.yTextOffset;
62 ye += yTextOffset;
63 }
64 if (!bOnlyNew || (item->member.para.nFlags & MEPF_REPAINT))
65 {
66 BOOL bPaint = (rcUpdate == NULL);
67 if (rcUpdate)
68 bPaint = c.pt.y<rcUpdate->bottom && ye>rcUpdate->top;
69 if (bPaint)
70 {
71 c.pt.y += yTextOffset;
72 ME_DrawParagraph(&c, item);
73 if (!rcUpdate || (rcUpdate->top<=c.pt.y-yTextOffset && rcUpdate->bottom>=ye))
74 item->member.para.nFlags &= ~MEPF_REPAINT;
75 }
76 }
77 if (item->member.para.pCell)
78 {
79 ME_Cell *cell = &item->member.para.pCell->member.cell;
80 ME_DisplayItem *next_para = item->member.para.next_para;
81 c.pt.x = cell->pt.x + cell->nWidth;
82 if (item->member.para.pCell == next_para->member.para.pCell &&
83 !(next_para->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND)))
84 {
85 c.pt.y = ye;
86 } else {
87 if (next_para->member.para.nFlags & MEPF_ROWSTART)
88 {
89 cell = &ME_FindItemFwd(next_para, diCell)->member.cell;
90 }
91 else if (next_para->member.para.nFlags & MEPF_ROWEND)
92 {
93 cell = &cell->next_cell->member.cell;
94 }
95 else
96 {
97 cell = &next_para->member.para.pCell->member.cell;
98 }
99 c.pt.y = cell->pt.y - yoffset;
100 }
101 } else if (!(item->member.para.nFlags & MEPF_ROWSTART)) {
102 c.pt.y = ye;
103 }
104 item = item->member.para.next_para;
105 }
106 if (c.pt.y<c.rcView.bottom) {
107 RECT rc;
108 int xs = c.rcView.left, xe = c.rcView.right;
109 int ys = c.pt.y, ye = c.rcView.bottom;
110
111 if (bOnlyNew)
112 {
113 int y1 = editor->nTotalLength-yoffset, y2 = editor->nLastTotalLength-yoffset;
114 if (y1<y2)
115 ys = y1, ye = y2+1;
116 else
117 ys = ye;
118 }
119
120 if (rcUpdate && ys!=ye)
121 {
122 xs = rcUpdate->left, xe = rcUpdate->right;
123 if (rcUpdate->top > ys)
124 ys = rcUpdate->top;
125 if (rcUpdate->bottom < ye)
126 ye = rcUpdate->bottom;
127 }
128
129 if (ye>ys) {
130 rc.left = xs;
131 rc.top = ys;
132 rc.right = xe;
133 rc.bottom = ye;
134 FillRect(hDC, &rc, c.editor->hbrBackground);
135 }
136 }
137 if (editor->nTotalLength != editor->nLastTotalLength)
138 ME_SendRequestResize(editor, FALSE);
139 editor->nLastTotalLength = editor->nTotalLength;
140 ME_DestroyContext(&c, NULL);
141 }
142
143 void ME_Repaint(ME_TextEditor *editor)
144 {
145 if (ME_WrapMarkedParagraphs(editor))
146 {
147 ME_UpdateScrollBar(editor);
148 FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
149 }
150 if (!editor->bEmulateVersion10 || (editor->nEventMask & ENM_UPDATE))
151 ME_SendOldNotify(editor, EN_UPDATE);
152 UpdateWindow(editor->hWnd);
153 }
154
155 void ME_UpdateRepaint(ME_TextEditor *editor)
156 {
157 /* Should be called whenever the contents of the control have changed */
158 ME_Cursor *pCursor;
159 BOOL wrappedParagraphs;
160
161 wrappedParagraphs = ME_WrapMarkedParagraphs(editor);
162 if (!editor->bRedraw) return;
163 if (wrappedParagraphs)
164 ME_UpdateScrollBar(editor);
165
166 /* Ensure that the cursor is visible */
167 pCursor = &editor->pCursors[0];
168 ME_EnsureVisible(editor, pCursor->pRun);
169
170 /* send EN_CHANGE if the event mask asks for it */
171 if(editor->nEventMask & ENM_CHANGE)
172 {
173 editor->nEventMask &= ~ENM_CHANGE;
174 ME_SendOldNotify(editor, EN_CHANGE);
175 editor->nEventMask |= ENM_CHANGE;
176 }
177 ME_Repaint(editor);
178 ME_SendSelChange(editor);
179 }
180
181 void
182 ME_RewrapRepaint(ME_TextEditor *editor)
183 {
184 /* RewrapRepaint should be called whenever the control has changed in
185 * looks, but not content. Like resizing. */
186
187 ME_MarkAllForWrapping(editor);
188 if (editor->bRedraw)
189 {
190 ME_WrapMarkedParagraphs(editor);
191 ME_UpdateScrollBar(editor);
192 ME_Repaint(editor);
193 }
194 }
195
196 int ME_twips2pointsX(ME_Context *c, int x)
197 {
198 if (c->editor->nZoomNumerator == 0)
199 return x * c->dpi.cx / 1440;
200 else
201 return x * c->dpi.cx * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
202 }
203
204 int ME_twips2pointsY(ME_Context *c, int y)
205 {
206 if (c->editor->nZoomNumerator == 0)
207 return y * c->dpi.cy / 1440;
208 else
209 return y * c->dpi.cy * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
210 }
211
212 static void ME_HighlightSpace(ME_Context *c, int x, int y, LPCWSTR szText,
213 int nChars, ME_Style *s, int width,
214 int nSelFrom, int nSelTo, int ymin, int cy)
215 {
216 HDC hDC = c->hDC;
217 HGDIOBJ hOldFont = NULL;
218 SIZE sz;
219 int selWidth;
220 /* Only highlight if there is a selection in the run and when
221 * EM_HIDESELECTION is not being used to hide the selection. */
222 if (nSelFrom >= nChars || nSelTo < 0 || nSelFrom >= nSelTo
223 || c->editor->bHideSelection)
224 return;
225 hOldFont = ME_SelectStyleFont(c, s);
226 if (width <= 0)
227 {
228 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
229 width = sz.cx;
230 }
231 if (nSelFrom < 0) nSelFrom = 0;
232 if (nSelTo > nChars) nSelTo = nChars;
233 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
234 x += sz.cx;
235 if (nSelTo != nChars)
236 {
237 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
238 selWidth = sz.cx;
239 } else {
240 selWidth = width - sz.cx;
241 }
242 ME_UnselectStyleFont(c, s, hOldFont);
243
244 if (c->editor->bEmulateVersion10)
245 PatBlt(hDC, x, ymin, selWidth, cy, DSTINVERT);
246 else
247 {
248 RECT rect;
249 HBRUSH hBrush;
250 rect.left = x;
251 rect.top = ymin;
252 rect.right = x + selWidth;
253 rect.bottom = ymin + cy;
254 hBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
255 FillRect(hDC, &rect, hBrush);
256 DeleteObject(hBrush);
257 }
258 }
259
260 static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText,
261 int nChars, ME_Style *s, int width,
262 int nSelFrom, int nSelTo, int ymin, int cy)
263 {
264 HDC hDC = c->hDC;
265 HGDIOBJ hOldFont;
266 COLORREF rgbOld;
267 int yOffset = 0, yTwipsOffset = 0;
268 SIZE sz;
269 COLORREF rgb;
270 HPEN hPen = NULL, hOldPen = NULL;
271 BOOL bHighlightedText = (nSelFrom < nChars && nSelTo >= 0
272 && nSelFrom < nSelTo && !c->editor->bHideSelection);
273 int xSelStart = x, xSelEnd = x;
274 int *lpDx = NULL;
275 /* lpDx is only needed for tabs to make sure the underline done automatically
276 * by the font extends to the end of the tab. Tabs are always stored as
277 * a single character run, so we can handle this case separately, since
278 * otherwise lpDx would need to specify the lengths of each character. */
279 if (width && nChars == 1)
280 lpDx = &width; /* Make sure underline for tab extends across tab space */
281
282 hOldFont = ME_SelectStyleFont(c, s);
283 if ((s->fmt.dwMask & s->fmt.dwEffects) & CFM_OFFSET) {
284 yTwipsOffset = s->fmt.yOffset;
285 }
286 if ((s->fmt.dwMask & s->fmt.dwEffects) & (CFM_SUPERSCRIPT | CFM_SUBSCRIPT)) {
287 if (s->fmt.dwEffects & CFE_SUPERSCRIPT) yTwipsOffset = s->fmt.yHeight/3;
288 if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
289 }
290 if (yTwipsOffset)
291 yOffset = ME_twips2pointsY(c, yTwipsOffset);
292
293 if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
294 rgb = RGB(0,0,255);
295 else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
296 rgb = GetSysColor(COLOR_WINDOWTEXT);
297 else
298 rgb = s->fmt.crTextColor;
299
300 /* Determine the area that is selected in the run. */
301 GetTextExtentPoint32W(hDC, szText, nChars, &sz);
302 /* Treat width as an optional parameter. We can get the width from the
303 * text extent of the string if it isn't specified. */
304 if (!width) width = sz.cx;
305 if (bHighlightedText)
306 {
307 if (nSelFrom <= 0)
308 {
309 nSelFrom = 0;
310 }
311 else
312 {
313 GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
314 xSelStart = x + sz.cx;
315 }
316 if (nSelTo >= nChars)
317 {
318 nSelTo = nChars;
319 xSelEnd = x + width;
320 }
321 else
322 {
323 GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
324 xSelEnd = xSelStart + sz.cx;
325 }
326 }
327
328 /* Choose the pen type for underlining the text. */
329 if (s->fmt.dwMask & CFM_UNDERLINETYPE)
330 {
331 switch (s->fmt.bUnderlineType)
332 {
333 case CFU_UNDERLINE:
334 case CFU_UNDERLINEWORD: /* native seems to map it to simple underline (MSDN) */
335 case CFU_UNDERLINEDOUBLE: /* native seems to map it to simple underline (MSDN) */
336 hPen = CreatePen(PS_SOLID, 1, rgb);
337 break;
338 case CFU_UNDERLINEDOTTED:
339 hPen = CreatePen(PS_DOT, 1, rgb);
340 break;
341 default:
342 WINE_FIXME("Unknown underline type (%u)\n", s->fmt.bUnderlineType);
343 /* fall through */
344 case CFU_CF1UNDERLINE: /* this type is supported in the font, do nothing */
345 case CFU_UNDERLINENONE:
346 hPen = NULL;
347 break;
348 }
349 if (hPen)
350 {
351 hOldPen = SelectObject(hDC, hPen);
352 }
353 }
354
355 rgbOld = SetTextColor(hDC, rgb);
356 if (bHighlightedText && !c->editor->bEmulateVersion10)
357 {
358 COLORREF rgbBackOld;
359 RECT dim;
360 /* FIXME: should use textmetrics info for Descent info */
361 if (hPen)
362 MoveToEx(hDC, x, y - yOffset + 1, NULL);
363 if (xSelStart > x)
364 {
365 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nSelFrom, NULL);
366 if (hPen)
367 LineTo(hDC, xSelStart, y - yOffset + 1);
368 }
369 dim.top = ymin;
370 dim.bottom = ymin + cy;
371 dim.left = xSelStart;
372 dim.right = xSelEnd;
373 SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
374 rgbBackOld = SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
375 ExtTextOutW(hDC, xSelStart, y-yOffset, ETO_OPAQUE, &dim,
376 szText+nSelFrom, nSelTo-nSelFrom, lpDx);
377 if (hPen)
378 LineTo(hDC, xSelEnd, y - yOffset + 1);
379 SetBkColor(hDC, rgbBackOld);
380 if (xSelEnd < x + width)
381 {
382 SetTextColor(hDC, rgb);
383 ExtTextOutW(hDC, xSelEnd, y-yOffset, 0, NULL, szText+nSelTo,
384 nChars-nSelTo, NULL);
385 if (hPen)
386 LineTo(hDC, x + width, y - yOffset + 1);
387 }
388 }
389 else
390 {
391 ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, lpDx);
392
393 /* FIXME: should use textmetrics info for Descent info */
394 if (hPen)
395 {
396 MoveToEx(hDC, x, y - yOffset + 1, NULL);
397 LineTo(hDC, x + width, y - yOffset + 1);
398 }
399
400 if (bHighlightedText) /* v1.0 inverts the selection */
401 {
402 PatBlt(hDC, xSelStart, ymin, xSelEnd-xSelStart, cy, DSTINVERT);
403 }
404 }
405
406 if (hPen)
407 {
408 SelectObject(hDC, hOldPen);
409 DeleteObject(hPen);
410 }
411 SetTextColor(hDC, rgbOld);
412 ME_UnselectStyleFont(c, s, hOldFont);
413 }
414
415 static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) {
416 int align = SetTextAlign(hDC, TA_LEFT|TA_TOP);
417 HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
418 COLORREF color = SetTextColor(hDC, RGB(128,128,128));
419 TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText));
420 SelectObject(hDC, hFont);
421 SetTextAlign(hDC, align);
422 SetTextColor(hDC, color);
423 }
424
425 static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para)
426 {
427 ME_Run *run = &rundi->member.run;
428 ME_DisplayItem *start;
429 int runofs = run->nCharOfs+para->nCharOfs;
430 int nSelFrom, nSelTo;
431 const WCHAR wszSpace[] = {' ', 0};
432
433 if (run->nFlags & MERF_HIDDEN)
434 return;
435
436 start = ME_FindItemBack(rundi, diStartRow);
437 ME_GetSelection(c->editor, &nSelFrom, &nSelTo);
438
439 /* Draw selected end-of-paragraph mark */
440 /* you can always comment it out if you need visible paragraph marks */
441 if (run->nFlags & MERF_ENDPARA)
442 {
443 if (runofs >= nSelFrom && runofs < nSelTo)
444 {
445 ME_HighlightSpace(c, x, y, wszSpace, 1, run->style, 0, 0, 1,
446 c->pt.y + start->member.row.pt.y,
447 start->member.row.nHeight);
448 }
449 return;
450 }
451
452 if (run->nFlags & (MERF_TAB | MERF_ENDCELL))
453 {
454 /* wszSpace is used instead of the tab character because otherwise
455 * an unwanted symbol can be inserted instead. */
456 ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, run->nWidth,
457 nSelFrom-runofs,nSelTo-runofs,
458 c->pt.y + start->member.row.pt.y,
459 start->member.row.nHeight);
460 return;
461 }
462
463 if (run->nFlags & MERF_GRAPHICS)
464 ME_DrawOLE(c, x, y, run, para, (runofs >= nSelFrom) && (runofs < nSelTo));
465 else
466 {
467 if (c->editor->cPasswordMask)
468 {
469 ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText));
470 ME_DrawTextWithStyle(c, x, y,
471 szMasked->szData, ME_StrVLen(szMasked), run->style, run->nWidth,
472 nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.pt.y, start->member.row.nHeight);
473 ME_DestroyString(szMasked);
474 }
475 else
476 ME_DrawTextWithStyle(c, x, y,
477 run->strText->szData, ME_StrVLen(run->strText), run->style, run->nWidth,
478 nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.pt.y, start->member.row.nHeight);
479 }
480 }
481
482 static const struct {unsigned width_num : 4, width_den : 4, pen_style : 4, dble : 1;} border_details[] = {
483 /* none */ {0, 1, PS_SOLID, FALSE},
484 /* 3/4 */ {3, 4, PS_SOLID, FALSE},
485 /* 1 1/2 */ {3, 2, PS_SOLID, FALSE},
486 /* 2 1/4 */ {9, 4, PS_SOLID, FALSE},
487 /* 3 */ {3, 1, PS_SOLID, FALSE},
488 /* 4 1/2 */ {9, 2, PS_SOLID, FALSE},
489 /* 6 */ {6, 1, PS_SOLID, FALSE},
490 /* 3/4 double */ {3, 4, PS_SOLID, TRUE},
491 /* 1 1/2 double */ {3, 2, PS_SOLID, TRUE},
492 /* 2 1/4 double */ {9, 4, PS_SOLID, TRUE},
493 /* 3/4 gray */ {3, 4, PS_DOT /* FIXME */, FALSE},
494 /* 1 1/2 dashed */ {3, 2, PS_DASH, FALSE},
495 };
496
497 static const COLORREF pen_colors[16] = {
498 /* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
499 /* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
500 /* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
501 /* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
502 /* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
503 /* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
504 /* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
505 /* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
506 };
507
508 static int ME_GetBorderPenWidth(ME_TextEditor* editor, int idx)
509 {
510 int width;
511
512 if (editor->nZoomNumerator == 0)
513 {
514 width = border_details[idx].width_num + border_details[idx].width_den / 2;
515 width /= border_details[idx].width_den;
516 }
517 else
518 {
519 width = border_details[idx].width_num * editor->nZoomNumerator;
520 width += border_details[idx].width_den * editor->nZoomNumerator / 2;
521 width /= border_details[idx].width_den * editor->nZoomDenominator;
522 }
523 return width;
524 }
525
526 int ME_GetParaBorderWidth(ME_TextEditor* editor, int flags)
527 {
528 int idx = (flags >> 8) & 0xF;
529 int width;
530
531 if (idx >= sizeof(border_details) / sizeof(border_details[0]))
532 {
533 FIXME("Unsupported border value %d\n", idx);
534 return 0;
535 }
536 width = ME_GetBorderPenWidth(editor, idx);
537 if (border_details[idx].dble) width = width * 2 + 1;
538 return width;
539 }
540
541 int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
542 {
543 int sp = 0, ls = 0;
544 if (!(para->pFmt->dwMask & PFM_LINESPACING)) return 0;
545
546 /* FIXME: how to compute simply the line space in ls ??? */
547 /* FIXME: does line spacing include the line itself ??? */
548 switch (para->pFmt->bLineSpacingRule)
549 {
550 case 0: sp = ls; break;
551 case 1: sp = (3 * ls) / 2; break;
552 case 2: sp = 2 * ls; break;
553 case 3: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); if (sp < ls) sp = ls; break;
554 case 4: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); break;
555 case 5: sp = para->pFmt->dyLineSpacing / 20; break;
556 default: FIXME("Unsupported spacing rule value %d\n", para->pFmt->bLineSpacingRule);
557 }
558 if (c->editor->nZoomNumerator == 0)
559 return sp;
560 else
561 return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
562 }
563
564 static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT* bounds)
565 {
566 int idx, border_width, top_border, bottom_border;
567 RECT rc;
568 BOOL hasParaBorder;
569
570 SetRectEmpty(bounds);
571 if (!(para->pFmt->dwMask & (PFM_BORDER | PFM_SPACEBEFORE | PFM_SPACEAFTER))) return;
572
573 border_width = top_border = bottom_border = 0;
574 idx = (para->pFmt->wBorders >> 8) & 0xF;
575 hasParaBorder = (!(c->editor->bEmulateVersion10 &&
576 para->pFmt->dwMask & PFM_TABLE &&
577 para->pFmt->wEffects & PFE_TABLE) &&
578 (para->pFmt->dwMask & PFM_BORDER) &&
579 idx != 0 &&
580 (para->pFmt->wBorders & 0xF));
581 if (hasParaBorder)
582 {
583 /* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
584 * controls. It actually stores the paragraph or row border style. Although
585 * the value isn't used for drawing, it is used for streaming out rich text.
586 *
587 * wBorders stores the border style for each side (top, left, bottom, right)
588 * using nibble (4 bits) to store each border style. The rich text format
589 * control words, and their associated value are the following:
590 * \brdrdash 0
591 * \brdrdashsm 1
592 * \brdrdb 2
593 * \brdrdot 3
594 * \brdrhair 4
595 * \brdrs 5
596 * \brdrth 6
597 * \brdrtriple 7
598 *
599 * The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
600 * The mask corresponding to each side for the version are the following:
601 * mask v1.0-3.0 v4.1
602 * 0x000F top left
603 * 0x00F0 left top
604 * 0x0F00 bottom right
605 * 0xF000 right bottom
606 */
607 if (para->pFmt->wBorders & 0x00B0)
608 FIXME("Unsupported border flags %x\n", para->pFmt->wBorders);
609 border_width = ME_GetParaBorderWidth(c->editor, para->pFmt->wBorders);
610 if (para->pFmt->wBorders & 4) top_border = border_width;
611 if (para->pFmt->wBorders & 8) bottom_border = border_width;
612 }
613
614 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
615 {
616 rc.left = c->rcView.left;
617 rc.right = c->rcView.right;
618 rc.top = y;
619 bounds->top = ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
620 rc.bottom = y + bounds->top + top_border;
621 FillRect(c->hDC, &rc, c->editor->hbrBackground);
622 }
623
624 if (para->pFmt->dwMask & PFM_SPACEAFTER)
625 {
626 rc.left = c->rcView.left;
627 rc.right = c->rcView.right;
628 rc.bottom = y + para->nHeight;
629 bounds->bottom = ME_twips2pointsY(c, para->pFmt->dySpaceAfter);
630 rc.top = rc.bottom - bounds->bottom - bottom_border;
631 FillRect(c->hDC, &rc, c->editor->hbrBackground);
632 }
633
634 /* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
635 * but might support it in later versions. */
636 if (hasParaBorder) {
637 int pen_width;
638 COLORREF pencr;
639 HPEN pen = NULL, oldpen = NULL;
640 POINT pt;
641
642 if (para->pFmt->wBorders & 64) /* autocolor */
643 pencr = GetSysColor(COLOR_WINDOWTEXT);
644 else
645 pencr = pen_colors[(para->pFmt->wBorders >> 12) & 0xF];
646
647 pen_width = ME_GetBorderPenWidth(c->editor, idx);
648 pen = CreatePen(border_details[idx].pen_style, pen_width, pencr);
649 oldpen = SelectObject(c->hDC, pen);
650 MoveToEx(c->hDC, 0, 0, &pt);
651
652 /* before & after spaces are not included in border */
653
654 /* helper to draw the double lines in case of corner */
655 #define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
656
657 if (para->pFmt->wBorders & 1)
658 {
659 MoveToEx(c->hDC, c->rcView.left, y + bounds->top, NULL);
660 LineTo(c->hDC, c->rcView.left, y + para->nHeight - bounds->bottom);
661 if (border_details[idx].dble) {
662 rc.left = c->rcView.left + 1;
663 rc.right = rc.left + border_width;
664 rc.top = y + bounds->top;
665 rc.bottom = y + para->nHeight - bounds->bottom;
666 FillRect(c->hDC, &rc, c->editor->hbrBackground);
667 MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + bounds->top + DD(4), NULL);
668 LineTo(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - bounds->bottom - DD(8));
669 }
670 bounds->left += border_width;
671 }
672 if (para->pFmt->wBorders & 2)
673 {
674 MoveToEx(c->hDC, c->rcView.right - 1, y + bounds->top, NULL);
675 LineTo(c->hDC, c->rcView.right - 1, y + para->nHeight - bounds->bottom);
676 if (border_details[idx].dble) {
677 rc.left = c->rcView.right - pen_width - 1;
678 rc.right = c->rcView.right - 1;
679 rc.top = y + bounds->top;
680 rc.bottom = y + para->nHeight - bounds->bottom;
681 FillRect(c->hDC, &rc, c->editor->hbrBackground);
682 MoveToEx(c->hDC, c->rcView.right - 1 - pen_width - 1, y + bounds->top + DD(4), NULL);
683 LineTo(c->hDC, c->rcView.right - 1 - pen_width - 1, y + para->nHeight - bounds->bottom - DD(8));
684 }
685 bounds->right += border_width;
686 }
687 if (para->pFmt->wBorders & 4)
688 {
689 MoveToEx(c->hDC, c->rcView.left, y + bounds->top, NULL);
690 LineTo(c->hDC, c->rcView.right, y + bounds->top);
691 if (border_details[idx].dble) {
692 MoveToEx(c->hDC, c->rcView.left + DD(1), y + bounds->top + pen_width + 1, NULL);
693 LineTo(c->hDC, c->rcView.right - DD(2), y + bounds->top + pen_width + 1);
694 }
695 bounds->top += border_width;
696 }
697 if (para->pFmt->wBorders & 8)
698 {
699 MoveToEx(c->hDC, c->rcView.left, y + para->nHeight - bounds->bottom - 1, NULL);
700 LineTo(c->hDC, c->rcView.right, y + para->nHeight - bounds->bottom - 1);
701 if (border_details[idx].dble) {
702 MoveToEx(c->hDC, c->rcView.left + DD(1), y + para->nHeight - bounds->bottom - 1 - pen_width - 1, NULL);
703 LineTo(c->hDC, c->rcView.right - DD(2), y + para->nHeight - bounds->bottom - 1 - pen_width - 1);
704 }
705 bounds->bottom += border_width;
706 }
707 #undef DD
708
709 MoveToEx(c->hDC, pt.x, pt.y, NULL);
710 SelectObject(c->hDC, oldpen);
711 DeleteObject(pen);
712 }
713 }
714
715 static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
716 {
717 ME_Paragraph *para = ¶graph->member.para;
718 if (!c->editor->bEmulateVersion10) /* v4.1 */
719 {
720 if (para->pCell)
721 {
722 RECT rc;
723 ME_Cell *cell = ¶->pCell->member.cell;
724 ME_DisplayItem *paraAfterRow;
725 HPEN pen, oldPen;
726 LOGBRUSH logBrush;
727 HBRUSH brush;
728 COLORREF color;
729 POINT oldPt;
730 int width;
731 BOOL atTop = (para->pCell != para->prev_para->member.para.pCell);
732 BOOL atBottom = (para->pCell != para->next_para->member.para.pCell);
733 int top = (atTop ? cell->pt.y : para->pt.y) - ME_GetYScrollPos(c->editor);
734 int bottom = (atBottom ?
735 cell->pt.y + cell->nHeight - ME_GetYScrollPos(c->editor):
736 top + para->nHeight + (atTop ? cell->yTextOffset : 0));
737 rc.left = cell->pt.x;
738 rc.right = rc.left + cell->nWidth;
739 if (atTop) {
740 /* Erase gap before text if not all borders are the same height. */
741 width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
742 rc.top = top + width;
743 width = cell->yTextOffset - width;
744 rc.bottom = rc.top + width;
745 if (width) {
746 FillRect(c->hDC, &rc, c->editor->hbrBackground);
747 }
748 }
749 /* Draw cell borders.
750 * The borders 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)) {
754 rc.top = top;
755 rc.bottom = bottom;
756 if (cell->border.left.width > 0)
757 {
758 color = cell->border.left.colorRef;
759 width = max(ME_twips2pointsX(c, cell->border.left.width), 1);
760 } else {
761 color = RGB(192,192,192);
762 width = 1;
763 }
764 logBrush.lbStyle = BS_SOLID;
765 logBrush.lbColor = color;
766 logBrush.lbHatch = 0;
767 pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
768 width, &logBrush, 0, NULL);
769 oldPen = SelectObject(c->hDC, pen);
770 MoveToEx(c->hDC, rc.left, rc.top, &oldPt);
771 LineTo(c->hDC, rc.left, rc.bottom);
772 SelectObject(c->hDC, oldPen);
773 DeleteObject(pen);
774 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
775 }
776
777 if (atTop) {
778 if (cell->border.top.width > 0)
779 {
780 brush = CreateSolidBrush(cell->border.top.colorRef);
781 width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
782 } else {
783 brush = GetStockObject(LTGRAY_BRUSH);
784 width = 1;
785 }
786 rc.top = top;
787 rc.bottom = rc.top + width;
788 FillRect(c->hDC, &rc, brush);
789 if (cell->border.top.width > 0)
790 DeleteObject(brush);
791 }
792
793 /* Draw the bottom border if at the last paragraph in the cell, and when
794 * in the last row of the table. */
795 if (atBottom) {
796 int oldLeft = rc.left;
797 width = max(ME_twips2pointsY(c, cell->border.bottom.width), 1);
798 paraAfterRow = ME_GetTableRowEnd(paragraph)->member.para.next_para;
799 if (paraAfterRow->member.para.nFlags & MEPF_ROWSTART) {
800 ME_DisplayItem *nextEndCell;
801 nextEndCell = ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow), diCell);
802 assert(nextEndCell && !nextEndCell->member.cell.next_cell);
803 rc.left = nextEndCell->member.cell.pt.x;
804 /* FIXME: Native draws FROM the bottom of the table rather than
805 * TO the bottom of the table in this case, but just doing so here
806 * will case the next row to erase the border. */
807 /*
808 rc.top = bottom;
809 rc.bottom = rc.top + width;
810 */
811 }
812 if (rc.left < rc.right) {
813 if (cell->border.bottom.width > 0) {
814 brush = CreateSolidBrush(cell->border.bottom.colorRef);
815 } else {
816 brush = GetStockObject(LTGRAY_BRUSH);
817 }
818 rc.bottom = bottom;
819 rc.top = rc.bottom - width;
820 FillRect(c->hDC, &rc, brush);
821 if (cell->border.bottom.width > 0)
822 DeleteObject(brush);
823 }
824 rc.left = oldLeft;
825 }
826
827 /* Right border only drawn if at the end of the table row. */
828 if (!cell->next_cell->member.cell.next_cell &&
829 !(para->nFlags & MEPF_ROWSTART))
830 {
831 rc.top = top;
832 rc.bottom = bottom;
833 if (cell->border.right.width > 0) {
834 color = cell->border.right.colorRef;
835 width = max(ME_twips2pointsX(c, cell->border.right.width), 1);
836 } else {
837 color = RGB(192,192,192);
838 width = 1;
839 }
840 logBrush.lbStyle = BS_SOLID;
841 logBrush.lbColor = color;
842 logBrush.lbHatch = 0;
843 pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
844 width, &logBrush, 0, NULL);
845 oldPen = SelectObject(c->hDC, pen);
846 MoveToEx(c->hDC, rc.right - 1, rc.top, &oldPt);
847 LineTo(c->hDC, rc.right - 1, rc.bottom);
848 SelectObject(c->hDC, oldPen);
849 DeleteObject(pen);
850 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
851 }
852 }
853 } else { /* v1.0 - 3.0 */
854 /* Draw simple table border */
855 if (para->pFmt->dwMask & PFM_TABLE && para->pFmt->wEffects & PFE_TABLE) {
856 HPEN pen = NULL, oldpen = NULL;
857 int i, firstX, startX, endX, rowY, rowBottom, nHeight;
858 POINT oldPt;
859 PARAFORMAT2 *pNextFmt;
860
861 pen = CreatePen(PS_SOLID, 0, para->border.top.colorRef);
862 oldpen = SelectObject(c->hDC, pen);
863
864 /* Find the start relative to the text */
865 firstX = ME_FindItemFwd(paragraph, diRun)->member.run.pt.x;
866 /* Go back by the horizontal gap, which is stored in dxOffset */
867 firstX -= ME_twips2pointsX(c, para->pFmt->dxOffset);
868 /* The left edge, stored in dxStartIndent affected just the first edge */
869 startX = firstX - ME_twips2pointsX(c, para->pFmt->dxStartIndent);
870 rowY = c->pt.y;
871 if (para->pFmt->dwMask & PFM_SPACEBEFORE)
872 rowY += ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
873 nHeight = ME_FindItemFwd(paragraph, diStartRow)->member.row.nHeight;
874 rowBottom = rowY + nHeight;
875
876 /* Draw horizontal lines */
877 MoveToEx(c->hDC, firstX, rowY, &oldPt);
878 i = para->pFmt->cTabCount - 1;
879 endX = startX + ME_twips2pointsX(c, para->pFmt->rgxTabs[i] & 0x00ffffff) + 1;
880 LineTo(c->hDC, endX, rowY);
881 pNextFmt = para->next_para->member.para.pFmt;
882 /* The bottom of the row only needs to be drawn if the next row is
883 * not a table. */
884 if (!(pNextFmt && pNextFmt->dwMask & PFM_TABLE && pNextFmt->wEffects &&
885 para->nRows == 1))
886 {
887 /* Decrement rowBottom to draw the bottom line within the row, and
888 * to not draw over this line when drawing the vertical lines. */
889 rowBottom--;
890 MoveToEx(c->hDC, firstX, rowBottom, NULL);
891 LineTo(c->hDC, endX, rowBottom);
892 }
893
894 /* Draw vertical lines */
895 MoveToEx(c->hDC, firstX, rowY, NULL);
896 LineTo(c->hDC, firstX, rowBottom);
897 for (i = 0; i < para->pFmt->cTabCount; i++)
898 {
899 int rightBoundary = para->pFmt->rgxTabs[i] & 0x00ffffff;
900 endX = startX + ME_twips2pointsX(c, rightBoundary);
901 MoveToEx(c->hDC, endX, rowY, NULL);
902 LineTo(c->hDC, endX, rowBottom);
903 }
904
905 MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
906 SelectObject(c->hDC, oldpen);
907 DeleteObject(pen);
908 }
909 }
910 }
911
912 void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
913 int align = SetTextAlign(c->hDC, TA_BASELINE);
914 ME_DisplayItem *p;
915 ME_Run *run;
916 ME_Paragraph *para = NULL;
917 RECT rc, bounds;
918 int y = c->pt.y;
919 int height = 0, baseline = 0, no=0;
920 BOOL visible = FALSE;
921
922 c->pt.x = c->rcView.left;
923 rc.left = c->rcView.left;
924 rc.right = c->rcView.right;
925 for (p = paragraph; p!=paragraph->member.para.next_para; p = p->next) {
926 switch(p->type) {
927 case diParagraph:
928 para = &p->member.para;
929 assert(para);
930 if (para->pCell)
931 {
932 ME_Cell *cell = ¶->pCell->member.cell;
933 rc.left = cell->pt.x;
934 rc.right = rc.left + cell->nWidth;
935 }
936 if (para->nFlags & MEPF_ROWSTART) {
937 ME_Cell *cell = ¶->next_para->member.para.pCell->member.cell;
938 rc.right = cell->pt.x;
939 } else if (para->nFlags & MEPF_ROWEND) {
940 ME_Cell *cell = ¶->prev_para->member.para.pCell->member.cell;
941 rc.left = cell->pt.x + cell->nWidth;
942 }
943 ME_DrawParaDecoration(c, para, y, &bounds);
944 y += bounds.top;
945 break;
946 case diStartRow:
947 /* we should have seen a diParagraph before */
948 assert(para);
949 y += height;
950 rc.top = y;
951 if (para->nFlags & MEPF_ROWSTART) {
952 ME_Cell *cell = ¶->next_para->member.para.pCell->member.cell;
953 rc.bottom = y + cell->nHeight;
954 } else if (para->nFlags & MEPF_ROWEND) {
955 ME_Cell *cell = ¶->prev_para->member.para.pCell->member.cell;
956 rc.bottom = y + cell->nHeight;
957 } else {
958 rc.bottom = y+p->member.row.nHeight;
959 }
960 visible = RectVisible(c->hDC, &rc);
961 if (visible) {
962 FillRect(c->hDC, &rc, c->editor->hbrBackground);
963 }
964 if (me_debug)
965 {
966 const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
967 WCHAR buf[128];
968 POINT pt = c->pt;
969 wsprintfW(buf, wszRowDebug, no);
970 pt.y = 12+y;
971 ME_DebugWrite(c->hDC, &pt, buf);
972 }
973
974 height = p->member.row.nHeight;
975 baseline = p->member.row.nBaseline;
976 break;
977 case diRun:
978 assert(para);
979 run = &p->member.run;
980 if (visible && me_debug) {
981 rc.left = c->rcView.left+run->pt.x;
982 rc.right = c->rcView.left+run->pt.x+run->nWidth;
983 rc.top = c->pt.y+run->pt.y;
984 rc.bottom = c->pt.y+run->pt.y+height;
985 TRACE("rc = (%d, %d, %d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
986 if (run->nFlags & MERF_SKIPPED)
987 DrawFocusRect(c->hDC, &rc);
988 else
989 FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
990 }
991 if (visible)
992 ME_DrawRun(c, run->pt.x, c->pt.y+run->pt.y+baseline, p, ¶graph->member.para);
993 if (me_debug)
994 {
995 /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
996 const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
997 WCHAR buf[2560];
998 POINT pt;
999 pt.x = run->pt.x;
1000 pt.y = c->pt.y + run->pt.y;
1001 wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
1002 ME_DebugWrite(c->hDC, &pt, buf);
1003 }
1004 /* c->pt.x += p->member.run.nWidth; */
1005 break;
1006 case diCell:
1007 /* Clear any space at the bottom of the cell after the text. */
1008 if (para->nFlags & MEPF_ROWSTART)
1009 break;
1010 y += height;
1011 rc.top = y;
1012 rc.bottom = p->member.cell.pt.y + p->member.cell.nHeight
1013 - ME_GetYScrollPos(c->editor);
1014 if (RectVisible(c->hDC, &rc))
1015 {
1016 FillRect(c->hDC, &rc, c->editor->hbrBackground);
1017 }
1018 break;
1019 default:
1020 break;
1021 }
1022 no++;
1023 }
1024
1025 ME_DrawTableBorders(c, paragraph);
1026
1027 SetTextAlign(c->hDC, align);
1028 }
1029
1030 void ME_ScrollAbs(ME_TextEditor *editor, int absY)
1031 {
1032 ME_Scroll(editor, absY, 1);
1033 }
1034
1035 void ME_ScrollUp(ME_TextEditor *editor, int cy)
1036 {
1037 ME_Scroll(editor, cy, 2);
1038 }
1039
1040 void ME_ScrollDown(ME_TextEditor *editor, int cy)
1041 {
1042 ME_Scroll(editor, cy, 3);
1043 }
1044
1045 void ME_Scroll(ME_TextEditor *editor, int value, int type)
1046 {
1047 SCROLLINFO si;
1048 int nOrigPos, nNewPos, nActualScroll;
1049 HWND hWnd;
1050 LONG winStyle;
1051 BOOL bScrollBarIsVisible, bScrollBarWillBeVisible;
1052
1053 nOrigPos = ME_GetYScrollPos(editor);
1054
1055 si.cbSize = sizeof(SCROLLINFO);
1056 si.fMask = SIF_POS;
1057
1058 switch (type)
1059 {
1060 case 1:
1061 /*Scroll absolutely*/
1062 si.nPos = value;
1063 break;
1064 case 2:
1065 /* Scroll up - towards the beginning of the document */
1066 si.nPos = nOrigPos - value;
1067 break;
1068 case 3:
1069 /* Scroll down - towards the end of the document */
1070 si.nPos = nOrigPos + value;
1071 break;
1072 default:
1073 FIXME("ME_Scroll called incorrectly\n");
1074 si.nPos = 0;
1075 }
1076
1077 nNewPos = SetScrollInfo(editor->hWnd, SB_VERT, &si, editor->bRedraw);
1078 editor->vert_si.nPos = nNewPos;
1079 nActualScroll = nOrigPos - nNewPos;
1080 if (editor->bRedraw)
1081 {
1082 if (abs(nActualScroll) > editor->sizeWindow.cy)
1083 InvalidateRect(editor->hWnd, NULL, TRUE);
1084 else
1085 ScrollWindowEx(editor->hWnd, 0, nActualScroll, NULL, NULL, NULL, NULL, SW_INVALIDATE);
1086 ME_Repaint(editor);
1087 }
1088
1089 hWnd = editor->hWnd;
1090 winStyle = GetWindowLongW(hWnd, GWL_STYLE);
1091 bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0;
1092 bScrollBarWillBeVisible = (editor->nHeight > editor->sizeWindow.cy)
1093 || (winStyle & ES_DISABLENOSCROLL);
1094 if (bScrollBarIsVisible != bScrollBarWillBeVisible)
1095 {
1096 ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible);
1097 }
1098 ME_UpdateScrollBar(editor);
1099 }
1100
1101
1102 void ME_UpdateScrollBar(ME_TextEditor *editor)
1103 {
1104 /* Note that this is the only function that should ever call SetScrolLInfo
1105 * with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
1106 * be used at all. */
1107
1108 HWND hWnd;
1109 SCROLLINFO si;
1110 BOOL bScrollBarWasVisible,bScrollBarWillBeVisible;
1111
1112 if (ME_WrapMarkedParagraphs(editor))
1113 FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
1114
1115 hWnd = editor->hWnd;
1116 si.cbSize = sizeof(si);
1117 bScrollBarWasVisible = ME_GetYScrollVisible(editor);
1118 bScrollBarWillBeVisible = editor->nHeight > editor->sizeWindow.cy;
1119
1120 si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
1121 if (GetWindowLongW(hWnd, GWL_STYLE) & ES_DISABLENOSCROLL)
1122 {
1123 si.fMask |= SIF_DISABLENOSCROLL;
1124 bScrollBarWillBeVisible = TRUE;
1125 }
1126
1127 if (bScrollBarWasVisible != bScrollBarWillBeVisible)
1128 {
1129 ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible);
1130 ME_MarkAllForWrapping(editor);
1131 ME_WrapMarkedParagraphs(editor);
1132 }
1133
1134 si.nMin = 0;
1135 si.nMax = editor->nTotalLength;
1136 si.nPos = editor->vert_si.nPos;
1137 si.nPage = editor->sizeWindow.cy;
1138
1139 if (!(si.nMin == editor->vert_si.nMin && si.nMax == editor->vert_si.nMax && si.nPage == editor->vert_si.nPage))
1140 {
1141 TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
1142 editor->vert_si.nMin = si.nMin;
1143 editor->vert_si.nMax = si.nMax;
1144 editor->vert_si.nPage = si.nPage;
1145 if (bScrollBarWillBeVisible)
1146 {
1147 SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
1148 }
1149 else
1150 {
1151 if (bScrollBarWasVisible && !(si.fMask & SIF_DISABLENOSCROLL))
1152 {
1153 SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
1154 ShowScrollBar(hWnd, SB_VERT, FALSE);
1155 ME_ScrollAbs(editor, 0);
1156 }
1157 }
1158 }
1159 }
1160
1161 int ME_GetYScrollPos(ME_TextEditor *editor)
1162 {
1163 return editor->vert_si.nPos;
1164 }
1165
1166 BOOL ME_GetYScrollVisible(ME_TextEditor *editor)
1167 { /* Returns true if the scrollbar is visible */
1168 return (editor->vert_si.nMax - editor->vert_si.nMin >= max(editor->vert_si.nPage - 1, 0));
1169 }
1170
1171 void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun)
1172 {
1173 ME_DisplayItem *pRow = ME_FindItemBack(pRun, diStartRow);
1174 ME_DisplayItem *pPara = ME_FindItemBack(pRun, diParagraph);
1175 int y, yrel, yheight, yold;
1176
1177 assert(pRow);
1178 assert(pPara);
1179
1180 y = pPara->member.para.pt.y+pRow->member.row.pt.y;
1181 yheight = pRow->member.row.nHeight;
1182 yold = ME_GetYScrollPos(editor);
1183 yrel = y - yold;
1184
1185 if (y < yold)
1186 ME_ScrollAbs(editor,y);
1187 else if (yrel + yheight > editor->sizeWindow.cy)
1188 ME_ScrollAbs(editor,y+yheight-editor->sizeWindow.cy);
1189 }
1190
1191
1192 void
1193 ME_InvalidateFromOfs(ME_TextEditor *editor, int nCharOfs)
1194 {
1195 RECT rc;
1196 int x, y, height;
1197 ME_Cursor tmp;
1198
1199 ME_RunOfsFromCharOfs(editor, nCharOfs, &tmp.pRun, &tmp.nOffset);
1200 ME_GetCursorCoordinates(editor, &tmp, &x, &y, &height);
1201
1202 rc.left = 0;
1203 rc.top = y;
1204 rc.bottom = y + height;
1205 rc.right = editor->rcFormat.right;
1206 InvalidateRect(editor->hWnd, &rc, FALSE);
1207 }
1208
1209
1210 void
1211 ME_InvalidateSelection(ME_TextEditor *editor)
1212 {
1213 ME_DisplayItem *para1, *para2;
1214 int nStart, nEnd;
1215 int len = ME_GetTextLength(editor);
1216
1217 ME_GetSelection(editor, &nStart, &nEnd);
1218 /* if both old and new selection are 0-char (= caret only), then
1219 there's no (inverted) area to be repainted, neither old nor new */
1220 if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
1221 return;
1222 ME_WrapMarkedParagraphs(editor);
1223 ME_GetSelectionParas(editor, ¶1, ¶2);
1224 assert(para1->type == diParagraph);
1225 assert(para2->type == diParagraph);
1226 /* last selection markers aren't always updated, which means
1227 they can point past the end of the document */
1228 if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
1229 ME_MarkForPainting(editor,
1230 ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph),
1231 ME_FindItemFwd(editor->pBuffer->pFirst, diTextEnd));
1232 } else {
1233 /* if the start part of selection is being expanded or contracted... */
1234 if (nStart < editor->nLastSelStart) {
1235 ME_MarkForPainting(editor, para1, ME_FindItemFwd(editor->pLastSelStartPara, diParagraphOrEnd));
1236 } else
1237 if (nStart > editor->nLastSelStart) {
1238 ME_MarkForPainting(editor, editor->pLastSelStartPara, ME_FindItemFwd(para1, diParagraphOrEnd));
1239 }
1240
1241 /* if the end part of selection is being contracted or expanded... */
1242 if (nEnd < editor->nLastSelEnd) {
1243 ME_MarkForPainting(editor, para2, ME_FindItemFwd(editor->pLastSelEndPara, diParagraphOrEnd));
1244 } else
1245 if (nEnd > editor->nLastSelEnd) {
1246 ME_MarkForPainting(editor, editor->pLastSelEndPara, ME_FindItemFwd(para2, diParagraphOrEnd));
1247 }
1248 }
1249
1250 ME_InvalidateMarkedParagraphs(editor);
1251 /* remember the last invalidated position */
1252 ME_GetSelection(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
1253 ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
1254 assert(editor->pLastSelStartPara->type == diParagraph);
1255 assert(editor->pLastSelEndPara->type == diParagraph);
1256 }
1257
1258 void
1259 ME_QueueInvalidateFromCursor(ME_TextEditor *editor, int nCursor)
1260 {
1261 editor->nInvalidOfs = ME_GetCursorOfs(editor, nCursor);
1262 }
1263
1264
1265 BOOL
1266 ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
1267 {
1268 /* TODO: Zoom images and objects */
1269
1270 if (numerator != 0)
1271 {
1272 if (denominator == 0)
1273 return FALSE;
1274 if (1.0 / 64.0 > (float)numerator / (float)denominator
1275 || (float)numerator / (float)denominator > 64.0)
1276 return FALSE;
1277 }
1278
1279 editor->nZoomNumerator = numerator;
1280 editor->nZoomDenominator = denominator;
1281
1282 ME_RewrapRepaint(editor);
1283 return TRUE;
1284 }
1285
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.