blob: 27a621be4510174f27ed0ca73cd6a72ed242144c (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 | // Some useful information can be found from chromium code:
// https://chromium.googlesource.com/chromium/chromium/+/refs/heads/master/ui/base/win/ime_input.h
// https://chromium.googlesource.com/chromium/chromium/+/refs/heads/master/ui/base/win/ime_input.cc
#pragma once
#include "Resource.h"
#include "WindowNativeMessageEventArgs.h"
#include "cru/platform/gui/InputMethod.h"
#include <imm.h>
namespace cru::platform::gui::win {
class CRU_WIN_GUI_API AutoHIMC : public Object {
  CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::gui::win::AutoHIMC")
 public:
  explicit AutoHIMC(HWND hwnd);
  CRU_DELETE_COPY(AutoHIMC)
  AutoHIMC(AutoHIMC&& other);
  AutoHIMC& operator=(AutoHIMC&& other);
  ~AutoHIMC() override;
  HWND GetHwnd() const { return hwnd_; }
  HIMC Get() const { return handle_; }
 private:
  HWND hwnd_;
  HIMC handle_;
};
class CRU_WIN_GUI_API WinInputMethodContext
    : public WinNativeResource,
      public virtual IInputMethodContext {
  CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::gui::win::WinInputMethodContext")
 public:
  WinInputMethodContext(gsl::not_null<WinNativeWindow*> window);
  CRU_DELETE_COPY(WinInputMethodContext)
  CRU_DELETE_MOVE(WinInputMethodContext)
  ~WinInputMethodContext() override;
  bool ShouldManuallyDrawCompositionText() override { return true; }
  void EnableIME() override;
  void DisableIME() override;
  void CompleteComposition() override;
  void CancelComposition() override;
  CompositionText GetCompositionText() override;
  void SetCandidateWindowPosition(const Point& point) override;
  IEvent<std::nullptr_t>* CompositionStartEvent() override;
  IEvent<std::nullptr_t>* CompositionEndEvent() override;
  IEvent<std::nullptr_t>* CompositionEvent() override;
  IEvent<StringView>* TextEvent() override;
 private:
  void OnWindowNativeMessage(WindowNativeMessageEventArgs& args);
  String GetResultString();
  AutoHIMC GetHIMC();
 private:
  WinNativeWindow* native_window_;
  EventRevokerListGuard event_guard_;
  Event<std::nullptr_t> composition_start_event_;
  Event<std::nullptr_t> composition_end_event_;
  Event<std::nullptr_t> composition_event_;
  Event<StringView> text_event_;
};
}  // namespace cru::platform::gui::win
 |