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.

984 lines
24 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : dlgNewRule.cpp //
  3. // //
  4. // DESCRIPTION : The CDlgNewFaxOutboundRule class implements the //
  5. // dialog for additon of new Rule. //
  6. // //
  7. // AUTHOR : yossg //
  8. // //
  9. // HISTORY : //
  10. // Dec 30 1999 yossg Create //
  11. // Jan 25 2000 yossg Change the Dialog Design //
  12. // Oct 17 2000 yossg //
  13. // //
  14. // Copyright (C) 1999 - 2000 Microsoft Corporation All Rights Reserved //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "StdAfx.h"
  17. #include "dlgNewRule.h"
  18. #include "DlgSelectCountry.h"
  19. #include "FaxServer.h"
  20. #include "FaxServerNode.h"
  21. #include "FaxMMCUtils.h"
  22. #include "dlgutils.h"
  23. #include "Helper.h"
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CDlgNewFaxOutboundRule
  26. CDlgNewFaxOutboundRule::CDlgNewFaxOutboundRule(CFaxServer * pFaxServer)
  27. {
  28. m_pFaxDevicesConfig = NULL;
  29. m_dwNumOfDevices = 0;
  30. m_pFaxGroupsConfig = NULL;
  31. m_dwNumOfGroups = 0;
  32. m_fAllReadyToApply = FALSE;
  33. ATLASSERT(pFaxServer);
  34. m_pFaxServer = pFaxServer;
  35. }
  36. CDlgNewFaxOutboundRule::~CDlgNewFaxOutboundRule()
  37. {
  38. if (NULL != m_pFaxDevicesConfig)
  39. FaxFreeBuffer(m_pFaxDevicesConfig);
  40. if (NULL != m_pFaxGroupsConfig)
  41. FaxFreeBuffer(m_pFaxGroupsConfig);
  42. }
  43. /*
  44. + CDlgNewFaxOutboundRule::OnInitDialog
  45. +
  46. * Purpose:
  47. * Initiate all dialog controls.
  48. *
  49. * Arguments:
  50. * [in] uMsg : Value identifying the event.
  51. * [in] lParam : Message-specific value.
  52. * [in] wParam : Message-specific value.
  53. * [in] bHandled : bool value.
  54. *
  55. - Return:
  56. - 0 or 1
  57. */
  58. LRESULT
  59. CDlgNewFaxOutboundRule::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  60. {
  61. DEBUG_FUNCTION_NAME( _T("CDlgNewFaxOutboundRule::OnInitDialog"));
  62. HRESULT hRc = S_OK;
  63. DWORD ec = ERROR_SUCCESS;
  64. int i , j ,k, l;
  65. i = j = k = l = 0;
  66. const int iAllDevicesComboIndex = 0;
  67. int iAllDevicesRPCIndex = 0;
  68. int iGroupListIndexToSelect = 0;
  69. HINSTANCE hInst;
  70. hInst = _Module.GetResourceInstance();
  71. WCHAR buf[FXS_MAX_DISPLAY_NAME_LEN+1];
  72. //
  73. // Attach controls
  74. //
  75. m_CountryCodeEdit.Attach(GetDlgItem(IDC_NEWRULE_COUNTRYCODE_EDIT));
  76. m_AreaCodeEdit.Attach(GetDlgItem(IDC_RULE_AREACODE_EDIT));
  77. m_DeviceCombo.Attach(GetDlgItem(IDC_DEVICES4RULE_COMBO));
  78. m_GroupCombo.Attach(GetDlgItem(IDC_GROUP4RULE_COMBO));
  79. //
  80. // Set length limit to area code
  81. //
  82. m_CountryCodeEdit.SetLimitText(FXS_MAX_COUNTRYCODE_LEN - 1);
  83. m_AreaCodeEdit.SetLimitText(FXS_MAX_AREACODE_LEN-1);
  84. //
  85. // Step 1: Init Lists
  86. //
  87. //
  88. // Init Devices
  89. //
  90. for (k = 0; (DWORD)k < m_dwNumOfDevices; k++ )
  91. {
  92. hRc = AddComboBoxItem ( m_DeviceCombo,
  93. m_pFaxDevicesConfig[k].lpctstrDeviceName,
  94. m_pFaxDevicesConfig[k].dwDeviceID,
  95. hInst);
  96. if (FAILED(hRc))
  97. {
  98. DebugPrintEx( DEBUG_ERR, _T("Fail to load device list."));
  99. PageError(IDS_FAIL2LOADDEVICELIST, m_hWnd, hInst);
  100. ::EnableWindow(GetDlgItem(IDC_DEVICES4RULE_COMBO), FALSE);
  101. goto Cleanup;
  102. }
  103. }
  104. //
  105. // Init groups
  106. //
  107. for (l = 0; (DWORD)l < m_dwNumOfGroups; l++ )
  108. {
  109. if ( 0 == wcscmp(ROUTING_GROUP_ALL_DEVICES, m_pFaxGroupsConfig[l].lpctstrGroupName))
  110. {
  111. iAllDevicesRPCIndex = l;
  112. //Do not do any more;
  113. }
  114. else
  115. {
  116. hRc = AddComboBoxItem ( m_GroupCombo,
  117. m_pFaxGroupsConfig[l].lpctstrGroupName,
  118. (DWORD)l,
  119. hInst);
  120. if (FAILED(hRc))
  121. {
  122. DebugPrintEx( DEBUG_ERR, _T("Fail to load group list."));
  123. PageError(IDS_FAIL2LOADDEVICELIST, m_hWnd, hInst);
  124. ::EnableWindow(GetDlgItem(IDC_GROUP4RULE_COMBO), FALSE);
  125. goto Cleanup;
  126. }
  127. }
  128. }
  129. //
  130. // Now add "All Devices" Group as the first one
  131. //
  132. //
  133. // Replace <all Devices> string for localization
  134. //
  135. if (!hInst)
  136. {
  137. hInst = _Module.GetResourceInstance();
  138. }
  139. if (!LoadString(hInst, IDS_ALL_DEVICES, buf, FXS_MAX_DISPLAY_NAME_LEN))
  140. {
  141. hRc = E_OUTOFMEMORY;
  142. DebugPrintEx( DEBUG_ERR, _T("Fail to load string. Out of memory."));
  143. PageError(IDS_FAXOUTOFMEMORY, m_hWnd, hInst);
  144. goto Cleanup;
  145. }
  146. //
  147. // insert "All Devices" Group as the first one in the groups list
  148. //
  149. ATLASSERT( 0 == iAllDevicesComboIndex );
  150. hRc = SetComboBoxItem ( m_GroupCombo,
  151. iAllDevicesComboIndex,
  152. buf,
  153. iAllDevicesRPCIndex,
  154. hInst);
  155. if (FAILED(hRc))
  156. {
  157. DebugPrintEx( DEBUG_ERR, _T("Fail to load group list."));
  158. PageError(IDS_FAIL2LOADGROUPLIST, m_hWnd, hInst);
  159. ::EnableWindow(GetDlgItem(IDC_GROUP4RULE_COMBO), FALSE);
  160. goto Cleanup;
  161. }
  162. //
  163. // Step 2: Set current status
  164. // (Select items in Lists, select radio button etc.)
  165. // (Gray/UnGray controls)
  166. //
  167. m_GroupCombo.SetCurSel (iAllDevicesComboIndex);
  168. //
  169. // Radio buttons, Gray/UnGray
  170. //
  171. CheckDlgButton(IDC_COUNTRY_RADIO, BST_CHECKED);
  172. ::EnableWindow(GetDlgItem(IDC_RULE_AREACODE_EDIT), FALSE);
  173. CheckDlgButton(IDC_DESTINATION_RADIO2, BST_CHECKED) ;
  174. ::EnableWindow(GetDlgItem(IDC_DEVICES4RULE_COMBO), FALSE);
  175. Cleanup:
  176. EnableOK(FALSE);
  177. return 1; // Let the system set the focus
  178. }
  179. /*
  180. + CDlgNewFaxOutboundRule::OnOK
  181. +
  182. * Purpose:
  183. * Submit data
  184. *
  185. * Arguments:
  186. *
  187. - Return:
  188. - 0 or 1
  189. */
  190. LRESULT
  191. CDlgNewFaxOutboundRule::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  192. {
  193. DEBUG_FUNCTION_NAME( _T("CDlgNewFaxOutboundRule::OnOK"));
  194. HRESULT hRc = S_OK;
  195. DWORD ec = ERROR_SUCCESS;
  196. BOOL fSkipMessage = FALSE;
  197. CComBSTR bstrAreaCode;
  198. CComBSTR bstrCountryCode;
  199. int iCurrentSelectedItem = 0;
  200. DWORD dwAreaCode = 0;
  201. DWORD dwCountryCode = 0;
  202. BOOL bUseGroup;
  203. DWORD dwDeviceID = 0;
  204. WCHAR lpszGroupName[MAX_ROUTING_GROUP_NAME];
  205. LPCTSTR lpctstrGroupName = NULL;
  206. //
  207. // Step 0: PreApply Checks
  208. //
  209. ATLASSERT( TRUE == m_fAllReadyToApply );
  210. if (!AllReadyToApply(/*fSilent =*/ FALSE))
  211. {
  212. EnableOK(FALSE);
  213. hRc =S_FALSE;
  214. goto Exit;
  215. }
  216. //
  217. // Step 1: get data
  218. //
  219. //
  220. // Country Code
  221. //
  222. if ( !m_CountryCodeEdit.GetWindowText(&bstrCountryCode))
  223. {
  224. DebugPrintEx(
  225. DEBUG_ERR,
  226. TEXT("Failed to GetWindowText(&bstrCountryCode)"));
  227. DlgMsgBox(this, IDS_FAIL2READ_COUNTRYCODE);
  228. ::SetFocus(GetDlgItem(IDC_RULE_COUNTRYCODE_EDIT));
  229. hRc = S_FALSE;
  230. goto Exit;
  231. }
  232. dwCountryCode = (DWORD)wcstoul( bstrCountryCode, NULL, 10 );
  233. if (ROUTING_RULE_COUNTRY_CODE_ANY == dwCountryCode)
  234. {
  235. //
  236. // The user try to set the country code to zero
  237. //
  238. DebugPrintEx(
  239. DEBUG_ERR,
  240. TEXT(" CountryCode == ROUTING_RULE_COUNTRY_CODE_ANY "));
  241. DlgMsgBox(this, IDS_ZERO_COUNTRYCODE);
  242. ::SetFocus(GetDlgItem(IDC_RULE_COUNTRYCODE_EDIT));
  243. hRc = S_FALSE;
  244. goto Exit;
  245. }
  246. //
  247. // Area Code
  248. //
  249. if ( IsDlgButtonChecked(IDC_COUNTRY_RADIO) == BST_CHECKED )
  250. {
  251. dwAreaCode = (DWORD)ROUTING_RULE_AREA_CODE_ANY;
  252. }
  253. else // IsDlgButtonChecked(IDC_AREA_RADIO) == BST_CHECKED
  254. {
  255. if ( !m_AreaCodeEdit.GetWindowText(&bstrAreaCode))
  256. {
  257. DebugPrintEx(
  258. DEBUG_ERR,
  259. TEXT("Failed to GetWindowText(&bstrAreaCode)"));
  260. DlgMsgBox(this, IDS_FAIL2READ_AREACODE);
  261. ::SetFocus(GetDlgItem(IDC_RULE_AREACODE_EDIT));
  262. hRc = S_FALSE;
  263. goto Exit;
  264. }
  265. dwAreaCode = (DWORD)wcstoul( bstrAreaCode, NULL, 10 );
  266. }
  267. if ( IsDlgButtonChecked(IDC_DESTINATION_RADIO1) == BST_CHECKED )
  268. {
  269. //
  270. // Use Group ?
  271. //
  272. bUseGroup = FALSE;
  273. //
  274. // Device
  275. //
  276. iCurrentSelectedItem = m_DeviceCombo.GetCurSel();
  277. ATLASSERT(iCurrentSelectedItem != CB_ERR); //should be chacked pre apply
  278. dwDeviceID = (DWORD)m_DeviceCombo.GetItemData (iCurrentSelectedItem);
  279. }
  280. else // IsDlgButtonChecked(IDC_DESTINATION_RADIO2) == BST_CHECKED
  281. {
  282. //
  283. // Use Group ?
  284. //
  285. bUseGroup = TRUE;
  286. //
  287. // Group
  288. //
  289. iCurrentSelectedItem = m_GroupCombo.GetCurSel();
  290. //ATLASSERT(iCurrentSelectedItem != CB_ERR); //should be chacked pre apply
  291. if (0 == iCurrentSelectedItem) //All Devices
  292. {
  293. lpctstrGroupName = ROUTING_GROUP_ALL_DEVICES;
  294. }
  295. else
  296. {
  297. ATLASSERT(MAX_ROUTING_GROUP_NAME > m_GroupCombo.GetLBTextLen(iCurrentSelectedItem)); //should be chacked by service before
  298. m_GroupCombo.GetLBText( iCurrentSelectedItem, lpszGroupName );
  299. lpctstrGroupName = (LPCTSTR)lpszGroupName;
  300. }
  301. }
  302. //
  303. // Step 2: Add Rule to service with RPC
  304. //
  305. //
  306. // get RPC Handle
  307. //
  308. if (!m_pFaxServer->GetFaxServerHandle())
  309. {
  310. ec= GetLastError();
  311. DebugPrintEx(
  312. DEBUG_ERR,
  313. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  314. ec);
  315. goto Error;
  316. }
  317. //
  318. // Add the rule
  319. //
  320. if (!FaxAddOutboundRule (
  321. m_pFaxServer->GetFaxServerHandle(),
  322. dwAreaCode,
  323. dwCountryCode,
  324. dwDeviceID,
  325. lpctstrGroupName,
  326. bUseGroup))
  327. {
  328. ec = GetLastError();
  329. DebugPrintEx(
  330. DEBUG_ERR,
  331. _T("Fail to add rule. (ec: %ld)"),
  332. ec);
  333. if (ERROR_DUP_NAME == ec)
  334. {
  335. DlgMsgBox(this, IDS_OUTRULE_EXISTS);
  336. goto Exit;
  337. }
  338. if (FAX_ERR_BAD_GROUP_CONFIGURATION == ec)
  339. {
  340. DebugPrintEx(
  341. DEBUG_ERR,
  342. _T("The group is empty or none of group devices is valid. (ec: %ld)"),
  343. ec);
  344. PageError(IDS_BAD_GROUP_CONFIGURATION,m_hWnd);
  345. fSkipMessage = TRUE;
  346. goto Error;
  347. }
  348. if (IsNetworkError(ec))
  349. {
  350. DebugPrintEx(
  351. DEBUG_ERR,
  352. _T("Network Error was found. (ec: %ld)"),
  353. ec);
  354. m_pFaxServer->Disconnect();
  355. }
  356. goto Error;
  357. }
  358. //
  359. // Step 3: Close the dialog
  360. //
  361. ATLASSERT(S_OK == hRc && ERROR_SUCCESS == ec);
  362. DebugPrintEx( DEBUG_MSG,
  363. _T("The rule was added successfully."));
  364. EndDialog(wID);
  365. goto Exit;
  366. Error:
  367. ATLASSERT(ERROR_SUCCESS != ec);
  368. hRc = HRESULT_FROM_WIN32(ec);
  369. if (!fSkipMessage)
  370. {
  371. PageErrorEx(IDS_FAIL_ADD_RULE, GetFaxServerErrorMsg(ec), m_hWnd);
  372. }
  373. Exit:
  374. return FAILED(hRc) ? 0 : 1;
  375. }
  376. /*
  377. - CDlgNewFaxOutboundRule::OnDestenationRadioClicked
  378. -
  379. * Purpose:
  380. * Gray/Ungray the folder edit box and the
  381. * browse button. Enable apply button.
  382. *
  383. * Arguments:
  384. *
  385. * Return:
  386. * 1
  387. */
  388. LRESULT CDlgNewFaxOutboundRule::OnDestenationRadioClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  389. {
  390. BOOL State;
  391. State = ( IsDlgButtonChecked(IDC_DESTINATION_RADIO1) == BST_CHECKED );
  392. ::EnableWindow(GetDlgItem(IDC_DEVICES4RULE_COMBO), State);
  393. ATLASSERT(!State == (IsDlgButtonChecked(IDC_DESTINATION_RADIO2) == BST_CHECKED));
  394. ::EnableWindow(GetDlgItem(IDC_GROUP4RULE_COMBO), !State);
  395. if (State)//IsDlgButtonChecked(IDC_DESTINATION_RADIO1) == BST_CHECKED
  396. {
  397. if ( CB_ERR == m_DeviceCombo.GetCurSel())
  398. {
  399. m_fAllReadyToApply = FALSE;
  400. EnableOK(FALSE);
  401. goto Exit;
  402. }
  403. //else continue to whole controls check
  404. }
  405. else //IsDlgButtonChecked(IDC_DESTINATION_RADIO2) == BST_CHECKED
  406. {
  407. if ( CB_ERR == m_GroupCombo.GetCurSel())
  408. {
  409. m_fAllReadyToApply = FALSE;
  410. EnableOK(FALSE);
  411. goto Exit;
  412. }
  413. //else continue to whole controls check
  414. }
  415. if (!m_fAllReadyToApply)
  416. {
  417. if (AllReadyToApply(TRUE))
  418. {
  419. m_fAllReadyToApply = TRUE;
  420. EnableOK(TRUE);
  421. }
  422. else
  423. {
  424. //Should be EnableOK(FALSE);
  425. }
  426. }
  427. Exit:
  428. return(1);
  429. }
  430. /*
  431. - CDlgNewFaxOutboundRule::OnRuleTypeRadioClicked
  432. -
  433. * Purpose:
  434. * Gray/Ungray the folder edit box and the
  435. * browse button. Enable apply button.
  436. *
  437. * Arguments:
  438. *
  439. * Return:
  440. * 1
  441. */
  442. LRESULT CDlgNewFaxOutboundRule::OnRuleTypeRadioClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  443. {
  444. BOOL State;
  445. State = ( IsDlgButtonChecked(IDC_COUNTRY_RADIO) == BST_CHECKED );
  446. ATLASSERT(!State == (IsDlgButtonChecked(IDC_AREA_RADIO) == BST_CHECKED));
  447. ::EnableWindow(GetDlgItem(IDC_RULE_AREACODE_EDIT), !State);
  448. if (!State)//IsDlgButtonChecked(IDC_AREA_RADIO) == BST_CHECKED
  449. {
  450. if ( !m_AreaCodeEdit.GetWindowTextLength() )
  451. {
  452. m_fAllReadyToApply = FALSE;
  453. EnableOK(FALSE);
  454. goto Exit;
  455. }
  456. //else continue to whole controls check
  457. }
  458. //else //IsDlgButtonChecked(IDC_COUNTRY_RADIO) == BST_CHECKED
  459. //Do noting - continue to whole controls check
  460. if (!m_fAllReadyToApply)
  461. {
  462. if (AllReadyToApply(TRUE))
  463. {
  464. m_fAllReadyToApply = TRUE;
  465. EnableOK(TRUE);
  466. }
  467. }
  468. Exit:
  469. return(1);
  470. }
  471. /*
  472. - CDlgNewFaxOutboundRule::OnComboChanged
  473. -
  474. * Purpose:
  475. * Gray/Ungray the submit button.
  476. *
  477. * Arguments:
  478. *
  479. * Return:
  480. * 1
  481. */
  482. LRESULT
  483. CDlgNewFaxOutboundRule::OnComboChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  484. {
  485. DEBUG_FUNCTION_NAME( _T("CDlgNewFaxOutboundRule::OnComboChanged"));
  486. if (!m_fAllReadyToApply)
  487. {
  488. if (AllReadyToApply(TRUE))
  489. {
  490. m_fAllReadyToApply = TRUE;
  491. EnableOK(TRUE);
  492. }
  493. }
  494. return 1;
  495. }
  496. /*
  497. - CDlgNewFaxOutboundRule::OnTextChanged
  498. -
  499. * Purpose:
  500. * Enable/Disable the submit button.
  501. *
  502. * Arguments:
  503. *
  504. * Return:
  505. * 1
  506. */
  507. LRESULT
  508. CDlgNewFaxOutboundRule::OnTextChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  509. {
  510. DEBUG_FUNCTION_NAME( _T("CDlgNewFaxOutboundRule::OnTextChanged"));
  511. UINT fEnableOK = 0;
  512. switch (wID)
  513. {
  514. case IDC_RULE_AREACODE_EDIT:
  515. fEnableOK = ( m_AreaCodeEdit.GetWindowTextLength() );
  516. break;
  517. case IDC_NEWRULE_COUNTRYCODE_EDIT:
  518. fEnableOK = ( m_CountryCodeEdit.GetWindowTextLength() );
  519. break;
  520. default:
  521. ATLASSERT(FALSE);
  522. }
  523. if(!!fEnableOK)
  524. {
  525. if (!m_fAllReadyToApply)
  526. {
  527. if (AllReadyToApply(TRUE))
  528. {
  529. m_fAllReadyToApply = TRUE;
  530. EnableOK(TRUE);
  531. }
  532. }
  533. }
  534. else
  535. {
  536. EnableOK(FALSE);
  537. m_fAllReadyToApply = FALSE;
  538. }
  539. return 1;
  540. }
  541. /*
  542. - CDlgNewFaxOutboundRule::AllReadyToApply
  543. -
  544. * Purpose:
  545. * Enable/Disable the submit button.
  546. *
  547. * Arguments:
  548. *
  549. * Return:
  550. * TRUE if all ready to apply, else FALSE.
  551. */
  552. BOOL
  553. CDlgNewFaxOutboundRule::AllReadyToApply(BOOL fSilent)
  554. {
  555. DEBUG_FUNCTION_NAME( _T("CDlgNewFaxOutboundRule::AllReadyToApply"));
  556. if ( !m_CountryCodeEdit.GetWindowTextLength() )
  557. {
  558. if (!fSilent)
  559. {
  560. DlgMsgBox(this, IDS_ZERO_COUNTRYCODE);
  561. ::SetFocus(GetDlgItem(IDC_NEWRULE_COUNTRYCODE_EDIT));
  562. }
  563. return FALSE;
  564. }
  565. if ( IsDlgButtonChecked(IDC_AREA_RADIO) == BST_CHECKED )
  566. {
  567. if ( !m_AreaCodeEdit.GetWindowTextLength() )
  568. {
  569. if (!fSilent)
  570. {
  571. DlgMsgBox(this, IDS_EMPTY_AREACODE);
  572. ::SetFocus(GetDlgItem(IDC_RULE_AREACODE_EDIT));
  573. }
  574. return FALSE;
  575. }
  576. }
  577. //else do noting.
  578. if ( IsDlgButtonChecked(IDC_DESTINATION_RADIO1) == BST_CHECKED )
  579. {
  580. if ( CB_ERR == m_DeviceCombo.GetCurSel())
  581. {
  582. if (!fSilent)
  583. {
  584. DlgMsgBox(this, IDS_PLEASESELECT_DEVICE);
  585. ::SetFocus(GetDlgItem(IDC_DEVICES4RULE_COMBO));
  586. }
  587. return FALSE;
  588. }
  589. }
  590. else if ( CB_ERR == m_GroupCombo.GetCurSel())
  591. {
  592. if (!fSilent)
  593. {
  594. DlgMsgBox(this, IDS_PLEASESELECT_GROUP);
  595. ::SetFocus(GetDlgItem(IDC_GROUP4RULE_COMBO));
  596. }
  597. return FALSE;
  598. }
  599. //
  600. // Cheers!
  601. // ...every thing ready to apply now.
  602. //
  603. return TRUE;
  604. }
  605. /*
  606. - CDlgNewFaxOutboundRule::EnableOK
  607. -
  608. * Purpose:
  609. * Enable/Disable the submit button.
  610. *
  611. * Arguments:
  612. * [in] fEnable - boolen value tells
  613. * to Enable or Disable the OK button.
  614. *
  615. * Return:
  616. * VOID
  617. */
  618. VOID
  619. CDlgNewFaxOutboundRule::EnableOK(BOOL fEnable)
  620. {
  621. HWND hwndOK = GetDlgItem(IDOK);
  622. ::EnableWindow(hwndOK, fEnable);
  623. }
  624. /*
  625. - CDlgNewFaxOutboundRule::OnCancel
  626. -
  627. * Purpose:
  628. * End the dialog.
  629. *
  630. * Arguments:
  631. *
  632. * Return:
  633. * 0
  634. */
  635. LRESULT
  636. CDlgNewFaxOutboundRule::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  637. {
  638. DEBUG_FUNCTION_NAME( _T("CDlgNewFaxOutboundRule::OnCancel"));
  639. EndDialog(wID);
  640. return 0;
  641. }
  642. /*
  643. - CDlgNewFaxOutboundRule::InitRuleDlg
  644. -
  645. * Purpose:
  646. * Init all the members as country list pointer and
  647. * device list pointer
  648. *
  649. * Arguments:
  650. * No.
  651. *
  652. * Return:
  653. * 0
  654. */
  655. HRESULT CDlgNewFaxOutboundRule::InitRuleDlg()
  656. {
  657. DEBUG_FUNCTION_NAME( _T("CDlgNewFaxOutboundRule::InitRuleDlg"));
  658. HRESULT hRc = S_OK;
  659. DWORD ec = ERROR_SUCCESS;
  660. //
  661. // Step 1: Init Lists from RPC
  662. //
  663. //
  664. // get Fax Handle
  665. //
  666. if (!m_pFaxServer->GetFaxServerHandle())
  667. {
  668. ec= GetLastError();
  669. DebugPrintEx(
  670. DEBUG_ERR,
  671. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  672. ec);
  673. goto Error;
  674. }
  675. //
  676. // Devices (id, name)
  677. //
  678. if (!FaxEnumPortsEx(m_pFaxServer->GetFaxServerHandle(),
  679. &m_pFaxDevicesConfig,
  680. &m_dwNumOfDevices))
  681. {
  682. ec = GetLastError();
  683. DebugPrintEx(
  684. DEBUG_ERR,
  685. _T("Fail to get devices configuration. (ec: %ld)"),
  686. ec);
  687. if (IsNetworkError(ec))
  688. {
  689. DebugPrintEx(
  690. DEBUG_ERR,
  691. _T("Network Error was found. (ec: %ld)"),
  692. ec);
  693. m_pFaxServer->Disconnect();
  694. }
  695. goto Error;
  696. }
  697. ATLASSERT(m_pFaxDevicesConfig);
  698. //
  699. // Groups (names)
  700. //
  701. if (!FaxEnumOutboundGroups(m_pFaxServer->GetFaxServerHandle(),
  702. &m_pFaxGroupsConfig,
  703. &m_dwNumOfGroups))
  704. {
  705. ec = GetLastError();
  706. DebugPrintEx(
  707. DEBUG_ERR,
  708. _T("Fail to get groups configuration. (ec: %ld)"),
  709. ec);
  710. if (IsNetworkError(ec))
  711. {
  712. DebugPrintEx(
  713. DEBUG_ERR,
  714. _T("Network Error was found. (ec: %ld)"),
  715. ec);
  716. m_pFaxServer->Disconnect();
  717. }
  718. goto Error;
  719. }
  720. ATLASSERT(m_pFaxGroupsConfig);
  721. ATLASSERT(S_OK == hRc);
  722. DebugPrintEx( DEBUG_MSG,
  723. _T("Succeed to get all configurations."));
  724. goto Exit;
  725. Error:
  726. ATLASSERT(ERROR_SUCCESS != ec);
  727. hRc = HRESULT_FROM_WIN32(ec);
  728. //MsgBox will be done by calling Func.
  729. Exit:
  730. return hRc;
  731. }
  732. /*
  733. - CDlgNewFaxOutboundRule::OnSelectCountryCodeClicked
  734. -
  735. * Purpose:
  736. *
  737. *
  738. * Arguments:
  739. * [out] bHandled - Do we handle it?
  740. * [in] pRoot - The root node
  741. *
  742. * Return:
  743. * OLE Error code
  744. */
  745. LRESULT
  746. CDlgNewFaxOutboundRule::OnSelectCountryCodeClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  747. {
  748. DEBUG_FUNCTION_NAME( _T("CDlgNewFaxOutboundRule::OnSelectCountryCodeClicked"));
  749. HRESULT hRc = S_OK;
  750. INT_PTR rc = IDOK;
  751. int iCount = 0;
  752. WCHAR szwCountryCode[FXS_MAX_COUNTRYCODE_LEN+1];
  753. DWORD dwCountryCode = 0;
  754. CDlgSelectCountry DlgSelectCountry(m_pFaxServer);
  755. hRc = DlgSelectCountry.InitSelectCountryCodeDlg();
  756. if (S_OK != hRc)
  757. {
  758. //MsgBox + debug print by called func.
  759. goto Cleanup;
  760. }
  761. //
  762. // Dialog select country code
  763. //
  764. rc = DlgSelectCountry.DoModal();
  765. if (rc != IDOK)
  766. {
  767. goto Cleanup;
  768. }
  769. //
  770. // Retreive CountryCode
  771. //
  772. dwCountryCode = DlgSelectCountry.GetCountryCode();
  773. iCount = swprintf(szwCountryCode, L"%ld", dwCountryCode);
  774. if( iCount <= 0 )
  775. {
  776. DebugPrintEx(
  777. DEBUG_ERR,
  778. TEXT("Fail to read member - m_dwCountryCode."));
  779. goto Cleanup;
  780. }
  781. m_CountryCodeEdit.SetWindowText(szwCountryCode);
  782. //
  783. // EnableOK
  784. //
  785. if (!m_fAllReadyToApply)
  786. {
  787. if (AllReadyToApply(TRUE))
  788. {
  789. m_fAllReadyToApply = TRUE;
  790. EnableOK(TRUE);
  791. }
  792. else
  793. {
  794. //Should be EnableOK(FALSE);
  795. }
  796. }
  797. Cleanup:
  798. return hRc;
  799. }
  800. //////////////////////////////////////////////////////////////////////////////
  801. /*++
  802. CDlgNewFaxOutboundRule::OnHelpRequest
  803. This is called in response to the WM_HELP Notify
  804. message and to the WM_CONTEXTMENU Notify message.
  805. WM_HELP Notify message.
  806. This message is sent when the user presses F1 or <Shift>-F1
  807. over an item or when the user clicks on the ? icon and then
  808. presses the mouse over an item.
  809. WM_CONTEXTMENU Notify message.
  810. This message is sent when the user right clicks over an item
  811. and then clicks "What's this?"
  812. --*/
  813. /////////////////////////////////////////////////////////////////////////////
  814. LRESULT
  815. CDlgNewFaxOutboundRule::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  816. {
  817. DEBUG_FUNCTION_NAME(_T("CDlgNewFaxOutboundRule::OnHelpRequest"));
  818. switch (uMsg)
  819. {
  820. case WM_HELP:
  821. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  822. break;
  823. case WM_CONTEXTMENU:
  824. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  825. break;
  826. }
  827. return TRUE;
  828. }
  829. /////////////////////////////////////////////////////////////////////////////