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.

523 lines
12 KiB

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