CtrlLib: RichTextView WhenLeftClick, ClearSelection

This commit is contained in:
Mirek Fidler 2022-05-16 13:43:22 +02:00
parent 143ad0aa3d
commit dc53ff972d
3 changed files with 11 additions and 4 deletions

View file

@ -14,7 +14,6 @@ public:
virtual void LeftTriple(Point p, dword keyflags);
virtual void RightDown(Point p, dword keyflags);
virtual String GetSelectionData(const String& fmt) const;
virtual void LostFocus();
private:
Rect margin;
@ -55,6 +54,7 @@ protected:
public:
Event<const String&> WhenLink;
Event<int> WhenMouseMove;
Event<> WhenLeftClick;
void Clear();
void Pick(RichText&& t);
@ -81,6 +81,7 @@ public:
int GetLength() const { return text.GetLength(); }
bool IsSelection() const { return anchor != cursor; }
void ClearSelection();
void Copy();
void ScrollUp() { sb.PrevLine(); }

View file

@ -208,10 +208,12 @@ void RichTextView::RefreshSel()
SetSelectionSource(ClipFmtsText());
}
void RichTextView::LostFocus()
void RichTextView::ClearSelection()
{
anchor = cursor;
RefreshSel();
if(IsSelection()) {
anchor = cursor;
RefreshSel();
}
}
void RichTextView::LeftDown(Point p, dword keyflags)
@ -232,6 +234,7 @@ void RichTextView::LeftDown(Point p, dword keyflags)
SetFocus();
SetCapture();
}
WhenLeftClick();
}
void RichTextView::LeftDouble(Point p, dword keyflags)

View file

@ -5,6 +5,9 @@ RichTextCtrlSelection::RichTextCtrlSelection()
CtrlLayout(*this, "Window title");
a <<= "This is some text";
b <<= "This is another text";
a.WhenLeftClick = [=] { b.ClearSelection(); };
b.WhenLeftClick = [=] { a.ClearSelection(); };
}
GUI_APP_MAIN