aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/text_box.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/controls/text_box.hpp')
-rw-r--r--src/ui/controls/text_box.hpp57
1 files changed, 57 insertions, 0 deletions
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<IDWriteTextFormat>& init_text_format = nullptr,
+ const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush = nullptr)
+ {
+ return new TextBox(init_text_format, init_brush);
+ }
+
+ protected:
+ explicit TextBox(
+ const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
+ const Microsoft::WRL::ComPtr<ID2D1Brush>& 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<TimerTask> caret_timer_{};
+ Microsoft::WRL::ComPtr<ID2D1Brush> caret_brush_;
+ bool is_caret_show_ = false;
+ };
+}