Blender V5.3
GHOST_ImeWin32.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2010 The Chromium Authors. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#ifdef WITH_INPUT_IME
12
13# include <windows.h>
14
15# include <string>
16
17# include "GHOST_Event.hh"
18# include "GHOST_Rect.hh"
19# include <vector>
20
21/* MSDN LOCALE_SISO639LANGNAME states maximum length of 9, including terminating null. */
22# define W32_ISO639_LEN 9
23
24class GHOST_EventIME : public GHOST_Event {
25 public:
32 GHOST_EventIME(uint64_t msec,
34 GHOST_IWindow *window,
35 const void *customdata)
36 : GHOST_Event(msec, type, window)
37 {
38 this->data_ = customdata;
39 }
40};
41
82
83/* This struct represents the status of an ongoing composition. */
84struct ImeComposition {
85 /* Represents the cursor position in the IME composition. */
86 int cursor_position;
87
88 /* Represents the position of the beginning of the selection */
89 int target_start;
90
91 /* Represents the position of the end of the selection */
92 int target_end;
93
102 int string_type;
103
104 /* Represents the string retrieved from IME (Input Method Editor) */
105 std::wstring ime_string;
106 std::vector<char> utf8_buf;
107 std::vector<unsigned char> format;
108};
109
126class GHOST_ImeWin32 {
127 public:
128 GHOST_ImeWin32();
129 ~GHOST_ImeWin32();
130
131 /* Retrieves whether or not there is an ongoing composition. */
132 bool is_composing() const
133 {
134 return is_composing_;
135 }
136
137 /* Retrieve the input language from Windows and store it. */
138 void UpdateInputLanguage();
139
140 BOOL IsLanguage(const char name[W32_ISO639_LEN]);
141
142 /* Saves the current conversion status. */
143 void UpdateConversionStatus(HWND window_handle);
144
145 /* Is the IME currently in conversion mode? */
146 bool IsEnglishMode();
147
148 /* Checks a key whether IME has to do handling. */
149 bool IsImeKeyEvent(char ascii, GHOST_TKey key);
150
157 void CreateImeWindow(HWND window_handle);
158
179 void SetImeWindowStyle(
180 HWND window_handle, UINT message, WPARAM wparam, LPARAM lparam, BOOL *handled);
181
188 void DestroyImeWindow(HWND window_handle);
189
196 void UpdateImeWindow(HWND window_handle);
197
205 void CleanupComposition(HWND window_handle);
206
215 void ResetComposition(HWND window_handle);
216
238 bool GetResult(HWND window_handle, LPARAM lparam, ImeComposition *composition);
239
261 bool GetComposition(HWND window_handle, LPARAM lparam, ImeComposition *composition);
262
285 void BeginIME(HWND window_handle, const GHOST_Rect &caret_rect, bool complete);
286
296 void EndIME(HWND window_handle);
297
299 void UpdateInfo(HWND window_handle);
300
302 void CheckFirst(HWND window_handle);
303
304 ImeComposition resultInfo, compInfo;
305 GHOST_TEventImeData eventImeData;
306
307 protected:
308 /* Determines whether or not the given attribute represents a target (a.k.a. a selection). */
309 bool IsTargetAttribute(char attribute) const
310 {
311 return (attribute == ATTR_TARGET_CONVERTED || attribute == ATTR_TARGET_NOTCONVERTED);
312 }
313
314 /* Retrieve the target area. */
315 void GetCaret(HIMC imm_context, LPARAM lparam, ImeComposition *composition);
316
317 /* Update the position of the IME windows. */
318 void MoveImeWindow(HWND window_handle, HIMC imm_context);
319
320 /* Complete the ongoing composition if it exists. */
321 void CompleteComposition(HWND window_handle, HIMC imm_context);
322
323 /* Retrieve a string from the IMM. */
324 bool GetString(HIMC imm_context, WPARAM lparam, int type, ImeComposition *composition);
325
326 private:
331 bool is_composing_;
332
333 /* Abbreviated ISO 639-1 name of the input language, such as "en" for English. */
334 char language_[W32_ISO639_LEN];
335
336 /* Current Conversion Mode Values. Retrieved with ImmGetConversionStatus. */
337 DWORD conversion_modes_;
338
339 /* Current Sentence Mode. Retrieved with ImmGetConversionStatus. */
340 DWORD sentence_mode_;
341
348 bool system_caret_;
349
350 /* The rectangle of the input caret retrieved from a renderer process. */
351 GHOST_Rect caret_rect_;
352
353 /* used for disable ime when start up */
354 bool is_first, is_enable;
355};
356
357#endif /* WITH_INPUT_IME */
GHOST_TEventType
GHOST_TKey
unsigned long long int uint64_t
#define attribute(slot)
std::string format(const std::string &fmt, Args &&...args)
Definition diagnostic.hh:43