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.

1630 lines
43 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) Microsoft Corporation, 1995 - 1999
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #include "stdafx.h"
  9. #include "wiz.h"
  10. #include <userenv.h>
  11. #include "genpage.h"
  12. static MMCBUTTON SvrMgrToolbar1Buttons[] =
  13. {
  14. { 0, IDC_STARTSERVER, TBSTATE_ENABLED, TBSTYLE_BUTTON, L"Start", L"Start this service" },
  15. { 1, IDC_STOPSERVER, TBSTATE_ENABLED, TBSTYLE_BUTTON, L"Stop", L"Stop this service" },
  16. };
  17. static int n_count = 0;
  18. //
  19. // Extracts the coclass guid format from the data object
  20. //
  21. template <class TYPE>
  22. TYPE* Extract(LPDATAOBJECT lpDataObject, unsigned int cf)
  23. {
  24. ASSERT(lpDataObject != NULL);
  25. TYPE* p = NULL;
  26. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  27. FORMATETC formatetc = { (CLIPFORMAT)cf, NULL,
  28. DVASPECT_CONTENT, -1, TYMED_HGLOBAL
  29. };
  30. // Allocate memory for the stream
  31. int len = (int)((cf == CDataObject::m_cfWorkstation) ?
  32. ((MAX_COMPUTERNAME_LENGTH+1) * sizeof(TYPE)) : sizeof(TYPE));
  33. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, len);
  34. // Get the workstation name from the data object
  35. do
  36. {
  37. if (stgmedium.hGlobal == NULL)
  38. break;
  39. if (FAILED(lpDataObject->GetDataHere(&formatetc, &stgmedium)))
  40. {
  41. GlobalFree(stgmedium.hGlobal);
  42. break;
  43. }
  44. p = reinterpret_cast<TYPE*>(stgmedium.hGlobal);
  45. if (p == NULL)
  46. break;
  47. } while (FALSE);
  48. return p;
  49. }
  50. BOOL IsMMCMultiSelectDataObject(LPDATAOBJECT pDataObject)
  51. {
  52. if (pDataObject == NULL)
  53. return FALSE;
  54. FORMATETC fmt = {(CLIPFORMAT)CDataObject::m_cfIsMultiSel, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  55. return (pDataObject->QueryGetData(&fmt) == S_OK);
  56. }
  57. // Data object extraction helpers
  58. CLSID* ExtractClassID(LPDATAOBJECT lpDataObject)
  59. {
  60. return Extract<CLSID>(lpDataObject, CDataObject::m_cfCoClass);
  61. }
  62. GUID* ExtractNodeType(LPDATAOBJECT lpDataObject)
  63. {
  64. return Extract<GUID>(lpDataObject, CDataObject::m_cfNodeType);
  65. }
  66. wchar_t* ExtractWorkstation(LPDATAOBJECT lpDataObject)
  67. {
  68. return Extract<wchar_t>(lpDataObject, CDataObject::m_cfWorkstation);
  69. }
  70. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject)
  71. {
  72. return Extract<INTERNAL>(lpDataObject, CDataObject::m_cfInternal);
  73. }
  74. HRESULT _QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  75. CComponentDataImpl* pImpl, LPDATAOBJECT* ppDataObject)
  76. {
  77. ASSERT(ppDataObject != NULL);
  78. ASSERT(pImpl != NULL);
  79. CComObject<CDataObject>* pObject;
  80. CComObject<CDataObject>::CreateInstance(&pObject);
  81. ASSERT(pObject != NULL);
  82. if(pObject == NULL)
  83. {
  84. return E_FAIL;
  85. }
  86. // Save cookie and type for delayed rendering
  87. pObject->SetType(type);
  88. pObject->SetCookie(cookie);
  89. // Store the coclass with the data object
  90. pObject->SetClsid(pImpl->GetCoClassID());
  91. return pObject->QueryInterface(IID_IDataObject,
  92. reinterpret_cast<void**>(ppDataObject));
  93. }
  94. DWORD GetItemType(MMC_COOKIE cookie)
  95. {
  96. // folder = CFoder* is cookie
  97. // result = RESULT_DATA* is the cookie
  98. return (*reinterpret_cast<DWORD*>(cookie));
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CSnapin's IComponent implementation
  102. STDMETHODIMP CSnapin::GetResultViewType(MMC_COOKIE cookie, LPOLESTR* ppViewType, long* pViewOptions)
  103. {
  104. if (m_CustomViewID == VIEW_ERROR_OCX)
  105. {
  106. StringFromCLSID (CLSID_MessageView, ppViewType);
  107. return S_FALSE;
  108. }
  109. else
  110. {
  111. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  112. // if list view
  113. if (m_CustomViewID == VIEW_DEFAULT_LV)
  114. {
  115. return S_FALSE;
  116. }
  117. }
  118. return S_FALSE;
  119. }
  120. STDMETHODIMP CSnapin::Initialize(LPCONSOLE lpConsole)
  121. {
  122. DBX_PRINT(_T(" ---------- CSnapin::Initialize<0x08x>\n"), this);
  123. ASSERT(lpConsole != NULL);
  124. m_bInitializedC = true;
  125. HRESULT hr;
  126. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  127. // Save the IConsole pointer
  128. if (lpConsole == NULL)
  129. return E_POINTER;
  130. hr = lpConsole->QueryInterface(IID_IConsole2,
  131. reinterpret_cast<void**>(&m_pConsole));
  132. _JumpIfError(hr, Ret, "QI IID_IConsole2");
  133. // Load resource strings
  134. LoadResources();
  135. // QI for a IHeaderCtrl
  136. hr = m_pConsole->QueryInterface(IID_IHeaderCtrl,
  137. reinterpret_cast<void**>(&m_pHeader));
  138. _JumpIfError(hr, Ret, "QI IID_IHeaderCtrl");
  139. // Give the console the header control interface pointer
  140. if (SUCCEEDED(hr))
  141. m_pConsole->SetHeader(m_pHeader);
  142. hr = m_pConsole->QueryInterface(IID_IResultData,
  143. reinterpret_cast<void**>(&m_pResult));
  144. _JumpIfError(hr, Ret, "QI IID_IResultData");
  145. hr = m_pConsole->QueryResultImageList(&m_pImageResult);
  146. _JumpIfError(hr, Ret, "ImageResult");
  147. hr = m_pConsole->QueryConsoleVerb(&m_pConsoleVerb);
  148. _JumpIfError(hr, Ret, "m_pConsoleVerb");
  149. Ret:
  150. return hr;
  151. }
  152. STDMETHODIMP CSnapin::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  153. {
  154. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  155. if (IS_SPECIAL_DATAOBJECT(lpDataObject))
  156. {
  157. if (event == MMCN_BTN_CLICK)
  158. {
  159. if (m_CustomViewID != VIEW_DEFAULT_LV)
  160. {
  161. switch (param)
  162. {
  163. case MMC_VERB_REFRESH:
  164. ::AfxMessageBox(_T("MMCN_BTN_CLICK::MMC_VERB_REFRESH"));
  165. _OnRefresh(lpDataObject);
  166. break;
  167. case MMC_VERB_PROPERTIES:
  168. ::AfxMessageBox(_T("MMCN_BTN_CLICK::MMC_VERB_PROPERTIES"));
  169. break;
  170. default:
  171. ::AfxMessageBox(_T("MMCN_BTN_CLICK::param unknown"));
  172. break;
  173. }
  174. }
  175. }
  176. else
  177. {
  178. switch (event)
  179. {
  180. case MMCN_REFRESH:
  181. ::AfxMessageBox(_T("MMCN_BTN_CLICK::MMCN_REFRESH"));
  182. _OnRefresh(lpDataObject);
  183. break;
  184. }
  185. }
  186. return S_OK;
  187. }
  188. HRESULT hr = S_OK;
  189. MMC_COOKIE cookie = NULL;
  190. switch(event)
  191. {
  192. case MMCN_COLUMNS_CHANGED:
  193. hr = S_OK;
  194. break;
  195. case MMCN_PROPERTY_CHANGE:
  196. hr = OnPropertyChange(lpDataObject);
  197. break;
  198. case MMCN_VIEW_CHANGE:
  199. hr = OnUpdateView(lpDataObject);
  200. break;
  201. case MMCN_DESELECT_ALL:
  202. DBX_PRINT(_T("CSnapin::Notify -> MMCN_DESELECT_ALL \n"));
  203. break;
  204. case MMCN_COLUMN_CLICK:
  205. DBX_PRINT(_T("CSnapin::Notify -> MMCN_COLUMN_CLICK \n"));
  206. break;
  207. case MMCN_SNAPINHELP:
  208. AfxMessageBox(_T("CSnapin::Notify ->MMCN_SNAPINHELP"));
  209. break;
  210. default:
  211. {
  212. INTERNAL* pInternal = NULL;
  213. if (IsMMCMultiSelectDataObject(lpDataObject) == FALSE)
  214. {
  215. pInternal = ExtractInternalFormat(lpDataObject);
  216. if (pInternal == NULL)
  217. {
  218. //ASSERT(FALSE);
  219. return S_OK;
  220. }
  221. cookie = pInternal->m_cookie;
  222. }
  223. switch(event)
  224. {
  225. case MMCN_ACTIVATE:
  226. break;
  227. case MMCN_CLICK:
  228. if (NULL == pInternal)
  229. {
  230. hr = S_FALSE;
  231. break;
  232. }
  233. hr = OnResultItemClk(pInternal->m_type, cookie);
  234. break;
  235. case MMCN_DBLCLICK:
  236. hr = S_FALSE; // do the default verb
  237. break;
  238. case MMCN_ADD_IMAGES:
  239. OnAddImages(cookie, arg, param);
  240. break;
  241. case MMCN_SHOW:
  242. hr = OnShow(cookie, arg, param);
  243. break;
  244. case MMCN_MINIMIZED:
  245. hr = OnMinimize(cookie, arg, param);
  246. break;
  247. case MMCN_DESELECT_ALL:
  248. case MMCN_SELECT:
  249. HandleStandardVerbs((event == MMCN_DESELECT_ALL),
  250. arg, lpDataObject);
  251. break;
  252. case MMCN_PASTE:
  253. AfxMessageBox(_T("CSnapin::MMCN_PASTE"));
  254. break;
  255. case MMCN_DELETE:
  256. hr = OnDelete(lpDataObject, arg, param);
  257. // fall through to refresh -- break;
  258. case MMCN_REFRESH:
  259. {
  260. _OnRefresh(lpDataObject);
  261. }
  262. break;
  263. case MMCN_CONTEXTHELP:
  264. hr = OnContextHelp(lpDataObject);
  265. break;
  266. case MMCN_RENAME:
  267. OutputDebugString(_T("\n\n\t\tCSnapin::MMCN_RENAME\n\n"));
  268. break;
  269. // Note - Future expansion of notify types possible
  270. default:
  271. hr = E_UNEXPECTED;
  272. break;
  273. }
  274. if (pInternal != NULL)
  275. FREE_DATA(pInternal);
  276. break;
  277. }
  278. }
  279. return hr;
  280. }
  281. HRESULT CSnapin::OnUpdateView(LPDATAOBJECT pDataObject)
  282. {
  283. _OnRefresh(pDataObject);
  284. return S_OK;
  285. }
  286. void CSnapin::_OnRefresh(LPDATAOBJECT pDataObject)
  287. {
  288. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  289. INTERNAL* pInternal = ExtractInternalFormat(pDataObject);
  290. if (pInternal == NULL)
  291. return;
  292. if (pInternal->m_type == CCT_SCOPE)
  293. {
  294. CComponentDataImpl* pData = dynamic_cast<CComponentDataImpl*>(m_pComponentData);
  295. CFolder* pFolder = pData->FindObject(pInternal->m_cookie);
  296. // only do if this is the currently selected folder!!
  297. if (m_pCurrentlySelectedScopeFolder == pFolder)
  298. {
  299. // HIDE, remove all items, remove header, SHOW
  300. OnShow(pInternal->m_cookie, FALSE, 0); // emulate HIDE
  301. m_pResult->DeleteAllRsltItems(); // delete items from m_pResult
  302. while(S_OK == m_pHeader->DeleteColumn(0)) {}; // remove all cols from header
  303. OnShow(pInternal->m_cookie, TRUE, 0); // emulate SHOW
  304. }
  305. }
  306. else
  307. {
  308. RESULT_DATA* pData = reinterpret_cast<RESULT_DATA*>(pInternal->m_cookie);
  309. }
  310. FREE_DATA(pInternal);
  311. }
  312. HRESULT CSnapin::OnContextHelp(LPDATAOBJECT pdtobj)
  313. {
  314. HRESULT hr = S_OK;
  315. CString cstrHelpFile;
  316. IDisplayHelp* pDisplayHelp = NULL;
  317. WCHAR szWindows[MAX_PATH];
  318. szWindows[0] = L'\0';
  319. hr = m_pConsole->QueryInterface (IID_IDisplayHelp, (void**)&pDisplayHelp);
  320. _JumpIfError(hr, Ret, "QI IDisplayHelp");
  321. if (0 == GetSystemWindowsDirectory(szWindows, MAX_PATH))
  322. {
  323. hr = myHLastError();
  324. _JumpError(hr, Ret, "GetSystemWindowsDirectory");
  325. }
  326. cstrHelpFile = szWindows;
  327. cstrHelpFile += HTMLHELP_COLLECTIONLINK_FILENAME;
  328. cstrHelpFile += L"::/sag_cs_topnode.htm";
  329. hr = pDisplayHelp->ShowTopic (T2OLE ((LPWSTR)(LPCWSTR)cstrHelpFile));
  330. _JumpIfError(hr, Ret, "ShowTopic");
  331. Ret:
  332. if (pDisplayHelp)
  333. pDisplayHelp->Release();
  334. return hr;
  335. }
  336. STDMETHODIMP CSnapin::Destroy(MMC_COOKIE cookie)
  337. {
  338. DBX_PRINT(_T(" ---------- CSnapin::Destroy<0x08x>\n"), this);
  339. ASSERT(m_bInitializedC);
  340. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  341. m_bDestroyedC = true;
  342. // Release the interfaces that we QI'ed
  343. if (m_pConsole != NULL)
  344. {
  345. // Tell the console to release the header control interface
  346. m_pConsole->SetHeader(NULL);
  347. SAFE_RELEASE(m_pHeader);
  348. SAFE_RELEASE(m_pResult);
  349. SAFE_RELEASE(m_pImageResult);
  350. // Release the IConsole interface last
  351. SAFE_RELEASE(m_pConsole);
  352. SAFE_RELEASE(m_pComponentData); // QI'ed in IComponentDataImpl::CreateComponent
  353. SAFE_RELEASE(m_pConsoleVerb);
  354. }
  355. return S_OK;
  356. }
  357. HRESULT CSnapin::QueryMultiSelectDataObject(MMC_COOKIE cookie,
  358. DATA_OBJECT_TYPES type,
  359. LPDATAOBJECT* ppDataObject)
  360. {
  361. CComponentDataImpl* pImpl = dynamic_cast<CComponentDataImpl*>(m_pComponentData);
  362. CComObject<CDataObject>* pObject = NULL;
  363. HRESULT hr = S_OK;
  364. LPRESULTDATA pResultData = NULL;
  365. RESULTDATAITEM rdi;
  366. ASSERT(ppDataObject != NULL);
  367. if (ppDataObject == NULL)
  368. {
  369. hr = E_POINTER;
  370. goto error;
  371. }
  372. hr = m_pConsole->QueryInterface(IID_IResultData,
  373. reinterpret_cast<void**>(&pResultData));
  374. if(hr != S_OK)
  375. {
  376. goto error;
  377. }
  378. ASSERT(pResultData != NULL);
  379. CComObject<CDataObject>::CreateInstance(&pObject);
  380. ASSERT(pObject != NULL);
  381. // Save cookie and type for delayed rendering
  382. pObject->SetType(type);
  383. pObject->SetCookie(cookie);
  384. // tell dataobj who we are
  385. // pObject->SetComponentData(pImpl);
  386. // Determine the items selected
  387. ZeroMemory(&rdi, sizeof(rdi));
  388. rdi.mask = RDI_STATE;
  389. rdi.nIndex = -1;
  390. rdi.nState = TVIS_SELECTED;
  391. while (pResultData->GetNextItem (&rdi) == S_OK)
  392. {
  393. CFolder* pFolder = reinterpret_cast <CFolder *> (rdi.lParam);
  394. if ( pFolder )
  395. {
  396. if(pFolder->GetType() == CA_CERT_TYPE)
  397. {
  398. pObject->AddCookie((MMC_COOKIE)pFolder);
  399. }
  400. }
  401. else
  402. {
  403. hr = E_INVALIDARG;
  404. goto error;
  405. }
  406. }
  407. // We're always adding things from policy settings these days.
  408. pObject->SetMultiSelDobj();
  409. pObject->SetClsid(pImpl->GetCoClassID());
  410. SMMCObjectTypes sObjGuids; // one is fine for now
  411. sObjGuids.count = 1;
  412. CopyMemory(&sObjGuids.guid[0], &cNodeTypePolicySettings, sizeof(GUID));
  413. // Store the coclass with the data object
  414. pObject->SetMultiSelData(&sObjGuids, sizeof(SMMCObjectTypes));
  415. hr = pObject->QueryInterface(IID_IDataObject,
  416. reinterpret_cast<void**>(ppDataObject));
  417. pObject = NULL;
  418. error:
  419. if(pObject)
  420. {
  421. pObject->Release();
  422. }
  423. if (pResultData)
  424. {
  425. pResultData->Release();
  426. }
  427. return hr;
  428. }
  429. STDMETHODIMP CSnapin::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  430. LPDATAOBJECT* ppDataObject)
  431. {
  432. if (cookie == MMC_MULTI_SELECT_COOKIE)
  433. {
  434. return QueryMultiSelectDataObject(cookie, type, ppDataObject);
  435. }
  436. ASSERT(type == CCT_RESULT);
  437. // Delegate it to the IComponentData
  438. ASSERT(m_pComponentData != NULL);
  439. CComponentDataImpl* pImpl = dynamic_cast<CComponentDataImpl*>(m_pComponentData);
  440. ASSERT(pImpl != NULL);
  441. return _QueryDataObject(cookie, type, pImpl, ppDataObject);
  442. }
  443. /////////////////////////////////////////////////////////////////////////////
  444. // CSnapin's implementation specific members
  445. DEBUG_DECLARE_INSTANCE_COUNTER(CSnapin);
  446. CSnapin::CSnapin()
  447. : m_bIsDirty(TRUE), m_bInitializedC(false), m_bDestroyedC(false)
  448. {
  449. DEBUG_INCREMENT_INSTANCE_COUNTER(CSnapin);
  450. Construct();
  451. }
  452. CSnapin::~CSnapin()
  453. {
  454. #if DBG==1
  455. ASSERT(dbg_cRef == 0);
  456. #endif
  457. DEBUG_DECREMENT_INSTANCE_COUNTER(CSnapin);
  458. if (m_pSvrMgrToolbar1)
  459. SAFE_RELEASE(m_pSvrMgrToolbar1);
  460. #ifdef INSERT_DEBUG_FOLDERS
  461. SAFE_RELEASE(m_pMenuButton1);
  462. #endif // INSERT_DEBUG_FOLDERS
  463. if (m_pControlbar)
  464. SAFE_RELEASE(m_pControlbar);
  465. // Make sure the interfaces have been released
  466. ASSERT(m_pConsole == NULL);
  467. ASSERT(m_pHeader == NULL);
  468. ASSERT(m_pSvrMgrToolbar1 == NULL);
  469. delete m_pbmpSvrMgrToolbar1;
  470. ASSERT(!m_bInitializedC || m_bDestroyedC);
  471. Construct();
  472. }
  473. void CSnapin::Construct()
  474. {
  475. #if DBG==1
  476. dbg_cRef = 0;
  477. #endif
  478. m_pConsole = NULL;
  479. m_pHeader = NULL;
  480. m_pResult = NULL;
  481. m_pImageResult = NULL;
  482. m_pComponentData = NULL;
  483. m_pControlbar = NULL;
  484. #ifdef INSERT_DEBUG_FOLDERS
  485. m_pMenuButton1 = NULL;
  486. #endif // INSERT_DEBUG_FOLDERS
  487. m_pSvrMgrToolbar1 = NULL;
  488. m_pbmpSvrMgrToolbar1 = NULL;
  489. m_pConsoleVerb = NULL;
  490. m_CustomViewID = VIEW_DEFAULT_LV;
  491. }
  492. CString g_ColumnHead_Name;
  493. CString g_ColumnHead_Size;
  494. CString g_ColumnHead_Type;
  495. CString g_ColumnHead_IntendedPurpose;
  496. void CSnapin::LoadResources()
  497. {
  498. // Load strings from resources
  499. g_ColumnHead_Name.LoadString(IDS_COLUMN_NAME);
  500. g_ColumnHead_Size.LoadString(IDS_COLUMN_SIZE);
  501. g_ColumnHead_Type.LoadString(IDS_COLUMN_TYPE);
  502. g_ColumnHead_IntendedPurpose.LoadString(IDS_COLUMN_INTENDED_PURPOSE);
  503. }
  504. HRESULT CSnapin::InitializeHeaders(MMC_COOKIE cookie)
  505. {
  506. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  507. ASSERT(m_pHeader);
  508. HRESULT hr = S_OK;
  509. BOOL fInsertedHeaders=FALSE;
  510. USES_CONVERSION;
  511. CFolder* pFolder = reinterpret_cast<CFolder*>(cookie);
  512. switch (pFolder->m_type)
  513. {
  514. case POLICYSETTINGS:
  515. case SCE_EXTENSION:
  516. m_pHeader->InsertColumn(0, W2COLE(g_ColumnHead_Name), LVCFMT_LEFT, 230); // Name
  517. m_pHeader->InsertColumn(1, W2COLE(g_ColumnHead_IntendedPurpose), LVCFMT_LEFT, 230); // Intended Purpose
  518. fInsertedHeaders = TRUE;
  519. break;
  520. default:
  521. // other scopes
  522. m_pHeader->InsertColumn(0, W2COLE(g_ColumnHead_Name), LVCFMT_LEFT, 180); // Name
  523. m_pHeader->InsertColumn(1, W2COLE(g_ColumnHead_Size), LVCFMT_LEFT, 90); // Size
  524. m_pHeader->InsertColumn(2, W2COLE(g_ColumnHead_Type), LVCFMT_LEFT, 160); // Type
  525. fInsertedHeaders = TRUE;
  526. }
  527. return hr;
  528. }
  529. STDMETHODIMP CSnapin::GetDisplayInfo(LPRESULTDATAITEM pResult)
  530. {
  531. static WCHAR* s_szSize = L"200";
  532. static WCHAR* s_szUnnamedItems = L"Unnamed subitem";
  533. ASSERT(pResult != NULL);
  534. CFolder* pFolder = reinterpret_cast<CFolder*>(pResult->lParam);
  535. ASSERT(pFolder);
  536. if (pResult)
  537. {
  538. // a folder or a result?
  539. if (pResult->bScopeItem == TRUE)
  540. {
  541. if (pResult->mask & RDI_STR)
  542. {
  543. switch (pFolder->m_type)
  544. {
  545. case POLICYSETTINGS:
  546. case SCE_EXTENSION:
  547. // just a single column here
  548. pResult->str = pFolder->m_pszName;
  549. break;
  550. default:
  551. break;
  552. }
  553. ASSERT(pResult->str != NULL);
  554. if (pResult->str == NULL)
  555. pResult->str = (LPOLESTR)L"";
  556. }
  557. if (pResult->mask & RDI_IMAGE)
  558. {
  559. if (pResult->nState & TVIS_EXPANDED)
  560. pResult->nImage = pFolder->m_pScopeItem->nOpenImage;
  561. else
  562. pResult->nImage = pFolder->m_pScopeItem->nImage;
  563. }
  564. }
  565. else
  566. {
  567. RESULT_DATA* pData;
  568. // lParam is the item pointer
  569. pData= reinterpret_cast<RESULT_DATA*>(pResult->lParam);
  570. if (pResult->mask & RDI_STR)
  571. {
  572. ASSERT(pFolder->m_hCertType != NULL);
  573. if (pResult->nCol == 0)
  574. pResult->str = pFolder->m_pszName;
  575. else if (pResult->nCol == 1)
  576. pResult->str = (LPWSTR)((LPCWSTR) pFolder->m_szIntendedUsages);
  577. ASSERT(pResult->str != NULL);
  578. if (pResult->str == NULL)
  579. pResult->str = (LPOLESTR)L"";
  580. }
  581. // MMC can request image and indent for virtual data
  582. if (pResult->mask & RDI_IMAGE)
  583. {
  584. // UNDONE: what to do here?
  585. ASSERT(0);
  586. pResult->nImage = IMGINDEX_CERTTYPE;
  587. }
  588. }
  589. }
  590. return S_OK;
  591. }
  592. /////////////////////////////////////////////////////////////////////////////
  593. // IExtendContextMenu Implementation
  594. STDMETHODIMP CSnapin::AddMenuItems(LPDATAOBJECT pDataObject,
  595. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  596. LONG *pInsertionAllowed)
  597. {
  598. return dynamic_cast<CComponentDataImpl*>(m_pComponentData)->
  599. AddMenuItems(pDataObject, pContextMenuCallback, pInsertionAllowed);
  600. }
  601. STDMETHODIMP CSnapin::Command(long nCommandID, LPDATAOBJECT pDataObject)
  602. {
  603. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  604. INTERNAL* pInternal = ExtractInternalFormat(pDataObject);
  605. HRESULT hr;
  606. HWND hwndConsole;
  607. if (pInternal == NULL)
  608. return E_FAIL;
  609. CFolder* pFolder = reinterpret_cast<CFolder*>(pInternal->m_cookie);
  610. if (pInternal->m_type == CCT_SCOPE)
  611. {
  612. // Handle view specific commands here
  613. switch (nCommandID)
  614. {
  615. case MMCC_STANDARD_VIEW_SELECT:
  616. m_CustomViewID = VIEW_DEFAULT_LV;
  617. break;
  618. default:
  619. // Pass non-view specific commands to ComponentData
  620. return dynamic_cast<CComponentDataImpl*>(m_pComponentData)->
  621. Command(nCommandID, pDataObject);
  622. }
  623. }
  624. else if (pInternal->m_type == CCT_RESULT)
  625. {
  626. // snag the selected items
  627. // only support single selection for now
  628. m_pResult->ModifyViewStyle(MMC_SINGLESEL, (MMC_RESULT_VIEW_STYLE)0);
  629. RESULTDATAITEM rdi;
  630. ZeroMemory(&rdi, sizeof(rdi));
  631. rdi.mask = RDI_STATE;
  632. rdi.nState = LVIS_SELECTED;
  633. rdi.nIndex = -1;
  634. m_pResult->GetNextItem(&rdi);
  635. int iSel = rdi.nIndex;
  636. RESULT_DATA* pData;
  637. ZeroMemory(&rdi, sizeof(rdi));
  638. rdi.mask = RDI_PARAM;
  639. rdi.nIndex = iSel;
  640. hr = m_pResult->GetItem(&rdi);
  641. ASSERT(SUCCEEDED(hr));
  642. ASSERT(rdi.lParam != 0);
  643. pData = reinterpret_cast<RESULT_DATA*>(rdi.lParam);
  644. // No current commands :(
  645. }
  646. else
  647. {
  648. ASSERT(0);
  649. }
  650. FREE_DATA(pInternal);
  651. return S_OK;
  652. }
  653. STDMETHODIMP CSnapin::GetClassID(CLSID *pClassID)
  654. {
  655. ASSERT(pClassID != NULL);
  656. ASSERT(0);
  657. // Copy the CLSID for this snapin
  658. // reid fix - what is up with this?
  659. *pClassID = CLSID_CAPolicyExtensionSnapIn;
  660. return E_NOTIMPL;
  661. }
  662. STDMETHODIMP CSnapin::IsDirty()
  663. {
  664. // Always save / Always dirty.
  665. return ThisIsDirty() ? S_OK : S_FALSE;
  666. }
  667. STDMETHODIMP CSnapin::Load(IStream *pStm)
  668. {
  669. DBX_PRINT(_T(" ---------- CSnapin::Load<0x08x>\n"), this);
  670. ASSERT(m_bInitializedC);
  671. ASSERT(pStm);
  672. // Read the string
  673. DWORD dwVer;
  674. ULONG nBytesRead;
  675. HRESULT hr = pStm->Read(&dwVer, sizeof(DWORD), &nBytesRead);
  676. ASSERT(SUCCEEDED(hr) && nBytesRead == sizeof(DWORD));
  677. if (dwVer != 0x1)
  678. {
  679. return (STG_E_OLDFORMAT);
  680. }
  681. ClearDirty();
  682. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  683. }
  684. STDMETHODIMP CSnapin::Save(IStream *pStm, BOOL fClearDirty)
  685. {
  686. DBX_PRINT(_T(" ---------- CSnapin::Save<0x08x>\n"), this);
  687. ASSERT(m_bInitializedC);
  688. ASSERT(pStm);
  689. // Write the string
  690. ULONG nBytesWritten;
  691. DWORD dwVersion = 0x1;
  692. HRESULT hr = pStm->Write(&dwVersion, sizeof(DWORD), &nBytesWritten);
  693. // Verify that the write operation succeeded
  694. ASSERT(SUCCEEDED(hr) && nBytesWritten == sizeof(DWORD));
  695. if (FAILED(hr))
  696. return STG_E_CANTSAVE;
  697. if (fClearDirty)
  698. ClearDirty();
  699. return S_OK;
  700. }
  701. STDMETHODIMP CSnapin::GetSizeMax(ULARGE_INTEGER *pcbSize)
  702. {
  703. ASSERT(pcbSize);
  704. DWORD cbSize;
  705. cbSize = sizeof(DWORD); // version
  706. // Set the size of the string to be saved
  707. ULISet32(*pcbSize, cbSize);
  708. return S_OK;
  709. }
  710. ///////////////////////////////////////////////////////////////////////////////
  711. // IExtendControlbar implementation
  712. //
  713. STDMETHODIMP CSnapin::SetControlbar(LPCONTROLBAR pControlbar)
  714. {
  715. /* TRACE(_T("CSnapin::SetControlbar(%ld)\n"),pControlbar);
  716. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  717. if (m_pControlbar)
  718. SAFE_RELEASE(m_pControlbar);
  719. if (pControlbar != NULL)
  720. {
  721. // Hold on to the controlbar interface.
  722. m_pControlbar = pControlbar;
  723. m_pControlbar->AddRef();
  724. HRESULT hr=S_FALSE;
  725. #ifdef INSERT_DEBUG_FOLDERS
  726. if (!m_pMenuButton1)
  727. {
  728. hr = m_pControlbar->Create(MENUBUTTON, this,
  729. reinterpret_cast<LPUNKNOWN*>(&m_pMenuButton1));
  730. ASSERT(SUCCEEDED(hr));
  731. }
  732. if (m_pMenuButton1)
  733. {
  734. // Unlike toolbar buttons, menu buttons need to be added every time.
  735. hr = m_pMenuButton1->AddButton(FOLDEREX_MENU, L"FolderEx", L"Extended Folder Menu");
  736. ASSERT(SUCCEEDED(hr));
  737. hr = m_pMenuButton1->AddButton(FILEEX_MENU, L"FileEx", L"Extended File Menu");
  738. ASSERT(SUCCEEDED(hr));
  739. }
  740. #endif // INSERT_DEBUG_FOLDERS
  741. // SvrMgrToolbar1
  742. if (!m_pSvrMgrToolbar1)
  743. {
  744. hr = m_pControlbar->Create(TOOLBAR, this, reinterpret_cast<LPUNKNOWN*>(&m_pSvrMgrToolbar1));
  745. ASSERT(SUCCEEDED(hr));
  746. // Add the bitmap
  747. m_pbmpSvrMgrToolbar1 = new ::CBitmap;
  748. m_pbmpSvrMgrToolbar1->LoadBitmap(IDB_TOOLBAR_SVRMGR1);
  749. hr = m_pSvrMgrToolbar1->AddBitmap(36, *m_pbmpSvrMgrToolbar1, 16, 16, RGB(192,192,192));
  750. ASSERT(SUCCEEDED(hr));
  751. // Add the buttons to the toolbar
  752. hr = m_pSvrMgrToolbar1->AddButtons(ARRAYLEN(SvrMgrToolbar1Buttons), SvrMgrToolbar1Buttons);
  753. ASSERT(SUCCEEDED(hr));
  754. }
  755. }
  756. */
  757. return S_OK;
  758. }
  759. void CSnapin::OnButtonClick(LPDATAOBJECT pdtobj, int idBtn)
  760. {
  761. WCHAR name[128];
  762. DWORD cName = sizeof(name)/sizeof(WCHAR);
  763. GetItemName(pdtobj, name, &cName);
  764. switch(idBtn)
  765. {
  766. case IDC_STOPSERVER:
  767. case IDC_STARTSERVER:
  768. // bubble this to our other handler
  769. dynamic_cast<CComponentDataImpl*>(m_pComponentData)->
  770. Command(idBtn, pdtobj);
  771. break;
  772. default:
  773. {
  774. #ifdef _DEBUG
  775. TCHAR buf[150];
  776. wsprintf(buf, L"Toolbar button<%d> was clicked.\nThe currently selected result item is <%s>", idBtn, name);
  777. OutputDebugString(buf);
  778. #endif // _DEBUG
  779. }
  780. break;
  781. }
  782. }
  783. STDMETHODIMP CSnapin::ControlbarNotify(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  784. {
  785. /* HRESULT hr=S_FALSE;
  786. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  787. switch (event)
  788. {
  789. case MMCN_BTN_CLICK:
  790. //TCHAR szMessage[MAX_PATH];
  791. //wsprintf(szMessage, _T("CommandID %ld"),param);
  792. //AfxMessageBox(szMessage);
  793. OnButtonClick(reinterpret_cast<LPDATAOBJECT>(arg), param);
  794. break;
  795. case MMCN_DESELECT_ALL:
  796. case MMCN_SELECT:
  797. HandleExtToolbars((event == MMCN_DESELECT_ALL), arg, param);
  798. break;
  799. case MMCN_MENU_BTNCLICK:
  800. HandleExtMenus(arg, param);
  801. break;
  802. default:
  803. break;
  804. }
  805. */
  806. return S_OK;
  807. }
  808. // This compares two data objects to see if they are the same object.
  809. // return
  810. // S_OK if equal otherwise S_FALSE
  811. //
  812. // Note: check to make sure both objects belong to the snap-in.
  813. //
  814. STDMETHODIMP CSnapin::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  815. {
  816. return S_FALSE;
  817. }
  818. // This compare is used to sort the item's in the listview
  819. //
  820. // Parameters:
  821. //
  822. // lUserParam - user param passed in when IResultData::Sort() was called
  823. // cookieA - first item to compare
  824. // cookieB - second item to compare
  825. // pnResult [in, out]- contains the col on entry,
  826. // -1, 0, 1 based on comparison for return value.
  827. //
  828. // Note: Assum sort is ascending when comparing.
  829. STDMETHODIMP CSnapin::Compare(LPARAM lUserParam, MMC_COOKIE cookieA, MMC_COOKIE cookieB, int* pnResult)
  830. {
  831. if (pnResult == NULL)
  832. {
  833. ASSERT(FALSE);
  834. return E_POINTER;
  835. }
  836. // check col range
  837. int nCol = *pnResult;
  838. ASSERT(nCol >=0);
  839. *pnResult = 0;
  840. USES_CONVERSION;
  841. LPWSTR szStringA;
  842. LPWSTR szStringB;
  843. CFolder* pDataA = reinterpret_cast<CFolder*>(cookieA);
  844. CFolder* pDataB = reinterpret_cast<CFolder*>(cookieB);
  845. ASSERT(pDataA != NULL && pDataB != NULL);
  846. if (nCol == 0)
  847. {
  848. szStringA = OLE2W(pDataA->m_pszName);
  849. szStringB = OLE2W(pDataB->m_pszName);
  850. }
  851. else if (nCol == 1)
  852. {
  853. szStringA = OLE2W((LPWSTR)((LPCWSTR) pDataA->m_szIntendedUsages));
  854. szStringB = OLE2W((LPWSTR)((LPCWSTR) pDataB->m_szIntendedUsages));
  855. }
  856. else
  857. return S_OK;
  858. if ((szStringA == NULL) || (szStringB == NULL))
  859. return E_POINTER;
  860. *pnResult = wcscmp(szStringA, szStringB);
  861. return S_OK;
  862. }
  863. void CSnapin::HandleStandardVerbs(bool bDeselectAll, LPARAM arg,
  864. LPDATAOBJECT lpDataObject)
  865. {
  866. if(m_pConsoleVerb == NULL)
  867. {
  868. return;
  869. }
  870. if (m_CustomViewID != VIEW_DEFAULT_LV)
  871. {
  872. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, HIDDEN, FALSE);
  873. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  874. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, FALSE);
  875. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  876. return;
  877. }
  878. if (!bDeselectAll && lpDataObject == NULL)
  879. return;
  880. // You should crack the data object and enable/disable/hide standard
  881. // commands appropriately. The standard commands are reset everytime you get
  882. // called. So you must reset them back.
  883. WORD bScope = LOWORD(arg);
  884. WORD bSelect = HIWORD(arg);
  885. DBX_PRINT(_T(" %4d - CSnapin::OnSelect<%d, %d>\n"), ++n_count, bScope, bSelect);
  886. if (!bDeselectAll && IsMMCMultiSelectDataObject(lpDataObject) == TRUE)
  887. {
  888. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, FALSE);
  889. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  890. return;
  891. }
  892. if (bDeselectAll || !bSelect)
  893. {
  894. // we have no items selected, so add the Refresh verb
  895. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, HIDDEN, FALSE);
  896. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  897. // bail
  898. return;
  899. }
  900. INTERNAL* pInternal = lpDataObject ? ExtractInternalFormat(lpDataObject) : NULL;
  901. DWORD dwCertTypeFlags;
  902. HRESULT hr;
  903. CFolder* pFolder = NULL;
  904. if (pInternal != NULL)
  905. {
  906. pFolder = reinterpret_cast<CFolder*>(pInternal->m_cookie);
  907. }
  908. // Standard funcitonality NOT support by all items
  909. m_pConsoleVerb->SetVerbState(MMC_VERB_COPY, HIDDEN, TRUE);
  910. m_pConsoleVerb->SetVerbState(MMC_VERB_COPY, ENABLED, FALSE);
  911. m_pConsoleVerb->SetVerbState(MMC_VERB_PASTE, HIDDEN, TRUE);
  912. m_pConsoleVerb->SetVerbState(MMC_VERB_PASTE, ENABLED, FALSE);
  913. m_pConsoleVerb->SetVerbState(MMC_VERB_RENAME, ENABLED, FALSE);
  914. m_pConsoleVerb->SetVerbState(MMC_VERB_OPEN, HIDDEN, TRUE);
  915. m_pConsoleVerb->SetVerbState(MMC_VERB_OPEN, ENABLED, FALSE);
  916. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_NONE);
  917. if (pInternal)
  918. {
  919. if (pInternal->m_type == CCT_SCOPE)
  920. {
  921. // Common verbs through all states
  922. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, HIDDEN, FALSE);
  923. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, TRUE);
  924. // Scope items can't be deleted
  925. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, TRUE);
  926. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, FALSE);
  927. // No properties on the scope item
  928. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  929. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, FALSE);
  930. // default folder verb is open
  931. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  932. }
  933. else
  934. {
  935. // check to see if this is a default cert type and we are in GPT,
  936. // if so then don't enable delete
  937. if (pFolder != NULL)
  938. {
  939. // Common verbs through all states
  940. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, HIDDEN, TRUE);
  941. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, ENABLED, FALSE);
  942. // They do have properties
  943. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, FALSE);
  944. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  945. // They can be deleted
  946. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, FALSE);
  947. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  948. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  949. }
  950. }
  951. }
  952. FREE_DATA(pInternal);
  953. }
  954. void EnableToolbar(LPTOOLBAR pToolbar, MMCBUTTON rgSnapinButtons[], int nRgSize,
  955. BOOL bEnable)
  956. {
  957. for (int i=0; i < nRgSize; ++i)
  958. {
  959. if (rgSnapinButtons[i].idCommand != 0)
  960. pToolbar->SetButtonState(rgSnapinButtons[i].idCommand, ENABLED,
  961. bEnable);
  962. }
  963. }
  964. void EnableMenuBtns(LPMENUBUTTON pMenuBtn, MMCBUTTON rgSnapinButtons[], int nRgSize,
  965. BOOL bEnable)
  966. {
  967. for (int i=0; i < nRgSize; ++i)
  968. {
  969. if (rgSnapinButtons[i].idCommand != 0)
  970. pMenuBtn->SetButtonState(rgSnapinButtons[i].idCommand, ENABLED,
  971. bEnable);
  972. }
  973. }
  974. void CSnapin::HandleExtToolbars(bool bDeselectAll, LPARAM arg, LPARAM param)
  975. {
  976. INTERNAL* pInternal = NULL;
  977. HRESULT hr;
  978. BOOL bScope = (BOOL) LOWORD(arg);
  979. BOOL bSelect = (BOOL) HIWORD(arg);
  980. if (param)
  981. {
  982. LPDATAOBJECT pDataObject = reinterpret_cast<LPDATAOBJECT>(param);
  983. pInternal = ExtractInternalFormat(pDataObject);
  984. }
  985. #ifdef _DEBUG
  986. TCHAR buf[200];
  987. wsprintf(buf, _T(" %4d - CExtendControlbar::OnSelect<%d, %d> = %d\n"),
  988. ++n_count, bScope, bSelect, pInternal ? pInternal->m_cookie : 0);
  989. OutputDebugString(buf);
  990. #endif //_DEBUG
  991. // Deselection Notification?
  992. if (bDeselectAll || bSelect == FALSE)
  993. {
  994. ASSERT(m_pSvrMgrToolbar1);
  995. EnableToolbar(m_pSvrMgrToolbar1, SvrMgrToolbar1Buttons,
  996. ARRAYLEN(SvrMgrToolbar1Buttons), FALSE);
  997. #ifdef INSERT_DEBUG_FOLDERS
  998. ASSERT(m_pMenuButton1 != NULL);
  999. m_pMenuButton1->SetButtonState(FOLDEREX_MENU, ENABLED, FALSE);
  1000. m_pMenuButton1->SetButtonState(FILEEX_MENU, ENABLED, FALSE);
  1001. #endif // INSERT_DEBUG_FOLDERS
  1002. return;
  1003. }
  1004. ASSERT(bSelect == TRUE);
  1005. bool bFileExBtn = false;
  1006. if (bScope == TRUE)
  1007. {
  1008. // at SCOPE level?
  1009. LPDATAOBJECT pDataObject = reinterpret_cast<LPDATAOBJECT>(param);
  1010. pInternal = ExtractInternalFormat(pDataObject);
  1011. if (pInternal == NULL)
  1012. return;
  1013. CFolder* pFolder = reinterpret_cast<CFolder*>(pInternal->m_cookie);
  1014. if (pInternal->m_cookie == 0)
  1015. {
  1016. if (IsPrimaryImpl() == TRUE)
  1017. {
  1018. // Attach the SvrMgrToolbar1 to the window
  1019. hr = m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pSvrMgrToolbar1);
  1020. ASSERT(SUCCEEDED(hr));
  1021. }
  1022. }
  1023. else if (IsPrimaryImpl() == TRUE /*&&
  1024. ( pFolder->GetType() == SERVER_INSTANCE ||
  1025. pFolder->GetType() == SERVERFUNC_CRL_PUBLICATION ||
  1026. pFolder->GetType() == SERVERFUNC_ISSUED_CERTIFICATES ||
  1027. pFolder->GetType() == SERVERFUNC_PENDING_CERTIFICATES )*/)
  1028. {
  1029. // Attach the SvrMgrToolbar1 to the window
  1030. hr = m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pSvrMgrToolbar1);
  1031. ASSERT(SUCCEEDED(hr));
  1032. }
  1033. else
  1034. {
  1035. // Detach the SvrMgrToolbar1 to the window
  1036. hr = m_pControlbar->Detach((LPUNKNOWN) m_pSvrMgrToolbar1);
  1037. ASSERT(SUCCEEDED(hr));
  1038. }
  1039. }
  1040. else // result item selected: result or subfolder
  1041. {
  1042. // at RESULTS level
  1043. LPDATAOBJECT pDataObject = reinterpret_cast<LPDATAOBJECT>(param);
  1044. if (pDataObject != NULL)
  1045. pInternal = ExtractInternalFormat(pDataObject);
  1046. if (pInternal == NULL)
  1047. return;
  1048. if (pInternal->m_type == CCT_RESULT)
  1049. {
  1050. bFileExBtn = true;
  1051. // UNDONE: what to do here with SvrMgrToolbar1Buttons1?
  1052. // For now, do nothing: allow them to remain in same state
  1053. }
  1054. else // sub folder slected
  1055. {
  1056. CFolder* pFolder = reinterpret_cast<CFolder*>(pInternal->m_cookie);
  1057. ASSERT(m_pControlbar);
  1058. if (pInternal->m_cookie == 0)
  1059. {
  1060. if (IsPrimaryImpl() == TRUE)
  1061. {
  1062. // Attach the SvrMgrToolbar1 to the window
  1063. hr = m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pSvrMgrToolbar1);
  1064. ASSERT(SUCCEEDED(hr));
  1065. }
  1066. }
  1067. else if (IsPrimaryImpl() == TRUE /*&&
  1068. ( pFolder->GetType() == SERVER_INSTANCE ||
  1069. pFolder->GetType() == SERVERFUNC_CRL_PUBLICATION ||
  1070. pFolder->GetType() == SERVERFUNC_ISSUED_CERTIFICATES ||
  1071. pFolder->GetType() == SERVERFUNC_PENDING_CERTIFICATES )*/)
  1072. {
  1073. // Attach the SvrMgrToolbar1 to the window
  1074. hr = m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pSvrMgrToolbar1);
  1075. ASSERT(SUCCEEDED(hr));
  1076. }
  1077. else
  1078. {
  1079. // Detach the SvrMgrToolbar1 to the window
  1080. hr = m_pControlbar->Detach((LPUNKNOWN) m_pSvrMgrToolbar1);
  1081. ASSERT(SUCCEEDED(hr));
  1082. }
  1083. }
  1084. }
  1085. #ifdef INSERT_DEBUG_FOLDERS
  1086. if (m_pMenuButton1)
  1087. {
  1088. // Always make sure the menuButton is attached
  1089. m_pControlbar->Attach(MENUBUTTON, m_pMenuButton1);
  1090. if (bFileExBtn)
  1091. {
  1092. m_pMenuButton1->SetButtonState(FILEEX_MENU, HIDDEN, FALSE);
  1093. m_pMenuButton1->SetButtonState(FOLDEREX_MENU, HIDDEN, TRUE);
  1094. m_pMenuButton1->SetButtonState(FILEEX_MENU, ENABLED, TRUE);
  1095. }
  1096. else
  1097. {
  1098. m_pMenuButton1->SetButtonState(FOLDEREX_MENU, HIDDEN, FALSE);
  1099. m_pMenuButton1->SetButtonState(FILEEX_MENU, HIDDEN, TRUE);
  1100. m_pMenuButton1->SetButtonState(FOLDEREX_MENU, ENABLED, TRUE);
  1101. }
  1102. }
  1103. #endif // INSERT_DEBUG_FOLDERS
  1104. FREE_DATA(pInternal);
  1105. }
  1106. // dropdown menu addition
  1107. void CSnapin::HandleExtMenus(LPARAM arg, LPARAM param)
  1108. {
  1109. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1110. LPDATAOBJECT* ppDataObject = reinterpret_cast<LPDATAOBJECT*>(arg);
  1111. LPMENUBUTTONDATA pMenuData = reinterpret_cast<LPMENUBUTTONDATA>(param);
  1112. if (ppDataObject == NULL || pMenuData == NULL)
  1113. {
  1114. ASSERT(FALSE);
  1115. return;
  1116. }
  1117. HMENU hMenu = NULL;
  1118. HMENU hSubMenu = NULL;
  1119. switch (pMenuData->idCommand)
  1120. {
  1121. case FOLDEREX_MENU:
  1122. hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(FOLDEREX_MENU));
  1123. if (NULL == hMenu)
  1124. break;
  1125. hSubMenu = GetSubMenu(hMenu, 0);
  1126. break;
  1127. case FILEEX_MENU:
  1128. hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(FILEEX_MENU));
  1129. if (NULL == hMenu)
  1130. break;
  1131. hSubMenu = GetSubMenu(hMenu, 0);
  1132. break;
  1133. default:
  1134. ASSERT(FALSE);
  1135. }
  1136. if (hSubMenu == NULL)
  1137. {
  1138. // might've already loaded hMenu -- free if we have
  1139. if (NULL != hMenu)
  1140. DestroyMenu(hMenu);
  1141. return;
  1142. }
  1143. //pMenu->TrackPopupMenu(TPM_RETURNCMD | TPM_NONOTIFY, pMenuData->x, pMenuData->y, AfxGetMainWnd());
  1144. HWND hwndMain = NULL;
  1145. m_pConsole->GetMainWindow(&hwndMain);
  1146. TrackPopupMenu(hSubMenu, TPM_RETURNCMD | TPM_NONOTIFY, pMenuData->x, pMenuData->y, 0, hwndMain, NULL);
  1147. }
  1148. void CSnapin::GetItemName(LPDATAOBJECT pdtobj, LPWSTR pszName, DWORD *pcName)
  1149. {
  1150. ASSERT(pszName != NULL);
  1151. pszName[0] = 0;
  1152. INTERNAL* pInternal = ExtractInternalFormat(pdtobj);
  1153. ASSERT(pInternal != NULL);
  1154. if (pInternal == NULL)
  1155. return;
  1156. ASSERT(pcName != NULL);
  1157. if (pcName == NULL)
  1158. return;
  1159. OLECHAR *pszTemp;
  1160. if (pInternal->m_type == CCT_RESULT)
  1161. {
  1162. RESULT_DATA* pData;
  1163. pData = reinterpret_cast<RESULT_DATA*>(pInternal->m_cookie);
  1164. ASSERT(pData != NULL);
  1165. pszTemp = pData->szStringArray[RESULTDATA_ARRAYENTRY_NAME]; // szName
  1166. }
  1167. else
  1168. {
  1169. CFolder* pFolder = reinterpret_cast<CFolder*>(pInternal->m_cookie);
  1170. if (pFolder == 0)
  1171. pszTemp = L"Static folder";
  1172. else
  1173. pszTemp = OLE2W(pFolder->m_pszName);
  1174. }
  1175. USES_CONVERSION;
  1176. lstrcpyn(pszName, OLE2W(pszTemp), *pcName);
  1177. if(*pcName > wcslen(pszName))
  1178. {
  1179. *pcName = wcslen(pszName) + 1;
  1180. }
  1181. FREE_DATA(pInternal);
  1182. }
  1183. /////////////////////////////////////////////////////////////////////////////
  1184. // IExtendPropertySheet Implementation
  1185. STDMETHODIMP CSnapin::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  1186. LONG_PTR handle,
  1187. LPDATAOBJECT lpIDataObject)
  1188. {
  1189. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1190. // Look at the data object and determine if this an extension or a primary
  1191. ASSERT(lpIDataObject != NULL);
  1192. PropertyPage* pBasePage;
  1193. INTERNAL* pInternal = ExtractInternalFormat(lpIDataObject);
  1194. if(pInternal == NULL)
  1195. {
  1196. return E_POINTER;
  1197. }
  1198. switch (pInternal->m_type)
  1199. {
  1200. case CCT_RESULT:
  1201. {
  1202. if (0 == pInternal->m_cookie)
  1203. {
  1204. // base scope
  1205. // Create the primary property page
  1206. CGeneralPage* pPage = new CGeneralPage();
  1207. if(pPage == NULL)
  1208. {
  1209. return E_OUTOFMEMORY;
  1210. }
  1211. pPage->m_hConsoleHandle = handle;
  1212. pBasePage = pPage;
  1213. break;
  1214. }
  1215. else
  1216. {
  1217. // switch on folder type
  1218. CFolder* pFolder = reinterpret_cast<CFolder*>(pInternal->m_cookie);
  1219. ASSERT(pFolder != NULL);
  1220. if (pFolder == NULL)
  1221. return E_INVALIDARG;
  1222. //1
  1223. CCertTemplateGeneralPage* pControlPage = new CCertTemplateGeneralPage(pFolder->m_hCertType);
  1224. if(pControlPage == NULL)
  1225. {
  1226. return E_OUTOFMEMORY;
  1227. }
  1228. {
  1229. pControlPage->m_hConsoleHandle = handle; // only do this on primary
  1230. pBasePage = pControlPage;
  1231. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1232. if (hPage == NULL)
  1233. {
  1234. delete (pControlPage);
  1235. return E_UNEXPECTED;
  1236. }
  1237. lpProvider->AddPage(hPage);
  1238. }
  1239. return S_OK;
  1240. }
  1241. }
  1242. break;
  1243. default:
  1244. return S_OK;
  1245. }
  1246. // Object gets deleted when the page is destroyed
  1247. ASSERT(lpProvider != NULL);
  1248. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1249. if (hPage == NULL)
  1250. return E_UNEXPECTED;
  1251. lpProvider->AddPage(hPage);
  1252. return S_OK;
  1253. }
  1254. STDMETHODIMP CSnapin::QueryPagesFor(LPDATAOBJECT lpDataObject)
  1255. {
  1256. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1257. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1258. if(pInternal == NULL)
  1259. {
  1260. return E_POINTER;
  1261. }
  1262. ASSERT(pInternal);
  1263. ASSERT(pInternal->m_type == CCT_RESULT);
  1264. CFolder* pFolder = reinterpret_cast<CFolder*>(pInternal->m_cookie);
  1265. FREE_DATA(pInternal);
  1266. return S_OK;
  1267. }