Commit a47d4a4c authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Adjust table spacing with horizontal gap and left edge.

parent b628482d
...@@ -761,19 +761,16 @@ static void ME_RTFTblAttrHook(RTF_Info *info) ...@@ -761,19 +761,16 @@ static void ME_RTFTblAttrHook(RTF_Info *info)
case rtfRowDef: case rtfRowDef:
{ {
if (!info->tableDef) { if (!info->tableDef) {
info->tableDef = ALLOC_OBJ(RTFTable); info->tableDef = ME_MakeTableDef(info->editor);
ZeroMemory(info->tableDef, sizeof(RTFTable));
} else { } else {
ZeroMemory(info->tableDef->cells, sizeof(info->tableDef->cells)); ME_InitTableDef(info->editor, info->tableDef);
info->tableDef->numCellsDefined = 0;
} }
break; break;
} }
case rtfCellPos: case rtfCellPos:
if (!info->tableDef) if (!info->tableDef)
{ {
info->tableDef = ALLOC_OBJ(RTFTable); info->tableDef = ME_MakeTableDef(info->editor);
ZeroMemory(info->tableDef, sizeof(RTFTable));
} }
if (info->tableDef->numCellsDefined >= MAX_TABLE_CELLS) if (info->tableDef->numCellsDefined >= MAX_TABLE_CELLS)
break; break;
...@@ -789,6 +786,14 @@ static void ME_RTFTblAttrHook(RTF_Info *info) ...@@ -789,6 +786,14 @@ static void ME_RTFTblAttrHook(RTF_Info *info)
} }
info->tableDef->numCellsDefined++; info->tableDef->numCellsDefined++;
break; break;
case rtfRowGapH:
if (info->tableDef)
info->tableDef->gapH = info->rtfParam;
break;
case rtfRowLeftEdge:
if (info->tableDef)
info->tableDef->leftEdge = info->rtfParam;
break;
} }
} }
...@@ -902,6 +907,8 @@ static void ME_RTFSpecialCharHook(RTF_Info *info) ...@@ -902,6 +907,8 @@ static void ME_RTFSpecialCharHook(RTF_Info *info)
} }
para = ME_InsertTableRowEndFromCursor(info->editor); para = ME_InsertTableRowEndFromCursor(info->editor);
para->member.para.pFmt->dxOffset = abs(info->tableDef->gapH);
para->member.para.pFmt->dxStartIndent = info->tableDef->leftEdge;
info->nestingLevel--; info->nestingLevel--;
if (!info->nestingLevel) if (!info->nestingLevel)
{ {
...@@ -922,6 +929,8 @@ static void ME_RTFSpecialCharHook(RTF_Info *info) ...@@ -922,6 +929,8 @@ static void ME_RTFSpecialCharHook(RTF_Info *info)
WCHAR endl = '\r'; WCHAR endl = '\r';
ME_DisplayItem *para = ME_GetParagraph(info->editor->pCursors[0].pRun); ME_DisplayItem *para = ME_GetParagraph(info->editor->pCursors[0].pRun);
PARAFORMAT2 *pFmt = para->member.para.pFmt; PARAFORMAT2 *pFmt = para->member.para.pFmt;
pFmt->dxOffset = info->tableDef->gapH;
pFmt->dxStartIndent = info->tableDef->leftEdge;
while (tableDef->numCellsInserted < tableDef->numCellsDefined) while (tableDef->numCellsInserted < tableDef->numCellsDefined)
{ {
WCHAR tab = '\t'; WCHAR tab = '\t';
......
...@@ -297,6 +297,8 @@ ME_DisplayItem *ME_GetTableRowStart(ME_DisplayItem *para); ...@@ -297,6 +297,8 @@ ME_DisplayItem *ME_GetTableRowStart(ME_DisplayItem *para);
void ME_CheckTablesForCorruption(ME_TextEditor *editor); void ME_CheckTablesForCorruption(ME_TextEditor *editor);
void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars); void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars);
void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow); void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow);
struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor);
void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef);
/* undo.c */ /* undo.c */
ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_DisplayItem *pdi); ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_DisplayItem *pdi);
......
...@@ -1018,6 +1018,8 @@ struct RTFTable ...@@ -1018,6 +1018,8 @@ struct RTFTable
RTFCell cells[MAX_TABLE_CELLS]; RTFCell cells[MAX_TABLE_CELLS];
int numCellsDefined; int numCellsDefined;
int gapH, leftEdge;
/* Used in v1.0 - v3.0 */ /* Used in v1.0 - v3.0 */
int numCellsInserted; int numCellsInserted;
......
...@@ -671,13 +671,21 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run ...@@ -671,13 +671,21 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run
if (run->nFlags & MERF_TAB) if (run->nFlags & MERF_TAB)
{ {
int pos = 0, i = 0, ppos; int pos = 0, i = 0, ppos, shift = 0;
PARAFORMAT2 *pFmt = para->pFmt; PARAFORMAT2 *pFmt = para->pFmt;
if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
/* The horizontal gap shifts the tab positions to leave the gap. */
shift = pFmt->dxOffset * 2;
do { do {
if (i < pFmt->cTabCount) if (i < pFmt->cTabCount)
{ {
pos = pFmt->rgxTabs[i]&0x00FFFFFF; /* Only one side of the horizontal gap is needed at the end of
* the table row. */
if (i == pFmt->cTabCount -1)
shift = shift >> 1;
pos = shift + (pFmt->rgxTabs[i]&0x00FFFFFF);
i++; i++;
} }
else else
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
*/ */
#include "editor.h" #include "editor.h"
#include "rtf.h"
WINE_DEFAULT_DEBUG_CHANNEL(richedit); WINE_DEFAULT_DEBUG_CHANNEL(richedit);
WINE_DECLARE_DEBUG_CHANNEL(richedit_lists); WINE_DECLARE_DEBUG_CHANNEL(richedit_lists);
...@@ -594,3 +595,23 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow) ...@@ -594,3 +595,23 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow)
ME_ShowCaret(editor); ME_ShowCaret(editor);
ME_SendSelChange(editor); ME_SendSelChange(editor);
} }
struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor)
{
RTFTable *tableDef = ALLOC_OBJ(RTFTable);
ZeroMemory(tableDef, sizeof(RTFTable));
if (!editor->bEmulateVersion10) /* v4.1 */
tableDef->gapH = 10;
return tableDef;
}
void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef)
{
ZeroMemory(tableDef->cells, sizeof(tableDef->cells));
tableDef->numCellsDefined = 0;
tableDef->leftEdge = 0;
if (!editor->bEmulateVersion10) /* v4.1 */
tableDef->gapH = 10;
else /* v1.0 - 3.0 */
tableDef->gapH = 0;
}
...@@ -62,6 +62,11 @@ static void ME_BeginRow(ME_WrapContext *wc, ME_DisplayItem *para) ...@@ -62,6 +62,11 @@ static void ME_BeginRow(ME_WrapContext *wc, ME_DisplayItem *para)
width = cell->nRightBoundary; width = cell->nRightBoundary;
if (cell->prev_cell) if (cell->prev_cell)
width -= cell->prev_cell->member.cell.nRightBoundary; width -= cell->prev_cell->member.cell.nRightBoundary;
if (!cell->prev_cell)
{
int rowIndent = ME_GetTableRowEnd(para)->member.para.pFmt->dxStartIndent;
width -= rowIndent;
}
cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0); cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0);
wc->nAvailWidth = cell->nWidth wc->nAvailWidth = cell->nWidth
...@@ -427,33 +432,49 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino ...@@ -427,33 +432,49 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino
ME_WrapContext wc; ME_WrapContext wc;
int border = 0; int border = 0;
int linespace = 0; int linespace = 0;
PARAFORMAT2 *pFmt;
assert(tp->type == diParagraph); assert(tp->type == diParagraph);
if (!(tp->member.para.nFlags & MEPF_REWRAP)) { if (!(tp->member.para.nFlags & MEPF_REWRAP)) {
return; return;
} }
ME_PrepareParagraphForWrapping(c, tp); ME_PrepareParagraphForWrapping(c, tp);
pFmt = tp->member.para.pFmt;
wc.context = c; wc.context = c;
/* wc.para_style = tp->member.para.style; */ /* wc.para_style = tp->member.para.style; */
wc.style = NULL; wc.style = NULL;
wc.nFirstMargin = ME_twips2pointsX(c, tp->member.para.pFmt->dxStartIndent) + beginofs; if (tp->member.para.nFlags & MEPF_ROWEND) {
wc.nLeftMargin = wc.nFirstMargin + ME_twips2pointsX(c, tp->member.para.pFmt->dxOffset); wc.nFirstMargin = wc.nLeftMargin = wc.nRightMargin = 0;
wc.nRightMargin = ME_twips2pointsX(c, tp->member.para.pFmt->dxRightIndent); } else {
int dxStartIndent = pFmt->dxStartIndent;
if (tp->member.para.pCell) {
dxStartIndent += ME_GetTableRowEnd(tp)->member.para.pFmt->dxOffset;
}
wc.nFirstMargin = ME_twips2pointsX(c, dxStartIndent);
wc.nLeftMargin = wc.nFirstMargin + ME_twips2pointsX(c, pFmt->dxOffset);
wc.nRightMargin = ME_twips2pointsX(c, pFmt->dxRightIndent);
}
if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
{
wc.nFirstMargin += ME_twips2pointsX(c, pFmt->dxOffset * 2);
}
wc.nRow = 0; wc.nRow = 0;
wc.pt.y = 0; wc.pt.y = 0;
if (tp->member.para.pFmt->dwMask & PFM_SPACEBEFORE) if (pFmt->dwMask & PFM_SPACEBEFORE)
wc.pt.y += ME_twips2pointsY(c, tp->member.para.pFmt->dySpaceBefore); wc.pt.y += ME_twips2pointsY(c, pFmt->dySpaceBefore);
if (tp->member.para.pFmt->dwMask & PFM_BORDER) if (!(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) &&
pFmt->dwMask & PFM_BORDER)
{ {
border = ME_GetParaBorderWidth(c->editor, tp->member.para.pFmt->wBorders); border = ME_GetParaBorderWidth(c->editor, tp->member.para.pFmt->wBorders);
if (tp->member.para.pFmt->wBorders & 1) { if (pFmt->wBorders & 1) {
wc.nFirstMargin += border; wc.nFirstMargin += border;
wc.nLeftMargin += border; wc.nLeftMargin += border;
} }
if (tp->member.para.pFmt->wBorders & 2) if (pFmt->wBorders & 2)
wc.nRightMargin -= border; wc.nRightMargin -= border;
if (tp->member.para.pFmt->wBorders & 4) if (pFmt->wBorders & 4)
wc.pt.y += border; wc.pt.y += border;
} }
...@@ -470,10 +491,11 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino ...@@ -470,10 +491,11 @@ static void ME_WrapTextParagraph(ME_Context *c, ME_DisplayItem *tp, DWORD begino
wc.pt.y += linespace; wc.pt.y += linespace;
} }
ME_WrapEndParagraph(&wc, p); ME_WrapEndParagraph(&wc, p);
if ((tp->member.para.pFmt->dwMask & PFM_BORDER) && (tp->member.para.pFmt->wBorders & 8)) if (!(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE) &&
(pFmt->dwMask & PFM_BORDER) && (pFmt->wBorders & 8))
wc.pt.y += border; wc.pt.y += border;
if (tp->member.para.pFmt->dwMask & PFM_SPACEAFTER) if (tp->member.para.pFmt->dwMask & PFM_SPACEAFTER)
wc.pt.y += ME_twips2pointsY(c, tp->member.para.pFmt->dySpaceAfter); wc.pt.y += ME_twips2pointsY(c, pFmt->dySpaceAfter);
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;
...@@ -528,6 +550,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { ...@@ -528,6 +550,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
int yLastPos = 0; int yLastPos = 0;
ME_InitContext(&c, editor, GetDC(editor->hWnd)); ME_InitContext(&c, editor, GetDC(editor->hWnd));
c.pt.x = editor->selofs;
editor->nHeight = 0; editor->nHeight = 0;
item = editor->pBuffer->pFirst->next; item = editor->pBuffer->pFirst->next;
while(item != editor->pBuffer->pLast) { while(item != editor->pBuffer->pLast) {
...@@ -556,7 +579,16 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { ...@@ -556,7 +579,16 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
if (item->member.para.nFlags & MEPF_ROWSTART) if (item->member.para.nFlags & MEPF_ROWSTART)
{ {
ME_DisplayItem *cell = ME_FindItemFwd(item, diCell); ME_DisplayItem *cell = ME_FindItemFwd(item, diCell);
ME_DisplayItem *endRowPara;
cell->member.cell.pt = c.pt; cell->member.cell.pt = c.pt;
endRowPara = ME_GetTableRowEnd(item);
if (endRowPara->member.para.pFmt->dxStartIndent > 0)
{
int dxStartIndent = endRowPara->member.para.pFmt->dxStartIndent;
cell = ME_FindItemFwd(item, diCell);
cell->member.cell.pt.x += ME_twips2pointsX(&c, dxStartIndent);
c.pt.x = cell->member.cell.pt.x;
}
} }
else if (item->member.para.nFlags & MEPF_ROWEND) else if (item->member.para.nFlags & MEPF_ROWEND)
{ {
...@@ -614,7 +646,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { ...@@ -614,7 +646,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
c.pt.x = item->member.para.pCell->member.cell.pt.x; c.pt.x = item->member.para.pCell->member.cell.pt.x;
} else { } else {
/* Normal paragraph */ /* Normal paragraph */
c.pt.x = 0; c.pt.x = editor->selofs;
} }
c.pt.y += item->member.para.nHeight; c.pt.y += item->member.para.nHeight;
} }
......
...@@ -298,9 +298,7 @@ ME_StreamOutRTFTableProps(ME_TextEditor *editor, ME_OutStream *pStream, ...@@ -298,9 +298,7 @@ ME_StreamOutRTFTableProps(ME_TextEditor *editor, ME_OutStream *pStream,
cell = para->member.para.next_para->member.para.pCell; cell = para->member.para.next_para->member.para.pCell;
assert(cell); assert(cell);
do { do {
sprintf(props, "\\cellx%d", cell->member.cell.nRightBoundary); sprintf(props + strlen(props), "\\cellx%d", cell->member.cell.nRightBoundary);
if (!ME_StreamOutPrint(pStream, props))
return FALSE;
cell = cell->member.cell.next_cell; cell = cell->member.cell.next_cell;
} while (cell->member.cell.next_cell); } while (cell->member.cell.next_cell);
} else { /* v1.0 - 3.0 */ } else { /* v1.0 - 3.0 */
...@@ -308,13 +306,17 @@ ME_StreamOutRTFTableProps(ME_TextEditor *editor, ME_OutStream *pStream, ...@@ -308,13 +306,17 @@ ME_StreamOutRTFTableProps(ME_TextEditor *editor, ME_OutStream *pStream,
int i; int i;
assert(!(para->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND|MEPF_CELL))); assert(!(para->member.para.nFlags & (MEPF_ROWSTART|MEPF_ROWEND|MEPF_CELL)));
if (pFmt->dxOffset)
sprintf(props + strlen(props), "\\trgaph%d", pFmt->dxOffset);
if (pFmt->dxStartIndent)
sprintf(props + strlen(props), "\\trleft%d", pFmt->dxStartIndent);
for (i = 0; i < pFmt->cTabCount; i++) for (i = 0; i < pFmt->cTabCount; i++)
{ {
sprintf(props, "\\cellx%d", pFmt->rgxTabs[i] & 0x00FFFFFF); sprintf(props + strlen(props), "\\cellx%d", pFmt->rgxTabs[i] & 0x00FFFFFF);
if (!ME_StreamOutPrint(pStream, props))
return FALSE;
} }
} }
if (!ME_StreamOutPrint(pStream, props))
return FALSE;
props[0] = '\0'; props[0] = '\0';
return TRUE; return TRUE;
} }
...@@ -405,19 +407,15 @@ ME_StreamOutRTFParaProps(ME_TextEditor *editor, ME_OutStream *pStream, ...@@ -405,19 +407,15 @@ ME_StreamOutRTFParaProps(ME_TextEditor *editor, ME_OutStream *pStream,
if (fmt->dwMask & PFM_SIDEBYSIDE && fmt->wEffects & PFE_SIDEBYSIDE) if (fmt->dwMask & PFM_SIDEBYSIDE && fmt->wEffects & PFE_SIDEBYSIDE)
strcat(props, "\\sbys"); strcat(props, "\\sbys");
if (!(editor->bEmulateVersion10 && /* v1.0 - 3.0 */
fmt->dwMask & PFM_TABLE && fmt->wEffects & PFE_TABLE))
{
if (fmt->dwMask & PFM_OFFSET) if (fmt->dwMask & PFM_OFFSET)
sprintf(props + strlen(props), "\\li%d", fmt->dxOffset); sprintf(props + strlen(props), "\\li%d", fmt->dxOffset);
if (fmt->dwMask & PFM_OFFSETINDENT || fmt->dwMask & PFM_STARTINDENT) if (fmt->dwMask & PFM_OFFSETINDENT || fmt->dwMask & PFM_STARTINDENT)
sprintf(props + strlen(props), "\\fi%d", fmt->dxStartIndent); sprintf(props + strlen(props), "\\fi%d", fmt->dxStartIndent);
if (fmt->dwMask & PFM_RIGHTINDENT) if (fmt->dwMask & PFM_RIGHTINDENT)
sprintf(props + strlen(props), "\\ri%d", fmt->dxRightIndent); sprintf(props + strlen(props), "\\ri%d", fmt->dxRightIndent);
if (fmt->dwMask & PFM_SPACEAFTER)
sprintf(props + strlen(props), "\\sa%d", fmt->dySpaceAfter);
if (fmt->dwMask & PFM_SPACEBEFORE)
sprintf(props + strlen(props), "\\sb%d", fmt->dySpaceBefore);
if (fmt->dwMask & PFM_STYLE)
sprintf(props + strlen(props), "\\s%d", fmt->sStyle);
if (fmt->dwMask & PFM_TABSTOPS) { if (fmt->dwMask & PFM_TABSTOPS) {
static const char * const leader[6] = { "", "\\tldot", "\\tlhyph", "\\tlul", "\\tlth", "\\tleq" }; static const char * const leader[6] = { "", "\\tldot", "\\tlhyph", "\\tlul", "\\tlth", "\\tleq" };
...@@ -441,7 +439,13 @@ ME_StreamOutRTFParaProps(ME_TextEditor *editor, ME_OutStream *pStream, ...@@ -441,7 +439,13 @@ ME_StreamOutRTFParaProps(ME_TextEditor *editor, ME_OutStream *pStream,
sprintf(props+strlen(props), "\\tx%d", fmt->rgxTabs[i]&0x00FFFFFF); sprintf(props+strlen(props), "\\tx%d", fmt->rgxTabs[i]&0x00FFFFFF);
} }
} }
}
if (fmt->dwMask & PFM_SPACEAFTER)
sprintf(props + strlen(props), "\\sa%d", fmt->dySpaceAfter);
if (fmt->dwMask & PFM_SPACEBEFORE)
sprintf(props + strlen(props), "\\sb%d", fmt->dySpaceBefore);
if (fmt->dwMask & PFM_STYLE)
sprintf(props + strlen(props), "\\s%d", fmt->sStyle);
if (fmt->dwMask & PFM_SHADING) { if (fmt->dwMask & PFM_SHADING) {
static const char * const style[16] = { "", "\\bgdkhoriz", "\\bgdkvert", "\\bgdkfdiag", static const char * const style[16] = { "", "\\bgdkhoriz", "\\bgdkvert", "\\bgdkfdiag",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment