mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
RichText: Numbering refactored
This commit is contained in:
parent
ad79d34015
commit
25f71b0a76
12 changed files with 166 additions and 100 deletions
|
|
@ -84,6 +84,7 @@ void RichEdit::FinishNF()
|
||||||
Action();
|
Action();
|
||||||
}
|
}
|
||||||
useraction = modified = false;
|
useraction = modified = false;
|
||||||
|
WhenSel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichEdit::Finish()
|
void RichEdit::Finish()
|
||||||
|
|
|
||||||
|
|
@ -673,6 +673,7 @@ public:
|
||||||
Event<String&> WhenLabel;
|
Event<String&> WhenLabel;
|
||||||
Event<String&> WhenIndexEntry;
|
Event<String&> WhenIndexEntry;
|
||||||
Event<Bar&> WhenBar;
|
Event<Bar&> WhenBar;
|
||||||
|
Event<> WhenSel;
|
||||||
|
|
||||||
void StdBar(Bar& menu);
|
void StdBar(Bar& menu);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,10 +144,12 @@ struct RichPara {
|
||||||
int n[8];
|
int n[8];
|
||||||
|
|
||||||
String AsText(const NumberFormat& format) const;
|
String AsText(const NumberFormat& format) const;
|
||||||
void TestReset(const NumberFormat& format);
|
|
||||||
void Next(const NumberFormat& format);
|
void Next(const NumberFormat& format);
|
||||||
|
void Reset() { memset(n, 0, sizeof(n)); }
|
||||||
|
|
||||||
Number();
|
bool operator!=(const Number& b) const { return !memeq_t(n, b.n, 8); }
|
||||||
|
|
||||||
|
Number() { Reset(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Part {
|
struct Part {
|
||||||
|
|
@ -182,10 +184,10 @@ struct RichPara {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Line : public HeightInfo {
|
struct Line : public HeightInfo {
|
||||||
int pos;
|
int pos; // offset in Lines arrays (e.g. text or pos)
|
||||||
int len;
|
int len; // number of characters in lines array
|
||||||
int ppos;
|
int ppos; // position of the first character
|
||||||
int plen;
|
int plen; // length in source characters (e.g. fields are single)
|
||||||
int xpos;
|
int xpos;
|
||||||
int cx;
|
int cx;
|
||||||
int objecti;
|
int objecti;
|
||||||
|
|
@ -207,6 +209,7 @@ struct RichPara {
|
||||||
Array<RichObject> object;
|
Array<RichObject> object;
|
||||||
int first_indent;
|
int first_indent;
|
||||||
int next_indent;
|
int next_indent;
|
||||||
|
int number_chars; // if paragraph starts with numbering, otherwise 0
|
||||||
|
|
||||||
|
|
||||||
int GetCount() const { return line.GetCount(); }
|
int GetCount() const { return line.GetCount(); }
|
||||||
|
|
@ -265,13 +268,13 @@ struct RichPara {
|
||||||
|
|
||||||
void GetRichPos(RichPos& rp, int pos) const;
|
void GetRichPos(RichPos& rp, int pos) const;
|
||||||
|
|
||||||
Lines FormatLines(int cx) const;
|
Lines FormatLines(int cx, const Number& n) const;
|
||||||
void Paint(PageDraw& pw, RichContext rc, const PaintInfo& pi, const Number& n, const Bits& spellerror, bool baselevel) const;
|
void Paint(PageDraw& pw, RichContext rc, const PaintInfo& pi, const Number& n, const Bits& spellerror, bool baselevel) const;
|
||||||
RichCaret GetCaret(int pos, RichContext rc) const;
|
RichCaret GetCaret(int pos, RichContext rc) const;
|
||||||
int GetPos(int x, PageY y, RichContext rc) const;
|
int GetPos(int x, PageY y, RichContext rc) const;
|
||||||
void GatherLabels(Vector<RichValPos>& info, RichContext rc, int pos) const;
|
void GatherLabels(Vector<RichValPos>& info, RichContext rc, int pos) const;
|
||||||
void GatherIndexes(Vector<RichValPos>& info, RichContext rc, int pos) const;
|
void GatherIndexes(Vector<RichValPos>& info, RichContext rc, int pos) const;
|
||||||
int GetVertMove(int pos, int gx, const Rect& page, int dir) const;
|
int GetVertMove(int pos, int gx, const Rect& page, int dir, const RichContext& rc) const;
|
||||||
|
|
||||||
WString GetText() const;
|
WString GetText() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ String RichPara::Number::AsText(const RichPara::NumberFormat& format) const
|
||||||
return format.before_number + result + format.after_number;
|
return format.before_number + result + format.after_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichPara::Number::TestReset(const RichPara::NumberFormat& fmt)
|
void RichPara::Number::Next(const RichPara::NumberFormat& fmt)
|
||||||
{
|
{
|
||||||
if(fmt.reset_number) {
|
if(fmt.reset_number) {
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
@ -111,10 +111,6 @@ void RichPara::Number::TestReset(const RichPara::NumberFormat& fmt)
|
||||||
if(!done && !IsNull(n[0]))
|
if(!done && !IsNull(n[0]))
|
||||||
n[0] = 0;
|
n[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void RichPara::Number::Next(const RichPara::NumberFormat& fmt)
|
|
||||||
{
|
|
||||||
for(int i = 7; i >= 0; --i)
|
for(int i = 7; i >= 0; --i)
|
||||||
if(fmt.number[i]) {
|
if(fmt.number[i]) {
|
||||||
n[i++]++;
|
n[i++]++;
|
||||||
|
|
@ -124,11 +120,6 @@ void RichPara::Number::Next(const RichPara::NumberFormat& fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RichPara::Number::Number()
|
|
||||||
{
|
|
||||||
memset8(n, 0, sizeof(n));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RichPara::NumberFormat::IsNumbered() const
|
bool RichPara::NumberFormat::IsNumbered() const
|
||||||
{
|
{
|
||||||
if(before_number.GetLength() || after_number.GetLength())
|
if(before_number.GetLength() || after_number.GetLength())
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ Color PaintInfo::ResolvePaper(Color paper) const
|
||||||
|
|
||||||
RichPara::Lines RichPara::Begin(RichContext& rc) const
|
RichPara::Lines RichPara::Begin(RichContext& rc) const
|
||||||
{
|
{
|
||||||
Lines pl = FormatLines(rc.page.Width());
|
Lines pl = FormatLines(rc.page.Width(), rc.number);
|
||||||
rc.py.y += format.before + format.ruler;
|
rc.py.y += format.before + format.ruler;
|
||||||
pl.Justify(format);
|
pl.Justify(format);
|
||||||
return pl;
|
return pl;
|
||||||
|
|
@ -337,15 +337,6 @@ void RichPara::Paint(PageDraw& pw, RichContext rc, const PaintInfo& pi,
|
||||||
case BULLET_ROUND:
|
case BULLET_ROUND:
|
||||||
draw.DrawEllipse(r, pi.ResolveInk(bullet_ink));
|
draw.DrawEllipse(r, pi.ResolveInk(bullet_ink));
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
String s = n.AsText(format);
|
|
||||||
if(!IsNull(s)) {
|
|
||||||
CharFormat cf = li.len && *pl.format ? **pl.format : format;
|
|
||||||
cf.Height(z * cf.GetHeight());
|
|
||||||
draw.DrawText(r.left,
|
|
||||||
z * y0 - cf.Info().GetAscent(),
|
|
||||||
s, cf, pi.ResolveInk(cf.ink));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int zlcy = z * linecy;
|
int zlcy = z * linecy;
|
||||||
|
|
@ -464,16 +455,23 @@ RichCaret RichPara::GetCaret(int pos, RichContext rc) const
|
||||||
pr.lineascent = li.ascent;
|
pr.lineascent = li.ascent;
|
||||||
pr.line = lni;
|
pr.line = lni;
|
||||||
if(pos < li.ppos + li.plen) {
|
if(pos < li.ppos + li.plen) {
|
||||||
int *w = pl.width + li.pos;
|
int npos = li.pos;
|
||||||
int *p = pl.pos + li.pos;
|
|
||||||
const CharFormat **i = pl.format + li.pos;
|
|
||||||
const HeightInfo *h = pl.height + li.pos;
|
|
||||||
int x = li.xpos + rc.page.left;
|
int x = li.xpos + rc.page.left;
|
||||||
|
if(lni == 0 && pl.number_chars) { // skip the number
|
||||||
|
npos += pl.number_chars;
|
||||||
|
for(int i = 0; i < pl.number_chars; i++)
|
||||||
|
x += pl.width[li.pos + i];
|
||||||
|
}
|
||||||
|
int *w = pl.width + npos;
|
||||||
|
int *p = pl.pos + npos;
|
||||||
|
int *pe = pl.pos + npos + li.len;
|
||||||
|
const CharFormat **i = pl.format + npos;
|
||||||
|
const HeightInfo *h = pl.height + npos;
|
||||||
if(li.len && *i) {
|
if(li.len && *i) {
|
||||||
pr.caretascent = h->ascent;
|
pr.caretascent = h->ascent;
|
||||||
pr.caretdescent = h->descent;
|
pr.caretdescent = h->descent;
|
||||||
}
|
}
|
||||||
while(pos > *p) {
|
while(pos > *p) { // second condition to skip the number
|
||||||
x += *w++;
|
x += *w++;
|
||||||
if(*i) {
|
if(*i) {
|
||||||
pr.caretascent = h->ascent;
|
pr.caretascent = h->ascent;
|
||||||
|
|
@ -502,11 +500,17 @@ RichCaret RichPara::GetCaret(int pos, RichContext rc) const
|
||||||
int RichPara::PosInLine(int x, const Rect& page, const Lines& pl, int lni) const
|
int RichPara::PosInLine(int x, const Rect& page, const Lines& pl, int lni) const
|
||||||
{
|
{
|
||||||
const Line& li = pl[lni];
|
const Line& li = pl[lni];
|
||||||
const int *w = pl.width + li.pos;
|
|
||||||
const int *wl = w + li.len;
|
|
||||||
if(lni < pl.GetCount() - 1 && li.len > 0 && pl.text[li.pos + li.len - 1] == ' ')
|
|
||||||
wl--;
|
|
||||||
int xp = li.xpos + page.left;
|
int xp = li.xpos + page.left;
|
||||||
|
int npos = li.pos;
|
||||||
|
if(lni == 0 && pl.number_chars) { // skip the number
|
||||||
|
npos += pl.number_chars;
|
||||||
|
for(int i = 0; i < pl.number_chars; i++)
|
||||||
|
xp += pl.width[li.pos + i];
|
||||||
|
}
|
||||||
|
const int *w = pl.width + npos;
|
||||||
|
const int *wl = w + li.len;
|
||||||
|
if(lni < pl.GetCount() - 1 && li.len > 0 && pl.text[npos + li.len - 1] == ' ')
|
||||||
|
wl--;
|
||||||
while(w < wl && xp + *w <= x)
|
while(w < wl && xp + *w <= x)
|
||||||
xp += *w++;
|
xp += *w++;
|
||||||
int pos = (int)(w - pl.width);
|
int pos = (int)(w - pl.width);
|
||||||
|
|
@ -529,9 +533,9 @@ int RichPara::GetPos(int x, PageY y, RichContext rc) const
|
||||||
return pl.len;
|
return pl.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RichPara::GetVertMove(int pos, int gx, const Rect& page, int dir) const
|
int RichPara::GetVertMove(int pos, int gx, const Rect& page, int dir, const RichContext& rc) const
|
||||||
{
|
{
|
||||||
Lines pl = FormatLines(page.Width());
|
Lines pl = FormatLines(page.Width(), rc.number);
|
||||||
int lni;
|
int lni;
|
||||||
if(pos >= 0) {
|
if(pos >= 0) {
|
||||||
for(lni = 0; lni < pl.GetCount() - 1; lni++) {
|
for(lni = 0; lni < pl.GetCount() - 1; lni++) {
|
||||||
|
|
@ -540,7 +544,7 @@ int RichPara::GetVertMove(int pos, int gx, const Rect& page, int dir) const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lni += sgn(dir);
|
lni += sgn(dir);
|
||||||
if(lni < 0 || lni >= pl.GetCount())
|
if(lni < 0 || lni >= pl.GetCount() || lni == 0 && pl.number_chars == pl[lni].len)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ struct RichPara::StorePart {
|
||||||
const CharFormat **f;
|
const CharFormat **f;
|
||||||
HeightInfo *h;
|
HeightInfo *h;
|
||||||
int pos;
|
int pos;
|
||||||
FontInfo pfi;
|
Font font;
|
||||||
|
|
||||||
void Store(Lines& lines, const Part& p, int pinc);
|
void Store(Lines& lines, const Part& p, int pinc);
|
||||||
};
|
};
|
||||||
|
|
@ -115,48 +115,47 @@ void RichPara::StorePart::Store(Lines& lines, const Part& part, int pinc)
|
||||||
const wchar *s = part.text;
|
const wchar *s = part.text;
|
||||||
const wchar *lim = part.text.End();
|
const wchar *lim = part.text.End();
|
||||||
Font fnt = part.format;
|
Font fnt = part.format;
|
||||||
FontInfo fi = fnt.Info();
|
Font fi = fnt;
|
||||||
FontInfo wfi = fi;
|
Font wf = fnt;
|
||||||
if(part.format.sscript) {
|
if(part.format.sscript) {
|
||||||
fnt.Height(fnt.GetHeight() * 3 / 5);
|
fnt.Height(fnt.GetHeight() * 3 / 5);
|
||||||
wfi = fnt.Info();
|
wf = fnt;
|
||||||
}
|
}
|
||||||
if(part.format.capitals) {
|
if(part.format.capitals) {
|
||||||
CharFormat& cfmt = lines.hformat.Add();
|
CharFormat& cfmt = lines.hformat.Add();
|
||||||
cfmt = part.format;
|
cfmt = part.format;
|
||||||
cfmt.Height(cfmt.GetHeight() * 4 / 5);
|
cfmt.Height(cfmt.GetHeight() * 4 / 5);
|
||||||
FontInfo cfi = cfmt.Info();
|
Font cwf = cfmt;
|
||||||
FontInfo cwfi = cfi;
|
|
||||||
if(part.format.sscript) {
|
if(part.format.sscript) {
|
||||||
Font fnt = cfmt;
|
Font fnt = cfmt;
|
||||||
fnt.Height(fnt.GetHeight() * 3 / 5);
|
fnt.Height(fnt.GetHeight() * 3 / 5);
|
||||||
cwfi = fnt.Info();
|
cwf = fnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(s < lim) {
|
while(s < lim) {
|
||||||
wchar c = *s++;
|
wchar c = *s++;
|
||||||
if(c == 9) {
|
if(c == 9) {
|
||||||
*f++ = &pfmt;
|
*f++ = &pfmt;
|
||||||
h->ascent = pfi.GetAscent();
|
h->ascent = font.GetAscent();
|
||||||
h->descent = pfi.GetDescent();
|
h->descent = font.GetDescent();
|
||||||
h->external = pfi.GetExternal();
|
h->external = font.GetExternal();
|
||||||
*w++ = 0;
|
*w++ = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if(IsLower(c)) {
|
if(IsLower(c)) {
|
||||||
*f++ = &cfmt;
|
*f++ = &cfmt;
|
||||||
c = (wchar)ToUpper(c);
|
c = (wchar)ToUpper(c);
|
||||||
h->ascent = cfi.GetAscent();
|
h->ascent = cfmt.GetAscent();
|
||||||
h->descent = cfi.GetDescent();
|
h->descent = cfmt.GetDescent();
|
||||||
h->external = cfi.GetExternal();
|
h->external = cfmt.GetExternal();
|
||||||
*w++ = c >= 32 ? cwfi[c] : 0;
|
*w++ = c >= 32 ? cwf[c] : 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*f++ = &pfmt;
|
*f++ = &pfmt;
|
||||||
h->ascent = fi.GetAscent();
|
h->ascent = fi.GetAscent();
|
||||||
h->descent = fi.GetDescent();
|
h->descent = fi.GetDescent();
|
||||||
h->external = fi.GetExternal();
|
h->external = fi.GetExternal();
|
||||||
*w++ = c >= 32 ? wfi[c] : 0;
|
*w++ = c >= 32 ? wf[c] : 0;
|
||||||
}
|
}
|
||||||
h->object = NULL;
|
h->object = NULL;
|
||||||
*t++ = c;
|
*t++ = c;
|
||||||
|
|
@ -170,9 +169,9 @@ void RichPara::StorePart::Store(Lines& lines, const Part& part, int pinc)
|
||||||
wchar c = *s++;
|
wchar c = *s++;
|
||||||
*f++ = &pfmt;
|
*f++ = &pfmt;
|
||||||
if(c == 9) {
|
if(c == 9) {
|
||||||
h->ascent = pfi.GetAscent();
|
h->ascent = font.GetAscent();
|
||||||
h->descent = pfi.GetDescent();
|
h->descent = font.GetDescent();
|
||||||
h->external = pfi.GetExternal();
|
h->external = font.GetExternal();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
h->ascent = fi.GetAscent();
|
h->ascent = fi.GetAscent();
|
||||||
|
|
@ -183,7 +182,7 @@ void RichPara::StorePart::Store(Lines& lines, const Part& part, int pinc)
|
||||||
*p++ = pos;
|
*p++ = pos;
|
||||||
pos += pinc;
|
pos += pinc;
|
||||||
h++;
|
h++;
|
||||||
*w++ = c >= 32 ? wfi[c] : 0;
|
*w++ = c >= 32 ? wf[c] : 0;
|
||||||
*t++ = c;
|
*t++ = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -208,6 +207,7 @@ RichPara::Lines::Lines()
|
||||||
justified = false;
|
justified = false;
|
||||||
incache = false;
|
incache = false;
|
||||||
cacheid = 0;
|
cacheid = 0;
|
||||||
|
number_chars = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<RichPara::Lines>& RichPara::Lines::Cache()
|
Array<RichPara::Lines>& RichPara::Lines::Cache()
|
||||||
|
|
@ -235,7 +235,7 @@ RichPara::Lines::~Lines()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RichPara::Lines RichPara::FormatLines(int acx) const
|
RichPara::Lines RichPara::FormatLines(int acx, const Number& n) const
|
||||||
{
|
{
|
||||||
Lines lines;
|
Lines lines;
|
||||||
if(cacheid) {
|
if(cacheid) {
|
||||||
|
|
@ -250,11 +250,18 @@ RichPara::Lines RichPara::FormatLines(int acx) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Number nn = n;
|
||||||
|
nn.Next(format);
|
||||||
|
WString number = nn.AsText(format).ToWString();
|
||||||
|
|
||||||
|
if(number.GetCount())
|
||||||
|
number.Cat(' ');
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
lines.cacheid = cacheid;
|
lines.cacheid = cacheid;
|
||||||
lines.cx = acx;
|
lines.cx = acx;
|
||||||
lines.len = GetLength();
|
lines.len = GetLength();
|
||||||
lines.clen = CountChars(part);
|
lines.clen = CountChars(part) + number.GetCount();
|
||||||
lines.first_indent = lines.next_indent = format.indent;
|
lines.first_indent = lines.next_indent = format.indent;
|
||||||
if(format.bullet == BULLET_TEXT)
|
if(format.bullet == BULLET_TEXT)
|
||||||
lines.first_indent = 0;
|
lines.first_indent = 0;
|
||||||
|
|
@ -262,8 +269,7 @@ RichPara::Lines RichPara::FormatLines(int acx) const
|
||||||
if(!format.bullet && !format.IsNumbered())
|
if(!format.bullet && !format.IsNumbered())
|
||||||
lines.next_indent = 0;
|
lines.next_indent = 0;
|
||||||
|
|
||||||
FontInfo pfi = format.Info();
|
if(lines.clen == 0) {
|
||||||
if(lines.len == 0) {
|
|
||||||
Line& l = lines.line.Add();
|
Line& l = lines.line.Add();
|
||||||
l.pos = 0;
|
l.pos = 0;
|
||||||
l.ppos = 0;
|
l.ppos = 0;
|
||||||
|
|
@ -273,9 +279,9 @@ RichPara::Lines RichPara::FormatLines(int acx) const
|
||||||
l.withtabs = false;
|
l.withtabs = false;
|
||||||
HeightInfo dummy;
|
HeightInfo dummy;
|
||||||
Smh(lines, &dummy, lines.cx);
|
Smh(lines, &dummy, lines.cx);
|
||||||
l.ascent = pfi.GetAscent();
|
l.ascent = format.GetAscent();
|
||||||
l.descent = pfi.GetDescent();
|
l.descent = format.GetDescent();
|
||||||
l.external = pfi.GetExternal();
|
l.external = format.GetExternal();
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,9 +297,19 @@ RichPara::Lines RichPara::FormatLines(int acx) const
|
||||||
sp.p = lines.pos;
|
sp.p = lines.pos;
|
||||||
sp.f = lines.format;
|
sp.f = lines.format;
|
||||||
sp.h = lines.height;
|
sp.h = lines.height;
|
||||||
sp.pfi = pfi;
|
sp.font = format;
|
||||||
sp.pos = 0;
|
sp.pos = 0;
|
||||||
|
|
||||||
|
if(number.GetCount()) {
|
||||||
|
Part np;
|
||||||
|
np.text = number;
|
||||||
|
np.format = part.GetCount() ? part[0].format : format;
|
||||||
|
np.format.indexentry.Clear();
|
||||||
|
np.format.link.Clear();
|
||||||
|
sp.Store(lines, np, 0);
|
||||||
|
lines.number_chars = number.GetCount();
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0; i < part.GetCount(); i++)
|
for(i = 0; i < part.GetCount(); i++)
|
||||||
sp.Store(lines, part[i], 1);
|
sp.Store(lines, part[i], 1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -303,9 +303,12 @@ int LineZoom(Zoom z, int a);
|
||||||
class RichTable;
|
class RichTable;
|
||||||
class RichText;
|
class RichText;
|
||||||
struct RichStyle;
|
struct RichStyle;
|
||||||
|
struct RichContext;
|
||||||
|
|
||||||
typedef ArrayMap<Uuid, RichStyle> RichStyles;
|
typedef ArrayMap<Uuid, RichStyle> RichStyles;
|
||||||
|
|
||||||
|
#include "Para.h"
|
||||||
|
|
||||||
struct RichContext {
|
struct RichContext {
|
||||||
const RichText *text;
|
const RichText *text;
|
||||||
const RichStyles *styles;
|
const RichStyles *styles;
|
||||||
|
|
@ -314,6 +317,7 @@ struct RichContext {
|
||||||
int current_header_cy, current_footer_cy; // current header/footer size
|
int current_header_cy, current_footer_cy; // current header/footer size
|
||||||
Rect page;
|
Rect page;
|
||||||
PageY py;
|
PageY py;
|
||||||
|
RichPara::Number number;
|
||||||
|
|
||||||
void HeaderFooter(RichText *header, RichText *footer_qtf);
|
void HeaderFooter(RichText *header, RichText *footer_qtf);
|
||||||
void AdjustPage();
|
void AdjustPage();
|
||||||
|
|
@ -324,8 +328,6 @@ struct RichContext {
|
||||||
RichContext() {}
|
RichContext() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "Para.h"
|
|
||||||
|
|
||||||
struct RichPos {
|
struct RichPos {
|
||||||
int tabtextparti;
|
int tabtextparti;
|
||||||
int tabtextpartcount;
|
int tabtextpartcount;
|
||||||
|
|
|
||||||
|
|
@ -70,12 +70,18 @@ protected:
|
||||||
int length;
|
int length;
|
||||||
String content;
|
String content;
|
||||||
Array<RichObject> object;
|
Array<RichObject> object;
|
||||||
int64 updateserial;
|
One<RichPara::NumberFormat> number_fmt;
|
||||||
|
|
||||||
|
mutable int64 updateserial;
|
||||||
|
mutable RichPara::Number number;
|
||||||
|
mutable Vector<int> linecy;
|
||||||
|
mutable Bits spellerrors;
|
||||||
|
mutable String header_qtf, footer_qtf;
|
||||||
|
mutable One<RichText> header, footer;
|
||||||
mutable int ccx;
|
mutable int ccx;
|
||||||
mutable int cy;
|
mutable int cy;
|
||||||
mutable int ruler;
|
mutable int ruler;
|
||||||
mutable int before;
|
mutable int before;
|
||||||
mutable Vector<int> linecy;
|
|
||||||
mutable int after;
|
mutable int after;
|
||||||
mutable bool newpage;
|
mutable bool newpage;
|
||||||
mutable bool firstonpage;
|
mutable bool firstonpage;
|
||||||
|
|
@ -83,15 +89,11 @@ protected:
|
||||||
mutable bool keepnext;
|
mutable bool keepnext;
|
||||||
mutable bool orphan;
|
mutable bool orphan;
|
||||||
mutable int numbering;
|
mutable int numbering;
|
||||||
mutable Bits spellerrors;
|
|
||||||
mutable bool checked;
|
mutable bool checked;
|
||||||
mutable bool haspos;
|
mutable bool haspos;
|
||||||
mutable bool newhdrftr;
|
mutable bool newhdrftr;
|
||||||
mutable String header_qtf, footer_qtf;
|
|
||||||
mutable One<RichText> header, footer;
|
|
||||||
One<RichPara::NumberFormat> number;
|
|
||||||
|
|
||||||
void Invalidate();
|
void Invalidate() const;
|
||||||
|
|
||||||
Para(const Para& src, int);
|
Para(const Para& src, int);
|
||||||
Para() { length = 0; Invalidate(); numbering = -1; checked = false; haspos = false; }
|
Para() { length = 0; Invalidate(); numbering = -1; checked = false; haspos = false; }
|
||||||
|
|
@ -228,7 +230,6 @@ public:
|
||||||
void SetPick(int parti, RichTable&& table);
|
void SetPick(int parti, RichTable&& table);
|
||||||
void CatPick(RichTable&& table) { SetPick(GetPartCount(), pick(table)); }
|
void CatPick(RichTable&& table) { SetPick(GetPartCount(), pick(table)); }
|
||||||
void Set(int parai, const RichPara& p, const RichStyles& s);
|
void Set(int parai, const RichPara& p, const RichStyles& s);
|
||||||
void Insert(int parai, const RichPara& p, const RichStyles& s);
|
|
||||||
void Cat(const RichPara& p, const RichStyles& s) { Set(GetPartCount(), p, s); }
|
void Cat(const RichPara& p, const RichStyles& s) { Set(GetPartCount(), p, s); }
|
||||||
|
|
||||||
void RemovePart(int parti);
|
void RemovePart(int parti);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Upp {
|
namespace Upp {
|
||||||
|
|
||||||
void RichTxt::Para::Invalidate()
|
void RichTxt::Para::Invalidate() const
|
||||||
{
|
{
|
||||||
INTERLOCKED {
|
INTERLOCKED {
|
||||||
static int64 ss;
|
static int64 ss;
|
||||||
|
|
@ -18,8 +18,8 @@ RichTxt::Para::Para(const Para& src, int)
|
||||||
styleid = src.styleid;
|
styleid = src.styleid;
|
||||||
content = src.content;
|
content = src.content;
|
||||||
haspos = src.haspos;
|
haspos = src.haspos;
|
||||||
if(src.number)
|
if(src.number_fmt)
|
||||||
number.Create<RichPara::NumberFormat>(*src.number);
|
number_fmt.Create<RichPara::NumberFormat>(*src.number_fmt);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
checked = false;
|
checked = false;
|
||||||
}
|
}
|
||||||
|
|
@ -115,12 +115,12 @@ void RichTxt::Put(int i, const RichPara& p, const RichStyle& s)
|
||||||
if(i >= part.GetCount() || !IsPara(i))
|
if(i >= part.GetCount() || !IsPara(i))
|
||||||
part.At(i).Create<Para>();
|
part.At(i).Create<Para>();
|
||||||
Para& pp = part[i].Get<Para>();
|
Para& pp = part[i].Get<Para>();
|
||||||
int numbering = p.format.GetNumberLevel();
|
int numbering = p.format.GetNumberLevel(); // level 0 just adds after and before...
|
||||||
if(pp.numbering != numbering)
|
if(pp.numbering != numbering)
|
||||||
SetRefreshFrom(i);
|
SetRefreshFrom(i);
|
||||||
else
|
else
|
||||||
SetRefresh(i);
|
SetRefresh(i);
|
||||||
pp.number.Clear();
|
pp.number_fmt.Clear();
|
||||||
pp.content = p.Pack(s.format, pp.object);
|
pp.content = p.Pack(s.format, pp.object);
|
||||||
pp.Invalidate();
|
pp.Invalidate();
|
||||||
pp.checked = false;
|
pp.checked = false;
|
||||||
|
|
@ -130,7 +130,7 @@ void RichTxt::Put(int i, const RichPara& p, const RichStyle& s)
|
||||||
pp.spellerrors.Clear();
|
pp.spellerrors.Clear();
|
||||||
pp.haspos = p.HasPos();
|
pp.haspos = p.HasPos();
|
||||||
if(numbering >= 0 || p.format.reset_number)
|
if(numbering >= 0 || p.format.reset_number)
|
||||||
pp.number.Create() = p.format;
|
pp.number_fmt.Create() = p.format;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichTxt::Put(int i, const RichPara& p, const RichStyles& s)
|
void RichTxt::Put(int i, const RichPara& p, const RichStyles& s)
|
||||||
|
|
@ -144,12 +144,6 @@ void RichTxt::Set(int i, const RichPara& p, const RichStyles& s)
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichTxt::Insert(int i, const RichPara& p, const RichStyles& s)
|
|
||||||
{
|
|
||||||
part.Insert(i);
|
|
||||||
Set(i, p, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RichTxt::RemovePart(int parti)
|
void RichTxt::RemovePart(int parti)
|
||||||
{
|
{
|
||||||
part.Remove(parti);
|
part.Remove(parti);
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,14 @@ namespace Upp {
|
||||||
int RichTxt::GetWidth(const RichStyles& st) const
|
int RichTxt::GetWidth(const RichStyles& st) const
|
||||||
{
|
{
|
||||||
int cx = 0;
|
int cx = 0;
|
||||||
|
RichPara::Number n;
|
||||||
for(int i = 0; i < part.GetCount(); i++) {
|
for(int i = 0; i < part.GetCount(); i++) {
|
||||||
if(IsPara(i)) {
|
if(IsPara(i)) {
|
||||||
RichPara p = Get(i, st, true);
|
RichPara p = Get(i, st, true);
|
||||||
RichPara::Lines pl = p.FormatLines(INT_MAX);
|
RichPara::Lines pl = p.FormatLines(INT_MAX, n);
|
||||||
if(pl.GetCount())
|
if(pl.GetCount())
|
||||||
cx = max(cx, pl[0].xpos + pl[0].cx);
|
cx = max(cx, pl[0].xpos + pl[0].cx);
|
||||||
|
n.Next(p.format);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cx = max(cx, GetTable(i).GetWidth(st));
|
cx = max(cx, GetTable(i).GetWidth(st));
|
||||||
|
|
@ -20,10 +22,11 @@ int RichTxt::GetWidth(const RichStyles& st) const
|
||||||
|
|
||||||
void RichTxt::Sync0(const Para& pp, int parti, const RichContext& rc) const
|
void RichTxt::Sync0(const Para& pp, int parti, const RichContext& rc) const
|
||||||
{
|
{
|
||||||
|
pp.Invalidate();
|
||||||
int cx = rc.page.Width();
|
int cx = rc.page.Width();
|
||||||
pp.ccx = cx;
|
pp.ccx = cx;
|
||||||
RichPara p = Get(parti, *rc.styles, false);
|
RichPara p = Get(parti, *rc.styles, false);
|
||||||
RichPara::Lines pl = p.FormatLines(cx);
|
RichPara::Lines pl = p.FormatLines(cx, rc.number);
|
||||||
pp.ruler = p.format.ruler;
|
pp.ruler = p.format.ruler;
|
||||||
pp.before = p.format.before;
|
pp.before = p.format.before;
|
||||||
pp.linecy.Clear();
|
pp.linecy.Clear();
|
||||||
|
|
@ -38,6 +41,7 @@ void RichTxt::Sync0(const Para& pp, int parti, const RichContext& rc) const
|
||||||
pp.keepnext = p.format.keepnext;
|
pp.keepnext = p.format.keepnext;
|
||||||
pp.orphan = p.format.orphan;
|
pp.orphan = p.format.orphan;
|
||||||
pp.newhdrftr = p.format.newhdrftr;
|
pp.newhdrftr = p.format.newhdrftr;
|
||||||
|
pp.number = rc.number;
|
||||||
if(~pp.header_qtf != ~p.format.header_qtf) { // we compare just pointers
|
if(~pp.header_qtf != ~p.format.header_qtf) { // we compare just pointers
|
||||||
pp.header_qtf = p.format.header_qtf;
|
pp.header_qtf = p.format.header_qtf;
|
||||||
Upp::SetQTF(pp.header, pp.header_qtf);
|
Upp::SetQTF(pp.header, pp.header_qtf);
|
||||||
|
|
@ -51,7 +55,7 @@ void RichTxt::Sync0(const Para& pp, int parti, const RichContext& rc) const
|
||||||
void RichTxt::Sync(int parti, const RichContext& rc) const {
|
void RichTxt::Sync(int parti, const RichContext& rc) const {
|
||||||
ASSERT(part[parti].Is<Para>());
|
ASSERT(part[parti].Is<Para>());
|
||||||
const Para& pp = part[parti].Get<Para>();
|
const Para& pp = part[parti].Get<Para>();
|
||||||
if(rc.page.Width() != pp.ccx)
|
if(rc.page.Width() != pp.ccx || pp.number_fmt && pp.number != rc.number)
|
||||||
Sync0(pp, parti, rc);
|
Sync0(pp, parti, rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +97,12 @@ void RichTxt::Advance(int parti, RichContext& rc, RichContext& begin) const
|
||||||
int nbefore = 0;
|
int nbefore = 0;
|
||||||
int nline = 0;
|
int nline = 0;
|
||||||
if(pp.keepnext && parti + 1 < part.GetCount() && part[parti + 1].Is<Para>()) {
|
if(pp.keepnext && parti + 1 < part.GetCount() && part[parti + 1].Is<Para>()) {
|
||||||
|
RichPara::Number n = rc.number;
|
||||||
|
if(pp.number_fmt)
|
||||||
|
rc.number.Next(*pp.number_fmt);
|
||||||
Sync(parti + 1, rc);
|
Sync(parti + 1, rc);
|
||||||
|
if(pp.number_fmt)
|
||||||
|
rc.number = n;
|
||||||
const Para& p = part[parti + 1].Get<Para>();
|
const Para& p = part[parti + 1].Get<Para>();
|
||||||
nbefore = p.before + p.ruler;
|
nbefore = p.before + p.ruler;
|
||||||
nline = p.linecy[0];
|
nline = p.linecy[0];
|
||||||
|
|
@ -121,6 +130,8 @@ void RichTxt::Advance(int parti, RichContext& rc, RichContext& begin) const
|
||||||
begin = rc;
|
begin = rc;
|
||||||
rc.py.y += pp.before + pp.cy + pp.after + pp.ruler;
|
rc.py.y += pp.before + pp.cy + pp.after + pp.ruler;
|
||||||
}
|
}
|
||||||
|
if(pp.number_fmt)
|
||||||
|
rc.number.Next(*pp.number_fmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,6 +173,7 @@ void RichTxt::Paint(PageDraw& pw, RichContext& rc, const PaintInfo& _pi) const
|
||||||
PaintInfo pi = _pi;
|
PaintInfo pi = _pi;
|
||||||
int parti = 0;
|
int parti = 0;
|
||||||
RichPara::Number n;
|
RichPara::Number n;
|
||||||
|
rc.number.Reset();
|
||||||
while(rc.py < pi.bottom && parti < part.GetCount()) {
|
while(rc.py < pi.bottom && parti < part.GetCount()) {
|
||||||
if(part[parti].Is<RichTable>()) {
|
if(part[parti].Is<RichTable>()) {
|
||||||
pi.tablesel--;
|
pi.tablesel--;
|
||||||
|
|
@ -173,10 +185,8 @@ void RichTxt::Paint(PageDraw& pw, RichContext& rc, const PaintInfo& _pi) const
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const Para& pp = part[parti].Get<Para>();
|
const Para& pp = part[parti].Get<Para>();
|
||||||
if(pp.number) {
|
if(pp.number_fmt)
|
||||||
n.TestReset(*pp.number);
|
n.Next(*pp.number_fmt);
|
||||||
n.Next(*pp.number);
|
|
||||||
}
|
|
||||||
RichContext begin;
|
RichContext begin;
|
||||||
RichContext next = GetAdvanced(parti, rc, begin);
|
RichContext next = GetAdvanced(parti, rc, begin);
|
||||||
if(next.py >= pi.top) {
|
if(next.py >= pi.top) {
|
||||||
|
|
@ -192,7 +202,7 @@ void RichTxt::Paint(PageDraw& pw, RichContext& rc, const PaintInfo& _pi) const
|
||||||
pp.spellerrors.Clear();
|
pp.spellerrors.Clear();
|
||||||
}
|
}
|
||||||
if(IsPainting(pw, pi.zoom, rc.page, begin.py, next.py))
|
if(IsPainting(pw, pi.zoom, rc.page, begin.py, next.py))
|
||||||
p.Paint(pw, begin, pi, n, pp.spellerrors, rc.text == this);
|
p.Paint(pw, begin, pi, pp.number_fmt ? rc.number : n, pp.spellerrors, rc.text == this);
|
||||||
}
|
}
|
||||||
rc = next;
|
rc = next;
|
||||||
}
|
}
|
||||||
|
|
@ -209,6 +219,7 @@ RichCaret RichTxt::GetCaret(int pos, RichContext rc) const
|
||||||
int parti = 0;
|
int parti = 0;
|
||||||
if(pos > GetLength())
|
if(pos > GetLength())
|
||||||
pos = GetLength();
|
pos = GetLength();
|
||||||
|
rc.number.Reset();
|
||||||
while(parti < part.GetCount()) {
|
while(parti < part.GetCount()) {
|
||||||
int l = GetPartLength(parti) + 1;
|
int l = GetPartLength(parti) + 1;
|
||||||
RichContext begin;
|
RichContext begin;
|
||||||
|
|
@ -230,6 +241,8 @@ RichCaret RichTxt::GetCaret(int pos, RichContext rc) const
|
||||||
|
|
||||||
int RichTxt::GetPos(int x, PageY y, RichContext rc) const
|
int RichTxt::GetPos(int x, PageY y, RichContext rc) const
|
||||||
{
|
{
|
||||||
|
rc.number.Reset();
|
||||||
|
|
||||||
int parti = 0;
|
int parti = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
|
|
@ -253,6 +266,8 @@ int RichTxt::GetPos(int x, PageY y, RichContext rc) const
|
||||||
|
|
||||||
RichHotPos RichTxt::GetHotPos(int x, PageY y, int tolerance, RichContext rc) const
|
RichHotPos RichTxt::GetHotPos(int x, PageY y, int tolerance, RichContext rc) const
|
||||||
{
|
{
|
||||||
|
rc.number.Reset();
|
||||||
|
|
||||||
int parti = 0;
|
int parti = 0;
|
||||||
int ti = 0;
|
int ti = 0;
|
||||||
if(part.GetCount()) {
|
if(part.GetCount()) {
|
||||||
|
|
@ -280,6 +295,8 @@ RichHotPos RichTxt::GetHotPos(int x, PageY y, int tolerance, RichContext rc) con
|
||||||
|
|
||||||
int RichTxt::GetVertMove(int pos, int gx, RichContext rc, int dir) const
|
int RichTxt::GetVertMove(int pos, int gx, RichContext rc, int dir) const
|
||||||
{
|
{
|
||||||
|
rc.number.Reset();
|
||||||
|
|
||||||
ASSERT(dir == -1 || dir == 1);
|
ASSERT(dir == -1 || dir == 1);
|
||||||
if(GetPartCount() == 0)
|
if(GetPartCount() == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -295,8 +312,13 @@ int RichTxt::GetVertMove(int pos, int gx, RichContext rc, int dir) const
|
||||||
pos = GetPartPos(pi);
|
pos = GetPartPos(pi);
|
||||||
}
|
}
|
||||||
while(pi < GetPartCount()) {
|
while(pi < GetPartCount()) {
|
||||||
int q = IsTable(pi) ? GetTable(pi).GetVertMove(p, gx, rc, dir)
|
int q;
|
||||||
: Get(pi, *rc.styles, true).GetVertMove(p, gx, rc.page, dir);
|
if(IsTable(pi))
|
||||||
|
q = GetTable(pi).GetVertMove(p, gx, rc, dir);
|
||||||
|
else {
|
||||||
|
rc.number = part[pi].Get<Para>().number;
|
||||||
|
q = Get(pi, *rc.styles, true).GetVertMove(p, gx, rc.page, dir, rc);
|
||||||
|
}
|
||||||
if(q >= 0)
|
if(q >= 0)
|
||||||
return q + pos;
|
return q + pos;
|
||||||
if(dir > 0)
|
if(dir > 0)
|
||||||
|
|
@ -313,6 +335,8 @@ int RichTxt::GetVertMove(int pos, int gx, RichContext rc, int dir) const
|
||||||
|
|
||||||
void RichTxt::GatherValPos(Vector<RichValPos>& f, RichContext rc, int pos, int type) const
|
void RichTxt::GatherValPos(Vector<RichValPos>& f, RichContext rc, int pos, int type) const
|
||||||
{
|
{
|
||||||
|
rc.number.Reset();
|
||||||
|
|
||||||
int parti = 0;
|
int parti = 0;
|
||||||
while(parti < part.GetCount()) {
|
while(parti < part.GetCount()) {
|
||||||
RichContext begin;
|
RichContext begin;
|
||||||
|
|
|
||||||
10
upptst/RichTextNumbering/RichTextNumbering.upp
Normal file
10
upptst/RichTextNumbering/RichTextNumbering.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
uses
|
||||||
|
CtrlLib,
|
||||||
|
RichEdit;
|
||||||
|
|
||||||
|
file
|
||||||
|
main.cpp;
|
||||||
|
|
||||||
|
mainconfig
|
||||||
|
"" = "GUI";
|
||||||
|
|
||||||
19
upptst/RichTextNumbering/main.cpp
Normal file
19
upptst/RichTextNumbering/main.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include <RichEdit/RichEdit.h>
|
||||||
|
|
||||||
|
using namespace Upp;
|
||||||
|
|
||||||
|
GUI_APP_MAIN
|
||||||
|
{
|
||||||
|
// PromptOK("[NI; Number 1&][NIA; Number 1a&][NIa; Number 1b&][NIa; &][NI; Number 2&][N1; Last 3]");
|
||||||
|
RichEditWithToolBar edit;
|
||||||
|
TopWindow win;
|
||||||
|
edit.SetQTF(
|
||||||
|
"[ $$0,0#00000000000000000000000000000000:Default]\r\n[{_} \r\n[s0;NI; Number 1&]\r\n[s0;NIA; Number 1a&]\r\n[s0;NIa; Number 1b&]\r\n[ {{5000:5000 [s0;NIa; ]\r\n:: [s0;NIa; ssasdf]}}&]\r\n[s0;r3264;NIa; asdf&]\r\n[s0;r3264;NIa; asdf&]\r\n[s0;r3264;NIa; &]\r\n[s0; &]\r\n[s0; &]\r\n[s0; &]\r\n[s0;r3264;NIa; &]\r\n[s0;r3264;NIa; asdfasdfasdf&]\r\n[s0;r3264;NIa; &]\r\n[s0;r3264;NIa; asdfasdfasdf&]\r\n[s0;r3264;NIa; &]\r\n[s0;r3264;NI; Number 2&]\r\n[s0;r3264;N1; Last 3]]"
|
||||||
|
);
|
||||||
|
|
||||||
|
edit.WhenSel << [&] { win.Title(AsString(edit.GetCursor())); };
|
||||||
|
win.Add(edit.SizePos());
|
||||||
|
win.Run();
|
||||||
|
|
||||||
|
DDUMP(AsCString(edit.GetQTF()));
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue