aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/controls
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-13 23:42:44 +0800
committercrupest <crupest@outlook.com>2018-09-13 23:42:44 +0800
commitda54cf6e1dd9ffbf1e57a8a3c19e41a8fcedf5b1 (patch)
tree59ab635a09bfb4fc219b243c920cd236dfa41010 /CruUI/ui/controls
parent42f9f6c0bce5b3bea05edf4e371539fe21ea1c5d (diff)
downloadcru-da54cf6e1dd9ffbf1e57a8a3c19e41a8fcedf5b1.tar.gz
cru-da54cf6e1dd9ffbf1e57a8a3c19e41a8fcedf5b1.tar.bz2
cru-da54cf6e1dd9ffbf1e57a8a3c19e41a8fcedf5b1.zip
...
Diffstat (limited to 'CruUI/ui/controls')
-rw-r--r--CruUI/ui/controls/text_block.cpp32
-rw-r--r--CruUI/ui/controls/text_block.h8
2 files changed, 13 insertions, 27 deletions
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<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : Control(false),
- window_deactivated_handler_(new events::UiEvent::EventHandler([this](events::UiEvent::ArgsType& args)
- {
- is_selecting_ = false;
- }))
+ const Microsoft::WRL::ComPtr<ID2D1Brush>& 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);
}
diff --git a/CruUI/ui/controls/text_block.h b/CruUI/ui/controls/text_block.h
index 689607ac..beb662b9 100644
--- a/CruUI/ui/controls/text_block.h
+++ b/CruUI/ui/controls/text_block.h
@@ -97,9 +97,6 @@ namespace cru
}
protected:
- void OnAttachToWindow(Window* window) override;
- void OnDetachToWindow(Window* window) override;
-
void OnSizeChangedCore(events::SizeChangedEventArgs& args) override final;
void OnDraw(ID2D1DeviceContext* device_context) override;
@@ -107,7 +104,7 @@ namespace cru
void OnMouseMoveCore(events::MouseEventArgs& args) override;
void OnMouseUpCore(events::MouseButtonEventArgs& args) override;
- void OnLoseFocusCore(events::UiEventArgs& args) override;
+ void OnLoseFocusCore(events::FocusChangeEventArgs& args) override;
Size OnMeasure(const Size& available_size) override;
@@ -131,9 +128,6 @@ namespace cru
bool is_selecting_ = false;
unsigned mouse_down_position_ = 0;
std::optional<TextRange> selected_range_ = std::nullopt;
-
-
- events::UiEvent::EventHandlerPtr window_deactivated_handler_;
};
}
}