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.

354 lines
8.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. snappp.h
  7. Brings up the Snapin property page
  8. FILE HISTORY:
  9. */
  10. // Snappp.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "Snappp.h"
  14. #include "root.h"
  15. #include "server.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. #define MILLISEC_PER_MINUTE 60 * 1000
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CSnapinPropGeneral property page
  24. IMPLEMENT_DYNCREATE(CSnapinPropGeneral, CPropertyPageBase)
  25. CSnapinPropGeneral::CSnapinPropGeneral() : CPropertyPageBase(CSnapinPropGeneral::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CSnapinPropGeneral)
  28. m_fLongName = FALSE;
  29. m_nOrderByName = 0;
  30. m_fValidateServers = FALSE;
  31. //}}AFX_DATA_INIT
  32. }
  33. CSnapinPropGeneral::~CSnapinPropGeneral()
  34. {
  35. }
  36. void CSnapinPropGeneral::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CPropertyPageBase::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CSnapinPropGeneral)
  40. DDX_Control(pDX, IDC_CHECK2, m_checkValidateServers);
  41. DDX_Check(pDX, IDC_CHECK1, m_fLongName);
  42. DDX_Radio(pDX, IDC_RADIO1, m_nOrderByName);
  43. DDX_Control(pDX, IDC_CHECK1, m_checkLongName);
  44. DDX_Control(pDX, IDC_RADIO1, m_buttonSortByName);
  45. DDX_Control(pDX, IDC_RADIO2, m_buttonSortByIP);
  46. DDX_Check(pDX, IDC_CHECK2, m_fValidateServers);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CSnapinPropGeneral, CPropertyPageBase)
  50. //{{AFX_MSG_MAP(CSnapinPropGeneral)
  51. ON_BN_CLICKED(IDC_CHECK2, OnChange)
  52. ON_BN_CLICKED(IDC_CHECK1, OnChange)
  53. ON_BN_CLICKED(IDC_RADIO1, OnChange)
  54. ON_BN_CLICKED(IDC_RADIO2, OnChange)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CSnapinPropGeneral message handlers
  59. BOOL CSnapinPropGeneral::OnApply()
  60. {
  61. if(!IsDirty())
  62. return TRUE;
  63. UpdateData();
  64. GetHolder()->EnablePeekMessageDuringNotifyConsole(TRUE);
  65. // get the root node
  66. SPITFSNode spRootNode;
  67. CWinsRootHandler * pRoot;
  68. spRootNode = ((CSnapinProperties*)(GetHolder()))->GetNode();
  69. pRoot = GETHANDLER(CWinsRootHandler, spRootNode);
  70. // set the values in the root handler
  71. if (m_fValidateServers)
  72. pRoot->m_dwFlags |= FLAG_VALIDATE_CACHE;
  73. else
  74. pRoot->m_dwFlags &= ~FLAG_VALIDATE_CACHE;
  75. // need to do this bcoz' changing the server order and the display name takes a
  76. // long time
  77. BOOL fOrderByName = (m_nOrderByName == 0) ? TRUE : FALSE;
  78. m_bDisplayServerOrderChanged = (fOrderByName == pRoot->GetOrderByName()) ? FALSE : TRUE;
  79. m_bDisplayFQDNChanged = (m_fLongName == pRoot->GetShowLongName()) ? FALSE : TRUE;
  80. // don't do anything, if the properties remained the same
  81. if (!m_bDisplayFQDNChanged && !m_bDisplayServerOrderChanged)
  82. return TRUE;
  83. // set the servername of the rootnode to the one updated
  84. pRoot->SetShowLongName(m_fLongName);
  85. pRoot->SetOrderByName(fOrderByName);
  86. spRootNode->SetData(TFS_DATA_DIRTY, TRUE);
  87. return CPropertyPageBase::OnApply();
  88. }
  89. BOOL CSnapinPropGeneral::OnInitDialog()
  90. {
  91. CPropertyPageBase::OnInitDialog();
  92. // get the root node
  93. // now add the node to the tree
  94. SPITFSNode spRootNode;
  95. CWinsRootHandler * pRoot;
  96. spRootNode = ((CSnapinProperties*)(GetHolder()))->GetNode();
  97. pRoot = GETHANDLER(CWinsRootHandler, spRootNode);
  98. m_uImage = (UINT) spRootNode->GetData(TFS_DATA_IMAGEINDEX);
  99. m_fLongName = pRoot->GetShowLongName();
  100. BOOL fOrderByName = pRoot->GetOrderByName();
  101. m_nOrderByName = (fOrderByName) ? 0 : 1;
  102. if (m_fLongName)
  103. m_checkLongName.SetCheck(TRUE);
  104. else
  105. m_checkLongName.SetCheck(FALSE);
  106. if (m_nOrderByName == 0)
  107. {
  108. m_buttonSortByName.SetCheck(TRUE);
  109. m_buttonSortByIP.SetCheck(FALSE);
  110. }
  111. else
  112. {
  113. m_buttonSortByName.SetCheck(FALSE);
  114. m_buttonSortByIP.SetCheck(TRUE);
  115. }
  116. if (pRoot->m_dwFlags & FLAG_VALIDATE_CACHE)
  117. m_checkValidateServers.SetCheck(TRUE);
  118. else
  119. m_checkValidateServers.SetCheck(FALSE);
  120. // load the correct icon
  121. for (int i = 0; i < ICON_IDX_MAX; i++)
  122. {
  123. if (g_uIconMap[i][1] == m_uImage)
  124. {
  125. HICON hIcon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  126. if (hIcon)
  127. ((CStatic *) GetDlgItem(IDC_STATIC_ICON))->SetIcon(hIcon);
  128. break;
  129. }
  130. }
  131. SetDirty(FALSE);
  132. return TRUE;
  133. }
  134. /////////////////////////////////////////////////////////////////////////////
  135. //
  136. // CSnapinProperties holder
  137. //
  138. /////////////////////////////////////////////////////////////////////////////
  139. CSnapinProperties::CSnapinProperties
  140. (
  141. ITFSNode * pNode,
  142. IComponentData * pComponentData,
  143. ITFSComponentData * pTFSCompData,
  144. LPCTSTR pszSheetName
  145. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  146. {
  147. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  148. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  149. Assert(pTFSCompData != NULL);
  150. m_spTFSCompData.Set(pTFSCompData);
  151. }
  152. CSnapinProperties::~CSnapinProperties()
  153. {
  154. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  155. }
  156. BOOL
  157. CSnapinPropGeneral::OnPropertyChange(BOOL bScope, LONG_PTR * ChangeMask)
  158. {
  159. SPITFSNode spRootNode;
  160. CWinsRootHandler * pRoot;
  161. spRootNode = ((CSnapinProperties*)(GetHolder()))->GetNode();
  162. pRoot = GETHANDLER(CWinsRootHandler, spRootNode);
  163. // enumerate thro' all the nodes
  164. HRESULT hr = hrOK;
  165. SPITFSNodeEnum spNodeEnum;
  166. SPITFSNodeEnum spNodeEnumAdd;
  167. SPITFSNode spCurrentNode;
  168. ULONG nNumReturned = 0;
  169. BEGIN_WAIT_CURSOR;
  170. if (m_bDisplayFQDNChanged)
  171. {
  172. CHAR szStringName[MAX_PATH] = {0};
  173. // get the enumerator for this node
  174. spRootNode->GetEnum(&spNodeEnum);
  175. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  176. while (nNumReturned)
  177. {
  178. // if the status node is encountered, just ignore
  179. const GUID *pGuid;
  180. pGuid = spCurrentNode->GetNodeType();
  181. if(*pGuid == GUID_WinsServerStatusNodeType)
  182. {
  183. spCurrentNode.Release();
  184. // get the next Server in the list
  185. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  186. continue;
  187. }
  188. // walk the list of servers
  189. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spCurrentNode);
  190. pServer->SetDisplay(spCurrentNode, m_fLongName);
  191. spCurrentNode.Release();
  192. // get the next Server in the list
  193. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  194. }// while
  195. }
  196. END_WAIT_CURSOR;
  197. BOOL fValidate = pRoot->m_fValidate;
  198. // turn off validation if it is on.
  199. pRoot->m_fValidate = FALSE;
  200. if (spNodeEnum)
  201. spNodeEnum.Set(NULL);
  202. if (m_bDisplayServerOrderChanged)
  203. {
  204. const GUID *pGuid;
  205. CTFSNodeList tfsNodeList;
  206. // get the enumerator for this node
  207. spRootNode->GetEnum(&spNodeEnum);
  208. // first remove all of the server nodes from the UI
  209. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  210. while (nNumReturned)
  211. {
  212. pGuid = spCurrentNode->GetNodeType();
  213. if (*pGuid == GUID_WinsServerStatusNodeType)
  214. {
  215. spCurrentNode.Release();
  216. // get the next Server in the list
  217. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  218. continue;
  219. }
  220. // remove from the UI
  221. spRootNode->ExtractChild(spCurrentNode);
  222. // add ref the pointer since we need to put it on the list
  223. // and adding it to the list doesn't addref
  224. spCurrentNode->AddRef();
  225. tfsNodeList.AddTail(spCurrentNode);
  226. // reset our smart pointer
  227. spCurrentNode.Set(NULL);
  228. // get the next Server in the list
  229. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  230. }
  231. // Next put them back in sorted
  232. while (tfsNodeList.GetCount() > 0)
  233. {
  234. // get the next Server in the list
  235. spCurrentNode = tfsNodeList.RemoveHead();
  236. // if the status node is encountered, just ignore
  237. pGuid = spCurrentNode->GetNodeType();
  238. if (*pGuid == GUID_WinsServerStatusNodeType)
  239. {
  240. spCurrentNode.Release();
  241. continue;
  242. }
  243. // walk the list of servers
  244. CWinsServerHandler *pServer = GETHANDLER(CWinsServerHandler, spCurrentNode);
  245. pRoot->AddServer(pServer->m_strServerAddress,
  246. FALSE,
  247. pServer->m_dwIPAdd,
  248. pServer->GetConnected(),
  249. pServer->m_dwFlags,
  250. pServer->m_dwRefreshInterval);
  251. // releasing here destroys the object
  252. spCurrentNode.Release();
  253. }
  254. }
  255. // restore the flag
  256. pRoot->m_fValidate = fValidate;
  257. return FALSE;
  258. }
  259. void CSnapinPropGeneral::OnChange()
  260. {
  261. SetDirty(TRUE);
  262. }