RichHotPos RichTxt::GetHotPos(int x, PageY y, int tolerance, RichContext rc) const { int parti = 0; int pos = 0; int ti = 0; if(part.GetCount()) { PageY nnext = GetNextPageY(parti, rc); while(parti < part.GetCount()) { PageY next = nnext; if(parti + 1 < part.GetCount()) { RichContext nrc = rc; nrc.py = next; nnext = GetNextPageY(parti + 1, nrc); } if(y < next || y.page < next.page) { if(IsTable(parti)) { RichHotPos pos = GetTable(parti).GetHotPos(x, y, tolerance, rc); pos.table += ti + 1; return pos; } else break; } if(IsTable(parti)) ti += 1 + GetTable(parti).GetTableCount(); pos += GetPartLength(parti) + 1; parti++; rc.py = next; } } return RichHotPos(); }
void RichTxt::GatherValPos(Vector<RichValPos>& f, RichContext rc, int pos, int type) const { int parti = 0; while(parti < part.GetCount()) { if(part[parti].Is<RichTable>()) GetTable(parti).GatherValPos(f, rc, pos, type); else { int nbefore = 0; int nline = 0; const Para& p = part[parti].Get<Para>(); if(p.keepnext && parti + 1 < part.GetCount() && IsPara(parti + 1)) { Sync(parti + 1, rc); const Para& pp = part[parti + 1].Get<Para>(); nbefore = pp.before; nline = pp.linecy[0]; } if(p.haspos) if(type == LABELS) Get(parti, rc.styles).GatherLabels(f, rc.page, rc.py, pos, nbefore, nline); else Get(parti, rc.styles).GatherIndexes(f, rc.page, rc.py, pos, nbefore, nline); } pos += GetPartLength(parti) + 1; rc.py = GetNextPageY(parti++, rc); } }
RichCaret RichTxt::GetCaret(int pos, RichContext rc) const { int parti = 0; if(pos > GetLength()) pos = GetLength(); while(parti < part.GetCount()) { int l = GetPartLength(parti) + 1; if(pos < l) if(IsTable(parti)) return GetTable(parti).GetCaret(pos, rc); else { const Para& p = part[parti].Get<Para>(); int nbefore = 0; int nline = 0; if(p.keepnext && parti + 1 < part.GetCount() && part[parti + 1].Is<Para>()) { Sync(parti + 1, rc); const Para& pp = part[parti + 1].Get<Para>(); nbefore = pp.before; nline = pp.linecy[0]; } RichCaret tp = Get(parti, rc.styles).GetCaret(pos, rc.page, rc.py, nbefore, nline); tp.textpage = rc.page; return tp; } pos -= l; rc.py = GetNextPageY(parti++, rc); } return RichCaret(); }
void RichTxt::Paint(PageDraw& pw, RichContext rc, const PaintInfo& _pi) const { PaintInfo pi = _pi; int parti = 0; int pos = 0; RichPara::Number n; while(rc.py < pi.bottom && parti < part.GetCount()) { if(part[parti].Is<RichTable>()) { pi.tablesel--; const RichTable& tab = GetTable(parti); tab.Paint(pw, rc, pi); rc.py = tab.GetHeight(rc); pi.tablesel -= tab.GetTableCount(); } else { const Para& pp = part[parti].Get<Para>(); if(pp.number) { n.TestReset(*pp.number); n.Next(*pp.number); } PageY next = GetNextPageY(parti, rc); if(next >= pi.top) { int nbefore = 0; int nline = 0; if(pp.keepnext && parti + 1 < part.GetCount() && part[parti + 1].Is<Para>()) { Sync(parti + 1, rc); const Para& pp = part[parti + 1].Get<Para>(); nbefore = pp.before; nline = pp.linecy[0]; } RichPara p = Get(parti, rc.styles); if(pi.spellingchecker) { if(!pp.checked) { pp.spellerrors = (*pi.spellingchecker)(p); pp.checked = true; } } else { pp.checked = false; pp.spellerrors.Clear(); } if(IsPainting(pw, pi.zoom, rc.page, rc.py, next)) p.Paint(pw, rc.page, rc.py, pi, n, pp.spellerrors, nbefore, nline); } rc.py = next; } int l = GetPartLength(parti) + 1; pi.highlightpara -= l; pi.sell -= l; pi.selh -= l; pos += l; ++parti; } }
int RichTxt::GetPos(int x, PageY y, RichContext rc) const { int parti = 0; int pos = 0; if(part.GetCount()) { PageY nnext = GetNextPageY(parti, rc); while(parti < part.GetCount()) { PageY next = nnext; if(parti + 1 < part.GetCount()) { RichContext nrc = rc; nrc.py = next; nnext = GetNextPageY(parti + 1, nrc); } if(y < next || y.page < next.page) { if(IsTable(parti)) return GetTable(parti).GetPos(x, y, rc) + pos; else { int nbefore = 0; int nline = 0; if(part[parti].Get<Para>().keepnext && parti + 1 < part.GetCount() && IsPara(parti + 1)) { Sync(parti + 1, rc); const Para& pp = part[parti + 1].Get<Para>(); nbefore = pp.before; nline = pp.linecy[0]; } return Get(parti, rc.styles).GetPos(x, y, rc.page, rc.py, nbefore, nline) + pos; } } pos += GetPartLength(parti) + 1; parti++; rc.py = next; } } return pos - 1; }
PageY RichTxt::GetHeight(RichContext rc) const { for(int i = 0; i < GetPartCount(); i++) rc.py = GetNextPageY(i, rc); return rc.py; }
PageY RichTxt::GetPartPageY(int parti, RichContext rc) const { for(int i = 0; i < parti; i++) rc.py = GetNextPageY(i, rc); return rc.py; }
bool RichText::GetInvalid(PageY& top, PageY& bottom, const Rect& page, int sell, int selh, int osell, int oselh) const { Mutex::Lock __(mutex); int spi = 0; int rtype = r_type; if(sell != selh || osell != oselh) { if(sell != osell) { if(rtype == NONE) { spi = FindPart(sell); rtype = spi == FindPart(osell) ? SPARA : ALL; } else rtype = ALL; } if(selh != oselh) { if(rtype == NONE) { spi = FindPart(selh); rtype = spi == FindPart(oselh) ? SPARA : ALL; } else rtype = ALL; } } bottom = top = PageY(0, page.top); if(rtype == NONE) { bottom = top; return false; } if(rtype == ALL) { bottom = GetHeight(page); return true; } #if 0 RichContext rc = Context(page, PageY(0, 0)); if(rtype == SPARA) { rc.py = top = GetPartPageY(spi, rc); bottom = GetNextPageY(spi, rc); return true; } #endif RichContext begin; if(rtype == SPARA) { // selection changed within single paragraph RichContext rc = GetPartContext(spi, Context(page)); top = rc.py; bottom = GetAdvanced(spi, rc, begin).py; return true; } RichContext rc = GetPartContext(r_parti, Context(page)); top = rc.py; if(rtype == PARA) { if(IsTable(r_parti)) switch(GetTable(r_parti).GetInvalid(top, bottom, rc)) { case -1: return false; case 0: return true; default: bottom = GetHeight(page); return true; } else { Sync(r_parti, rc); const Para& pp = part[r_parti].Get<Para>(); if(r_paraocx == pp.ccx && r_paraocy == Sum(pp.linecy, 0) + pp.ruler + pp.before + pp.after && r_keep == pp.keep && r_keepnext == pp.keepnext && r_newpage == pp.newpage) { bottom = GetAdvanced(r_parti, rc, begin).py; return true; } } } bottom = GetHeight(page); return true; }