#ifndef _TextDiffCtrl_TextDiffCtrl_h #define _TextDiffCtrl_TextDiffCtrl_h #include namespace Upp { #define IMAGECLASS DiffImg #define IMAGEFILE #include class TextSection { public: TextSection(int start1, int count1, int start2, int count2, bool same) : start1(start1), count1(count1), start2(start2), count2(count2), same(same) {} public: int start1; int count1; int start2; int count2 : 31; unsigned same : 1; }; Array CompareLineMaps(const Vector& l1, const Vector& l2); Vector GetLineMap(Stream& stream); Vector GetFileLineMap(const String& path); Vector GetStringLineMap(const String &s); class TextCompareCtrl : public Ctrl { public: virtual void Paint(Draw& draw); virtual void Layout(); virtual void MouseWheel(Point pt, int zdelta, dword keyflags); virtual void MouseMove(Point pt, dword keyflags); virtual void LeftDown(Point pt, dword keyflags); virtual void LeftDouble(Point pt, dword keyflags); virtual void LeftUp(Point pt, dword keyflags); virtual void LeftRepeat(Point pt, dword keyflags); virtual void RightDown(Point p, dword keyflags); virtual bool Key(dword key, int repcnt); virtual void LostFocus(); private: void SelfScroll(); void PairScroll(TextCompareCtrl *ctrl); void UpdateWidth(); WString ExpandTabs(const wchar *line) const; int MeasureLength(const wchar *line) const; bool GetSelection(int& l, int& h) const; void DoSelection(int y, bool shift); void Copy(); int GetLineNo(int y, int& yy); int GetMatchLen(const wchar *s1, const wchar *s2, int len); bool LineDiff(bool left, Vector& hln, Color eq_color, const wchar *s1, int l1, int h1, const wchar *s2, int l2, int h2, int depth); private: struct Line { Line() : number(Null), level(0) {} int number; bool diff; String text; int level; String text_diff; int number_diff; }; Array lines; int maxwidth; ScrollBars scroll; Font font; Font number_font; Color number_bg; Color gutter_fg; Color gutter_bg; Size letter; int tabsize; int number_width; int number_yshift; int gutter_width; int cursor; int anchor; bool gutter_capture; bool show_line_number; bool show_white_space; bool show_diff_highlight; bool change_paper_color; bool left = false; typedef TextCompareCtrl CLASSNAME; friend struct TextDiffCtrl; public: Event<> WhenSel; Event<> WhenScroll; Callback2 WhenLeftDouble; Event&, const WString&> WhenHighlight; void SetCount(int c); void AddCount(int c); int GetCount() const { return lines.GetCount(); } void SetFont(Font f, Font nf); void SetFont(Font f); Font GetFont() const { return font; } Font GetNumberFont() const { return number_font; } void NumberBgColor(Color bg) { number_bg = bg; Refresh(); } Color GetNumberBgColor() const { return number_bg; } void AutoHideSb(bool ssb=true){ scroll.AutoHide(ssb); } void ShowSb(bool ssb) { scroll.ShowY(ssb); } void HideSb() { ShowSb(false); } void Gutter(int size) { gutter_width = size; Refresh(); } void NoGutter() { gutter_width = 0; Refresh(); } void TabSize(int t); int GetTabSize() const { return tabsize; } void Set(int line, String text, bool diff, int number, int level, String text_diff, int number_diff); String GetText(int line) const { return lines[line].text; } bool GetDiff(int line) const { return lines[line].diff; } int GetNumber(int line) const { return lines[line].number; } int GetNumberDiff(int line) const { return lines[line].number_diff; } bool HasLine(int line) const { return !IsNull(lines[line].number); } Point GetPos() const; void SetPos(Point pos); int GetSb() const { return scroll.Get().y; } void SetSb(int y) { scroll.Set(0, y); } void ClearSelection() { cursor = Null; Refresh(); WhenSel(); } void SetSelection(int l, int h) { cursor = l; anchor = h; Refresh(); WhenSel(); } bool IsSelection() const { return cursor >= 0; } bool IsSelected(int i) const; void ShowLineNumber(bool sln) { show_line_number = sln; Refresh(); } void HideLineNumber() { ShowLineNumber(false); } void ShowWhiteSpace(bool sws) { show_white_space = sws; Refresh(); } void HideWhiteSpace() { ShowWhiteSpace(false); } void DiffHighlight(bool dh) { show_diff_highlight = dh; Refresh(); } void NoDiffHighlight() { DiffHighlight(false); } void ChangePaperColor(bool cpc) { change_paper_color = cpc; Refresh(); } void NoChangePaperColor() { ChangePaperColor(false); } void SetLeft() { left = true; } String RemoveSelected(bool cr); Event<> ScrollWhen(TextCompareCtrl& pair) { return THISBACK1(PairScroll, &pair); } TextCompareCtrl(); }; struct TextDiffCtrl : public Splitter { TextCompareCtrl left; TextCompareCtrl right; FrameTop