Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. imewnd.h
  5. Abstract:
  6. This file defines the Default IME Window Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #ifndef _IMEWND_H_
  12. #define _IMEWND_H_
  13. #include "cstring.h"
  14. extern "C" {
  15. // windows subclass
  16. LRESULT ImeWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  17. LRESULT ImeWndProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  18. }
  19. class CDefaultIMEWindow
  20. {
  21. public:
  22. CDefaultIMEWindow() {
  23. m_hDefaultIMEWnd = NULL;
  24. m_hDummyDefaultIMEWnd = NULL;
  25. m_nCntInAIMEProc = 0;
  26. m_bMyRegisterClass = FALSE;
  27. m_bMyCreateWindow = FALSE;
  28. // m_bNeedRecoverIMEWndProc = FALSE;
  29. m_SubclassWindowProc = 0;
  30. }
  31. virtual ~CDefaultIMEWindow() {
  32. if (IsWindow(m_hDefaultIMEWnd) && m_SubclassWindowProc) {
  33. //
  34. // Set the wndproc pointer back to original WndProc.
  35. //
  36. // some other subclass window may keep my WndProc pointer.
  37. // but msctf.dll may be unloaded from memory so we don't want to
  38. // call him to set the wndproc pointer back to our Wndproc pointer.
  39. // The pointer will be bogus.
  40. //
  41. WNDPROC pfnOrgImeWndProc;
  42. pfnOrgImeWndProc = (WNDPROC)GetClassLongPtr(m_hDefaultIMEWnd, GCLP_WNDPROC);
  43. SetWindowLongPtr(m_hDefaultIMEWnd,
  44. GWLP_WNDPROC,
  45. (LONG_PTR)pfnOrgImeWndProc);
  46. m_SubclassWindowProc = NULL;
  47. }
  48. }
  49. HRESULT GetDefaultIMEWnd(IN HWND hWnd, OUT HWND *phDefWnd);
  50. LRESULT CallWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  51. LRESULT SendIMEMessage(UINT Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode = TRUE,
  52. BOOL fCheckImm32 = TRUE) {
  53. if (fCheckImm32 && IsOnImm()) {
  54. return 0L;
  55. }
  56. LRESULT lRet;
  57. InterlockedIncrement(&m_nCntInAIMEProc); // Mark to avoid recursion.
  58. if (fUnicode)
  59. lRet = SendMessageW(m_hDefaultIMEWnd, Msg, wParam, lParam);
  60. else
  61. lRet = SendMessageA(m_hDefaultIMEWnd, Msg, wParam, lParam);
  62. InterlockedDecrement(&m_nCntInAIMEProc);
  63. return lRet;
  64. }
  65. BOOL IsAIMEHandler()
  66. {
  67. return (m_nCntInAIMEProc > 0);
  68. }
  69. public:
  70. BOOL _CreateDefaultIMEWindow(HIMC hDefIMC);
  71. BOOL _DestroyDefaultIMEWindow();
  72. protected:
  73. HWND _CreateIMEWindow(HIMC hDefIMC);
  74. public:
  75. BOOL IsNeedRecovIMEWndProc() {
  76. #if 0
  77. return (m_bNeedRecoverIMEWndProc == TRUE);
  78. #endif
  79. return FALSE;
  80. }
  81. private:
  82. #if 0
  83. BOOL InitDefIMEWndSubclass() {
  84. if (m_SubclassWindowProc == NULL) {
  85. m_SubclassWindowProc = SetWindowLongPtr(m_hDefaultIMEWnd,
  86. GWLP_WNDPROC,
  87. (LONG_PTR)ImeWndProcA);
  88. if (IsOnImm()) {
  89. LONG_PTR _OriginalWindowProc = GetWindowLongPtr(m_hDummyDefaultIMEWnd,
  90. GWLP_WNDPROC);
  91. //
  92. // We assume the m_SubclassWindowProc and _OriginalWindowProc are
  93. // the same address of USER32!ImeWndProcA/W.
  94. //
  95. if (m_SubclassWindowProc != _OriginalWindowProc) {
  96. //
  97. // Anybody rewrote the default IME window procedure address.
  98. // We know the MSIME9x/2K rewrote an address to MSIMEPrivateWindowProc.
  99. // We should catch a recovery procedure address by the IME
  100. // that using window call hook the _DefImeWnd_CallWndProc.
  101. //
  102. m_bNeedRecoverIMEWndProc = TRUE;
  103. }
  104. }
  105. }
  106. return (m_SubclassWindowProc != 0);
  107. }
  108. #endif
  109. BOOL Start() {
  110. Assert(IsWindow(m_hDefaultIMEWnd));
  111. if (m_SubclassWindowProc == NULL) {
  112. m_SubclassWindowProc = SetWindowLongPtr(m_hDefaultIMEWnd,
  113. GWLP_WNDPROC,
  114. (LONG_PTR)ImeWndProcA);
  115. }
  116. return (m_SubclassWindowProc != 0);
  117. }
  118. #if 0
  119. VOID UninitDefIMEWndSubclass() {
  120. if (m_SubclassWindowProc) {
  121. SetWindowLongPtr(m_hDefaultIMEWnd,
  122. GWLP_WNDPROC,
  123. m_SubclassWindowProc);
  124. m_SubclassWindowProc = NULL;
  125. }
  126. }
  127. #endif
  128. WNDPROC Stop() {
  129. Assert(IsWindow(m_hDefaultIMEWnd));
  130. WNDPROC pfnBack = (WNDPROC)m_SubclassWindowProc;
  131. if (m_SubclassWindowProc != NULL) {
  132. //
  133. // unfortunately, we can not restore the wndproc pointer always.
  134. // someone else subclassed it after we did.
  135. //
  136. WNDPROC pfnCur = (WNDPROC)GetWindowLongPtr(m_hDefaultIMEWnd, GWLP_WNDPROC);
  137. if (pfnCur == ImeWndProcA) {
  138. SetWindowLongPtr(m_hDefaultIMEWnd,
  139. GWLP_WNDPROC,
  140. (LONG_PTR) m_SubclassWindowProc);
  141. m_SubclassWindowProc = NULL;
  142. }
  143. }
  144. return pfnBack;
  145. }
  146. public:
  147. VOID ImeDefWndHook(HWND hWnd) {
  148. #if 0
  149. LONG_PTR _WindowProc = GetWindowLongPtr(m_hDefaultIMEWnd,
  150. GWLP_WNDPROC);
  151. ASSERT(m_hDummyDefaultIMEWnd != NULL);
  152. LONG_PTR _OriginalWindowProc = GetWindowLongPtr(m_hDummyDefaultIMEWnd,
  153. GWLP_WNDPROC);
  154. if (_WindowProc == _OriginalWindowProc) {
  155. //
  156. // Recovered procedure address.
  157. //
  158. m_SubclassWindowProc = SetWindowLongPtr(m_hDefaultIMEWnd,
  159. GWLP_WNDPROC,
  160. (LONG_PTR)ImeWndProcA);
  161. }
  162. #endif
  163. }
  164. private:
  165. HWND m_hDefaultIMEWnd; // Handle of default IME window.
  166. HWND m_hDummyDefaultIMEWnd; // Handle of Dummy default IME window.
  167. LONG m_nCntInAIMEProc; // Non-zero if hwnd has called into CCiceroIME::ActivateLayout/DeactivateLayout.
  168. BOOL m_bMyRegisterClass; // TRUE: RegisterClass("IME") myself.
  169. BOOL m_bMyCreateWindow; // TRUE: CreateWindow("IME") myself.
  170. // BOOL m_bNeedRecoverIMEWndProc; // TRUE: Need a recovery IME wnd proc addr.
  171. LONG_PTR m_SubclassWindowProc; // Address of subclass window procedure.
  172. };
  173. LRESULT ImeWndDestroyHandler(HWND hwnd);
  174. LRESULT ImeSelectHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL fUnicode);
  175. LRESULT ImeControlHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL fUnicode);
  176. LRESULT ImeSetContextHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL fUnicode);
  177. LRESULT ImeNotifyHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL fUnicode);
  178. #endif // _IMEWND_H_