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.

442 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: snapdata.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pch.h"
  11. #include <SnapBase.h>
  12. #include "resource.h"
  13. #include "adsiedit.h"
  14. #include "editor.h"
  15. #include "connection.h"
  16. #include "connectionui.h"
  17. #include "snapdata.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. BEGIN_MENU(CADSIEditRootMenuHolder)
  26. BEGIN_CTX
  27. CTX_ENTRY_TOP(IDM_CONNECT_TO, L"_ADSIEDIT_CONNECTTO")
  28. END_CTX
  29. BEGIN_RES
  30. RES_ENTRY(IDS_CONNECT_TO)
  31. END_RES
  32. END_MENU
  33. BEGIN_MENU(CADSIEditConnectMenuHolder)
  34. BEGIN_CTX
  35. CTX_ENTRY_VIEW(IDM_FILTER, L"_ADSIEDIT_FILTER")
  36. CTX_ENTRY_TOP(IDM_SETTINGS_CONNECTION, L"_ADSIEDIT_SETTINGS")
  37. CTX_ENTRY_TOP(IDM_REMOVE_CONNECTION, L"_ADSIEDIT_REMOVE")
  38. CTX_ENTRY_TOP(IDM_UPDATE_SCHEMA, L"_ADSIEDIT_UPDATE")
  39. CTX_ENTRY_NEW(IDM_NEW_QUERY, L"_ADSIEDIT_NEWQUERY")
  40. END_CTX
  41. BEGIN_RES
  42. RES_ENTRY(IDS_FILTER)
  43. RES_ENTRY(IDS_SETTINGS_CONNECTION)
  44. RES_ENTRY(IDS_REMOVE_CONNECTION)
  45. RES_ENTRY(IDS_UPDATE_SCHEMA)
  46. RES_ENTRY(IDS_NEW_QUERY)
  47. END_RES
  48. END_MENU
  49. BEGIN_MENU(CADSIEditContainerMenuHolder)
  50. BEGIN_CTX
  51. CTX_ENTRY_NEW(IDM_NEW_OBJECT, L"_ADSIEDIT_NEWOBJECT")
  52. CTX_ENTRY_TOP(IDM_MOVE, L"_ADSIEDIT_MOVE")
  53. CTX_ENTRY_TOP(IDM_NEW_CONNECT_FROM_HERE, L"_ADSIEDIT_CONNECTFROMHERE")
  54. END_CTX
  55. BEGIN_RES
  56. RES_ENTRY(IDS_NEW_OBJECT)
  57. RES_ENTRY(IDS_MOVE)
  58. RES_ENTRY(IDS_NEW_CONNECT_FROM_HERE)
  59. END_RES
  60. END_MENU
  61. BEGIN_MENU(CADSIEditLeafMenuHolder)
  62. BEGIN_CTX
  63. CTX_ENTRY_TOP(IDM_MOVE, L"_ADSIEDIT_MOVE")
  64. CTX_ENTRY_TOP(IDM_NEW_NC_CONNECT_FROM_HERE, L"_ADSIEDIT_CONNECTTONCFROMHERE")
  65. END_CTX
  66. BEGIN_RES
  67. RES_ENTRY(IDS_MOVE)
  68. RES_ENTRY(IDS_NEW_CONNECT_TO_NC_FROM_HERE)
  69. END_RES
  70. END_MENU
  71. BEGIN_MENU(CADSIEditQueryMenuHolder)
  72. BEGIN_CTX
  73. CTX_ENTRY_TOP(IDM_SETTINGS_QUERY, L"_ADSIEDIT_QUERYSETTINGS")
  74. CTX_ENTRY_TOP(IDM_REMOVE_QUERY, L"_ADSIEDIT_REMOVE")
  75. END_CTX
  76. BEGIN_RES
  77. RES_ENTRY(IDS_SETTINGS_QUERY)
  78. RES_ENTRY(IDS_REMOVE_QUERY)
  79. END_RES
  80. END_MENU
  81. //////////////////////////////////////////////////////////////////////
  82. // CADSIEditRootData
  83. // {D4F3374F-052F-11d2-97B0-00A0C9A06D2D}
  84. const GUID CADSIEditRootData::NodeTypeGUID =
  85. { 0xd4f3374f, 0x52f, 0x11d2, { 0x97, 0xb0, 0x0, 0xa0, 0xc9, 0xa0, 0x6d, 0x2d } };
  86. CADSIEditRootData::CADSIEditRootData(CComponentDataObject* pComponentData)
  87. : CRootData(pComponentData)
  88. {
  89. m_szDescriptionText = L"";
  90. }
  91. CADSIEditRootData::~CADSIEditRootData()
  92. {
  93. TRACE(_T("~CADSIEditRootData(), name <%s>\n"),GetDisplayName());
  94. }
  95. HRESULT CADSIEditRootData::LoadMRUs(IStream* pStm)
  96. {
  97. HRESULT hr = LoadStringListFromStream(pStm, m_sDNMRU);
  98. if (FAILED(hr))
  99. {
  100. return hr;
  101. }
  102. hr = LoadStringListFromStream(pStm, m_sServerMRU);
  103. return hr;
  104. }
  105. HRESULT CADSIEditRootData::SaveMRUs(IStream* pStm)
  106. {
  107. HRESULT hr = SaveStringListToStream(pStm, m_sDNMRU);
  108. if (FAILED(hr))
  109. {
  110. return hr;
  111. }
  112. hr = SaveStringListToStream(pStm, m_sServerMRU);
  113. return hr;
  114. }
  115. BOOL CADSIEditRootData::FindNode(LPCWSTR lpszPath, CList<CTreeNode*, CTreeNode*>& nodeList)
  116. {
  117. BOOL bFound = FALSE;
  118. POSITION pos;
  119. for (pos = m_containerChildList.GetHeadPosition(); pos != NULL; )
  120. {
  121. CTreeNode* pNode = m_containerChildList.GetNext(pos);
  122. CADSIEditConnectionNode* pConnectNode = dynamic_cast<CADSIEditConnectionNode*>(pNode);
  123. ASSERT(pConnectNode != NULL);
  124. CTreeNode* pFoundNode;
  125. BOOL bTemp;
  126. bTemp = pConnectNode->FindNode(lpszPath, nodeList);
  127. if (!bFound)
  128. {
  129. bFound = bTemp;
  130. }
  131. }
  132. return bFound;
  133. }
  134. BOOL CADSIEditRootData::OnAddMenuItem(LPCONTEXTMENUITEM2 pContextMenuItem,
  135. long *pInsertionAllowed)
  136. {
  137. //
  138. // Single selection
  139. //
  140. if (pContextMenuItem->lCommandID == IDM_CONNECT_TO)
  141. {
  142. return TRUE;
  143. }
  144. return FALSE;
  145. }
  146. BOOL CADSIEditRootData::OnSetRefreshVerbState(DATA_OBJECT_TYPES type,
  147. BOOL* pbHide,
  148. CNodeList* pNodeList)
  149. {
  150. *pbHide = FALSE;
  151. return !IsThreadLocked();
  152. }
  153. HRESULT CADSIEditRootData::OnCommand(long nCommandID,
  154. DATA_OBJECT_TYPES type,
  155. CComponentDataObject* pComponentData,
  156. CNodeList* pNodeList)
  157. {
  158. if (pNodeList->GetCount() == 1) // single selection
  159. {
  160. switch (nCommandID)
  161. {
  162. case IDM_CONNECT_TO :
  163. OnConnectTo(pComponentData);
  164. break;
  165. default:
  166. ASSERT(FALSE); // Unknown command!
  167. return E_FAIL;
  168. }
  169. }
  170. else if (pNodeList->GetCount() > 1) // multiple selection
  171. {
  172. switch (nCommandID)
  173. {
  174. case IDM_REMOVE_CONNECTION :
  175. {
  176. POSITION pos = pNodeList->GetHeadPosition();
  177. while (pos != NULL)
  178. {
  179. CTreeNode* pNode = pNodeList->GetNext(pos);
  180. ASSERT(pNode != NULL);
  181. CADSIEditConnectionNode* pConnectionNode = dynamic_cast<CADSIEditConnectionNode*>(pNode);
  182. ASSERT(pConnectionNode != NULL);
  183. pConnectionNode->OnRemove(pComponentData);
  184. }
  185. break;
  186. }
  187. default :
  188. ASSERT(FALSE);
  189. return E_FAIL;
  190. }
  191. }
  192. return S_OK;
  193. }
  194. void CADSIEditRootData::OnConnectTo(CComponentDataObject* pComponentData)
  195. {
  196. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  197. CString s, sPath;
  198. BSTR bstrPath;
  199. CConnectionData* pConnectData = NULL;
  200. CADSIEditConnectDialog pConnectDialog(NULL,
  201. this,
  202. pComponentData,
  203. pConnectData);
  204. pConnectDialog.DoModal();
  205. //Change the result pane if this is the first child being added
  206. pComponentData->UpdateResultPaneView(this);
  207. }
  208. HRESULT CADSIEditRootData::GetResultViewType(LPOLESTR* ppViewType, long* pViewOptions)
  209. {
  210. HRESULT hr = S_FALSE;
  211. if (m_containerChildList.IsEmpty() && m_leafChildList.IsEmpty())
  212. {
  213. *pViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  214. LPOLESTR psz = NULL;
  215. StringFromCLSID(CLSID_MessageView, &psz);
  216. USES_CONVERSION;
  217. if (psz != NULL)
  218. {
  219. *ppViewType = psz;
  220. hr = S_OK;
  221. }
  222. }
  223. else
  224. {
  225. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  226. *ppViewType = NULL;
  227. hr = S_FALSE;
  228. }
  229. return hr;
  230. }
  231. HRESULT CADSIEditRootData::OnShow(LPCONSOLE lpConsole)
  232. {
  233. CComPtr<IUnknown> spUnknown;
  234. CComPtr<IMessageView> spMessageView;
  235. HRESULT hr = lpConsole->QueryResultView(&spUnknown);
  236. if (FAILED(hr))
  237. return S_OK;
  238. hr = spUnknown->QueryInterface(IID_IMessageView, (PVOID*)&spMessageView);
  239. if (SUCCEEDED(hr))
  240. {
  241. CString szTitle, szMessage;
  242. IconIdentifier iconID;
  243. VERIFY(szTitle.LoadString(IDS_MESSAGE_VIEW_NO_CONNECTIONS_TITLE));
  244. VERIFY(szMessage.LoadString(IDS_MESSAGE_VIEW_NO_CONNECTIONS_MESSAGE));
  245. iconID = Icon_Information;
  246. spMessageView->SetTitleText(szTitle);
  247. spMessageView->SetBodyText(szMessage);
  248. spMessageView->SetIcon(iconID);
  249. }
  250. return S_OK;
  251. }
  252. #define ADSIEDIT_STREAM_VERSION (12)
  253. // IStream manipulation helpers overrides
  254. HRESULT CADSIEditRootData::Load(IStream* pStm)
  255. {
  256. //
  257. // assume never get multiple loads
  258. //
  259. if(!m_containerChildList.IsEmpty() || !m_leafChildList.IsEmpty())
  260. return E_FAIL;
  261. WCHAR szBuffer[256]; // REVIEW_MARCOC: hardcoded
  262. ULONG nLen; // WCHAR counting NULL
  263. UINT nCount;
  264. ULONG cbRead;
  265. // read the version ##
  266. DWORD dwVersion;
  267. VERIFY(SUCCEEDED(pStm->Read((void*)&dwVersion,sizeof(DWORD), &cbRead)));
  268. ASSERT(cbRead == sizeof(DWORD));
  269. if (dwVersion != ADSIEDIT_STREAM_VERSION)
  270. return E_FAIL;
  271. HRESULT hr = LoadMRUs(pStm);
  272. if (FAILED(hr))
  273. {
  274. return hr;
  275. }
  276. // load the list of connections
  277. VERIFY(SUCCEEDED(pStm->Read((void*)&nCount,sizeof(UINT), &cbRead)));
  278. ASSERT(cbRead == sizeof(UINT));
  279. CComponentDataObject* pComponentData = GetComponentDataObject();
  280. for (int k=0; k< (int)nCount; k++)
  281. {
  282. CADSIEditConnectionNode* p = NULL;
  283. VERIFY(SUCCEEDED(CADSIEditConnectionNode::CreateFromStream(pStm, &p)));
  284. ASSERT(p != NULL);
  285. VERIFY(AddChildToList(p));
  286. }
  287. if (nCount > 0)
  288. MarkEnumerated();
  289. ASSERT(m_containerChildList.GetCount() == (int)nCount);
  290. return S_OK;
  291. }
  292. HRESULT CADSIEditRootData::Save(IStream* pStm, BOOL fClearDirty)
  293. {
  294. UINT nCount;
  295. ULONG cbWrite;
  296. // write the version ##
  297. DWORD dwVersion = ADSIEDIT_STREAM_VERSION;
  298. VERIFY(SUCCEEDED(pStm->Write((void*)&dwVersion, sizeof(DWORD),&cbWrite)));
  299. ASSERT(cbWrite == sizeof(DWORD));
  300. HRESULT hr = SaveMRUs(pStm);
  301. if (FAILED(hr))
  302. {
  303. return hr;
  304. }
  305. // write # of servers
  306. nCount = (UINT)m_containerChildList.GetCount();
  307. VERIFY(SUCCEEDED(pStm->Write((void*)&nCount, sizeof(UINT),&cbWrite)));
  308. ASSERT(cbWrite == sizeof(UINT));
  309. // loop through the list of connections and serialize them
  310. POSITION pos;
  311. for (pos = m_containerChildList.GetHeadPosition(); pos != NULL; )
  312. {
  313. CADSIEditConnectionNode* pConnectNode = dynamic_cast<CADSIEditConnectionNode*>(m_containerChildList.GetNext(pos));
  314. ASSERT(pConnectNode != NULL);
  315. VERIFY(SUCCEEDED(pConnectNode->SaveToStream(pStm)));
  316. }
  317. if (fClearDirty)
  318. SetDirtyFlag(FALSE);
  319. return S_OK;
  320. }
  321. HRESULT CADSIEditRootData::IsDirty()
  322. {
  323. return CRootData::IsDirty();
  324. }
  325. BOOL CADSIEditRootData::CanCloseSheets()
  326. {
  327. //
  328. // We can't do this with the new property page since it is not derived
  329. // from the base class in MTFRMWK.
  330. //
  331. //return (IDCANCEL != ADSIEditMessageBox(IDS_MSG_RECORD_CLOSE_SHEET, MB_OKCANCEL));
  332. ADSIEditMessageBox(IDS_MSG_RECORD_SHEET_LOCKED, MB_OK);
  333. return FALSE;
  334. }
  335. BOOL CADSIEditRootData::OnRefresh(CComponentDataObject* pComponentData,
  336. CNodeList* pNodeList)
  337. {
  338. BOOL bRet = TRUE;
  339. if (pNodeList->GetCount() > 1) //multiple selection
  340. {
  341. POSITION pos = pNodeList->GetHeadPosition();
  342. while (pos != NULL)
  343. {
  344. CTreeNode* pNode = pNodeList->GetNext(pos);
  345. ASSERT(pNode != NULL);
  346. CNodeList nodeList;
  347. nodeList.AddTail(pNode);
  348. if (!pNode->OnRefresh(pComponentData, &nodeList))
  349. {
  350. bRet = FALSE;
  351. }
  352. }
  353. }
  354. else if (pNodeList->GetCount() == 1) // single selection
  355. {
  356. if (IsSheetLocked())
  357. {
  358. if (!CanCloseSheets())
  359. return FALSE;
  360. pComponentData->GetPropertyPageHolderTable()->DeleteSheetsOfNode(this);
  361. }
  362. ASSERT(!IsSheetLocked());
  363. POSITION pos;
  364. for (pos = m_containerChildList.GetHeadPosition(); pos != NULL; )
  365. {
  366. CTreeNode* pNode = m_containerChildList.GetNext(pos);
  367. CADSIEditConnectionNode* pConnectNode = dynamic_cast<CADSIEditConnectionNode*>(pNode);
  368. ASSERT(pConnectNode != NULL);
  369. CNodeList nodeList;
  370. nodeList.AddTail(pNode);
  371. pConnectNode->OnRefresh(pComponentData, &nodeList);
  372. }
  373. bRet = TRUE;
  374. }
  375. return bRet;
  376. }