aboutsummaryrefslogtreecommitdiff
path: root/src/osx/gui/InputMethodPrivate.h
blob: a4b614320b3a143bd0369e11148b159f9a9b5658 (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
#pragma once
#include "cru/osx/gui/InputMethod.hpp"

#import <AppKit/AppKit.h>

@interface CruInputClient : NSObject <NSTextInputClient>
- (id)init:(cru::platform::gui::osx::details::OsxInputMethodContextPrivate*)p;
@end

namespace cru::platform::gui::osx {
namespace details {
class OsxInputMethodContextPrivate {
  friend OsxInputMethodContext;

 public:
  OsxInputMethodContextPrivate(OsxInputMethodContext* input_method_context, OsxWindow* window);

  CRU_DELETE_COPY(OsxInputMethodContextPrivate)
  CRU_DELETE_MOVE(OsxInputMethodContextPrivate)

  ~OsxInputMethodContextPrivate();

  void SetCompositionText(CompositionText composition_text) {
    composition_text_ = std::move(composition_text);
  }

  void RaiseCompositionStartEvent();
  void RaiseCompositionEndEvent();
  void RaiseCompositionEvent();
  void RaiseTextEvent(StringView text);

  Point GetCandidateWindowPosition() const { return candidate_window_point_; }
  void SetCandidateWindowPosition(const Point& p) { candidate_window_point_ = p; }

  Range GetSelectionRange() const { return selection_range_; }
  void SetSelectionRange(Range selection_range) { selection_range_ = selection_range; }

  void PerformSel(SEL sel);

 private:
  OsxWindow* window_;

  CompositionText composition_text_;

  Range selection_range_;

  OsxInputMethodContext* input_method_context_;

  // On Osx, this is the text lefttop point on screen.
  Point candidate_window_point_;

  Event<std::nullptr_t> composition_start_event_;
  Event<std::nullptr_t> composition_event_;
  Event<std::nullptr_t> composition_end_event_;
  Event<StringView> text_event_;
};

}
}