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.

256 lines
7.2 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. Classes.h
  7. This file contains all of the prototypes for the
  8. option class dialog.
  9. FILE HISTORY:
  10. */
  11. #include "stdafx.h"
  12. #include "classes.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CDhcpClasses dialog
  20. CDhcpClasses::CDhcpClasses(CClassInfoArray * pClassArray, LPCTSTR pszServer, DWORD dwType, CWnd* pParent /*=NULL*/)
  21. : CBaseDialog(CDhcpClasses::IDD, pParent)
  22. {
  23. //{{AFX_DATA_INIT(CDhcpClasses)
  24. // NOTE: the ClassWizard will add member initialization here
  25. //}}AFX_DATA_INIT
  26. m_dwType = dwType;
  27. m_strServer = pszServer;
  28. m_pClassInfoArray = pClassArray;
  29. }
  30. void CDhcpClasses::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CBaseDialog::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CDhcpClasses)
  34. // NOTE: the ClassWizard will add DDX and DDV calls here
  35. //}}AFX_DATA_MAP
  36. }
  37. BEGIN_MESSAGE_MAP(CDhcpClasses, CBaseDialog)
  38. //{{AFX_MSG_MAP(CDhcpClasses)
  39. ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
  40. ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
  41. ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
  42. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_CLASSES, OnItemchangedListClasses)
  43. ON_NOTIFY(NM_DBLCLK, IDC_LIST_CLASSES, OnDblclkListClasses)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDhcpClasses message handlers
  48. BOOL CDhcpClasses::OnInitDialog()
  49. {
  50. CBaseDialog::OnInitDialog();
  51. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  52. CString strTitle;
  53. if (m_dwType == CLASS_TYPE_VENDOR)
  54. {
  55. strTitle.LoadString(IDS_VENDOR_CLASSES);
  56. }
  57. else
  58. {
  59. strTitle.LoadString(IDS_USER_CLASSES);
  60. }
  61. this->SetWindowText(strTitle);
  62. CListCtrl * pListCtrl = (CListCtrl *) GetDlgItem(IDC_LIST_CLASSES);
  63. LV_COLUMN lvColumn;
  64. CString strText;
  65. strText.LoadString(IDS_NAME);
  66. ListView_SetExtendedListViewStyle(pListCtrl->GetSafeHwnd(), LVS_EX_FULLROWSELECT);
  67. lvColumn.mask = LVCF_TEXT | LVCF_FMT | LVCF_WIDTH;
  68. lvColumn.fmt = LVCFMT_LEFT;
  69. lvColumn.cx = 125;
  70. lvColumn.pszText = (LPTSTR) (LPCTSTR) strText;
  71. pListCtrl->InsertColumn(0, &lvColumn);
  72. strText.LoadString(IDS_COMMENT);
  73. lvColumn.pszText = (LPTSTR) (LPCTSTR) strText;
  74. lvColumn.cx = 175;
  75. pListCtrl->InsertColumn(1, &lvColumn);
  76. UpdateList();
  77. UpdateButtons();
  78. return TRUE; // return TRUE unless you set the focus to a control
  79. // EXCEPTION: OCX Property Pages should return FALSE
  80. }
  81. void CDhcpClasses::OnButtonDelete()
  82. {
  83. CListCtrl * pListCtrl = (CListCtrl *) GetDlgItem(IDC_LIST_CLASSES);
  84. int nSelectedItem = pListCtrl->GetNextItem(-1, LVNI_SELECTED);
  85. CClassInfo * pClassInfo = (CClassInfo *) pListCtrl->GetItemData(nSelectedItem);
  86. CString strMessage;
  87. AfxFormatString1(strMessage, IDS_CONFIRM_CLASS_DELETE, pClassInfo->strName);
  88. if (AfxMessageBox(strMessage, MB_YESNO) == IDYES)
  89. {
  90. DWORD dwError = ::DhcpDeleteClass((LPTSTR) ((LPCTSTR) m_strServer),
  91. 0,
  92. (LPTSTR) ((LPCTSTR) pClassInfo->strName));
  93. if (dwError != ERROR_SUCCESS)
  94. {
  95. ::DhcpMessageBox(dwError);
  96. return;
  97. }
  98. else
  99. {
  100. m_pClassInfoArray->RemoveClass(pClassInfo->strName);
  101. UpdateList();
  102. UpdateButtons();
  103. }
  104. }
  105. }
  106. void CDhcpClasses::OnButtonEdit()
  107. {
  108. CDhcpModifyClass dlgModify(m_pClassInfoArray, m_strServer, FALSE, m_dwType);
  109. CListCtrl * pListCtrl = (CListCtrl *) GetDlgItem(IDC_LIST_CLASSES);
  110. // Find the selected item
  111. int nSelectedItem = pListCtrl->GetNextItem(-1, LVNI_SELECTED);
  112. CClassInfo * pClassInfo = (CClassInfo *) pListCtrl->GetItemData(nSelectedItem);
  113. dlgModify.m_EditValueParam.pValueName = (LPTSTR) ((LPCTSTR) pClassInfo->strName);
  114. dlgModify.m_EditValueParam.pValueComment = (LPTSTR) ((LPCTSTR) pClassInfo->strComment);
  115. dlgModify.m_EditValueParam.pValueData = pClassInfo->baData.GetData();
  116. dlgModify.m_EditValueParam.cbValueData = (UINT)pClassInfo->baData.GetSize();
  117. if (dlgModify.DoModal() == IDOK)
  118. {
  119. // need to refresh the view.
  120. UpdateList();
  121. UpdateButtons();
  122. }
  123. }
  124. void CDhcpClasses::OnButtonNew()
  125. {
  126. CDhcpModifyClass dlgModify(m_pClassInfoArray, m_strServer, TRUE, m_dwType);
  127. if (dlgModify.DoModal() == IDOK)
  128. {
  129. // need to refresh the view.
  130. UpdateList();
  131. UpdateButtons();
  132. }
  133. }
  134. void CDhcpClasses::OnOK()
  135. {
  136. CBaseDialog::OnOK();
  137. }
  138. void CDhcpClasses::UpdateList()
  139. {
  140. CListCtrl * pListCtrl = (CListCtrl *) GetDlgItem(IDC_LIST_CLASSES);
  141. pListCtrl->DeleteAllItems();
  142. for (int i = 0; i < m_pClassInfoArray->GetSize(); i++)
  143. {
  144. // add the appropriate classes depending on what we are looking at
  145. if ( (m_dwType == CLASS_TYPE_VENDOR &&
  146. (*m_pClassInfoArray)[i].bIsVendor) ||
  147. (m_dwType == CLASS_TYPE_USER &&
  148. !(*m_pClassInfoArray)[i].bIsVendor) )
  149. {
  150. int nPos = pListCtrl->InsertItem(i, (*m_pClassInfoArray)[i].strName);
  151. pListCtrl->SetItemText(nPos, 1, (*m_pClassInfoArray)[i].strComment);
  152. pListCtrl->SetItemData(nPos, (LPARAM) &(*m_pClassInfoArray)[i]);
  153. }
  154. }
  155. }
  156. void CDhcpClasses::UpdateButtons()
  157. {
  158. CListCtrl * pListCtrl = (CListCtrl *) GetDlgItem(IDC_LIST_CLASSES);
  159. BOOL bEnable = TRUE;
  160. CWnd * pCurFocus = GetFocus();
  161. if (pListCtrl->GetSelectedCount() == 0)
  162. {
  163. bEnable = FALSE;
  164. }
  165. CWnd * pEdit = GetDlgItem(IDC_BUTTON_EDIT);
  166. CWnd * pDelete = GetDlgItem(IDC_BUTTON_DELETE);
  167. if ( !bEnable &&
  168. ((pCurFocus == pEdit) ||
  169. (pCurFocus == pDelete)) )
  170. {
  171. GetDlgItem(IDCANCEL)->SetFocus();
  172. SetDefID(IDCANCEL);
  173. ((CButton *) pEdit)->SetButtonStyle(BS_PUSHBUTTON);
  174. ((CButton *) pDelete)->SetButtonStyle(BS_PUSHBUTTON);
  175. }
  176. // disable delete if this is the dynamic bootp class
  177. int nSelectedItem = pListCtrl->GetNextItem(-1, LVNI_SELECTED);
  178. if (nSelectedItem != -1)
  179. {
  180. CClassInfo * pClassInfo = (CClassInfo *) pListCtrl->GetItemData(nSelectedItem);
  181. if (pClassInfo->IsSystemClass() ||
  182. pClassInfo->IsRRASClass() ||
  183. pClassInfo->IsDynBootpClass())
  184. {
  185. bEnable = FALSE;
  186. }
  187. }
  188. pDelete->EnableWindow(bEnable);
  189. pEdit->EnableWindow(bEnable);
  190. }
  191. void CDhcpClasses::OnItemchangedListClasses(NMHDR* pNMHDR, LRESULT* pResult)
  192. {
  193. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  194. UpdateButtons();
  195. *pResult = 0;
  196. }
  197. void CDhcpClasses::OnDblclkListClasses(NMHDR* pNMHDR, LRESULT* pResult)
  198. {
  199. if (GetDlgItem(IDC_BUTTON_EDIT)->IsWindowEnabled())
  200. OnButtonEdit();
  201. *pResult = 0;
  202. }