Source code of Windows XP (NT5)
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.

229 lines
7.2 KiB

  1. #include "stdafx.h"
  2. #include "wlbsparm.h"
  3. #include "PortsPage.h"
  4. #include "HostPortsDlg.h"
  5. #include "ResourceString.h"
  6. BEGIN_MESSAGE_MAP(HostPortsDlg, CDialog)
  7. ON_WM_HELPINFO()
  8. ON_WM_CONTEXTMENU()
  9. END_MESSAGE_MAP()
  10. HostPortsDlg::HostPortsDlg( PortsPage::PortData& portData,
  11. CWnd* parent
  12. )
  13. :
  14. m_portData( portData ),
  15. CDialog( HostPortsDlg::IDD, parent )
  16. {
  17. m_parent = (PortsPage *) parent;
  18. }
  19. void
  20. HostPortsDlg::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange( pDX );
  23. DDX_Control(pDX, IDC_EDIT_SINGLE, m_priority);
  24. }
  25. BOOL
  26. HostPortsDlg::OnInitDialog()
  27. {
  28. CDialog::OnInitDialog();
  29. SetControlData();
  30. return TRUE;
  31. }
  32. void
  33. HostPortsDlg::OnOK()
  34. {
  35. wchar_t buffer[Common::BUF_SIZE];
  36. //
  37. // The only thing which potentially could change
  38. // is the load weight if mode is multiple and the priority
  39. // if mode is single.
  40. //
  41. // set the new port rule.
  42. if( m_portData.mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_MULTIPLE ) )
  43. {
  44. // set the load here.
  45. BOOL fError;
  46. int weight = ::GetDlgItemInt (m_hWnd, IDC_EDIT_MULTI, &fError, FALSE);
  47. if( fError == FALSE )
  48. {
  49. // some problem with the data input.
  50. // it has been left blank.
  51. swprintf( buffer, GETRESOURCEIDSTRING( IDS_PARM_LOAD_BLANK ), CVY_MIN_LOAD, CVY_MAX_LOAD);
  52. MessageBox( buffer,
  53. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  54. MB_ICONSTOP | MB_OK );
  55. return;
  56. }
  57. if( !( weight >= CVY_MIN_LOAD
  58. &&
  59. weight <= CVY_MAX_LOAD )
  60. )
  61. {
  62. // the weight value is not in valid range.
  63. // These controls are all screwed up, even
  64. // after setting the limits we need to all
  65. // this checking, it is amazing!!!
  66. //
  67. swprintf( buffer, GETRESOURCEIDSTRING( IDS_PARM_LOAD ), CVY_MIN_LOAD,CVY_MAX_LOAD );
  68. MessageBox( buffer,
  69. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  70. MB_ICONSTOP | MB_OK );
  71. return;
  72. }
  73. swprintf( buffer, L"%d", weight );
  74. m_portData.load = buffer;
  75. }
  76. else if( m_portData.mode == GETRESOURCEIDSTRING( IDS_REPORT_MODE_SINGLE ) )
  77. {
  78. ::GetDlgItemText(m_hWnd, IDC_EDIT_SINGLE, buffer, Common::BUF_SIZE );
  79. m_portData.priority = buffer;
  80. }
  81. EndDialog( IDOK );
  82. }
  83. void
  84. HostPortsDlg::SetControlData()
  85. {
  86. // set ranges.
  87. ::SendDlgItemMessage(m_hWnd, IDC_EDIT_MULTI, EM_SETLIMITTEXT, 3, 0);
  88. ::SendDlgItemMessage(m_hWnd, IDC_SPIN_MULTI, UDM_SETRANGE32, CVY_MIN_LOAD, CVY_MAX_LOAD);
  89. ::SendDlgItemMessage(m_hWnd, IDC_EDIT_SINGLE, EM_SETLIMITTEXT, 2, 0);
  90. ::SendDlgItemMessage(m_hWnd, IDC_SPIN_SINGLE, UDM_SETRANGE32, CVY_MIN_MAX_HOSTS, CVY_MAX_MAX_HOSTS);
  91. // set the ports
  92. ::SetDlgItemInt (m_hWnd, IDC_EDIT_START, _wtoi( m_portData.start_port), FALSE);
  93. ::SetDlgItemInt (m_hWnd, IDC_EDIT_END, _wtoi( m_portData.end_port ), FALSE);
  94. // set the protocol.
  95. if( m_portData.protocol == GETRESOURCEIDSTRING(IDS_REPORT_PROTOCOL_TCP) )
  96. {
  97. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_CHECKED );
  98. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_UNCHECKED );
  99. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_UNCHECKED );
  100. }
  101. else if( m_portData.protocol == GETRESOURCEIDSTRING(IDS_REPORT_PROTOCOL_UDP) )
  102. {
  103. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_UNCHECKED );
  104. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_CHECKED );
  105. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_UNCHECKED );
  106. }
  107. else
  108. {
  109. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_UNCHECKED );
  110. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_UNCHECKED );
  111. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_CHECKED );
  112. }
  113. // set the mode.
  114. if( m_portData.mode == GETRESOURCEIDSTRING(IDS_REPORT_MODE_MULTIPLE) )
  115. {
  116. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_CHECKED );
  117. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_UNCHECKED );
  118. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_UNCHECKED );
  119. ::CheckDlgButton( m_hWnd, IDC_CHECK_EQUAL, BST_UNCHECKED );
  120. ::SetDlgItemInt (m_hWnd, IDC_EDIT_MULTI, _wtoi( m_portData.load), FALSE);
  121. :: EnableWindow (GetDlgItem (IDC_TEXT_MULTI)->m_hWnd, TRUE);
  122. :: EnableWindow (GetDlgItem (IDC_EDIT_MULTI)->m_hWnd, TRUE);
  123. :: EnableWindow (GetDlgItem (IDC_SPIN_MULTI)->m_hWnd, TRUE);
  124. if( m_portData.affinity == GETRESOURCEIDSTRING(IDS_REPORT_AFFINITY_NONE ) )
  125. {
  126. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_CHECKED );
  127. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_UNCHECKED );
  128. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  129. }
  130. else if ( m_portData.affinity == GETRESOURCEIDSTRING(IDS_REPORT_AFFINITY_SINGLE) )
  131. {
  132. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  133. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_CHECKED );
  134. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  135. }
  136. else
  137. {
  138. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  139. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_UNCHECKED );
  140. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_CHECKED );
  141. }
  142. }
  143. else if( m_portData.mode == GETRESOURCEIDSTRING(IDS_REPORT_MODE_SINGLE) )
  144. {
  145. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_UNCHECKED );
  146. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_CHECKED );
  147. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_UNCHECKED );
  148. BOOL fError;
  149. set<long> availPriorities =
  150. m_parent->m_clusterData->portF[_wtoi( m_portData.start_port ) ].getAvailablePriorities();
  151. availPriorities.insert( _wtoi( m_portData.priority ) );
  152. wchar_t buf[Common::BUF_SIZE];
  153. set<long>::iterator top;
  154. for( top = availPriorities.begin();
  155. top != availPriorities.end();
  156. ++top )
  157. {
  158. swprintf( buf, L"%d", *top );
  159. m_priority.AddString( buf );
  160. }
  161. // set selection to present hostid
  162. swprintf( buf, L"%d", _wtoi( m_portData.priority ) );
  163. m_priority.SelectString( -1, buf );
  164. :: EnableWindow (GetDlgItem (IDC_TEXT_SINGLE)->m_hWnd, TRUE);
  165. :: EnableWindow (GetDlgItem (IDC_EDIT_SINGLE)->m_hWnd, TRUE);
  166. }
  167. }
  168. BOOL
  169. HostPortsDlg::OnHelpInfo (HELPINFO* helpInfo )
  170. {
  171. if( helpInfo->iContextType == HELPINFO_WINDOW )
  172. {
  173. ::WinHelp( static_cast<HWND> ( helpInfo->hItemHandle ),
  174. CVY_CTXT_HELP_FILE, HELP_WM_HELP,
  175. (ULONG_PTR ) g_aHelpIDs_IDD_PORT_RULE_PROP_HOSTS );
  176. }
  177. return TRUE;
  178. }
  179. void
  180. HostPortsDlg::OnContextMenu( CWnd* pWnd, CPoint point )
  181. {
  182. ::WinHelp( m_hWnd,
  183. CVY_CTXT_HELP_FILE,
  184. HELP_CONTEXTMENU,
  185. (ULONG_PTR ) g_aHelpIDs_IDD_PORT_RULE_PROP_HOSTS );
  186. }