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.

404 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: querynode.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pch.h"
  11. #include <SnapBase.h>
  12. #include "resource.h"
  13. #include "connection.h"
  14. #include "querynode.h"
  15. #include "queryui.h"
  16. #include "editor.h"
  17. #include <aclpage.h>
  18. #ifdef DEBUG_ALLOCATOR
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. #endif
  25. ////////////////////////////////////////////////////////////////////////
  26. // CADSIEditQueryData
  27. void CADSIEditQueryData::SetRootPath(LPCWSTR lpszRootPath)
  28. {
  29. m_sRootPath = lpszRootPath;
  30. GetDisplayPath(m_sDN);
  31. }
  32. void CADSIEditQueryData::GetDisplayPath(CString& sDisplayPath)
  33. {
  34. CComPtr<IADsPathname> pIADsPathname;
  35. HRESULT hr = ::CoCreateInstance(CLSID_Pathname, NULL, CLSCTX_INPROC_SERVER,
  36. IID_IADsPathname, (PVOID *)&(pIADsPathname));
  37. ASSERT((S_OK == hr) && ((pIADsPathname) != NULL));
  38. hr = pIADsPathname->Set(CComBSTR(m_sRootPath), ADS_SETTYPE_FULL);
  39. if (FAILED(hr))
  40. {
  41. TRACE(_T("Set failed. %s"), hr);
  42. }
  43. // Get the leaf name
  44. CString sDN;
  45. BSTR bstrPath = NULL;
  46. hr = pIADsPathname->Retrieve(ADS_FORMAT_X500_DN, &bstrPath);
  47. if (FAILED(hr))
  48. {
  49. TRACE(_T("Failed to get element. %s"), hr);
  50. sDisplayPath = L"";
  51. }
  52. else
  53. {
  54. sDisplayPath = bstrPath;
  55. }
  56. }
  57. void CADSIEditQueryData::GetDisplayName(CString& sDisplayName)
  58. {
  59. CString sDisplayPath;
  60. GetDisplayPath(sDisplayPath);
  61. sDisplayName = m_sName + _T(" [") + sDisplayPath + _T("]");
  62. }
  63. ////////////////////////////////////////////////////////////////////////
  64. // CADSIEditQueryNode
  65. //
  66. // {072B64B7-CFF7-11d2-8801-00C04F72ED31}
  67. const GUID CADSIEditQueryNode::NodeTypeGUID =
  68. { 0x72b64b7, 0xcff7, 0x11d2, { 0x88, 0x1, 0x0, 0xc0, 0x4f, 0x72, 0xed, 0x31 } };
  69. CADSIEditQueryNode::CADSIEditQueryNode(CADsObject* pADsObject,
  70. CADSIEditQueryData* pQueryData)
  71. {
  72. m_pADsObject = pADsObject;
  73. m_pQueryData = pQueryData;
  74. m_nState = notLoaded;
  75. m_sType.LoadString(IDS_QUERY_STRING);
  76. }
  77. HRESULT CADSIEditQueryNode::OnCommand(long nCommandID,
  78. DATA_OBJECT_TYPES type,
  79. CComponentDataObject* pComponentData,
  80. CNodeList* pNodeList)
  81. {
  82. ASSERT (pNodeList->GetCount() == 1); // not allowing multiple selection on any of these yet
  83. switch (nCommandID)
  84. {
  85. case IDM_SETTINGS_QUERY :
  86. {
  87. OnSettings(pComponentData);
  88. break;
  89. }
  90. case IDM_REMOVE_QUERY :
  91. {
  92. OnRemove(pComponentData);
  93. break;
  94. }
  95. default:
  96. ASSERT(FALSE); // Unknown command!
  97. return E_FAIL;
  98. }
  99. return S_OK;
  100. }
  101. BOOL CADSIEditQueryNode::OnSetDeleteVerbState(DATA_OBJECT_TYPES type,
  102. BOOL* pbHideVerb,
  103. CNodeList* pNodeList)
  104. {
  105. if (pNodeList->GetCount() == 1) // single selection
  106. {
  107. *pbHideVerb = TRUE; // always hide the verb
  108. return FALSE;
  109. }
  110. //
  111. // Multiple selection
  112. //
  113. *pbHideVerb = FALSE;
  114. return TRUE;
  115. }
  116. void CADSIEditQueryNode::OnRemove(CComponentDataObject* pComponentData)
  117. {
  118. if (ADSIEditMessageBox(IDS_MSG_REMOVE_QUERY, MB_YESNO | MB_DEFBUTTON2) == IDYES)
  119. {
  120. BOOL bLocked = IsThreadLocked();
  121. ASSERT(!bLocked); // cannot do refresh on locked node, the UI should prevent this
  122. if (bLocked)
  123. return;
  124. if (IsSheetLocked())
  125. {
  126. if (!CanCloseSheets())
  127. return;
  128. // Do deletion stuff
  129. pComponentData->GetPropertyPageHolderTable()->DeleteSheetsOfNode(this);
  130. }
  131. ASSERT(!IsSheetLocked());
  132. // Remove query data from connection node's list
  133. GetADsObject()->GetConnectionNode()->RemoveQueryFromList(GetQueryData());
  134. // now remove from the UI
  135. DeleteHelper(pComponentData);
  136. pComponentData->SetDescriptionBarText(GetContainer());
  137. delete this; // gone
  138. }
  139. }
  140. void CADSIEditQueryNode::OnDelete(CComponentDataObject* pComponentData,
  141. CNodeList* pNodeList)
  142. {
  143. if (pNodeList->GetCount() > 1) // multiple selection
  144. {
  145. // Delete some results
  146. OnDeleteMultiple(pComponentData, pNodeList);
  147. }
  148. else if (pNodeList->GetCount() == 1) // single selection
  149. {
  150. // Can't delete a query node
  151. ASSERT(FALSE);
  152. }
  153. }
  154. void CADSIEditQueryNode::OnSettings(CComponentDataObject* pComponentData)
  155. {
  156. CThemeContextActivator activator;
  157. // Get the data from the existing query node data
  158. BOOL bOneLevel;
  159. bOneLevel = (GetQueryData()->GetScope() == ADS_SCOPE_ONELEVEL);
  160. CString sFilter, sName, sPath, sConnectPath;
  161. GetQueryData()->GetName(sName);
  162. GetQueryData()->GetFilter(sFilter);
  163. GetQueryData()->GetRootPath(sPath);
  164. CConnectionData* pConnectData = GetADsObject()->GetConnectionNode()->GetConnectionData();
  165. ASSERT(pConnectData);
  166. GetADsObject()->GetConnectionNode()->GetADsObject()->GetPath(sConnectPath);
  167. CCredentialObject* pCredObject =
  168. pConnectData->GetCredentialObject();
  169. CString szServer;
  170. pConnectData->GetDomainServer(szServer);
  171. // Initialize dialog with data
  172. CADSIEditQueryDialog queryDialog(szServer, sName, sFilter, sPath, sConnectPath, bOneLevel, pCredObject);
  173. if (queryDialog.DoModal() == IDOK)
  174. {
  175. // If OK
  176. CString sNewPath;
  177. queryDialog.GetResults(sName, sFilter, sNewPath, &bOneLevel);
  178. GetQueryData()->SetName(sName);
  179. GetQueryData()->SetFilter(sFilter);
  180. GetQueryData()->SetRootPath(sNewPath);
  181. GetADsObject()->SetPath(sNewPath);
  182. ADS_SCOPEENUM scope = (bOneLevel) ? ADS_SCOPE_ONELEVEL : ADS_SCOPE_SUBTREE;
  183. GetQueryData()->SetScope(scope);
  184. // Make changes take effect
  185. CString sDisplayName;
  186. GetQueryData()->GetDisplayName(sDisplayName);
  187. SetDisplayName(sDisplayName);
  188. CNodeList nodeList;
  189. nodeList.AddTail(this);
  190. OnRefresh(pComponentData, &nodeList);
  191. }
  192. }
  193. LPCWSTR CADSIEditQueryNode::GetString(int nCol)
  194. {
  195. switch(nCol)
  196. {
  197. case N_HEADER_NAME :
  198. return GetDisplayName();
  199. case N_HEADER_TYPE :
  200. return m_sType;
  201. case N_HEADER_DN :
  202. return m_pQueryData->GetDNString();
  203. default :
  204. return NULL;
  205. }
  206. }
  207. BOOL CADSIEditQueryNode::HasPropertyPages(DATA_OBJECT_TYPES type,
  208. BOOL* pbHideVerb,
  209. CNodeList* pNodeList)
  210. {
  211. *pbHideVerb = TRUE; // always hide the verb
  212. return FALSE;
  213. }
  214. BOOL CADSIEditQueryNode::OnAddMenuItem(LPCONTEXTMENUITEM2 pContextMenuItem,
  215. long *pInsertionAllowed)
  216. {
  217. if (pContextMenuItem->lCommandID == IDM_SETTINGS_QUERY)
  218. {
  219. return TRUE;
  220. }
  221. else if (pContextMenuItem->lCommandID == IDM_REMOVE_QUERY)
  222. {
  223. return TRUE;
  224. }
  225. return FALSE;
  226. }
  227. CQueryObj* CADSIEditQueryNode::OnCreateQuery()
  228. {
  229. CConnectionData* pConnectData = GetADsObject()->GetConnectionNode()->GetConnectionData();
  230. CADSIEditRootData* pRootData = static_cast<CADSIEditRootData*>(GetRootContainer());
  231. CComponentDataObject* pComponentData = pRootData->GetComponentDataObject();
  232. RemoveAllChildrenHelper(pComponentData);
  233. CString sPath;
  234. GetADsObject()->GetPath(sPath);
  235. CString sFilter;
  236. GetQueryData()->GetFilter(sFilter);
  237. ADS_SCOPEENUM scope;
  238. scope = GetQueryData()->GetScope();
  239. CADSIEditQueryObject* pQuery = new CADSIEditQueryObject(sPath, sFilter, scope,
  240. pConnectData->GetMaxObjectCount(),
  241. pConnectData->GetCredentialObject(),
  242. pConnectData->IsGC(),
  243. pConnectData->GetConnectionNode());
  244. return pQuery;
  245. }
  246. BOOL CADSIEditQueryNode::OnSetRefreshVerbState(DATA_OBJECT_TYPES type,
  247. BOOL* pbHide,
  248. CNodeList* pNodeList)
  249. {
  250. *pbHide = FALSE;
  251. if (m_nState == loading)
  252. {
  253. return FALSE;
  254. }
  255. return !IsThreadLocked();
  256. }
  257. void CADSIEditQueryNode::OnChangeState(CComponentDataObject* pComponentDataObject)
  258. {
  259. switch (m_nState)
  260. {
  261. case notLoaded:
  262. case loaded:
  263. case unableToLoad:
  264. case accessDenied:
  265. {
  266. m_nState = loading;
  267. m_dwErr = 0;
  268. }
  269. break;
  270. case loading:
  271. {
  272. if (m_dwErr == 0)
  273. m_nState = loaded;
  274. else if (m_dwErr == ERROR_ACCESS_DENIED)
  275. m_nState = accessDenied;
  276. else
  277. m_nState = unableToLoad;
  278. }
  279. break;
  280. default:
  281. ASSERT(FALSE);
  282. }
  283. VERIFY(SUCCEEDED(pComponentDataObject->ChangeNode(this, CHANGE_RESULT_ITEM_ICON)));
  284. VERIFY(SUCCEEDED(pComponentDataObject->UpdateVerbState(this)));
  285. }
  286. int CADSIEditQueryNode::GetImageIndex(BOOL bOpenImage)
  287. {
  288. int nIndex = 0;
  289. switch (m_nState)
  290. {
  291. case notLoaded:
  292. nIndex = ZONE_IMAGE_1;
  293. break;
  294. case loading:
  295. nIndex = ZONE_IMAGE_LOADING_1;
  296. break;
  297. case loaded:
  298. nIndex = ZONE_IMAGE_1;
  299. break;
  300. case unableToLoad:
  301. nIndex = ZONE_IMAGE_UNABLE_TO_LOAD_1;
  302. break;
  303. case accessDenied:
  304. nIndex = ZONE_IMAGE_ACCESS_DENIED_1;
  305. break;
  306. default:
  307. ASSERT(FALSE);
  308. }
  309. return nIndex;
  310. }
  311. BOOL CADSIEditQueryNode::CanCloseSheets()
  312. {
  313. //
  314. // We can't do this with the new property page since it is not derived
  315. // from the base class in MTFRMWK.
  316. //
  317. //return (IDCANCEL != ADSIEditMessageBox(IDS_MSG_RECORD_CLOSE_SHEET, MB_OKCANCEL));
  318. ADSIEditMessageBox(IDS_MSG_RECORD_SHEET_LOCKED, MB_OK);
  319. return FALSE;
  320. }
  321. void CADSIEditQueryNode::OnHaveData(CObjBase* pObj, CComponentDataObject* pComponentDataObject)
  322. {
  323. CTreeNode* p = dynamic_cast<CTreeNode*>(pObj);
  324. ASSERT(p != NULL);
  325. if (p != NULL)
  326. {
  327. AddChildToListAndUI(p, pComponentDataObject);
  328. pComponentDataObject->SetDescriptionBarText(this);
  329. }
  330. }
  331. void CADSIEditQueryNode::OnError(DWORD dwerr)
  332. {
  333. if (dwerr == ERROR_TOO_MANY_NODES)
  334. {
  335. // need to pop message
  336. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  337. CThemeContextActivator activator;
  338. CString szFmt;
  339. szFmt.LoadString(IDS_MSG_QUERY_TOO_MANY_ITEMS);
  340. CString szMsg;
  341. szMsg.Format(szFmt, GetDisplayName());
  342. AfxMessageBox(szMsg);
  343. }
  344. else
  345. {
  346. ADSIEditErrorMessage(dwerr);
  347. }
  348. }