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.

532 lines
14 KiB

  1. //
  2. // nui.cpp
  3. //
  4. #include "private.h"
  5. #include "ids.h"
  6. #include "immxutil.h"
  7. #include "nui.h"
  8. #include "slbarid.h"
  9. #include "mslbui.h"
  10. #include "cregkey.h"
  11. #include "tchar.h"
  12. extern HINSTANCE g_hInst;
  13. /* 7e4bf406-00e4-469e-bc40-0ce2cb626849 */
  14. const GUID GUID_LBI_CICPADITEM = {
  15. 0x7e4bf406,
  16. 0x00e4,
  17. 0x469e,
  18. {0xbc, 0x40, 0x0c, 0xe2, 0xcb, 0x62, 0x68, 0x49}
  19. };
  20. /* 2aad8804-c5c8-4d7c-90b3-b5214ac54a9f */
  21. const GUID GUID_LBI_TESTITEM = {
  22. 0x2aad8804,
  23. 0xc5c8,
  24. 0x4d7c,
  25. {0x90, 0xb3, 0xb5, 0x21, 0x4a, 0xc5, 0x4a, 0x9f}
  26. };
  27. const GUID GUID_LBI_UNAWARE_MICROPHONE = {
  28. 0x24d583e2,
  29. 0xa785,
  30. 0x4b16,
  31. {0x86, 0x6b, 0xf9, 0xdc, 0x08, 0x1f, 0x4c, 0x2c}
  32. };
  33. /* 237bdc50-2aaa-44cd-be05-1b452b1acff1 */
  34. const GUID GUID_LBI_UNAWARE_BALLOON = {
  35. 0x237bdc50,
  36. 0x2aaa,
  37. 0x44cd,
  38. {0xbe, 0x05, 0x1b, 0x45, 0x2b, 0x1a, 0xcf, 0xf1}
  39. };
  40. /* a6b9e52b-3ab2-46b8-99d1-e44c1c8b3cf8 */
  41. const GUID GUID_LBI_UNAWARE_CFGMENUBUTTON = {
  42. 0xa6b9e52b,
  43. 0x3ab2,
  44. 0x46b8,
  45. {0x99, 0xd1, 0xe4, 0x4c, 0x1c, 0x8b, 0x3c, 0xf8}
  46. };
  47. // == don't know if we use the following 4 items
  48. #ifdef PERHAPS
  49. /* 17f9fa7f-a9ed-47b5-8bcd-eebb94b2e6ca */
  50. const GUID GUID_LBI_UNAWARE_COMMANDING = {
  51. 0x17f9fa7f,
  52. 0xa9ed,
  53. 0x47b5,
  54. {0x8b, 0xcd, 0xee, 0xbb, 0x94, 0xb2, 0xe6, 0xca}
  55. };
  56. /* 49261a4a-87df-47fc-8a68-6ea07ba82a87 */
  57. const GUID GUID_LBI_UNAWARE_DICTATION = {
  58. 0x49261a4a,
  59. 0x87df,
  60. 0x47fc,
  61. {0x8a, 0x68, 0x6e, 0xa0, 0x7b, 0xa8, 0x2a, 0x87}
  62. };
  63. /* 791b4403-0cda-4fe1-b748-517d049fde08 */
  64. const GUID GUID_LBI_UNAWARE_TTS_PLAY_STOP = {
  65. 0x791b4403,
  66. 0x0cda,
  67. 0x4fe1,
  68. {0xb7, 0x48, 0x51, 0x7d, 0x04, 0x9f, 0xde, 0x08}
  69. };
  70. /* e6fbfc9d-a2e0-4203-a27b-af2353e6a44e */
  71. const GUID GUID_LBI_UNAWARE_TTS_PAUSE_RESUME = {
  72. 0xe6fbfc9d,
  73. 0xa2e0,
  74. 0x4203,
  75. {0xa2, 0x7b, 0xaf, 0x23, 0x53, 0xe6, 0xa4, 0x4e}
  76. };
  77. #endif
  78. //////////////////////////////////////////////////////////////////////////////
  79. //
  80. // LBarCicPadItem
  81. //
  82. //////////////////////////////////////////////////////////////////////////////
  83. //+---------------------------------------------------------------------------
  84. //
  85. // ctor
  86. //
  87. //----------------------------------------------------------------------------
  88. CLBarCicPadItem::CLBarCicPadItem()
  89. {
  90. Dbg_MemSetThisName(TEXT("CLBarCicPadItem"));
  91. InitNuiInfo(CLSID_SYSTEMLANGBARITEM2,
  92. GUID_LBI_CICPADITEM,
  93. TF_LBI_STYLE_BTN_BUTTON
  94. | TF_LBI_STYLE_HIDDENSTATUSCONTROL
  95. | TF_LBI_STYLE_BTN_TOGGLE,
  96. CICPADBTN_ORDER,
  97. L"Cicero Pad");
  98. SetToolTip(L"CicPad");
  99. SetText(L"CicPad");
  100. }
  101. //+---------------------------------------------------------------------------
  102. //
  103. // GetIcon
  104. //
  105. //----------------------------------------------------------------------------
  106. STDAPI CLBarCicPadItem::GetIcon(HICON *phIcon)
  107. {
  108. *phIcon = LoadSmIcon(g_hInst, MAKEINTRESOURCE(ID_ICON_CICPAD));
  109. return S_OK;
  110. }
  111. //+---------------------------------------------------------------------------
  112. //
  113. // OnLButtonUpHandler
  114. //
  115. //----------------------------------------------------------------------------
  116. const TCHAR c_szCicPadWndClass[] = TEXT("cicpad_mainwnd");
  117. HRESULT CLBarCicPadItem::OnLButtonUp(const POINT pt, const RECT *prcArea)
  118. {
  119. HWND hwnd = FindWindow(c_szCicPadWndClass, NULL);
  120. if (!hwnd)
  121. {
  122. WinExec("cicpad.exe", 0);
  123. hwnd = FindWindow(c_szCicPadWndClass, NULL);
  124. if (!hwnd)
  125. return E_FAIL;
  126. SetGlobalCompartmentDWORD(GUID_COMPARTMENT_CICPAD, TRUE);
  127. return S_OK;
  128. }
  129. DWORD dw;
  130. if (SUCCEEDED(GetGlobalCompartmentDWORD(GUID_COMPARTMENT_CICPAD, &dw)))
  131. {
  132. SetGlobalCompartmentDWORD(GUID_COMPARTMENT_CICPAD, dw ? FALSE : TRUE);
  133. }
  134. return S_OK;
  135. }
  136. //////////////////////////////////////////////////////////////////////////////
  137. //
  138. // CLBarItemMicrophone
  139. //
  140. //////////////////////////////////////////////////////////////////////////////
  141. //+---------------------------------------------------------------------------
  142. //
  143. // ctor
  144. //
  145. //----------------------------------------------------------------------------
  146. CLBarItemMicrophone::CLBarItemMicrophone()
  147. {
  148. Dbg_MemSetThisName(TEXT("CLBarItemMicrophone"));
  149. InitNuiInfo(CLSID_SYSTEMLANGBARITEM_SPEECH,
  150. GUID_LBI_UNAWARE_MICROPHONE,
  151. TF_LBI_STYLE_HIDDENSTATUSCONTROL
  152. | TF_LBI_STYLE_BTN_TOGGLE
  153. | TF_LBI_STYLE_SHOWNINTRAY,
  154. SORT_MICROPHONE,
  155. CRStr(IDS_NUI_MICROPHONE_TOOLTIP));
  156. SetToolTip(CRStr(IDS_NUI_MICROPHONE_TOOLTIP));
  157. SetText(CRStr(IDS_NUI_MICROPHONE_TEXT));
  158. }
  159. //+---------------------------------------------------------------------------
  160. //
  161. // dtor
  162. //
  163. //----------------------------------------------------------------------------
  164. CLBarItemMicrophone::~CLBarItemMicrophone()
  165. {
  166. }
  167. //+---------------------------------------------------------------------------
  168. //
  169. // GetIcon
  170. //
  171. //----------------------------------------------------------------------------
  172. STDAPI CLBarItemMicrophone::GetIcon(HICON *phIcon)
  173. {
  174. if (!phIcon)
  175. return E_INVALIDARG;
  176. *phIcon = LoadSmIcon(g_hInst, MAKEINTRESOURCE(ID_ICON_MICROPHONE));
  177. return S_OK;
  178. }
  179. //+---------------------------------------------------------------------------
  180. //
  181. // OnLButtonUp
  182. //
  183. //----------------------------------------------------------------------------
  184. HRESULT CLBarItemMicrophone::OnLButtonUp(const POINT pt, const RECT *prcArea)
  185. {
  186. DWORD dw;
  187. if (SUCCEEDED(GetGlobalCompartmentDWORD(GUID_COMPARTMENT_SPEECH_OPENCLOSE, &dw)))
  188. {
  189. SetGlobalCompartmentDWORD(GUID_COMPARTMENT_SPEECH_OPENCLOSE, dw ? FALSE : TRUE);
  190. }
  191. return S_OK;
  192. }
  193. //////////////////////////////////////////////////////////////////////////////
  194. //
  195. // CLBarItemBalloon
  196. //
  197. //////////////////////////////////////////////////////////////////////////////
  198. //+---------------------------------------------------------------------------
  199. //
  200. // ctor
  201. //
  202. //----------------------------------------------------------------------------
  203. CLBarItemBalloon::CLBarItemBalloon()
  204. {
  205. Dbg_MemSetThisName(TEXT("CLBarItemBalloon"));
  206. InitNuiInfo(CLSID_SYSTEMLANGBARITEM_SPEECH,
  207. GUID_LBI_UNAWARE_BALLOON,
  208. 0,
  209. SORT_BALLOON,
  210. CRStr(IDS_NUI_BALLOON_TEXT));
  211. SIZE size;
  212. size.cx = 100;
  213. size.cy = 16;
  214. SetPreferedSize(&size);
  215. SetToolTip(CRStr(IDS_NUI_BALLOON_TOOLTIP));
  216. // by default Balloon is hidden.
  217. // SetStatusInternal(TF_LBI_STATUS_HIDDEN);
  218. }
  219. //+---------------------------------------------------------------------------
  220. //
  221. // dtor
  222. //
  223. //----------------------------------------------------------------------------
  224. CLBarItemBalloon::~CLBarItemBalloon()
  225. {
  226. if (_pszText)
  227. delete _pszText;
  228. }
  229. //+---------------------------------------------------------------------------
  230. //
  231. // GetBalloonInfo
  232. //
  233. //----------------------------------------------------------------------------
  234. STDAPI CLBarItemBalloon::GetBalloonInfo(TF_LBBALLOONINFO *pInfo)
  235. {
  236. pInfo->style = _style;
  237. pInfo->bstrText = SysAllocString(_pszText);
  238. return S_OK;
  239. }
  240. //+---------------------------------------------------------------------------
  241. //
  242. // Set
  243. //
  244. //----------------------------------------------------------------------------
  245. void CLBarItemBalloon::Set(TfLBBalloonStyle style, const WCHAR *psz)
  246. {
  247. if (_pszText)
  248. {
  249. delete _pszText;
  250. _pszText = NULL;
  251. }
  252. _pszText = new WCHAR[wcslen(psz) + 1];
  253. if (_pszText)
  254. {
  255. wcscpy(_pszText, psz);
  256. SetToolTip(_pszText);
  257. }
  258. _style = style;
  259. }
  260. //////////////////////////////////////////////////////////////////////////////
  261. //
  262. // CLBarItemCfgmenuButton
  263. //
  264. //////////////////////////////////////////////////////////////////////////////
  265. //+---------------------------------------------------------------------------
  266. //
  267. // ctor
  268. //
  269. //----------------------------------------------------------------------------
  270. CLBarItemCfgMenuButton::CLBarItemCfgMenuButton()
  271. {
  272. Dbg_MemSetThisName(TEXT("CLBarItemCfgMenuButton"));
  273. InitNuiInfo(CLSID_SYSTEMLANGBARITEM_SPEECH,
  274. GUID_LBI_UNAWARE_CFGMENUBUTTON,
  275. TF_LBI_STYLE_BTN_MENU,
  276. SORT_CFGMENUBUTTON,
  277. CRStr(IDS_NUI_CFGMENU_TOOLTIP));
  278. SetToolTip(CRStr(IDS_NUI_CFGMENU_TOOLTIP));
  279. SetText(CRStr(IDS_NUI_CFGMENU_TEXT));
  280. }
  281. //+---------------------------------------------------------------------------
  282. //
  283. // dtor
  284. //
  285. //----------------------------------------------------------------------------
  286. CLBarItemCfgMenuButton::~CLBarItemCfgMenuButton()
  287. {
  288. }
  289. //+---------------------------------------------------------------------------
  290. //
  291. // GetIcon
  292. //
  293. //----------------------------------------------------------------------------
  294. STDAPI CLBarItemCfgMenuButton::GetIcon(HICON *phIcon)
  295. {
  296. if (!phIcon)
  297. return E_INVALIDARG;
  298. *phIcon = LoadSmIcon(g_hInst, MAKEINTRESOURCE(ID_ICON_CFGMENU));
  299. return S_OK;
  300. }
  301. //+---------------------------------------------------------------------------
  302. //
  303. // InitMenu
  304. //
  305. //----------------------------------------------------------------------------
  306. STDAPI CLBarItemCfgMenuButton::InitMenu(ITfMenu *pMenu)
  307. {
  308. #if 0 // do I need this?
  309. UINT nTipCurMenuID = IDM_CUSTOM_MENU_START;
  310. _InsertCustomMenus(pMenu, &nTipCurMenuID);
  311. #endif
  312. HandleMenuCmd(IDSLB_INITMENU, pMenu, 0);
  313. return S_OK;
  314. }
  315. //+---------------------------------------------------------------------------
  316. //
  317. // OnMenuSelect
  318. //
  319. //----------------------------------------------------------------------------
  320. STDAPI CLBarItemCfgMenuButton::OnMenuSelect(UINT uID)
  321. {
  322. HRESULT hr;
  323. #if 0 // do I need this?
  324. if (uID >= IDM_CUSTOM_MENU_START)
  325. hr = CLBarItemSystemButtonBase::OnMenuSelect(uID);
  326. else
  327. #endif
  328. hr = HandleMenuCmd(IDSLB_ONMENUSELECT, NULL, uID);
  329. return hr;
  330. }
  331. //+---------------------------------------------------------------------------
  332. //
  333. // HandleMenuCmd
  334. //
  335. // Builds a list of fake menuitems. Nothing's real except "options..."
  336. // this is because we can't use COM here.
  337. //
  338. //----------------------------------------------------------------------------
  339. HRESULT
  340. CLBarItemCfgMenuButton::HandleMenuCmd(UINT uCode, ITfMenu *pMenu, UINT wID)
  341. {
  342. HRESULT hr = S_OK;
  343. if (uCode == IDSLB_INITMENU)
  344. {
  345. WCHAR sz[128];
  346. sz[0] = '\0';
  347. LoadStringWrapW(g_hInst, IDS_MIC_OPTIONS, sz, ARRAYSIZE(sz));
  348. LangBarInsertMenu(pMenu, IDM_MIC_OPTIONS, sz);
  349. sz[0] = '\0';
  350. LoadStringWrapW(g_hInst, IDS_MIC_SHOWBALLOON, sz, ARRAYSIZE(sz));
  351. LangBarInsertGrayedMenu(pMenu, sz);
  352. sz[0] = '\0';
  353. LoadStringWrapW(g_hInst, IDS_MIC_TRAINING, sz, ARRAYSIZE(sz));
  354. LangBarInsertGrayedMenu(pMenu, sz);
  355. sz[0] = '\0';
  356. LoadStringWrapW(g_hInst, IDS_MIC_ADDDELETE, sz, ARRAYSIZE(sz));
  357. LangBarInsertGrayedMenu(pMenu, sz);
  358. // [Save Data] menu...
  359. sz[0] = '\0';
  360. LoadStringWrapW(g_hInst, IDS_MIC_SAVEDATA, sz, ARRAYSIZE(sz));
  361. LangBarInsertGrayedMenu(pMenu, sz);
  362. LoadStringWrapW(g_hInst, IDS_MIC_CURRENTUSER, sz, ARRAYSIZE(sz));
  363. LangBarInsertGrayedMenu(pMenu, sz);
  364. }
  365. else if (uCode == IDSLB_ONMENUSELECT)
  366. {
  367. if (wID == IDM_MIC_OPTIONS)
  368. {
  369. TCHAR szCplPath[MAX_PATH];
  370. TCHAR szCmdLine[MAX_PATH * 2];
  371. GetSapiCplPath(szCplPath, ARRAYSIZE(szCplPath));
  372. StringCchPrintf(szCmdLine, ARRAYSIZE(szCmdLine), TEXT("rundll32 shell32.dll,Control_RunDLL \"%s\""), szCplPath);
  373. // start speech control panel applet
  374. RunCPLSetting(szCmdLine);
  375. }
  376. }
  377. return hr;
  378. }
  379. const TCHAR c_szcplsKey[] = TEXT("software\\microsoft\\windows\\currentversion\\control panel\\cpls");
  380. void CLBarItemCfgMenuButton::GetSapiCplPath(TCHAR *szCplPath, int cch)
  381. {
  382. CMyRegKey regkey;
  383. if (cch <= 0)
  384. return;
  385. szCplPath[0] = '\0';
  386. if (S_OK == regkey.Open(HKEY_LOCAL_MACHINE, c_szcplsKey, KEY_READ))
  387. {
  388. LONG lret = regkey.QueryValueCch(szCplPath, TEXT("SapiCpl"), cch);
  389. if (lret != ERROR_SUCCESS)
  390. lret = regkey.QueryValueCch(szCplPath, TEXT("Speech"), cch);
  391. }
  392. }
  393. //////////////////////////////////////////////////////////////////////////////
  394. //
  395. // LBarTestItem
  396. //
  397. //////////////////////////////////////////////////////////////////////////////
  398. #ifdef DEBUG
  399. //+---------------------------------------------------------------------------
  400. //
  401. // ctor
  402. //
  403. //----------------------------------------------------------------------------
  404. CLBarTestItem::CLBarTestItem()
  405. {
  406. Dbg_MemSetThisName(TEXT("CLBarTestItem"));
  407. InitNuiInfo(CLSID_SYSTEMLANGBARITEM2,
  408. GUID_LBI_TESTITEM,
  409. TF_LBI_STYLE_BTN_BUTTON,
  410. CICPADBTN_ORDER + 1,
  411. L"Cicero Pad");
  412. SetToolTip(L"Test");
  413. SetText(L"Test");
  414. }
  415. //+---------------------------------------------------------------------------
  416. //
  417. // GetIcon
  418. //
  419. //----------------------------------------------------------------------------
  420. STDAPI CLBarTestItem::GetIcon(HICON *phIcon)
  421. {
  422. *phIcon = LoadSmIcon(g_hInst, MAKEINTRESOURCE(ID_ICON_TEST));
  423. return S_OK;
  424. }
  425. #endif DEBUG