aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/text_box.hpp
blob: e5cd75458cebfdf6ef6eb8842330fe31cbd47edc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once

// ReSharper disable once CppUnusedIncludeDirective
#include "pre.hpp"

#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()
        {
            return new TextBox();
        }

    protected:
        TextBox();
    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 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;
    };
}