richedit: Pass left margin around when computing the size of a run, so that a tab will get a correct size.

This commit is contained in:
Eric Pouech 2008-03-16 21:47:08 +01:00 committed by Alexandre Julliard
parent 34a4f9227a
commit a86d7bdcea
4 changed files with 37 additions and 25 deletions

View File

@ -202,11 +202,14 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
pSizeRun = run = tmp; pSizeRun = run = tmp;
assert(run); assert(run);
assert(run->type == diRun); assert(run->type == diRun);
sz = ME_GetRunSize(&c, &para->member.para, &run->member.run, ME_StrLen(run->member.run.strText)); sz = ME_GetRunSize(&c, &para->member.para,
&run->member.run, ME_StrLen(run->member.run.strText),
row->member.row.nLMargin);
} }
} }
if (pCursor->nOffset && !(run->member.run.nFlags & MERF_SKIPPED)) { if (pCursor->nOffset && !(run->member.run.nFlags & MERF_SKIPPED)) {
sz = ME_GetRunSize(&c, &para->member.para, &run->member.run, pCursor->nOffset); sz = ME_GetRunSize(&c, &para->member.para, &run->member.run, pCursor->nOffset,
row->member.row.nLMargin);
} }
*height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent; *height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent;

View File

@ -156,13 +156,13 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset);
int ME_GetLastSplittablePlace(ME_Context *c, ME_Run *run); int ME_GetLastSplittablePlace(ME_Context *c, ME_Run *run);
int ME_CanJoinRuns(const ME_Run *run1, const ME_Run *run2); int ME_CanJoinRuns(const ME_Run *run1, const ME_Run *run2);
void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p); void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p);
ME_DisplayItem *ME_SplitRun(ME_Context *c, ME_DisplayItem *item, int nChar); ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nChar);
ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nChar); ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nChar);
int ME_FindSplitPoint(ME_Context *c, POINT *pt, ME_Run *run, int desperate); int ME_FindSplitPoint(ME_Context *c, POINT *pt, ME_Run *run, int desperate);
void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run); void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run);
ME_DisplayItem *ME_SplitFurther(ME_TextEditor *editor, ME_DisplayItem *run); ME_DisplayItem *ME_SplitFurther(ME_TextEditor *editor, ME_DisplayItem *run);
void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, ME_Run *run); void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Run *run);
SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen); SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, int startx);
void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor); void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor);
void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem **ppRun, int *pOfs); void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem **ppRun, int *pOfs);
int ME_CharOfsFromRunOfs(ME_TextEditor *editor, ME_DisplayItem *pRun, int nOfs); int ME_CharOfsFromRunOfs(ME_TextEditor *editor, ME_DisplayItem *pRun, int nOfs);

View File

