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.

441 lines
12 KiB

  1. #ifndef NETNODE_H
  2. #define NETNODE_H
  3. #include <atlsnap.h>
  4. #include "resource.h"
  5. #include "DomMigSI.h"
  6. #include "DomMigr.h"
  7. #include "Globals.h"
  8. #include "HtmlHelp.h"
  9. #include "HelpID.h"
  10. #define MAX_COLUMNS 6
  11. extern CSnapInToolbarInfo m_toolBar;
  12. template <class T>
  13. class ATL_NO_VTABLE CNetNode : public CSnapInItemImpl<T>
  14. {
  15. public:
  16. //
  17. bool m_bExpanded;
  18. int m_iColumnWidth[MAX_COLUMNS];
  19. bool m_bIsDirty;
  20. bool m_bLoaded;
  21. //
  22. CPtrArray m_ChildArray;
  23. CComPtr<IControlbar> m_spControlBar;
  24. CNetNode()
  25. {
  26. // Image indexes may need to be modified depending on the images specific to
  27. // the snapin.
  28. memset(&m_scopeDataItem, 0, sizeof(SCOPEDATAITEM));
  29. m_scopeDataItem.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM;
  30. m_scopeDataItem.displayname = MMC_CALLBACK;
  31. m_scopeDataItem.nImage = 0; // May need modification
  32. m_scopeDataItem.nOpenImage = 0; // May need modification
  33. m_scopeDataItem.lParam = (LPARAM) this;
  34. memset(&m_resultDataItem, 0, sizeof(RESULTDATAITEM));
  35. m_resultDataItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  36. m_resultDataItem.str = MMC_CALLBACK;
  37. m_resultDataItem.nImage = 0; // May need modification
  38. m_resultDataItem.lParam = (LPARAM) this;
  39. //
  40. CoInitialize( NULL );
  41. m_bLoaded = false;
  42. m_bExpanded = false;
  43. m_iColumnWidth[0] = 400;
  44. m_iColumnWidth[1] = 0;
  45. m_iColumnWidth[2] = 0;
  46. SetClean();
  47. }
  48. ~CNetNode()
  49. {
  50. for ( int i = 0; i < m_ChildArray.GetSize(); i++ )
  51. {
  52. delete (T *)(m_ChildArray[i]);
  53. }
  54. CoUninitialize();
  55. }
  56. STDMETHOD(GetScopePaneInfo)(SCOPEDATAITEM *pScopeDataItem)
  57. {
  58. if ( pScopeDataItem == NULL )
  59. return E_POINTER;
  60. if (pScopeDataItem->mask & SDI_STR)
  61. pScopeDataItem->displayname = m_bstrDisplayName;
  62. if (pScopeDataItem->mask & SDI_IMAGE)
  63. pScopeDataItem->nImage = m_scopeDataItem.nImage;
  64. if (pScopeDataItem->mask & SDI_OPENIMAGE)
  65. pScopeDataItem->nOpenImage = m_scopeDataItem.nOpenImage;
  66. if (pScopeDataItem->mask & SDI_PARAM)
  67. pScopeDataItem->lParam = m_scopeDataItem.lParam;
  68. if (pScopeDataItem->mask & SDI_STATE )
  69. pScopeDataItem->nState = m_scopeDataItem.nState;
  70. pScopeDataItem->cChildren = (int)m_ChildArray.GetSize();
  71. return S_OK;
  72. }
  73. STDMETHOD(GetResultPaneInfo)(RESULTDATAITEM *pResultDataItem)
  74. {
  75. if ( pResultDataItem == NULL )
  76. return E_POINTER;
  77. if (pResultDataItem->bScopeItem)
  78. {
  79. if (pResultDataItem->mask & RDI_STR)
  80. {
  81. pResultDataItem->str = GetResultPaneColInfo(pResultDataItem->nCol);
  82. }
  83. if (pResultDataItem->mask & RDI_IMAGE)
  84. {
  85. pResultDataItem->nImage = m_scopeDataItem.nImage;
  86. }
  87. if (pResultDataItem->mask & RDI_PARAM)
  88. {
  89. pResultDataItem->lParam = m_scopeDataItem.lParam;
  90. }
  91. return S_OK;
  92. }
  93. if (pResultDataItem->mask & RDI_STR)
  94. {
  95. pResultDataItem->str = GetResultPaneColInfo(pResultDataItem->nCol);
  96. }
  97. if (pResultDataItem->mask & RDI_IMAGE)
  98. {
  99. pResultDataItem->nImage = m_resultDataItem.nImage;
  100. }
  101. if (pResultDataItem->mask & RDI_PARAM)
  102. {
  103. pResultDataItem->lParam = m_resultDataItem.lParam;
  104. }
  105. if (pResultDataItem->mask & RDI_INDEX)
  106. {
  107. pResultDataItem->nIndex = m_resultDataItem.nIndex;
  108. }
  109. return S_OK;
  110. }
  111. HRESULT __stdcall Notify( MMC_NOTIFY_TYPE event,
  112. long arg,
  113. long param,
  114. IComponentData* pComponentData,
  115. IComponent* pComponent,
  116. DATA_OBJECT_TYPES type)
  117. {
  118. // Add code to handle the different notifications.
  119. // Handle MMCN_SHOW and MMCN_EXPAND to enumerate children items.
  120. // In response to MMCN_SHOW you have to enumerate both the scope
  121. // and result pane items.
  122. // For MMCN_EXPAND you only need to enumerate the scope items
  123. // Use IConsoleNameSpace::InsertItem to insert scope pane items
  124. // Use IResultData::InsertItem to insert result pane item.
  125. HRESULT hr = E_NOTIMPL;
  126. _ASSERTE(pComponentData != NULL || pComponent != NULL);
  127. if (( pComponent == NULL ) && ( pComponentData == NULL ))
  128. return E_POINTER;
  129. CComPtr<IConsole> spConsole;
  130. CComQIPtr<IHeaderCtrl, &IID_IHeaderCtrl> spHeader;
  131. if (pComponentData != NULL)
  132. spConsole = ((CDomMigrator*)pComponentData)->m_spConsole;
  133. else
  134. {
  135. spConsole = ((CDomMigratorComponent*)pComponent)->m_spConsole;
  136. spHeader = spConsole;
  137. }
  138. switch (event)
  139. {
  140. case MMCN_REMOVE_CHILDREN:
  141. hr = S_OK;
  142. break;
  143. case MMCN_SHOW:
  144. {
  145. CComQIPtr<IResultData, &IID_IResultData> spResultData(spConsole);
  146. bool bShow = (arg != 0);
  147. hr = OnShow( bShow, spHeader, spResultData );
  148. break;
  149. }
  150. /* case MMCN_EXPANDSYNC:
  151. {
  152. MMC_EXPANDSYNC_STRUCT *pExpandStruct = ( MMC_EXPANDSYNC_STRUCT *)param;
  153. break;
  154. }
  155. */
  156. case MMCN_EXPAND:
  157. {
  158. m_bExpanded = true;
  159. m_scopeDataItem.ID = param;
  160. hr = OnExpand( spConsole );
  161. hr = S_OK;
  162. break;
  163. }
  164. case MMCN_ADD_IMAGES:
  165. {
  166. // Add Images
  167. IImageList* pImageList = (IImageList*) arg;
  168. hr = E_FAIL;
  169. // Load bitmaps associated with the scope pane
  170. // and add them to the image list
  171. // Loads the default bitmaps generated by the wizard
  172. // Change as required
  173. HBITMAP hBitmap16 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_TOOL_16));
  174. if (hBitmap16 != NULL)
  175. {
  176. HBITMAP hBitmap32 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_TOOL_32));
  177. if (hBitmap32 != NULL)
  178. {
  179. hr = pImageList->ImageListSetStrip((long*)hBitmap16,
  180. (long*)hBitmap32, 0, RGB(0, 128, 128));
  181. if (FAILED(hr))
  182. ATLTRACE(_T("IImageList::ImageListSetStrip failed\n"));
  183. DeleteObject(hBitmap16);
  184. DeleteObject(hBitmap32);
  185. }
  186. else
  187. DeleteObject(hBitmap16);
  188. }
  189. break;
  190. }
  191. case MMCN_DBLCLICK:
  192. {
  193. hr = S_FALSE;
  194. break;
  195. }
  196. case MMCN_REFRESH:
  197. {
  198. hr = OnRefresh(spConsole);
  199. // ShowErrorMsg( spConsole, hr, _T("Refresh All Domains") );
  200. break;
  201. }
  202. case MMCN_SELECT:
  203. {
  204. //
  205. // Call our select handler.
  206. //
  207. bool bScope = (LOWORD(arg) != 0 );
  208. bool bSelect = (HIWORD(arg) != 0 );
  209. hr = OnSelect( bScope, bSelect, spConsole );
  210. break;
  211. }
  212. case MMCN_SNAPINHELP:
  213. case MMCN_HELP :
  214. case MMCN_CONTEXTHELP:
  215. {
  216. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  217. HWND mainHwnd;
  218. CComBSTR bstrTopic;
  219. HRESULT hr;
  220. IDisplayHelp * pHelp = NULL;
  221. ATLTRACE(_T("MMCN_SNAPINHELP\n"));
  222. spConsole->GetMainWindow( &mainHwnd );
  223. hr = spConsole->QueryInterface(IID_IDisplayHelp,(void**)&pHelp);
  224. if ( SUCCEEDED(hr) )
  225. {
  226. CString strTopic;
  227. strTopic.FormatMessage(IDS_HelpFileIntroTopic);
  228. if ( SUCCEEDED(hr) )
  229. {
  230. hr = pHelp->ShowTopic(strTopic.AllocSysString());
  231. if ( FAILED(hr) )
  232. {
  233. CString s;
  234. s.LoadString(IDS_FAILED);
  235. MessageBox(NULL,s,L"",MB_OK);
  236. }
  237. }
  238. else
  239. {
  240. CString s;
  241. s.LoadString(IDS_FAILED);
  242. MessageBox(NULL,s,L"",MB_OK);
  243. }
  244. pHelp->Release();
  245. }
  246. }
  247. return S_OK;
  248. default:
  249. break;
  250. }
  251. return hr;
  252. }
  253. virtual LPOLESTR GetResultPaneColInfo(int nCol)
  254. {
  255. if (nCol == 0)
  256. return m_bstrDisplayName;
  257. // TODO : Return the text for other columns
  258. return OLESTR("Override GetResultPaneColInfo");
  259. }
  260. // Message handler helpers
  261. HRESULT OnSelect( bool bScope, bool bSelect, IConsole* pConsole )
  262. {
  263. HRESULT hr=S_OK;
  264. if ( bSelect )
  265. {
  266. if ( pConsole == NULL )
  267. return E_POINTER;
  268. CComPtr<IConsoleVerb> spConsoleVerb;
  269. hr = pConsole->QueryConsoleVerb( &spConsoleVerb );
  270. if ( FAILED( hr ) )
  271. return hr;
  272. //
  273. // Enable the refresh verb.
  274. //
  275. hr = spConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE );
  276. if ( FAILED( hr ) )
  277. return hr;
  278. }
  279. return( hr );
  280. }
  281. virtual BOOL ShowInScopePane() { return TRUE; }
  282. virtual HRESULT OnExpand( IConsole *spConsole )
  283. {
  284. HRESULT hr=S_OK;
  285. CComQIPtr<IConsoleNameSpace, &IID_IConsoleNameSpace> spConsoleNameSpace(spConsole);
  286. //
  287. // Enumerate scope pane items
  288. //
  289. for (int i = 0; i < m_ChildArray.GetSize(); ++i)
  290. {
  291. if ( ((CNetNode*)m_ChildArray[i])->ShowInScopePane() )
  292. {
  293. hr = InsertNodeToScopepane(spConsoleNameSpace, (CNetNode*)m_ChildArray[i], m_scopeDataItem.ID );
  294. if (FAILED(hr))
  295. break;
  296. }
  297. }
  298. return hr;
  299. }
  300. virtual HRESULT OnShow( bool bShow, IHeaderCtrl *spHeader, IResultData *spResultData)
  301. {
  302. HRESULT hr=S_OK;
  303. if (bShow)
  304. { // show
  305. {
  306. CString cstr;
  307. CComBSTR text;
  308. if ( spResultData == NULL )
  309. return E_POINTER;
  310. cstr.Format(_T("%d subitem(s)"), m_ChildArray.GetSize() );
  311. text = (LPCTSTR)cstr;
  312. spResultData->SetDescBarText( BSTR(text) );
  313. }
  314. }
  315. else
  316. { // hide
  317. // save the column widths
  318. if ( spHeader == NULL )
  319. return E_POINTER;
  320. spHeader->GetColumnWidth(0, m_iColumnWidth);
  321. spHeader->GetColumnWidth(1, m_iColumnWidth + 1);
  322. spHeader->GetColumnWidth(2, m_iColumnWidth + 2);
  323. }
  324. hr = S_OK;
  325. return hr;
  326. }
  327. HRESULT OnRefresh(IConsole *spConsole)
  328. {
  329. HRESULT hr=S_OK;
  330. if ( m_bExpanded )
  331. {
  332. // Refresh the children
  333. for ( int i = 0; i < m_ChildArray.GetSize(); i++ )
  334. {
  335. hr = ((T *)m_ChildArray[i])->OnRefresh(spConsole);
  336. if ( FAILED(hr) )
  337. break;
  338. }
  339. }
  340. if ( FAILED(hr) )
  341. {
  342. ATLTRACE("CNetNode::OnRefresh failed, hr = %lx\n", hr );
  343. }
  344. return hr;
  345. }
  346. HRESULT OnGroupDDSetup(bool &bHandled, CSnapInObjectRootBase* pObj) { return S_OK; }
  347. HRESULT OnVersionInfo(bool &bHandled, CSnapInObjectRootBase* pObj) { return S_OK; }
  348. void UpdateMenuState( UINT id, LPTSTR pBuf, UINT *flags)
  349. {
  350. if ( id == ID_TASK_UNDO )
  351. {
  352. //if ( CanUndo(pBuf) )
  353. // *flags = MF_ENABLED;
  354. // else
  355. *flags = MF_GRAYED;
  356. }
  357. if ( id == ID_TASK_REDO )
  358. {
  359. // if ( CanRedo(pBuf) )
  360. // *flags = MF_ENABLED;
  361. // else
  362. *flags = MF_GRAYED;
  363. }
  364. }
  365. // IPersistStreamImpl
  366. HRESULT Load(IStream *pStm);
  367. HRESULT Save(IStream *pStm, BOOL fClearDirty);
  368. HRESULT GetSaveSizeMax(ULARGE_INTEGER *pcbSize);
  369. HRESULT Loaded()
  370. {
  371. if ( m_bLoaded )
  372. return S_OK;
  373. else
  374. return S_FALSE;
  375. }
  376. HRESULT IsDirty();
  377. void SetDirty()
  378. {
  379. m_bIsDirty = S_OK;
  380. }
  381. void SetClean()
  382. {
  383. m_bIsDirty = S_FALSE;
  384. }
  385. static CSnapInToolbarInfo* GetToolbarInfo()
  386. {
  387. return (CSnapInToolbarInfo*)&m_toolBar;
  388. }
  389. };
  390. #endif