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.

300 lines
7.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: atltask.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _ATL_TASKPAD_H_
  11. #define _ATL_TASKPAD_H_
  12. #include "SnapHelp.h"
  13. //
  14. // Derive from this class if you'd like to use the
  15. // IExtendTaskpadImpl implementation in your snap-in.
  16. //
  17. class CTaskpadItem
  18. {
  19. public:
  20. //
  21. // Should be overridden by client.
  22. //
  23. STDMETHOD( TaskNotify )( IConsole* pConsole, VARIANT* arg, VARIANT* param )
  24. {
  25. UNUSED_ALWAYS( arg );
  26. UNUSED_ALWAYS( param );
  27. return( E_NOTIMPL );
  28. }
  29. //
  30. // Should be overridden by client.
  31. //
  32. STDMETHOD( EnumTasks )( LPOLESTR szTaskGroup, IEnumTASK** ppEnumTASK )
  33. {
  34. UNUSED_ALWAYS( szTaskGroup );
  35. UNUSED_ALWAYS( ppEnumTASK );
  36. return( E_NOTIMPL );
  37. }
  38. protected:
  39. //
  40. // Given a destination and source task list, this copies the
  41. // strings using CoTaskMemAlloc, and also adds module file path
  42. // information as appropriate.
  43. //
  44. int CoTasksDup( MMC_TASK* pDestTasks, MMC_TASK* pSrcTasks, int nNumTasks )
  45. {
  46. USES_CONVERSION;
  47. _ASSERTE( pDestTasks != NULL );
  48. _ASSERTE( pSrcTasks != NULL );
  49. _ASSERTE( nNumTasks > 0 );
  50. int nCopied = 0;
  51. TCHAR szImagesPath[ _MAX_PATH * 2 ];
  52. TCHAR szBuf[ _MAX_PATH * 2 ];
  53. try
  54. {
  55. //
  56. // Get the path of our module.
  57. //
  58. _tcscpy( szImagesPath, _T( "res://" ) );
  59. if ( GetModuleFileName( _Module.GetModuleInstance(), szImagesPath + _tcslen( szImagesPath ), MAX_PATH ) == 0 )
  60. throw;
  61. //
  62. // Append another seperator.
  63. //
  64. _tcscat( szImagesPath, _T( "/" ) );
  65. //
  66. // Initialize the destination tasks.
  67. //
  68. memset( pDestTasks, 0, sizeof( MMC_TASK ) * nNumTasks );
  69. //
  70. // Loop through and copy each appropriate task.
  71. //
  72. for ( int i = 0; i < nNumTasks; i++ )
  73. {
  74. //
  75. // Copy the display object.
  76. //
  77. switch( pSrcTasks[ i ].sDisplayObject.eDisplayType )
  78. {
  79. case MMC_TASK_DISPLAY_TYPE_SYMBOL:
  80. pDestTasks[ i ].sDisplayObject.uSymbol.szFontFamilyName = CoTaskDupString( pSrcTasks[ i ].sDisplayObject.uSymbol.szFontFamilyName );
  81. pDestTasks[ i ].sDisplayObject.uSymbol.szURLtoEOT = CoTaskDupString( pSrcTasks[ i ].sDisplayObject.uSymbol.szURLtoEOT );
  82. pDestTasks[ i ].sDisplayObject.uSymbol.szSymbolString = CoTaskDupString( pSrcTasks[ i ].sDisplayObject.uSymbol.szSymbolString );
  83. break;
  84. default:
  85. _tcscpy( szBuf, szImagesPath );
  86. _tcscat( szBuf, W2T( pSrcTasks[ i ].sDisplayObject.uBitmap.szMouseOverBitmap ) );
  87. pDestTasks[ i ].sDisplayObject.uBitmap.szMouseOverBitmap = CoTaskDupString( T2W( szBuf ) );
  88. _tcscpy( szBuf, szImagesPath );
  89. _tcscat( szBuf, W2T( pSrcTasks[ i ].sDisplayObject.uBitmap.szMouseOffBitmap ) );
  90. pDestTasks[ i ].sDisplayObject.uBitmap.szMouseOffBitmap = CoTaskDupString( T2W( szBuf ) );
  91. break;
  92. }
  93. //
  94. // Copy the display type.
  95. //
  96. pDestTasks[ i ].sDisplayObject.eDisplayType = MMC_TASK_DISPLAY_TYPE_BITMAP;
  97. //
  98. // Copy the help string.
  99. //
  100. pDestTasks[ i ].szHelpString = CoTaskDupString( pSrcTasks[ i ].szHelpString );
  101. //
  102. // Handle the button text.
  103. //
  104. pDestTasks[ i ].szText = CoTaskDupString( pSrcTasks[ i ].szText );
  105. //
  106. // Handle the action type.
  107. //
  108. pDestTasks[ i ].eActionType = pSrcTasks[ i ].eActionType;
  109. //
  110. // Based on the action type, handle the appropriate union member.
  111. //
  112. switch( pDestTasks[ i ].eActionType )
  113. {
  114. case MMC_ACTION_ID:
  115. pDestTasks[ i ].nCommandID = pSrcTasks[ i ].nCommandID;
  116. break;
  117. case MMC_ACTION_LINK:
  118. pDestTasks[ i ].szActionURL = CoTaskDupString( pSrcTasks[ i ].szActionURL );
  119. break;
  120. case MMC_ACTION_SCRIPT:
  121. pDestTasks[ i ].szScript = CoTaskDupString( pSrcTasks[ i ].szScript );
  122. break;
  123. }
  124. //
  125. // Increment our successful copy.
  126. //
  127. nCopied++;
  128. }
  129. }
  130. catch(...)
  131. {
  132. //
  133. // Likely thrown by the cotaskdup() allocations.
  134. //
  135. }
  136. return( nCopied );
  137. }
  138. };
  139. template <class T>
  140. class ATL_NO_VTABLE IExtendTaskPadImpl : public IExtendTaskPad
  141. {
  142. public:
  143. STDMETHOD( TaskNotify )( LPDATAOBJECT pdo, VARIANT* arg, VARIANT* param)
  144. {
  145. HRESULT hr = E_POINTER;
  146. T* pT = static_cast<T*>(this);
  147. CSnapInItem* pItem;
  148. DATA_OBJECT_TYPES type;
  149. //
  150. // Retrieve the data class from the passed in object.
  151. //
  152. hr = pT->m_pComponentData->GetDataClass( pdo, &pItem, &type );
  153. if (SUCCEEDED(hr))
  154. {
  155. CTaskpadItem* pTaskpadItem = dynamic_cast< CTaskpadItem* >( pItem );
  156. if ( pTaskpadItem )
  157. {
  158. //
  159. // We're guaranteed that the passed in object will be one
  160. // of ours since we should have derived from it.
  161. //
  162. hr = pTaskpadItem->TaskNotify( pT->m_spConsole, arg, param );
  163. }
  164. }
  165. return( hr );
  166. }
  167. STDMETHOD( EnumTasks )( IDataObject * pdo, LPOLESTR szTaskGroup, IEnumTASK** ppEnumTASK )
  168. {
  169. HRESULT hr = E_POINTER;
  170. T* pT = static_cast<T*>(this);
  171. CSnapInItem* pItem;
  172. DATA_OBJECT_TYPES type;
  173. //
  174. // Retrieve the data class from the passed in object.
  175. //
  176. hr = pT->m_pComponentData->GetDataClass( pdo, &pItem, &type );
  177. if (SUCCEEDED(hr))
  178. {
  179. CTaskpadItem* pTaskpadItem = dynamic_cast< CTaskpadItem* >( pItem );
  180. if ( pTaskpadItem )
  181. {
  182. //
  183. // We're guaranteed that the passed in object will be one
  184. // of ours since we should have derived from it.
  185. //
  186. hr = pTaskpadItem->EnumTasks( szTaskGroup, ppEnumTASK );
  187. }
  188. }
  189. return( hr );
  190. }
  191. STDMETHOD( GetTitle )( LPOLESTR pszGroup, LPOLESTR * pszTitle )
  192. {
  193. UNUSED_ALWAYS( pszGroup );
  194. USES_CONVERSION;
  195. HRESULT hr = E_FAIL;
  196. T* pT = static_cast<T*>(this);
  197. try
  198. {
  199. //
  200. // Allocate memory for the title.
  201. //
  202. *pszTitle = (LPOLESTR) CoTaskMemAlloc( ( wcslen( pT->m_pszTitle ) + 1 ) * sizeof( OLECHAR ) );
  203. if ( pszTitle == NULL )
  204. throw;
  205. //
  206. // Copy the title.
  207. //
  208. wcscpy( *pszTitle, pT->m_pszTitle );
  209. hr = S_OK;
  210. }
  211. catch( ... )
  212. {
  213. }
  214. return( hr );
  215. }
  216. STDMETHOD( GetBackground )( LPOLESTR pszGroup, MMC_TASK_DISPLAY_OBJECT * pTDO )
  217. {
  218. UNUSED_ALWAYS( pszGroup );
  219. USES_CONVERSION;
  220. HRESULT hr = E_FAIL;
  221. T* pT = static_cast<T*>(this);
  222. TCHAR szModulePath[ _MAX_PATH ];
  223. OLECHAR szBackgroundPath[ _MAX_PATH ];
  224. try
  225. {
  226. //
  227. // In the taskpad case, the module path of MMC.EXE should be
  228. // obtained. Use the template contained therein.
  229. //
  230. if ( GetModuleFileName( _Module.GetModuleInstance(), szModulePath, _MAX_PATH ) == 0 )
  231. throw;
  232. //
  233. // Append the necessary decorations for correct access.
  234. //
  235. wcscpy( szBackgroundPath, L"res://" );
  236. wcscat( szBackgroundPath, T2W( szModulePath ) );
  237. wcscat( szBackgroundPath, L"/" );
  238. wcscat( szBackgroundPath, pT->m_pszBackgroundPath );
  239. pTDO->eDisplayType = MMC_TASK_DISPLAY_TYPE_BITMAP;
  240. pTDO->uBitmap.szMouseOverBitmap = CoTaskDupString( szBackgroundPath );
  241. if ( pTDO->uBitmap.szMouseOverBitmap == NULL )
  242. throw;
  243. pTDO->uBitmap.szMouseOffBitmap = NULL;
  244. hr = S_OK;
  245. }
  246. catch( ... )
  247. {
  248. }
  249. return( hr );
  250. }
  251. STDMETHOD( GetDescriptiveText )( LPOLESTR pszGroup, LPOLESTR * pszDescriptiveText )
  252. {
  253. UNUSED_ALWAYS( pszGroup );
  254. UNUSED_ALWAYS( pszDescriptiveText );
  255. return( E_NOTIMPL );
  256. }
  257. STDMETHOD( GetListPadInfo )( LPOLESTR pszGroup, MMC_LISTPAD_INFO * lpListPadInfo )
  258. {
  259. UNUSED_ALWAYS( pszGroup );
  260. UNUSED_ALWAYS( lpListPadInfo );
  261. return( E_NOTIMPL );
  262. }
  263. };
  264. #endif