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.

412 lines
9.8 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : dlgSelectCountry.cpp //
  3. // //
  4. // DESCRIPTION : The CDlgSelectCountry class implements the //
  5. // dialog for selecting Country code from country ID. //
  6. // //
  7. // AUTHOR : yossg //
  8. // //
  9. // HISTORY : //
  10. // Sep 22 2000 yossg Create //
  11. // Oct 17 2000 yossg //
  12. // //
  13. // Copyright (C) 2000 Microsoft Corporation All Rights Reserved //
  14. /////////////////////////////////////////////////////////////////////////////
  15. #include "StdAfx.h"
  16. #include "dlgSelectCountry.h"
  17. #include "FaxServer.h"
  18. #include "FaxServerNode.h"
  19. #include "FaxMMCUtils.h"
  20. #include "dlgutils.h"
  21. #include "Helper.h"
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDlgSelectCountry
  24. CDlgSelectCountry::CDlgSelectCountry(CFaxServer * pFaxServer)
  25. {
  26. m_pCountryList = NULL;
  27. m_dwNumOfCountries = 0;
  28. m_fAllReadyToApply = FALSE;
  29. ATLASSERT(pFaxServer);
  30. m_pFaxServer = pFaxServer;
  31. }
  32. CDlgSelectCountry::~CDlgSelectCountry()
  33. {
  34. if (NULL != m_pCountryList)
  35. FaxFreeBuffer(m_pCountryList);
  36. }
  37. /*
  38. + CDlgSelectCountry::OnInitDialog
  39. +
  40. * Purpose:
  41. * Initiate all dialog controls.
  42. *
  43. * Arguments:
  44. * [in] uMsg : Value identifying the event.
  45. * [in] lParam : Message-specific value.
  46. * [in] wParam : Message-specific value.
  47. * [in] bHandled : bool value.
  48. *
  49. - Return:
  50. - 0 or 1
  51. */
  52. LRESULT
  53. CDlgSelectCountry::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  54. {
  55. DEBUG_FUNCTION_NAME( _T("CDlgSelectCountry::OnInitDialog"));
  56. HRESULT hRc = S_OK;
  57. DWORD ec = ERROR_SUCCESS;
  58. HINSTANCE hInst;
  59. hInst = _Module.GetResourceInstance();
  60. PFAX_TAPI_LINECOUNTRY_ENTRYW pCountryEntries;
  61. pCountryEntries = NULL;
  62. WCHAR buf[FXS_MAX_COUNTRYNAME_LEN //256 == TAPIUTIL MAX_COUNTRY_NAME
  63. +3 // " (" and ")"
  64. +FXS_MAX_COUNTRYCODE_LEN // 10
  65. +1]; //NULL
  66. //
  67. // Attach controls
  68. //
  69. m_CountryCombo.Attach(GetDlgItem(IDC_COUNTRYRULE_COMBO));
  70. //
  71. // Step 1: Init List
  72. //
  73. //
  74. // Init country drop-down box
  75. //
  76. ATLASSERT(m_pCountryList);
  77. pCountryEntries = m_pCountryList->LineCountryEntries;
  78. for (int i = 0; (DWORD)i < m_dwNumOfCountries; i++ )
  79. {
  80. wsprintf(buf, _T("%s (%d)"),
  81. pCountryEntries[i].lpctstrCountryName,
  82. pCountryEntries[i].dwCountryCode);
  83. hRc = AddComboBoxItem ( m_CountryCombo,
  84. buf, //pCountryEntries[i].lpctstrCountryName,
  85. pCountryEntries[i].dwCountryCode,
  86. hInst);
  87. if (FAILED(hRc))
  88. {
  89. DebugPrintEx( DEBUG_ERR, _T("Fail to load country list."));
  90. PageError(IDS_FAIL2LOADCOUNTRYLIST, m_hWnd, hInst);
  91. ::EnableWindow(GetDlgItem(IDC_COUNTRYRULE_COMBO), FALSE);
  92. goto Cleanup;
  93. }
  94. }
  95. Cleanup:
  96. EnableOK(FALSE);
  97. return 1; // Let the system set the focus
  98. }
  99. /*
  100. + CDlgSelectCountry::OnOK
  101. +
  102. * Purpose:
  103. * Submit data
  104. *
  105. * Arguments:
  106. *
  107. - Return:
  108. - 0 or 1
  109. */
  110. LRESULT
  111. CDlgSelectCountry::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  112. {
  113. DEBUG_FUNCTION_NAME( _T("CDlgSelectCountry::OnOK"));
  114. HRESULT hRc = S_OK;
  115. DWORD ec = ERROR_SUCCESS;
  116. BOOL fSkipMessage = FALSE;
  117. int iCurrentSelectedItem = 0;
  118. DWORD dwCountryCode = 0;
  119. //
  120. // Step 0: PreApply Checks
  121. //
  122. ATLASSERT( TRUE == m_fAllReadyToApply );
  123. if (!AllReadyToApply(/*fSilent =*/ FALSE))
  124. {
  125. EnableOK(FALSE);
  126. hRc =S_FALSE;
  127. goto Exit;
  128. }
  129. //
  130. // Step 1: get selected country
  131. //
  132. iCurrentSelectedItem = m_CountryCombo.GetCurSel();
  133. ATLASSERT(iCurrentSelectedItem != CB_ERR);
  134. //
  135. // Step 2: setCountryCode from the ItemData
  136. //
  137. m_dwCountryCode = (DWORD)m_CountryCombo.GetItemData(iCurrentSelectedItem);
  138. //
  139. // Step 3: Close the dialog
  140. //
  141. ATLASSERT(S_OK == hRc && ERROR_SUCCESS == ec);
  142. DebugPrintEx( DEBUG_MSG,
  143. _T("The rule was added successfully."));
  144. EndDialog(wID);
  145. goto Exit;
  146. Exit:
  147. return FAILED(hRc) ? 0 : 1;
  148. }
  149. /*
  150. - CDlgSelectCountry::OnComboChanged
  151. -
  152. * Purpose:
  153. * Gray/Ungray the submit button.
  154. *
  155. * Arguments:
  156. *
  157. * Return:
  158. * 1
  159. */
  160. LRESULT
  161. CDlgSelectCountry::OnComboChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  162. {
  163. DEBUG_FUNCTION_NAME( _T("CDlgSelectCountry::OnComboChanged"));
  164. if (AllReadyToApply(TRUE))
  165. {
  166. m_fAllReadyToApply = TRUE;
  167. EnableOK(TRUE);
  168. }
  169. else
  170. {
  171. m_fAllReadyToApply = FALSE;
  172. EnableOK(FALSE);
  173. }
  174. return 1;
  175. }
  176. /*
  177. - CDlgSelectCountry::AllReadyToApply
  178. -
  179. * Purpose:
  180. * Enable/Disable the submit button.
  181. *
  182. * Arguments:
  183. *
  184. * Return:
  185. * TRUE if all ready to apply, else FALSE.
  186. */
  187. BOOL
  188. CDlgSelectCountry::AllReadyToApply(BOOL fSilent)
  189. {
  190. DEBUG_FUNCTION_NAME( _T("CDlgSelectCountry::AllReadyToApply"));
  191. if ( CB_ERR == m_CountryCombo.GetCurSel())
  192. {
  193. if (!fSilent)
  194. {
  195. DlgMsgBox(this, IDS_PLEASESELECT_COUNTRY);
  196. ::SetFocus(GetDlgItem(IDC_COUNTRYRULE_COMBO));
  197. }
  198. return FALSE;
  199. }
  200. return TRUE;
  201. }
  202. /*
  203. - CDlgSelectCountry::EnableOK
  204. -
  205. * Purpose:
  206. * Enable/Disable the submit button.
  207. *
  208. * Arguments:
  209. * [in] fEnable - boolen value tells
  210. * to Enable or Disable the OK button.
  211. *
  212. * Return:
  213. * VOID
  214. */
  215. VOID
  216. CDlgSelectCountry::EnableOK(BOOL fEnable)
  217. {
  218. HWND hwndOK = GetDlgItem(IDOK);
  219. ::EnableWindow(hwndOK, fEnable);
  220. }
  221. /*
  222. - CDlgSelectCountry::OnCancel
  223. -
  224. * Purpose:
  225. * End the dialog.
  226. *
  227. * Arguments:
  228. *
  229. * Return:
  230. * 0
  231. */
  232. LRESULT
  233. CDlgSelectCountry::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  234. {
  235. DEBUG_FUNCTION_NAME( _T("CDlgSelectCountry::OnCancel"));
  236. EndDialog(wID);
  237. return 0;
  238. }
  239. /*
  240. - CDlgSelectCountry::InitSelectCountryCodeDlg
  241. -
  242. * Purpose:
  243. * Init all the members as country list pointer and
  244. * device list pointer
  245. *
  246. * Arguments:
  247. * No.
  248. *
  249. * Return:
  250. * 0
  251. */
  252. HRESULT CDlgSelectCountry::InitSelectCountryCodeDlg()
  253. {
  254. DEBUG_FUNCTION_NAME( _T("CDlgSelectCountry::InitSelectCountryCodeDlg"));
  255. HRESULT hRc = S_OK;
  256. DWORD ec = ERROR_SUCCESS;
  257. //
  258. // Step 1: Init Lists from RPC
  259. //
  260. //
  261. // get Fax Handle
  262. //
  263. if (!m_pFaxServer->GetFaxServerHandle())
  264. {
  265. ec= GetLastError();
  266. DebugPrintEx(
  267. DEBUG_ERR,
  268. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  269. ec);
  270. goto Error;
  271. }
  272. //
  273. // Country (code ,name)
  274. //
  275. if (!FaxGetCountryList(m_pFaxServer->GetFaxServerHandle(),
  276. &m_pCountryList))
  277. {
  278. ec = GetLastError();
  279. DebugPrintEx(
  280. DEBUG_ERR,
  281. _T("Fail to get c TAPI country list. (ec: %ld)"),
  282. ec);
  283. if (IsNetworkError(ec))
  284. {
  285. DebugPrintEx(
  286. DEBUG_ERR,
  287. _T("Network Error was found. (ec: %ld)"),
  288. ec);
  289. m_pFaxServer->Disconnect();
  290. }
  291. goto Error;
  292. }
  293. ATLASSERT(m_pCountryList);
  294. m_dwNumOfCountries = m_pCountryList->dwNumCountries;
  295. ATLASSERT(S_OK == hRc);
  296. DebugPrintEx( DEBUG_MSG,
  297. _T("Succeed to get all configurations."));
  298. goto Exit;
  299. Error:
  300. ATLASSERT(ERROR_SUCCESS != ec);
  301. hRc = HRESULT_FROM_WIN32(ec);
  302. //MsgBox will be done by calling Func.
  303. Exit:
  304. return hRc;
  305. }
  306. //////////////////////////////////////////////////////////////////////////////
  307. /*++
  308. CDlgSelectCountry::OnHelpRequest
  309. This is called in response to the WM_HELP Notify
  310. message and to the WM_CONTEXTMENU Notify message.
  311. WM_HELP Notify message.
  312. This message is sent when the user presses F1 or <Shift>-F1
  313. over an item or when the user clicks on the ? icon and then
  314. presses the mouse over an item.
  315. WM_CONTEXTMENU Notify message.
  316. This message is sent when the user right clicks over an item
  317. and then clicks "What's this?"
  318. --*/
  319. /////////////////////////////////////////////////////////////////////////////
  320. LRESULT
  321. CDlgSelectCountry::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  322. {
  323. DEBUG_FUNCTION_NAME(_T("CDlgSelectCountry::OnHelpRequest"));
  324. switch (uMsg)
  325. {
  326. case WM_HELP:
  327. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  328. break;
  329. case WM_CONTEXTMENU:
  330. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  331. break;
  332. }
  333. return TRUE;
  334. }
  335. /////////////////////////////////////////////////////////////////////////////