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.

205 lines
7.9 KiB

  1. /*******************************************************************************
  2. * SRDlg.h *
  3. *------------*
  4. * Description:
  5. * This is the header file for the default voice dialog.
  6. *-------------------------------------------------------------------------------
  7. * Created By: MIKEAR Date: 11/17/98
  8. * Copyright (C) 1998 Microsoft Corporation
  9. * All Rights Reserved
  10. *
  11. *-------------------------------------------------------------------------------
  12. * Revisions:
  13. * BRENTMID 11/29/1999 - Redesigned UI to match functional spec.
  14. *
  15. *******************************************************************************/
  16. #ifndef _SRDlg_h
  17. #define _SRDlg_h
  18. #include "audiodlg.h"
  19. // External Declarations
  20. class CEnvrDlg;
  21. class CEnvrPropDlg;
  22. #define IDH_NOHELP -1
  23. #define CPL_HELPFILE L"sapicpl.hlp"
  24. #define WM_RECOEVENT WM_APP // Window message used for recognition events
  25. // Constant Declarations
  26. const int iMaxColLength_c = 255;
  27. const int iMaxAddedProfiles_c = 100; // maximum number of profiles a user can add
  28. // in one session
  29. const int iMaxDeletedProfiles_c = 100; // maximum number of profiles a user can delete
  30. // and rollback in one session
  31. // Typedefs
  32. typedef enum EPD_RETURN_VALUE
  33. {
  34. EPD_OK,
  35. EPD_DUP,
  36. EPD_EMPTY_NAME,
  37. EPD_FAILED
  38. } EPD_RETURN_VALUE;
  39. typedef enum SRDLGUPDATEFLAGS
  40. {
  41. SRDLGF_RECOGNIZER = 0x01,
  42. SRDLGF_AUDIOINPUT = 0x02,
  43. SRDLGF_ALL =0x03
  44. } SRDLGUPDATEFLAGS;
  45. // Class Declarations
  46. class CSRDlg
  47. {
  48. private:
  49. HACCEL m_hAccelTable;
  50. HWND m_hDlg;
  51. HWND m_hSRCombo; // engine selection combobox
  52. HWND m_hUserList; // user selection window
  53. BOOL m_fDontDelete;
  54. BOOL m_bInitEngine; // has the default engine been initialized
  55. BOOL m_bPreferredDevice;
  56. CComPtr<ISpRecognizer> m_cpRecoEngine;
  57. CComPtr<ISpRecoContext> m_cpRecoCtxt; // Recognition context
  58. CAudioDlg *m_pAudioDlg;
  59. ISpObjectToken *m_pCurRecoToken; // holds the token for the currently selected engine
  60. CSpDynamicString m_dstrOldUserTokenId;
  61. // the original user token ID - need to revert to this on Cancel
  62. ISpObjectToken* m_aDeletedTokens[iMaxDeletedProfiles_c];
  63. // array holding the tokens
  64. int m_iDeletedTokens; // holds the number of currently deleted tokens
  65. CSpDynamicString m_aAddedTokens[ iMaxAddedProfiles_c ];
  66. int m_iAddedTokens;
  67. int m_iLastSelected; // index of the previously selected item
  68. WCHAR m_szCaption[ MAX_LOADSTRING ];
  69. HRESULT CreateRecoContext(BOOL *pfContextInitialized = NULL, BOOL fInitialize = FALSE, ULONG ulFlags = SRDLGF_ALL);
  70. void RecoEvent();
  71. void PopulateList(); // Populates the list
  72. void InitUserList(HWND hWnd); // initializes user profile list
  73. void ProfileProperties(); // Modifies the profile properties through engine UI
  74. void DrawItemColumn(HDC hdc, WCHAR* lpsz, LPRECT prcClip);
  75. CSpDynamicString CalcStringEllipsis(HDC hdc, CSpDynamicString lpszString, int cchMax, UINT uColWidth);
  76. void SetCheckmark( HWND hList, int iIndex, bool bCheck );
  77. HRESULT UserPropDlg( ISpObjectToken * pToken); // user wants to add a new profile
  78. public:
  79. CSRDlg() :
  80. m_hAccelTable( NULL ),
  81. m_hDlg( NULL ),
  82. m_hSRCombo( NULL ),
  83. m_hUserList( NULL ),
  84. m_fDontDelete( FALSE ),
  85. m_bInitEngine( FALSE ),
  86. m_bPreferredDevice( TRUE ),
  87. m_cpRecoEngine( NULL ),
  88. m_cpRecoCtxt( NULL ),
  89. m_pAudioDlg(NULL),
  90. m_pCurRecoToken( NULL ),
  91. m_dstrOldUserTokenId( (WCHAR *) NULL ),
  92. m_iDeletedTokens( 0 ),
  93. m_iAddedTokens( 0 ),
  94. m_pCurUserToken( NULL ),
  95. m_pDefaultRecToken( NULL )
  96. {
  97. ::memset( m_aAddedTokens, 0, sizeof( CSpDynamicString ) * iMaxAddedProfiles_c );
  98. }
  99. ~CSRDlg()
  100. {
  101. if ( m_pAudioDlg )
  102. {
  103. delete m_pAudioDlg;
  104. }
  105. }
  106. ISpObjectToken *m_pCurUserToken; // currently selected user token
  107. ISpObjectToken *m_pDefaultRecToken; // current default recognizer token.
  108. // This is the token of the engine that is
  109. // currently running (except for temporary switches
  110. // in order to train non-default engines.
  111. void CreateNewUser(); // Adds a new speech user profile to the registry
  112. void DeleteCurrentUser(); // Deletes the current user
  113. void OnCancel(); // Handles undoing the changes to the settings
  114. void UserSelChange( int iSelIndex);
  115. // Handles a new selection
  116. void OnDrawItem( HWND hWnd, const DRAWITEMSTRUCT * pDrawStruct ); // handles item drawing
  117. void OnApply();
  118. void OnDestroy();
  119. void OnInitDialog(HWND hWnd);
  120. void ChangeDefaultUser(); // Changes the default user in the registry
  121. void ShutDown(); // Shuts off the engine
  122. void EngineSelChange(BOOL fInitialize = FALSE);
  123. HRESULT IsCurRecoEngineAndCurRecoTokenMatch( bool *pfMatch );
  124. HRESULT TrySwitchDefaultEngine( bool fShowErrorMessages = false );
  125. HRESULT ResetDefaultEngine( bool fShowErrorMessages = true);
  126. bool IsRecoTokenCurrentlyBeingUsed( ISpObjectToken *pRecoToken );
  127. bool HasRecognizerChanged();
  128. void KickCPLUI(); // Looks at the current requested defaults
  129. // and decides if "Apply" needs to be enabled
  130. void RecoContextError( BOOL fRecoContextExists = FALSE, BOOL fGiveErrorMessage = TRUE,
  131. HRESULT hrRelevantError = E_FAIL );
  132. UINT HRESULTToErrorID( HRESULT hr );
  133. bool IsProfileNameInvisible( WCHAR *pwszProfile );
  134. HWND GetHDlg() { return m_hDlg; }
  135. ISpRecognizer *GetRecognizer() { return m_cpRecoEngine; }
  136. ISpRecoContext *GetRecoContext() { return m_cpRecoCtxt; }
  137. BOOL IsPreferredDevice() { return m_bPreferredDevice; }
  138. void SetPreferredDevice( BOOL b ) { m_bPreferredDevice = b; }
  139. friend INT_PTR CALLBACK SRDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  140. friend CEnvrPropDlg;
  141. };
  142. // Function Declarations
  143. INT_PTR CALLBACK SRDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  144. class CEnvrPropDlg
  145. {
  146. public:
  147. CSRDlg * m_pParent;
  148. HWND m_hDlg;
  149. CComPtr<ISpObjectToken> m_cpToken;
  150. int m_isModify; // is this a new profile or a modify of an old profile
  151. CEnvrPropDlg(CSRDlg * pParent, ISpObjectToken * pToken) :
  152. m_cpToken(pToken),
  153. m_pParent(pParent)
  154. {
  155. CSpUnicodeSupport unicode;
  156. m_hinstRichEdit = unicode.LoadLibrary(L"riched20.dll");
  157. m_hDlg = NULL;
  158. m_isModify = 0;
  159. }
  160. ~CEnvrPropDlg()
  161. {
  162. FreeLibrary(m_hinstRichEdit);
  163. }
  164. BOOL InitDialog(HWND hDlg);
  165. EPD_RETURN_VALUE ApplyChanges();
  166. static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  167. private:
  168. HINSTANCE m_hinstRichEdit; // used to allow rich edit controls
  169. };
  170. // Function Declarations
  171. // Callback function to handle windows messages
  172. INT_PTR CALLBACK EnvrDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  173. // Globals
  174. extern CSRDlg *g_pSRDlg;
  175. extern CEnvrDlg *g_pEnvrDlg;
  176. #endif