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.

253 lines
6.3 KiB

  1. // strarrdlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "strarrdlg.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // StringArrayEditor dialog
  12. CDhcpStringArrayEditor::CDhcpStringArrayEditor(
  13. CDhcpOption *pdhcType,
  14. DHCP_OPTION_SCOPE_TYPE dhcScopeType,
  15. CWnd *pParent )
  16. : CBaseDialog( CDhcpStringArrayEditor::IDD, pParent ),
  17. m_p_type( pdhcType ),
  18. m_option_type( dhcScopeType )
  19. {
  20. //{{AFX_DATA_INIT(StringArrayEditor)
  21. // m_edit_value.Empty();
  22. //}}AFX_DATA_INIT
  23. }
  24. void CDhcpStringArrayEditor::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CDhcpStringArrayEditor)
  28. DDX_Control(pDX, IDC_STATIC_OPTION_NAME, m_static_option_name);
  29. DDX_Control(pDX, IDC_STATIC_APPLICATION, m_static_application);
  30. DDX_Control(pDX, IDC_BUTN_UP, m_b_up);
  31. DDX_Control(pDX, IDC_BUTN_DOWN, m_b_down);
  32. DDX_Control(pDX, IDC_BUTN_DELETE, m_b_delete);
  33. DDX_Control(pDX, IDC_BUTN_ADD, m_b_add);
  34. DDX_Control(pDX, IDC_LIST_STRING, m_lb_str);
  35. DDX_Control(pDX, IDC_EDIT_STRING, m_edit);
  36. DDX_Text(pDX, IDC_EDIT_STRING, m_edit_value);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CDhcpStringArrayEditor, CBaseDialog)
  40. //{{AFX_MSG_MAP(CDhcpStringArrayEditor)
  41. ON_BN_CLICKED(IDC_BUTN_ADD, OnButnAdd)
  42. ON_BN_CLICKED(IDC_BUTN_DELETE, OnButnDelete)
  43. ON_BN_CLICKED(IDC_BUTN_DOWN, OnButnDown)
  44. ON_BN_CLICKED(IDC_BUTN_UP, OnButnUp)
  45. ON_EN_CHANGE(IDC_EDIT_STRING, OnChangeEditString)
  46. ON_LBN_SELCHANGE(IDC_LIST_STRING, OnSelchangeListString)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CDhcpStringArrayEditor message handlers
  51. void CDhcpStringArrayEditor::OnButnAdd()
  52. {
  53. UpdateData();
  54. m_lb_str.InsertString( 0, m_edit_value );
  55. m_edit_value.Empty();
  56. m_lb_str.SetCurSel( 0 );
  57. // Set the focus back to the edit_value
  58. m_edit.SetFocus();
  59. UpdateData( FALSE );
  60. HandleActivation();
  61. } // CDhcpStringArrayEditor::OnButnAdd()
  62. void CDhcpStringArrayEditor::OnButnDelete()
  63. {
  64. int nSel = m_lb_str.GetCurSel();
  65. m_lb_str.GetText( nSel, m_edit_value );
  66. m_lb_str.DeleteString( nSel );
  67. nSel--;
  68. if ( nSel < 0 ) {
  69. nSel = 0;
  70. }
  71. m_lb_str.SetCurSel( nSel );
  72. m_lb_str.SetFocus();
  73. UpdateData( FALSE );
  74. HandleActivation();
  75. } // CDhcpStringArrayEditor::OnButnDelete()
  76. void CDhcpStringArrayEditor::OnButnDown()
  77. {
  78. int nSel = m_lb_str.GetCurSel();
  79. CString str;
  80. m_lb_str.GetText( nSel, str );
  81. m_lb_str.DeleteString( nSel );
  82. nSel++;
  83. m_lb_str.InsertString( nSel, str );
  84. m_lb_str.SetCurSel( nSel );
  85. UpdateData( FALSE );
  86. HandleActivation();
  87. } // CDhcpStringArrayEditor::OnButnDown()
  88. void CDhcpStringArrayEditor::OnButnUp()
  89. {
  90. int nSel = m_lb_str.GetCurSel();
  91. CString str;
  92. m_lb_str.GetText( nSel, str );
  93. m_lb_str.DeleteString( nSel );
  94. nSel--;
  95. m_lb_str.InsertString( nSel, str );
  96. m_lb_str.SetCurSel( nSel );
  97. UpdateData( FALSE );
  98. HandleActivation();
  99. } // CDhcpStringArrayEditor::OnButnUp()
  100. void CDhcpStringArrayEditor::OnChangeEditString()
  101. {
  102. UpdateData();
  103. m_b_add.EnableWindow( !m_edit_value.IsEmpty());
  104. } // CDhcpStringArrayEditor::OnChangeEditString()
  105. void CDhcpStringArrayEditor::OnSelchangeListString()
  106. {
  107. HandleActivation();
  108. } // CDhcpStringArrayEditor::OnSelchangeListString()
  109. void CDhcpStringArrayEditor::OnCancel()
  110. {
  111. CBaseDialog::OnCancel();
  112. }
  113. void CDhcpStringArrayEditor::OnOK()
  114. {
  115. int cItems = ( int ) m_lb_str.GetCount();
  116. DWORD err = 0;
  117. CString str;
  118. UpdateData();
  119. CATCH_MEM_EXCEPTION {
  120. CDhcpOptionValue *pdhcValue = &m_p_type->QueryValue();
  121. pdhcValue->RemoveAll();
  122. pdhcValue->SetUpperBound( cItems );
  123. for ( int i = 0; i < cItems; i++ ) {
  124. m_lb_str.GetText( i, str );
  125. pdhcValue->SetString( str, i );
  126. } // for
  127. m_p_type->SetDirty();
  128. }
  129. END_MEM_EXCEPTION( err );
  130. if ( err ) {
  131. ::DhcpMessageBox( err );
  132. OnCancel();
  133. }
  134. else {
  135. CBaseDialog::OnOK();
  136. }
  137. } // CDhcpStringArrayEditor::OnOK()
  138. BOOL CDhcpStringArrayEditor::OnInitDialog()
  139. {
  140. CBaseDialog::OnInitDialog();
  141. DWORD err = 0;
  142. int cStrId = ( m_option_type == DhcpDefaultOptions)
  143. ? IDS_INFO_TITLE_DEFAULT_OPTIONS
  144. : (( m_option_type == DhcpGlobalOptions )
  145. ? IDS_INFO_TITLE_GLOBAL_OPTIONS
  146. : IDS_INFO_TITLE_SCOPE_OPTIONS );
  147. CString str;
  148. CATCH_MEM_EXCEPTION {
  149. m_static_option_name.SetWindowText( m_p_type->QueryName());
  150. str.LoadString( cStrId );
  151. m_static_application.SetWindowText( str );
  152. // fill the internal list form the current value
  153. int cMax = m_p_type->QueryValue().QueryUpperBound();
  154. for ( int i = 0; i < cMax; i++ ) {
  155. str = m_p_type->QueryValue().QueryString( i );
  156. if ( !str.IsEmpty()) {
  157. m_lb_str.AddString( str );
  158. }
  159. } // for
  160. // Select the top most value
  161. if ( cMax > 0 ) {
  162. m_lb_str.SetCurSel( 0 );
  163. }
  164. // Set proper button states.
  165. HandleActivation();
  166. }
  167. END_MEM_EXCEPTION( err );
  168. UpdateData( FALSE );
  169. if ( err ) {
  170. ::DhcpMessageBox( err );
  171. EndDialog( -1 );
  172. }
  173. m_edit_value.Empty();
  174. return TRUE; // return TRUE unless you set the focus to a control
  175. // EXCEPTION: OCX Property Pages should return FALSE
  176. } // CDhcpStringArrayEditor::OnInitDialog()
  177. void CDhcpStringArrayEditor::HandleActivation()
  178. {
  179. int cItems = m_lb_str.GetCount();
  180. int cSel = m_lb_str.GetCurSel();
  181. m_b_add.EnableWindow( !m_edit_value.IsEmpty());
  182. if ( 0 == cItems ) {
  183. m_b_delete.EnableWindow( FALSE );
  184. m_b_down.EnableWindow( FALSE );
  185. m_b_up.EnableWindow( FALSE );
  186. return;
  187. }
  188. if ( LB_ERR != cSel ) {
  189. m_b_delete.EnableWindow( TRUE );
  190. m_b_down.EnableWindow( cItems > ( cSel + 1 ));
  191. m_b_up.EnableWindow( cSel > 0 );
  192. } // else
  193. // check if the focus in on a disabled control
  194. // If yes, put the focus back to list box
  195. if ( !::IsWindowEnabled( ::GetFocus())) {
  196. m_lb_str.SetFocus();
  197. }
  198. } // CDhcpStringArrayEditor::HandleActivation()