Source code of Windows XP (NT5)
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.

228 lines
5.6 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. int lstrncmpi (OLECHAR * first, OLECHAR * second, long ncount)
  112. {
  113. for (long i=0; i<ncount; i++) {
  114. if (towupper (first[i]) != towupper(second[i]))
  115. if (towupper (first[i]) > towupper(second[i]))
  116. return 1;
  117. else
  118. return -1;
  119. }
  120. return 0;
  121. }
  122. HRESULT CMMCTask::SetScript (LPOLESTR szScript)
  123. {
  124. FreeActions ();
  125. // look for "VBSCRIPT:", "JSCRIPT:" and "JAVASCRIPT:"
  126. if (!lstrncmpi (L"VBSCRIPT:", szScript, 9)) {
  127. m_bstrLanguage = SysAllocString (L"VBSCRIPT");
  128. szScript += 9;
  129. } else
  130. if (!lstrncmpi (L"JSCRIPT:", szScript, 8)) {
  131. m_bstrLanguage = SysAllocString (L"JSCRIPT");
  132. szScript += 8;
  133. } else
  134. if (!lstrncmpi (L"JAVASCRIPT:", szScript, 11)) {
  135. m_bstrLanguage = SysAllocString (L"JAVASCRIPT");
  136. szScript += 11;
  137. } else {
  138. m_bstrLanguage = SysAllocString (L"JAVASCRIPT");
  139. }
  140. if (!m_bstrLanguage)
  141. return E_OUTOFMEMORY;
  142. m_bstrScript = SysAllocString (szScript);
  143. if (m_bstrScript == NULL)
  144. return E_OUTOFMEMORY;
  145. m_type = MMC_ACTION_SCRIPT;
  146. return S_OK;
  147. }
  148. HRESULT CMMCTask::SetActionURL (LPOLESTR szActionURL)
  149. {
  150. FreeActions ();
  151. m_bstrActionURL = SysAllocString (szActionURL);
  152. if (m_bstrActionURL == NULL)
  153. return E_OUTOFMEMORY;
  154. m_type = MMC_ACTION_LINK;
  155. return S_OK;
  156. }
  157. HRESULT CMMCTask::SetCommandID (LONG_PTR nID)
  158. {
  159. FreeActions ();
  160. m_ID = nID;
  161. m_type = MMC_ACTION_ID;
  162. return S_OK;
  163. }
  164. HRESULT CMMCTask::SetActionType(long nType)
  165. {
  166. m_type = nType;
  167. return S_OK;
  168. }
  169. HRESULT CMMCTask::SetHelp (LPOLESTR szHelp)
  170. {
  171. if (m_bstrHelp) SysFreeString (m_bstrHelp);
  172. m_bstrHelp = SysAllocString (szHelp);
  173. if (!m_bstrHelp)
  174. return E_OUTOFMEMORY;
  175. return S_OK;
  176. }
  177. HRESULT CMMCTask::SetText (LPOLESTR szText)
  178. {
  179. if (m_bstrText) SysFreeString (m_bstrText);
  180. m_bstrText = SysAllocString (szText);
  181. if (!m_bstrText)
  182. return E_OUTOFMEMORY;
  183. return S_OK;
  184. }
  185. HRESULT CMMCTask::SetClsid(LPOLESTR szClsid)
  186. {
  187. if (m_bstrClsid) SysFreeString (m_bstrClsid);
  188. m_bstrClsid = SysAllocString (szClsid);
  189. if (!m_bstrClsid)
  190. return E_OUTOFMEMORY;
  191. return S_OK;
  192. }
  193. void CMMCTask::FreeActions ()
  194. {
  195. if (m_bstrLanguage) {
  196. SysFreeString (m_bstrLanguage);
  197. m_bstrLanguage = NULL;
  198. }
  199. if (m_bstrScript) {
  200. SysFreeString(m_bstrScript);
  201. m_bstrScript = NULL;
  202. }
  203. if (m_bstrActionURL) {
  204. SysFreeString(m_bstrActionURL);
  205. m_bstrActionURL = NULL;
  206. }
  207. m_ID = 0;
  208. m_type = MMC_ACTION_UNINITIALIZED;
  209. }