home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / AutoPC / apcsdk10.exe / data1.cab / Win32_Samples / win32 / tts / appsink.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-13  |  9.0 KB  |  333 lines

  1. //--------------------------------------------------------------------------------------------
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  4. //  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  5. //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  6. //  PARTICULAR PURPOSE.
  7. //
  8. //    Copyright (c) Microsoft Corporation, 1997 All Rights Reserved
  9. //
  10. //    Description:
  11. //        
  12. //        Contains the base application level code and classes for a simple Apollo application
  13. //
  14. //--------------------------------------------------------------------------------------------
  15.  
  16. #include <windows.h>
  17. #include <olectl.h>
  18. #include <asfc.h>
  19. #include <ascmnctl.h>
  20. #include <speech.h>
  21.  
  22. #include "app.h"
  23. #include "resource.h"
  24. #include "appsink.h"
  25.  
  26.  
  27. //global app object
  28. extern CTTSApp * g_pApp;
  29. //--------------------------------------------------------------------------------------------
  30. //
  31. // CFormEventSink Class implementation
  32. //
  33. //--------------------------------------------------------------------------------------------
  34.  
  35. //+-------------------------------------------------------------------------
  36. //
  37. //    Function: CFormEventSink::CFormEventSink
  38. //
  39. //    Synopsis: Constructor, just initializes reference count.
  40. //
  41. //    Arguments: none
  42. //
  43. //     Returns:  void
  44. //                
  45. //---------------------------------------------------------------------------
  46.  
  47. CFormEventSink::CFormEventSink()
  48. {
  49.     m_cRef = 0;
  50. }
  51.  
  52. //+-------------------------------------------------------------------------
  53. //
  54. //    Function: CFormEventSink::QueryInterface
  55. //
  56. //    Synopsis: Standard IUnknown method.  Returns requested interface.
  57. //
  58. //    Arguments:  REFIID - reference to Interface GUID
  59. //                PVOID - returned interface pointer
  60. //
  61. //     Returns:  HRESULT result code
  62. //                
  63. //---------------------------------------------------------------------------
  64.  
  65. STDMETHODIMP
  66. CFormEventSink::QueryInterface( REFIID riid,
  67.                                 PVOID *ppv)
  68. {
  69.  
  70.     HRESULT hr = NOERROR;
  71.  
  72.     if (!ppv)
  73.         hr = E_INVALIDARG;
  74.  
  75.     // Returns requested interface, if it is supported
  76.     if( SUCCEEDED( hr ) ) {
  77.         if (riid == IID_ASEVENTSINK)
  78.             *ppv = (PVOID) (IASEventSink*) this; 
  79.         else if (riid == IID_IUnknown)
  80.             *ppv = (PVOID) (IUnknown*) (IVCmdNotifySinkW*) this;
  81.         else if (riid == IID_IDispatch)
  82.             *ppv = (PVOID) (IDispatch*) this;
  83.         else
  84.             hr = E_NOINTERFACE;
  85.     }
  86.  
  87.     if( SUCCEEDED( hr ) ) 
  88.         AddRef();
  89.  
  90.     return hr;
  91. }
  92.  
  93. //+-------------------------------------------------------------------------
  94. //
  95. //    Function: CFormEventSink::AddRef
  96. //
  97. //    Synopsis: Increments objects reference count.
  98. //
  99. //    Arguments: none
  100. //
  101. //     Returns: ULONG - Current reference count
  102. //                
  103. //---------------------------------------------------------------------------
  104. STDMETHODIMP_(ULONG)
  105. CFormEventSink::AddRef()
  106. {
  107.     InterlockedIncrement(&m_cRef);
  108.  
  109.     return m_cRef;         
  110. }
  111.  
  112. //+-------------------------------------------------------------------------
  113. //
  114. //    Function: CFormEventSink::Release
  115. //
  116. //    Synopsis: Decrements reference count, deletes object if it == 0.
  117. //
  118. //    Arguments: none
  119. //
  120. //     Returns: ULONG - Current reference count
  121. //                
  122. //---------------------------------------------------------------------------
  123. STDMETHODIMP_(ULONG)
  124. CFormEventSink::Release()
  125. {
  126.  
  127.     if (InterlockedDecrement(&m_cRef) == 0)
  128.     {
  129.         delete this;
  130.         return(0);
  131.     }
  132.     return m_cRef;
  133. }            
  134.  
  135. //+-------------------------------------------------------------------------
  136. //
  137. //    Function: CFormEventSink::ReceiveMsg
  138. //
  139. //    Synopsis: Event sink to be attatched to form.  Calls main app's ProcessMessage
  140. //        function to handle messages it receives.
  141. //
  142. //    Arguments:    LONG uMsg        - Win 32 message
  143. //                LONG wParam        - message parameter
  144. //                LONG lParam        - message parameter
  145. //
  146. //     Returns:  void
  147. //                
  148. //---------------------------------------------------------------------------
  149.  
  150. STDMETHODIMP    
  151. CFormEventSink::ReceiveMsg(LONG uMsg, LONG wParam, LONG lParam)
  152. {
  153.  
  154.     g_pApp->ProcessMessage(uMsg, wParam, lParam);
  155.     return S_FALSE;
  156. }
  157.  
  158. //--------------------------------------------------------------------------------------------
  159. //
  160. // CAppMessageSink class implementation
  161. //
  162. //--------------------------------------------------------------------------------------------
  163.  
  164. //+-------------------------------------------------------------------------
  165. //
  166. //    Function: CAppMessageSink::CAppMessageSink
  167. //
  168. //    Synopsis: Constructor, just initializes reference count.
  169. //
  170. //    Arguments: none
  171. //
  172. //     Returns:  void
  173. //                
  174. //---------------------------------------------------------------------------
  175.  
  176. CAppMessageSink::CAppMessageSink()
  177. {
  178.     m_cRef = 0;
  179. }
  180.  
  181. //+-------------------------------------------------------------------------
  182. //
  183. //    Function: CAppMessageSink::QueryInterface
  184. //
  185. //    Synopsis: Returns pointer to requested interface.
  186. //
  187. //    Arguments:    REFIID - Requested interface's GUID
  188. //                PVOID - pointer to interface return 
  189. //
  190. //     Returns:  HRESULT result code
  191. //                
  192. //---------------------------------------------------------------------------
  193. STDMETHODIMP
  194. CAppMessageSink::QueryInterface(REFIID     riid,
  195.                                 PVOID *    ppv)
  196. {
  197.     HRESULT hr = NOERROR;
  198.  
  199.     if (!ppv)
  200.         hr = E_INVALIDARG;
  201.  
  202.     if( SUCCEEDED( hr ) ) {
  203.         if (riid == IID_ASCLASSMSGSINK)
  204.             *ppv = (PVOID) (IASClassMsgSink *) this; 
  205.         else if (riid == IID_ASEVENTSINK)
  206.             *ppv = (PVOID) (IASEventSink*) this; 
  207.         else if (riid == IID_IUnknown)
  208.             *ppv = (PVOID) (IUnknown *) (IASClassMsgSink *)this;
  209.         else if (riid == IID_IDispatch)
  210.             *ppv = (PVOID) (IDispatch *) (IASClassMsgSink *)this;
  211.         else
  212.             hr = E_NOINTERFACE;
  213.     }
  214.  
  215.     if( SUCCEEDED( hr ) ) 
  216.         AddRef();
  217.  
  218.     return hr;
  219. }
  220.  
  221. //+-------------------------------------------------------------------------
  222. //
  223. //    Function: CAppMessageSink::AddRef
  224. //
  225. //    Synopsis: Increments objects reference count.
  226. //
  227. //    Arguments: none
  228. //
  229. //     Returns: ULONG - Current reference count
  230. //                
  231. //---------------------------------------------------------------------------
  232.  
  233. STDMETHODIMP_(ULONG)    
  234. CAppMessageSink::AddRef()
  235. {
  236.     InterlockedIncrement(&m_cRef);
  237.     return m_cRef;         
  238. }
  239.  
  240. //+-------------------------------------------------------------------------
  241. //
  242. //    Function: CAppMessageSink::Release
  243. //
  244. //    Synopsis: Decrements reference count, deletes object if it == 0.
  245. //
  246. //    Arguments: none
  247. //
  248. //     Returns: ULONG - Current reference count
  249. //                
  250. //---------------------------------------------------------------------------
  251. STDMETHODIMP_(ULONG)
  252. CAppMessageSink::Release()
  253. {
  254.     if (InterlockedDecrement(&m_cRef) == 0)
  255.     {
  256.         delete this;
  257.         return(0);
  258.     }
  259.     return m_cRef;
  260. }            
  261.  
  262. //+-------------------------------------------------------------------------
  263. //
  264. //    Function: CAppMessageSink::HandleMessage
  265. //
  266. //    Synopsis: Message sink attatched to the Forms manager.  Handles the 
  267. //        WM_SPCH_NOTIFY messages and detects when someone changes the 
  268. //        feedback level outside our application.
  269. //
  270. //    Arguments:    IDispatch* - Pointer to control calling this method
  271. //                LONG uMsg - Win32 Message
  272. //                LONG wParam - Message parameter
  273. //                LONG lParam - Message parameter
  274. //
  275. //     Returns: S_FALSE - keeps messages going down the pipeline
  276. //                
  277. //---------------------------------------------------------------------------
  278. STDMETHODIMP 
  279. CAppMessageSink::HandleMessage(IDispatch* pdispControl, LONG uMsg, LONG wParam, LONG lParam)
  280. {
  281.     switch(uMsg)
  282.     {
  283.     default:
  284.         break;
  285.  
  286.     case WM_SPCH_NOTIFY:    // Notifications from TTS engine
  287.         switch(wParam)
  288.         {
  289.         default:
  290.             break;
  291.  
  292.         case VTXTF_SPEAKDONE:    // When a TTS phrase is done, this is called
  293.             g_pApp->OnSpeakDone();    // Call a CTTSApp function to handle this
  294.             break;
  295.             
  296.         case VTXTF_SPEAK:    // Messages fired while TTS engine is speaking, holds 
  297.                             // the bookmark ID passed to the Speak function
  298.             g_pApp->SetFocusOnId(lParam);    // in this App, the bookmark ID is the 
  299.             break;                            // ID of the menu item about to be said
  300.         } //end switch(wParam)
  301.         break;
  302.  
  303.     case WM_SETTINGCHANGE:        // Fired when a system setting changed
  304.         if(wParam == SPI_SETAPCFEEDBACK) g_pApp->GetFeedbackLevels();    // Feedback level changed
  305.         break;                                                            // Refresh our applications variables
  306.  
  307.     } //end switch(uMsg)
  308.  
  309.     return S_FALSE; // return S_FALSE to keep message going on its way down the hiarchy
  310. }
  311.  
  312. //+-------------------------------------------------------------------------
  313. //
  314. //    Function: CAppMessageSink::ReceiveMsg
  315. //
  316. //    Synopsis: Event sink attatched to the Forms manager.  We don'e handle any 
  317. //        of the events in this function right now.
  318. //    
  319. //    Arguments:    LONG uMsg - Win32 Message
  320. //                LONG wParam - Message parameter
  321. //                LONG lParam - Message parameter
  322. //
  323. //     Returns: S_FALSE - keeps messages going down the pipe.
  324. //                
  325. //---------------------------------------------------------------------------
  326. STDMETHODIMP CAppMessageSink::ReceiveMsg(long uMsg, long wParam, long lParam)
  327. {
  328.     return S_FALSE;
  329. }
  330.  
  331.  
  332.  
  333.