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.

355 lines
8.9 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. m_bTheme = TRUE;
  149. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  150. Assert(pTFSCompData != NULL);
  151. m_spTFSCompData.Set(pTFSCompData);
  152. }
  153. CSnapinProperties::~CSnapinProperties()
  154. {
  155. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  156. }
  157. BOOL
  158. CSnapinPropGeneral::OnPropertyChange(BOOL bScope, LONG_PTR * ChangeMask)
  159. {
  160. SPITFSNode spRootNode;
  161. CWinsRootHandler * pRoot;
  162. spRootNode = ((CSnapinProperties*)(GetHolder()))->GetNode();
  163. pRoot = GETHANDLER(CWinsRootHandler, spRootNode);
  164. // enumerate thro' all the nodes
  165. HRESULT hr = hrOK;
  166. SPITFSNodeEnum spNodeEnum;
  167. SPITFSNodeEnum spNodeEnumAdd;
  168. SPITFSNode spCurrentNode;
  169. ULONG nNumReturned = 0;
  170. BEGIN_WAIT_CURSOR;
  171. if (m_bDisplayFQDNChanged)
  172. {
  173. CHAR szStringName[MAX_PATH] = {0};
  174. // get the enumerator for this node
  175. spRootNode->GetEnum(&spNodeEnum);
  176. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  177. while (nNumReturned)
  178. {
  179. // if the status node is encountered, just ignore
  180. const GUID *pGuid;
  181. pGuid = spCurrentNode->GetNodeType();
  182. if(*pGuid == GUID_WinsServerStatusNodeType)
  183. {
  184. spCurrentNode.Release();
  185. // get the next Server in the list
  186. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  187. continue;
  188. }
  189. // walk the list of servers
  190. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spCurrentNode);
  191. pServer->SetDisplay(spCurrentNode, m_fLongName);
  192. spCurrentNode.Release();
  193. // get the next Server in the list
  194. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  195. }// while
  196. }
  197. END_WAIT_CURSOR;
  198. BOOL fValidate = pRoot->m_fValidate;
  199. // turn off validation if it is on.
  200. pRoot->m_fValidate = FALSE;
  201. if (spNodeEnum)
  202. spNodeEnum.Set(NULL);
  203. if (m_bDisplayServerOrderChanged)
  204. {
  205. const GUID *pGuid;
  206. CTFSNodeList tfsNodeList;
  207. // get the enumerator for this node
  208. spRootNode->GetEnum(&spNodeEnum);
  209. // first remove all of the server nodes from the UI
  210. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  211. while (nNumReturned)
  212. {
  213. pGuid = spCurrentNode->GetNodeType();
  214. if (*pGuid == GUID_WinsServerStatusNodeType)
  215. {
  216. spCurrentNode.Release();
  217. // get the next Server in the list
  218. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  219. continue;
  220. }
  221. // remove from the UI
  222. spRootNode->ExtractChild(spCurrentNode);
  223. // add ref the pointer since we need to put it on the list
  224. // and adding it to the list doesn't addref
  225. spCurrentNode->AddRef();
  226. tfsNodeList.AddTail(spCurrentNode);
  227. // reset our smart pointer
  228. spCurrentNode.Set(NULL);
  229. // get the next Server in the list
  230. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  231. }
  232. // Next put them back in sorted
  233. while (tfsNodeList.GetCount() > 0)
  234. {
  235. // get the next Server in the list
  236. spCurrentNode = tfsNodeList.RemoveHead();
  237. // if the status node is encountered, just ignore
  238. pGuid = spCurrentNode->GetNodeType();
  239. if (*pGuid == GUID_WinsServerStatusNodeType)
  240. {
  241. spCurrentNode.Release();
  242. continue;
  243. }
  244. // walk the list of servers
  245. CWinsServerHandler *pServer = GETHANDLER(CWinsServerHandler, spCurrentNode);
  246. pRoot->AddServer(pServer->m_strServerAddress,
  247. FALSE,
  248. pServer->m_dwIPAdd,
  249. pServer->GetConnected(),
  250. pServer->m_dwFlags,
  251. pServer->m_dwRefreshInterval);
  252. // releasing here destroys the object
  253. spCurrentNode.Release();
  254. }
  255. }
  256. // restore the flag
  257. pRoot->m_fValidate = fValidate;
  258. return FALSE;
  259. }
  260. void CSnapinPropGeneral::OnChange()
  261. {
  262. SetDirty(TRUE);
  263. }