richedit: Added support for changing cell border colours.

This commit is contained in:
Dylan Smith 2008-08-12 23:15:40 -04:00 committed by Alexandre Julliard
parent 421c5b0e02
commit ddc107bd26
5 changed files with 74 additions and 11 deletions

View File

@ -320,6 +320,32 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea
return 0;
}
static void ME_ApplyBorderProperties(RTF_Info *info,
ME_BorderRect *borderRect,
RTFBorder *borderDef)
{
int i, colorNum;
ME_Border *pBorders[] = {&borderRect->top,
&borderRect->left,
&borderRect->bottom,
&borderRect->right};
for (i = 0; i < 4; i++)
{
RTFColor *colorDef = info->colorList;
pBorders[i]->width = borderDef[i].width;
colorNum = borderDef[i].color;
while (colorDef && colorDef->rtfCNum != colorNum)
colorDef = colorDef->rtfNextColor;
if (colorDef)
pBorders[i]->colorRef = RGB(
colorDef->rtfCRed >= 0 ? colorDef->rtfCRed : 0,
colorDef->rtfCGreen >= 0 ? colorDef->rtfCGreen : 0,
colorDef->rtfCBlue >= 0 ? colorDef->rtfCBlue : 0);
else
pBorders[i]->colorRef = RGB(0, 0, 0);
}
}
static void ME_RTFCharAttrHook(RTF_Info *info)
{
CHARFORMAT2W fmt;
@ -767,7 +793,31 @@ static void ME_RTFParAttrHook(RTF_Info *info)
fmt.wBorderSpace = info->rtfParam;
fmt.dwMask = PFM_BORDER;
break;
}
case rtfBorderColor:
{
RTFTable *tableDef = info->tableDef;
int borderSide = info->borderType & RTFBorderSideMask;
int borderType = info->borderType & RTFBorderTypeMask;
switch(borderType)
{
case RTFBorderTypePara:
if (!info->editor->bEmulateVersion10) /* v4.1 */
break;
/* v1.0 - 3.0 treat paragraph and row borders the same. */
case RTFBorderTypeRow:
if (tableDef) {
tableDef->border[borderSide].color = info->rtfParam;
}
break;
case RTFBorderTypeCell:
if (tableDef && tableDef->numCellsDefined < MAX_TABLE_CELLS) {
tableDef->cells[tableDef->numCellsDefined].border[borderSide].color = info->rtfParam;
}
break;
}
break;
}
}
if (fmt.dwMask) {
RTFFlushOutputBuffer(info);
/* FIXME too slow ? how come ?*/
@ -930,11 +980,10 @@ static void ME_RTFSpecialCharHook(RTF_Info *info)
} else {
for (i = 0; i < tableDef->numCellsDefined; i++)
{
cell->member.cell.nRightBoundary = tableDef->cells[i].rightBoundary;
cell->member.cell.border.top.width = tableDef->cells[i].border[0].width;
cell->member.cell.border.left.width = tableDef->cells[i].border[1].width;
cell->member.cell.border.bottom.width = tableDef->cells[i].border[2].width;
cell->member.cell.border.right.width = tableDef->cells[i].border[3].width;
RTFCell *cellDef = &tableDef->cells[i];
cell->member.cell.nRightBoundary = cellDef->rightBoundary;
ME_ApplyBorderProperties(info, &cell->member.cell.border,
cellDef->border);
cell = cell->member.cell.next_cell;
if (!cell)
{
@ -962,6 +1011,8 @@ static void ME_RTFSpecialCharHook(RTF_Info *info)
para = ME_InsertTableRowEndFromCursor(info->editor);
para->member.para.pFmt->dxOffset = abs(info->tableDef->gapH);
para->member.para.pFmt->dxStartIndent = info->tableDef->leftEdge;
ME_ApplyBorderProperties(info, &para->member.para.border,
tableDef->border);
info->nestingLevel--;
if (!info->nestingLevel)
{
@ -984,6 +1035,10 @@ static void ME_RTFSpecialCharHook(RTF_Info *info)
PARAFORMAT2 *pFmt = para->member.para.pFmt;
pFmt->dxOffset = info->tableDef->gapH;
pFmt->dxStartIndent = info->tableDef->leftEdge;
para = ME_GetParagraph(info->editor->pCursors[0].pRun);
ME_ApplyBorderProperties(info, &para->member.para.border,
tableDef->border);
while (tableDef->numCellsInserted < tableDef->numCellsDefined)
{
WCHAR tab = '\t';

View File

@ -168,6 +168,7 @@ typedef struct tagME_Document {
typedef struct tagME_Border
{
int width;
COLORREF colorRef;
} ME_Border;
typedef struct tagME_BorderRect
@ -183,6 +184,7 @@ typedef struct tagME_Paragraph
PARAFORMAT2 *pFmt;
struct tagME_DisplayItem *pCell; /* v4.1 */
ME_BorderRect border;
int nCharOfs;
int nFlags;

View File

@ -755,7 +755,7 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
rc.bottom = bottom;
if (cell->border.left.width > 0)
{
color = RGB(0,0,0);
color = cell->border.left.colorRef;
width = max(ME_twips2pointsX(c, cell->border.left.width), 1);
} else {
color = RGB(192,192,192);
@ -777,7 +777,7 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
if (atTop) {
if (cell->border.top.width > 0)
{
brush = GetStockObject(BLACK_BRUSH);
brush = CreateSolidBrush(cell->border.top.colorRef);
width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
} else {
brush = GetStockObject(LTGRAY_BRUSH);
@ -786,6 +786,8 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
rc.top = top;
rc.bottom = rc.top + width;
FillRect(c->hDC, &rc, brush);
if (cell->border.top.width > 0)
DeleteObject(brush);
}
/* Draw the bottom border if at the last paragraph in the cell, and when
@ -809,13 +811,15 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
}
if (rc.left < rc.right) {
if (cell->border.bottom.width > 0) {
brush = GetStockObject(BLACK_BRUSH);
brush = CreateSolidBrush(cell->border.bottom.colorRef);
} else {
brush = GetStockObject(LTGRAY_BRUSH);
}
rc.bottom = bottom;
rc.top = rc.bottom - width;
FillRect(c->hDC, &rc, brush);
if (cell->border.bottom.width > 0)
DeleteObject(brush);
}
rc.left = oldLeft;
}
@ -827,7 +831,7 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
rc.top = top;
rc.bottom = bottom;
if (cell->border.right.width > 0) {
color = RGB(0,0,0);
color = cell->border.right.colorRef;
width = max(ME_twips2pointsX(c, cell->border.right.width), 1);
} else {
color = RGB(192,192,192);
@ -854,7 +858,7 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
POINT oldPt;
PARAFORMAT2 *pNextFmt;
pen = CreatePen(PS_SOLID, 0, RGB(0,0,0));
pen = CreatePen(PS_SOLID, 0, para->border.top.colorRef);
oldpen = SelectObject(c->hDC, pen);
/* Find the start relative to the text */

View File

@ -177,6 +177,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
/* FIXME initialize format style and call ME_SetParaFormat blah blah */
*new_para->member.para.pFmt = *run_para->member.para.pFmt;
new_para->member.para.border = run_para->member.para.border;
/* insert paragraph into paragraph double linked list */
new_para->member.para.prev_para = run_para;

View File

@ -1010,6 +1010,7 @@ struct RTFStyleElt
struct RTFBorder
{
int width;
int color;
};
struct RTFCell