aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CruUI/ui/controls/text_block.cpp22
-rw-r--r--CruUI/ui/controls/text_block.h9
-rw-r--r--CruUI/ui/window.cpp19
-rw-r--r--CruUI/ui/window.h8
4 files changed, 55 insertions, 3 deletions
diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp
index 132bd3e7..04166f32 100644
--- a/CruUI/ui/controls/text_block.cpp
+++ b/CruUI/ui/controls/text_block.cpp
@@ -25,7 +25,14 @@ namespace cru
}
TextBlock::TextBlock(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : Control(false)
+ const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : Control(false),
+ window_deactivated_handler_(new events::UiEvent::EventHandler([this](events::UiEvent::ArgsType& args)
+ {
+ if (is_selecting_)
+ {
+ is_selecting_ = false;
+ }
+ }))
{
text_format_ = init_text_format;
if (init_brush == nullptr)
@@ -59,6 +66,19 @@ namespace cru
Repaint();
}
+ void TextBlock::OnAttachToWindow(Window* window)
+ {
+ window->deactivated_event.AddHandler([](auto args)
+ {
+
+ });
+ }
+
+ void TextBlock::OnDetachToWindow(Window* window)
+ {
+
+ }
+
void TextBlock::OnSizeChangedCore(events::SizeChangedEventArgs& args)
{
text_layout_->SetMaxWidth(args.GetNewSize().width);
diff --git a/CruUI/ui/controls/text_block.h b/CruUI/ui/controls/text_block.h
index c817104e..4c1f1fb1 100644
--- a/CruUI/ui/controls/text_block.h
+++ b/CruUI/ui/controls/text_block.h
@@ -27,9 +27,9 @@ namespace cru
unsigned position;
unsigned count;
- operator DWRITE_TEXT_RANGE() const
+ explicit operator DWRITE_TEXT_RANGE() const
{
- DWRITE_TEXT_RANGE result;
+ DWRITE_TEXT_RANGE result{};
result.startPosition = position;
result.length = count;
return result;
@@ -97,6 +97,9 @@ 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;
@@ -130,6 +133,8 @@ namespace cru
std::optional<TextRange> selected_range_ = std::nullopt;
bool is_selecting_ = false;
+
+ events::UiEvent::EventHandlerPtr window_deactivated_handler_;
};
}
}
diff --git a/CruUI/ui/window.cpp b/CruUI/ui/window.cpp
index 8430d09b..fe37fc46 100644
--- a/CruUI/ui/window.cpp
+++ b/CruUI/ui/window.cpp
@@ -337,6 +337,13 @@ namespace cru
OnResizeInternal(LOWORD(l_param), HIWORD(l_param));
result = 0;
return true;
+ case WM_ACTIVATE:
+ if (w_param == WA_ACTIVE || w_param == WA_CLICKACTIVE)
+ OnActivatedInternal();
+ else if (w_param == WA_INACTIVE)
+ OnDeactivatedInternal();
+ result = 0;
+ return true;
case WM_DESTROY:
OnDestroyInternal();
result = 0;
@@ -577,6 +584,18 @@ namespace cru
DispatchEvent(control, &Control::OnMouseUpCore, nullptr, dip_point, button);
}
+ void Window::OnActivatedInternal()
+ {
+ events::UiEventArgs args(this, this);
+ activated_event.Raise(args);
+ }
+
+ void Window::OnDeactivatedInternal()
+ {
+ events::UiEventArgs args(this, this);
+ deactivated_event.Raise(args);
+ }
+
void Window::DispatchMouseHoverControlChangeEvent(Control* old_control, Control* new_control, const Point& point)
{
if (new_control != old_control) //if the mouse-hover-on control changed
diff --git a/CruUI/ui/window.h b/CruUI/ui/window.h
index 551e2048..92b084e1 100644
--- a/CruUI/ui/window.h
+++ b/CruUI/ui/window.h
@@ -213,6 +213,11 @@ namespace cru {
Control* CaptureMouseFor(Control* control);
Control* ReleaseCurrentMouseCapture();
+ public:
+ //*************** region: events ***************
+ events::UiEvent activated_event;
+ events::UiEvent deactivated_event;
+
private:
//*************** region: native operations ***************
@@ -236,6 +241,9 @@ namespace cru {
void OnMouseDownInternal(MouseButton button, POINT point);
void OnMouseUpInternal(MouseButton button, POINT point);
+ void OnActivatedInternal();
+ void OnDeactivatedInternal();
+
//*************** region: event dispatcher helper ***************
template<typename EventArgs>