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.

300 lines
7.4 KiB

  1. //
  2. // nuiinat.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "nuiinat.h"
  7. #include "tipbar.h"
  8. #include "resource.h"
  9. #include "inatlib.h"
  10. #include "cresstr.h"
  11. extern HINSTANCE g_hInst;
  12. extern CTipbarWnd *g_pTipbarWnd;
  13. const GUID GUID_LBI_INATITEM = { /* cdbc683a-55ce-4717-bac0-50bf44a3270c */
  14. 0xcdbc683a,
  15. 0x55ce,
  16. 0x4717,
  17. {0xba, 0xc0, 0x50, 0xbf, 0x44, 0xa3, 0x27, 0x0c}
  18. };
  19. //+---------------------------------------------------------------------------
  20. //
  21. // GetIconIndexFromhKL
  22. //
  23. //----------------------------------------------------------------------------
  24. ULONG GetIconIndexFromhKL(HKL hKL)
  25. {
  26. BOOL bFound;
  27. int nCnt = TF_MlngInfoCount();
  28. HKL hKLTmp;
  29. int i;
  30. bFound = FALSE;
  31. for (i = 0; i < nCnt; i++)
  32. {
  33. if (!TF_GetMlngHKL(i, &hKLTmp, NULL, 0))
  34. continue;
  35. if (hKL == hKLTmp)
  36. {
  37. bFound = TRUE;
  38. break;
  39. }
  40. }
  41. if (!bFound)
  42. {
  43. i = 0;
  44. if (!TF_GetMlngHKL(0, &hKL, NULL, 0))
  45. return -1;
  46. }
  47. return TF_GetMlngIconIndex(i);
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // GethKLDesc
  52. //
  53. //----------------------------------------------------------------------------
  54. BOOL GethKLDesc(HKL hKL, WCHAR *psz, UINT cch)
  55. {
  56. BOOL bFound;
  57. int nCnt = TF_MlngInfoCount();
  58. HKL hKLTmp;
  59. int i;
  60. bFound = FALSE;
  61. for (i = 0; i < nCnt; i++)
  62. {
  63. if (!TF_GetMlngHKL(i, &hKLTmp, psz, cch))
  64. continue;
  65. if (hKL == hKLTmp)
  66. {
  67. bFound = TRUE;
  68. break;
  69. }
  70. }
  71. if (!bFound)
  72. {
  73. i = 0;
  74. if (TF_GetMlngHKL(0, &hKL, psz, cch))
  75. return TRUE;
  76. }
  77. return bFound ? TRUE : FALSE;
  78. }
  79. //---------------------------------------------------------------------------
  80. //
  81. // GetFontSig()
  82. //
  83. //---------------------------------------------------------------------------
  84. BOOL GetFontSig(HWND hwnd, HKL hKL)
  85. {
  86. LOCALESIGNATURE ls;
  87. BOOL bFontSig = 0;
  88. //
  89. // 4th param is TCHAR count but we call GetLocaleInfoA()
  90. // ~
  91. // so we pass "sizeof(LOCALESIGNATURE) / sizeof(char)".
  92. //
  93. if( GetLocaleInfoA( (DWORD)(LOWORD(hKL)),
  94. LOCALE_FONTSIGNATURE,
  95. (LPSTR)&ls,
  96. sizeof(LOCALESIGNATURE) / sizeof(char)))
  97. {
  98. CHARSETINFO cs;
  99. HDC hdc = GetDC(hwnd);
  100. TranslateCharsetInfo((LPDWORD)UIntToPtr(GetTextCharsetInfo(hdc,NULL,0)),
  101. &cs, TCI_SRCCHARSET);
  102. DWORD fsShell = cs.fs.fsCsb[0];
  103. ReleaseDC(hwnd, hdc);
  104. if (fsShell & ls.lsCsbSupported[0])
  105. bFontSig = 1;
  106. }
  107. return bFontSig;
  108. }
  109. //+---------------------------------------------------------------------------
  110. //
  111. // ctor
  112. //
  113. //----------------------------------------------------------------------------
  114. CLBarInatItem::CLBarInatItem(DWORD dwThreadId)
  115. {
  116. Dbg_MemSetThisName(TEXT("CLBarInatItem"));
  117. InitNuiInfo(CLSID_SYSTEMLANGBARITEM,
  118. GUID_LBI_INATITEM,
  119. TF_LBI_STYLE_BTN_MENU | TF_LBI_STYLE_HIDDENSTATUSCONTROL,
  120. 0,
  121. CRStr(IDS_NUI_LANGUAGE_TEXT));
  122. SetToolTip(CRStr(IDS_NUI_LANGUAGE_TOOLTIP));
  123. _dwThreadId = dwThreadId;
  124. _hKL = GetKeyboardLayout(dwThreadId);
  125. TF_InitMlngInfo();
  126. int nLang = TF_MlngInfoCount();
  127. ShowInternal((nLang > 1), FALSE);
  128. }
  129. //+---------------------------------------------------------------------------
  130. //
  131. // dtor
  132. //
  133. //----------------------------------------------------------------------------
  134. CLBarInatItem::~CLBarInatItem()
  135. {
  136. }
  137. //+---------------------------------------------------------------------------
  138. //
  139. // GetIcon
  140. //
  141. //----------------------------------------------------------------------------
  142. STDAPI CLBarInatItem::GetIcon(HICON *phIcon)
  143. {
  144. ULONG uIconIndex;
  145. HICON hIcon = NULL;
  146. uIconIndex = GetIconIndexFromhKL(_hKL);
  147. if (uIconIndex != -1)
  148. hIcon = TF_InatExtractIcon(uIconIndex);
  149. *phIcon = hIcon;
  150. return S_OK;
  151. }
  152. //+---------------------------------------------------------------------------
  153. //
  154. // GetText
  155. //
  156. //----------------------------------------------------------------------------
  157. STDAPI CLBarInatItem::GetText(BSTR *pbstr)
  158. {
  159. WCHAR szText[NUIBASE_TEXT_MAX];
  160. if (!pbstr)
  161. return E_INVALIDARG;
  162. if (GethKLDesc(_hKL, szText, ARRAYSIZE(szText)))
  163. {
  164. *pbstr = SysAllocString(szText);
  165. return S_OK;
  166. }
  167. return CLBarItemButtonBase::GetText(pbstr);
  168. }
  169. //+---------------------------------------------------------------------------
  170. //
  171. // OnLButtonUpHandler
  172. //
  173. //----------------------------------------------------------------------------
  174. HRESULT CLBarInatItem::OnLButtonUp(const POINT pt, const RECT *prcArea)
  175. {
  176. return S_OK;
  177. }
  178. //+---------------------------------------------------------------------------
  179. //
  180. // InitMenu
  181. //
  182. //----------------------------------------------------------------------------
  183. STDAPI CLBarInatItem::InitMenu(ITfMenu *pMenu)
  184. {
  185. int nLang;
  186. int i;
  187. HKL hkl;
  188. WCHAR szDesc[128];
  189. TF_InitMlngInfo();
  190. nLang = TF_MlngInfoCount();
  191. for (i = 0; i < nLang; i++)
  192. {
  193. if (TF_GetMlngHKL(i, &hkl, szDesc, ARRAYSIZE(szDesc)))
  194. {
  195. ULONG uIconIndex;
  196. HICON hIcon = NULL;
  197. uIconIndex = GetIconIndexFromhKL(hkl);
  198. if (uIconIndex != -1)
  199. hIcon = TF_InatExtractIcon(uIconIndex);
  200. LangBarInsertMenu(pMenu,
  201. i,
  202. szDesc,
  203. hkl == _hKL ? TRUE : FALSE,
  204. hIcon);
  205. }
  206. }
  207. if (g_pTipbarWnd && g_pTipbarWnd->GetLangBarMgr())
  208. {
  209. DWORD dwFlags;
  210. if (SUCCEEDED(g_pTipbarWnd->GetLangBarMgr()->GetShowFloatingStatus(&dwFlags)))
  211. {
  212. if (dwFlags & (TF_SFT_MINIMIZED | TF_SFT_DESKBAND))
  213. {
  214. LangBarInsertSeparator(pMenu);
  215. LangBarInsertMenu(pMenu, IDM_SHOWLANGBARONCMD, CRStr(IDS_RESTORE));
  216. }
  217. }
  218. }
  219. return S_OK;
  220. }
  221. //+---------------------------------------------------------------------------
  222. //
  223. // OnMenuSelect
  224. //
  225. //----------------------------------------------------------------------------
  226. STDAPI CLBarInatItem::OnMenuSelect(UINT uID)
  227. {
  228. HKL hkl;
  229. if (uID == IDM_SHOWLANGBARONCMD)
  230. {
  231. if (g_pTipbarWnd && g_pTipbarWnd->GetLangBarMgr())
  232. g_pTipbarWnd->GetLangBarMgr()->ShowFloating(TF_SFT_SHOWNORMAL);
  233. }
  234. else if (TF_GetMlngHKL(uID, &hkl, NULL, 0))
  235. {
  236. Assert(g_pTipbarWnd);
  237. if (!g_pTipbarWnd->IsInDeskBand())
  238. g_pTipbarWnd->RestoreLastFocus(NULL, FALSE);
  239. else
  240. g_pTipbarWnd->RestoreLastFocus(NULL, TRUE);
  241. HWND hwndFore = GetForegroundWindow();
  242. if (_dwThreadId == GetWindowThreadProcessId(hwndFore, NULL))
  243. {
  244. BOOL bFontSig = GetFontSig(hwndFore, hkl);
  245. PostMessage(hwndFore,
  246. WM_INPUTLANGCHANGEREQUEST,
  247. (WPARAM)bFontSig,
  248. (LPARAM)hkl);
  249. }
  250. }
  251. return S_OK;
  252. }