bool LineEdit::GetRectSelection(const Rect& rect, int line, int& l, int &h) { if(line >= rect.top && line <= rect.bottom) { l = GetGPos(line, rect.left); h = GetGPos(line, rect.right); return true; } return false; }
void LineEdit::AlignChar() { int c = GetCursor(); if(c == 0) return; Point pos = GetColumnLine(c); if(pos.x == 0) return; for(int d = 1; d <= pos.y && d < 100; d++) { int lny = pos.y - d; WString above = GetWLine(lny); int offset = GetGPos(lny, pos.x) - GetPos(lny); int end = offset; char ch = GetChar(c - 1); if(ch == ' ') { offset++; while(end < above.GetLength() && above[end] != ' ') end++; while(end < above.GetLength() && above[end] == ' ') end++; } else while(end < above.GetLength() && above[end] != ch) end++; if(end < above.GetLength()) { int count = end - offset + 1; WString s(' ', count); Insert(c - 1, s, true); SetCursor(c + count); return; } } }
void LineEdit::PasteColumn(const WString& text) { Vector<WString> cl = Split(text, '\n', false); if(cl.GetCount() && cl.Top().IsEmpty()) cl.Drop(); if(cl.GetCount() == 0) return; int pos; if(IsRectSelection()) { Rect t = GetRectSelection(); RemoveSelection(); Point p = t.TopLeft(); pos = cursor; for(int i = 0; i < t.bottom - t.top + 1; i++) { CacheLinePos(i + p.y); int l = GetGPos(i + p.y, p.x); pos = l + Insert(l, cl[i % cl.GetCount()]); } } else { RemoveSelection(); Point p = GetColumnLine(cursor); pos = cursor; for(int i = 0; i < cl.GetCount(); i++) { CacheLinePos(i + p.y); int li = p.y + i; if(li < line.GetCount()) { int l = GetGPos(i + p.y, p.x); pos = l + Insert(l, cl[i]); } else { Insert(GetLength(), cl[i] + "\n"); pos = GetLength(); } } } PlaceCaret(pos); }
int LineEdit::RemoveRectSelection() { Rect rect = GetRectSelection(); WString txt; for(int i = rect.top; i <= rect.bottom; i++) { int l, h; CacheLinePos(i); GetRectSelection(rect, i, l, h); WString s = GetWLine(i); s.Remove(l - GetPos(i), h - l); txt.Cat(s); txt.Cat('\n'); } int l = GetPos(rect.top); int h = GetPos(rect.bottom) + GetLineLength(rect.bottom); if(h < GetLength()) h++; Remove(l, h - l); Insert(l, txt); return GetGPos(rect.bottom, rect.left); }
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); }
int LineEdit::GetMousePos(Point p) const { Size fsz = GetFontSize(); p = (p + fsz.cx / 2 + fsz * (Size)sb.Get()) / fsz; return GetGPos(p.y, p.x); }
void LineEdit::SetRectSelection(const Rect& rect) { SetRectSelection(GetGPos(rect.top, rect.left), GetGPos(rect.bottom, rect.right)); }