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.

378 lines
9.0 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((LPWSTR)(LPCWSTR)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_OKCANCEL) == IDOK)
  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::OnSettings(CComponentDataObject* pComponentData)
  141. {
  142. // Get the data from the existing query node data
  143. BOOL bOneLevel;
  144. bOneLevel = (GetQueryData()->GetScope() == ADS_SCOPE_ONELEVEL);
  145. CString sFilter, sName, sPath, sConnectPath;
  146. GetQueryData()->GetName(sName);
  147. GetQueryData()->GetFilter(sFilter);
  148. GetQueryData()->GetRootPath(sPath);
  149. GetADsObject()->GetConnectionNode()->GetADsObject()->GetPath(sConnectPath);
  150. CCredentialObject* pCredObject =
  151. GetADsObject()->GetConnectionNode()->GetConnectionData()->GetCredentialObject();
  152. // Initialize dialog with data
  153. CADSIEditQueryDialog queryDialog(sName, sFilter, sPath, sConnectPath, bOneLevel, pCredObject);
  154. if (queryDialog.DoModal() == IDOK)
  155. {
  156. // If OK
  157. CString sNewPath;
  158. queryDialog.GetResults(sName, sFilter, sNewPath, &bOneLevel);
  159. GetQueryData()->SetName(sName);
  160. GetQueryData()->SetFilter(sFilter);
  161. GetQueryData()->SetRootPath(sNewPath);
  162. GetADsObject()->SetPath(sNewPath);
  163. ADS_SCOPEENUM scope = (bOneLevel) ? ADS_SCOPE_ONELEVEL : ADS_SCOPE_SUBTREE;
  164. GetQueryData()->SetScope(scope);
  165. // Make changes take effect
  166. CString sDisplayName;
  167. GetQueryData()->GetDisplayName(sDisplayName);
  168. SetDisplayName(sDisplayName);
  169. CNodeList nodeList;
  170. nodeList.AddTail(this);
  171. OnRefresh(pComponentData, &nodeList);
  172. }
  173. }
  174. LPCWSTR CADSIEditQueryNode::GetString(int nCol)
  175. {
  176. switch(nCol)
  177. {
  178. case N_HEADER_NAME :
  179. return GetDisplayName();
  180. case N_HEADER_TYPE :
  181. return m_sType;
  182. case N_HEADER_DN :
  183. return m_pQueryData->GetDNString();
  184. default :
  185. return NULL;
  186. }
  187. }
  188. BOOL CADSIEditQueryNode::HasPropertyPages(DATA_OBJECT_TYPES type,
  189. BOOL* pbHideVerb,
  190. CNodeList* pNodeList)
  191. {
  192. *pbHideVerb = TRUE; // always hide the verb
  193. return FALSE;
  194. }
  195. BOOL CADSIEditQueryNode::OnAddMenuItem(LPCONTEXTMENUITEM2 pContextMenuItem,
  196. long *pInsertionAllowed)
  197. {
  198. if (pContextMenuItem->lCommandID == IDM_SETTINGS_QUERY)
  199. {
  200. return TRUE;
  201. }
  202. else if (pContextMenuItem->lCommandID == IDM_REMOVE_QUERY)
  203. {
  204. return TRUE;
  205. }
  206. return FALSE;
  207. }
  208. CQueryObj* CADSIEditQueryNode::OnCreateQuery()
  209. {
  210. CConnectionData* pConnectData = GetADsObject()->GetConnectionNode()->GetConnectionData();
  211. CADSIEditRootData* pRootData = static_cast<CADSIEditRootData*>(GetRootContainer());
  212. CComponentDataObject* pComponentData = pRootData->GetComponentDataObject();
  213. RemoveAllChildrenHelper(pComponentData);
  214. CString sPath;
  215. GetADsObject()->GetPath(sPath);
  216. CString sFilter;
  217. GetQueryData()->GetFilter(sFilter);
  218. ADS_SCOPEENUM scope;
  219. scope = GetQueryData()->GetScope();
  220. CADSIEditQueryObject* pQuery = new CADSIEditQueryObject(sPath, sFilter, scope,
  221. pConnectData->GetMaxObjectCount(),
  222. pConnectData->GetCredentialObject(),
  223. pConnectData->IsGC(),
  224. pConnectData->GetConnectionNode());
  225. return pQuery;
  226. }
  227. BOOL CADSIEditQueryNode::OnSetRefreshVerbState(DATA_OBJECT_TYPES type,
  228. BOOL* pbHide,
  229. CNodeList* pNodeList)
  230. {
  231. *pbHide = FALSE;
  232. if (m_nState == loading)
  233. {
  234. return FALSE;
  235. }
  236. return !IsThreadLocked();
  237. }
  238. void CADSIEditQueryNode::OnChangeState(CComponentDataObject* pComponentDataObject)
  239. {
  240. switch (m_nState)
  241. {
  242. case notLoaded:
  243. case loaded:
  244. case unableToLoad:
  245. case accessDenied:
  246. {
  247. m_nState = loading;
  248. m_dwErr = 0;
  249. }
  250. break;
  251. case loading:
  252. {
  253. if (m_dwErr == 0)
  254. m_nState = loaded;
  255. else if (m_dwErr == ERROR_ACCESS_DENIED)
  256. m_nState = accessDenied;
  257. else
  258. m_nState = unableToLoad;
  259. }
  260. break;
  261. default:
  262. ASSERT(FALSE);
  263. }
  264. VERIFY(SUCCEEDED(pComponentDataObject->ChangeNode(this, CHANGE_RESULT_ITEM_ICON)));
  265. VERIFY(SUCCEEDED(pComponentDataObject->UpdateVerbState(this)));
  266. }
  267. int CADSIEditQueryNode::GetImageIndex(BOOL bOpenImage)
  268. {
  269. int nIndex = 0;
  270. switch (m_nState)
  271. {
  272. case notLoaded:
  273. nIndex = ZONE_IMAGE_1;
  274. break;
  275. case loading:
  276. nIndex = ZONE_IMAGE_LOADING_1;
  277. break;
  278. case loaded:
  279. nIndex = ZONE_IMAGE_1;
  280. break;
  281. case unableToLoad:
  282. nIndex = ZONE_IMAGE_UNABLE_TO_LOAD_1;
  283. break;
  284. case accessDenied:
  285. nIndex = ZONE_IMAGE_ACCESS_DENIED_1;
  286. break;
  287. default:
  288. ASSERT(FALSE);
  289. }
  290. return nIndex;
  291. }
  292. BOOL CADSIEditQueryNode::CanCloseSheets()
  293. {
  294. //
  295. // We can't do this with the new property page since it is not derived
  296. // from the base class in MTFRMWK.
  297. //
  298. //return (IDCANCEL != ADSIEditMessageBox(IDS_MSG_RECORD_CLOSE_SHEET, MB_OKCANCEL));
  299. ADSIEditMessageBox(IDS_MSG_RECORD_SHEET_LOCKED, MB_OK);
  300. return FALSE;
  301. }
  302. void CADSIEditQueryNode::OnHaveData(CObjBase* pObj, CComponentDataObject* pComponentDataObject)
  303. {
  304. CTreeNode* p = dynamic_cast<CTreeNode*>(pObj);
  305. ASSERT(p != NULL);
  306. if (p != NULL)
  307. {
  308. AddChildToListAndUI(p, pComponentDataObject);
  309. pComponentDataObject->SetDescriptionBarText(this);
  310. }
  311. }
  312. void CADSIEditQueryNode::OnError(DWORD dwerr)
  313. {
  314. if (dwerr == ERROR_TOO_MANY_NODES)
  315. {
  316. // need to pop message
  317. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  318. CString szFmt;
  319. szFmt.LoadString(IDS_MSG_QUERY_TOO_MANY_ITEMS);
  320. CString szMsg;
  321. szMsg.Format(szFmt, GetDisplayName());
  322. AfxMessageBox(szMsg);
  323. }
  324. else
  325. {
  326. ADSIEditErrorMessage(dwerr);
  327. }
  328. }