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.

412 lines
9.1 KiB

  1. /**************************************************************************\
  2. * Module Name: softkbdes.cpp
  3. *
  4. * Copyright (c) 1985 - 2000, Microsoft Corporation
  5. *
  6. * Soft Keyboard Event Sink for the Symbol layout
  7. *
  8. * History:
  9. * 28-March-2000 weibz Created
  10. \**************************************************************************/
  11. #include "private.h"
  12. #include "globals.h"
  13. #include "immxutil.h"
  14. #include "proputil.h"
  15. #include "helpers.h"
  16. #include "editcb.h"
  17. #include "dispattr.h"
  18. #include "computil.h"
  19. #include "regsvr.h"
  20. #include "Softkbdimx.h"
  21. #include "SoftKbdES.h"
  22. //////////////////////////////////////////////////////////////////////
  23. // Construction/Destruction
  24. //////////////////////////////////////////////////////////////////////
  25. CSoftKeyboardEventSink::CSoftKeyboardEventSink(CSoftkbdIMX *pSoftKbdIMX,
  26. DWORD dwSoftLayout)
  27. {
  28. _pSoftKbdIMX = pSoftKbdIMX;
  29. _dwSoftLayout= dwSoftLayout;
  30. _fCaps = FALSE;
  31. _fShift= FALSE;
  32. _tid = pSoftKbdIMX->_tid;
  33. _tim = pSoftKbdIMX->_tim;
  34. _tim->AddRef( );
  35. _cRef = 1;
  36. }
  37. CSoftKeyboardEventSink::~CSoftKeyboardEventSink()
  38. {
  39. SafeReleaseClear(_tim);
  40. }
  41. //+---------------------------------------------------------------------------
  42. //
  43. // IUnknown
  44. //
  45. //----------------------------------------------------------------------------
  46. STDAPI CSoftKeyboardEventSink::QueryInterface(REFIID riid, void **ppvObj)
  47. {
  48. *ppvObj = NULL;
  49. if (IsEqualIID(riid, IID_IUnknown) ||
  50. IsEqualIID(riid, IID_ISoftKeyboardEventSink))
  51. {
  52. *ppvObj = SAFECAST(this, CSoftKeyboardEventSink *);
  53. }
  54. if (*ppvObj)
  55. {
  56. AddRef();
  57. return S_OK;
  58. }
  59. return E_NOINTERFACE;
  60. }
  61. STDAPI_(ULONG) CSoftKeyboardEventSink::AddRef()
  62. {
  63. return ++_cRef;
  64. }
  65. STDAPI_(ULONG) CSoftKeyboardEventSink::Release()
  66. {
  67. long cr;
  68. cr = --_cRef;
  69. Assert(cr >= 0);
  70. if (cr == 0)
  71. {
  72. delete this;
  73. }
  74. return cr;
  75. }
  76. //
  77. // ISoftKeyboardEventSink
  78. //
  79. STDAPI CSoftKeyboardEventSink::OnKeySelection(KEYID KeySelected, WCHAR *lpszLabel)
  80. {
  81. ITfContext *pic;
  82. HRESULT hr;
  83. CEditSession *pes;
  84. hr = S_OK;
  85. switch ( KeySelected )
  86. {
  87. case KID_CTRL :
  88. case KID_ALT :
  89. // doesn't handle
  90. // just return
  91. break;
  92. case KID_CAPS :
  93. _fCaps = !_fCaps;
  94. if ( _fCaps == _fShift )
  95. // use state 0
  96. (_pSoftKbdIMX->_KbdSymbol).dwCurLabel = 0;
  97. else
  98. // use state 1
  99. (_pSoftKbdIMX->_KbdSymbol).dwCurLabel = 1;
  100. hr = SetCompartmentDWORD(_tid, _tim, GUID_COMPARTMENT_SOFTKBD_KBDLAYOUT, _dwSoftLayout, FALSE);
  101. break;
  102. case KID_LSHFT :
  103. case KID_RSHFT :
  104. _fShift = !_fShift;
  105. if ( _fCaps == _fShift )
  106. // use state 0
  107. (_pSoftKbdIMX->_KbdSymbol).dwCurLabel = 0;
  108. else
  109. // use state 1
  110. (_pSoftKbdIMX->_KbdSymbol).dwCurLabel = 1;
  111. hr = SetCompartmentDWORD(_tid, _tim, GUID_COMPARTMENT_SOFTKBD_KBDLAYOUT, _dwSoftLayout, FALSE);
  112. break;
  113. case KID_F1 :
  114. case KID_F2 :
  115. case KID_F3 :
  116. case KID_F4 :
  117. case KID_F5 :
  118. case KID_F6 :
  119. case KID_F7 :
  120. case KID_F8 :
  121. case KID_F9 :
  122. case KID_F10 :
  123. case KID_F11 :
  124. case KID_F12 :
  125. case KID_TAB :
  126. // simulate a key event and send to system.
  127. case KID_ENTER :
  128. case KID_ESC :
  129. case KID_SPACE :
  130. case KID_BACK :
  131. case KID_UP :
  132. case KID_DOWN :
  133. case KID_LEFT :
  134. case KID_RIGHT :
  135. {
  136. BYTE bVk, bScan;
  137. int j, jIndex;
  138. KEYID keyId;
  139. BOOL fExtendKey, fPictureKey;
  140. keyId = KeySelected;
  141. fPictureKey = FALSE;
  142. for ( j=0; j<NUM_PICTURE_KEYS; j++)
  143. {
  144. if ( gPictureKeys[j].uScanCode == keyId )
  145. {
  146. // This is a picture key.
  147. // it may be a extended key.
  148. jIndex = j;
  149. fPictureKey = TRUE;
  150. break;
  151. }
  152. if ( gPictureKeys[j].uScanCode == 0 )
  153. {
  154. // This is the last item in gPictureKeys.
  155. break;
  156. }
  157. }
  158. fExtendKey = FALSE;
  159. if ( fPictureKey )
  160. {
  161. if ( (keyId & 0xFF00) == 0xE000 )
  162. {
  163. fExtendKey = TRUE;
  164. bScan = (BYTE)(keyId & 0x000000ff);
  165. }
  166. else
  167. bScan = (BYTE)keyId;
  168. bVk = (BYTE)(gPictureKeys[jIndex].uVkey);
  169. }
  170. else
  171. {
  172. bScan = (BYTE)keyId;
  173. bVk = (BYTE)MapVirtualKeyEx((UINT)bScan, 1, 0);
  174. }
  175. if ( fExtendKey )
  176. {
  177. keybd_event(bVk, bScan, (DWORD)KEYEVENTF_EXTENDEDKEY, 0);
  178. keybd_event(bVk, bScan, (DWORD)(KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP), 0);
  179. }
  180. else
  181. {
  182. keybd_event(bVk, bScan, 0, 0);
  183. keybd_event(bVk, bScan, (DWORD)KEYEVENTF_KEYUP, 0);
  184. }
  185. break;
  186. }
  187. default :
  188. if ( lpszLabel == NULL )
  189. {
  190. hr = E_FAIL;
  191. return hr;
  192. }
  193. pic = _pSoftKbdIMX->GetIC( );
  194. if ( pic == NULL )
  195. {
  196. return hr;
  197. }
  198. if (pes = new CEditSession(CSoftkbdIMX::_EditSessionCallback))
  199. {
  200. WCHAR *lpLabel;
  201. int i, iLen;
  202. iLen = (int) wcslen(lpszLabel);
  203. lpLabel = (WCHAR *)cicMemAllocClear((iLen+1)*sizeof(WCHAR));
  204. if ( lpLabel == NULL )
  205. {
  206. // not enough memory.
  207. hr = E_OUTOFMEMORY;
  208. return hr;
  209. }
  210. for ( i=0; i<iLen; i++)
  211. lpLabel[i] = lpszLabel[i];
  212. lpLabel[iLen] = L'\0';
  213. pes->_state.u = ESCB_KEYLABEL;
  214. pes->_state.pv = _pSoftKbdIMX;
  215. pes->_state.wParam = (WPARAM)KeySelected;
  216. pes->_state.lParam = (LPARAM)lpLabel;
  217. pes->_state.pic = pic;
  218. pes->_state.pv1 = NULL;
  219. pic->RequestEditSession(_pSoftKbdIMX->_tid,
  220. pes,
  221. TF_ES_READWRITE,
  222. &hr);
  223. if ( FAILED(hr) )
  224. {
  225. SafeFreePointer(lpLabel);
  226. }
  227. SafeRelease(pes);
  228. }
  229. else
  230. hr = E_FAIL;
  231. SafeRelease(pic);
  232. break;
  233. }
  234. return hr;
  235. }
  236. CSoftKbdWindowEventSink::CSoftKbdWindowEventSink(CSoftkbdIMX *pSoftKbdIMX)
  237. {
  238. _pSoftKbdIMX = pSoftKbdIMX;
  239. _cRef = 1;
  240. }
  241. CSoftKbdWindowEventSink::~CSoftKbdWindowEventSink()
  242. {
  243. }
  244. //+---------------------------------------------------------------------------
  245. //
  246. // IUnknown
  247. //
  248. //----------------------------------------------------------------------------
  249. STDAPI CSoftKbdWindowEventSink::QueryInterface(REFIID riid, void **ppvObj)
  250. {
  251. *ppvObj = NULL;
  252. if (IsEqualIID(riid, IID_IUnknown) ||
  253. IsEqualIID(riid, IID_ISoftKbdWindowEventSink))
  254. {
  255. *ppvObj = SAFECAST(this, CSoftKbdWindowEventSink *);
  256. }
  257. if (*ppvObj)
  258. {
  259. AddRef();
  260. return S_OK;
  261. }
  262. return E_NOINTERFACE;
  263. }
  264. STDAPI_(ULONG) CSoftKbdWindowEventSink::AddRef()
  265. {
  266. return ++_cRef;
  267. }
  268. STDAPI_(ULONG) CSoftKbdWindowEventSink::Release()
  269. {
  270. long cr;
  271. cr = --_cRef;
  272. Assert(cr >= 0);
  273. if (cr == 0)
  274. {
  275. delete this;
  276. }
  277. return cr;
  278. }
  279. //
  280. // ISoftKbdWindowEventSink
  281. //
  282. STDAPI CSoftKbdWindowEventSink::OnWindowClose( )
  283. {
  284. HRESULT hr = S_OK;
  285. if ( _pSoftKbdIMX != NULL )
  286. _pSoftKbdIMX->SetSoftKBDOnOff(FALSE);
  287. return hr;
  288. }
  289. STDAPI CSoftKbdWindowEventSink::OnWindowMove(int xWnd, int yWnd, int width, int height)
  290. {
  291. HRESULT hr = S_OK;
  292. if ( _pSoftKbdIMX != NULL )
  293. _pSoftKbdIMX->SetSoftKBDPosition(xWnd, yWnd);
  294. // support size change later.
  295. UNREFERENCED_PARAMETER(width);
  296. UNREFERENCED_PARAMETER(height);
  297. return hr;
  298. }