diff options
author | crupest <crupest@outlook.com> | 2019-04-04 17:12:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-04 17:12:25 +0800 |
commit | a410e2048db6f5ef6fb50e401a59b4b98b979050 (patch) | |
tree | 500680c63b074e8c3eefd756fd6a1d0f41840c1a /include/cru/ui/window.hpp | |
parent | fcaf471275a67d718887430ee63a53890915c4c7 (diff) | |
download | cru-a410e2048db6f5ef6fb50e401a59b4b98b979050.tar.gz cru-a410e2048db6f5ef6fb50e401a59b4b98b979050.tar.bz2 cru-a410e2048db6f5ef6fb50e401a59b4b98b979050.zip |
...
Diffstat (limited to 'include/cru/ui/window.hpp')
-rw-r--r-- | include/cru/ui/window.hpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp new file mode 100644 index 00000000..043aae35 --- /dev/null +++ b/include/cru/ui/window.hpp @@ -0,0 +1,97 @@ +#pragma once +#include "content_control.hpp" + +#include "event/ui_event.hpp" + +#include <memory> + +namespace cru::platform { +struct NativeWindow; +} + +namespace cru::ui { +namespace render { +class WindowRenderObject; +} + +class Window final : public ContentControl { + public: + static constexpr auto control_type = L"Window"; + + public: + static Window* CreateOverlapped(); + + private: + struct tag_overlapped_constructor {}; + + explicit Window(tag_overlapped_constructor); + + public: + Window(const Window& other) = delete; + Window(Window&& other) = delete; + Window& operator=(const Window& other) = delete; + Window& operator=(Window&& other) = delete; + ~Window() override; + + public: + std::wstring_view GetControlType() const override final; + + render::RenderObject* GetRenderObject() const override; + + platform::NativeWindow* GetNativeWindow() const; + + Control* GetMouseHoverControl() const { return mouse_hover_control_; } + + //*************** region: focus *************** + + // Request focus for specified control. + bool RequestFocusFor(Control* control); + + // Get the control that has focus. + Control* GetFocusControl(); + + protected: + void OnChildChanged(Control* old_child, Control* new_child) override; + + private: + Control* HitTest(const Point& point); + + //*************** region: native messages *************** + + void OnNativeDestroy(); + void OnNativePaint(); + void OnNativeResize(float new_width, float new_height); + + void OnSetFocusInternal(); + void OnKillFocusInternal(); + + void OnMouseMoveInternal(POINT point); + void OnMouseLeaveInternal(); + void OnMouseDownInternal(MouseButton button, POINT point); + void OnMouseUpInternal(MouseButton button, POINT point); + + void OnMouseWheelInternal(short delta, POINT point); + void OnKeyDownInternal(int virtual_code); + void OnKeyUpInternal(int virtual_code); + void OnCharInternal(wchar_t c); + + void OnActivatedInternal(); + void OnDeactivatedInternal(); + + //*************** region: event dispatcher helper *************** + + void DispatchMouseHoverControlChangeEvent(Control* old_control, + Control* new_control, + const Point& point); + + private: + platform::NativeWindow* native_window_; + std::vector<EventHandlerToken> revoke_tokens_; + + std::shared_ptr<render::WindowRenderObject> render_object_; + + Control* mouse_hover_control_ = nullptr; + + Control* focus_control_ = this; // "focus_control_" can't be nullptr +}; +} // namespace cru::ui |