My Project
GUIIME.h
1 #pragma once
2 #if defined(USE_DIRECTX_RENDERER) || 0
3 #include "util/mutex.h"
4 #include "GrowableArray.h"
5 #include "GUIUniBuffer.h"
6 
7 namespace ParaEngine
8 {
9  enum IMESTATE
10  {
11  IMEUI_STATE_OFF,
12  IMEUI_STATE_ON,
13  IMEUI_STATE_ENGLISH,
14  };
15 
16  enum IMELanguage
17  {
18  IMELanguage_Unknown,
19  IMELanguage_English,
20  IMELanguage_ChineseSimplified,
21  IMELanguage_ChineseTraditional,
22  IMELanguage_Korean,
23  IMELanguage_Japanese,
24  };
25 
28  class IIMESystem
29  {
30  public:
32  virtual bool GetShowImeReadingWindow() = 0;
34  virtual bool GetShowImeCandidateWindow() = 0;
36  virtual bool GetIsVerticalImeCandidate() = 0;
38  virtual bool GetIsHorizontalImeReading() = 0;
39 
41  virtual void SetImeState(IMESTATE aState) = 0;
43  virtual IMESTATE GetImeState() = 0;
45  virtual IMELanguage GetImeLanguage() = 0;
47  virtual const char16_t* GetImeIndicator() = 0;
49  virtual int GetNumImeCandidates() = 0;
51  virtual int GetSelectedImeCandidate() = 0;
53  virtual const char16_t* GetImeCandidate(int anIndex) = 0;
54 
57  virtual void ImeFinalizeString(bool bSend) = 0;
59  virtual const char16_t* GetImeString() = 0;
61  virtual int GetImeCursorPosition() = 0;
62  };
63 
65  class CIMELock : ParaEngine::mutex::ScopedLock
66  {
67  public:
68  CIMELock();
69  };
70 
71 #define MAX_CANDLIST 10
72 #define MAX_COMPSTRING_SIZE 256
73 
78  class CGUIIME : public IIMESystem
79  {
80  public:
81  CGUIIME(){};
82 
83  public:
85  virtual bool GetShowImeReadingWindow();
87  virtual bool GetShowImeCandidateWindow();
89  virtual bool GetIsVerticalImeCandidate();
91  virtual bool GetIsHorizontalImeReading();
92 
94  virtual void SetImeState(IMESTATE aState);
96  virtual IMESTATE GetImeState();
98  virtual IMELanguage GetImeLanguage();
100  virtual const char16_t* GetImeIndicator();
102  virtual int GetNumImeCandidates();
104  virtual int GetSelectedImeCandidate();
106  virtual const char16_t* GetImeCandidate(int anIndex);
107 
110  virtual void ImeFinalizeString(bool bSend);
112  virtual const char16_t* GetImeString();
114  virtual int GetImeCursorPosition();
115 
116  public:
117  static void Initialize();
118  static void Uninitialize();
119  // Empty implementation of the IMM32 API
120  static INPUTCONTEXT* WINAPI Dummy_ImmLockIMC( HIMC ) { return NULL; }
121  static BOOL WINAPI Dummy_ImmUnlockIMC( HIMC ) { return FALSE; }
122  static LPVOID WINAPI Dummy_ImmLockIMCC( HIMCC ) { return NULL; }
123  static BOOL WINAPI Dummy_ImmUnlockIMCC( HIMCC ) { return FALSE; }
124  static BOOL WINAPI Dummy_ImmDisableTextFrameService( DWORD ) { return TRUE; }
125  static LONG WINAPI Dummy_ImmGetCompositionStringW( HIMC, DWORD, LPVOID, DWORD ) { return IMM_ERROR_GENERAL; }
126  static DWORD WINAPI Dummy_ImmGetCandidateListW( HIMC, DWORD, LPCANDIDATELIST, DWORD ) { return 0; }
127  // added 2010.4.24 Xizhi, for interprocess IME
128  static HIMC WINAPI Dummy_ImmCreateContext() {return NULL;};
129  static BOOL WINAPI Dummy_ImmDestroyContext( HIMC hIMC) {return FALSE;};
130  static HIMC WINAPI Dummy_ImmGetContext( HWND ) { return NULL; }
131  static BOOL WINAPI Dummy_ImmReleaseContext( HWND, HIMC ) { return FALSE; }
132  static HIMC WINAPI Dummy_ImmAssociateContext( HWND, HIMC ) { return NULL; }
133  static BOOL WINAPI Dummy_ImmGetOpenStatus( HIMC ) { return 0; }
134  static BOOL WINAPI Dummy_ImmSetOpenStatus( HIMC, BOOL ) { return 0; }
135  static BOOL WINAPI Dummy_ImmGetConversionStatus( HIMC, LPDWORD, LPDWORD ) { return 0; }
136  static HWND WINAPI Dummy_ImmGetDefaultIMEWnd( HWND ) { return NULL; }
137  static UINT WINAPI Dummy_ImmGetIMEFileNameA( HKL, LPSTR, UINT ) { return 0; }
138  static UINT WINAPI Dummy_ImmGetVirtualKey( HWND ) { return 0; }
139  static BOOL WINAPI Dummy_ImmNotifyIME( HIMC, DWORD, DWORD, DWORD ) { return FALSE; }
140  static BOOL WINAPI Dummy_ImmSetConversionStatus( HIMC, DWORD, DWORD ) { return FALSE; }
141  static BOOL WINAPI Dummy_ImmSimulateHotKey( HWND, DWORD ) { return FALSE; }
142  static BOOL WINAPI Dummy_ImmIsIME( HKL ) { return FALSE; }
143  static BOOL WINAPI Dummy_ImmSetCandidateWindow(HIMC, LPCANDIDATEFORM) {return FALSE;};
144 
145  // Traditional Chinese IME
146  static UINT WINAPI Dummy_GetReadingString( HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT ) { return 0; }
147  static BOOL WINAPI Dummy_ShowReadingWindow( HIMC, BOOL ) { return FALSE; }
148 
149  // Verion library imports
150  static BOOL APIENTRY Dummy_VerQueryValueA( const LPVOID, LPSTR, LPVOID *, PUINT ) { return 0; }
151  static BOOL APIENTRY Dummy_GetFileVersionInfoA( LPSTR, DWORD, DWORD, LPVOID ) { return 0; }
152  static DWORD APIENTRY Dummy_GetFileVersionInfoSizeA( LPSTR, LPDWORD ) { return 0; }
153 
154  // Function pointers: IMM32
155  static INPUTCONTEXT* (WINAPI * _ImmLockIMC)( HIMC );
156  static BOOL (WINAPI * _ImmUnlockIMC)( HIMC );
157  static LPVOID (WINAPI * _ImmLockIMCC)( HIMCC );
158  static BOOL (WINAPI * _ImmUnlockIMCC)( HIMCC );
159  static BOOL (WINAPI * _ImmDisableTextFrameService)( DWORD );
160  static LONG (WINAPI * _ImmGetCompositionStringW)( HIMC, DWORD, LPVOID, DWORD );
161  static DWORD (WINAPI * _ImmGetCandidateListW)( HIMC, DWORD, LPCANDIDATELIST, DWORD );
162  static HIMC (WINAPI* _ImmCreateContext)();
163  static BOOL (WINAPI* _ImmDestroyContext)( HIMC hIMC);
164  static HIMC (WINAPI * _ImmGetContext)( HWND );
165  static BOOL (WINAPI * _ImmReleaseContext)( HWND, HIMC );
166  static HIMC (WINAPI * _ImmAssociateContext)( HWND, HIMC );
167  static BOOL (WINAPI * _ImmGetOpenStatus)( HIMC );
168  static BOOL (WINAPI * _ImmSetOpenStatus)( HIMC, BOOL );
169  static BOOL (WINAPI * _ImmGetConversionStatus)( HIMC, LPDWORD, LPDWORD );
170  static HWND (WINAPI * _ImmGetDefaultIMEWnd)( HWND );
171  static UINT (WINAPI * _ImmGetIMEFileNameA)( HKL, LPSTR, UINT );
172  static UINT (WINAPI * _ImmGetVirtualKey)( HWND );
173  static BOOL (WINAPI * _ImmNotifyIME)( HIMC, DWORD, DWORD, DWORD );
174  static BOOL (WINAPI * _ImmSetConversionStatus)( HIMC, DWORD, DWORD );
175  static BOOL (WINAPI * _ImmSimulateHotKey)( HWND, DWORD );
176  static BOOL (WINAPI * _ImmIsIME)( HKL );
177  static BOOL (WINAPI * _ImmSetCandidateWindow)(HIMC, LPCANDIDATEFORM);
178 
179  // Function pointers: Traditional Chinese IME
180  static UINT (WINAPI * _GetReadingString)( HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT );
181  static BOOL (WINAPI * _ShowReadingWindow)( HIMC, BOOL );
182 
183  // Function pointers: Verion library imports
184  static BOOL (APIENTRY * _VerQueryValueA)( const LPVOID, LPSTR, LPVOID *, PUINT );
185  static BOOL (APIENTRY * _GetFileVersionInfoA)( LPSTR, DWORD, DWORD, LPVOID );
186  static DWORD (APIENTRY * _GetFileVersionInfoSizeA)( LPSTR, LPDWORD );
187 
188  public:
190  static HRESULT StaticOnCreateDevice();
191 
193  static bool HandleWinThreadMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
194 
196  static bool StaticMsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
197 
199  static void EnableImeSystem( bool bEnable );
200  static bool IsEnableImeSystem();
201 
208  static void SetIMEOpenStatus(bool bOpen, bool bForce=true);
209  static void SetIMEOpenStatus_imp(bool bOpen);
210 
212  static bool SwitchIn();
213 
215  static bool SwitchOut();
216 
218  static bool OnFocusIn();
220  static bool OnFocusIn_imp();
221 
223  static bool OnFocusOut();
225  static bool OnFocusOut_imp();
226 
232  static bool GetIMEOpenStatus();
233 
234  /***/
235  static bool WinMsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
236 
237  static void ResetCaretBlink();
238 
240  static bool IMEHasFocus();
241 
243  static IMESTATE GetImeStateS();
244 
245 
247  static void SendWinMsgChar(WCHAR c);
248 
252  static std::wstring GetWinMsgChar(bool bRemove = true);
253 
255  static void SetCompositionPosition(int x, int y);
256 
260  static std::wstring GetLastCompString(bool bRemove = true);
261  static std::wstring GetCurrentCompString();
262 
263  protected:
264  static WORD GetLanguage() { return LOWORD( s_hklCurrent ); }
265  static WORD GetPrimaryLanguage() { return PRIMARYLANGID( LOWORD( s_hklCurrent ) ); }
266  static WORD GetSubLanguage() { return SUBLANGID( LOWORD( s_hklCurrent ) ); }
267  static void SendKey( BYTE nVirtKey );
268  static DWORD GetImeId( UINT uIndex = 0 );
269  static void CheckInputLocale();
270  static void CheckToggleState();
271  static void SetupImeApi();
272  static void ResetCompositionString();
273  static void TruncateCompString( bool bUseBackSpace = true, int iNewStrLen = 0 );
274  static void FinalizeString( bool bSend );
275  static void GetReadingWindowOrientation( DWORD dwId );
276  static void GetPrivateReadingString();
277 
279  static void SendCompString();
280 
281  protected:
282  enum { INDICATOR_NON_IME, INDICATOR_CHS, INDICATOR_CHT, INDICATOR_KOREAN, INDICATOR_JAPANESE };
283 
284  struct CCandList
285  {
286  WCHAR awszCandidate[MAX_CANDLIST][256];
287  CUniBuffer HoriCand; // Candidate list string (for horizontal candidate window)
288  int nFirstSelected; // First character position of the selected string in HoriCand
289  int nHoriSelectedLen; // Length of the selected string in HoriCand
290  DWORD dwCount; // Number of valid entries in the candidate list
291  DWORD dwSelection; // Currently selected candidate entry relative to page top
292  DWORD dwPageSize;
293  int nReadingError; // Index of the error character
294  bool bShowWindow; // Whether the candidate list window is visible
295  RECT rcCandidate; // Candidate rectangle computed and filled each time before rendered
296  };
297 
298  struct CInputLocale
299  {
300  HKL m_hKL; // Keyboard layout
301  WCHAR m_wszLangAbb[3]; // Language abbreviation
302  WCHAR m_wszLang[64]; // Localized language name
303  };
304 
305  // Application-wide data
306  static HINSTANCE s_hDllImm32; // IMM32 DLL handle
307  static HINSTANCE s_hDllVer; // Version DLL handle
308  static HIMC s_hImcDef; // Default input context
309 
310  static HKL s_hklCurrent; // Current keyboard layout of the process
311  static bool s_bVerticalCand; // Indicates that the candidates are listed vertically
312  static LPWSTR s_wszCurrIndicator; // Points to an indicator string that corresponds to current input locale
313  static WCHAR s_aszIndicator[5][3]; // string to draw to indicate current input locale
314  static bool s_bInsertOnType; // Insert the character as soon as a key is pressed (Korean behavior)
315  static HINSTANCE s_hDllIme; // Instance handle of the current IME module
316  static IMESTATE s_ImeState; // IME global state
317  static bool s_bEnableImeSystem; // Whether the IME system is active
318  static POINT s_ptCompString; // Composition string position. Updated every frame.
319  static int s_nCompCaret; // Caret position of the composition string
320  static int s_nFirstTargetConv; // Index of the first target converted char in comp string. If none, -1.
321  static CUniBuffer s_CompString; // Buffer to hold the composition string (we fix its length)
322  static BYTE s_abCompStringAttr[MAX_COMPSTRING_SIZE];
323  static DWORD s_adwCompStringClause[MAX_COMPSTRING_SIZE];
324  static WCHAR s_wszReadingString[32];// Used only with horizontal reading window (why?)
325  static CCandList s_CandList; // Data relevant to the candidate list
326  static bool s_bShowReadingWindow; // Indicates whether reading window is visible
327  static bool s_bHorizontalReading; // Indicates whether the reading window is vertical or horizontal
328  static bool s_bChineseIME;
329  static CGrowableArray< CInputLocale > s_Locale; // Array of loaded keyboard layout on system
330 
331  // Static
332  static bool s_bHideCaret; // If true, we don't render the caret.
333  static bool s_bRenderLocaleIndicator;
334  static bool s_bIMETrap;
335  static bool s_bIMEHasFocus;
336 
337  static bool m_bInsertMode;
338  static bool m_bCaretOn;
339  static double m_dfLastBlink;
340 
341  static POINT m_nCompositionWindowPoint;
342 
344  static bool s_bCreateIMEContext;
345 
346 #if defined(DEBUG) | defined(_DEBUG)
347  static bool m_bIMEStaticMsgProcCalled;
348 #endif
349  static ParaEngine::mutex s_mutex;
350  static std::wstring s_sLastCompString;
352  static std::wstring s_sLastWindowsChars;
353  static std::wstring s_sCurrentCompString;
354 
355  friend class CIMELock;
356  };
357 }
358 #else
359 namespace ParaEngine
360 {
364  class CGUIIME
365  {
366  public:
367  static void EnableImeSystem( bool bEnable){};
368  static bool IsEnableImeSystem() {return false;};
369 
371  static void SetCompositionPosition(int x, int y){};
372 
374  static bool OnFocusIn() {return true;};
375 
377  static bool OnFocusOut() {return true;};
378  };
379 }
380 
381 #endif
different physics engine has different winding order.
Definition: EventBinding.h:32
simple scoped lock function
Definition: mutex.h:12
Definition: PEtypes.h:116
Definition: ManagedDef.h:18
static void SetCompositionPosition(int x, int y)
when we use the default IME window to render, the application (EditBox control) should call this func...
Definition: GUIIME.h:371
static bool OnFocusIn()
To be called when a GUI virtual window gains focus.
Definition: GUIIME.h:374
static bool OnFocusOut()
To be called when a GUI virtual window loses focus.
Definition: GUIIME.h:377
cross platform mutex
Definition: mutex.h:95
GUI IME message system.
Definition: GUIIME.h:364