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.

344 lines
8.5 KiB

  1. /**************************************************************************\
  2. * Module Name: softkbdimx.cpp
  3. *
  4. * Copyright (c) 1985 - 2000, Microsoft Corporation
  5. *
  6. * Declaration of Soft Keyboard Input TIP class.
  7. *
  8. * History:
  9. * 28-March-2000 weibz Created
  10. \**************************************************************************/
  11. #ifndef SOFTKBDIMX_H
  12. #define SOFTKBDIMX_H
  13. #include "private.h"
  14. #include "globals.h"
  15. #include "dap.h"
  16. #include "computil.h"
  17. #include "resource.h"
  18. #include "softkbd.h"
  19. #include "nui.h"
  20. #include "immxutil.h"
  21. class CCommandEventSink;
  22. class CEditSession;
  23. class CThreadMgrEventSink;
  24. class CSoftKeyboardEventSink;
  25. class CSoftKbdWindowEventSink;
  26. class CFunctionProvider;
  27. class CActiveLanguageProfileNotifySink;
  28. class CLanguageProfileNotifySink;
  29. #define ESCB_KEYLABEL 10
  30. #define NON_LAYOUT 0
  31. #define KBDTYPE_NONE 0
  32. #define KBDTYPE_STANDARD 1
  33. #define KBDTYPE_SYMBOL 2
  34. typedef struct tagSoftLayout
  35. {
  36. DWORD dwSoftKbdLayout;
  37. BOOL fStandard;
  38. DWORD dwNumLabels; // Number of Label status.
  39. DWORD dwCurLabel;
  40. CSoftKeyboardEventSink *pskbdes;
  41. DWORD dwSkbdESCookie;
  42. } SOFTLAYOUT;
  43. class CSoftkbdIMX :
  44. public CComObjectRoot_CreateInstance<CSoftkbdIMX>,
  45. public ITfTextInputProcessor,
  46. public ITfThreadFocusSink,
  47. public CDisplayAttributeProvider
  48. {
  49. public:
  50. CSoftkbdIMX();
  51. ~CSoftkbdIMX();
  52. BEGIN_COM_MAP_IMMX(CSoftkbdIMX)
  53. COM_INTERFACE_ENTRY(ITfTextInputProcessor)
  54. COM_INTERFACE_ENTRY(ITfThreadFocusSink)
  55. COM_INTERFACE_ENTRY(ITfDisplayAttributeProvider)
  56. END_COM_MAP_IMMX()
  57. public:
  58. // ITfX methods
  59. STDMETHODIMP Activate(ITfThreadMgr *ptim, TfClientId tid);
  60. STDMETHODIMP Deactivate();
  61. // ITfThreadFocusSink
  62. STDMETHODIMP OnSetThreadFocus();
  63. STDMETHODIMP OnKillThreadFocus();
  64. static LRESULT CALLBACK _OwnerWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  65. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  66. }
  67. void _OnOffToggle( );
  68. ITfContext *GetIC();
  69. HWND GetOwnerWnd() {return _hOwnerWnd;}
  70. HRESULT Initialize( );
  71. BOOL _fOnOffSave;
  72. BOOL GetSoftKBDOnOff( )
  73. {
  74. DWORD dw;
  75. if ( _tim == NULL )
  76. return FALSE;
  77. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_HANDWRITING_OPENCLOSE , &dw, FALSE);
  78. return dw ? TRUE : FALSE;
  79. }
  80. void SetSoftKBDOnOff( BOOL fOn )
  81. {
  82. // check to see if the _SoftKbd and soft keyboard related members are initialized.
  83. if ( _fInitialized == FALSE )
  84. {
  85. Initialize( );
  86. }
  87. if ( (_SoftKbd == NULL) || ( _tim == NULL) )
  88. return;
  89. if ( fOn == GetSoftKBDOnOff( ) )
  90. return;
  91. SetCompartmentDWORD(_tid, _tim, GUID_COMPARTMENT_HANDWRITING_OPENCLOSE ,fOn ? 0x01 : 0x00 , FALSE);
  92. }
  93. DWORD GetSoftKBDLayout( )
  94. {
  95. DWORD dw;
  96. if ( (_SoftKbd == NULL) || ( _tim == NULL) )
  97. return NON_LAYOUT;
  98. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SOFTKBD_KBDLAYOUT, &dw, FALSE);
  99. return dw;
  100. }
  101. void SetSoftKBDLayout(DWORD dwKbdLayout)
  102. {
  103. // check to see if the _SoftKbd and soft keyboard related members are initialized.
  104. if ( _fInitialized == FALSE )
  105. {
  106. Initialize( );
  107. }
  108. if ( (_SoftKbd == NULL) || ( _tim == NULL) )
  109. return;
  110. SetCompartmentDWORD(_tid, _tim, GUID_COMPARTMENT_SOFTKBD_KBDLAYOUT, dwKbdLayout , FALSE);
  111. }
  112. HRESULT GetSoftKBDPosition(int *xWnd, int *yWnd)
  113. {
  114. DWORD dwPos;
  115. HRESULT hr = S_OK;
  116. if ( (_SoftKbd == NULL) || ( _tim == NULL) )
  117. return E_FAIL;
  118. if ( !xWnd || !yWnd )
  119. return E_FAIL;
  120. hr = GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SOFTKBD_WNDPOSITION, &dwPos, TRUE);
  121. if ( hr == S_OK )
  122. {
  123. *xWnd = dwPos & 0x0000ffff;
  124. *yWnd = (dwPos >> 16) & 0x0000ffff;
  125. hr = S_OK;
  126. }
  127. else
  128. {
  129. *xWnd = 0;
  130. *yWnd = 0;
  131. hr = E_FAIL;
  132. }
  133. return hr;
  134. }
  135. void SetSoftKBDPosition(int xWnd, int yWnd )
  136. {
  137. DWORD dwPos;
  138. DWORD left, top;
  139. if ( (_SoftKbd == NULL) || ( _tim == NULL) )
  140. return;
  141. if ( xWnd < 0 )
  142. left = 0;
  143. else
  144. left = (WORD)xWnd;
  145. if ( yWnd < 0 )
  146. top = 0;
  147. else
  148. top = (WORD)yWnd;
  149. dwPos = ((DWORD)top << 16) + left;
  150. SetCompartmentDWORD(_tid, _tim, GUID_COMPARTMENT_SOFTKBD_WNDPOSITION, dwPos, TRUE);
  151. }
  152. static HRESULT _EditSessionCallback(TfEditCookie ec, CEditSession *pes);
  153. ITfThreadMgr *_tim;
  154. TfClientId _GetId() { return _tid; }
  155. LANGID _GetLangId( ) { return _langid; }
  156. ISoftKbd *_SoftKbd;
  157. SOFTLAYOUT _KbdStandard;
  158. SOFTLAYOUT _KbdSymbol;
  159. DWORD _CurLayout;
  160. DWORD _CurKbdType;
  161. TfClientId _tid;
  162. ITfDocumentMgr *_dim;
  163. LANGID _langid;
  164. ITfInputProcessorProfiles *_pProfile;
  165. void _InitLangID()
  166. {
  167. ITfInputProcessorProfiles *pProfile;
  168. _langid = 0x409;
  169. if ( _pProfile == NULL )
  170. {
  171. CoCreateInstance(CLSID_TF_InputProcessorProfiles,
  172. NULL,
  173. CLSCTX_INPROC_SERVER,
  174. IID_ITfInputProcessorProfiles,
  175. (void **) &_pProfile);
  176. }
  177. if ( _pProfile != NULL )
  178. {
  179. GUID guid;
  180. pProfile = _pProfile;
  181. pProfile->AddRef( );
  182. pProfile->GetActiveLanguageProfile(CLSID_SoftkbdIMX,
  183. &_langid,
  184. &guid);
  185. pProfile->Release( );
  186. }
  187. }
  188. private:
  189. HRESULT _InputKeyLabel(TfEditCookie ec, ITfContext *pic, WCHAR *lpszLabel, UINT nLabLen);
  190. void _UpdateUI();
  191. HRESULT _MySetSelectionSimple(TfEditCookie ec, ITfContext *pic, ITfRange *range);
  192. HRESULT _ShowSoftKBDWindow( BOOL fShow );
  193. HWND _hOwnerWnd;
  194. CFunctionProvider *_pFuncPrv;
  195. static HRESULT _CompEventSinkCallback(void *pv, REFGUID rguid);
  196. // compartment (storage) event sink
  197. CCompartmentEventSink *_pCes;
  198. UINT_PTR _uCurrentEditCookie;
  199. DWORD _dwThreadFocusCookie;
  200. static HRESULT _AlsCallback(REFCLSID clsid, REFGUID guidProfile, BOOL fActivated, void *pv);
  201. static HRESULT _LsCallback(BOOL fChanged, LANGID langid, BOOL *pfAccept, void *pv);
  202. CActiveLanguageProfileNotifySink *_timActiveLangSink;
  203. CLanguageProfileNotifySink *_timLangSink;
  204. CSoftKbdWindowEventSink *_psftkbdwndes;
  205. DWORD _dwsftkbdwndesCookie;
  206. CLBarItem *_plbi;
  207. BOOL _fInitialized;
  208. LIBTHREAD _libTLS; // tls for the helper library. Since this object is apt threaded,
  209. // all members are accessed in a single thread
  210. // also, cicero will only create a single instance of this obj per thread
  211. };
  212. inline void SetThis(HWND hWnd, LPARAM lParam)
  213. {
  214. SetWindowLongPtr(hWnd, GWLP_USERDATA, (UINT_PTR)((CREATESTRUCT *)lParam)->lpCreateParams);
  215. }
  216. inline CSoftkbdIMX *GetThis(HWND hWnd)
  217. {
  218. CSoftkbdIMX *pIMX = (CSoftkbdIMX *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
  219. Assert(pIMX != NULL);
  220. return pIMX;
  221. }
  222. class CSoftkbdRegistry :
  223. public CComObjectRoot_CreateInstance<CSoftkbdRegistry>,
  224. public ITfSoftKbdRegistry
  225. {
  226. public:
  227. CSoftkbdRegistry();
  228. ~CSoftkbdRegistry();
  229. BEGIN_COM_MAP_IMMX(CSoftkbdRegistry)
  230. COM_INTERFACE_ENTRY(ITfSoftKbdRegistry)
  231. END_COM_MAP_IMMX()
  232. public:
  233. // ITfSoftKbdRegistry
  234. STDMETHODIMP EnableSoftkbd(LANGID langid );
  235. STDMETHODIMP DisableSoftkbd(LANGID langid );
  236. private:
  237. HRESULT _SetSoftkbdTIP(LANGID langid, BOOL fEnable );
  238. HRESULT _GenerateCurrentLangProfileList( );
  239. BOOL m_fInitialized;
  240. CComPtr<ITfInputProcessorProfilesEx> m_cpInputProcessorProfiles;
  241. CStructArray<LANGID> m_rgLang;
  242. WCHAR m_pwszStandard[128];
  243. WCHAR m_pwszSymbol[128];
  244. WCHAR m_pwszIconFile[MAX_PATH];
  245. };
  246. #endif // SOFTKBDIMX_H