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.

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