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.

587 lines
14 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation
  3. Module Name:
  4. events.cpp
  5. Abstract:
  6. implementation of CComponent functions
  7. Author:
  8. William Hsieh (williamh) created
  9. Revision History:
  10. --*/
  11. #include "devmgr.h"
  12. HRESULT CComponent::OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  13. {
  14. UNREFERENCED_PARAMETER(param);
  15. //
  16. // Note - arg is TRUE when it is time to enumerate
  17. //
  18. CFolder* pFolder = FindFolder(cookie);
  19. if (arg) {
  20. m_pCurFolder = pFolder;
  21. }
  22. if (pFolder) {
  23. return pFolder->OnShow((BOOL)arg);
  24. } else {
  25. return S_OK;
  26. }
  27. }
  28. HRESULT CComponent::OnMinimize(
  29. MMC_COOKIE cookie,
  30. LPARAM arg,
  31. LPARAM param
  32. )
  33. {
  34. UNREFERENCED_PARAMETER(cookie);
  35. UNREFERENCED_PARAMETER(arg);
  36. UNREFERENCED_PARAMETER(param);
  37. return S_OK;
  38. }
  39. HRESULT CComponent::OnViewChange(
  40. MMC_COOKIE cookie,
  41. LPARAM arg,
  42. LPARAM param
  43. )
  44. {
  45. UNREFERENCED_PARAMETER(cookie);
  46. UNREFERENCED_PARAMETER(arg);
  47. UNREFERENCED_PARAMETER(param);
  48. return S_OK;
  49. }
  50. HRESULT CComponent::OnProperties(
  51. MMC_COOKIE cookie,
  52. LPARAM arg,
  53. LPARAM param
  54. )
  55. {
  56. UNREFERENCED_PARAMETER(cookie);
  57. UNREFERENCED_PARAMETER(arg);
  58. UNREFERENCED_PARAMETER(param);
  59. return S_OK;
  60. }
  61. HRESULT CComponent::OnResultItemClick(
  62. MMC_COOKIE cookie,
  63. LPARAM arg,
  64. LPARAM param
  65. )
  66. {
  67. UNREFERENCED_PARAMETER(cookie);
  68. UNREFERENCED_PARAMETER(arg);
  69. UNREFERENCED_PARAMETER(param);
  70. return S_OK;
  71. }
  72. HRESULT CComponent::OnResultItemDblClick(
  73. MMC_COOKIE cookie,
  74. LPARAM arg,
  75. LPARAM param
  76. )
  77. {
  78. UNREFERENCED_PARAMETER(cookie);
  79. UNREFERENCED_PARAMETER(arg);
  80. UNREFERENCED_PARAMETER(param);
  81. return S_FALSE;
  82. }
  83. HRESULT CComponent::OnActivate(
  84. MMC_COOKIE cookie,
  85. LPARAM arg,
  86. LPARAM param
  87. )
  88. {
  89. UNREFERENCED_PARAMETER(cookie);
  90. UNREFERENCED_PARAMETER(arg);
  91. UNREFERENCED_PARAMETER(param);
  92. return S_OK;
  93. }
  94. HRESULT CComponent::OnSelect(
  95. MMC_COOKIE cookie,
  96. LPARAM arg,
  97. LPARAM param
  98. )
  99. {
  100. UNREFERENCED_PARAMETER(param);
  101. CFolder* pFolder;
  102. pFolder = FindFolder(cookie);
  103. if (pFolder && LOWORD(arg)) {
  104. //
  105. // LOWORD(arg) being set indicated this is for the scope pane item.
  106. // Save the bSelect value for use by the MenuCommand.
  107. //
  108. pFolder->m_bSelect = (BOOL) HIWORD(arg);
  109. }
  110. if (!pFolder || S_FALSE == pFolder->OnSelect()) {
  111. //
  112. // either we can not find the responsible folder
  113. // or the responsible folder asks us to do it,
  114. // set the console verb to its defaults
  115. //
  116. m_pConsoleVerb->SetVerbState(MMC_VERB_OPEN, HIDDEN, TRUE);
  117. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, TRUE);
  118. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  119. m_pConsoleVerb->SetVerbState(MMC_VERB_PASTE, HIDDEN, TRUE);
  120. m_pConsoleVerb->SetVerbState(MMC_VERB_REFRESH, HIDDEN, TRUE);
  121. m_pConsoleVerb->SetVerbState(MMC_VERB_PRINT, HIDDEN, TRUE);
  122. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  123. }
  124. return S_OK;
  125. }
  126. HRESULT CComponent::OnOcxNotify(
  127. MMC_NOTIFY_TYPE event,
  128. LPARAM arg,
  129. LPARAM param
  130. )
  131. {
  132. //TRACE1(TEXT("Componet:OnOcxNotify, event = %lx\n"), event);
  133. if (m_pCurFolder) {
  134. return m_pCurFolder->OnOcxNotify(event, arg, param);
  135. }
  136. return S_OK;
  137. }
  138. HRESULT CComponent::OnBtnClick(
  139. MMC_COOKIE cookie,
  140. LPARAM arg,
  141. LPARAM param
  142. )
  143. {
  144. UNREFERENCED_PARAMETER(cookie);
  145. UNREFERENCED_PARAMETER(arg);
  146. UNREFERENCED_PARAMETER(param);
  147. return S_OK;
  148. }
  149. HRESULT CComponent::OnAddImages(
  150. MMC_COOKIE cookie,
  151. IImageList* pIImageList,
  152. HSCOPEITEM hScopeItem
  153. )
  154. {
  155. UNREFERENCED_PARAMETER(hScopeItem);
  156. if (!cookie) {
  157. return LoadScopeIconsForResultPane(pIImageList);
  158. }
  159. return S_OK;
  160. }
  161. HRESULT CComponent::OnRestoreView(
  162. MMC_COOKIE cookie,
  163. LPARAM arg,
  164. LPARAM param
  165. )
  166. {
  167. UNREFERENCED_PARAMETER(arg);
  168. if (!param) {
  169. return E_INVALIDARG;
  170. }
  171. CFolder* pFolder;
  172. pFolder = FindFolder(cookie);
  173. if (pFolder) {
  174. return pFolder->OnRestoreView((BOOL*)param);
  175. } else {
  176. *((BOOL *)param) = FALSE;
  177. return S_OK;
  178. }
  179. }
  180. HRESULT CComponent::OnContextHelp(
  181. MMC_COOKIE cookie,
  182. LPARAM arg,
  183. LPARAM param
  184. )
  185. {
  186. UNREFERENCED_PARAMETER(cookie);
  187. UNREFERENCED_PARAMETER(arg);
  188. UNREFERENCED_PARAMETER(param);
  189. String strHelpOverview;
  190. String strHelpTopic;
  191. //
  192. // Load help file and overview topic strings.
  193. //
  194. strHelpOverview.LoadString(g_hInstance, IDS_HTMLHELP_NAME);
  195. strHelpTopic.LoadString(g_hInstance, IDS_HTMLHELP_OVERVIEW_TOPIC);
  196. strHelpOverview += TEXT("::");
  197. strHelpOverview += strHelpTopic;
  198. return m_pDisplayHelp->ShowTopic(const_cast<BSTR>((LPCTSTR)strHelpOverview));
  199. }
  200. HRESULT CComponent::LoadScopeIconsForResultPane(
  201. IImageList* pIImageList
  202. )
  203. {
  204. if (pIImageList) {
  205. HICON hIcon;
  206. HRESULT hr = S_OK;
  207. hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_DEVMGR));
  208. if (hIcon) {
  209. hr = pIImageList->ImageListSetIcon((PLONG_PTR)hIcon, IMAGE_INDEX_DEVMGR);
  210. DeleteObject(hIcon);
  211. }
  212. return hr;
  213. } else {
  214. return E_INVALIDARG;
  215. }
  216. }
  217. #if DBG
  218. TCHAR *tvNotifyStr[] = {
  219. TEXT("CLICK"),
  220. TEXT("DBLCLK"),
  221. TEXT("RCLICK"),
  222. TEXT("RDBLCLK"),
  223. TEXT("KEYDOWN"),
  224. TEXT("CONTEXTMENU"),
  225. TEXT("EXPANDING"),
  226. TEXT("EXPANDED"),
  227. TEXT("SELCHANGING"),
  228. TEXT("SELCHANGED"),
  229. TEXT("GETDISPINFO"),
  230. TEXT("FOCUSCHANGED"),
  231. TEXT("UNKNOWN")
  232. };
  233. #endif
  234. HRESULT CComponent::tvNotify(
  235. HWND hwndTV,
  236. MMC_COOKIE cookie,
  237. TV_NOTIFY_CODE Code,
  238. LPARAM arg,
  239. LPARAM param
  240. )
  241. {
  242. #if DBG
  243. int i = Code;
  244. if (Code > TV_NOTIFY_CODE_UNKNOWN) {
  245. i = TV_NOTIFY_CODE_UNKNOWN;
  246. }
  247. //TRACE((TEXT("Componet:tvNotify, Code = %lx %s cookie = %lx\n"), Code, tvNotifyStr[i], cookie));
  248. #endif
  249. CFolder* pFolder;
  250. pFolder = FindFolder(cookie);
  251. if (pFolder) {
  252. return pFolder->tvNotify(hwndTV, GetActiveCookie(cookie), Code, arg, param);
  253. }
  254. return S_FALSE;
  255. }
  256. ////////////////////////////////////////////////////////////////////////////
  257. //// IComponentData events handlers
  258. ////
  259. HRESULT
  260. CComponentData::OnProperties(
  261. MMC_COOKIE cookie,
  262. LPARAM arg,
  263. LPARAM param
  264. )
  265. {
  266. UNREFERENCED_PARAMETER(cookie);
  267. UNREFERENCED_PARAMETER(arg);
  268. UNREFERENCED_PARAMETER(param);
  269. return S_OK;
  270. }
  271. HRESULT
  272. CComponentData::OnBtnClick(
  273. MMC_COOKIE cookie,
  274. LPARAM arg,
  275. LPARAM param
  276. )
  277. {
  278. UNREFERENCED_PARAMETER(cookie);
  279. UNREFERENCED_PARAMETER(arg);
  280. UNREFERENCED_PARAMETER(param);
  281. return S_OK;
  282. }
  283. HRESULT
  284. CComponentData::OnDelete(
  285. MMC_COOKIE cookie,
  286. LPARAM arg,
  287. LPARAM param
  288. )
  289. {
  290. UNREFERENCED_PARAMETER(cookie);
  291. UNREFERENCED_PARAMETER(arg);
  292. UNREFERENCED_PARAMETER(param);
  293. return S_OK;
  294. }
  295. HRESULT
  296. CComponentData::OnRename(
  297. MMC_COOKIE cookie,
  298. LPARAM arg,
  299. LPARAM param
  300. )
  301. {
  302. UNREFERENCED_PARAMETER(cookie);
  303. UNREFERENCED_PARAMETER(arg);
  304. UNREFERENCED_PARAMETER(param);
  305. return S_OK;
  306. }
  307. //
  308. // This function handles the MMCN_EXPAND notification code
  309. // Input: lpDataObject -- point to the target IDataObject
  310. // arg -- TRUE if expanding, FALSE if collapsing.
  311. // param -- not used.
  312. //
  313. // Output: HRESULT
  314. HRESULT
  315. CComponentData::OnExpand(
  316. LPDATAOBJECT lpDataObject,
  317. LPARAM arg,
  318. LPARAM param
  319. )
  320. {
  321. INTERNAL_DATA tID;
  322. HRESULT hr;
  323. //
  324. // If we are not expanding, do nothing
  325. //
  326. if (!arg) {
  327. return S_OK;
  328. }
  329. hr = ExtractData(lpDataObject, CDataObject::m_cfSnapinInternal,
  330. (PBYTE)&tID, sizeof(tID));
  331. if (SUCCEEDED(hr)) {
  332. hr = CreateScopeItems();
  333. if (SUCCEEDED(hr) && !m_pMachine) {
  334. if (!g_MachineList.CreateMachine(m_strMachineName, &m_pMachine)) {
  335. hr = HRESULT_FROM_WIN32(GetLastError());
  336. }
  337. }
  338. if (SUCCEEDED(hr)) {
  339. CCookie* pCookie = GetActiveCookie(tID.cookie);
  340. ASSERT(pCookie);
  341. HSCOPEITEM hScopeParent = (HSCOPEITEM)param;
  342. CScopeItem* pScopeItem = pCookie->GetScopeItem();
  343. ASSERT(pScopeItem);
  344. pScopeItem->SetHandle(hScopeParent);
  345. //
  346. // If we have children and this is the first time we
  347. // are expanding, insert all the children to scope pane.
  348. //
  349. if (pCookie->GetChild() && !pScopeItem->IsEnumerated()) {
  350. SCOPEDATAITEM ScopeDataItem;
  351. CCookie* pTheCookie = pCookie->GetChild();
  352. do {
  353. CScopeItem* pTheItem = pTheCookie->GetScopeItem();
  354. ASSERT(pTheItem);
  355. ScopeDataItem.relativeID = hScopeParent;
  356. ScopeDataItem.nState = 0;
  357. ScopeDataItem.displayname = (LPOLESTR)(-1);
  358. ScopeDataItem.mask = SDI_IMAGE | SDI_OPENIMAGE | SDI_CHILDREN |
  359. SDI_STR | SDI_PARAM | SDI_STATE;
  360. ScopeDataItem.nImage = pTheItem->GetImageIndex();
  361. ScopeDataItem.nOpenImage = pTheItem->GetOpenImageIndex();
  362. ScopeDataItem.cChildren = pTheItem->GetChildCount();
  363. ScopeDataItem.lParam = reinterpret_cast<LPARAM>(pTheCookie);
  364. hr = m_pScope->InsertItem(&ScopeDataItem);
  365. if (FAILED(hr)) {
  366. break;
  367. }
  368. pTheItem->SetHandle(ScopeDataItem.ID);
  369. pTheCookie = pTheCookie->GetSibling();
  370. } while (pTheCookie);
  371. }
  372. pScopeItem->Enumerated();
  373. }
  374. }
  375. else {
  376. //
  377. // The provided lpDataObject is not ours, we are being
  378. // expanded as an extension snapin. Find out what
  379. // node type the data object is. If it is "MyComputer"
  380. // system tools, attach our scope items to
  381. // it.
  382. //
  383. CLSID CLSID_NodeType;
  384. hr = ExtractData(lpDataObject, CDataObject::m_cfNodeType,
  385. (PBYTE)&CLSID_NodeType, sizeof(CLSID_NodeType));
  386. if (FAILED(hr)) {
  387. return hr;
  388. }
  389. if (CLSID_SYSTOOLS == CLSID_NodeType) {
  390. TCHAR MachineName[MAX_PATH + 1];
  391. MachineName[0] = _T('\0');
  392. hr = ExtractData(lpDataObject, CDataObject::m_cfMachineName,
  393. (BYTE*)MachineName, sizeof(MachineName));
  394. if (SUCCEEDED(hr)) {
  395. m_ctRoot = COOKIE_TYPE_SCOPEITEM_DEVMGR;
  396. m_strMachineName.Empty();
  397. if (_T('\0') != MachineName[0]) {
  398. if (_T('\\') != MachineName[0]) {
  399. m_strMachineName = TEXT("\\\\");
  400. }
  401. m_strMachineName += MachineName;
  402. }
  403. hr = CreateScopeItems();
  404. if (SUCCEEDED(hr)) {
  405. CMachine* pMachine;
  406. pMachine = g_MachineList.FindMachine(m_strMachineName);
  407. if (!pMachine || pMachine != m_pMachine) {
  408. if (!g_MachineList.CreateMachine(m_strMachineName, &m_pMachine)) {
  409. hr = HRESULT_FROM_WIN32(GetLastError());
  410. }
  411. }
  412. }
  413. }
  414. if (SUCCEEDED(hr)) {
  415. //
  416. // Always insert "Device Manager" node because
  417. // we are expanding as an extention to Computer Management
  418. //
  419. CCookie* pCookie = GetActiveCookie(0);
  420. ASSERT(pCookie);
  421. CScopeItem* pScopeItem = pCookie->GetScopeItem();
  422. ASSERT(pScopeItem);
  423. SCOPEDATAITEM ScopeDataItem;
  424. memset(&ScopeDataItem, 0, sizeof(ScopeDataItem));
  425. ScopeDataItem.relativeID = (HSCOPEITEM)(param);
  426. ScopeDataItem.nState = 0;
  427. ScopeDataItem.displayname = (LPOLESTR)(-1);
  428. ScopeDataItem.mask = SDI_IMAGE | SDI_OPENIMAGE | SDI_CHILDREN |
  429. SDI_STR | SDI_PARAM | SDI_STATE;
  430. ScopeDataItem.nImage = pScopeItem->GetImageIndex();
  431. ScopeDataItem.nOpenImage = pScopeItem->GetOpenImageIndex();
  432. ScopeDataItem.cChildren = pScopeItem->GetChildCount();
  433. ScopeDataItem.lParam = reinterpret_cast<LPARAM>(pCookie);
  434. hr = m_pScope->InsertItem(&ScopeDataItem);
  435. pScopeItem->SetHandle(ScopeDataItem.ID);
  436. }
  437. }
  438. }
  439. return hr;
  440. }
  441. HRESULT
  442. CComponentData::OnContextMenu(
  443. MMC_COOKIE cookie,
  444. LPARAM arg,
  445. LPARAM param
  446. )
  447. {
  448. UNREFERENCED_PARAMETER(cookie);
  449. UNREFERENCED_PARAMETER(arg);
  450. UNREFERENCED_PARAMETER(param);
  451. return S_OK;
  452. }