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.

614 lines
18 KiB

  1. //
  2. // nui.h
  3. //
  4. #ifndef NUI_H
  5. #define NUI_H
  6. #include "private.h"
  7. #include "nuibase.h"
  8. #include "timsink.h"
  9. #include "sysbtn.h"
  10. #define SORT_MICROPHONE 100
  11. #define SORT_DICTATION 300
  12. #define SORT_COMMANDING 400
  13. #define SORT_BALLOON 500
  14. #define SORT_TTSPLAYSTOP 510
  15. #define SORT_TTSPAUSERESUME 520
  16. #define SORT_CFGMENUBUTTON 600
  17. // If Enable bit is 1, Show active buttons,
  18. // If it is 0, Gray the buttons.
  19. // If Toggled bit is 1, show stop or resume buttons respectively.
  20. // If it is 0, show play or pause buttons respectively.
  21. #define TF_TTS_PLAY_STOP_TOGGLED 0x0001
  22. #define TF_TTS_PAUSE_RESUME_TOGGLED 0x0002
  23. #define TF_TTS_BUTTON_ENABLE 0x0008
  24. extern const IID IID_PRIV_CSPEECHUISERVER;
  25. extern const GUID GUID_LBI_SAPILAYR_MICROPHONE;
  26. extern const GUID GUID_LBI_SAPILAYR_CFGMENUBUTTON;
  27. extern const GUID GUID_LBI_SAPILAYR_BALLOON;
  28. class CSapiIMX;
  29. class CLBarItemMicrophone;
  30. class CLBarItemCfgMenuButton;
  31. class CLBarItemBalloon;
  32. class CLBarItemCommanding;
  33. class CLBarItemDictation;
  34. class CLBarItemSystemButtonBase;
  35. class CLBarItemTtsPlayStop;
  36. class CLBarItemTtsPauseResume;
  37. #define ADDREMOVEITEMFUNCDEF(item_name) \
  38. void AddItem ## item_name ## (); \
  39. void RemoveItem ## item_name ## (); \
  40. void DisableItem ## item_name ## (BOOL fDisable);
  41. #define ADDREMOVEITEMFUNC(item_name) \
  42. __inline void CSpeechUIServer::AddItem ## item_name ## () \
  43. { \
  44. if (!_plbi ## item_name ## ) \
  45. _plbi ## item_name ## = new CLBarItem ## item_name ## (this); \
  46. if (_plbi ## item_name ## ) \
  47. _lbim->AddItem(_plbi ## item_name ## ); \
  48. } \
  49. \
  50. __inline void CSpeechUIServer::RemoveItem ## item_name ## () \
  51. { \
  52. if (_plbi ## item_name ## ) \
  53. _lbim->RemoveItem(_plbi ## item_name ## ); \
  54. } \
  55. \
  56. __inline void CSpeechUIServer::DisableItem ## item_name ## (BOOL fDisable) \
  57. { \
  58. if (!_plbi ## item_name ## ) \
  59. return; \
  60. _plbi ## item_name ## ->SetOrClearStatus(TF_LBI_STATUS_DISABLED, \
  61. fDisable); \
  62. if (_plbi ## item_name ## ->GetSink()) \
  63. _plbi ## item_name ## ->GetSink()->OnUpdate(TF_LBI_STATUS); \
  64. }
  65. #define TOGGLEITEMFUNCDEF(item_name) \
  66. void ToggleItem ## item_name ## (BOOL fOn);
  67. #define TOGGLEITEMFUNC(item_name) \
  68. __inline void CSpeechUIServer::ToggleItem ## item_name ## (BOOL fOn) \
  69. { \
  70. if (!_plbi ## item_name ## ) \
  71. return; \
  72. _plbi ## item_name ## ->SetOrClearStatus(TF_LBI_STATUS_BTN_TOGGLED, fOn); \
  73. if (_plbi ## item_name ## ->GetSink()) \
  74. _plbi ## item_name ## ->GetSink()->OnUpdate(TF_LBI_STATUS); \
  75. }
  76. //////////////////////////////////////////////////////////////////////////////
  77. //
  78. // CLBarItemTtsPlayStop
  79. //
  80. //////////////////////////////////////////////////////////////////////////////
  81. class CLBarItemTtsPlayStop : public CLBarItemButtonBase
  82. {
  83. public:
  84. CLBarItemTtsPlayStop(CSpeechUIServer *psus);
  85. ~CLBarItemTtsPlayStop();
  86. STDMETHODIMP GetIcon(HICON *phIcon);
  87. HRESULT UpdateStatus( );
  88. private:
  89. HRESULT OnLButtonUp(const POINT pt, const RECT *prcArea);
  90. CSpeechUIServer *_psus;
  91. };
  92. //////////////////////////////////////////////////////////////////////////////
  93. //
  94. // CLBarItemTtsPauseResume
  95. //
  96. //////////////////////////////////////////////////////////////////////////////
  97. class CLBarItemTtsPauseResume : public CLBarItemButtonBase
  98. {
  99. public:
  100. CLBarItemTtsPauseResume(CSpeechUIServer *psus);
  101. ~CLBarItemTtsPauseResume();
  102. STDMETHODIMP GetIcon(HICON *phIcon);
  103. HRESULT UpdateStatus( );
  104. private:
  105. HRESULT OnLButtonUp(const POINT pt, const RECT *prcArea);
  106. CSpeechUIServer *_psus;
  107. };
  108. //////////////////////////////////////////////////////////////////////////////
  109. //
  110. // CSpeechUIServer
  111. //
  112. //////////////////////////////////////////////////////////////////////////////
  113. class CSpeechUIServer : public ITfSpeechUIServer,
  114. public CComObjectRoot_CreateSingletonInstance_Verify<CSpeechUIServer>
  115. {
  116. public:
  117. CSpeechUIServer();
  118. ~CSpeechUIServer();
  119. BEGIN_COM_MAP_IMMX(CSpeechUIServer)
  120. COM_INTERFACE_ENTRY_IID(IID_PRIV_CSPEECHUISERVER, CSpeechUIServer)
  121. COM_INTERFACE_ENTRY(ITfSpeechUIServer)
  122. END_COM_MAP_IMMX()
  123. static BOOL VerifyCreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj) { return TRUE; }
  124. static void PostCreateInstance(REFIID riid, void *pvObj);
  125. //
  126. // ITfSpeechUIServer
  127. //
  128. STDMETHODIMP Initialize();
  129. STDMETHODIMP ShowUI(BOOL fShow);
  130. STDMETHODIMP UpdateBalloon(TfLBBalloonStyle style,
  131. const WCHAR *pch,
  132. ULONG cch);
  133. //
  134. // internal API
  135. //
  136. void _EnsureSpeechProfile();
  137. HRESULT UpdateBalloonAndTooltip
  138. (
  139. TfLBBalloonStyle style,
  140. const WCHAR *pch,
  141. ULONG cch,
  142. const WCHAR *pchTooltip,
  143. ULONG cchTooltip
  144. );
  145. static CSpeechUIServer *_GetThis()
  146. {
  147. SPTIPTHREAD *pstt = GetSPTIPTHREAD();
  148. if (!pstt)
  149. return NULL;
  150. return pstt->psus;
  151. }
  152. static BOOL _SetThis(CSpeechUIServer *_this)
  153. {
  154. SPTIPTHREAD *ptt = GetSPTIPTHREAD();
  155. if (!ptt)
  156. return FALSE;
  157. ptt->psus = _this;
  158. return TRUE;
  159. }
  160. BOOL GetOnOff()
  161. {
  162. DWORD dw;
  163. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_OPENCLOSE, &dw, TRUE);
  164. return dw ? TRUE : FALSE;
  165. }
  166. #ifdef TF_DISABLE_SPEECH
  167. BOOL GetDisabled()
  168. {
  169. DWORD dw;
  170. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_DISABLED, &dw, FALSE);
  171. return (dw & TF_DISABLE_SPEECH) ? TRUE : FALSE;
  172. }
  173. BOOL GetDictationDisabled()
  174. {
  175. DWORD dw;
  176. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_DISABLED, &dw, FALSE);
  177. return (dw & TF_DISABLE_DICTATION) ? TRUE : FALSE;
  178. }
  179. BOOL GetCommandingDisabled()
  180. {
  181. DWORD dw;
  182. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_DISABLED, &dw, FALSE);
  183. return (dw & TF_DISABLE_COMMANDING) ? TRUE : FALSE;
  184. }
  185. #else
  186. BOOL GetDisabled()
  187. {
  188. DWORD dw;
  189. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_DISABLED, &dw, FALSE);
  190. return dw ? TRUE : FALSE;
  191. }
  192. #endif
  193. DWORD GetUIStatus()
  194. {
  195. DWORD dw;
  196. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_UI_STATUS, &dw, TRUE);
  197. return dw;
  198. }
  199. DWORD GetDictStatus()
  200. {
  201. DWORD dwLocal, dwGlobal;
  202. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_DICTATIONSTAT, &dwLocal, FALSE);
  203. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_GLOBALSTATE, &dwGlobal, TRUE);
  204. dwLocal = (dwLocal & (TF_DICTATION_ENABLED | TF_COMMANDING_ENABLED)) +
  205. (dwGlobal & (TF_DICTATION_ON | TF_COMMANDING_ON));
  206. return dwLocal;
  207. }
  208. void SetDictStatus()
  209. {
  210. DWORD dwGlobal=0;
  211. DWORD dwNewState;
  212. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_GLOBALSTATE, &dwGlobal, TRUE);
  213. dwNewState = dwGlobal ^ TF_DICTATION_ON;
  214. if ( dwNewState | TF_DICTATION_ON )
  215. dwNewState &= ~TF_COMMANDING_ON; // it is not possible that both Dication On and Command On
  216. SetCompartmentDWORD(0,
  217. _tim,
  218. GUID_COMPARTMENT_SPEECH_GLOBALSTATE,
  219. dwNewState,
  220. TRUE);
  221. }
  222. void SetCmdStatus()
  223. {
  224. DWORD dwGlobal=0;
  225. DWORD dwNewState;
  226. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_GLOBALSTATE, &dwGlobal, TRUE);
  227. dwNewState = dwGlobal ^ TF_COMMANDING_ON;
  228. if ( dwNewState | TF_COMMANDING_ON )
  229. dwNewState &= ~TF_DICTATION_ON;
  230. SetCompartmentDWORD(0,
  231. _tim,
  232. GUID_COMPARTMENT_SPEECH_GLOBALSTATE,
  233. dwNewState,
  234. TRUE);
  235. }
  236. void SetCfgMenu(BOOL fReady)
  237. {
  238. DWORD dw;
  239. HRESULT hr = GetCompartmentDWORD(_tim, GUID_COMPARTMENT_SPEECH_CFGMENU, &dw, FALSE);
  240. if (S_OK == hr)
  241. {
  242. BOOL fReadyNow = (dw > 0);
  243. if (fReadyNow == fReady)
  244. return;
  245. }
  246. SetCompartmentDWORD(0, _tim, GUID_COMPARTMENT_SPEECH_CFGMENU, fReady, FALSE);
  247. }
  248. BOOL GetTtsPlayOnOff( )
  249. {
  250. DWORD dw;
  251. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_TTS_STATUS, &dw, FALSE);
  252. return (dw & TF_TTS_PLAY_STOP_TOGGLED ? TRUE : FALSE);
  253. }
  254. void SetTtsPlayOnOff( BOOL fOn )
  255. {
  256. DWORD dw;
  257. HRESULT hr = S_OK;
  258. BOOL fEnabled;
  259. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_TTS_STATUS, &dw, FALSE);
  260. fEnabled = ( dw & TF_TTS_BUTTON_ENABLE) ? TRUE : FALSE;
  261. if ( fEnabled )
  262. {
  263. dw = (dw & ~TF_TTS_PLAY_STOP_TOGGLED) | (fOn ? TF_TTS_PLAY_STOP_TOGGLED : 0 );
  264. hr = SetCompartmentDWORD(0,
  265. _tim,
  266. GUID_COMPARTMENT_TTS_STATUS,
  267. dw,
  268. FALSE);
  269. if ( hr == S_OK )
  270. {
  271. // update the icon, text, tooltip for Play/Stop botton.
  272. if ( _plbiTtsPlayStop )
  273. _plbiTtsPlayStop->UpdateStatus( );
  274. }
  275. }
  276. }
  277. BOOL GetTtsPauseOnOff( )
  278. {
  279. DWORD dw;
  280. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_TTS_STATUS, &dw, FALSE);
  281. return (dw & TF_TTS_PAUSE_RESUME_TOGGLED ? TRUE : FALSE);
  282. }
  283. void SetTtsPauseOnOff( BOOL fOn )
  284. {
  285. DWORD dw;
  286. HRESULT hr;
  287. BOOL fEnabled;
  288. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_TTS_STATUS, &dw, FALSE);
  289. fEnabled = ( dw & TF_TTS_BUTTON_ENABLE) ? TRUE : FALSE;
  290. if ( fEnabled )
  291. {
  292. dw = (dw & ~TF_TTS_PAUSE_RESUME_TOGGLED) | (fOn ? TF_TTS_PAUSE_RESUME_TOGGLED : 0);
  293. hr = SetCompartmentDWORD(0,
  294. _tim,
  295. GUID_COMPARTMENT_TTS_STATUS,
  296. dw,
  297. FALSE);
  298. if ( hr == S_OK )
  299. {
  300. // update the icon, text, tooltip for Pause/Resume botton.
  301. if ( _plbiTtsPauseResume )
  302. _plbiTtsPauseResume->UpdateStatus( );
  303. }
  304. }
  305. }
  306. BOOL GetTtsButtonStatus( )
  307. {
  308. DWORD dw;
  309. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_TTS_STATUS, &dw, FALSE);
  310. return (dw & TF_TTS_BUTTON_ENABLE ? TRUE : FALSE );
  311. }
  312. void SetTtsButtonStatus( BOOL fEnable )
  313. {
  314. DWORD dw;
  315. GetCompartmentDWORD(_tim, GUID_COMPARTMENT_TTS_STATUS, &dw, FALSE);
  316. dw = (dw & ~TF_TTS_BUTTON_ENABLE) | (fEnable ? TF_TTS_BUTTON_ENABLE : 0);
  317. SetCompartmentDWORD(0,
  318. _tim,
  319. GUID_COMPARTMENT_TTS_STATUS,
  320. dw,
  321. FALSE);
  322. }
  323. void SetIMX(CSapiIMX *pimx)
  324. {
  325. _pimx = pimx;
  326. }
  327. // TABLETPC
  328. HRESULT IsActiveThread()
  329. {
  330. if (m_fStageTip)
  331. {
  332. // To avoid a race condition with no immediately available solution, we are now active only when the stage is visible.
  333. if (m_fStageVisible)
  334. {
  335. return S_OK;
  336. }
  337. else
  338. {
  339. return S_FALSE;
  340. }
  341. }
  342. else if (m_fStageVisible)
  343. {
  344. // Stage is visible. We are always inactive since we are not the stage.
  345. return S_FALSE;
  346. }
  347. else
  348. {
  349. // Stage is not visible. We're active if we have focus as normal Cicero.
  350. BOOL fThreadFocus = FALSE;
  351. HRESULT hr = S_OK;
  352. hr = _tim->IsThreadFocus(&fThreadFocus);
  353. hr = (S_OK == hr) ? ( (fThreadFocus) ? S_OK : S_FALSE ) : hr;
  354. return hr;
  355. }
  356. }
  357. ITfThreadMgr *GetTIM() {return _tim;}
  358. CSapiIMX *GetIMX() {return _pimx;}
  359. HRESULT SetBalloonSAPIInitFlag(BOOL fSet);
  360. private:
  361. ADDREMOVEITEMFUNCDEF(Microphone)
  362. ADDREMOVEITEMFUNCDEF(CfgMenuButton)
  363. ADDREMOVEITEMFUNCDEF(Balloon)
  364. ADDREMOVEITEMFUNCDEF(Commanding)
  365. ADDREMOVEITEMFUNCDEF(Dictation)
  366. ADDREMOVEITEMFUNCDEF(TtsPlayStop)
  367. ADDREMOVEITEMFUNCDEF(TtsPauseResume)
  368. #ifdef CHANGE_MIC_TOOLTIP_ONTHEFLY
  369. HRESULT _ToggleMicrophone(BOOL fOn);
  370. #else
  371. TOGGLEITEMFUNCDEF(Microphone);
  372. #endif
  373. TOGGLEITEMFUNCDEF(Commanding);
  374. TOGGLEITEMFUNCDEF(Dictation);
  375. TOGGLEITEMFUNCDEF(TtsPlayStop);
  376. TOGGLEITEMFUNCDEF(TtsPauseResume);
  377. static HRESULT _CompEventSinkCallback(void *pv, REFGUID rguid);
  378. ITfThreadMgr *_tim;
  379. ITfLangBarItemMgr *_lbim;
  380. CSapiIMX *_pimx;
  381. BOOL _fShown;
  382. BOOL m_fCommandingReady;
  383. // TABLET
  384. BOOL m_fStageTip;
  385. BOOL m_fStageVisible;
  386. DWORD m_cRef;
  387. CLBarItemMicrophone *_plbiMicrophone;
  388. CLBarItemCfgMenuButton *_plbiCfgMenuButton;
  389. CLBarItemBalloon *_plbiBalloon;
  390. CLBarItemCommanding *_plbiCommanding;
  391. CLBarItemDictation *_plbiDictation;
  392. CLBarItemTtsPlayStop *_plbiTtsPlayStop;
  393. CLBarItemTtsPauseResume *_plbiTtsPauseResume;
  394. ATOM m_hAtom;
  395. CCompartmentEventSink *_pCes;
  396. };
  397. //////////////////////////////////////////////////////////////////////////////
  398. //
  399. // CLBarItemMicrophone
  400. //
  401. //////////////////////////////////////////////////////////////////////////////
  402. class CLBarItemMicrophone : public CLBarItemButtonBase
  403. {
  404. public:
  405. CLBarItemMicrophone(CSpeechUIServer *psus);
  406. ~CLBarItemMicrophone();
  407. STDMETHODIMP GetIcon(HICON *phIcon);
  408. private:
  409. HRESULT OnLButtonUp(const POINT pt, const RECT *prcArea);
  410. CSpeechUIServer *_psus;
  411. };
  412. //////////////////////////////////////////////////////////////////////////////
  413. //
  414. // CLBarItemCfgMenuButton
  415. //
  416. //////////////////////////////////////////////////////////////////////////////
  417. class CLBarItemCfgMenuButton : public CLBarItemSystemButtonBase
  418. {
  419. public:
  420. CLBarItemCfgMenuButton(CSpeechUIServer *psus);
  421. ~CLBarItemCfgMenuButton();
  422. //
  423. // ITfNotifyUI
  424. //
  425. STDMETHODIMP GetIcon(HICON *phIcon);
  426. STDMETHODIMP InitMenu(ITfMenu *pMenu);
  427. STDMETHODIMP OnMenuSelect(UINT uID);
  428. private:
  429. CSpeechUIServer *_psus;
  430. };
  431. //////////////////////////////////////////////////////////////////////////////
  432. //
  433. // CLBarItemBalloon
  434. //
  435. //////////////////////////////////////////////////////////////////////////////
  436. class CLBarItemBalloon : public CLBarItemBalloonBase
  437. {
  438. public:
  439. CLBarItemBalloon(CSpeechUIServer *psus);
  440. ~CLBarItemBalloon();
  441. STDMETHODIMP GetBalloonInfo(TF_LBBALLOONINFO *pInfo);
  442. void Set(TfLBBalloonStyle style, const WCHAR *psz);
  443. BOOL NeedUpdate(TfLBBalloonStyle style, const WCHAR *psz)
  444. {
  445. return (!_bstrText || _style != style || wcscmp(_bstrText, psz) != 0);
  446. }
  447. void SetToFireInitializeSAPI(BOOL fSet)
  448. {
  449. m_fFireInitializeSapi = fSet;
  450. }
  451. TfLBBalloonStyle GetStyle(void)
  452. {
  453. return _style;
  454. }
  455. void SetStyle(TfLBBalloonStyle style)
  456. {
  457. _style = style;
  458. }
  459. private:
  460. BSTR _bstrText;
  461. TfLBBalloonStyle _style;
  462. CSpeechUIServer *_psus;
  463. BOOL m_fFireInitializeSapi;
  464. };
  465. //////////////////////////////////////////////////////////////////////////////
  466. //
  467. // CLBarItemDictation
  468. //
  469. //////////////////////////////////////////////////////////////////////////////
  470. class CLBarItemDictation : public CLBarItemButtonBase
  471. {
  472. public:
  473. CLBarItemDictation(CSpeechUIServer *psus);
  474. ~CLBarItemDictation();
  475. STDMETHODIMP GetIcon(HICON *phIcon);
  476. private:
  477. HRESULT OnLButtonUp(const POINT pt, const RECT *prcArea);
  478. CSpeechUIServer *_psus;
  479. };
  480. //////////////////////////////////////////////////////////////////////////////
  481. //
  482. // CLBarItemCommanding
  483. //
  484. //////////////////////////////////////////////////////////////////////////////
  485. class CLBarItemCommanding : public CLBarItemButtonBase
  486. {
  487. public:
  488. CLBarItemCommanding(CSpeechUIServer *psus);
  489. ~CLBarItemCommanding();
  490. STDMETHODIMP GetIcon(HICON *phIcon);
  491. private:
  492. HRESULT OnLButtonUp(const POINT pt, const RECT *prcArea);
  493. CSpeechUIServer *_psus;
  494. };
  495. ADDREMOVEITEMFUNC(Microphone)
  496. ADDREMOVEITEMFUNC(CfgMenuButton)
  497. ADDREMOVEITEMFUNC(Balloon)
  498. ADDREMOVEITEMFUNC(Commanding)
  499. ADDREMOVEITEMFUNC(Dictation)
  500. ADDREMOVEITEMFUNC(TtsPlayStop)
  501. ADDREMOVEITEMFUNC(TtsPauseResume)
  502. #ifndef CHANGE_MIC_TOOLTIP_ONTHEFLY
  503. TOGGLEITEMFUNC(Microphone);
  504. #endif
  505. TOGGLEITEMFUNC(Commanding);
  506. TOGGLEITEMFUNC(Dictation);
  507. TOGGLEITEMFUNC(TtsPlayStop);
  508. TOGGLEITEMFUNC(TtsPauseResume);
  509. #endif // NUI_H