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.

301 lines
8.5 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1997 - 1999
  4. Module Name:
  5. MachineEnumTask.cpp
  6. Abstract:
  7. This class implements the CMachineEnumTask class, an enumerator for
  8. tasks the NAP snapin will add to the main IAS taskpad.
  9. Revision History:
  10. mmaguire 03/06/98 - created from IAS taskpad code
  11. --*/
  12. //////////////////////////////////////////////////////////////////////////////
  13. //////////////////////////////////////////////////////////////////////////////
  14. // BEGIN INCLUDES
  15. //
  16. // standard includes:
  17. //
  18. #include "Precompiled.h"
  19. //
  20. // where we can find declaration for main class in this file:
  21. //
  22. #include "MachineEnumTask.h"
  23. //
  24. // where we can find declarations needed in this file:
  25. //
  26. #include "MachineNode.h"
  27. //
  28. // END INCLUDES
  29. //////////////////////////////////////////////////////////////////////////////
  30. //////////////////////////////////////////////////////////////////////////////
  31. /*++
  32. CMachineEnumTask::CMachineEnumTask
  33. Constructor
  34. --*/
  35. //////////////////////////////////////////////////////////////////////////////
  36. CMachineEnumTask::CMachineEnumTask( CMachineNode * pMachineNode )
  37. {
  38. TRACE_FUNCTION("CMachineEnumTask::CMachineEnumTask");
  39. // Check for preconditions.
  40. _ASSERTE( pMachineNode != NULL );
  41. m_pMachineNode = pMachineNode;
  42. }
  43. //////////////////////////////////////////////////////////////////////////////
  44. /*++
  45. CMachineEnumTask::CMachineEnumTask
  46. Constructor
  47. --*/
  48. //////////////////////////////////////////////////////////////////////////////
  49. CMachineEnumTask::CMachineEnumTask()
  50. {
  51. TRACE_FUNCTION("CMachineEnumTask::CMachineEnumTask");
  52. }
  53. //////////////////////////////////////////////////////////////////////////////
  54. /*++
  55. CMachineEnumTask::Init
  56. Here is where we see what taskpad we are providing tasks for.
  57. In our case we know that we only have one taskpad.
  58. The string we test for is "CMTP1". This was the string following the '#'
  59. that we passed in GetResultViewType.
  60. --*/
  61. //////////////////////////////////////////////////////////////////////////////
  62. STDMETHODIMP CMachineEnumTask::Init (IDataObject * pdo, LPOLESTR szTaskGroup)
  63. {
  64. TRACE_FUNCTION("CMachineEnumTask::Init");
  65. // Return ok, if we can handle data object and group.
  66. if( !lstrcmp(szTaskGroup, L"CMTP1") )
  67. {
  68. m_type = 1; // default tasks
  69. }
  70. else
  71. {
  72. _ASSERTE(FALSE);
  73. }
  74. return S_OK;
  75. }
  76. //////////////////////////////////////////////////////////////////////////////
  77. /*++
  78. CMachineEnumTask::Next
  79. We get called here over and over untill we have no more tasks to provide.
  80. Other tasks may still appear on our taskpad as a result of what extensions add.
  81. --*/
  82. //////////////////////////////////////////////////////////////////////////////
  83. STDMETHODIMP CMachineEnumTask::Next (ULONG celt, MMC_TASK *rgelt, ULONG *pceltFetched)
  84. {
  85. TRACE_FUNCTION("CMachineEnumTask::Next");
  86. // Caller alloc's array of MMC_TASKs.
  87. // Callee fills MMC_TASK elements (via CoTaskMemAlloc).
  88. // Check for preconditions.
  89. if ((rgelt == NULL) || (pceltFetched == NULL))
  90. {
  91. return E_INVALIDARG;
  92. }
  93. _ASSERTE(!IsBadWritePtr (rgelt, celt*sizeof(MMC_TASK)));
  94. _ASSERTE(!IsBadWritePtr (pceltFetched, sizeof(ULONG)));
  95. _ASSERTE( m_type == 1 );
  96. _ASSERTE( m_pMachineNode != NULL );
  97. UINT uintTextResourceID;
  98. UINT uintHelpTextResourceID;
  99. TCHAR lpszTemp[IAS_MAX_STRING];
  100. int nLoadStringResult;
  101. // Setup a path to resources used in each case.
  102. // In each case, we are constructing a string pointing to the resource
  103. // of the form: "res://D:\MyPath\MySnapin.dll/img\SomeImage.bmp"
  104. // Make the mouse over bitmap address.
  105. OLECHAR szMouseOverBuffer[MAX_PATH*2]; // A little extra.
  106. lstrcpy (szMouseOverBuffer, L"res://");
  107. HINSTANCE hInstance = _Module.GetModuleInstance();
  108. ::GetModuleFileName (hInstance, szMouseOverBuffer + lstrlen(szMouseOverBuffer), MAX_PATH);
  109. OLECHAR * szMouseOverBufferAfterFileName = szMouseOverBuffer + lstrlen(szMouseOverBuffer);
  110. // Make a copy of the string we built above for the mouse off bitmap address.
  111. OLECHAR szMouseOffBuffer[MAX_PATH*2]; // A little extra.
  112. lstrcpy( szMouseOffBuffer, szMouseOverBuffer );
  113. OLECHAR * szMouseOffBufferAfterFileName = szMouseOffBuffer + lstrlen(szMouseOffBuffer);
  114. // celt will actually always only be 1
  115. for (ULONG i=0; i<celt; i++)
  116. {
  117. // make an MMC_TASK pointer to make life easier below.
  118. MMC_TASK * task = &rgelt[i];
  119. // Add action.
  120. task->eActionType = MMC_ACTION_ID;
  121. task->sDisplayObject.eDisplayType = MMC_TASK_DISPLAY_TYPE_BITMAP; // Non-transparent raster.
  122. // Decide on the appropriate resource to use based on m_index,
  123. // which tells us which task we are enumerating.
  124. switch( m_index )
  125. {
  126. case 0:
  127. // if( m_pMachineNode->m_fClientAdded )
  128. // {
  129. // lstrcpy (szBufferAfterFileName , L"/img\\TaskClientDone.bmp");
  130. // }
  131. // else
  132. // {
  133. lstrcpy (szMouseOverBufferAfterFileName , L"/img\\TaskDefineNAPMouseOver.gif");
  134. lstrcpy (szMouseOffBufferAfterFileName , L"/img\\TaskDefineNAP.gif");
  135. // }
  136. uintTextResourceID = IDS_TASKPAD_TEXT__DEFINE_NETWORK_ACCCESS_POLICY;
  137. uintHelpTextResourceID = IDS_TASKPAD_HELP_TEXT__DEFINE_NETWORK_ACCCESS_POLICY;
  138. task->nCommandID = MACHINE_TASK__DEFINE_NETWORK_ACCESS_POLICY; // Set the task identifier.
  139. break;
  140. default:
  141. // Problem -- we only have the tasks listed above.
  142. if (pceltFetched)
  143. {
  144. *pceltFetched = i; // Note that this is accurate because i above is zero based.
  145. }
  146. return S_FALSE; // Failed to enumerate any more tasks.
  147. break;
  148. }
  149. task->sDisplayObject.uBitmap.szMouseOverBitmap = (LPOLESTR) CoTaskMemAlloc( sizeof(OLECHAR)*(lstrlen(szMouseOverBuffer)+1) );
  150. if( task->sDisplayObject.uBitmap.szMouseOverBitmap )
  151. {
  152. // Copy the string to the allocated memory.
  153. lstrcpy( task->sDisplayObject.uBitmap.szMouseOverBitmap, szMouseOverBuffer );
  154. task->sDisplayObject.uBitmap.szMouseOffBitmap = (LPOLESTR) CoTaskMemAlloc( sizeof(OLECHAR)*(lstrlen(szMouseOffBuffer)+1) );
  155. if( task->sDisplayObject.uBitmap.szMouseOffBitmap )
  156. {
  157. // Copy the string to the allocated memory.
  158. lstrcpy( task->sDisplayObject.uBitmap.szMouseOffBitmap, szMouseOffBuffer);
  159. // Add button text, loaded from resources.
  160. nLoadStringResult = LoadString( _Module.GetResourceInstance(), uintTextResourceID, lpszTemp, IAS_MAX_STRING );
  161. _ASSERT( nLoadStringResult > 0 );
  162. task->szText = (LPOLESTR) CoTaskMemAlloc( sizeof(OLECHAR)*(lstrlen(lpszTemp)+1) );
  163. if (task->szText)
  164. {
  165. // Copy the string to the allocated memory.
  166. lstrcpy( task->szText, lpszTemp );
  167. // Add help string, loaded from resources.
  168. // ISSUE: Why don't I seem to be loading the whole string here sometimes
  169. // e.g.: for IDS_TASKPAD_HELP_TEXT__REGISTER_NEW_RADIUS_CLIENT ?
  170. nLoadStringResult = LoadString( _Module.GetResourceInstance(), uintHelpTextResourceID, lpszTemp, IAS_MAX_STRING );
  171. _ASSERT( nLoadStringResult > 0 );
  172. task->szHelpString = (LPOLESTR) CoTaskMemAlloc( sizeof(OLECHAR)*(lstrlen(lpszTemp)+1) );
  173. if (task->szHelpString)
  174. {
  175. // Copy the string to the allocated memory.
  176. lstrcpy( task->szHelpString, lpszTemp );
  177. m_index++;
  178. continue; // all is well
  179. }
  180. // If we get here, there was an error, and we didn't "continue".
  181. CoTaskMemFree(task->szText);
  182. }
  183. // If we get here, there was an error, and we didn't "continue".
  184. CoTaskMemFree(task->sDisplayObject.uBitmap.szMouseOffBitmap);
  185. }
  186. // If we get here, there was an error, and we didn't "continue".
  187. CoTaskMemFree(task->sDisplayObject.uBitmap.szMouseOverBitmap);
  188. }
  189. // If we get here, we didn't "continue" and therefore fail.
  190. if ( NULL != pceltFetched)
  191. {
  192. *pceltFetched = i; // Note that this is accurate because i above is zero based.
  193. }
  194. return S_FALSE; // Failure.
  195. }
  196. // If we get here all is well.
  197. if (pceltFetched)
  198. *pceltFetched = celt;
  199. return S_OK;
  200. }
  201. //////////////////////////////////////////////////////////////////////////////
  202. /*++
  203. CMachineEnumTask::CopyState
  204. Used by the clone method.
  205. --*/
  206. //////////////////////////////////////////////////////////////////////////////
  207. STDMETHODIMP CMachineEnumTask::CopyState( CMachineEnumTask * pSourceMachineEnumTask )
  208. {
  209. TRACE_FUNCTION("CMachineEnumTask::CopyState");
  210. m_pMachineNode = pSourceMachineEnumTask->m_pMachineNode;
  211. m_index = pSourceMachineEnumTask->m_index;
  212. m_type = pSourceMachineEnumTask->m_type;
  213. return S_OK;
  214. }