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.

204 lines
5.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. edituser.h
  7. Edit user dialog implementation file
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "EditUser.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CEditUsers dialog
  19. CEditUsers::CEditUsers(CTapiDevice * pTapiDevice, CWnd* pParent /*=NULL*/)
  20. : CBaseDialog(CEditUsers::IDD, pParent),
  21. m_pTapiDevice(pTapiDevice),
  22. m_bDirty(FALSE)
  23. {
  24. //{{AFX_DATA_INIT(CEditUsers)
  25. // NOTE: the ClassWizard will add member initialization here
  26. //}}AFX_DATA_INIT
  27. }
  28. void CEditUsers::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CBaseDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CEditUsers)
  32. DDX_Control(pDX, IDC_LIST_USERS, m_listUsers);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CEditUsers, CBaseDialog)
  36. //{{AFX_MSG_MAP(CEditUsers)
  37. ON_BN_CLICKED(IDC_BUTTON_ADD_USER, OnButtonAdd)
  38. ON_BN_CLICKED(IDC_BUTTON_REMOVE_USER, OnButtonRemove)
  39. ON_LBN_SELCHANGE(IDC_LIST_USERS, OnSelchangeListUsers)
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CEditUsers message handlers
  44. BOOL CEditUsers::OnInitDialog()
  45. {
  46. CBaseDialog::OnInitDialog();
  47. for (int i = 0; i < m_pTapiDevice->m_arrayUsers.GetSize(); i++)
  48. {
  49. CString strDisplay;
  50. FormatName(m_pTapiDevice->m_arrayUsers[i].m_strFullName,
  51. m_pTapiDevice->m_arrayUsers[i].m_strName,
  52. strDisplay);
  53. int nIndex = m_listUsers.AddString(strDisplay);
  54. m_listUsers.SetItemData(nIndex, i);
  55. }
  56. UpdateButtons();
  57. return TRUE; // return TRUE unless you set the focus to a control
  58. // EXCEPTION: OCX Property Pages should return FALSE
  59. }
  60. //
  61. // Refresh the list box and rebuild the index
  62. //
  63. void CEditUsers::RefreshList()
  64. {
  65. m_listUsers.ResetContent();
  66. for (int i = 0; i < m_pTapiDevice->m_arrayUsers.GetSize(); i++)
  67. {
  68. CString strDisplay;
  69. FormatName(m_pTapiDevice->m_arrayUsers[i].m_strFullName,
  70. m_pTapiDevice->m_arrayUsers[i].m_strName,
  71. strDisplay);
  72. int nIndex = m_listUsers.AddString(strDisplay);
  73. m_listUsers.SetItemData(nIndex, i);
  74. }
  75. }
  76. void CEditUsers::OnButtonAdd()
  77. {
  78. CGetUsers getUsers(TRUE);
  79. if (!getUsers.GetUsers(GetSafeHwnd()))
  80. return;
  81. for (int nCount = 0; nCount < getUsers.GetSize(); nCount++)
  82. {
  83. CUserInfo userTemp;
  84. userTemp = getUsers[nCount];
  85. // check for duplicates
  86. BOOL fDuplicate = FALSE;
  87. for (int i = 0; i < m_pTapiDevice->m_arrayUsers.GetSize(); i++)
  88. {
  89. if (m_pTapiDevice->m_arrayUsers[i].m_strName.CompareNoCase(userTemp.m_strName) == 0)
  90. {
  91. fDuplicate = TRUE;
  92. break;
  93. }
  94. }
  95. if (!fDuplicate)
  96. {
  97. // add to the array
  98. int nIndex = (int)m_pTapiDevice->m_arrayUsers.Add(userTemp);
  99. // now add to the listbox
  100. CString strDisplay;
  101. FormatName(m_pTapiDevice->m_arrayUsers[nIndex].m_strFullName,
  102. m_pTapiDevice->m_arrayUsers[nIndex].m_strName,
  103. strDisplay);
  104. int nListboxIndex = m_listUsers.AddString(strDisplay);
  105. m_listUsers.SetItemData(nListboxIndex, nIndex);
  106. }
  107. else
  108. {
  109. // tell the user we're not adding this to the list
  110. CString strMessage;
  111. AfxFormatString1(strMessage, IDS_USER_ALREADY_AUTHORIZED, userTemp.m_strName);
  112. AfxMessageBox(strMessage);
  113. }
  114. SetDirty(TRUE);
  115. }
  116. UpdateButtons();
  117. }
  118. void CEditUsers::OnButtonRemove()
  119. {
  120. CString strSelectedName, strFullName, strDomainName;
  121. int nCurSel = m_listUsers.GetCurSel();
  122. int nIndex = (int)m_listUsers.GetItemData(nCurSel);
  123. // remove from the list
  124. m_pTapiDevice->m_arrayUsers.RemoveAt(nIndex);
  125. //Fix bug 386474, we need to rebuild the index <-> string mapping in the list box.
  126. //So reload the users to the list box
  127. RefreshList();
  128. SetDirty(TRUE);
  129. UpdateButtons();
  130. }
  131. void CEditUsers::OnOK()
  132. {
  133. if (IsDirty())
  134. {
  135. }
  136. CBaseDialog::OnOK();
  137. }
  138. void CEditUsers::UpdateButtons()
  139. {
  140. // enable the remove button if something is selected
  141. BOOL fEnable = (m_listUsers.GetCurSel() != LB_ERR);
  142. CWnd * pwndRemove = GetDlgItem(IDC_BUTTON_REMOVE_USER);
  143. //if we will disable the remove button and the remove button has the focus,
  144. //we should change focus to the OK button
  145. if (!fEnable && GetFocus() == pwndRemove)
  146. {
  147. SetDefID(IDOK);
  148. GetDlgItem(IDOK)->SetFocus();
  149. ((CButton*)pwndRemove)->SetButtonStyle(BS_PUSHBUTTON);
  150. }
  151. pwndRemove->EnableWindow(fEnable);
  152. }
  153. void CEditUsers::OnSelchangeListUsers()
  154. {
  155. UpdateButtons();
  156. }