From da54cf6e1dd9ffbf1e57a8a3c19e41a8fcedf5b1 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 13 Sep 2018 23:42:44 +0800 Subject: ... --- CruUI/ui/controls/text_block.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'CruUI/ui/controls/text_block.cpp') diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp index 00850b0b..3d53da7c 100644 --- a/CruUI/ui/controls/text_block.cpp +++ b/CruUI/ui/controls/text_block.cpp @@ -25,11 +25,7 @@ namespace cru } TextBlock::TextBlock(const Microsoft::WRL::ComPtr& init_text_format, - const Microsoft::WRL::ComPtr& init_brush) : Control(false), - window_deactivated_handler_(new events::UiEvent::EventHandler([this](events::UiEvent::ArgsType& args) - { - is_selecting_ = false; - })) + const Microsoft::WRL::ComPtr& init_brush) : Control(false) { text_format_ = init_text_format; if (init_brush == nullptr) @@ -63,18 +59,6 @@ namespace cru Repaint(); } - void TextBlock::OnAttachToWindow(Window* window) - { - Control::OnAttachToWindow(window); - window->deactivated_event.AddHandler(window_deactivated_handler_); - } - - void TextBlock::OnDetachToWindow(Window* window) - { - Control::OnDetachToWindow(window); - window->deactivated_event.RemoveHandler(window_deactivated_handler_); - } - void TextBlock::OnSizeChangedCore(events::SizeChangedEventArgs& args) { text_layout_->SetMaxWidth(args.GetNewSize().width); @@ -171,10 +155,18 @@ namespace cru Control::OnMouseUpCore(args); } - void TextBlock::OnLoseFocusCore(events::UiEventArgs& args) + void TextBlock::OnLoseFocusCore(events::FocusChangeEventArgs& args) { - selected_range_ = std::nullopt; - Repaint(); + if (is_selecting_) + { + is_selecting_ = false; + GetWindow()->ReleaseCurrentMouseCapture(); + } + if (!args.IsWindow()) + { + selected_range_ = std::nullopt; + Repaint(); + } Control::OnLoseFocusCore(args); } -- cgit v1.2.3