void LineEdit::LeftTriple(Point, dword) { int q = cursor; int i = GetLinePos(q); q = cursor - q; SetSelection(q, q + GetLineLength(i) + 1); }
bool DCirfile::FindNum(const char *sect, uns num) { CurrLeft = sect; CurrPos = 0; for (;;) { CurrLeft = GetLinePos(CurrLeft); if (!CurrLeft) return false; //skipLine(); if ((*CurrLeft == ';') || (*CurrLeft == '\r') || (*CurrLeft == '\n')) continue; if ((*CurrLeft == '\0') || (*CurrLeft == '[')) { CurrLeft = CurrRight = NULL; LeftLen = RightLen = 0; CurrPos = 0; return false; } CurrPos++; if (isdigit(*CurrLeft)) { if (atol(CurrLeft) == num) break; } } setRight(); return true; }
bool DCirfile::NextItemStr(const char *pos) { CurrLeft = pos; for (;;) { CurrLeft = GetLinePos(CurrLeft); if (!CurrLeft) return false; //skipLine(); if (isalnum(*CurrLeft) || (ispunct(*CurrLeft) && ((*CurrLeft != ';') || (*(CurrLeft + 1) == '=')) // deleted setting && (*CurrLeft != '[')) || (*CurrLeft < 0)) { // allow high-bit chars if (*CurrLeft == '\\') CurrLeft++; break; } if ((*CurrLeft == '\0') || (*CurrLeft == '[')) { CurrLeft = CurrRight = NULL; LeftLen = RightLen = 0; return false; } } setRight(); return true; }
Point LineEdit::GetIndexLine(int pos) const { Point p; if(pos > total) pos = total; p.y = GetLinePos(pos); p.x = minmax(pos, 0, line[p.y].GetLength()); return p; }
void LineEdit::MoveHome(bool sel) { int cl = cursor; int li = GetLinePos(cl); int i = 0; WString l = line[li]; while(sTabSpace(l[i])) i++; PlaceCaret(GetPos(li, cl == i ? 0 : i), sel); }
bool DCirfile::FindStr(const char *sect, const char **names, short count) { if (!names || !count) return false; CurrLeft = sect; CurrPos = 0; if (!names[0]) return false; uns len = strlen(names[0]); if (len == 0) return false; for (;;) { CurrLeft = GetLinePos(CurrLeft); if (!CurrLeft) return false; //skipLine(); if ((*CurrLeft == ';') || (*CurrLeft == '\r') || (*CurrLeft == '\n')) continue; if ((*CurrLeft == '\0') || (*CurrLeft == '[')) { CurrLeft = CurrRight = NULL; LeftLen = RightLen = 0; CurrPos = 0; return false; } CurrPos++; if (isalnum(*CurrLeft) || ispunct(*CurrLeft) // allow punct, may start style || (*CurrLeft < 0)) { // allow high-bit chars if (*CurrLeft == '\\') // backslash escapes anything CurrLeft++; bool found = false; for (short i = 0; i < count; i++) { if (match(CurrLeft, names[i])) { found = true; break; } } if (found) break; } } setRight(); return true; }
void AssistEditor::StartParamInfo(const CppItem& m, int pos) { int x = GetCursor(); ParamInfo& f = param[parami]; f.line = GetLinePos(x); f.test = GetWLine(f.line).Mid(0, x); f.item = m; f.editfile = theide->editfile; f.pos = pos; SyncParamInfo(); parami = (parami + 1) % PARAMN; }
Point DocEdit::GetCaret(int pos) { int i = GetLinePos(pos); Fmt fmt = Format(line[i]); int l; for(l = 0; l < fmt.line.GetCount(); l++) if(pos < fmt.line[l]) break; l--; const int *w = fmt.width + fmt.line[l]; pos -= fmt.line[l]; int x = 0; while(pos-- > 0) x += *w++; return Point(x, GetY(i) + l * fmt.fi.GetHeight()); }
Point LineEdit::GetColumnLine(int pos) const { Point p; if(pos > total) pos = total; p.y = GetLinePos(pos); p.x = 0; WString txt = line[p.y]; const wchar *s = txt; while(pos--) { if(*s == '\t') p.x = (p.x + tabsize) / tabsize * tabsize; else p.x += 1 + IsCJKIdeograph(*s); s++; } return p; }
char * DCirfile::SecContStr(const char *sect) { //CurrLeft = sect; CurrLeft = GetLinePos(sect); if (!CurrLeft) return NULL; //skipLine(); // skip section title const char *cstart = CurrLeft; CurrLeft = GetSectPos(sect); if (!CurrLeft) return NULL; //while ((*CurrLeft != '\0') && (*CurrLeft != '[')) // skipLine(); return NewName(cstart, (CurrLeft - cstart) - 1); }
bool LineEdit::InsertChar(dword key, int count, bool canow) { if(key == K_TAB && !processtab) return false; if(filter && key >= 32 && key < 65535) key = (*filter)(key); if(!IsReadOnly() && (key >= 32 && key < 65536 || key == '\t' || key == '\n' || key == K_ENTER && processenter || key == K_SHIFT_SPACE)) { if(key >= 128 && key < 65536 && (charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) && FromUnicode((wchar)key, charset) == DEFAULTCHAR) return true; if(!RemoveSelection() && overwrite && key != '\n' && key != K_ENTER && canow) { int q = cursor; int i = GetLinePos(q); if(q + count - 1 < GetLineLength(i)) Remove(cursor, count); } WString text(key == K_ENTER ? '\n' : key == K_SHIFT_SPACE ? ' ' : key, count); Insert(cursor, text, true); PlaceCaret(cursor + count); Action(); return true; } return false; }
void LineEdit::MoveUpDown(int n, bool sel) { int cl = cursor; int ln = GetLinePos(cl); ln = minmax(ln + n, 0, line.GetCount() - 1); PlaceCaretNoG(GetGPos(ln, gcolumn), sel); }
void LineEdit::Paint0(Draw& w) { LTIMING("LineEdit::Paint0"); int sell, selh; GetSelection(sell, selh); if(!IsEnabled()) sell = selh = 0; Rect rect; bool rectsel = IsRectSelection(); if(IsRectSelection()) rect = GetRectSelection(); Size sz = GetSize(); Size fsz = GetFontSize(); Point sc = sb; int ll = min(line.GetCount(), sz.cy / fsz.cy + sc.y + 1); int y = 0; sc.y = minmax(sc.y, 0, line.GetCount() - 1); cpos = GetPos(sc.y); cline = sc.y; sell -= cpos; selh -= cpos; int pos = cpos; int fascent = font.Info().GetAscent(); int cursorline = GetLine(cursor); Highlight ih; ih.ink = color[IsShowEnabled() ? INK_NORMAL : INK_DISABLED]; ih.paper = color[IsReadOnly() && showreadonly || !IsShowEnabled() ? PAPER_READONLY : PAPER_NORMAL]; if(nobg) ih.paper = Null; ih.font = font; ih.chr = 0; for(int i = sc.y; i < ll; i++) { Color showcolor = color[WHITESPACE]; WString tx = line[i]; bool warn_whitespace = false; if(warnwhitespace && !IsSelection()) { int pos = GetCursor(); int linei = GetLinePos(pos); if(linei != i || pos < tx.GetCount()) { int wkind = 0; bool empty = true; for(const wchar *s = tx; *s; s++) { if(*s == '\t') { if(wkind == ' ') { warn_whitespace = true; break; } wkind = '\t'; } else if(*s == ' ') wkind = ' '; else if(*s > ' ') { empty = false; wkind = 0; } } if(wkind && !empty) warn_whitespace = true; if(warn_whitespace) showcolor = color[WARN_WHITESPACE]; } } bool do_highlight = tx.GetCount() < 100000; int len = tx.GetLength(); if(w.IsPainting(0, y, sz.cx, fsz.cy)) { LTIMING("PaintLine"); Vector<Highlight> hl; int ln; if(do_highlight) { hl.SetCount(len + 1, ih); for(int q = 0; q < tx.GetCount(); q++) hl[q].chr = tx[q]; LTIMING("HighlightLine"); HighlightLine(i, hl, pos); ln = hl.GetCount() - 1; } else ln = tx.GetCount(); int lgp = -1; for(int pass = 0; pass < 2; pass++) { int gp = 0; int scx = fsz.cx * sc.x; sOptimizedRectRenderer rw(w); if(ln >= 0) { int q = 0; int x = 0; int scx2 = scx - max(2, tabsize) * fsz.cx; while(q < ln && x < scx2) { // Skip part before left border wchar chr = do_highlight ? hl[q++].chr : tx[q++]; if(chr == '\t') { gp = (gp + tabsize) / tabsize * tabsize; x = fsz.cx * gp; } else if(IsCJKIdeograph(chr)) { x += 2 * fsz.cx; gp += 2; } else { x += fsz.cx; gp++; } } sOptimizedTextRenderer tw(w); while(q < ln) { if(q == tx.GetCount()) lgp = gp; Highlight h; if(do_highlight) h = hl[q]; else { h = ih; h.chr = tx[q]; } int pos = min(q, len); // Highligting can add chars at the end of line if(rectsel ? i >= rect.top && i <= rect.bottom && gp >= rect.left && gp < rect.right : pos >= sell && pos < selh) { h.paper = color[PAPER_SELECTED]; h.ink = color[INK_SELECTED]; } int x = gp * fsz.cx - scx; if(h.chr == '\t') { int ngp = (gp + tabsize) / tabsize * tabsize; int l = ngp - gp; LLOG("Highlight -> tab[" << q << "] paper = " << h.paper); if(pass == 0 && x >= -fsz.cy * tabsize) { rw.DrawRect(x, y, fsz.cx * l, fsz.cy, h.paper); if((showtabs || warn_whitespace) && h.paper != SColorHighlight && q < tx.GetLength()) { rw.DrawRect(x + 2, y + fsz.cy / 2, l * fsz.cx - 4, 1, showcolor); rw.DrawRect(ngp * fsz.cx - scx - 3, y + 3, 1, fsz.cy - 6, showcolor); } if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + l) rw.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor); } q++; gp = ngp; } else if(h.chr == ' ') { LLOG("Highlight -> space[" << q << "] paper = " << h.paper); if(pass == 0 && x >= -fsz.cy) { rw.DrawRect(x, y, fsz.cx, fsz.cy, h.paper); if((showspaces || warn_whitespace) && h.paper != SColorHighlight && q < tx.GetLength()) { int n = fsz.cy / 10 + 1; rw.DrawRect(x + fsz.cx / 2, y + fsz.cy / 2, n, n, showcolor); } if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + 1) rw.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor); } q++; gp++; } else { bool cjk = IsCJKIdeograph(h.chr); LLOG("Highlight -> paper[" << q << "] = " << h.paper); int xx = x + (gp + 1 + cjk) * fsz.cx; if(max(x, 0) < min(xx, sz.cx) && fsz.cx >= -fsz.cy) { if(pass == 0) { rw.DrawRect(x, y, (cjk + 1) * fsz.cx, fsz.cy, h.paper); if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + 1 + cjk) rw.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor); } else tw.DrawChar(x + (h.flags & SHIFT_L ? -fsz.cx / 6 : h.flags & SHIFT_R ? fsz.cx / 6 : 0), y + fascent - h.font.GetAscent(), h.chr, (cjk + 1) * fsz.cx, h.font, h.ink); } q++; gp += 1 + cjk; if(x > sz.cx) break; } } } if(pass == 0) { int gpx = gp * fsz.cx - scx; rw.DrawRect(gpx, y, sz.cx - gpx, fsz.cy, !rectsel && sell <= len && len < selh ? color[PAPER_SELECTED] : (do_highlight ? hl.Top() : ih).paper); if(bordercolumn > 0 && bordercolumn >= gp) rw.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor); } if(pass == 0 && (showlines || warn_whitespace)) { int yy = 2 * fsz.cy / 3; int x = (lgp >= 0 ? lgp : gp) * fsz.cx - scx; rw.DrawRect(x, y + yy, fsz.cx / 2, 1, showcolor); if(fsz.cx > 2) rw.DrawRect(x + 1, y + yy - 1, 1, 3, showcolor); if(fsz.cx > 5) rw.DrawRect(x + 2, y + yy - 2, 1, 5, showcolor); rw.DrawRect(x + fsz.cx / 2, y + yy / 2, 1, yy - yy / 2, showcolor); } if(pass == 0 && !IsNull(hline) && sell == selh && i == cursorline) { rw.DrawRect(0, y, sz.cx, 1, hline); rw.DrawRect(0, y + fsz.cy - 1, sz.cx, 1, hline); } if(pass == 0 && rectsel && rect.left == rect.right && i >= rect.top && i <= rect.bottom) rw.DrawRect(rect.left * fsz.cx - scx, y, 2, fsz.cy, Blend(color[PAPER_SELECTED], color[PAPER_NORMAL])); } } y += fsz.cy; sell -= len + 1; selh -= len + 1; pos += len + 1; } w.DrawRect(0, y, sz.cx, sz.cy - y, color[IsReadOnly() && showreadonly || !IsShowEnabled() ? PAPER_READONLY : PAPER_NORMAL]); DrawTiles(w, DropCaret(), CtrlImg::checkers()); }