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.

640 lines
16 KiB

  1. //depot/Lab06_N/windows/AdvCore/ctf/uim/nuictrl.cpp#50 - edit change 9353 (text)
  2. //
  3. // nui.cpp
  4. //
  5. #include "private.h"
  6. #include "globals.h"
  7. #include "nuictrl.h"
  8. #include "xstring.h"
  9. #include "immxutil.h"
  10. #include "tim.h"
  11. #include "profiles.h"
  12. #include "ctffunc.h"
  13. #include "slbarid.h"
  14. #include "cregkey.h"
  15. #include "cmydc.h"
  16. #include "nuihkl.h"
  17. #include "cresstr.h"
  18. #include "slbarid.h"
  19. #include "iconlib.h"
  20. DBG_ID_INSTANCE(CLBarItemCtrl);
  21. DBG_ID_INSTANCE(CLBarItemHelp);
  22. #define SHOW_BRANDINGICON 1
  23. //---------------------------------------------------------------------------
  24. //
  25. // TF_RunInputCPL
  26. //
  27. //---------------------------------------------------------------------------
  28. HRESULT WINAPI TF_RunInputCPL()
  29. {
  30. CicSystemModulePath fullpath;
  31. TCHAR szRunInputCPLCmd[MAX_PATH * 2];
  32. UINT uLen = 0;
  33. HRESULT hr = E_FAIL;
  34. if (IsOnNT51())
  35. fullpath.Init(c_szRunInputCPLOnNT51);
  36. else if (IsOn98() || IsOn95())
  37. fullpath.Init(c_szRunInputCPLOnWin9x);
  38. else
  39. fullpath.Init(c_szRunInputCPL);
  40. if (!fullpath.GetLength())
  41. return hr;
  42. StringCchPrintf(szRunInputCPLCmd,
  43. ARRAYSIZE(szRunInputCPLCmd),
  44. c_szRunInputCPLCmdLine,
  45. fullpath.GetPath());
  46. if (RunCPLSetting(szRunInputCPLCmd))
  47. hr = S_OK;
  48. return hr;
  49. }
  50. //////////////////////////////////////////////////////////////////////////////
  51. //
  52. // CLBarItemCtrl
  53. //
  54. //////////////////////////////////////////////////////////////////////////////
  55. //+---------------------------------------------------------------------------
  56. //
  57. // ctor
  58. //
  59. //----------------------------------------------------------------------------
  60. CLBarItemCtrl::CLBarItemCtrl(SYSTHREAD *psfn) : CSysThreadRef(psfn)
  61. {
  62. Dbg_MemSetThisNameID(TEXT("CLBarItemCtrl"));
  63. InitNuiInfo(CLSID_SYSTEMLANGBARITEM,
  64. GUID_LBI_CTRL,
  65. TF_LBI_STYLE_BTN_MENU |
  66. TF_LBI_STYLE_HIDDENSTATUSCONTROL |
  67. TF_LBI_STYLE_SHOWNINTRAY,
  68. 0,
  69. CRStr(IDS_NUI_LANGUAGE_TEXT));
  70. SetToolTip(CRStr(IDS_NUI_LANGUAGE_TOOLTIP));
  71. _meEto = 0;
  72. _Init();
  73. }
  74. //+---------------------------------------------------------------------------
  75. //
  76. // dtor
  77. //
  78. //----------------------------------------------------------------------------
  79. CLBarItemCtrl::~CLBarItemCtrl()
  80. {
  81. HICON hIcon = GetIcon();
  82. SetIcon(NULL);
  83. if (hIcon)
  84. DestroyIcon(hIcon);
  85. }
  86. //----------------------------------------------------------------------------
  87. //
  88. // Init
  89. //
  90. //----------------------------------------------------------------------------
  91. #define NLS_RESOURCE_LOCALE_KEY TEXT("Control Panel\\desktop\\ResourceLocale")
  92. void CLBarItemCtrl::_Init()
  93. {
  94. if (GetSystemMetrics(SM_MIDEASTENABLED))
  95. {
  96. char sz[10];
  97. long cb = sizeof(sz);
  98. //
  99. // as we are releasing an enabled version, we need to check the
  100. // resource locale as well.
  101. //
  102. sz[0] = '\0';
  103. if( RegQueryValue( HKEY_CURRENT_USER,
  104. NLS_RESOURCE_LOCALE_KEY, sz, &cb) == ERROR_SUCCESS)
  105. if ((cb == 9) &&
  106. (sz[6] == '0') &&
  107. ((sz[7] == '1') || (sz[7] == 'd') || (sz[7] == 'D')))
  108. _meEto = ETO_RTLREADING;
  109. }
  110. TF_InitMlngInfo();
  111. _AsmListUpdated(FALSE);
  112. }
  113. //+---------------------------------------------------------------------------
  114. //
  115. // InitMenu
  116. //
  117. //----------------------------------------------------------------------------
  118. STDAPI CLBarItemCtrl::InitMenu(ITfMenu *pMenu)
  119. {
  120. CThreadInputMgr *ptim;
  121. CAssemblyList *pAsmList;
  122. int i;
  123. int nCnt;
  124. INT cxSmIcon;
  125. INT cySmIcon;
  126. LOGFONT lf;
  127. int nMenuFontHeight;
  128. cxSmIcon = cySmIcon = GetMenuIconHeight(&nMenuFontHeight);
  129. if( !SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0))
  130. return E_FAIL;
  131. lf.lfHeight = nMenuFontHeight;
  132. lf.lfWidth = 0;
  133. lf.lfWeight = FW_NORMAL;
  134. if ((pAsmList = EnsureAssemblyList(_psfn)) == NULL)
  135. return E_FAIL;
  136. nCnt = pAsmList->Count();
  137. Assert(nCnt > 0);
  138. ptim = CThreadInputMgr::_GetThisFromSYSTHREAD(_psfn);
  139. for (i = 0; i < nCnt; i++)
  140. {
  141. CAssembly *pAsm = pAsmList->GetAssembly(i);
  142. if (pAsm->IsEnabled(_psfn))
  143. {
  144. BOOL bChecked = (pAsm->GetLangId() == GetCurrentAssemblyLangId(_psfn));
  145. HICON hIcon = InatCreateIconBySize(pAsm->GetLangId(), cxSmIcon, cySmIcon, &lf);
  146. HBITMAP hbmp = NULL;
  147. HBITMAP hbmpMask = NULL;
  148. if (hIcon)
  149. {
  150. SIZE size = {cxSmIcon, cySmIcon};
  151. if (!GetIconBitmaps(hIcon, &hbmp, &hbmpMask, &size))
  152. return E_FAIL;
  153. if (hIcon)
  154. DestroyIcon(hIcon);
  155. }
  156. pMenu->AddMenuItem(IDM_ASM_MENU_START + i,
  157. bChecked ? TF_LBMENUF_CHECKED : 0,
  158. hbmp,
  159. hbmpMask,
  160. pAsm->GetLangName(),
  161. wcslen(pAsm->GetLangName()),
  162. NULL);
  163. }
  164. }
  165. DWORD dwFlags;
  166. if (SUCCEEDED(CLangBarMgr::s_GetShowFloatingStatus(&dwFlags)))
  167. {
  168. if (dwFlags & (TF_SFT_MINIMIZED | TF_SFT_DESKBAND))
  169. {
  170. LangBarInsertSeparator(pMenu);
  171. LangBarInsertMenu(pMenu, IDM_SHOWLANGBAR, CRStr(IDS_SHOWLANGBAR));
  172. #if 0
  173. if (dwFlags & TF_SFT_EXTRAICONSONMINIMIZED)
  174. LangBarInsertMenu(pMenu,
  175. IDM_NONOTIFICATIONICONS,
  176. CRStr(IDS_NOTIFICATIONICONS),
  177. TRUE);
  178. else
  179. LangBarInsertMenu(pMenu,
  180. IDM_NOTIFICATIONICONS,
  181. CRStr(IDS_NOTIFICATIONICONS),
  182. FALSE);
  183. LangBarInsertMenu(pMenu, IDM_SHOWINPUTCPL, CRStr(IDS_SHOWINPUTCPL));
  184. #endif
  185. }
  186. }
  187. return S_OK;
  188. }
  189. //+---------------------------------------------------------------------------
  190. //
  191. // OnMenuSelect
  192. //
  193. //----------------------------------------------------------------------------
  194. STDAPI CLBarItemCtrl::OnMenuSelect(UINT uID)
  195. {
  196. CAssemblyList *pAsmList = EnsureAssemblyList(_psfn);
  197. switch (uID)
  198. {
  199. case IDM_SHOWLANGBAR:
  200. CLangBarMgr::s_ShowFloating(TF_SFT_SHOWNORMAL);
  201. break;
  202. case IDM_NOTIFICATIONICONS:
  203. CLangBarMgr::s_ShowFloating(TF_SFT_EXTRAICONSONMINIMIZED);
  204. break;
  205. case IDM_NONOTIFICATIONICONS:
  206. CLangBarMgr::s_ShowFloating(TF_SFT_NOEXTRAICONSONMINIMIZED);
  207. break;
  208. case IDM_SHOWINPUTCPL:
  209. TF_RunInputCPL();
  210. break;
  211. default:
  212. if (uID >= IDM_ASM_MENU_START)
  213. {
  214. Assert((uID - IDM_ASM_MENU_START) < (UINT)pAsmList->Count());
  215. CAssembly *pAsm = pAsmList->GetAssembly(uID - IDM_ASM_MENU_START);
  216. if (pAsm && (pAsm->GetLangId() != GetCurrentAssemblyLangId(_psfn)))
  217. ActivateAssembly(pAsm->GetLangId(), ACTASM_NONE);
  218. }
  219. break;
  220. }
  221. return S_OK;
  222. }
  223. //+---------------------------------------------------------------------------
  224. //
  225. // OnShellLanguage
  226. //
  227. //----------------------------------------------------------------------------
  228. void CLBarItemCtrl::OnShellLanguage(HKL hKL)
  229. {
  230. _UpdateLangIcon(hKL, FALSE);
  231. }
  232. //+---------------------------------------------------------------------------
  233. //
  234. // UpdateLangIcon
  235. //
  236. //----------------------------------------------------------------------------
  237. void CLBarItemCtrl::_UpdateLangIcon(HKL hKL, BOOL fNotify)
  238. {
  239. CLBarItemDeviceType *plbiDT = NULL;
  240. BOOL fIsPureIME;
  241. CThreadInputMgr *ptim;
  242. int nCnt;
  243. int i;
  244. if (!hKL)
  245. hKL = GetKeyboardLayout(NULL);
  246. _UpdateLangIconForCic(fNotify);
  247. ptim = CThreadInputMgr::_GetThisFromSYSTHREAD(_psfn);
  248. if (ptim && ptim->_GetFocusDocInputMgr())
  249. {
  250. CAssembly *pAsm = GetCurrentAssembly(_psfn);
  251. if (!pAsm)
  252. return;
  253. fIsPureIME = pAsm->IsFEIMEActive();
  254. }
  255. else
  256. {
  257. fIsPureIME = IsPureIMEHKL(hKL);
  258. }
  259. if (fIsPureIME)
  260. {
  261. if (_psfn->plbim != NULL)
  262. {
  263. _psfn->plbim->_AddWin32IMECtrl(fNotify);
  264. }
  265. }
  266. else
  267. {
  268. if (_psfn->plbim != NULL)
  269. {
  270. _psfn->plbim->_RemoveWin32IMECtrl();
  271. }
  272. }
  273. #ifdef SHOW_BRANDINGICON
  274. if (_psfn->plbim && _psfn->plbim->_GetLBarItemDeviceTypeArray())
  275. {
  276. nCnt = _psfn->plbim->_GetLBarItemDeviceTypeArray()->Count();
  277. for (i = 0; i < nCnt; i++)
  278. {
  279. plbiDT = _psfn->plbim->_GetLBarItemDeviceTypeArray()->Get(i);
  280. if (!plbiDT)
  281. continue;
  282. if (plbiDT->IsKeyboardType())
  283. {
  284. plbiDT->SetBrandingIcon(hKL, fNotify);
  285. break;
  286. }
  287. }
  288. }
  289. #endif SHOW_BRANDINGICON
  290. if (fNotify && _plbiSink)
  291. _plbiSink->OnUpdate(TF_LBI_ICON);
  292. }
  293. //+---------------------------------------------------------------------------
  294. //
  295. // AsmListUpdated
  296. //
  297. //----------------------------------------------------------------------------
  298. void CLBarItemCtrl::_AsmListUpdated(BOOL fNotify)
  299. {
  300. CAssemblyList *pAsmList;
  301. int i;
  302. int nCntShowInMenu = 0;
  303. int nCnt;
  304. if ((pAsmList = EnsureAssemblyList(_psfn)) == NULL)
  305. return;
  306. nCnt = pAsmList->Count();
  307. Assert(nCnt > 0);
  308. for (i = 0; i < nCnt; i++)
  309. {
  310. CAssembly *pAsm = pAsmList->GetAssembly(i);
  311. if (pAsm->IsEnabled(_psfn))
  312. {
  313. nCntShowInMenu++;
  314. }
  315. }
  316. ShowInternal((nCntShowInMenu > 1), fNotify);
  317. }
  318. //+---------------------------------------------------------------------------
  319. //
  320. // UpdateLangIconForCic
  321. //
  322. //----------------------------------------------------------------------------
  323. void CLBarItemCtrl::_UpdateLangIconForCic(BOOL fNotify)
  324. {
  325. HICON hIcon;
  326. LANGID langid = GetCurrentAssemblyLangId(_psfn);
  327. if (langid == _langidForIcon)
  328. return;
  329. _langidForIcon = langid;
  330. hIcon = GetIcon();
  331. SetIcon(NULL);
  332. if (hIcon)
  333. DestroyIcon(hIcon);
  334. hIcon = InatCreateIcon(_langidForIcon);
  335. SetIcon(hIcon);
  336. if (hIcon)
  337. {
  338. CAssembly *pAsm = GetCurrentAssembly(_psfn);
  339. if (pAsm != NULL)
  340. {
  341. SetToolTip(pAsm->GetLangName());
  342. SetText(pAsm->GetLangName());
  343. }
  344. }
  345. if (fNotify && _plbiSink)
  346. _plbiSink->OnUpdate(TF_LBI_ICON | TF_LBI_TEXT | TF_LBI_TOOLTIP);
  347. }
  348. //+---------------------------------------------------------------------------
  349. //
  350. // OnSysColorChanged
  351. //
  352. //----------------------------------------------------------------------------
  353. void CLBarItemCtrl::OnSysColorChanged()
  354. {
  355. HICON hIcon = GetIcon();
  356. SetIcon(NULL);
  357. if (hIcon)
  358. DestroyIcon(hIcon);
  359. hIcon = InatCreateIcon(_langidForIcon);
  360. SetIcon(hIcon);
  361. #ifdef WHISTLER_LATER
  362. if (_plbiSink && GetFocus())
  363. _plbiSink->OnUpdate(TF_LBI_ICON);
  364. #endif
  365. }
  366. //////////////////////////////////////////////////////////////////////////////
  367. //
  368. // CLBarItemHelp
  369. //
  370. //////////////////////////////////////////////////////////////////////////////
  371. //+---------------------------------------------------------------------------
  372. //
  373. // ctor
  374. //
  375. //----------------------------------------------------------------------------
  376. CLBarItemHelp::CLBarItemHelp(SYSTHREAD *psfn) : CLBarItemSystemButtonBase(psfn)
  377. {
  378. Dbg_MemSetThisNameID(TEXT("CLBarItemHelp"));
  379. InitNuiInfo(CLSID_SYSTEMLANGBARITEM2,
  380. GUID_LBI_HELP,
  381. TF_LBI_STYLE_BTN_MENU |
  382. // TF_LBI_STYLE_HIDDENSTATUSCONTROL |
  383. TF_LBI_STYLE_HIDEONNOOTHERITEMS,
  384. HELPBTN_ORDER,
  385. CRStr(IDS_IMEHELP));
  386. SetToolTip(CRStr(IDS_NUI_HELP));
  387. if (!IsInteractiveUserLogon())
  388. SetStatusInternal(TF_LBI_STATUS_DISABLED);
  389. }
  390. //+---------------------------------------------------------------------------
  391. //
  392. // InitMenu
  393. //
  394. //----------------------------------------------------------------------------
  395. STDAPI CLBarItemHelp::InitMenu(ITfMenu *pMenu)
  396. {
  397. int nCnt = 0;
  398. CThreadInputMgr *ptim;
  399. UINT nTipCurMenuID = IDM_CUSTOM_MENU_START;
  400. ptim = _psfn->ptim;
  401. if (!_InsertCustomMenus(pMenu, &nTipCurMenuID))
  402. goto InsertSysHelpItem;
  403. //
  404. // Insert separator.
  405. //
  406. if (nTipCurMenuID > IDM_CUSTOM_MENU_START)
  407. LangBarInsertSeparator(pMenu);
  408. if (ptim && ptim->_GetFocusDocInputMgr())
  409. {
  410. int i = 0;
  411. BOOL fInsert = FALSE;
  412. nCnt = ptim->_GetTIPCount();
  413. for (i = 0; i < nCnt; i++)
  414. {
  415. const CTip *ptip = ptim->_GetCTip(i);
  416. ITfFnShowHelp *phelp;
  417. if (nCnt >= IDM_CUSTOM_MENU_START)
  418. {
  419. Assert(0);
  420. break;
  421. }
  422. if (!ptip->_pFuncProvider)
  423. continue;
  424. if (SUCCEEDED(ptip->_pFuncProvider->GetFunction(GUID_NULL,
  425. IID_ITfFnShowHelp,
  426. (IUnknown **)&phelp)))
  427. {
  428. BSTR bstr;
  429. if (SUCCEEDED(phelp->GetDisplayName(&bstr)))
  430. {
  431. LangBarInsertMenu(pMenu, i, bstr, FALSE);
  432. fInsert = TRUE;
  433. SysFreeString(bstr);
  434. }
  435. phelp->Release();
  436. }
  437. }
  438. if (fInsert)
  439. LangBarInsertSeparator(pMenu);
  440. }
  441. InsertSysHelpItem:
  442. LangBarInsertMenu(pMenu, nCnt, CRStr(IDS_LANGBARHELP), FALSE);
  443. return S_OK;
  444. }
  445. //+---------------------------------------------------------------------------
  446. //
  447. // OnMenuSelect
  448. //
  449. //----------------------------------------------------------------------------
  450. STDAPI CLBarItemHelp::OnMenuSelect(UINT uID)
  451. {
  452. HRESULT hr = E_FAIL;
  453. CThreadInputMgr *ptim = CThreadInputMgr::_GetThis();
  454. UINT ulCnt = 0;
  455. if (ptim)
  456. ulCnt = ptim->_GetTIPCount();
  457. if (uID >= IDM_CUSTOM_MENU_START)
  458. {
  459. int nMenuMapoCnt = _pMenuMap->Count();
  460. int i;
  461. for (i = 0; i < nMenuMapoCnt; i++)
  462. {
  463. TIPMENUITEMMAP *ptmm;
  464. ptmm = _pMenuMap->GetPtr(i);
  465. if (ptmm->nTmpID == (UINT)uID)
  466. {
  467. hr = ptmm->plbSink->OnMenuSelect(ptmm->nOrgID);
  468. break;
  469. }
  470. }
  471. }
  472. else if (uID > ulCnt)
  473. {
  474. hr = E_UNEXPECTED;
  475. }
  476. else if (uID == ulCnt)
  477. {
  478. //
  479. // show Langbar help
  480. //
  481. InvokeCicHelp();
  482. hr = S_OK;
  483. }
  484. else
  485. {
  486. Assert(ptim);
  487. const CTip *ptip = ptim->_GetCTip(uID);
  488. if (ptip->_pFuncProvider)
  489. {
  490. ITfFnShowHelp *phelp;
  491. if (SUCCEEDED(ptip->_pFuncProvider->GetFunction(GUID_NULL,
  492. IID_ITfFnShowHelp,
  493. (IUnknown **)&phelp)))
  494. {
  495. hr = phelp->Show(GetActiveWindow());
  496. phelp->Release();
  497. }
  498. }
  499. }
  500. ClearMenuMap();
  501. return hr;
  502. }
  503. //+---------------------------------------------------------------------------
  504. //
  505. // InvokeCicHelp
  506. //
  507. //----------------------------------------------------------------------------
  508. BOOL CLBarItemHelp::InvokeCicHelp()
  509. {
  510. return FullPathExec(c_szHHEXE, c_szHHEXELANGBARCHM, SW_SHOWNORMAL, TRUE);
  511. }
  512. //+---------------------------------------------------------------------------
  513. //
  514. // GetIcon
  515. //
  516. //----------------------------------------------------------------------------
  517. STDAPI CLBarItemHelp::GetIcon(HICON *phIcon)
  518. {
  519. *phIcon = LoadSmIcon(g_hInst, MAKEINTRESOURCE(ID_ICON_HELP));
  520. return S_OK;
  521. }