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.

424 lines
13 KiB

  1. /****************************************************************************
  2. SOFTKBD.CPP :
  3. History:
  4. 19-SEP-2000 CSLim Created
  5. ****************************************************************************/
  6. #include "private.h"
  7. #include "globals.h"
  8. #include "korimx.h"
  9. #include "softkbd.h"
  10. #include "skbdkor.h"
  11. #include "softkbdes.h"
  12. #include "gdata.h"
  13. #include "helpers.h"
  14. PICTUREKEY gPictureKeys[NUM_PICTURE_KEYS+1] =
  15. {
  16. // uScanCode, uVKey
  17. { KID_LWINLOGO, VK_LWIN },
  18. { KID_RWINLOGO, VK_RWIN },
  19. { KID_APPS, VK_APPS },
  20. { KID_LEFT, VK_LEFT },
  21. { KID_RIGHT, VK_RIGHT },
  22. { KID_UP, VK_UP },
  23. { KID_DOWN, VK_DOWN },
  24. { KID_ESC, VK_ESCAPE },
  25. { KID_BACK, VK_BACK },
  26. { KID_TAB, VK_TAB },
  27. { KID_CAPS, VK_CAPITAL },
  28. { KID_ENTER, VK_RETURN },
  29. { KID_LSHFT, VK_SHIFT },
  30. { KID_RSHFT, VK_SHIFT },
  31. { KID_CTRL, VK_CONTROL },
  32. { KID_RCTRL, VK_CONTROL },
  33. { KID_ALT, VK_MENU },
  34. { KID_RALT, VK_RMENU },
  35. { KID_DELETE, VK_DELETE },
  36. { 0,0 }
  37. };
  38. /*---------------------------------------------------------------------------
  39. CKorIMX::InitializeSoftKbd
  40. ---------------------------------------------------------------------------*/
  41. HRESULT CKorIMX::InitializeSoftKbd()
  42. {
  43. DWORD dwFileLen;
  44. WCHAR wszModuleFile[MAX_PATH];
  45. CHAR szModuleFile[MAX_PATH];
  46. INT wScreenWidth, wScreenHeight;
  47. INT left, top, width, height;
  48. RECT rcWork;
  49. CIMEData ImeData;
  50. UINT uiCurBeolSik;
  51. // SKD resoulrce ID string
  52. static LPWSTR rgwzKorXMLResStr[3] = { L"IDSKD_2BEOLSIK", L"IDSKD_3BEOLSIK390", L"IDSKD_3BEOLSIKFINAL" };
  53. HRESULT hr;
  54. // if Already initialized
  55. if (m_fSoftKbdEnabled)
  56. return S_OK;
  57. // Create SoftKbd object
  58. hr = CoCreateInstance(CLSID_SoftKbd, NULL, CLSCTX_INPROC_SERVER, IID_ISoftKbd, (void**)&m_pSoftKbd);
  59. if (FAILED(hr))
  60. {
  61. // assert(0);
  62. return hr;
  63. }
  64. m_pSoftKbd->Initialize();
  65. // initialize Standard soft layout and Symbol Soft Layout.
  66. m_KbdStandard.dwSoftKbdLayout = SOFTKBD_US_STANDARD;
  67. m_KbdStandard.fStandard = TRUE;
  68. m_KbdStandard.dwNumLabels = 0; // for standard, this field is not really used.
  69. m_KbdStandard.dwCurLabel = 0;
  70. m_KbdStandard.pskbdes = NULL; // standard layout doesn't supply sftkbd event sink.
  71. m_KbdStandard.dwSkbdESCookie = 0;
  72. // Get current user selection
  73. uiCurBeolSik = ImeData.GetCurrentBeolsik();
  74. // US Standard layout
  75. m_KbdHangul.fStandard = fFalse;
  76. m_KbdHangul.dwNumLabels = 2;
  77. m_KbdHangul.dwCurLabel = 0;
  78. // Load Keyboard layout file from resource
  79. dwFileLen = GetModuleFileNameA(g_hInst, szModuleFile, MAX_PATH);
  80. if (dwFileLen == 0)
  81. {
  82. hr = E_FAIL;
  83. goto Exit3;
  84. }
  85. MultiByteToWideChar(CP_ACP, 0, szModuleFile, -1, wszModuleFile, MAX_PATH);
  86. hr = m_pSoftKbd->CreateSoftKeyboardLayoutFromResource(wszModuleFile, L"SKDFILE", rgwzKorXMLResStr[uiCurBeolSik],
  87. &(m_KbdHangul.dwSoftKbdLayout));
  88. if (FAILED(hr))
  89. goto Exit3;
  90. // Create ISoftKeyboardEventSink for Hangul layout
  91. m_KbdHangul.pskbdes = new CSoftKeyboardEventSink(this, m_KbdHangul.dwSoftKbdLayout);
  92. if (m_KbdHangul.pskbdes == NULL )
  93. {
  94. hr = E_FAIL;
  95. goto Exit3;
  96. }
  97. hr = m_pSoftKbd->AdviseSoftKeyboardEventSink(m_KbdHangul.dwSoftKbdLayout,
  98. IID_ISoftKeyboardEventSink,
  99. m_KbdHangul.pskbdes,
  100. &(m_KbdHangul.dwSkbdESCookie));
  101. if (FAILED(hr))
  102. goto Exit2;
  103. m_psftkbdwndes = new CSoftKbdWindowEventSink(this);
  104. if (m_psftkbdwndes == NULL)
  105. {
  106. hr = E_FAIL;
  107. goto Exit2;
  108. }
  109. // To handle softkbd window Open/Close event
  110. hr = m_pSoftKbd->AdviseSoftKeyboardEventSink(0, IID_ISoftKbdWindowEventSink, m_psftkbdwndes, &m_dwSftKbdwndesCookie);
  111. if (FAILED(hr))
  112. goto Exit1;
  113. width = 400;
  114. height = 172;
  115. if (FAILED(GetSoftKBDPosition(&left, &top)))
  116. {
  117. // the compartment is not initialize.
  118. SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0 );
  119. wScreenWidth = (INT)(rcWork.right - rcWork.left + 1);
  120. wScreenHeight = (INT)(rcWork.bottom - rcWork.top + 1);
  121. left = wScreenWidth - width -2;
  122. top = wScreenHeight - height - 1;
  123. }
  124. hr = m_pSoftKbd->CreateSoftKeyboardWindow(m_hOwnerWnd,TITLEBAR_GRIPPER_BUTTON, left, top, width, height);
  125. if (FAILED(hr))
  126. goto Exit;
  127. SetSoftKBDPosition(left, top);
  128. m_fSoftKbdEnabled = fTrue;
  129. return hr;
  130. // Error handling
  131. Exit:
  132. delete m_psftkbdwndes;
  133. m_psftkbdwndes = 0;
  134. Exit1:
  135. m_pSoftKbd->UnadviseSoftKeyboardEventSink(m_dwSftKbdwndesCookie);
  136. Exit2:
  137. delete m_KbdHangul.pskbdes;
  138. m_KbdHangul.pskbdes = NULL;
  139. Exit3:
  140. SafeReleaseClear(m_pSoftKbd);
  141. return hr;
  142. }
  143. /*---------------------------------------------------------------------------
  144. CKorIMX::TerminateSoftKbd
  145. ---------------------------------------------------------------------------*/
  146. void CKorIMX::TerminateSoftKbd()
  147. {
  148. SetSoftKBDOnOff(fFalse);
  149. if (m_pSoftKbd)
  150. m_pSoftKbd->DestroySoftKeyboardWindow();
  151. m_fSoftKbdEnabled = fFalse;
  152. if (m_pSoftKbd)
  153. {
  154. if (m_KbdHangul.pskbdes)
  155. {
  156. m_pSoftKbd->UnadviseSoftKeyboardEventSink(m_KbdHangul.dwSkbdESCookie);
  157. delete m_KbdHangul.pskbdes;
  158. }
  159. m_pSoftKbd->UnadviseSoftKeyboardEventSink(m_dwSftKbdwndesCookie);
  160. delete m_psftkbdwndes;
  161. m_psftkbdwndes = 0;
  162. SafeReleaseClear(m_pSoftKbd);
  163. }
  164. }
  165. #if 0
  166. /*---------------------------------------------------------------------------
  167. CKorIMX::ToggleSoftKbd
  168. ---------------------------------------------------------------------------*/
  169. void CKorIMX::ToggleSoftKbd()
  170. {
  171. if (m_fSoftKbdEnabled)
  172. TerminateSoftKbd();
  173. else
  174. InitializeSoftKbd();
  175. }
  176. /*---------------------------------------------------------------------------
  177. CKorIMX::OnActivatedSoftKbd
  178. ---------------------------------------------------------------------------*/
  179. void CKorIMX::OnActivatedSoftKbd(BOOl fActivated)
  180. {
  181. if (fActivated)
  182. {
  183. if (GetSoftKBDOnOff())
  184. m_pSoftKbd->ShowSoftKBDWindow(fTrue);
  185. }
  186. else
  187. {
  188. if (GetSoftKBDOnOff())
  189. m_pSoftKbd->ShowSoftKeyboard(fFalse);
  190. }
  191. }
  192. #endif
  193. /*---------------------------------------------------------------------------
  194. CKorIMX::ShowSoftKBDWindow
  195. Show or Hide the soft keyboard window based on current setting.
  196. ---------------------------------------------------------------------------*/
  197. HRESULT CKorIMX::ShowSoftKBDWindow(BOOL fShow)
  198. {
  199. HRESULT hr = S_OK;
  200. // call the initialize function to get the ISoftKbd.
  201. if (fShow && m_fSoftKbdEnabled == fFalse)
  202. InitializeSoftKbd( );
  203. if (m_pSoftKbd == NULL)
  204. return E_FAIL;
  205. if (fShow)
  206. {
  207. //DWORD dwSoftLayout;
  208. if ((GetConvMode(GetIC()) & TIP_HANGUL_MODE) == 0)
  209. {
  210. // m_KbdStandard.dwSoftKbdLayout = SOFTKBD_US_STANDARD;
  211. // if (FAILED(hr))
  212. // return hr;
  213. // dwSoftLayout = m_KbdStandard.dwSoftKbdLayout;
  214. // _CurLayout = m_KbdStandard.dwSoftKbdLayout;
  215. hr = m_pSoftKbd->SelectSoftKeyboard(m_KbdStandard.dwSoftKbdLayout);
  216. if (FAILED(hr))
  217. return hr;
  218. m_pSoftKbd->SetKeyboardLabelText(GetKeyboardLayout(0));
  219. if (FAILED(hr))
  220. return hr;
  221. }
  222. else
  223. {
  224. hr = m_pSoftKbd->SelectSoftKeyboard(m_KbdHangul.dwSoftKbdLayout);
  225. if (FAILED(hr))
  226. return hr;
  227. m_pSoftKbd->SetKeyboardLabelTextCombination(m_KbdHangul.dwCurLabel);
  228. if (FAILED(hr))
  229. return hr;
  230. }
  231. hr = m_pSoftKbd->ShowSoftKeyboard(fTrue);
  232. if (FAILED(hr))
  233. return hr;
  234. }
  235. else
  236. {
  237. m_pSoftKbd->ShowSoftKeyboard(fFalse);
  238. }
  239. #if 0
  240. if ( _CurKbdType == KBDTYPE_STANDARD )
  241. {
  242. // Standard soft kbd was selected.
  243. WORD prmlangid;
  244. prmlangid = PRIMARYLANGID(_langid);
  245. switch ( prmlangid ) {
  246. case LANG_JAPANESE :
  247. // Lang JPN is activated.
  248. // select the standard layout to J 106-k.
  249. _KbdStandard.dwSoftKbdLayout = SOFTKBD_JPN_STANDARD;
  250. break;
  251. case LANG_AZERI :
  252. case LANG_BELARUSIAN :
  253. case LANG_CHINESE :
  254. case LANG_KOREAN :
  255. case LANG_RUSSIAN :
  256. case LANG_THAI :
  257. case LANG_URDU :
  258. case LANG_UZBEK :
  259. _KbdStandard.dwSoftKbdLayout = SOFTKBD_US_STANDARD;
  260. break;
  261. case LANG_ENGLISH :
  262. if ( SUBLANGID(_langid) != SUBLANG_ENGLISH_US )
  263. _KbdStandard.dwSoftKbdLayout = SOFTKBD_EURO_STANDARD;
  264. else
  265. _KbdStandard.dwSoftKbdLayout = SOFTKBD_US_STANDARD;
  266. break;
  267. default :
  268. _KbdStandard.dwSoftKbdLayout = SOFTKBD_EURO_STANDARD;
  269. break;
  270. }
  271. // the current layout is standard layout.
  272. // we need to set the correct standard layout id based on current lang profile.
  273. dwSoftLayout = _KbdStandard.dwSoftKbdLayout;
  274. _CurLayout = dwSoftLayout;
  275. CHECKHR(_SoftKbd->SelectSoftKeyboard(dwSoftLayout));
  276. CHECKHR(_SoftKbd->SetKeyboardLabelText(GetKeyboardLayout(0)));
  277. }
  278. else if ( _CurKbdType == KBDTYPE_SYMBOL)
  279. {
  280. // This is symbol soft keyboard layout
  281. //
  282. DWORD dwCurLabel;
  283. dwSoftLayout = _KbdSymbol.dwSoftKbdLayout;
  284. dwCurLabel = _KbdSymbol.dwCurLabel;
  285. CHECKHR(_SoftKbd->SelectSoftKeyboard(dwSoftLayout));
  286. CHECKHR(_SoftKbd->SetKeyboardLabelTextCombination(dwCurLabel));
  287. }
  288. // TIP is ON, so we need to show soft keyboard.
  289. CHECKHR(_SoftKbd->ShowSoftKeyboard(TRUE));
  290. }
  291. else
  292. {
  293. // TIP is going to close.
  294. // close the soft keyboard window also.
  295. CHECKHR(_SoftKbd->ShowSoftKeyboard(FALSE));
  296. }
  297. CleanUp:
  298. #endif
  299. return hr;
  300. }
  301. /*---------------------------------------------------------------------------
  302. CKorIMX::SoftKbdOnThreadFocusChange
  303. ---------------------------------------------------------------------------*/
  304. void CKorIMX::SoftKbdOnThreadFocusChange(BOOL fSet)
  305. {
  306. if (fSet)
  307. {
  308. // Restore the ON/OFF status before KillThreadFocus( )
  309. if (m_pSoftKbd)
  310. {
  311. if (m_fSoftKbdOnOffSave)
  312. {
  313. // adjust the window position.
  314. int xWnd, yWnd;
  315. WORD width=0, height=0;
  316. POINT OldPoint;
  317. HRESULT hr;
  318. m_pSoftKbd->GetSoftKeyboardPosSize(&OldPoint, &width, &height);
  319. hr = GetSoftKBDPosition(&xWnd, &yWnd);
  320. if (hr == S_OK)
  321. {
  322. if ((xWnd != OldPoint.x) || (yWnd != OldPoint.y))
  323. {
  324. POINT NewPoint;
  325. NewPoint.x = xWnd;
  326. NewPoint.y = yWnd;
  327. m_pSoftKbd->SetSoftKeyboardPosSize(NewPoint, width, height);
  328. }
  329. }
  330. ShowSoftKBDWindow(fTrue);
  331. }
  332. else
  333. m_pSoftKbd->ShowSoftKeyboard(fFalse);
  334. }
  335. }
  336. else
  337. {
  338. // keep the ON/OFF status so that OnSetThreadFocus( ) can restore it later
  339. m_fSoftKbdOnOffSave = GetSoftKBDOnOff();
  340. if (m_pSoftKbd)
  341. m_pSoftKbd->ShowSoftKeyboard(fFalse);
  342. // release all the modifier keys except lock keys. that is , Shift, Alt, Ctrl,
  343. keybd_event((BYTE)VK_SHIFT, (BYTE)KID_LSHFT, (DWORD)KEYEVENTF_KEYUP, 0);
  344. keybd_event((BYTE)VK_MENU, (BYTE)KID_ALT, (DWORD)KEYEVENTF_KEYUP, 0);
  345. keybd_event((BYTE)VK_LMENU, (BYTE)KID_ALT, (DWORD)KEYEVENTF_KEYUP, 0);
  346. keybd_event((BYTE)VK_RMENU, (BYTE)KID_RALT, (DWORD)KEYEVENTF_KEYUP, 0);
  347. keybd_event((BYTE)VK_CONTROL, (BYTE)KID_CTRL, (DWORD)KEYEVENTF_KEYUP, 0);
  348. }
  349. }