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.

475 lines
9.9 KiB

  1. //
  2. //
  3. // Sapilayr TIP Misc function impl.
  4. //
  5. //
  6. #include "private.h"
  7. #include "sapilayr.h"
  8. #include "nui.h"
  9. #include "miscfunc.h"
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // CGetSAPIObject
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. //
  16. // ctor / dtor
  17. //
  18. CGetSAPIObject::CGetSAPIObject(CSapiIMX *psi)
  19. {
  20. m_psi = psi;
  21. m_psi->AddRef();
  22. m_psi->GetFocusIC(&m_cpIC); // AddRef in the call
  23. m_cRef = 1;
  24. }
  25. CGetSAPIObject::~CGetSAPIObject()
  26. {
  27. if (m_psi)
  28. m_psi->Release();
  29. }
  30. //
  31. // IUnknown
  32. //
  33. STDMETHODIMP CGetSAPIObject::QueryInterface(REFGUID riid, LPVOID *ppvObj)
  34. {
  35. Assert(ppvObj);
  36. *ppvObj = NULL;
  37. if (IsEqualIID(riid, IID_IUnknown) ||
  38. IsEqualIID(riid, IID_ITfFnGetSAPIObject))
  39. {
  40. *ppvObj = SAFECAST(this, CGetSAPIObject *);
  41. }
  42. if (*ppvObj)
  43. {
  44. AddRef();
  45. return S_OK;
  46. }
  47. return E_NOINTERFACE;
  48. }
  49. STDMETHODIMP_(ULONG) CGetSAPIObject::AddRef(void)
  50. {
  51. return InterlockedIncrement(&m_cRef);
  52. }
  53. STDMETHODIMP_(ULONG) CGetSAPIObject::Release(void)
  54. {
  55. long cr;
  56. cr = InterlockedDecrement(&m_cRef);
  57. Assert(cr >= 0);
  58. if (cr == 0)
  59. {
  60. delete this;
  61. }
  62. return cr;
  63. }
  64. //
  65. // ITfFunction
  66. //
  67. STDMETHODIMP CGetSAPIObject::GetDisplayName(BSTR *pbstrName)
  68. {
  69. HRESULT hr = E_INVALIDARG;
  70. if (pbstrName)
  71. {
  72. *pbstrName = SysAllocString(L"Get SAPI objects");
  73. if (!*pbstrName)
  74. hr = E_OUTOFMEMORY;
  75. else
  76. hr = S_OK;
  77. }
  78. return hr;
  79. }
  80. //
  81. // ITfFnGetSAPIObject
  82. //
  83. static const struct {
  84. TfSapiObject sObj;
  85. const GUID *riid;
  86. BOOL fInit;
  87. } SapiInterfaceTbl[] =
  88. {
  89. {GETIF_RESMGR , &IID_ISpResourceManager, TRUE },
  90. {GETIF_RECOCONTEXT , &IID_ISpRecoContext, TRUE},
  91. {GETIF_RECOGNIZER , &IID_ISpRecognizer, TRUE},
  92. {GETIF_VOICE , &IID_ISpVoice, TRUE},
  93. {GETIF_DICTGRAM , &IID_ISpRecoGrammar, TRUE},
  94. {GETIF_RECOGNIZERNOINIT , &IID_ISpRecognizer, FALSE},
  95. };
  96. STDMETHODIMP CGetSAPIObject::Get(TfSapiObject sObj, IUnknown **ppunk)
  97. {
  98. HRESULT hr = S_FALSE;
  99. //
  100. // sObj is an index to SapiInterfaceTbl[]
  101. //
  102. Assert(GETIF_RESMGR == 0);
  103. if (ppunk)
  104. *ppunk = NULL;
  105. if(sObj < ARRAYSIZE(SapiInterfaceTbl))
  106. {
  107. CSpTask *psptask = NULL;
  108. if (S_OK == m_psi->GetSpeechTask(&psptask, SapiInterfaceTbl[sObj].fInit))
  109. {
  110. hr = psptask->GetSAPIInterface(*(SapiInterfaceTbl[sObj].riid), (void **)ppunk);
  111. }
  112. SafeRelease(psptask);
  113. }
  114. return hr;
  115. }
  116. //
  117. // IsSupported() (internal)
  118. // returns S_OK when the passed in IID is supported,
  119. // otherwise returns S_FALSE
  120. //
  121. //
  122. HRESULT CGetSAPIObject::IsSupported(REFIID riid, TfSapiObject *psObj)
  123. {
  124. HRESULT hr = S_FALSE;
  125. Assert(psObj);
  126. for (int i = 0; i < ARRAYSIZE(SapiInterfaceTbl); i++)
  127. {
  128. Assert(i == SapiInterfaceTbl[i].sObj);
  129. if (IsEqualGUID(*SapiInterfaceTbl[i].riid, riid))
  130. {
  131. *psObj = SapiInterfaceTbl[i].sObj;
  132. hr = S_OK;
  133. break;
  134. }
  135. }
  136. return hr;
  137. }
  138. //////////////////////////////////////////////////////////////////////////////
  139. //
  140. // CFnBalloon
  141. //
  142. //////////////////////////////////////////////////////////////////////////////
  143. //+---------------------------------------------------------------------------
  144. //
  145. // IUnknown
  146. //
  147. //----------------------------------------------------------------------------
  148. STDAPI CFnBalloon::QueryInterface(REFIID riid, void **ppvObj)
  149. {
  150. *ppvObj = NULL;
  151. if (IsEqualIID(riid, IID_IUnknown) ||
  152. IsEqualIID(riid, IID_ITfFnBalloon))
  153. {
  154. *ppvObj = SAFECAST(this, CFnBalloon *);
  155. }
  156. if (*ppvObj)
  157. {
  158. AddRef();
  159. return S_OK;
  160. }
  161. return E_NOINTERFACE;
  162. }
  163. STDAPI_(ULONG) CFnBalloon::AddRef()
  164. {
  165. return InterlockedIncrement(&_cRef);
  166. }
  167. STDAPI_(ULONG) CFnBalloon::Release()
  168. {
  169. long cr;
  170. cr = InterlockedDecrement(&_cRef);
  171. Assert(cr >= 0);
  172. if (cr == 0)
  173. {
  174. delete this;
  175. }
  176. return cr;
  177. }
  178. //+---------------------------------------------------------------------------
  179. //
  180. // ctor
  181. //
  182. //----------------------------------------------------------------------------
  183. CFnBalloon::CFnBalloon(CSapiIMX *psi) : CFunction(psi)
  184. {
  185. _cRef = 1;
  186. }
  187. //+---------------------------------------------------------------------------
  188. //
  189. // dtor
  190. //
  191. //----------------------------------------------------------------------------
  192. CFnBalloon::~CFnBalloon()
  193. {
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // dtor
  198. //
  199. //----------------------------------------------------------------------------
  200. STDAPI CFnBalloon::GetDisplayName(BSTR *pbstrName)
  201. {
  202. HRESULT hr = E_INVALIDARG;
  203. if (pbstrName)
  204. {
  205. *pbstrName = SysAllocString(L"Speech Conversion");
  206. if (!*pbstrName)
  207. hr = E_OUTOFMEMORY;
  208. else
  209. hr = S_OK;
  210. }
  211. return hr;
  212. }
  213. //+---------------------------------------------------------------------------
  214. //
  215. // CFnBalloon::UpdateBalloon
  216. //
  217. //----------------------------------------------------------------------------
  218. STDAPI CFnBalloon::UpdateBalloon(TfLBBalloonStyle style, const WCHAR *pch, ULONG cch)
  219. {
  220. HRESULT hr = S_OK;
  221. if (!m_pImx->GetSpeechUIServer())
  222. return hr;
  223. m_pImx->GetSpeechUIServer()->UpdateBalloon(style, pch, cch);
  224. return hr;
  225. }
  226. //////////////////////////////////////////////////////////////////////////////
  227. //
  228. // CFnAbort
  229. //
  230. //////////////////////////////////////////////////////////////////////////////
  231. //+---------------------------------------------------------------------------
  232. //
  233. // IUnknown
  234. //
  235. //----------------------------------------------------------------------------
  236. STDAPI CFnAbort::QueryInterface(REFIID riid, void **ppvObj)
  237. {
  238. *ppvObj = NULL;
  239. if (IsEqualIID(riid, IID_IUnknown) ||
  240. IsEqualIID(riid, IID_ITfFnAbort))
  241. {
  242. *ppvObj = SAFECAST(this, CFnAbort *);
  243. }
  244. if (*ppvObj)
  245. {
  246. AddRef();
  247. return S_OK;
  248. }
  249. return E_NOINTERFACE;
  250. }
  251. STDAPI_(ULONG) CFnAbort::AddRef()
  252. {
  253. return InterlockedIncrement(&_cRef);
  254. }
  255. STDAPI_(ULONG) CFnAbort::Release()
  256. {
  257. long cr;
  258. cr = InterlockedDecrement(&_cRef);
  259. Assert(cr >= 0);
  260. if (cr == 0)
  261. {
  262. delete this;
  263. }
  264. return cr;
  265. }
  266. //+---------------------------------------------------------------------------
  267. //
  268. // ctor
  269. //
  270. //----------------------------------------------------------------------------
  271. CFnAbort::CFnAbort(CSapiIMX *psi) : CFunction(psi)
  272. {
  273. _cRef = 1;
  274. }
  275. //+---------------------------------------------------------------------------
  276. //
  277. // dtor
  278. //
  279. //----------------------------------------------------------------------------
  280. CFnAbort::~CFnAbort()
  281. {
  282. }
  283. //+---------------------------------------------------------------------------
  284. //
  285. // dtor
  286. //
  287. //----------------------------------------------------------------------------
  288. STDAPI CFnAbort::GetDisplayName(BSTR *pbstrName)
  289. {
  290. HRESULT hr = E_INVALIDARG;
  291. if (pbstrName)
  292. {
  293. *pbstrName = SysAllocString(L"Speech Abort Pending Conversion");
  294. if (!*pbstrName)
  295. hr = E_OUTOFMEMORY;
  296. else
  297. hr = S_OK;
  298. }
  299. return hr;
  300. }
  301. //+---------------------------------------------------------------------------
  302. //
  303. // CFnAbort::Abort
  304. //
  305. //----------------------------------------------------------------------------
  306. HRESULT CFnAbort::Abort(ITfContext *pctxt)
  307. {
  308. HRESULT hr;
  309. Assert(m_pImx);
  310. Assert(pctxt);
  311. // put up the hour glass
  312. HCURSOR hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
  313. hr = m_pImx->_RequestEditSession(ESCB_ABORT,TF_ES_READWRITE | TF_ES_SYNC, NULL, pctxt);
  314. if (hCur)
  315. SetCursor(hCur);
  316. return hr;
  317. }
  318. //+---------------------------------------------------------------------------
  319. //
  320. // CFnConfigure::Show
  321. //
  322. //----------------------------------------------------------------------------
  323. STDMETHODIMP CFnConfigure::Show(HWND hwndParent, LANGID langid, REFGUID rguidProfile)
  324. {
  325. m_psi->_InvokeSpeakerOptions( TRUE );
  326. return S_OK;
  327. };
  328. //+---------------------------------------------------------------------------
  329. //
  330. // CFnPropertyUIStatus implementation
  331. //
  332. //----------------------------------------------------------------------------
  333. //
  334. // IUnknown
  335. //
  336. STDMETHODIMP CFnPropertyUIStatus::QueryInterface(REFGUID riid, LPVOID *ppvObj)
  337. {
  338. Assert(ppvObj);
  339. *ppvObj = NULL;
  340. if (IsEqualIID(riid, IID_IUnknown) ||
  341. IsEqualIID(riid, IID_ITfFnPropertyUIStatus))
  342. {
  343. *ppvObj = SAFECAST(this, CFnPropertyUIStatus *);
  344. }
  345. if (*ppvObj)
  346. {
  347. AddRef();
  348. return S_OK;
  349. }
  350. return E_NOINTERFACE;
  351. }
  352. STDMETHODIMP_(ULONG) CFnPropertyUIStatus::AddRef(void)
  353. {
  354. return InterlockedIncrement(&m_cRef);
  355. }
  356. STDMETHODIMP_(ULONG) CFnPropertyUIStatus::Release(void)
  357. {
  358. long cr;
  359. cr = InterlockedDecrement(&m_cRef);
  360. Assert(cr >= 0);
  361. if (cr == 0)
  362. {
  363. delete this;
  364. }
  365. return cr;
  366. }
  367. STDMETHODIMP CFnPropertyUIStatus::GetStatus(REFGUID refguidProp, DWORD *pdw)
  368. {
  369. HRESULT hr = S_FALSE;
  370. if (pdw)
  371. {
  372. *pdw = 0;
  373. }
  374. else
  375. {
  376. hr = E_INVALIDARG;
  377. }
  378. if (SUCCEEDED(hr) &&
  379. IsEqualGUID(refguidProp, GUID_PROP_SAPIRESULTOBJECT))
  380. {
  381. *pdw |= m_psi->_SerializeEnabled() ?
  382. TF_PROPUI_STATUS_SAVETOFILE : 0;
  383. hr = S_OK;
  384. }
  385. return hr;
  386. }