Flutter Windows Embedder
flutter::TextInputManager Class Reference

#include <text_input_manager.h>

Public Member Functions

 TextInputManager () noexcept=default
 
virtual ~TextInputManager ()=default
 
void SetWindowHandle (HWND window_handle)
 
void CreateImeWindow ()
 
void DestroyImeWindow ()
 
void UpdateImeWindow ()
 
void UpdateCaretRect (const Rect &rect)
 
virtual long GetComposingCursorPosition () const
 
virtual std::optional< std::u16string > GetComposingString () const
 
virtual std::optional< std::u16string > GetResultString () const
 
void AbortComposing ()
 

Detailed Description

Definition at line 29 of file text_input_manager.h.

Constructor & Destructor Documentation

◆ TextInputManager()

flutter::TextInputManager::TextInputManager ( )
defaultnoexcept

◆ ~TextInputManager()

virtual flutter::TextInputManager::~TextInputManager ( )
virtualdefault

Member Function Documentation

◆ AbortComposing()

void flutter::TextInputManager::AbortComposing ( )

Aborts IME composing.

Aborts composing, closes the candidates window, and clears the contents of the composing string.

Definition at line 126 of file text_input_manager.cc.

126  {
127  if (window_handle_ == nullptr || !ime_active_) {
128  return;
129  }
130 
131  ImmContext imm_context(window_handle_);
132  if (imm_context.IsValid()) {
133  // Cancel composing and close the candidates window.
134  ::ImmNotifyIME(imm_context.get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0);
135  ::ImmNotifyIME(imm_context.get(), NI_CLOSECANDIDATE, 0, 0);
136 
137  // Clear the composing string.
138  wchar_t composition_str[] = L"";
139  wchar_t reading_str[] = L"";
140  ::ImmSetCompositionStringW(imm_context.get(), SCS_SETSTR, composition_str,
141  sizeof(wchar_t), reading_str, sizeof(wchar_t));
142  }
143 }

References flutter::ImmContext::get(), and flutter::ImmContext::IsValid().

◆ CreateImeWindow()

void flutter::TextInputManager::CreateImeWindow ( )

Definition at line 51 of file text_input_manager.cc.

51  {
52  if (window_handle_ == nullptr) {
53  return;
54  }
55 
56  // Some IMEs ignore calls to ::ImmSetCandidateWindow() and use the position of
57  // the current system caret instead via ::GetCaretPos(). In order to behave
58  // as expected with these IMEs, we create a temporary system caret.
59  if (!ime_active_) {
60  ::CreateCaret(window_handle_, nullptr, 1, 1);
61  }
62  ime_active_ = true;
63 
64  // Set the position of the IME windows.
66 }

References UpdateImeWindow().

◆ DestroyImeWindow()

void flutter::TextInputManager::DestroyImeWindow ( )

Definition at line 68 of file text_input_manager.cc.

68  {
69  if (window_handle_ == nullptr) {
70  return;
71  }
72 
73  // Destroy the system caret created in CreateImeWindow().
74  if (ime_active_) {
75  ::DestroyCaret();
76  }
77  ime_active_ = false;
78 }

◆ GetComposingCursorPosition()

long flutter::TextInputManager::GetComposingCursorPosition ( ) const
virtual

Definition at line 104 of file text_input_manager.cc.

104  {
105  if (window_handle_ == nullptr) {
106  return false;
107  }
108 
109  ImmContext imm_context(window_handle_);
110  if (imm_context.IsValid()) {
111  // Read the cursor position within the composing string.
112  return ImmGetCompositionString(imm_context.get(), GCS_CURSORPOS, nullptr,
113  0);
114  }
115  return -1;
116 }

References flutter::ImmContext::get(), and flutter::ImmContext::IsValid().

◆ GetComposingString()

std::optional< std::u16string > flutter::TextInputManager::GetComposingString ( ) const
virtual

Definition at line 118 of file text_input_manager.cc.

118  {
119  return GetString(GCS_COMPSTR);
120 }

◆ GetResultString()

std::optional< std::u16string > flutter::TextInputManager::GetResultString ( ) const
virtual

Definition at line 122 of file text_input_manager.cc.

122  {
123  return GetString(GCS_RESULTSTR);
124 }

◆ SetWindowHandle()

void flutter::TextInputManager::SetWindowHandle ( HWND  window_handle)

Definition at line 47 of file text_input_manager.cc.

47  {
48  window_handle_ = window_handle;
49 }

◆ UpdateCaretRect()

void flutter::TextInputManager::UpdateCaretRect ( const Rect rect)

Definition at line 91 of file text_input_manager.cc.

91  {
92  caret_rect_ = rect;
93 
94  if (window_handle_ == nullptr) {
95  return;
96  }
97 
98  ImmContext imm_context(window_handle_);
99  if (imm_context.IsValid()) {
100  MoveImeWindow(imm_context.get());
101  }
102 }

References flutter::ImmContext::get(), and flutter::ImmContext::IsValid().

◆ UpdateImeWindow()

void flutter::TextInputManager::UpdateImeWindow ( )

Definition at line 80 of file text_input_manager.cc.

80  {
81  if (window_handle_ == nullptr) {
82  return;
83  }
84 
85  ImmContext imm_context(window_handle_);
86  if (imm_context.IsValid()) {
87  MoveImeWindow(imm_context.get());
88  }
89 }

References flutter::ImmContext::get(), and flutter::ImmContext::IsValid().

Referenced by CreateImeWindow().


The documentation for this class was generated from the following files:
flutter::TextInputManager::UpdateImeWindow
void UpdateImeWindow()
Definition: text_input_manager.cc:80