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