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.

226 lines
5.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: mmctask.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // MMCTask.cpp : Implementation of CMMCTask
  11. #include "stdafx.h"
  12. #include "cic.h"
  13. #include "MMCTask.h"
  14. #include "DispObj.h"
  15. #include "mmc.h"
  16. #include <wtypes.h>
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMMCTask
  19. CMMCTask::CMMCTask()
  20. {
  21. m_ID = 0;
  22. m_bstrClsid = m_bstrScript = m_bstrLanguage =
  23. m_bstrActionURL = m_bstrHelp = m_bstrText = NULL;
  24. m_type = MMC_ACTION_UNINITIALIZED;
  25. }
  26. CMMCTask::~CMMCTask()
  27. {
  28. if (m_bstrScript) SysFreeString(m_bstrScript);
  29. if (m_bstrActionURL) SysFreeString(m_bstrActionURL);
  30. if (m_bstrHelp) SysFreeString(m_bstrHelp);
  31. if (m_bstrText) SysFreeString(m_bstrText);
  32. if (m_bstrClsid) SysFreeString(m_bstrClsid);
  33. }
  34. STDMETHODIMP CMMCTask::get_DisplayObject (IDispatch** pDispatch)
  35. {
  36. IDispatchPtr spDispatch = m_spDisplayObject;
  37. *pDispatch = spDispatch.Detach();
  38. return S_OK;
  39. }
  40. HRESULT CMMCTask::SetDisplayObject (MMC_TASK_DISPLAY_OBJECT* pdo)
  41. {
  42. HRESULT hr = S_OK;
  43. CComObject<class CMMCDisplayObject>* cdo = NULL;
  44. CComObject<CMMCDisplayObject>::CreateInstance(&cdo);
  45. if (!cdo)
  46. hr = E_OUTOFMEMORY;
  47. else {
  48. hr = cdo->Init (pdo);
  49. m_spDisplayObject = cdo;
  50. }
  51. return hr;
  52. }
  53. STDMETHODIMP CMMCTask::get_Text(BSTR * pVal)
  54. {
  55. if (m_bstrText)
  56. *pVal = SysAllocString ((const OLECHAR *)m_bstrText);
  57. return S_OK;
  58. }
  59. STDMETHODIMP CMMCTask::get_Help(BSTR * pVal)
  60. {
  61. if (m_bstrHelp)
  62. *pVal = SysAllocString ((const OLECHAR *)m_bstrHelp);
  63. return S_OK;
  64. }
  65. STDMETHODIMP CMMCTask::get_ActionType(long * pVal)
  66. {
  67. *pVal = m_type;
  68. return S_OK;
  69. }
  70. STDMETHODIMP CMMCTask::get_CommandID(LONG_PTR * pVal)
  71. {
  72. _ASSERT (m_type == MMC_ACTION_ID);
  73. if (m_type != MMC_ACTION_ID)
  74. return E_UNEXPECTED;
  75. *pVal = m_ID;
  76. return S_OK;
  77. }
  78. STDMETHODIMP CMMCTask::get_ActionURL(BSTR * pVal)
  79. {
  80. _ASSERT (m_type == MMC_ACTION_LINK);
  81. if (m_type != MMC_ACTION_LINK)
  82. return E_UNEXPECTED;
  83. if (m_bstrActionURL)
  84. *pVal = SysAllocString ((const OLECHAR *)m_bstrActionURL);
  85. return S_OK;
  86. }
  87. STDMETHODIMP CMMCTask::get_Clsid(BSTR * pVal)
  88. {
  89. if (m_bstrClsid)
  90. *pVal = SysAllocString ((const OLECHAR *)m_bstrClsid);
  91. return S_OK;
  92. }
  93. STDMETHODIMP CMMCTask::get_Script(BSTR * pVal)
  94. {
  95. _ASSERT (m_type == MMC_ACTION_SCRIPT);
  96. if (m_type != MMC_ACTION_SCRIPT)
  97. return E_UNEXPECTED;
  98. if (m_bstrScript)
  99. *pVal = SysAllocString ((const OLECHAR *)m_bstrScript);
  100. return S_OK;
  101. }
  102. STDMETHODIMP CMMCTask::get_ScriptLanguage(BSTR *pVal)
  103. {
  104. _ASSERT (m_type == MMC_ACTION_SCRIPT);
  105. if (m_type != MMC_ACTION_SCRIPT)
  106. return E_UNEXPECTED;
  107. if (m_bstrLanguage)
  108. *pVal = SysAllocString ((const OLECHAR *)m_bstrLanguage);
  109. return S_OK;
  110. }
  111. HRESULT CMMCTask::SetScript (LPOLESTR szScript)
  112. {
  113. FreeActions ();
  114. // look for "VBSCRIPT:", "JSCRIPT:" and "JAVASCRIPT:"
  115. WCHAR szVBScriptColon[] = L"VBSCRIPT:";
  116. WCHAR szJScriptColon[] = L"JSCRIPT:";
  117. WCHAR szJavaScriptColon[] = L"JAVASCRIPT:";
  118. if (0==_wcsnicmp(szVBScriptColon, szScript, wcslen(szVBScriptColon)))
  119. {
  120. m_bstrLanguage = SysAllocString (L"VBSCRIPT");
  121. szScript += wcslen(szVBScriptColon);
  122. }
  123. else if (0==_wcsnicmp(szJScriptColon, szScript, wcslen(szJScriptColon)))
  124. {
  125. m_bstrLanguage = SysAllocString (L"JSCRIPT");
  126. szScript += wcslen(szJScriptColon);
  127. }
  128. else if (0==_wcsnicmp (szJavaScriptColon, szScript, wcslen(szJavaScriptColon)))
  129. {
  130. m_bstrLanguage = SysAllocString (L"JAVASCRIPT");
  131. szScript += wcslen(szJavaScriptColon);
  132. } else
  133. {
  134. m_bstrLanguage = SysAllocString (L"JAVASCRIPT");
  135. }
  136. if (!m_bstrLanguage)
  137. return E_OUTOFMEMORY;
  138. m_bstrScript = SysAllocString (szScript);
  139. if (m_bstrScript == NULL)
  140. return E_OUTOFMEMORY;
  141. m_type = MMC_ACTION_SCRIPT;
  142. return S_OK;
  143. }
  144. HRESULT CMMCTask::SetActionURL (LPOLESTR szActionURL)
  145. {
  146. FreeActions ();
  147. m_bstrActionURL = SysAllocString (szActionURL);
  148. if (m_bstrActionURL == NULL)
  149. return E_OUTOFMEMORY;
  150. m_type = MMC_ACTION_LINK;
  151. return S_OK;
  152. }
  153. HRESULT CMMCTask::SetCommandID (LONG_PTR nID)
  154. {
  155. FreeActions ();
  156. m_ID = nID;
  157. m_type = MMC_ACTION_ID;
  158. return S_OK;
  159. }
  160. HRESULT CMMCTask::SetActionType(long nType)
  161. {
  162. m_type = nType;
  163. return S_OK;
  164. }
  165. HRESULT CMMCTask::SetHelp (LPOLESTR szHelp)
  166. {
  167. if (m_bstrHelp) SysFreeString (m_bstrHelp);
  168. m_bstrHelp = SysAllocString (szHelp);
  169. if (!m_bstrHelp)
  170. return E_OUTOFMEMORY;
  171. return S_OK;
  172. }
  173. HRESULT CMMCTask::SetText (LPOLESTR szText)
  174. {
  175. if (m_bstrText) SysFreeString (m_bstrText);
  176. m_bstrText = SysAllocString (szText);
  177. if (!m_bstrText)
  178. return E_OUTOFMEMORY;
  179. return S_OK;
  180. }
  181. HRESULT CMMCTask::SetClsid(LPOLESTR szClsid)
  182. {
  183. if (m_bstrClsid) SysFreeString (m_bstrClsid);
  184. m_bstrClsid = SysAllocString (szClsid);
  185. if (!m_bstrClsid)
  186. return E_OUTOFMEMORY;
  187. return S_OK;
  188. }
  189. void CMMCTask::FreeActions ()
  190. {
  191. if (m_bstrLanguage) {
  192. SysFreeString (m_bstrLanguage);
  193. m_bstrLanguage = NULL;
  194. }
  195. if (m_bstrScript) {
  196. SysFreeString(m_bstrScript);
  197. m_bstrScript = NULL;
  198. }
  199. if (m_bstrActionURL) {
  200. SysFreeString(m_bstrActionURL);
  201. m_bstrActionURL = NULL;
  202. }
  203. m_ID = 0;
  204. m_type = MMC_ACTION_UNINITIALIZED;
  205. }