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();
|
||||
}
|
||||
useraction = modified = false;
|
||||
WhenSel();
|
||||
}
|
||||
|
||||
void RichEdit::Finish()
|
||||
|
|
|
|||
|
|
@ -673,6 +673,7 @@ public:
|
|||
Event<String&> WhenLabel;
|
||||
Event<String&> WhenIndexEntry;
|
||||
Event<Bar&> WhenBar;
|
||||
Event<> WhenSel;
|
||||
|
||||
void StdBar(Bar& menu);
|
||||
|
||||
|
|
|
|||
|
|
@ -144,10 +144,12 @@ struct RichPara {
|
|||
int n[8];
|
||||
|
||||
String AsText(const NumberFormat& format) const;
|
||||
void TestReset(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 {
|
||||
|
|
@ -182,10 +184,10 @@ struct RichPara {
|
|||
};
|
||||
|
||||
struct Line : public HeightInfo {
|
||||
int pos;
|
||||
int len;
|
||||
int ppos;
|
||||
int plen;
|
||||
int pos; // offset in Lines arrays (e.g. text or pos)
|
||||
int len; // number of characters in lines array
|
||||
int ppos; // position of the first character
|
||||
int plen; // length in source characters (e.g. fields are single)
|
||||
int xpos;
|
||||
int cx;
|
||||
int objecti;
|
||||
|
|
@ -207,6 +209,7 @@ struct RichPara {
|
|||
Array<RichObject> object;
|
||||
int first_indent;
|
||||
int next_indent;
|
||||
int number_chars; // if paragraph starts with numbering, otherwise 0
|
||||
|
||||
|
||||
int GetCount() const { return line.GetCount(); }
|
||||
|
|
@ -265,13 +268,13 @@ struct RichPara {
|
|||
|
||||
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;
|
||||
RichCaret GetCaret(int pos, RichContext rc) const;
|
||||
int GetPos(int x, PageY y, RichContext rc) const;
|
||||
void GatherLabels(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;
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ String RichPara::Number::AsText(const RichPara::NumberFormat& format) const
|
|||
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) {
|
||||
bool done = false;
|
||||
|
|
@ -111,10 +111,6 @@ void RichPara::Number::TestReset(const RichPara::NumberFormat& fmt)
|
|||
if(!done && !IsNull(n[0]))
|
||||
n[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RichPara::Number::Next(const RichPara::NumberFormat& fmt)
|
||||
{
|
||||
for(int i = 7; i >= 0; --i)
|
||||
if(fmt.number[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
|
||||
{
|
||||
if(before_number.GetLength() || after_number.GetLength())
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ Color PaintInfo::ResolvePaper(Color paper) 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;
|
||||
pl.Justify(format);
|
||||
return pl;
|
||||
|
|
@ -337,15 +337,6 @@ void RichPara::Paint(PageDraw& pw, RichContext rc, const PaintInfo& pi,
|
|||
case BULLET_ROUND:
|
||||
draw.DrawEllipse(r, pi.ResolveInk(bullet_ink));
|
||||
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;
|
||||
|
|
@ -464,16 +455,23 @@ RichCaret RichPara::GetCaret(int pos, RichContext rc) const
|
|||
pr.lineascent = li.ascent;
|
||||
pr.line = lni;
|
||||
if(pos < li.ppos + li.plen) {
|
||||
int *w = pl.width + li.pos;
|
||||
int *p = pl.pos + li.pos;
|
||||
const CharFormat **i = pl.format + li.pos;
|
||||
const HeightInfo *h = pl.height + li.pos;
|
||||
int npos = li.pos;
|
||||
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) {
|
||||
pr.caretascent = h->ascent;
|
||||
pr.caretdescent = h->descent;
|
||||
}
|
||||
while(pos > *p) {
|
||||
while(pos > *p) { // second condition to skip the number
|
||||
x += *w++;
|
||||
if(*i) {
|
||||
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
|
||||
{
|
||||
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 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)
|
||||
xp += *w++;
|
||||
int pos = (int)(w - pl.width);
|
||||
|
|
@ -529,9 +533,9 @@ int RichPara::GetPos(int x, PageY y, RichContext rc) const
|
|||
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;
|
||||
if(pos >= 0) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ struct RichPara::StorePart {
|
|||
const CharFormat **f;
|
||||
HeightInfo *h;
|
||||
int pos;
|
||||
FontInfo pfi;
|
||||
Font font;
|
||||
|
||||
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 *lim = part.text.End();
|
||||
Font fnt = part.format;
|
||||
FontInfo fi = fnt.Info();
|
||||
FontInfo wfi = fi;
|
||||
Font fi = fnt;
|
||||
Font wf = fnt;
|
||||
if(part.format.sscript) {
|
||||
fnt.Height(fnt.GetHeight() * 3 / 5);
|
||||
wfi = fnt.Info();
|
||||
wf = fnt;
|
||||
}
|
||||
if(part.format.capitals) {
|
||||
CharFormat& cfmt = lines.hformat.Add();
|
||||
cfmt = part.format;
|
||||
cfmt.Height(cfmt.GetHeight() * 4 / 5);
|
||||
FontInfo cfi = cfmt.Info();
|
||||
FontInfo cwfi = cfi;
|
||||
Font cwf = cfmt;
|
||||
if(part.format.sscript) {
|
||||
Font fnt = cfmt;
|
||||
fnt.Height(fnt.GetHeight() * 3 / 5);
|
||||
cwfi = fnt.Info();
|
||||
cwf = fnt;
|
||||
}
|
||||
|
||||
while(s < lim) {
|
||||
wchar c = *s++;
|
||||
if(c == 9) {
|
||||
*f++ = &pfmt;
|
||||
h->ascent = pfi.GetAscent();
|
||||
h->descent = pfi.GetDescent();
|
||||
h->external = pfi.GetExternal();
|
||||
h->ascent = font.GetAscent();
|
||||
h->descent = font.GetDescent();
|
||||
h->external = font.GetExternal();
|
||||
*w++ = 0;
|
||||
}
|
||||
else
|
||||
if(IsLower(c)) {
|
||||
*f++ = &cfmt;
|
||||
c = (wchar)ToUpper(c);
|
||||
h->ascent = cfi.GetAscent();
|
||||
h->descent = cfi.GetDescent();
|
||||
h->external = cfi.GetExternal();
|
||||
*w++ = c >= 32 ? cwfi[c] : 0;
|
||||
h->ascent = cfmt.GetAscent();
|
||||
h->descent = cfmt.GetDescent();
|
||||
h->external = cfmt.GetExternal();
|
||||
*w++ = c >= 32 ? cwf[c] : 0;
|
||||
}
|
||||
else {
|
||||
*f++ = &pfmt;
|
||||
h->ascent = fi.GetAscent();
|
||||
h->descent = fi.GetDescent();
|
||||
h->external = fi.GetExternal();
|
||||
*w++ = c >= 32 ? wfi[c] : 0;
|
||||
*w++ = c >= 32 ? wf[c] : 0;
|
||||
}
|
||||
h->object = NULL;
|
||||
*t++ = c;
|
||||
|
|
@ -170,9 +169,9 @@ void RichPara::StorePart::Store(Lines& lines, const Part& part, int pinc)
|
|||
wchar c = *s++;
|
||||
*f++ = &pfmt;
|
||||
if(c == 9) {
|
||||
h->ascent = pfi.GetAscent();
|
||||
h->descent = pfi.GetDescent();
|
||||
h->external = pfi.GetExternal();
|
||||
h->ascent = font.GetAscent();
|
||||
h->descent = font.GetDescent();
|
||||
h->external = font.GetExternal();
|
||||
}
|
||||
else {
|
||||
h->ascent = fi.GetAscent();
|
||||
|
|
@ -183,7 +182,7 @@ void RichPara::StorePart::Store(Lines& lines, const Part& part, int pinc)
|
|||
*p++ = pos;
|
||||
pos += pinc;
|
||||
h++;
|
||||
*w++ = c >= 32 ? wfi[c] : 0;
|
||||
*w++ = c >= 32 ? wf[c] : 0;
|
||||
*t++ = c;
|
||||
}
|
||||
}
|
||||
|
|
@ -208,6 +207,7 @@ RichPara::Lines::Lines()
|
|||
justified = false;
|
||||
incache = false;
|
||||
cacheid = 0;
|
||||
number_chars = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
lines.cacheid = cacheid;
|
||||
lines.cx = acx;
|
||||
lines.len = GetLength();
|
||||
lines.clen = CountChars(part);
|
||||
lines.clen = CountChars(part) + number.GetCount();
|
||||
lines.first_indent = lines.next_indent = format.indent;
|
||||
if(format.bullet == BULLET_TEXT)
|
||||
lines.first_indent = 0;
|
||||
|
|
@ -262,8 +269,7 @@ RichPara::Lines RichPara::FormatLines(int acx) const
|
|||
if(!format.bullet && !format.IsNumbered())
|
||||
lines.next_indent = 0;
|
||||
|
||||
FontInfo pfi = format.Info();
|
||||
if(lines.len == 0) {
|
||||
if(lines.clen == 0) {
|
||||
Line& l = lines.line.Add();
|
||||
l.pos = 0;
|
||||
l.ppos = 0;
|
||||
|
|
@ -273,9 +279,9 @@ RichPara::Lines RichPara::FormatLines(int acx) const
|
|||
l.withtabs = false;
|
||||
HeightInfo dummy;
|
||||
Smh(lines, &dummy, lines.cx);
|
||||
l.ascent = pfi.GetAscent();
|
||||
l.descent = pfi.GetDescent();
|
||||
l.external = pfi.GetExternal();
|
||||
l.ascent = format.GetAscent();
|
||||
l.descent = format.GetDescent();
|
||||
l.external = format.GetExternal();
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
|
@ -291,9 +297,19 @@ RichPara::Lines RichPara::FormatLines(int acx) const
|
|||
sp.p = lines.pos;
|
||||
sp.f = lines.format;
|
||||
sp.h = lines.height;
|
||||
sp.pfi = pfi;
|
||||
sp.font = format;
|
||||
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++)
|
||||
sp.Store(lines, part[i], 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -303,9 +303,12 @@ int LineZoom(Zoom z, int a);
|
|||
class RichTable;
|
||||
class RichText;
|
||||
struct RichStyle;
|
||||
struct RichContext;
|
||||
|
||||
typedef ArrayMap<Uuid, RichStyle> RichStyles;
|
||||
|
||||
#include "Para.h"
|
||||
|
||||
struct RichContext {
|
||||
const RichText *text;
|
||||
const RichStyles *styles;
|
||||
|
|
@ -314,6 +317,7 @@ struct RichContext {
|
|||
int current_header_cy, current_footer_cy; // current header/footer size
|
||||
Rect page;
|
||||
PageY py;
|
||||
RichPara::Number number;
|
||||
|
||||
void HeaderFooter(RichText *header, RichText *footer_qtf);
|
||||
void AdjustPage();
|
||||
|
|
@ -324,8 +328,6 @@ struct RichContext {
|
|||
RichContext() {}
|
||||
};
|
||||
|
||||
#include "Para.h"
|
||||
|
||||
struct RichPos {
|
||||
int tabtextparti;
|
||||
int tabtextpartcount;
|
||||
|
|
|
|||
|
|
@ -70,12 +70,18 @@ protected:
|
|||
int length;
|
||||
String content;
|
||||
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 cy;
|
||||
mutable int ruler;
|
||||
mutable int before;
|
||||
mutable Vector<int> linecy;
|
||||
mutable int after;
|
||||
mutable bool newpage;
|
||||
mutable bool firstonpage;
|
||||
|
|
@ -83,15 +89,11 @@ protected:
|
|||
mutable bool keepnext;
|
||||
mutable bool orphan;
|
||||
mutable int numbering;
|
||||
mutable Bits spellerrors;
|
||||
mutable bool checked;
|
||||
mutable bool haspos;
|
||||
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() { length = 0; Invalidate(); numbering = -1; checked = false; haspos = false; }
|
||||
|
|
@ -228,7 +230,6 @@ public:
|
|||
void SetPick(int parti, RichTable&& table);
|
||||
void CatPick(RichTable&& table) { SetPick(GetPartCount(), pick(table)); }
|
||||
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 RemovePart(int parti);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Upp {
|
||||
|
||||
void RichTxt::Para::Invalidate()
|
||||
void RichTxt::Para::Invalidate() const
|
||||
{
|
||||
INTERLOCKED {
|
||||
static int64 ss;
|
||||
|
|
@ -18,8 +18,8 @@ RichTxt::Para::Para(const Para& src, int)
|
|||
styleid = src.styleid;
|
||||
content = src.content;
|
||||
haspos = src.haspos;
|
||||
if(src.number)
|
||||
number.Create<RichPara::NumberFormat>(*src.number);
|
||||
if(src.number_fmt)
|
||||
number_fmt.Create<RichPara::NumberFormat>(*src.number_fmt);
|
||||
Invalidate();
|
||||
checked = false;
|
||||
}
|
||||
|
|
@ -115,12 +115,12 @@ void RichTxt::Put(int i, const RichPara& p, const RichStyle& s)
|
|||
if(i >= part.GetCount() || !IsPara(i))
|
||||
part.At(i).Create<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)
|
||||
SetRefreshFrom(i);
|
||||
else
|
||||
SetRefresh(i);
|
||||
pp.number.Clear();
|
||||
pp.number_fmt.Clear();
|
||||
pp.content = p.Pack(s.format, pp.object);
|
||||
pp.Invalidate();
|
||||
pp.checked = false;
|
||||
|
|
@ -130,7 +130,7 @@ void RichTxt::Put(int i, const RichPara& p, const RichStyle& s)
|
|||
pp.spellerrors.Clear();
|
||||
pp.haspos = p.HasPos();
|
||||
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)
|
||||
|
|
@ -144,12 +144,6 @@ void RichTxt::Set(int i, const RichPara& p, const RichStyles& s)
|
|||
Invalidate();
|
||||
}
|
||||
|
||||
void RichTxt::Insert(int i, const RichPara& p, const RichStyles& s)
|
||||
{
|
||||
part.Insert(i);
|
||||
Set(i, p, s);
|
||||
}
|
||||
|
||||
void RichTxt::RemovePart(int parti)
|
||||
{
|
||||
part.Remove(parti);
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ namespace Upp {
|
|||
int RichTxt::GetWidth(const RichStyles& st) const
|
||||
{
|
||||
int cx = 0;
|
||||
RichPara::Number n;
|
||||
for(int i = 0; i < part.GetCount(); i++) {
|
||||
if(IsPara(i)) {
|
||||
RichPara p = Get(i, st, true);
|
||||
RichPara::Lines pl = p.FormatLines(INT_MAX);
|
||||
RichPara::Lines pl = p.FormatLines(INT_MAX, n);
|
||||
if(pl.GetCount())
|
||||
cx = max(cx, pl[0].xpos + pl[0].cx);
|
||||
n.Next(p.format);
|
||||
}
|
||||
else
|
||||
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
|
||||
{
|
||||
pp.Invalidate();
|
||||
int cx = rc.page.Width();
|
||||
pp.ccx = cx;
|
||||
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.before = p.format.before;
|
||||
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.orphan = p.format.orphan;
|
||||
pp.newhdrftr = p.format.newhdrftr;
|
||||
pp.number = rc.number;
|
||||
if(~pp.header_qtf != ~p.format.header_qtf) { // we compare just pointers
|
||||
pp.header_qtf = p.format.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 {
|
||||
ASSERT(part[parti].Is<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);
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +97,12 @@ void RichTxt::Advance(int parti, RichContext& rc, RichContext& begin) const
|
|||
int nbefore = 0;
|
||||
int nline = 0;
|
||||
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);
|
||||
if(pp.number_fmt)
|
||||
rc.number = n;
|
||||
const Para& p = part[parti + 1].Get<Para>();
|
||||
nbefore = p.before + p.ruler;
|
||||
nline = p.linecy[0];
|
||||
|
|
@ -121,6 +130,8 @@ void RichTxt::Advance(int parti, RichContext& rc, RichContext& begin) const
|
|||
begin = rc;
|
||||
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;
|
||||
int parti = 0;
|
||||
RichPara::Number n;
|
||||
rc.number.Reset();
|
||||
while(rc.py < pi.bottom && parti < part.GetCount()) {
|
||||
if(part[parti].Is<RichTable>()) {
|
||||
pi.tablesel--;
|
||||
|
|
@ -173,10 +185,8 @@ void RichTxt::Paint(PageDraw& pw, RichContext& rc, const PaintInfo& _pi) const
|
|||
}
|
||||
else {
|
||||
const Para& pp = part[parti].Get<Para>();
|
||||
if(pp.number) {
|
||||
n.TestReset(*pp.number);
|
||||
n.Next(*pp.number);
|
||||
}
|
||||
if(pp.number_fmt)
|
||||
n.Next(*pp.number_fmt);
|
||||
RichContext begin;
|
||||
RichContext next = GetAdvanced(parti, rc, begin);
|
||||
if(next.py >= pi.top) {
|
||||
|
|
@ -192,7 +202,7 @@ void RichTxt::Paint(PageDraw& pw, RichContext& rc, const PaintInfo& _pi) const
|
|||
pp.spellerrors.Clear();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
@ -209,6 +219,7 @@ RichCaret RichTxt::GetCaret(int pos, RichContext rc) const
|
|||
int parti = 0;
|
||||
if(pos > GetLength())
|
||||
pos = GetLength();
|
||||
rc.number.Reset();
|
||||
while(parti < part.GetCount()) {
|
||||
int l = GetPartLength(parti) + 1;
|
||||
RichContext begin;
|
||||
|
|
@ -230,6 +241,8 @@ RichCaret RichTxt::GetCaret(int pos, RichContext rc) const
|
|||
|
||||
int RichTxt::GetPos(int x, PageY y, RichContext rc) const
|
||||
{
|
||||
rc.number.Reset();
|
||||
|
||||
int parti = 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
|
||||
{
|
||||
rc.number.Reset();
|
||||
|
||||
int parti = 0;
|
||||
int ti = 0;
|
||||
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
|
||||
{
|
||||
rc.number.Reset();
|
||||
|
||||
ASSERT(dir == -1 || dir == 1);
|
||||
if(GetPartCount() == 0)
|
||||
return -1;
|
||||
|
|
@ -295,8 +312,13 @@ int RichTxt::GetVertMove(int pos, int gx, RichContext rc, int dir) const
|
|||
pos = GetPartPos(pi);
|
||||
}
|
||||
while(pi < GetPartCount()) {
|
||||
int q = IsTable(pi) ? GetTable(pi).GetVertMove(p, gx, rc, dir)
|
||||
: Get(pi, *rc.styles, true).GetVertMove(p, gx, rc.page, dir);
|
||||
int q;
|
||||
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)
|
||||
return q + pos;
|
||||
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
|
||||
{
|
||||
rc.number.Reset();
|
||||
|
||||
int parti = 0;
|
||||
while(parti < part.GetCount()) {
|
||||
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