@ -267,9 +267,9 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p)
* Splits a run into two in a given place. It also updates the screen position * Splits a run into two in a given place. It also updates the screen position
* and size (extent) of the newly generated runs. * and size (extent) of the newly generated runs.
*/ */
ME_DisplayItem *ME_SplitRun(ME_Context *c, ME_DisplayItem *item, int nVChar) ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar)
{ {
ME_TextEditor *editor = c->editor; ME_TextEditor *editor = wc->context->editor;
ME_DisplayItem *item2 = NULL; ME_DisplayItem *item2 = NULL;
ME_Run *run, *run2; ME_Run *run, *run2;
ME_Paragraph *para = &ME_GetParagraph(item)->member.para; ME_Paragraph *para = &ME_GetParagraph(item)->member.para;
@ -291,8 +291,8 @@ ME_DisplayItem *ME_SplitRun(ME_Context *c, ME_DisplayItem *item, int nVChar)
run2 = &item2->member.run; run2 = &item2->member.run;
ME_CalcRunExtent(c, para, run); ME_CalcRunExtent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run);
ME_CalcRunExtent(c, para, run2); ME_CalcRunExtent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run2);
run2->pt.x = run->pt.x+run->nWidth; run2->pt.x = run->pt.x+run->nWidth;
run2->pt.y = run->pt.y; run2->pt.y = run->pt.y;
@ -638,7 +638,7 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
* (nLen). * (nLen).
*/ */
static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen,
int *pAscent, int *pDescent) int startx, int *pAscent, int *pDescent)
{ {
SIZE size; SIZE size;
int nMaxLen = ME_StrVLen(run->strText); int nMaxLen = ME_StrVLen(run->strText);
@ -668,8 +668,8 @@ 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;
PARAFORMAT2 *pFmt = para->pFmt; PARAFORMAT2 *pFmt = para->pFmt;
do { do {
if (i < pFmt->cTabCount) if (i < pFmt->cTabCount)
{ {
@ -681,8 +681,8 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run
pos += 720-(pos%720); pos += 720-(pos%720);
} }
ppos = ME_twips2pointsX(c, pos); ppos = ME_twips2pointsX(c, pos);
if (ppos>run->pt.x) { if (ppos > startx + run->pt.x) {
size.cx = ppos - run->pt.x; size.cx = ppos - startx - run->pt.x;
break; break;
} }
} while(1); } while(1);
@ -711,10 +711,11 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run
* Finds width and height (but not ascent and descent) of a part of the run * Finds width and height (but not ascent and descent) of a part of the run
* up to given character. * up to given character.
*/ */
SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen) SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para,
ME_Run *run, int nLen, int startx)
{ {
int asc, desc; int asc, desc;
return ME_GetRunSizeCommon(c, para, run, nLen, &asc, &desc); return ME_GetRunSizeCommon(c, para, run, nLen, startx, &asc, &desc);
} }
/****************************************************************************** /******************************************************************************
@ -724,14 +725,15 @@ SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLe
* is calculated based on whole row's ascent and descent anyway, so no need * is calculated based on whole row's ascent and descent anyway, so no need
* to use it here. * to use it here.
*/ */
void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, ME_Run *run) void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Run *run)
{ {
if (run->nFlags & MERF_HIDDEN) if (run->nFlags & MERF_HIDDEN)
run->nWidth = 0; run->nWidth = 0;
else else
{ {
int nEnd = ME_StrVLen(run->strText); int nEnd = ME_StrVLen(run->strText);
SIZE size = ME_GetRunSizeCommon(c, para, run, nEnd, &run->nAscent, &run->nDescent); SIZE size = ME_GetRunSizeCommon(c, para, run, nEnd, startx,
&run->nAscent, &run->nDescent);
run->nWidth = size.cx; run->nWidth = size.cx;
if (!size.cx) if (!size.cx)
WARN("size.cx == 0\n"); WARN("size.cx == 0\n");

View File

@ -117,7 +117,8 @@ static void ME_WrapSizeRun(ME_WrapContext *wc, ME_DisplayItem *p)
ME_UpdateRunFlags(wc->context->editor, &p->member.run); ME_UpdateRunFlags(wc->context->editor, &p->member.run);
ME_CalcRunExtent(wc->context, &ME_GetParagraph(p)->member.para, &p->member.run); ME_CalcRunExtent(wc->context, &ME_GetParagraph(p)->member.para,
wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, &p->member.run);
} }
static ME_DisplayItem *ME_MaximizeSplit(ME_WrapContext *wc, ME_DisplayItem *p, int i) static ME_DisplayItem *ME_MaximizeSplit(ME_WrapContext *wc, ME_DisplayItem *p, int i)
@ -128,7 +129,7 @@ static ME_DisplayItem *ME_MaximizeSplit(ME_WrapContext *wc, ME_DisplayItem *p, i
return NULL; return NULL;
j = ME_ReverseFindNonWhitespaceV(p->member.run.strText, i); j = ME_ReverseFindNonWhitespaceV(p->member.run.strText, i);
if (j>0) { if (j>0) {
pp = ME_SplitRun(wc->context, piter, j); pp = ME_SplitRun(wc, piter, j);
wc->pt.x += piter->member.run.nWidth; wc->pt.x += piter->member.run.nWidth;
return pp; return pp;
} }
@ -147,7 +148,7 @@ static ME_DisplayItem *ME_MaximizeSplit(ME_WrapContext *wc, ME_DisplayItem *p, i
if (piter->member.run.nFlags & MERF_ENDWHITE) if (piter->member.run.nFlags & MERF_ENDWHITE)
{ {
j = ME_ReverseFindNonWhitespaceV(piter->member.run.strText, i); j = ME_ReverseFindNonWhitespaceV(piter->member.run.strText, i);
pp = ME_SplitRun(wc->context, piter, i); pp = ME_SplitRun(wc, piter, i);
wc->pt = pp->member.run.pt; wc->pt = pp->member.run.pt;
return pp; return pp;
} }
@ -202,7 +203,7 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem
if (i == len) if (i == len)
i = ME_ReverseFindNonWhitespaceV(run->strText, len); i = ME_ReverseFindNonWhitespaceV(run->strText, len);
if (i) { if (i) {
ME_DisplayItem *piter2 = ME_SplitRun(wc->context, piter, i); ME_DisplayItem *piter2 = ME_SplitRun(wc, piter, i);
wc->pt = piter2->member.run.pt; wc->pt = piter2->member.run.pt;
return piter2; return piter2;
} }
@ -219,7 +220,7 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem
TRACE("Backtracking failed, trying desperate: %s\n", debugstr_w(p->member.run.strText->szData)); TRACE("Backtracking failed, trying desperate: %s\n", debugstr_w(p->member.run.strText->szData));
/* OK, no better idea, so assume we MAY split words if we can split at all*/ /* OK, no better idea, so assume we MAY split words if we can split at all*/
if (idesp) if (idesp)
return ME_SplitRun(wc->context, piter, idesp); return ME_SplitRun(wc, piter, idesp);
else else
if (wc->pRowStart && piter != wc->pRowStart) if (wc->pRowStart && piter != wc->pRowStart)
{ {
@ -235,7 +236,7 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem
int pos2 = ME_StrRelPos(run->strText, 0, &chars); int pos2 = ME_StrRelPos(run->strText, 0, &chars);
if (pos2 != len) { if (pos2 != len) {
/* the run is more than 1 char, so we may split */ /* the run is more than 1 char, so we may split */
return ME_SplitRun(wc->context, piter, pos2); return ME_SplitRun(wc, piter, pos2);
} }
/* the run is one char, can't split it */ /* the run is one char, can't split it */
return piter; return piter;
@ -272,7 +273,7 @@ static ME_DisplayItem *ME_WrapHandleRun(ME_WrapContext *wc, ME_DisplayItem *p)
black = ME_FindNonWhitespaceV(run->strText, 0); black = ME_FindNonWhitespaceV(run->strText, 0);
if (black) { if (black) {
wc->bOverflown = FALSE; wc->bOverflown = FALSE;
pp = ME_SplitRun(wc->context, p, black); pp = ME_SplitRun(wc, p, black);
p->member.run.nFlags |= MERF_SKIPPED; p->member.run.nFlags |= MERF_SKIPPED;
ME_InsertRowStart(wc, pp); ME_InsertRowStart(wc, pp);
return pp; return pp;
@ -290,6 +291,12 @@ static ME_DisplayItem *ME_WrapHandleRun(ME_WrapContext *wc, ME_DisplayItem *p)
return p; return p;
} }
/* we're not at the end of the row */ /* we're not at the end of the row */
if (run->nFlags & MERF_TAB) {
/* force recomputation of tabs' size as it depends on position */
ME_CalcRunExtent(wc->context, &ME_GetParagraph(p)->member.para,
wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run);
}
/* will current run fit? */ /* will current run fit? */
if (wc->pt.x + run->nWidth > wc->nAvailWidth) if (wc->pt.x + run->nWidth > wc->nAvailWidth)
{ {
@ -315,7 +322,7 @@ static ME_DisplayItem *ME_WrapHandleRun(ME_WrapContext *wc, ME_DisplayItem *p)
{ {
/* we aren't sure if it's *really* necessary, it's a good start however */ /* we aren't sure if it's *really* necessary, it's a good start however */
int black = ME_ReverseFindNonWhitespaceV(run->strText, len); int black = ME_ReverseFindNonWhitespaceV(run->strText, len);
ME_SplitRun(wc->context, p, black); ME_SplitRun(wc, p, black);
/* handle both parts again */ /* handle both parts again */
return p; return p;
} }