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.

186 lines
7.1 KiB

  1. /******************************************************************************
  2. * Comp.h
  3. * This module contains the base definitions for the SAPI 5 Grammar
  4. * portion of the GramComp application.
  5. *
  6. * Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
  7. ******************************************************************************/
  8. #ifndef __COMPILER__CLASS__
  9. #define __COMPILER__CLASS__
  10. #define MAX_LOADSTRING 100
  11. // Helper function
  12. inline char ConfidenceGroupChar(char Confidence)
  13. {
  14. switch (Confidence)
  15. {
  16. case SP_LOW_CONFIDENCE:
  17. return '-';
  18. case SP_NORMAL_CONFIDENCE:
  19. return ' ';
  20. case SP_HIGH_CONFIDENCE:
  21. return '+';
  22. default:
  23. _ASSERTE(false);
  24. return '?';
  25. }
  26. }
  27. //--- Class, Struct and Union Definitions -------------------------------------
  28. class CCompiler : public ISpErrorLog
  29. {
  30. public:
  31. CCompiler(HINSTANCE hInstance): m_hInstance(hInstance),
  32. m_hWnd(NULL),
  33. m_hAccelTable(0),
  34. m_hrWorstError(S_OK),
  35. m_hDlg(NULL),
  36. m_fNeedStartCompile(TRUE),
  37. m_fSilent(FALSE),
  38. m_fCommandLine(FALSE),
  39. m_fGenerateHeader(FALSE),
  40. m_fGotReco(FALSE),
  41. m_hWndEdit(NULL),
  42. m_hWndStatus(NULL),
  43. m_hMod(0)
  44. {
  45. m_szXMLSrcFile[0] = 0;
  46. m_szCFGDestFile[0] = 0;
  47. m_szHeaderDestFile[0] = 0;
  48. }
  49. ~CCompiler();
  50. STDMETHODIMP QueryInterface(REFIID riid, void ** ppv)
  51. {
  52. if (riid == __uuidof(IUnknown) ||
  53. riid == __uuidof(ISpErrorLog))
  54. {
  55. *ppv = (ISpErrorLog *)this;
  56. return S_OK;
  57. }
  58. *ppv = NULL;
  59. return E_NOINTERFACE;
  60. }
  61. STDMETHODIMP_(ULONG) AddRef()
  62. {
  63. return 2;
  64. }
  65. STDMETHODIMP_(ULONG) Release()
  66. {
  67. return 1;
  68. }
  69. HRESULT Initialize( int nCmdShow );
  70. int Run();
  71. static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  72. static LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  73. static LRESULT CALLBACK Find(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  74. static LRESULT CALLBACK Goto(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  75. static LRESULT CALLBACK TestGrammar(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  76. void AddStatus(HRESULT hr, UINT uID, const TCHAR * pFmtString = NULL);
  77. STDMETHODIMP AddError(const long lLine, HRESULT hr, const WCHAR * pszDescription, const WCHAR * pszHelpFile, DWORD dwHelpContext);
  78. HRESULT EnterIdle();
  79. HRESULT LoadGrammar(TCHAR* szPath);
  80. HRESULT WriteStream(IStream * pStream, const char * pszText);
  81. HRESULT StripWrite(IStream * pStream, const char * pszText);
  82. BOOL CallOpenFileDialog( HWND hWnd, LPSTR szFileName, TCHAR* szFilter );
  83. BOOL CallSaveFileDialog( HWND hWnd, TCHAR* szSaveFile );
  84. HRESULT FileSave( HWND hWnd, CCompiler* pComp, TCHAR* szSaveFile );
  85. HRESULT Compile( HWND hWnd, TCHAR* szSaveFileName, TCHAR* szTitle, CCompiler* pComp );
  86. void RecoEvent( HWND hDlg, CCompiler* pComp );
  87. HRESULT EmulateRecognition( WCHAR *pszText );
  88. void Recognize( HWND hDlg, CCompiler &rComp, CSpEvent &rEvent );
  89. HRESULT ConstructPropertyDisplay(const SPPHRASEELEMENT *pElem, const SPPHRASEPROPERTY *pProp,
  90. CSpDynamicString & dstr, ULONG ulLevel);
  91. HRESULT ConstructRuleDisplay(const SPPHRASERULE *pRule, CSpDynamicString &dstr, ULONG ulLevel);
  92. inline void AddInternalError(HRESULT hr, UINT uID, const TCHAR * pFmtString = NULL)
  93. {
  94. if (hr != S_OK)
  95. {
  96. AddStatus(hr, uID, pFmtString);
  97. }
  98. }
  99. // Member functions for the command line version of the application
  100. BOOL InitDialog(HWND);
  101. static int CALLBACK CCompiler::DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  102. public:
  103. const HINSTANCE m_hInstance; // Instance handle of process
  104. HWND m_hWnd; // Window handle of dialog
  105. HACCEL m_hAccelTable; // Handle to the accelerators
  106. BOOL m_fNeedStartCompile; // Need a recompile?
  107. BOOL m_fSilent; // Silent or non-silent mode
  108. BOOL m_fCommandLine; // App being run from command line?
  109. BOOL m_fGenerateHeader; // Create a header file from compilation?
  110. BOOL m_fGotReco; // Was a recognition received?
  111. HWND m_hDlg; // Window handle of command line compile dialog
  112. HWND m_hWndEdit; // Window handle of main edit window
  113. HWND m_hWndStatus; // Window handle of compile status window
  114. HRESULT m_hrWorstError; // Error code from compiler
  115. HMODULE m_hMod; // Handle to the rich edit control
  116. CComPtr<ISpErrorLog> m_cpError; // Error log object
  117. CComPtr<ISpGrammarCompiler> m_cpCompiler; // Grammar compiler interface
  118. CComPtr<ISpRecoGrammar> m_cpRecoGrammar; // Grammar compiler interface
  119. CComPtr<IRichEditOle> m_cpRichEdit; // OLE interface to the rich edit control
  120. CComPtr<ITextDocument> m_cpTextDoc; // Rich edit control interface
  121. CComPtr<ITextSelection> m_cpTextSel; // Rich edit control interface
  122. CComPtr<ISpRecognizer> m_cpRecognizer; // SR engine interface
  123. CComPtr<ISpRecoContext> m_cpRecoContext; // SR engine interface
  124. TCHAR m_szXMLSrcFile[MAX_PATH]; // Path to xml source file
  125. TCHAR m_szCFGDestFile[MAX_PATH]; // Output location for cfg file
  126. TCHAR m_szHeaderDestFile[MAX_PATH]; // Output location for header file
  127. CSpDynamicString m_dstr;
  128. };
  129. class CError : public ISpErrorLog
  130. {
  131. public:
  132. CError() : m_pszFileName(NULL) {};
  133. CError(const char * pszFileName)
  134. {
  135. m_pszFileName = pszFileName;
  136. }
  137. STDMETHODIMP QueryInterface(REFIID riid, void ** ppv)
  138. {
  139. if (riid == __uuidof(IUnknown) ||
  140. riid == __uuidof(ISpErrorLog))
  141. {
  142. *ppv = (ISpErrorLog *)this;
  143. return S_OK;
  144. }
  145. *ppv = NULL;
  146. return E_NOINTERFACE;
  147. }
  148. STDMETHODIMP_(ULONG) AddRef()
  149. {
  150. return 2;
  151. }
  152. STDMETHODIMP_(ULONG) Release()
  153. {
  154. return 1;
  155. }
  156. // -- ISpErrorLog
  157. STDMETHODIMP AddError(const long lLine, HRESULT hr, const WCHAR * pszDescription, const WCHAR * pszHelpFile, DWORD dwHelpContext);
  158. // -- local
  159. HRESULT Init(const char *pszFileName);
  160. // --- data members
  161. const char * m_pszFileName;
  162. };
  163. #endif // Must be the last line of this file.