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.

249 lines
8.3 KiB

  1. // DomainListDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "DomainListDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDomainListDlg dialog
  13. CDomainListDlg::CDomainListDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CDomainListDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CDomainListDlg)
  17. //}}AFX_DATA_INIT
  18. bExcludeOne = FALSE;
  19. }
  20. void CDomainListDlg::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. //{{AFX_DATA_MAP(CDomainListDlg)
  24. DDX_Control(pDX, IDC_DOMAINTREE, m_domainTree);
  25. DDX_Control(pDX, IDOK, m_NextBtn);
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(CDomainListDlg, CDialog)
  29. //{{AFX_MSG_MAP(CDomainListDlg)
  30. //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CDomainListDlg message handlers
  34. BOOL CDomainListDlg::OnInitDialog()
  35. {
  36. CDialog::OnInitDialog();
  37. //fill the tree control
  38. FillTreeControl();
  39. return TRUE; // return TRUE unless you set the focus to a control
  40. // EXCEPTION: OCX Property Pages should return FALSE
  41. }
  42. void CDomainListDlg::OnCancel()
  43. {
  44. // TODO: Add extra cleanup here
  45. CString msg, title;
  46. title.LoadString(IDS_EXIT_TITLE);
  47. msg.LoadString(IDS_EXIT_MSG);
  48. if (MessageBox(msg, title, MB_YESNO | MB_ICONQUESTION) == IDYES)
  49. CDialog::OnCancel();
  50. }
  51. void CDomainListDlg::OnOK()
  52. {
  53. CString msg, title;
  54. // TODO: Add extra validation here
  55. //remove deselected items from the domain list
  56. ModifyDomainList();
  57. //if at least one domain was deselected, post a warning message
  58. if (bExcludeOne)
  59. {
  60. title.LoadString(IDS_EXCLUDE_TITLE);
  61. msg.LoadString(IDS_EXCLUDE_MSG);
  62. if (MessageBox(msg, title, MB_YESNO | MB_ICONQUESTION) == IDYES)
  63. CDialog::OnOK();
  64. else
  65. AddExclutedBackToList();
  66. }
  67. else
  68. CDialog::OnOK();
  69. }
  70. /*********************************************************************
  71. * *
  72. * Written by: Paul Thompson *
  73. * Date: 17 AUG 2000 *
  74. * *
  75. * This protected member function of the CDomainListDlg class is *
  76. * responsible for displaying all domains in the Protar database's *
  77. * MigratedObjects table. *
  78. * *
  79. *********************************************************************/
  80. //BEGIN FillTreeControl
  81. void CDomainListDlg::FillTreeControl()
  82. {
  83. /* local variables */
  84. POSITION currentPos; //current position in the list
  85. CString domainName; //name of domain from the list
  86. WCHAR sName[MAX_PATH]; //name in string format to pass to tree control
  87. /* function body */
  88. CWaitCursor wait; //Put up a wait cursor
  89. //make sure the checkbox sytle is set for this tree control
  90. long lStyles = GetWindowLong(m_domainTree.m_hWnd, GWL_STYLE);
  91. //if checkbox style is not set, set it
  92. if (!(lStyles & TVS_CHECKBOXES))
  93. {
  94. lStyles = lStyles | TVS_CHECKBOXES;
  95. SetWindowLong(m_domainTree.m_hWnd, GWL_STYLE, lStyles);
  96. }
  97. //get the position and string of the first name in the list
  98. currentPos = pDomainList->GetHeadPosition();
  99. //while there is another entry to retrieve from the list, then
  100. //get a name from the list and add it to the tree control
  101. while (currentPos != NULL)
  102. {
  103. //get the next string in the list, starts with the first
  104. domainName = pDomainList->GetNext(currentPos);
  105. wcscpy(sName, (LPCTSTR)domainName);
  106. AddOneItem((HTREEITEM)TVI_ROOT, sName);
  107. }
  108. wait.~CWaitCursor(); //remove the wait cursor
  109. }
  110. //END FillTreeControl
  111. /*********************************************************************
  112. * *
  113. * Written by: Paul Thompson *
  114. * Date: 17 AUG 2000 *
  115. * *
  116. * This protected member function of the CDomainListDlg class is *
  117. * responsible for adding one item to the tree control in the *
  118. * specified place. *
  119. * *
  120. *********************************************************************/
  121. //BEGIN AddOneItem
  122. HTREEITEM CDomainListDlg::AddOneItem(HTREEITEM hParent, LPTSTR szText)
  123. {
  124. /* local variables */
  125. HTREEITEM hItem;
  126. TV_INSERTSTRUCT tvstruct;
  127. /* function body */
  128. // fill the tree control
  129. tvstruct.hParent = hParent;
  130. tvstruct.hInsertAfter = TVI_SORT;
  131. tvstruct.item.pszText = szText;
  132. tvstruct.item.cchTextMax = MAX_PATH;
  133. tvstruct.item.mask = TVIF_TEXT | TVIF_STATE;
  134. tvstruct.item.state = INDEXTOSTATEIMAGEMASK(2);
  135. tvstruct.item.stateMask = TVIS_STATEIMAGEMASK;
  136. hItem = m_domainTree.InsertItem(&tvstruct);
  137. //make sure item is checked
  138. m_domainTree.SetCheck(hItem, TRUE);
  139. return (hItem);
  140. }
  141. //END AddOneItem
  142. /*********************************************************************
  143. * *
  144. * Written by: Paul Thompson *
  145. * Date: 17 AUG 2000 *
  146. * *
  147. * This protected member function of the CDomainListDlg class is *
  148. * responsible for removing list entries if they where deselected in *
  149. * the tree control. *
  150. * *
  151. *********************************************************************/
  152. //BEGIN ModifyDomainList
  153. void CDomainListDlg::ModifyDomainList()
  154. {
  155. /* local variables */
  156. HTREEITEM hItem; //current tree control item
  157. POSITION currentPos; //current position in the list
  158. CString domainName; //name of domain from the list
  159. UINT ndx; //for loop counter
  160. /* function body */
  161. CWaitCursor wait; //Put up a wait cursor
  162. //get the number of entries in the tree control
  163. for (ndx=0; ndx < m_domainTree.GetCount(); ndx++)
  164. {
  165. if (ndx == 0)
  166. hItem = m_domainTree.GetNextItem(NULL, TVGN_CHILD);
  167. else
  168. hItem = m_domainTree.GetNextItem(hItem, TVGN_NEXT);
  169. domainName = m_domainTree.GetItemText(hItem);
  170. //if deselected, remove from the list and add to the excluded list
  171. if (m_domainTree.GetCheck(hItem) == 0)
  172. {
  173. //if we find the string in the list, remove it
  174. currentPos = pDomainList->Find(domainName);
  175. if (currentPos != NULL)
  176. {
  177. pDomainList->RemoveAt(currentPos);
  178. pExcludeList->AddTail(domainName);
  179. }
  180. bExcludeOne = TRUE; //set class flag to tell one is excluded
  181. }
  182. }
  183. wait.~CWaitCursor(); //remove the wait cursor
  184. }
  185. //END ModifyDomainList
  186. /*********************************************************************
  187. * *
  188. * Written by: Paul Thompson *
  189. * Date: 22 AUG 2000 *
  190. * *
  191. * This protected member function of the CDomainListDlg class is *
  192. * responsible for taking the domain names out of the excluded list *
  193. * and placing it back into the domain list. *
  194. * *
  195. *********************************************************************/
  196. //BEGIN AddExclutedBackToList
  197. void CDomainListDlg::AddExclutedBackToList()
  198. {
  199. /* local variables */
  200. POSITION currentPos; //current position in the list
  201. CString domainName; //name of domain from the list
  202. /* function body */
  203. currentPos = pExcludeList->GetHeadPosition();
  204. while (currentPos != NULL)
  205. {
  206. domainName = pExcludeList->GetNext(currentPos);
  207. pDomainList->AddTail(domainName);
  208. }
  209. pExcludeList->RemoveAll();
  210. }
  211. //END AddExclutedBackToList