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.

991 lines
25 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : ppFaxDeviceGeneral.cpp //
  3. // //
  4. // DESCRIPTION : prop pages of Inbox archive //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Oct 17 2000 yossg //
  10. // Windows XP //
  11. // Feb 14 2001 yossg Add Manual Receive support //
  12. // //
  13. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  14. // //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "stdafx.h"
  17. #include "MSFxsSnp.h"
  18. #include "ppFaxDeviceGeneral.h"
  19. #include "Device.h"
  20. #include "FaxServer.h"
  21. #include "FaxServerNode.h"
  22. #include "FaxMMCPropertyChange.h"
  23. #include "FaxMMCGlobals.h"
  24. #include "FxsValid.h"
  25. #include "dlgutils.h"
  26. #include <faxres.h>
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. //
  32. // Constructor
  33. //
  34. CppFaxDeviceGeneral::CppFaxDeviceGeneral(
  35. LONG_PTR hNotificationHandle,
  36. CSnapInItem *pNode,
  37. CSnapInItem *pParentNode,
  38. DWORD dwDeviceID,
  39. HINSTANCE hInst)
  40. : CPropertyPageExImpl<CppFaxDeviceGeneral>(pNode, NULL)
  41. {
  42. m_lpNotifyHandle = hNotificationHandle;
  43. m_pParentNode = NULL; //in case static-cast failed and wont change the pointer
  44. m_pParentNode = static_cast <CFaxDeviceNode *> (pNode);
  45. m_pGrandParentNode = pParentNode;
  46. m_dwDeviceID = dwDeviceID;
  47. m_pFaxDeviceConfig = NULL;
  48. m_fAllReadyToApply = FALSE;
  49. m_fIsDialogInitiated = FALSE;
  50. }
  51. //
  52. // Destructor
  53. //
  54. CppFaxDeviceGeneral::~CppFaxDeviceGeneral()
  55. {
  56. if (NULL != m_pFaxDeviceConfig)
  57. {
  58. FaxFreeBuffer( m_pFaxDeviceConfig );
  59. }
  60. // Note - This needs to be called only once per property sheet.
  61. // In our convention called in the general tab.
  62. if (NULL != m_lpNotifyHandle)
  63. {
  64. MMCFreeNotifyHandle(m_lpNotifyHandle);
  65. m_lpNotifyHandle = NULL;
  66. }
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CppFaxDeviceGeneral message handlers
  70. /*
  71. - CppFaxDeviceGeneral::InitRPC
  72. -
  73. * Purpose:
  74. * Initiates the configuration structure from RPC get Call.
  75. *
  76. * Arguments:
  77. *
  78. * Return:
  79. * OLE error code
  80. */
  81. HRESULT CppFaxDeviceGeneral::InitRPC( )
  82. {
  83. DEBUG_FUNCTION_NAME( _T("CppFaxDeviceGeneral::InitRPC"));
  84. HRESULT hRc = S_OK;
  85. DWORD ec = ERROR_SUCCESS;
  86. //
  87. // get RPC Handle
  88. //
  89. if (!m_pFaxServer->GetFaxServerHandle())
  90. {
  91. ec= GetLastError();
  92. DebugPrintEx(
  93. DEBUG_ERR,
  94. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  95. ec);
  96. goto Error;
  97. }
  98. //
  99. // Retrieve the Device configuration
  100. //
  101. if (!FaxGetPortEx(m_pFaxServer->GetFaxServerHandle(),
  102. m_dwDeviceID,
  103. &m_pFaxDeviceConfig))
  104. {
  105. ec = GetLastError();
  106. DebugPrintEx(
  107. DEBUG_ERR,
  108. _T("Fail to get device configuration. (ec: %ld)"),
  109. ec);
  110. if (IsNetworkError(ec))
  111. {
  112. DebugPrintEx(
  113. DEBUG_ERR,
  114. _T("Network Error was found. (ec: %ld)"),
  115. ec);
  116. m_pFaxServer->Disconnect();
  117. }
  118. goto Error;
  119. }
  120. //For max verification
  121. ATLASSERT(m_pFaxDeviceConfig);
  122. ATLASSERT(S_OK == hRc);
  123. DebugPrintEx( DEBUG_MSG,
  124. _T("Succeed to get device configuration."));
  125. goto Exit;
  126. Error:
  127. ATLASSERT(ERROR_SUCCESS != ec);
  128. hRc = HRESULT_FROM_WIN32(ec);
  129. PageError(GetFaxServerErrorMsg(ec), m_hWnd);
  130. Exit:
  131. return (hRc);
  132. }
  133. /*
  134. - CppFaxDeviceGeneral::OnInitDialog
  135. -
  136. * Purpose:
  137. * Initiates all controls when dialog is called.
  138. *
  139. * Arguments:
  140. *
  141. * Return:
  142. *
  143. */
  144. LRESULT CppFaxDeviceGeneral::OnInitDialog( UINT uiMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled )
  145. {
  146. DEBUG_FUNCTION_NAME( _T("CppFaxDeviceGeneral::PageInitDialog"));
  147. DWORD ec = ERROR_SUCCESS;
  148. UNREFERENCED_PARAMETER( uiMsg );
  149. UNREFERENCED_PARAMETER( wParam );
  150. UNREFERENCED_PARAMETER( lParam );
  151. UNREFERENCED_PARAMETER( fHandled );
  152. //
  153. // init controls
  154. //
  155. m_DescriptionBox.Attach(GetDlgItem(IDC_DEVICE_DESCRIPTION_EDIT));
  156. m_TSIDBox.Attach(GetDlgItem(IDC_DEVICE_TSID_EDIT));
  157. m_CSIDBox.Attach(GetDlgItem(IDC_DEVICE_CSID_EDIT));
  158. m_RingsBox.Attach(GetDlgItem(IDC_DEVICE_RINGS_EDIT));
  159. m_RingsSpin.Attach(GetDlgItem(IDC_DEVICE_RINGS_SPIN));
  160. m_DescriptionBox.SetLimitText(MAX_FAX_STRING_LEN-1);
  161. m_TSIDBox.SetLimitText(FXS_TSID_CSID_MAX_LENGTH);
  162. m_CSIDBox.SetLimitText(FXS_TSID_CSID_MAX_LENGTH);
  163. m_RingsBox.SetLimitText(FXS_RINGS_LENGTH);
  164. ATLASSERT(m_pFaxDeviceConfig);
  165. //
  166. // Description
  167. //
  168. m_DescriptionBox.SetWindowText(m_pFaxDeviceConfig->lptstrDescription);
  169. //
  170. // Rings
  171. //
  172. m_RingsSpin.SetRange(FXS_RINGS_LOWER, FXS_RINGS_UPPER);
  173. m_RingsSpin.SetPos((int)m_pFaxDeviceConfig->dwRings);
  174. //
  175. // CSID
  176. //
  177. m_CSIDBox.SetWindowText(m_pFaxDeviceConfig->lptstrCsid);
  178. //
  179. // Receive
  180. //
  181. switch ( m_pFaxDeviceConfig->ReceiveMode )
  182. {
  183. case FAX_DEVICE_RECEIVE_MODE_OFF: // Do not answer to incoming calls
  184. CheckDlgButton(IDC_RECEIVE_CHECK, BST_UNCHECKED);
  185. CheckDlgButton(IDC_RECEIVE_AUTO_RADIO1, BST_CHECKED);
  186. EnableReceiveControls (FALSE);
  187. break;
  188. case FAX_DEVICE_RECEIVE_MODE_AUTO: // Automatically answer to incoming calls after dwRings rings
  189. CheckDlgButton(IDC_RECEIVE_CHECK, BST_CHECKED);
  190. CheckDlgButton(IDC_RECEIVE_AUTO_RADIO1, BST_CHECKED);
  191. EnableRingsControls (TRUE);
  192. break;
  193. case FAX_DEVICE_RECEIVE_MODE_MANUAL: // Manually answer to incoming calls - only FaxAnswerCall answers the call
  194. CheckDlgButton(IDC_RECEIVE_CHECK, BST_CHECKED);
  195. CheckDlgButton(IDC_RECEIVE_MANUAL_RADIO2, BST_CHECKED);
  196. EnableRingsControls (FALSE);
  197. break;
  198. default:
  199. ATLASSERT(FALSE);
  200. DebugPrintEx(
  201. DEBUG_ERR,
  202. TEXT("Unexpected m_pFaxDeviceConfig->ReceiveMode"));
  203. }
  204. if(m_pFaxServer->GetServerAPIVersion() == FAX_API_VERSION_0)
  205. {
  206. //
  207. // The remote fax server is SBS/BOS 2000
  208. // is does not support manual answering
  209. //
  210. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_RECEIVE_MANUAL_RADIO2), FALSE);
  211. ATLASSERT(IsDlgButtonChecked(IDC_RECEIVE_MANUAL_RADIO2) != BST_CHECKED);
  212. }
  213. //
  214. // TSID
  215. //
  216. m_TSIDBox.SetWindowText(m_pFaxDeviceConfig->lptstrTsid);
  217. //
  218. // Send
  219. //
  220. if (m_pFaxDeviceConfig->bSend)
  221. {
  222. CheckDlgButton(IDC_SEND_CHECK, BST_CHECKED) ;
  223. }
  224. else
  225. {
  226. CheckDlgButton(IDC_SEND_CHECK, BST_UNCHECKED) ;
  227. ::EnableWindow(GetDlgItem(IDC_DEVICE_TSID_EDIT), FALSE);
  228. }
  229. m_fIsDialogInitiated = TRUE;
  230. return (1);
  231. }
  232. /*
  233. - CppFaxDeviceGeneral::SetProps
  234. -
  235. * Purpose:
  236. * Sets properties on apply.
  237. *
  238. * Arguments:
  239. * pCtrlFocus - focus pointer (int)
  240. *
  241. * Return:
  242. * OLE error code
  243. */
  244. HRESULT CppFaxDeviceGeneral::SetProps(int *pCtrlFocus)
  245. {
  246. DEBUG_FUNCTION_NAME( _T("CppFaxDeviceGeneral::SetProps"));
  247. HRESULT hRc = S_OK;
  248. DWORD ec = ERROR_SUCCESS;
  249. HINSTANCE hInst = _Module.GetResourceInstance();
  250. CComBSTR bstrDescription = L"";
  251. CComBSTR bstrCSID = L"";
  252. CComBSTR bstrTSID = L"";
  253. FAX_PORT_INFO_EX FaxDeviceConfig;
  254. ATLASSERT(m_dwDeviceID == m_pFaxDeviceConfig->dwDeviceID);
  255. CFaxDevicePropertyChangeNotification * pDevicePropPageNotification = NULL;
  256. ATLASSERT(TRUE == m_fAllReadyToApply);
  257. m_fAllReadyToApply = FALSE;
  258. //
  259. // Step 1: Collect all data and init the structure's fields
  260. // uses Copy() to copy and also allocate before
  261. //
  262. ZeroMemory (&FaxDeviceConfig, sizeof(FAX_PORT_INFO_EX));
  263. FaxDeviceConfig.dwSizeOfStruct = sizeof(FAX_PORT_INFO_EX);
  264. FaxDeviceConfig.dwDeviceID = m_dwDeviceID;
  265. FaxDeviceConfig.lpctstrDeviceName = m_pFaxDeviceConfig->lpctstrDeviceName;
  266. FaxDeviceConfig.lpctstrProviderName = m_pFaxDeviceConfig->lpctstrProviderName;
  267. FaxDeviceConfig.lpctstrProviderGUID = m_pFaxDeviceConfig->lpctstrProviderGUID;
  268. //
  269. // Description
  270. //
  271. if ( !m_DescriptionBox.GetWindowText(&bstrDescription))
  272. {
  273. *pCtrlFocus = IDC_DEVICE_DESCRIPTION_EDIT;
  274. DebugPrintEx(
  275. DEBUG_ERR,
  276. TEXT("Failed to GetWindowText(&bstrDescription)"));
  277. ec = ERROR_OUTOFMEMORY;
  278. goto Error;
  279. }
  280. // We allow empty description string!
  281. FaxDeviceConfig.lptstrDescription = bstrDescription;
  282. //
  283. // Receive
  284. //
  285. if (IsDlgButtonChecked(IDC_RECEIVE_CHECK) == BST_CHECKED)
  286. {
  287. if (IsDlgButtonChecked(IDC_RECEIVE_AUTO_RADIO1) == BST_CHECKED)
  288. {
  289. FaxDeviceConfig.ReceiveMode = FAX_DEVICE_RECEIVE_MODE_AUTO;
  290. //
  291. // new Rings
  292. //
  293. FaxDeviceConfig.dwRings = (DWORD)m_RingsSpin.GetPos();
  294. }
  295. else //(IDC_RECEIVE_MANUAL_RADIO2) == BST_CHECKED)
  296. {
  297. FaxDeviceConfig.ReceiveMode = FAX_DEVICE_RECEIVE_MODE_MANUAL;
  298. //
  299. // Rings and CSID stay as is
  300. //
  301. FaxDeviceConfig.dwRings = m_pFaxDeviceConfig->dwRings;
  302. }
  303. //
  304. // new CSID
  305. //
  306. if ( !m_CSIDBox.GetWindowText(&bstrCSID))
  307. {
  308. *pCtrlFocus = IDC_DEVICE_CSID_EDIT;
  309. DebugPrintEx(
  310. DEBUG_ERR,
  311. TEXT("Failed to GetWindowText(&bstrCSID)"));
  312. ec = ERROR_OUTOFMEMORY;
  313. goto Error;
  314. }
  315. //We allow empty CSID.
  316. FaxDeviceConfig.lptstrCsid = bstrCSID;
  317. }
  318. else
  319. {
  320. FaxDeviceConfig.ReceiveMode = FAX_DEVICE_RECEIVE_MODE_OFF;
  321. //
  322. // Rings and CSID stay as is
  323. //
  324. FaxDeviceConfig.dwRings = m_pFaxDeviceConfig->dwRings;
  325. FaxDeviceConfig.lptstrCsid = m_pFaxDeviceConfig->lptstrCsid;
  326. }
  327. //
  328. // Send
  329. //
  330. if (IsDlgButtonChecked(IDC_SEND_CHECK) == BST_CHECKED)
  331. {
  332. FaxDeviceConfig.bSend = TRUE;
  333. //
  334. // new TSID
  335. //
  336. if ( !m_TSIDBox.GetWindowText(&bstrTSID))
  337. {
  338. *pCtrlFocus = IDC_DEVICE_TSID_EDIT;
  339. DebugPrintEx(
  340. DEBUG_ERR,
  341. TEXT("Failed to GetWindowText(&bstrTSID)"));
  342. ec = ERROR_OUTOFMEMORY;
  343. goto Error;
  344. }
  345. //we allow empty TSID!
  346. FaxDeviceConfig.lptstrTsid = bstrTSID;
  347. }
  348. else
  349. {
  350. FaxDeviceConfig.bSend = FALSE;
  351. //
  352. // TSID stay as is
  353. //
  354. FaxDeviceConfig.lptstrTsid = m_pFaxDeviceConfig->lptstrTsid;
  355. }
  356. //
  357. // Step 2: Set data via RPC
  358. //
  359. //
  360. // get RPC Handle
  361. //
  362. if (!m_pFaxServer->GetFaxServerHandle())
  363. {
  364. ec= GetLastError();
  365. DebugPrintEx(
  366. DEBUG_ERR,
  367. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  368. ec);
  369. goto Error;
  370. }
  371. //
  372. // Set Config
  373. //
  374. if (!FaxSetPortEx(
  375. m_pFaxServer->GetFaxServerHandle(),
  376. m_dwDeviceID,
  377. &FaxDeviceConfig))
  378. {
  379. ec = GetLastError();
  380. DebugPrintEx(
  381. DEBUG_ERR,
  382. _T("Fail to Set device configuration. (ec: %ld)"),
  383. ec);
  384. if ( FAX_ERR_DEVICE_NUM_LIMIT_EXCEEDED == ec )
  385. {
  386. hRc = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  387. DlgMsgBox(this, IDS_ERR_ADMIN_DEVICE_LIMIT, MB_OK|MB_ICONEXCLAMATION);
  388. goto Exit;
  389. }
  390. if (IsNetworkError(ec))
  391. {
  392. DebugPrintEx(
  393. DEBUG_ERR,
  394. _T("Network Error was found. (ec: %ld)"),
  395. ec);
  396. m_pFaxServer->Disconnect();
  397. }
  398. goto Error;
  399. }
  400. DebugPrintEx( DEBUG_MSG,
  401. _T("Succeed to set device configuration."));
  402. //
  403. // Step 3: Update MMC
  404. //
  405. //
  406. // Prepare the notification fields before submit
  407. //
  408. pDevicePropPageNotification = new CFaxDevicePropertyChangeNotification();
  409. if (!pDevicePropPageNotification)
  410. {
  411. ec = ERROR_NOT_ENOUGH_MEMORY;
  412. DebugPrintEx(
  413. DEBUG_ERR,
  414. _T("Out of Memory - fail to operate new for CFaxDevicePropertyChangeNotification"));
  415. goto Error;
  416. }
  417. pDevicePropPageNotification->dwDeviceID = m_dwDeviceID;
  418. //
  419. // We have decided that we'll refresh all devices on a
  420. // manual receive enabling. If it gets FALSE, just the single device is refreshed.
  421. //
  422. pDevicePropPageNotification->fIsToNotifyAdditionalDevices =
  423. ( (FAX_DEVICE_RECEIVE_MODE_MANUAL == FaxDeviceConfig.ReceiveMode) ? TRUE : FALSE );
  424. pDevicePropPageNotification->pItem = m_pGrandParentNode;
  425. pDevicePropPageNotification->enumType = DeviceFaxPropNotification;
  426. //
  427. // Send notification from the property sheet thread to the main MMC thread
  428. //
  429. hRc = MMCPropertyChangeNotify(m_lpNotifyHandle, reinterpret_cast<LPARAM>(pDevicePropPageNotification));
  430. if (FAILED(hRc))
  431. {
  432. DebugPrintEx(
  433. DEBUG_ERR,
  434. _T("Fail to call MMCPropertyChangeNotify. (hRc: %08X)"),
  435. hRc);
  436. PageError(IDS_FAIL_NOTIFY_MMCPROPCHANGE,m_hWnd);
  437. goto Exit;
  438. }
  439. //
  440. // To prevent deletion on error since it will be deleted
  441. // by the reciever of the notification.
  442. //
  443. pDevicePropPageNotification = NULL;
  444. ATLASSERT(S_OK == hRc);
  445. goto Exit;
  446. Error:
  447. ATLASSERT(ERROR_SUCCESS != ec);
  448. hRc = HRESULT_FROM_WIN32(ec);
  449. PropSheet_SetCurSelByID( GetParent(), IDD);
  450. ATLASSERT(::IsWindow(m_hWnd));
  451. PageError(GetFaxServerErrorMsg(ec),m_hWnd);
  452. Exit:
  453. return(hRc);
  454. }
  455. /*
  456. - CppFaxDeviceGeneral::PreApply
  457. -
  458. * Purpose:
  459. * Checks properties before apply.
  460. *
  461. * Arguments:
  462. *
  463. * Return:
  464. * OLE error code
  465. */
  466. HRESULT CppFaxDeviceGeneral::PreApply(int *pCtrlFocus)
  467. {
  468. HRESULT hRc = S_OK;
  469. //
  470. // PreApply Checks
  471. //
  472. if (!AllReadyToApply(/*fSilent =*/ FALSE))
  473. {
  474. m_fAllReadyToApply = FALSE;
  475. SetModified(FALSE);
  476. hRc = E_FAIL ;
  477. }
  478. else
  479. {
  480. m_fAllReadyToApply = TRUE;
  481. SetModified(TRUE);
  482. }
  483. return(hRc);
  484. }
  485. /*
  486. - CppFaxDeviceGeneral::OnApply
  487. -
  488. * Purpose:
  489. * Calls PreApply and SetProp to Apply changes.
  490. *
  491. * Arguments:
  492. *
  493. * Return:
  494. * TRUE or FALSE
  495. */
  496. BOOL CppFaxDeviceGeneral::OnApply()
  497. {
  498. DEBUG_FUNCTION_NAME( _T("CppFaxDeviceGeneral::OnApply"));
  499. HRESULT hRc = S_OK;
  500. int CtrlFocus = 0;
  501. hRc = PreApply(&CtrlFocus);
  502. if (FAILED(hRc))
  503. {
  504. //Error Msg by called func.
  505. if (CtrlFocus)
  506. {
  507. GotoDlgCtrl(GetDlgItem(CtrlFocus));
  508. }
  509. return FALSE;
  510. }
  511. else //(Succeeded(hRc))
  512. {
  513. hRc = SetProps(&CtrlFocus);
  514. if (FAILED(hRc))
  515. {
  516. //Error Msg by called func.
  517. if (CtrlFocus)
  518. {
  519. GotoDlgCtrl(GetDlgItem(CtrlFocus));
  520. }
  521. return FALSE;
  522. }
  523. else //(Succeeded(hRc))
  524. {
  525. return TRUE;
  526. }
  527. }
  528. }
  529. /*
  530. - CppFaxDeviceGeneral::OnReceiveCheckboxClicked
  531. -
  532. * Purpose:
  533. * Gray/Ungray the sub controls
  534. * Enable apply button.
  535. *
  536. * Arguments:
  537. *
  538. * Return:
  539. * 1
  540. */
  541. LRESULT CppFaxDeviceGeneral::OnReceiveCheckboxClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  542. {
  543. DEBUG_FUNCTION_NAME( _T("CppFaxDeviceGeneral::OnReceiveCheckboxClicked"));
  544. BOOL State;
  545. if (!m_fIsDialogInitiated) //event receieved in too early stage
  546. {
  547. return 0;
  548. }
  549. State = ( IsDlgButtonChecked(IDC_RECEIVE_CHECK) == BST_CHECKED );
  550. EnableReceiveControls(State);
  551. if (m_fAllReadyToApply)//only last change should be considered
  552. {
  553. if ( !m_RingsBox.GetWindowTextLength() )
  554. {
  555. m_fAllReadyToApply = FALSE;
  556. SetModified(FALSE);
  557. }
  558. else
  559. {
  560. SetModified(TRUE);
  561. }
  562. }
  563. else //m_fAllReadyToApply == FALSE
  564. {
  565. if (AllReadyToApply(TRUE))
  566. {
  567. m_fAllReadyToApply = TRUE;
  568. SetModified(TRUE);
  569. }
  570. else
  571. {
  572. SetModified(FALSE);
  573. }
  574. }
  575. return 1;
  576. }
  577. /*
  578. - CppFaxDeviceGeneral::OnReceiveRadioButtonClicked
  579. -
  580. * Purpose:
  581. * Check status OnReceiveRadioButtonClicked
  582. *
  583. * Arguments:
  584. *
  585. * Return:
  586. * 1
  587. */
  588. LRESULT
  589. CppFaxDeviceGeneral::OnReceiveRadioButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  590. {
  591. UNREFERENCED_PARAMETER (wNotifyCode);
  592. UNREFERENCED_PARAMETER (wID);
  593. UNREFERENCED_PARAMETER (hWndCtl);
  594. UNREFERENCED_PARAMETER (bHandled);
  595. DEBUG_FUNCTION_NAME( _T("CppFaxDeviceGeneral::OnReceiveRadioButtonClicked"));
  596. if ( IsDlgButtonChecked(IDC_RECEIVE_AUTO_RADIO1) == BST_CHECKED )
  597. {
  598. EnableRingsControls(TRUE);
  599. ::SetFocus(GetDlgItem(IDC_DEVICE_RINGS_EDIT));
  600. }
  601. else //IDC_RECEIVE_MANUAL_RADIO2
  602. {
  603. EnableRingsControls(FALSE);
  604. }
  605. if (m_fAllReadyToApply)//only last change should be considered
  606. {
  607. if (
  608. ( IsDlgButtonChecked(IDC_RECEIVE_AUTO_RADIO1) == BST_CHECKED )
  609. &&
  610. (!m_RingsBox.GetWindowTextLength() )
  611. )
  612. {
  613. m_fAllReadyToApply = FALSE;
  614. SetModified(FALSE);
  615. }
  616. else
  617. {
  618. SetModified(TRUE);
  619. }
  620. }
  621. else //m_fAllReadyToApply == FALSE
  622. {
  623. if (AllReadyToApply(TRUE))
  624. {
  625. m_fAllReadyToApply = TRUE;
  626. SetModified(TRUE);
  627. }
  628. else
  629. {
  630. SetModified(FALSE);
  631. }
  632. }
  633. return 1;
  634. }
  635. /*
  636. + CppFaxDeviceGeneral::OnSendCheckboxClicked
  637. +
  638. * Purpose:
  639. * Gray/Ungray sub copntrols
  640. * Enable apply button.
  641. *
  642. * Arguments:
  643. *
  644. * Return:
  645. - 1
  646. -
  647. */
  648. LRESULT CppFaxDeviceGeneral::OnSendCheckboxClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  649. {
  650. DEBUG_FUNCTION_NAME( _T("CppFaxDeviceGeneral::OnSendCheckboxClicked"));
  651. BOOL State;
  652. if (!m_fIsDialogInitiated) //event receieved in too early stage
  653. {
  654. return 0;
  655. }
  656. State = ( IsDlgButtonChecked(IDC_SEND_CHECK) == BST_CHECKED );
  657. ::EnableWindow(GetDlgItem(IDC_DEVICE_TSID_EDIT), State);
  658. ::EnableWindow(GetDlgItem(IDC_TSID_STATIC), State);
  659. if (AllReadyToApply(TRUE))
  660. {
  661. m_fAllReadyToApply = TRUE;
  662. SetModified(TRUE);
  663. }
  664. else
  665. {
  666. m_fAllReadyToApply = FALSE;
  667. SetModified(FALSE);
  668. }
  669. //this is due to the fact that we allow empty CSID
  670. return 1;
  671. }
  672. /*
  673. - CppFaxDeviceGeneral::DeviceTextChanged
  674. -
  675. * Purpose:
  676. * set Apply buttom modified.
  677. *
  678. * Arguments:
  679. *
  680. * Return:
  681. * 1
  682. */
  683. LRESULT CppFaxDeviceGeneral::DeviceTextChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  684. {
  685. if (AllReadyToApply(TRUE))
  686. {
  687. m_fAllReadyToApply = TRUE;
  688. SetModified(TRUE);
  689. }
  690. else
  691. {
  692. m_fAllReadyToApply = FALSE;
  693. SetModified(FALSE);
  694. }
  695. return(1);
  696. }
  697. /*
  698. + CppFaxDeviceGeneral::AllReadyToApply
  699. +
  700. * Purpose:
  701. * This function validate that no zero length strings
  702. * are found data areas that should be saved.
  703. *
  704. * Arguments:
  705. * [in] fSilent - boolean who defines if to pop up messages (FALSE)
  706. * or not.(TRUE)
  707. *
  708. * Return:
  709. - BOOOLEAN
  710. -
  711. */
  712. BOOL CppFaxDeviceGeneral::AllReadyToApply(BOOL fSilent)
  713. {
  714. DEBUG_FUNCTION_NAME( _T("CppFaxDeviceGeneral::AllReadyToApply"));
  715. DWORD ec = ERROR_SUCCESS;
  716. HINSTANCE hInst = _Module.GetResourceInstance();
  717. if (
  718. (IsDlgButtonChecked(IDC_RECEIVE_CHECK) == BST_CHECKED)
  719. &&
  720. (IsDlgButtonChecked(IDC_RECEIVE_AUTO_RADIO1) == BST_CHECKED)
  721. )
  722. {
  723. if ( !m_RingsBox.GetWindowTextLength() )
  724. {
  725. ec = GetLastError();
  726. DebugPrintEx(
  727. DEBUG_ERR,
  728. _T("Zero text length - m_RingsBox. (ec: %ld)"),
  729. ec);
  730. if (!fSilent)
  731. {
  732. PageError(IDS_DEVICE_RINGS_EMPTY, m_hWnd, hInst);
  733. ::SetFocus(GetDlgItem(IDC_DEVICE_RINGS_EDIT));
  734. }
  735. return FALSE;
  736. }
  737. }
  738. //we allow empty tsid
  739. //we allow empty csid
  740. //we allow empty description
  741. ATLASSERT(ERROR_SUCCESS == ec);
  742. //
  743. // Cheers!
  744. // ...every thing ready to apply now.
  745. //
  746. return TRUE;
  747. }
  748. /*
  749. - CppFaxDeviceGeneral::EnableRingsControls
  750. -
  751. * Purpose:
  752. * Enable/disable the Rings controls.
  753. *
  754. * Arguments:
  755. * [in] state - boolean value to enable TRUE or FALSE to disable
  756. *
  757. * Return:
  758. * void
  759. */
  760. void CppFaxDeviceGeneral::EnableRingsControls(BOOL fState)
  761. {
  762. //
  763. // enable/disable controls
  764. //
  765. ::EnableWindow(GetDlgItem(IDC_DEVICE_RINGS_EDIT), fState);
  766. ::EnableWindow(GetDlgItem(IDC_DEVICE_RINGS_SPIN), fState);
  767. ::EnableWindow(GetDlgItem(IDC_DEVICE_RINGS_STATIC), fState);
  768. }
  769. /*
  770. - CppFaxDeviceGeneral::EnableReceiveControls
  771. -
  772. * Purpose:
  773. * Enable/disable the Rings controls.
  774. *
  775. * Arguments:
  776. * [in] state - boolean value to enable TRUE or FALSE to disable
  777. *
  778. * Return:
  779. * void
  780. */
  781. void CppFaxDeviceGeneral::EnableReceiveControls(BOOL fState)
  782. {
  783. //
  784. // enable/disable controls
  785. //
  786. if(m_pFaxServer->GetServerAPIVersion() == CURRENT_FAX_API_VERSION)
  787. {
  788. ::EnableWindow(GetDlgItem(IDC_RECEIVE_MANUAL_RADIO2), fState);
  789. }
  790. ::EnableWindow(GetDlgItem(IDC_RECEIVE_AUTO_RADIO1), fState);
  791. ::EnableWindow(GetDlgItem(IDC_DEVICE_CSID_EDIT), fState);
  792. ::EnableWindow(GetDlgItem(IDC_CSID_STATIC), fState);
  793. //
  794. // Combined state
  795. //
  796. fState = fState && (IsDlgButtonChecked(IDC_RECEIVE_AUTO_RADIO1) == BST_CHECKED);
  797. EnableRingsControls(fState);
  798. }
  799. //////////////////////////////////////////////////////////////////////////////
  800. /*++
  801. CppFaxDeviceGeneral::OnHelpRequest
  802. This is called in response to the WM_HELP Notify
  803. message and to the WM_CONTEXTMENU Notify message.
  804. WM_HELP Notify message.
  805. This message is sent when the user presses F1 or <Shift>-F1
  806. over an item or when the user clicks on the ? icon and then
  807. presses the mouse over an item.
  808. WM_CONTEXTMENU Notify message.
  809. This message is sent when the user right clicks over an item
  810. and then clicks "What's this?"
  811. --*/
  812. /////////////////////////////////////////////////////////////////////////////
  813. LRESULT
  814. CppFaxDeviceGeneral::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  815. {
  816. DEBUG_FUNCTION_NAME(_T("CppFaxDeviceGeneral::OnHelpRequest"));
  817. switch (uMsg)
  818. {
  819. case WM_HELP:
  820. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  821. break;
  822. case WM_CONTEXTMENU:
  823. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  824. break;
  825. }
  826. return TRUE;
  827. }
  828. /////////////////////////////////////////////////////////////////////////////