From efdce672123284847bd7fb6f12ac1ec96f28f3ef Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 7 Nov 2018 21:40:04 +0800 Subject: Make all header *.hpp . --- src/ui/controls/text_box.hpp | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/ui/controls/text_box.hpp (limited to 'src/ui/controls/text_box.hpp') diff --git a/src/ui/controls/text_box.hpp b/src/ui/controls/text_box.hpp new file mode 100644 index 00000000..434aa232 --- /dev/null +++ b/src/ui/controls/text_box.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include "text_control.hpp" +#include "timer.hpp" + +namespace cru::ui::controls +{ + class TextBox : public TextControl + { + public: + static constexpr auto control_type = L"TextBox"; + + static TextBox* Create( + const Microsoft::WRL::ComPtr& init_text_format = nullptr, + const Microsoft::WRL::ComPtr& init_brush = nullptr) + { + return new TextBox(init_text_format, init_brush); + } + + protected: + explicit TextBox( + const Microsoft::WRL::ComPtr& init_text_format, + const Microsoft::WRL::ComPtr& init_brush + ); + public: + TextBox(const TextBox& other) = delete; + TextBox(TextBox&& other) = delete; + TextBox& operator=(const TextBox& other) = delete; + TextBox& operator=(TextBox&& other) = delete; + ~TextBox() override; + + StringView GetControlType() const override final; + + protected: + void OnDrawContent(ID2D1DeviceContext* device_context) override; + + void OnGetFocusCore(events::FocusChangeEventArgs& args) override final; + void OnLoseFocusCore(events::FocusChangeEventArgs& args) override final; + + void OnKeyDownCore(events::KeyEventArgs& args) override final; + void OnCharCore(events::CharEventArgs& args) override final; + + void RequestChangeCaretPosition(unsigned position) override final; + + private: + // return true if left + bool GetCaretSelectionSide() const; + void ShiftLeftSelectionRange(int count); + void ShiftRightSelectionRange(int count); + + private: + unsigned caret_position_ = 0; + std::optional caret_timer_{}; + Microsoft::WRL::ComPtr caret_brush_; + bool is_caret_show_ = false; + }; +} -- cgit v1.2.3