richedit: Added support for spaces above & below paragraphs.

This commit is contained in:
Eric Pouech 2008-01-01 22:04:52 +01:00 committed by Alexandre Julliard
parent caa37c749a
commit f1b029ef6a
2 changed files with 88 additions and 52 deletions

View File

@ -365,20 +365,46 @@ int ME_GetParaBorderWidth(ME_TextEditor* editor, int flags)
return width; return width;
} }
static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y) static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, int dpi)
{ {
HPEN pen, oldpen; int idx, border_width;
POINT pt; int ybefore, yafter;
int idx, pen_width, border_width; RECT rc;
COLORREF pencr;
if (!(para->pFmt->dwMask & PFM_BORDER)) return 0; if (!(para->pFmt->dwMask & (PFM_BORDER | PFM_SPACEBEFORE | PFM_SPACEAFTER))) return 0;
if (para->pFmt->dwMask & PFM_SPACEBEFORE)
{
rc.left = c->rcView.left;
rc.right = c->rcView.right;
rc.top = y;
ybefore = ME_twips2points(c, para->pFmt->dySpaceBefore, dpi);
rc.bottom = y + ybefore;
FillRect(c->hDC, &rc, c->editor->hbrBackground);
}
else ybefore = 0;
if (para->pFmt->dwMask & PFM_SPACEAFTER)
{
rc.left = c->rcView.left;
rc.right = c->rcView.right;
rc.bottom = y + para->nHeight;
yafter = ME_twips2points(c, para->pFmt->dySpaceAfter, dpi);
rc.top = rc.bottom - yafter;
FillRect(c->hDC, &rc, c->editor->hbrBackground);
}
else yafter = 0;
border_width = 0;
idx = (para->pFmt->wBorders >> 8) & 0xF;
if ((para->pFmt->dwMask & PFM_BORDER) && idx != 0 && (para->pFmt->wBorders & 0xF)) {
int pen_width;
COLORREF pencr;
HPEN pen = NULL, oldpen = NULL;
POINT pt;
if (para->pFmt->wBorders & 0x00B0) if (para->pFmt->wBorders & 0x00B0)
FIXME("Unsupported border flags %x\n", para->pFmt->wBorders); FIXME("Unsupported border flags %x\n", para->pFmt->wBorders);
border_width = ME_GetParaBorderWidth(c->editor, para->pFmt->wBorders); border_width = ME_GetParaBorderWidth(c->editor, para->pFmt->wBorders);
if (border_width == 0 || !(para->pFmt->wBorders & 0xF)) return 0;
idx = (para->pFmt->wBorders >> 8) & 0xF;
if (para->pFmt->wBorders & 64) /* autocolor */ if (para->pFmt->wBorders & 64) /* autocolor */
pencr = GetSysColor(COLOR_WINDOWTEXT); pencr = GetSysColor(COLOR_WINDOWTEXT);
@ -389,46 +415,52 @@ static int ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y)
pen = CreatePen(border_details[idx].pen_style, pen_width, pencr); pen = CreatePen(border_details[idx].pen_style, pen_width, pencr);
oldpen = SelectObject(c->hDC, pen); oldpen = SelectObject(c->hDC, pen);
MoveToEx(c->hDC, 0, 0, &pt); MoveToEx(c->hDC, 0, 0, &pt);
/* before & after spaces are not included in border */
if (para->pFmt->wBorders & 1) if (para->pFmt->wBorders & 1)
{ {
MoveToEx(c->hDC, c->rcView.left, y, NULL); MoveToEx(c->hDC, c->rcView.left, y + ybefore, NULL);
LineTo(c->hDC, c->rcView.left, y + para->nHeight); LineTo(c->hDC, c->rcView.left, y + para->nHeight - yafter);
if (border_details[idx].dble) { if (border_details[idx].dble) {
MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + pen_width + 1, NULL); MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + ybefore + pen_width + 1, NULL);
LineTo(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - pen_width - 1); LineTo(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - yafter - pen_width - 1);
} }
} }
if (para->pFmt->wBorders & 2) if (para->pFmt->wBorders & 2)
{ {
MoveToEx(c->hDC, c->rcView.right, y, NULL); MoveToEx(c->hDC, c->rcView.right, y + ybefore, NULL);
LineTo(c->hDC, c->rcView.right, y + para->nHeight); LineTo(c->hDC, c->rcView.right, y + para->nHeight - yafter);
if (border_details[idx].dble) { if (border_details[idx].dble) {
MoveToEx(c->hDC, c->rcView.right - pen_width - 1, y + pen_width + 1, NULL); MoveToEx(c->hDC, c->rcView.right - pen_width - 1, y + ybefore + pen_width + 1, NULL);
LineTo(c->hDC, c->rcView.right - pen_width - 1, y + para->nHeight - pen_width - 1); LineTo(c->hDC, c->rcView.right - pen_width - 1, y + para->nHeight - yafter - pen_width - 1);
} }
} }
if (para->pFmt->wBorders & 4) if (para->pFmt->wBorders & 4)
{ {
MoveToEx(c->hDC, c->rcView.left, y, NULL); MoveToEx(c->hDC, c->rcView.left, y + ybefore, NULL);
LineTo(c->hDC, c->rcView.right, y); LineTo(c->hDC, c->rcView.right, y + ybefore);
if (border_details[idx].dble) { if (border_details[idx].dble) {
MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + pen_width + 1, NULL); MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + ybefore + pen_width + 1, NULL);
LineTo(c->hDC, c->rcView.right - pen_width - 1, y + pen_width + 1); LineTo(c->hDC, c->rcView.right - pen_width - 1, y + ybefore + pen_width + 1);
} }
} }
if (para->pFmt->wBorders & 8) if (para->pFmt->wBorders & 8)
{ {
MoveToEx(c->hDC, c->rcView.left, y + para->nHeight - 1, NULL); MoveToEx(c->hDC, c->rcView.left, y + para->nHeight - yafter - 1, NULL);
LineTo(c->hDC, c->rcView.right, y + para->nHeight - 1); LineTo(c->hDC, c->rcView.right, y + para->nHeight - yafter - 1);
if (border_details[idx].dble) { if (border_details[idx].dble) {
MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - 1 - pen_width - 1, NULL); MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - yafter - 1 - pen_width - 1, NULL);
LineTo(c->hDC, c->rcView.right - pen_width - 1, y + para->nHeight - 1 - pen_width - 1); LineTo(c->hDC, c->rcView.right - pen_width - 1, y + para->nHeight - yafter - 1 - pen_width - 1);
} }
} }
MoveToEx(c->hDC, pt.x, pt.y, NULL); MoveToEx(c->hDC, pt.x, pt.y, NULL);
SelectObject(c->hDC, oldpen); SelectObject(c->hDC, oldpen);
DeleteObject(pen); DeleteObject(pen);
return (para->pFmt->wBorders & 4) ? border_width : 0; }
return ybefore +
((para->pFmt->dwMask & PFM_BORDER) && (para->pFmt->wBorders & 4) ?
border_width : 0);
} }
void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) { void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
@ -457,7 +489,7 @@ void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
nMargWidth += ME_twips2points(c, para->pFmt->dxOffset, dpi); nMargWidth += ME_twips2points(c, para->pFmt->dxOffset, dpi);
xs = c->rcView.left+nMargWidth; xs = c->rcView.left+nMargWidth;
xe = c->rcView.right - ME_twips2points(c, para->pFmt->dxRightIndent, dpi); xe = c->rcView.right - ME_twips2points(c, para->pFmt->dxRightIndent, dpi);
y += ME_DrawParaDecoration(c, para, y); y += ME_DrawParaDecoration(c, para, y, dpi);
break; break;
case diStartRow: case diStartRow:
y += height; y += height;

View File

@ -359,6 +359,8 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino
wc.nRow = 0; wc.nRow = 0;
wc.pt.x = 0; wc.pt.x = 0;
wc.pt.y = 0; wc.pt.y = 0;
if (tp->member.para.pFmt->dwMask & PFM_SPACEBEFORE)
wc.pt.y += ME_twips2points(c, tp->member.para.pFmt->dySpaceBefore, dpi);
if (tp->member.para.pFmt->dwMask & PFM_BORDER) if (tp->member.para.pFmt->dwMask & PFM_BORDER)
{ {
border = ME_GetParaBorderWidth(c->editor, tp->member.para.pFmt->wBorders); border = ME_GetParaBorderWidth(c->editor, tp->member.para.pFmt->wBorders);
@ -388,6 +390,8 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino
ME_WrapEndParagraph(&wc, p); ME_WrapEndParagraph(&wc, p);
if ((tp->member.para.pFmt->dwMask & PFM_BORDER) && (tp->member.para.pFmt->wBorders & 8)) if ((tp->member.para.pFmt->dwMask & PFM_BORDER) && (tp->member.para.pFmt->wBorders & 8))
wc.pt.y += border; wc.pt.y += border;
if (tp->member.para.pFmt->dwMask & PFM_SPACEAFTER)
wc.pt.y += ME_twips2points(c, tp->member.para.pFmt->dySpaceAfter, dpi);
tp->member.para.nFlags &= ~MEPF_REWRAP; tp->member.para.nFlags &= ~MEPF_REWRAP;
tp->member.para.nHeight = wc.pt.y; tp->member.para.nHeight = wc.pt.y;