IMEManager.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * FILE
  21. * $Archive: /Commando/Code/wwui/IMEManager.h $
  22. *
  23. * DESCRIPTION
  24. * Input Method Editor Manager for input of far east characters.
  25. *
  26. * PROGRAMMER
  27. * $Author: Denzil_l $
  28. *
  29. * VERSION INFO
  30. * $Revision: 3 $
  31. * $Modtime: 1/08/02 8:38p $
  32. *
  33. ******************************************************************************/
  34. #ifndef __IMEMANAGER_H__
  35. #define __IMEMANAGER_H__
  36. #include "RefCount.h"
  37. #include "IMECandidate.h"
  38. #include "Notify.h"
  39. #include "WideString.h"
  40. #include "win.h"
  41. #include <imm.h>
  42. namespace IME {
  43. #define IME_MAX_STRING_LEN 255
  44. #define IME_MAX_TYPING_LEN 80
  45. class IMEManager;
  46. typedef enum
  47. {
  48. IME_ACTIVATED = 1,
  49. IME_DEACTIVATED,
  50. IME_LANGUAGECHANGED,
  51. IME_GUIDELINE,
  52. IME_ENABLED,
  53. IME_DISABLED,
  54. } IMEAction;
  55. typedef TypedActionPtr<IMEAction, IMEManager> IMEEvent;
  56. typedef enum
  57. {
  58. COMPOSITION_INVALID = 0,
  59. COMPOSITION_TYPING,
  60. COMPOSITION_START,
  61. COMPOSITION_CHANGE,
  62. COMPOSITION_FULL,
  63. COMPOSITION_END,
  64. COMPOSITION_CANCEL,
  65. COMPOSITION_RESULT
  66. } CompositionAction;
  67. typedef TypedActionPtr<CompositionAction, IMEManager> CompositionEvent;
  68. class UnicodeType;
  69. typedef TypedEvent<UnicodeType, wchar_t> UnicodeChar;
  70. class IMEManager :
  71. public RefCountClass,
  72. public Notifier<IMEEvent>,
  73. public Notifier<UnicodeChar>,
  74. public Notifier<CompositionEvent>,
  75. public Notifier<CandidateEvent>
  76. {
  77. public:
  78. static IMEManager* Create(HWND hwnd);
  79. void Activate(void);
  80. void Deactivate(void);
  81. bool IsActive(void) const;
  82. void Disable(void);
  83. void Enable(void);
  84. bool IsDisabled(void) const;
  85. const wchar_t* GetDescription(void) const
  86. {return mIMEDescription;}
  87. WORD GetLanguageID(void) const
  88. {return mLangID;}
  89. UINT GetCodePage(void) const
  90. {return mCodePage;}
  91. const wchar_t* GetResultString(void) const
  92. {return mResultString;}
  93. const wchar_t* GetCompositionString(void) const
  94. {return mCompositionString;}
  95. long GetCompositionCursorPos(void) const
  96. {return mCompositionCursorPos;}
  97. const wchar_t* GetReadingString(void) const
  98. {return mReadingString;}
  99. #ifdef SHOW_IME_TYPING
  100. const wchar_t* GetTypingString(void) const
  101. {return mTypingString;}
  102. #endif
  103. void GetTargetClause(unsigned long& start, unsigned long& end);
  104. bool GetCompositionFont(LPLOGFONT lpFont);
  105. const IMECandidateCollection GetCandidateColl(void) const
  106. {return mCandidateColl;}
  107. unsigned long GetGuideline(wchar_t* outString, int length);
  108. bool ProcessMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT& result);
  109. protected:
  110. IMEManager();
  111. virtual ~IMEManager();
  112. bool FinalizeCreate(HWND hwnd);
  113. LRESULT IMENotify(WPARAM wParam, LPARAM lParam);
  114. HKL InputLanguageChangeRequest(HKL hkl);
  115. void InputLanguageChanged(HKL hkl);
  116. void ResetComposition(void);
  117. void StartComposition(void);
  118. void DoComposition(unsigned int dbcsChar, long changeFlag);
  119. void EndComposition(void);
  120. bool ReadCompositionString(HIMC imc, unsigned long flag, wchar_t* buffer, int length);
  121. long ReadReadingAttr(HIMC imc, unsigned char* attr, int length);
  122. long ReadReadingClause(HIMC imc, unsigned long* clause, int length);
  123. long ReadCompositionAttr(HIMC imc, unsigned char* attr, int length);
  124. long ReadCompositionClause(HIMC imc, unsigned long* clause, int length);
  125. long ReadCursorPos(HIMC imc);
  126. void OpenCandidate(unsigned long candList);
  127. void ChangeCandidate(unsigned long candList);
  128. void CloseCandidate(unsigned long candList);
  129. bool IMECharHandler(unsigned short dbcs);
  130. bool CharHandler(unsigned short ch);
  131. long ConvertAttrForUnicode(unsigned char* mbcs, unsigned char* attr);
  132. long ConvertClauseForUnicode(unsigned char* mbcs, long length, unsigned long* clause);
  133. DECLARE_NOTIFIER(IMEEvent)
  134. DECLARE_NOTIFIER(UnicodeChar)
  135. DECLARE_NOTIFIER(CompositionEvent)
  136. DECLARE_NOTIFIER(CandidateEvent)
  137. // Prevent copy and assignment
  138. IMEManager(const IMEManager&);
  139. const IMEManager& operator=(const IMEManager&);
  140. private:
  141. HWND mHWND;
  142. HIMC mDefaultHIMC;
  143. HIMC mHIMC;
  144. HIMC mDisabledHIMC;
  145. unsigned long mDisableCount;
  146. WORD mLangID;
  147. UINT mCodePage;
  148. WideStringClass mIMEDescription;
  149. DWORD mIMEProperties;
  150. bool mHilite;
  151. bool mStartCandListFrom1;
  152. bool mOSCanUnicode;
  153. bool mUseUnicode;
  154. bool mInComposition;
  155. #ifdef SHOW_IME_TYPING
  156. wchar_t mTypingString[IME_MAX_TYPING_LEN];
  157. long mTypingCursorPos;
  158. #endif
  159. wchar_t mCompositionString[IME_MAX_STRING_LEN];
  160. unsigned char mCompositionAttr[IME_MAX_STRING_LEN];
  161. unsigned long mCompositionClause[IME_MAX_STRING_LEN / 2];
  162. long mCompositionCursorPos;
  163. wchar_t mReadingString[IME_MAX_STRING_LEN * 2];
  164. wchar_t mResultString[IME_MAX_STRING_LEN];
  165. IMECandidateCollection mCandidateColl;
  166. };
  167. } // namespace IME
  168. #endif __IMEMANAGER_H__