aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/text_control.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-25 17:42:57 +0800
committercrupest <crupest@outlook.com>2018-09-25 17:42:57 +0800
commitda768af31952a28aa7aca8f60acd85bf2832465c (patch)
tree27317ae0d9ac5b1409408ef165595f9c127aa027 /src/ui/controls/text_control.cpp
parentccbc293c0158d4450c0db344474193f17925403f (diff)
downloadcru-da768af31952a28aa7aca8f60acd85bf2832465c.tar.gz
cru-da768af31952a28aa7aca8f60acd85bf2832465c.tar.bz2
cru-da768af31952a28aa7aca8f60acd85bf2832465c.zip
Make TextBox inherates TextControl. Add slection-related features to it.
Diffstat (limited to 'src/ui/controls/text_control.cpp')
-rw-r--r--src/ui/controls/text_control.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp
index 3a466592..845b090a 100644
--- a/src/ui/controls/text_control.cpp
+++ b/src/ui/controls/text_control.cpp
@@ -66,7 +66,11 @@ namespace cru::ui::controls
{
if (!is_selectable)
{
- is_selecting_ = false;
+ if (is_selecting_)
+ {
+ is_selecting_ = false;
+ GetWindow()->ReleaseCurrentMouseCapture();
+ }
selected_range_ = std::nullopt;
Repaint();
}
@@ -133,8 +137,6 @@ namespace cru::ui::controls
device_context->DrawTextLayout(D2D1::Point2F(), text_layout_.Get(), brush_.Get());
}
-
-
void TextControl::OnMouseDownCore(events::MouseButtonEventArgs& args)
{
Control::OnMouseDownCore(args);
@@ -144,6 +146,7 @@ namespace cru::ui::controls
const auto hit_test_result = TextLayoutHitTest(text_layout_.Get(), args.GetPoint(this), true);
if (hit_test_result.has_value())
{
+ RequestChangeCaretPosition(hit_test_result.value());
mouse_down_position_ = hit_test_result.value();
is_selecting_ = true;
GetWindow()->CaptureMouseFor(this);
@@ -158,12 +161,19 @@ namespace cru::ui::controls
if (is_selecting_)
{
const auto hit_test_result = TextLayoutHitTest(text_layout_.Get(), args.GetPoint(this), false).value();
+ RequestChangeCaretPosition(hit_test_result);
if (hit_test_result > mouse_down_position_)
+ {
selected_range_ = TextRange(mouse_down_position_, hit_test_result - mouse_down_position_);
+ }
else if (hit_test_result < mouse_down_position_)
+ {
selected_range_ = TextRange(hit_test_result, mouse_down_position_ - hit_test_result);
+ }
else
+ {
selected_range_ = std::nullopt;
+ }
Repaint();
}
}
@@ -249,6 +259,10 @@ namespace cru::ui::controls
return result_size;
}
+ void TextControl::RequestChangeCaretPosition(unsigned position)
+ {
+
+ }
void TextControl::OnTextChangedCore(const String& old_text, const String& new_text)
{