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.

1209 lines
32 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : ppFaxServerInbox.cpp //
  3. // //
  4. // DESCRIPTION : prop pages of Inbox archive //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Oct 25 1999 yossg created //
  10. // Nov 3 1999 yossg OnInitDialog, SetProps //
  11. // Nov 15 1999 yossg Call RPC func //
  12. // Nov 24 1999 yossg OnApply create call to all tabs from parent //
  13. // Oct 17 2000 yossg //
  14. // Dec 10 2000 yossg Update Windows XP //
  15. // //
  16. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  17. // //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "MSFxsSnp.h"
  21. #include "ppFaxServerInbox.h"
  22. #include "FaxMMCGlobals.h"
  23. #include "FaxServer.h"
  24. #include "FaxServerNode.h"
  25. #include "FxsValid.h"
  26. #include "dlgutils.h"
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. //
  32. // Constructor
  33. //
  34. CppFaxServerInbox::CppFaxServerInbox(
  35. LONG_PTR hNotificationHandle,
  36. CSnapInItem *pNode,
  37. BOOL fIsLocalServer,
  38. HINSTANCE hInst)
  39. : CPropertyPageExImpl<CppFaxServerInbox>(pNode, NULL)
  40. {
  41. m_pParentNode = static_cast <CFaxServerNode *> (pNode);
  42. m_pFaxArchiveConfig = NULL;
  43. m_fAllReadyToApply = FALSE;
  44. m_fIsDialogInitiated = FALSE;
  45. m_fIsDirty = FALSE;
  46. m_fIsLocalServer = fIsLocalServer;
  47. }
  48. //
  49. // Destructor
  50. //
  51. CppFaxServerInbox::~CppFaxServerInbox()
  52. {
  53. if (NULL != m_pFaxArchiveConfig)
  54. {
  55. FaxFreeBuffer( m_pFaxArchiveConfig );
  56. }
  57. }
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CppFaxServerInbox message handlers
  60. /*
  61. - CppFaxServerInbox::InitRPC
  62. -
  63. * Purpose:
  64. * Initiates the configuration structure from RPC get Call.
  65. *
  66. * Arguments:
  67. *
  68. * Return:
  69. * OLE error code
  70. */
  71. HRESULT CppFaxServerInbox::InitRPC( )
  72. {
  73. DEBUG_FUNCTION_NAME( _T("CppFaxServerInbox::InitRPC"));
  74. HRESULT hRc = S_OK;
  75. DWORD ec = ERROR_SUCCESS;
  76. //
  77. // get RPC Handle
  78. //
  79. if (!m_pFaxServer->GetFaxServerHandle())
  80. {
  81. ec= GetLastError();
  82. DebugPrintEx(
  83. DEBUG_ERR,
  84. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  85. ec);
  86. goto Error;
  87. }
  88. //
  89. // Retrieve the fax Archive configuration
  90. //
  91. if (!FaxGetArchiveConfiguration(m_pFaxServer->GetFaxServerHandle(),
  92. FAX_MESSAGE_FOLDER_INBOX,
  93. &m_pFaxArchiveConfig))
  94. {
  95. ec = GetLastError();
  96. DebugPrintEx(
  97. DEBUG_ERR,
  98. _T("Fail to get inbox configuration. (ec: %ld)"),
  99. ec);
  100. if (IsNetworkError(ec))
  101. {
  102. DebugPrintEx(
  103. DEBUG_ERR,
  104. _T("Network Error was found. (ec: %ld)"),
  105. ec);
  106. m_pFaxServer->Disconnect();
  107. }
  108. goto Error;
  109. }
  110. //For max verification
  111. ATLASSERT(m_pFaxArchiveConfig);
  112. //
  113. // Init specific members for set proprties follow-up
  114. //
  115. m_dwLastGoodSizeQuotaHighWatermark = m_pFaxArchiveConfig->dwSizeQuotaHighWatermark;
  116. m_dwLastGoodSizeQuotaLowWatermark = m_pFaxArchiveConfig->dwSizeQuotaLowWatermark;
  117. m_bstrLastGoodFolder = m_pFaxArchiveConfig->lpcstrFolder;
  118. if (!m_bstrLastGoodFolder)
  119. {
  120. DebugPrintEx(
  121. DEBUG_ERR,
  122. TEXT("Failed to allocate string (m_bstrLastGoodFolder)."));
  123. ec = ERROR_OUTOFMEMORY;
  124. goto Error;
  125. }
  126. ATLASSERT(ERROR_SUCCESS == ec);
  127. DebugPrintEx( DEBUG_MSG,
  128. _T("Succeed to get inbox configuration."));
  129. goto Exit;
  130. Error:
  131. ATLASSERT(ERROR_SUCCESS != ec);
  132. hRc = HRESULT_FROM_WIN32(ec);
  133. ATLASSERT(NULL != m_pParentNode);
  134. m_pParentNode->NodeMsgBox(GetFaxServerErrorMsg(ec));
  135. Exit:
  136. return (hRc);
  137. }
  138. /*
  139. - CppFaxServerInbox::OnInitDialog
  140. -
  141. * Purpose:
  142. * Initiates all controls when dialog is called.
  143. *
  144. * Arguments:
  145. *
  146. * Return:
  147. *
  148. */
  149. LRESULT CppFaxServerInbox::OnInitDialog( UINT uiMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled )
  150. {
  151. DEBUG_FUNCTION_NAME( _T("CppFaxServerInbox::PageInitDialog"));
  152. DWORD ec = ERROR_SUCCESS;
  153. UNREFERENCED_PARAMETER( uiMsg );
  154. UNREFERENCED_PARAMETER( wParam );
  155. UNREFERENCED_PARAMETER( lParam );
  156. UNREFERENCED_PARAMETER( fHandled );
  157. int iLow,
  158. iHigh,
  159. iAgeLimit;
  160. ATLASSERT(m_pFaxArchiveConfig);
  161. //
  162. // init controls
  163. //
  164. m_FolderBox.Attach(GetDlgItem(IDC_INBOX_FOLDER_EDIT));
  165. m_FolderBox.SetLimitText(MAX_ARCHIVE_FOLDER_PATH);
  166. SHAutoComplete (GetDlgItem(IDC_INBOX_FOLDER_EDIT), SHACF_FILESYSTEM);
  167. m_HighWatermarkBox.Attach(GetDlgItem(IDC_HIGH_EDIT));
  168. m_LowWatermarkBox.Attach(GetDlgItem(IDC_LOW_EDIT));
  169. m_AutoDelBox.Attach(GetDlgItem(IDC_AUTODEL_EDIT));
  170. m_HighWatermarkBox.SetLimitText(FXS_QUOTA_LENGTH);
  171. m_LowWatermarkBox.SetLimitText(FXS_QUOTA_LENGTH);
  172. m_AutoDelBox.SetLimitText(FXS_DIRTYDAYS_LENGTH);
  173. m_HighWatermarkSpin.Attach(GetDlgItem(IDC_HIGH_SPIN));
  174. m_LowWatermarkSpin.Attach(GetDlgItem(IDC_LOW_SPIN));
  175. m_AutoDelSpin.Attach(GetDlgItem(IDC_AUTODEL_SPIN));
  176. //
  177. // FOLDER_EDIT
  178. //
  179. m_FolderBox.SetWindowText(m_pFaxArchiveConfig->lpcstrFolder);
  180. //
  181. // Disable Browse button for remote admin
  182. //
  183. if (!m_fIsLocalServer)
  184. {
  185. ::EnableWindow(GetDlgItem(IDC_INBOX_BROWSE_BUTTON), FALSE);
  186. }
  187. //
  188. // TO_ARCHIVE_CHECK
  189. //
  190. if (m_pFaxArchiveConfig->bUseArchive)
  191. {
  192. CheckDlgButton(IDC_TO_ARCHIVE_CHECK, BST_CHECKED) ;
  193. }
  194. else
  195. {
  196. CheckDlgButton(IDC_TO_ARCHIVE_CHECK, BST_UNCHECKED) ;
  197. ::EnableWindow(GetDlgItem(IDC_INBOX_FOLDER_EDIT), FALSE);
  198. ::EnableWindow(GetDlgItem(IDC_INBOX_BROWSE_BUTTON), FALSE);
  199. }
  200. //
  201. // Quota size - Low
  202. //
  203. iLow = (int)m_pFaxArchiveConfig->dwSizeQuotaLowWatermark;
  204. m_LowWatermarkSpin.SetRange(FXS_QUOTA_LOW_LOWER, FXS_QUOTA_LOW_UPPER);
  205. m_LowWatermarkSpin.SetPos(iLow);
  206. //
  207. // Quota size - High
  208. //
  209. iHigh = (int)m_pFaxArchiveConfig->dwSizeQuotaHighWatermark;
  210. m_HighWatermarkSpin.SetRange(FXS_QUOTA_HIGH_LOWER, FXS_QUOTA_HIGH_UPPER);
  211. m_HighWatermarkSpin.SetPos(iHigh);// Set Position
  212. //
  213. //Generate event log warning
  214. //
  215. if (m_pFaxArchiveConfig->bSizeQuotaWarning)
  216. {
  217. CheckDlgButton(IDC_GENERATE_WARNING_CHECK, BST_CHECKED) ;
  218. }
  219. else
  220. {
  221. CheckDlgButton(IDC_GENERATE_WARNING_CHECK, BST_UNCHECKED) ;
  222. ::EnableWindow(GetDlgItem(IDC_HIGH_EDIT), FALSE);
  223. ::EnableWindow(GetDlgItem(IDC_HIGH_SPIN), FALSE);
  224. ::EnableWindow(GetDlgItem(IDC_LOW_EDIT), FALSE);
  225. ::EnableWindow(GetDlgItem(IDC_LOW_SPIN), FALSE);
  226. }
  227. //
  228. // message life-time (dirty days)
  229. //
  230. iAgeLimit = (int)m_pFaxArchiveConfig->dwAgeLimit;
  231. m_AutoDelSpin.SetRange(FXS_DIRTYDAYS_LOWER, FXS_DIRTYDAYS_UPPER);
  232. m_AutoDelSpin.SetPos(iAgeLimit);
  233. //
  234. // Auto Delete
  235. //
  236. if (FXS_DIRTYDAYS_ZERO == iAgeLimit)
  237. {
  238. CheckDlgButton(IDC_AUTODEL_CHECK, BST_UNCHECKED);
  239. ::EnableWindow(GetDlgItem(IDC_AUTODEL_EDIT), FALSE);
  240. ::EnableWindow(GetDlgItem(IDC_AUTODEL_SPIN), FALSE);
  241. }
  242. else
  243. {
  244. CheckDlgButton(IDC_AUTODEL_CHECK, BST_CHECKED);
  245. }
  246. m_fIsDialogInitiated = TRUE;
  247. return (1);
  248. }
  249. /*
  250. - CppFaxServerInbox::SetProps
  251. -
  252. * Purpose:
  253. * Sets properties on apply.
  254. *
  255. * Arguments:
  256. * pCtrlFocus - focus pointer (int)
  257. *
  258. * Return:
  259. * OLE error code
  260. */
  261. HRESULT CppFaxServerInbox::SetProps(int *pCtrlFocus, UINT * puIds)
  262. {
  263. DEBUG_FUNCTION_NAME( _T("CppFaxServerInbox::SetProps"));
  264. HRESULT hRc = S_OK;
  265. DWORD ec = ERROR_SUCCESS;
  266. HINSTANCE hInst = _Module.GetResourceInstance();
  267. CComBSTR bstrFolder = L"";
  268. BOOL fSkipMessage = FALSE;
  269. FAX_ARCHIVE_CONFIG FaxArchiveConfig;
  270. ATLASSERT(TRUE == m_fAllReadyToApply);
  271. m_fAllReadyToApply = FALSE;
  272. //
  273. // Collect all data and init the structure's fields
  274. // uses Copy() to copy and also allocate before
  275. //
  276. ZeroMemory (&FaxArchiveConfig, sizeof(FAX_ARCHIVE_CONFIG));
  277. //
  278. // Size of struct.
  279. //
  280. FaxArchiveConfig.dwSizeOfStruct = sizeof(FAX_ARCHIVE_CONFIG);
  281. //
  282. // IDC_TO_ARCHIVE_CHECK
  283. //
  284. if (IsDlgButtonChecked(IDC_TO_ARCHIVE_CHECK) == BST_CHECKED)
  285. {
  286. FaxArchiveConfig.bUseArchive = TRUE;
  287. //IDC_INBOX_FOLDER_EDIT
  288. if ( !m_FolderBox.GetWindowText(&bstrFolder))
  289. {
  290. *pCtrlFocus = IDC_INBOX_FOLDER_EDIT;
  291. DebugPrintEx(
  292. DEBUG_ERR,
  293. TEXT("Failed to GetWindowText(&bstrFolder)"));
  294. ec = ERROR_OUTOFMEMORY;
  295. goto Error;
  296. }
  297. if (!IsNotEmptyString(bstrFolder))
  298. {
  299. *pCtrlFocus = IDC_INBOX_FOLDER_EDIT;
  300. *puIds = IDS_INBOX_ARCHIVE_PATH_EMPTY;
  301. DebugPrintEx( DEBUG_ERR,
  302. _T("Archive path string is empty or includes spaces only."));
  303. fSkipMessage = TRUE;
  304. ec = ERROR_INVALID_DATA;
  305. goto Error;
  306. }
  307. FaxArchiveConfig.lpcstrFolder = bstrFolder;
  308. //
  309. // follow-up for an OnApply following submition
  310. // with unchecked IDC_TO_ARCHIVE_CHECK
  311. //
  312. m_bstrLastGoodFolder = bstrFolder;
  313. if (!m_bstrLastGoodFolder)
  314. {
  315. *pCtrlFocus = IDC_INBOX_FOLDER_EDIT;
  316. DebugPrintEx(
  317. DEBUG_ERR,
  318. TEXT("Failed to allocate string (m_bstrLastGoodFolder)."));
  319. ec = ERROR_OUTOFMEMORY;
  320. goto Error;
  321. }
  322. }
  323. else
  324. {
  325. FaxArchiveConfig.bUseArchive = FALSE;
  326. FaxArchiveConfig.lpcstrFolder = m_bstrLastGoodFolder;
  327. }
  328. //
  329. // IDC_GENERATE_WARNING_CHECK
  330. //
  331. if (IsDlgButtonChecked(IDC_GENERATE_WARNING_CHECK) == BST_CHECKED)
  332. {
  333. FaxArchiveConfig.bSizeQuotaWarning = TRUE;
  334. int iHigh = m_HighWatermarkSpin.GetPos();
  335. FaxArchiveConfig.dwSizeQuotaHighWatermark = (DWORD) iHigh;
  336. int iLow = m_LowWatermarkSpin.GetPos();
  337. FaxArchiveConfig.dwSizeQuotaLowWatermark = (DWORD) iLow;
  338. if (iHigh <= iLow)
  339. {
  340. *pCtrlFocus = IDC_SENT_HIGH_EDIT;
  341. *puIds = IDS_INBOX_WATERMARK_HI_LOW;
  342. DebugPrintEx( DEBUG_ERR,
  343. _T("Watermark High < Low."));
  344. fSkipMessage = TRUE;
  345. ec = ERROR_INVALID_DATA;
  346. goto Error;
  347. }
  348. //
  349. // follow-up for an OnApply following submition
  350. // with unchecked IDC_SENT_GENERATE_WARNING_CHECK
  351. //
  352. m_dwLastGoodSizeQuotaHighWatermark = (DWORD)iHigh;
  353. m_dwLastGoodSizeQuotaLowWatermark = (DWORD)iLow;
  354. }
  355. else
  356. {
  357. FaxArchiveConfig.bSizeQuotaWarning = FALSE;
  358. FaxArchiveConfig.dwSizeQuotaHighWatermark = m_dwLastGoodSizeQuotaHighWatermark;
  359. FaxArchiveConfig.dwSizeQuotaLowWatermark = m_dwLastGoodSizeQuotaLowWatermark;
  360. }
  361. //
  362. // IDC_AUTODEL_CHECK - AutoDelete Messages
  363. //
  364. if (IsDlgButtonChecked(IDC_AUTODEL_CHECK) == BST_CHECKED)
  365. {
  366. int iAgeLimit = m_AutoDelSpin.GetPos();
  367. FaxArchiveConfig.dwAgeLimit = (DWORD) iAgeLimit;
  368. }
  369. else
  370. {
  371. FaxArchiveConfig.dwAgeLimit = (DWORD)FXS_DIRTYDAYS_ZERO;
  372. }
  373. //
  374. // get RPC Handle
  375. //
  376. if (!m_pFaxServer->GetFaxServerHandle())
  377. {
  378. ec= GetLastError();
  379. DebugPrintEx(
  380. DEBUG_ERR,
  381. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  382. ec);
  383. goto Error;
  384. }
  385. //
  386. // Set Config
  387. //
  388. if (!FaxSetArchiveConfiguration(
  389. m_pFaxServer->GetFaxServerHandle(),
  390. FAX_MESSAGE_FOLDER_INBOX,
  391. &FaxArchiveConfig))
  392. {
  393. ec = GetLastError();
  394. DebugPrintEx(DEBUG_ERR, _T("Fail to Set inbox configuration. (ec: %ld)"), ec);
  395. //
  396. // Try to adjust folder
  397. //
  398. PropSheet_SetCurSelByID( GetParent(), IDD);
  399. GotoDlgCtrl(GetDlgItem(IDC_INBOX_FOLDER_EDIT));
  400. ec = AskUserAndAdjustFaxFolder(m_hWnd,
  401. m_pFaxServer->GetServerName(),
  402. FaxArchiveConfig.lpcstrFolder,
  403. ec);
  404. if(ERROR_SUCCESS != ec)
  405. {
  406. if(ERROR_BAD_PATHNAME == ec)
  407. {
  408. //
  409. // The error message has been shown by AskUserAndAdjustFaxFolder
  410. //
  411. fSkipMessage = TRUE;
  412. }
  413. goto Error;
  414. }
  415. //
  416. // The folder has been adjusted, set it again
  417. //
  418. if (!FaxSetArchiveConfiguration(m_pFaxServer->GetFaxServerHandle(),
  419. FAX_MESSAGE_FOLDER_INBOX,
  420. &FaxArchiveConfig))
  421. {
  422. ec = GetLastError();
  423. DebugPrintEx(DEBUG_ERR, _T("Fail to Set inbox configuration. (ec: %ld)"), ec);
  424. goto Error;
  425. }
  426. }
  427. ATLASSERT(S_OK == hRc);
  428. m_fIsDirty = FALSE;
  429. DebugPrintEx( DEBUG_MSG, _T("Succeed to set inbox configuration."));
  430. return hRc;
  431. Error:
  432. ATLASSERT(ERROR_SUCCESS != ec);
  433. hRc = HRESULT_FROM_WIN32(ec);
  434. DWORD dwIDS = 0;
  435. switch (ec)
  436. {
  437. case ERROR_DISK_FULL:
  438. DebugPrintEx( DEBUG_ERR, _T("ERROR_DISK_FULL == ec"));
  439. dwIDS = IDS_INBOX_ERROR_DISK_FULL;
  440. break;
  441. case FAX_ERR_NOT_NTFS:
  442. DebugPrintEx( DEBUG_ERR, _T("FAX_ERR_NOT_NTFS == ec"));
  443. dwIDS = IDS_INBOX_FAX_ERR_NOT_NTFS;
  444. break;
  445. case FAX_ERR_FILE_ACCESS_DENIED:
  446. DebugPrintEx( DEBUG_ERR, _T("FAX_ERR_FILE_ACCESS_DENIED == ec"));
  447. dwIDS = IDS_INBOX_FAX_ERR_FILE_ACCESS_DENIED;
  448. break;
  449. default:
  450. dwIDS = GetFaxServerErrorMsg(ec);
  451. break;
  452. }
  453. if (dwIDS && !fSkipMessage)
  454. {
  455. PropSheet_SetCurSelByID( GetParent(), IDD);
  456. PageError(dwIDS, m_hWnd);
  457. }
  458. if (IsNetworkError(ec))
  459. {
  460. DebugPrintEx(DEBUG_ERR, _T("Network Error was found. (ec: %ld)"), ec);
  461. m_pFaxServer->Disconnect();
  462. }
  463. return hRc;
  464. }
  465. /*
  466. - CppFaxServerInbox::PreApply
  467. -
  468. * Purpose:
  469. * Checks properties before apply.
  470. *
  471. * Arguments:
  472. *
  473. * Return:
  474. * OLE error code
  475. */
  476. HRESULT CppFaxServerInbox::PreApply(int *pCtrlFocus, UINT * puIds)
  477. {
  478. HRESULT hRc = S_OK;
  479. //
  480. // PreApply Checks
  481. //
  482. if (!AllReadyToApply(/*fSilent =*/ FALSE, pCtrlFocus , puIds))
  483. {
  484. m_fAllReadyToApply = FALSE;
  485. SetModified(FALSE);
  486. hRc = E_FAIL ;
  487. }
  488. else
  489. {
  490. m_fAllReadyToApply = TRUE;
  491. SetModified(TRUE);
  492. }
  493. return(hRc);
  494. }
  495. /*
  496. - CppFaxServerInbox::ToArchiveCheckboxClicked
  497. -
  498. * Purpose:
  499. * Gray/Ungray the folder edit box and the
  500. * browse button. Enable apply button.
  501. *
  502. * Arguments:
  503. *
  504. * Return:
  505. * 1
  506. */
  507. LRESULT CppFaxServerInbox::ToArchiveCheckboxClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  508. {
  509. BOOL State;
  510. if (!m_fIsDialogInitiated) //event receieved in too early stage
  511. {
  512. return 0;
  513. }
  514. else
  515. {
  516. m_fIsDirty = TRUE;
  517. }
  518. State = ( IsDlgButtonChecked(IDC_TO_ARCHIVE_CHECK) == BST_CHECKED );
  519. ::EnableWindow(GetDlgItem(IDC_INBOX_FOLDER_EDIT), State);
  520. ::EnableWindow(GetDlgItem(IDC_INBOX_BROWSE_BUTTON), State && m_fIsLocalServer);
  521. if (m_fAllReadyToApply)//only last change should be considered
  522. {
  523. if ( !m_FolderBox.GetWindowTextLength() )
  524. {
  525. m_fAllReadyToApply = FALSE;
  526. SetModified(FALSE);
  527. }
  528. }
  529. else //m_fAllReadyToApply == FALSE
  530. {
  531. if (AllReadyToApply(TRUE))
  532. {
  533. m_fAllReadyToApply = TRUE;
  534. SetModified(TRUE);
  535. }
  536. }
  537. return 1;
  538. }
  539. /*
  540. - CppFaxServerInbox::GenerateEventLogCheckboxClicked
  541. -
  542. * Purpose:
  543. * Gray/Ungray the spin buttons and edit boxes
  544. * Enable apply button.
  545. *
  546. * Arguments:
  547. *
  548. * Return:
  549. * 1
  550. */
  551. LRESULT CppFaxServerInbox::GenerateEventLogCheckboxClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  552. {
  553. BOOL State;
  554. if (!m_fIsDialogInitiated) //event receieved in too early stage
  555. {
  556. return 0;
  557. }
  558. else
  559. {
  560. m_fIsDirty = TRUE;
  561. }
  562. State = ( IsDlgButtonChecked(IDC_GENERATE_WARNING_CHECK) == BST_CHECKED );
  563. ::EnableWindow(GetDlgItem(IDC_HIGH_EDIT), State);
  564. ::EnableWindow(GetDlgItem(IDC_HIGH_SPIN), State);
  565. ::EnableWindow(GetDlgItem(IDC_QUOTA_HIGH_STATIC), State);
  566. ::EnableWindow(GetDlgItem(IDC_MB1_STATIC), State);
  567. ::EnableWindow(GetDlgItem(IDC_LOW_EDIT), State);
  568. ::EnableWindow(GetDlgItem(IDC_LOW_SPIN), State);
  569. ::EnableWindow(GetDlgItem(IDC_QUOTA_LOW_STATIC), State);
  570. ::EnableWindow(GetDlgItem(IDC_MB2_STATIC), State);
  571. if (m_fAllReadyToApply)//only last change should be considered
  572. {
  573. if ( !m_HighWatermarkBox.GetWindowTextLength() )
  574. {
  575. m_fAllReadyToApply = FALSE;
  576. SetModified(FALSE);
  577. }
  578. else if ( 0 != HIWORD( m_HighWatermarkSpin.GetPos() ) ) //occures for out of range such zero. MSDN UDM_GETPOS
  579. {
  580. m_fAllReadyToApply = FALSE;
  581. SetModified(FALSE);
  582. }
  583. else if ( !m_LowWatermarkBox.GetWindowTextLength() )
  584. {
  585. m_fAllReadyToApply = FALSE;
  586. SetModified(FALSE);
  587. }
  588. }
  589. else //m_fAllReadyToApply == FALSE
  590. {
  591. if (AllReadyToApply(TRUE))
  592. {
  593. m_fAllReadyToApply = TRUE;
  594. SetModified(TRUE);
  595. }
  596. }
  597. return(1);
  598. }
  599. /*
  600. - CppFaxServerInbox::AutoDelCheckboxClicked
  601. -
  602. * Purpose:
  603. * Gray/Ungray the spin button and edit box
  604. * and enable apply button after Auto Delete Checkbox
  605. * status was changed.
  606. *
  607. * Arguments:
  608. *
  609. * Return:
  610. * 1
  611. */
  612. LRESULT CppFaxServerInbox::AutoDelCheckboxClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  613. {
  614. BOOL State;
  615. if (!m_fIsDialogInitiated) //event receieved in too early stage
  616. {
  617. return 0;
  618. }
  619. else
  620. {
  621. m_fIsDirty = TRUE;
  622. }
  623. State = ( IsDlgButtonChecked(IDC_AUTODEL_CHECK) == BST_CHECKED );
  624. ::EnableWindow(GetDlgItem(IDC_AUTODEL_EDIT), State);
  625. ::EnableWindow(GetDlgItem(IDC_AUTODEL_SPIN), State);
  626. if (m_fAllReadyToApply)//only last change should be considered
  627. {
  628. if (State)
  629. {
  630. if ( !m_AutoDelBox.GetWindowTextLength() )
  631. {
  632. m_fAllReadyToApply = FALSE;
  633. SetModified(FALSE);
  634. }
  635. else if ( 0 != HIWORD( m_AutoDelSpin.GetPos() ) ) //occures for out of range such zero. MSDN UDM_GETPOS
  636. {
  637. m_fAllReadyToApply = FALSE;
  638. SetModified(FALSE);
  639. }
  640. }
  641. }
  642. else //m_fAllReadyToApply == FALSE
  643. {
  644. if (AllReadyToApply(TRUE))
  645. {
  646. m_fAllReadyToApply = TRUE;
  647. SetModified(TRUE);
  648. }
  649. }
  650. return(1);
  651. }
  652. /*
  653. + Routine Description:
  654. +
  655. * Browse for a directory
  656. *
  657. * Arguments:
  658. *
  659. * hwndDlg - Specifies the dialog window on which the Browse button is displayed
  660. *
  661. * Return Value:
  662. *
  663. * TRUE if successful, FALSE if the user presses Cancel
  664. -
  665. -
  666. */
  667. BOOL
  668. CppFaxServerInbox::BrowseForDirectory( WORD wNotifyCode, WORD wID, HWND hwndDlg, BOOL& bHandled )
  669. {
  670. UNREFERENCED_PARAMETER( wNotifyCode );
  671. UNREFERENCED_PARAMETER( wID );
  672. UNREFERENCED_PARAMETER( hwndDlg );
  673. UNREFERENCED_PARAMETER( bHandled );
  674. DEBUG_FUNCTION_NAME( _T("CppFaxServerInbox::BrowseForDirectory"));
  675. BOOL fResult = FALSE;
  676. WCHAR szBrowseFolder[MAX_PATH]={0};
  677. WCHAR szBrowseDlgTitle[FXS_MAX_TITLE_LEN];
  678. CComBSTR bstrOldPath;
  679. unsigned int len;
  680. unsigned long ulBrowseFlags;
  681. //
  682. // Collecting the browse dialog headline
  683. //
  684. if (!LoadString( _Module.GetResourceInstance(),
  685. IDS_GET_ARCHIVE_DIRECTORY,
  686. szBrowseDlgTitle,
  687. FXS_MAX_TITLE_LEN))
  688. {
  689. DWORD ec;
  690. ec = GetLastError();
  691. if (ec == ERROR_NOT_ENOUGH_MEMORY)
  692. {
  693. DebugPrintEx(
  694. DEBUG_ERR,
  695. _T("Out of Memory - fail to load string."));
  696. DlgMsgBox(this, IDS_MEMORY);
  697. return fResult;
  698. }
  699. DebugPrintEx(
  700. DEBUG_ERR,
  701. _T("Failed to load titile string - unexpected behavior."));
  702. szBrowseDlgTitle[0] = 0;
  703. }
  704. //
  705. // Collecting the old path from the calling dialog edit box
  706. //
  707. if(! GetDlgItemText( IDC_INBOX_FOLDER_EDIT, bstrOldPath.m_str))
  708. {
  709. DebugPrintEx(
  710. DEBUG_ERR,
  711. _T("Failed to collect old path from the property page edit box."));
  712. szBrowseFolder[0] = 0;
  713. }
  714. else
  715. {
  716. len = bstrOldPath.Length();
  717. if ( len > MAX_PATH )
  718. {
  719. DebugPrintEx(
  720. DEBUG_ERR,
  721. _T("Old Path Length is bigger then alowed maximal path."));
  722. szBrowseFolder[0] = 0;
  723. }
  724. else
  725. {
  726. wcsncpy(szBrowseFolder, bstrOldPath, ARR_SIZE(szBrowseFolder)-1);
  727. }
  728. }
  729. //
  730. // Preparing the browse dialog style flags.
  731. //
  732. ulBrowseFlags = BIF_RETURNONLYFSDIRS |
  733. BIF_STATUSTEXT |
  734. BIF_NEWDIALOGSTYLE |
  735. BIF_NONEWFOLDERBUTTON |
  736. BIF_VALIDATE;
  737. //
  738. // Invoke the browse dialog with a function based on
  739. // Shell functions.
  740. //
  741. if (InvokeBrowseDialog(szBrowseFolder,
  742. MAX_ARCHIVE_FOLDER_PATH,
  743. szBrowseDlgTitle,
  744. ulBrowseFlags,
  745. this))
  746. {
  747. SetDlgItemText(IDC_INBOX_FOLDER_EDIT, szBrowseFolder);
  748. fResult = TRUE;
  749. }
  750. return fResult;
  751. }
  752. /*
  753. - CppFaxServerInbox::OnApply
  754. -
  755. * Purpose:
  756. * Calls PreApply and SetProp to Apply changes.
  757. *
  758. * Arguments:
  759. *
  760. * Return:
  761. * TRUE or FALSE
  762. */
  763. BOOL CppFaxServerInbox::OnApply()
  764. {
  765. DEBUG_FUNCTION_NAME( _T("CppFaxServerInbox::OnApply"));
  766. HRESULT hRc = S_OK;
  767. int CtrlFocus = 0;
  768. UINT uIds = 0;
  769. if (!m_fIsDirty)
  770. {
  771. return TRUE;
  772. }
  773. hRc = PreApply(&CtrlFocus, &uIds);
  774. if (FAILED(hRc))
  775. {
  776. if (PropSheet_SetCurSelByID( GetParent(), IDD) )
  777. {
  778. PageError(uIds, m_hWnd, _Module.GetResourceInstance());
  779. if (CtrlFocus)
  780. {
  781. GotoDlgCtrl(GetDlgItem(CtrlFocus));
  782. }
  783. }
  784. return FALSE;
  785. }
  786. else //(Succeeded(hRc))
  787. {
  788. hRc = SetProps(&CtrlFocus, &uIds);
  789. if (FAILED(hRc))
  790. {
  791. if (uIds)
  792. {
  793. if (PropSheet_SetCurSelByID( GetParent(), IDD) )
  794. {
  795. PageError(uIds, m_hWnd, _Module.GetResourceInstance());
  796. if (CtrlFocus)
  797. {
  798. GotoDlgCtrl(GetDlgItem(CtrlFocus));
  799. }
  800. }
  801. }
  802. //else Error Msg by called func.
  803. return FALSE;
  804. }
  805. else //(Succeeded(hRc))
  806. {
  807. return TRUE;
  808. }
  809. }
  810. }
  811. /*
  812. - CppFaxServerInbox::EditChanged
  813. -
  814. * Purpose:
  815. * set Apply buttom modified.
  816. *
  817. * Arguments:
  818. *
  819. * Return:
  820. * 1
  821. */
  822. LRESULT CppFaxServerInbox::EditChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  823. {
  824. if (!m_fIsDialogInitiated)
  825. {
  826. return 1;
  827. }
  828. else
  829. {
  830. m_fIsDirty = TRUE;
  831. }
  832. if (m_fAllReadyToApply) //only last change should be considered
  833. {
  834. switch (wID)
  835. {
  836. case IDC_INBOX_FOLDER_EDIT:
  837. if ( !m_FolderBox.GetWindowTextLength() )
  838. {
  839. SetModified(FALSE);
  840. m_fAllReadyToApply = FALSE;
  841. }
  842. break;
  843. case IDC_HIGH_EDIT:
  844. if ( !m_HighWatermarkBox.GetWindowTextLength() )
  845. {
  846. SetModified(FALSE);
  847. m_fAllReadyToApply = FALSE;
  848. }
  849. else if ( 0 != HIWORD( m_HighWatermarkSpin.GetPos() ) ) //occures for out of range such zero. MSDN UDM_GETPOS
  850. {
  851. SetModified(FALSE);
  852. m_fAllReadyToApply = FALSE;
  853. }
  854. break;
  855. case IDC_LOW_EDIT:
  856. if ( !m_LowWatermarkBox.GetWindowTextLength() )
  857. {
  858. SetModified(FALSE);
  859. m_fAllReadyToApply = FALSE;
  860. }
  861. break;
  862. case IDC_AUTODEL_EDIT:
  863. if ( !m_AutoDelBox.GetWindowTextLength() )
  864. {
  865. SetModified(FALSE);
  866. m_fAllReadyToApply = FALSE;
  867. }
  868. else if ( 0 != HIWORD( m_AutoDelSpin.GetPos() ) ) //occures for out of range such zero. MSDN UDM_GETPOS
  869. {
  870. m_fAllReadyToApply = FALSE;
  871. SetModified(FALSE);
  872. }
  873. break;
  874. default:
  875. return 1;
  876. }
  877. }
  878. else //m_fAllReadyToApply == FALSE
  879. {
  880. if (AllReadyToApply(TRUE))
  881. {
  882. m_fAllReadyToApply = TRUE;
  883. SetModified(TRUE);
  884. }
  885. }
  886. return 1;
  887. }
  888. /*
  889. - CppFaxServerInbox::AllReadyToApply
  890. -
  891. * Purpose:
  892. * This function validate that no zero length strings
  893. * are found data areas that should be saved.
  894. *
  895. * Arguments:
  896. * [in] fSilent - boolean who defines if to pop up messages (FALSE)
  897. * or not.(TRUE)
  898. *
  899. * Return:
  900. * BOOOLEAN
  901. */
  902. BOOL CppFaxServerInbox::AllReadyToApply(BOOL fSilent, int *pCtrlFocus, UINT *pIds)
  903. {
  904. DEBUG_FUNCTION_NAME( _T("CppFaxServerInbox::AllReadyToApply"));
  905. DWORD ec = ERROR_SUCCESS;
  906. HINSTANCE hInst = _Module.GetResourceInstance();
  907. if (IsDlgButtonChecked(IDC_TO_ARCHIVE_CHECK) == BST_CHECKED)
  908. {
  909. if ( !m_FolderBox.GetWindowTextLength() )
  910. {
  911. ec = GetLastError();
  912. DebugPrintEx(
  913. DEBUG_ERR,
  914. _T("Zero text length - m_FolderBox. (ec: %ld)"),
  915. ec);
  916. if (!fSilent)
  917. {
  918. *pIds = IDS_INBOX_ARCHIVE_PATH_EMPTY;
  919. *pCtrlFocus = IDC_INBOX_FOLDER_EDIT;
  920. }
  921. return FALSE;
  922. }
  923. }
  924. if (IsDlgButtonChecked(IDC_GENERATE_WARNING_CHECK) == BST_CHECKED)
  925. {
  926. if ( !m_HighWatermarkBox.GetWindowTextLength() )
  927. {
  928. ec = GetLastError();
  929. DebugPrintEx(
  930. DEBUG_ERR,
  931. _T("Zero text length - m_HighWatermarkBox. (ec: %ld)"),
  932. ec);
  933. if (!fSilent)
  934. {
  935. *pIds = IDS_INBOX_WATERMARK_EMPTY;
  936. *pCtrlFocus = IDC_HIGH_EDIT;
  937. }
  938. return FALSE;
  939. }
  940. else if ( 0 != HIWORD( m_HighWatermarkSpin.GetPos() ) ) //occures for out of range such zero. MSDN UDM_GETPOS
  941. {
  942. DebugPrintEx(
  943. DEBUG_ERR,
  944. _T("Zero value - m_HighWatermarkBox. (ec: %ld)"));
  945. if (!fSilent)
  946. {
  947. *pIds = IDS_INBOX_HIGH_WATERMARK_ZERO;
  948. *pCtrlFocus = IDC_HIGH_EDIT;
  949. }
  950. return FALSE;
  951. }
  952. if ( !m_LowWatermarkBox.GetWindowTextLength() )
  953. {
  954. ec = GetLastError();
  955. DebugPrintEx(
  956. DEBUG_ERR,
  957. _T("Zero text length - m_LowWatermarkBox. (ec: %ld)"),
  958. ec);
  959. if (!fSilent)
  960. {
  961. *pIds = IDS_INBOX_WATERMARK_EMPTY;
  962. *pCtrlFocus = IDC_SENT_LOW_EDIT;
  963. }
  964. return FALSE;
  965. }
  966. }
  967. if (IsDlgButtonChecked(IDC_AUTODEL_CHECK) == BST_CHECKED)
  968. {
  969. if ( !m_AutoDelBox.GetWindowTextLength() )
  970. {
  971. ec = GetLastError();
  972. DebugPrintEx(
  973. DEBUG_ERR,
  974. _T("Zero text length - m_AutoDelBox. (ec: %ld)"),
  975. ec);
  976. if (!fSilent)
  977. {
  978. *pIds = IDS_INBOX_AUTODEL_EMPTY;
  979. *pCtrlFocus = IDC_AUTODEL_EDIT;
  980. }
  981. return FALSE;
  982. }
  983. else if ( 0 != HIWORD( m_AutoDelSpin.GetPos() ) ) //occures for out of range such zero. MSDN UDM_GETPOS
  984. {
  985. DebugPrintEx(
  986. DEBUG_ERR,
  987. _T("Zero value - m_AutoDelBox."));
  988. if (!fSilent)
  989. {
  990. *pIds = IDS_INBOX_AUTODEL_EMPTY;
  991. *pCtrlFocus = IDC_AUTODEL_EDIT;
  992. }
  993. return FALSE;
  994. }
  995. }
  996. ATLASSERT(ERROR_SUCCESS == ec);
  997. //
  998. // Cheers!
  999. // ...every thing ready to apply now.
  1000. //
  1001. return TRUE;
  1002. }
  1003. //////////////////////////////////////////////////////////////////////////////
  1004. /*++
  1005. CppFaxServerInbox::OnHelpRequest
  1006. This is called in response to the WM_HELP Notify
  1007. message and to the WM_CONTEXTMENU Notify message.
  1008. WM_HELP Notify message.
  1009. This message is sent when the user presses F1 or <Shift>-F1
  1010. over an item or when the user clicks on the ? icon and then
  1011. presses the mouse over an item.
  1012. WM_CONTEXTMENU Notify message.
  1013. This message is sent when the user right clicks over an item
  1014. and then clicks "What's this?"
  1015. --*/
  1016. /////////////////////////////////////////////////////////////////////////////
  1017. LRESULT
  1018. CppFaxServerInbox::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  1019. {
  1020. DEBUG_FUNCTION_NAME(_T("CppFaxServerInbox::OnHelpRequest"));
  1021. switch (uMsg)
  1022. {
  1023. case WM_HELP:
  1024. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  1025. break;
  1026. case WM_CONTEXTMENU:
  1027. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  1028. break;
  1029. }
  1030. return TRUE;
  1031. }
  1032. /////////////////////////////////////////////////////////////////////////////