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.

314 lines
8.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: compdata.cpp
  7. //
  8. // Contents:
  9. //
  10. // History: 07-26-2001 Hiteshr Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.h"
  14. // {1F5EEC01-1214-4d94-80C5-4BDCD2014DDD}
  15. const GUID CLSID_RoleSnapin =
  16. { 0x1f5eec01, 0x1214, 0x4d94, { 0x80, 0xc5, 0x4b, 0xdc, 0xd2, 0x1, 0x4d, 0xdd } };
  17. DEBUG_DECLARE_INSTANCE_COUNTER(CRoleComponentDataObject)
  18. CRoleComponentDataObject::CRoleComponentDataObject()
  19. {
  20. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN, CRoleComponentDataObject)
  21. DEBUG_INCREMENT_INSTANCE_COUNTER(CRoleComponentDataObject)
  22. m_columnSetList.AddTail(new CRoleDefaultColumnSet(L"---Default Column Set---"));
  23. }
  24. CRoleComponentDataObject::~CRoleComponentDataObject()
  25. {
  26. TRACE_DESTRUCTOR_EX(DEB_SNAPIN, CRoleComponentDataObject)
  27. DEBUG_DECREMENT_INSTANCE_COUNTER(CRoleComponentDataObject)
  28. }
  29. STDMETHODIMP
  30. CRoleComponentDataObject::
  31. CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  32. {
  33. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject,CompareObjects)
  34. if(!lpDataObjectA || !lpDataObjectB)
  35. {
  36. ASSERT(lpDataObjectA);
  37. ASSERT(lpDataObjectB);
  38. }
  39. CInternalFormatCracker ifcA, ifcB;
  40. VERIFY(SUCCEEDED(ifcA.Extract(lpDataObjectA)));
  41. VERIFY(SUCCEEDED(ifcB.Extract(lpDataObjectB)));
  42. CTreeNode* pNodeA = ifcA.GetCookieAt(0);
  43. CTreeNode* pNodeB = ifcB.GetCookieAt(0);
  44. if(!pNodeA || !pNodeB)
  45. {
  46. ASSERT(pNodeA != NULL);
  47. ASSERT(pNodeB != NULL);
  48. return S_FALSE;
  49. }
  50. if(pNodeA == pNodeB)
  51. return S_OK;
  52. //Check if the are of same type container or leafnode
  53. if(pNodeA->IsContainer() != pNodeB->IsContainer())
  54. return S_FALSE;
  55. CBaseAz* pBaseAzA = (dynamic_cast<CBaseNode*>(pNodeA))->GetBaseAzObject();
  56. CBaseAz* pBaseAzB = (dynamic_cast<CBaseNode*>(pNodeB))->GetBaseAzObject();
  57. ASSERT(pBaseAzA);
  58. ASSERT(pBaseAzB);
  59. if(CompareBaseAzObjects(pBaseAzA,pBaseAzB))
  60. {
  61. return S_OK;
  62. }
  63. return S_FALSE;
  64. }
  65. CRootData*
  66. CRoleComponentDataObject::
  67. OnCreateRootData()
  68. {
  69. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject, OnCreateRootData)
  70. CRoleRootData* pRoleRootNode = new CRoleRootData(this);
  71. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  72. CString szSnapinName;
  73. szSnapinName.LoadString(IDS_SNAPIN_NAME);
  74. pRoleRootNode->SetDisplayName(szSnapinName);
  75. return pRoleRootNode;
  76. }
  77. STDMETHODIMP
  78. CRoleComponentDataObject::
  79. CreateComponent(LPCOMPONENT* ppComponent)
  80. {
  81. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject,CreateComponent)
  82. if(!ppComponent)
  83. {
  84. ASSERT(FALSE);
  85. return E_POINTER;
  86. }
  87. CComObject<CRoleComponentObject>* pObject;
  88. HRESULT hr = CComObject<CRoleComponentObject>::CreateInstance(&pObject);
  89. if(FAILED(hr))
  90. {
  91. DBG_OUT_HRESULT(hr);
  92. return hr;
  93. }
  94. ASSERT(pObject != NULL);
  95. //
  96. // Store IComponentData
  97. //
  98. pObject->SetIComponentData(this);
  99. hr = pObject->QueryInterface(IID_IComponent,
  100. reinterpret_cast<void**>(ppComponent));
  101. CHECK_HRESULT(hr);
  102. return hr;
  103. }
  104. BOOL
  105. CRoleComponentDataObject::LoadResources()
  106. {
  107. return
  108. LoadContextMenuResources(CRootDataMenuHolder::GetMenuMap()) &&
  109. LoadContextMenuResources(CAdminManagerNodeMenuHolder::GetMenuMap()) &&
  110. LoadContextMenuResources(CApplicationNodeMenuHolder::GetMenuMap()) &&
  111. LoadContextMenuResources(CScopeNodeMenuHolder::GetMenuMap()) &&
  112. LoadContextMenuResources(CGroupCollectionNodeMenuHolder::GetMenuMap()) &&
  113. LoadContextMenuResources(CRoleCollectionNodeMenuHolder::GetMenuMap()) &&
  114. LoadContextMenuResources(CTaskCollectionNodeMenuHolder::GetMenuMap()) &&
  115. LoadContextMenuResources(CGroupNodeMenuHolder::GetMenuMap()) &&
  116. LoadContextMenuResources(CRoleNodeMenuHolder::GetMenuMap()) &&
  117. LoadContextMenuResources(CTaskNodeMenuHolder::GetMenuMap()) &&
  118. LoadContextMenuResources(COperationCollectionNodeMenuHolder::GetMenuMap()) &&
  119. LoadContextMenuResources(CRoleDefinitionCollectionNodeMenuHolder::GetMenuMap()) &&
  120. LoadResultHeaderResources(_DefaultHeaderStrings,N_DEFAULT_HEADER_COLS);
  121. }
  122. HRESULT
  123. CRoleComponentDataObject::OnSetImages(LPIMAGELIST lpScopeImage)
  124. {
  125. TRACE_METHOD_EX(DEB_SNAPIN, CRoleComponentDataObject, OnSetImages)
  126. return LoadIcons(lpScopeImage);
  127. }
  128. LPCWSTR
  129. CRoleComponentDataObject::
  130. GetHTMLHelpFileName()
  131. {
  132. TRACE_METHOD_EX(DEB_SNAPIN, CRoleComponentDataObject, GetHTMLHelpFileName)
  133. Dbg(DEB_SNAPIN,"HTMLHelpFile is %ws\n", g_szHTMLHelpFileName);
  134. return g_szHTMLHelpFileName;
  135. }
  136. void
  137. CRoleComponentDataObject::
  138. OnNodeContextHelp(CNodeList* /*pNode*/)
  139. {
  140. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject,OnNodeContextHelp)
  141. CComPtr<IDisplayHelp> spHelp;
  142. HRESULT hr = GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  143. if (SUCCEEDED(hr))
  144. {
  145. CString strHelpPath = g_szLinkHTMLHelpFileName;
  146. strHelpPath += L"::/";
  147. strHelpPath += g_szTopHelpNodeName;
  148. spHelp->ShowTopic((LPOLESTR)(LPCWSTR)strHelpPath);
  149. }
  150. }
  151. void
  152. CRoleComponentDataObject::
  153. OnNodeContextHelp(CTreeNode*)
  154. {
  155. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject,OnNodeContextHelp)
  156. CComPtr<IDisplayHelp> spHelp;
  157. HRESULT hr = GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  158. if (SUCCEEDED(hr))
  159. {
  160. CString strHelpPath = g_szLinkHTMLHelpFileName;
  161. strHelpPath += L"::/";
  162. strHelpPath += g_szTopHelpNodeName;
  163. spHelp->ShowTopic((LPOLESTR)(LPCWSTR)strHelpPath);
  164. }
  165. }
  166. void
  167. CRoleComponentDataObject::OnTimer()
  168. {
  169. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject,OnTimer)
  170. }
  171. void
  172. CRoleComponentDataObject::OnTimerThread(WPARAM /*wParam*/, LPARAM /*lParam*/)
  173. {
  174. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject,OnTimerThread)
  175. }
  176. CTimerThread*
  177. CRoleComponentDataObject::OnCreateTimerThread()
  178. {
  179. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject,OnCreateTimerThread)
  180. return NULL;
  181. }
  182. CColumnSet*
  183. CRoleComponentDataObject::GetColumnSet(LPCWSTR lpszID)
  184. {
  185. TRACE_METHOD_EX(DEB_SNAPIN,CRoleComponentDataObject, GetColumnSet)
  186. return m_columnSetList.FindColumnSet(lpszID);
  187. }
  188. void
  189. CBaseRoleExecContext::
  190. Wait()
  191. {
  192. // The message loop lasts until we get a WM_QUIT message,
  193. // upon which we shall return from the function.
  194. while (TRUE)
  195. {
  196. DWORD result = 0;
  197. MSG msg ;
  198. // Read all of the messages in this next loop,
  199. // removing each message as we read it.
  200. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  201. {
  202. // If it's a quit message
  203. if(msg.message == WM_QUIT)
  204. {
  205. return;
  206. }
  207. else if((msg.message == WM_LBUTTONDOWN) ||
  208. (msg.message == WM_RBUTTONDOWN) ||
  209. (msg.message == WM_KEYDOWN))
  210. {
  211. //Ignore these messages while in wait
  212. continue;
  213. }
  214. // Otherwise, dispatch the message.
  215. DispatchMessage(&msg);
  216. } // End of PeekMessage while loop.
  217. // Wait for any message sent or posted to this queue
  218. // or for one of the passed handles be set to signaled.
  219. result = MsgWaitForMultipleObjects(1, &m_hEventHandle,
  220. FALSE, INFINITE, QS_ALLINPUT);
  221. // The result tells us the type of event we have.
  222. if (result == (WAIT_OBJECT_0 + 1))
  223. {
  224. // New messages have arrived.
  225. // Continue to the top of the always while loop to
  226. // dispatch them and resume waiting.
  227. continue;
  228. }
  229. else
  230. {
  231. // One of the handles became signaled.
  232. return;
  233. } // End of else clause.
  234. } // End of the always while loop.
  235. }
  236. void CDisplayHelpFromPropPageExecContext::
  237. Execute(LPARAM /*arg*/)
  238. {
  239. CComPtr<IDisplayHelp> spHelp;
  240. HRESULT hr = m_pComponentDataObject->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  241. if (SUCCEEDED(hr))
  242. {
  243. hr = spHelp->ShowTopic((LPOLESTR)(LPCWSTR)m_strHelpPath);
  244. CHECK_HRESULT(hr);
  245. }
  246. }
  247. //
  248. //Helper Class for displaying secondary property pages from
  249. //Existing property pages. For example on double clicking
  250. //a member of group, display the property of member. Since
  251. //propertysheet needs to be brought up from main thread, a
  252. //message is posted from PropertyPage thread to Main thread.
  253. //An instance of this class is sent as param and main
  254. //thread calls execute on the Instance
  255. //
  256. void
  257. CPropPageExecContext::Execute(LPARAM /*arg*/)
  258. {
  259. FindOrCreateModelessPropertySheet((CRoleComponentDataObject*)pComponentDataObject,pTreeNode);
  260. }