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.

610 lines
19 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. droutpri.cpp
  5. Abstract:
  6. This file contains implementation of
  7. the routing extension priority dialog.
  8. Environment:
  9. WIN32 User Mode
  10. Author:
  11. Darwin Ouyang (t-darouy) 30-Sept-1997
  12. --*/
  13. #include "stdafx.h"
  14. #include "droutpri.h"
  15. #include "faxcompd.h"
  16. #include "faxcomp.h"
  17. #include "inode.h"
  18. #include "idevice.h"
  19. #include "adminhlp.h"
  20. #pragma hdrstop
  21. ////////////////////////////////////////////////////////////////////////////////////////////////////
  22. ////////////////////////////////////////////////////////////////////////////////////////////////////
  23. ////////////////////////////////////////////////////////////////////////////////////////////////////
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////
  25. //
  26. //
  27. // Constructor and destructor
  28. //
  29. //
  30. CFaxRoutePriPropSheet::CFaxRoutePriPropSheet(
  31. IN HINSTANCE hInstance,
  32. IN LONG_PTR hMmcNotify,
  33. IN CInternalNode * NodePtr,
  34. IN CFaxComponent * pComp
  35. )
  36. : _hMmcNotify( hMmcNotify ),
  37. _hFaxServer( 0 ),
  38. _pOwnNode( NodePtr ),
  39. _pRoutingMethod( NULL ),
  40. _iRoutingMethodCount( 0 ),
  41. _pRoutingMethodIndex( NULL ),
  42. _pComp( pComp )
  43. /*++
  44. Routine Description:
  45. Constructor
  46. Arguments:
  47. hInstance - the instance pointer
  48. hMmcNotify - the MMC notify handle
  49. NodePtr - a pointer to the owning node
  50. Return Value:
  51. None.
  52. --*/
  53. {
  54. INITCOMMONCONTROLSEX icex;
  55. icex.dwSize = sizeof(icex);
  56. icex.dwICC = ICC_DATE_CLASSES;
  57. InitCommonControlsEx(&icex);
  58. DebugPrint(( TEXT("CFaxRoutePriPropSheet Created") ));
  59. _PropSheet.dwSize = sizeof( *this );
  60. _PropSheet.dwFlags = PSP_USETITLE | PSP_USECALLBACK;
  61. _PropSheet.hInstance = hInstance;
  62. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDD_ROUTE_PRI);
  63. _PropSheet.pszTitle = MAKEINTRESOURCE(IDD_ROUTE_PRI_TITLE);
  64. _PropSheet.pfnDlgProc = CFaxRoutePriPropSheet::DlgProc;
  65. _PropSheet.lParam = (LONG_PTR)this;
  66. _PropSheet.pfnCallback = &PropSheetPageProc;
  67. _hPropSheet = NULL;
  68. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  69. assert(_hPropSheet != NULL );
  70. assert( NodePtr != NULL );
  71. _pCompData = NodePtr->m_pCompData;
  72. _hFaxServer = _pCompData->m_FaxHandle;
  73. }
  74. CFaxRoutePriPropSheet::~CFaxRoutePriPropSheet()
  75. /*++
  76. Routine Description:
  77. Destructor
  78. Arguments:
  79. None.
  80. Return Value:
  81. None.
  82. --*/
  83. {
  84. DebugPrint(( TEXT("CFaxRoutePriPropSheet Destroyed") ));
  85. if( _pRoutingMethodIndex != NULL ) {
  86. delete _pRoutingMethodIndex;
  87. _pRoutingMethodIndex = NULL;
  88. _iRoutingMethodIndexCount = 0;
  89. }
  90. }
  91. ////////////////////////////////////////////////////////////////////////////////////////////////////
  92. ////////////////////////////////////////////////////////////////////////////////////////////////////
  93. ////////////////////////////////////////////////////////////////////////////////////////////////////
  94. ////////////////////////////////////////////////////////////////////////////////////////////////////
  95. //
  96. //
  97. // Dialog Proc
  98. //
  99. //
  100. INT_PTR
  101. APIENTRY
  102. CFaxRoutePriPropSheet::DlgProc(
  103. IN HWND hwndDlg,
  104. IN UINT message,
  105. IN WPARAM wParam,
  106. IN LPARAM lParam
  107. )
  108. /*++
  109. Routine Description:
  110. Dialog Procedure
  111. Arguments:
  112. hwndDlg - the hwnd of the dialog
  113. message - the message
  114. wParam, lParam - the window message parameters
  115. Return Value:
  116. BOOL
  117. --*/
  118. {
  119. // DebugPrint(( TEXT("Trace: CFaxRoutePriPropSheet::DlgProc") ));
  120. BOOL fRet = FALSE;
  121. HWND hwnd = NULL;
  122. HWND hwndSheet = NULL;
  123. switch( message ) {
  124. case WM_INITDIALOG:
  125. {
  126. DebugPrint(( TEXT("CFaxRoutePriPropSheet::DlgProc -- WM_INITDIALOG\n") ));
  127. assert( lParam != NULL );
  128. LONG_PTR lthis = ((CFaxRoutePriPropSheet *)lParam)->_PropSheet.lParam;
  129. CFaxRoutePriPropSheet * pthis = (CFaxRoutePriPropSheet *)lthis;
  130. assert( pthis != NULL );
  131. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  132. if( pthis->_pComp != NULL ) {
  133. pthis->_pComp->IncPropSheetCount();
  134. } else {
  135. pthis->_pCompData->IncPropSheetCount();
  136. }
  137. fRet = TRUE;
  138. break;
  139. }
  140. case WM_COMMAND:
  141. {
  142. // DebugPrint(( TEXT("CFaxRoutePriPropSheet::DlgProc -- WM_COMMAND\n") ));
  143. // activate apply button
  144. WORD wID = LOWORD( wParam );
  145. WORD wCMD = HIWORD( wParam );
  146. DWORD dwSelectedItem;
  147. CFaxRoutePriPropSheet * pthis =
  148. (CFaxRoutePriPropSheet *)GetWindowLongPtr( hwndDlg,
  149. DWLP_USER );
  150. hwnd = GetDlgItem( hwndDlg, IDC_ROUTE_EXTS );
  151. switch( wCMD ) {
  152. case BN_CLICKED:
  153. {
  154. switch( wID ) {
  155. case IDC_ROUTEPRI_UP:
  156. {
  157. DebugPrint(( TEXT(" ++++++++++++++ CFaxRoutePriPropSheet::DlgProc -- UP button pushed \n") ));
  158. //
  159. // handle click here!!
  160. //
  161. PFAX_GLOBAL_ROUTING_INFO tempRM;
  162. dwSelectedItem = (DWORD)SendMessage( hwnd, LB_GETCURSEL, 0, 0 );
  163. SetFocus( hwnd );
  164. if( dwSelectedItem != LB_ERR ) {
  165. if( dwSelectedItem < pthis->_iRoutingMethodIndexCount &&
  166. dwSelectedItem > 0 ) {
  167. tempRM = pthis->_pRoutingMethodIndex[ dwSelectedItem - 1 ];
  168. pthis->_pRoutingMethodIndex[ dwSelectedItem - 1 ] = pthis->_pRoutingMethodIndex[ dwSelectedItem ];
  169. pthis->_pRoutingMethodIndex[ dwSelectedItem ] = tempRM;
  170. hwndSheet = GetParent( hwndDlg );
  171. pthis->PopulateListBox( hwndDlg );
  172. SetFocus( hwnd );
  173. SendMessage( hwnd, LB_SETCURSEL, dwSelectedItem - 1 , 0 );
  174. PropSheet_Changed( hwndSheet, hwndDlg );
  175. }
  176. }
  177. break;
  178. }
  179. case IDC_ROUTEPRI_DOWN:
  180. {
  181. DebugPrint(( TEXT(" ++++++++++++++ CFaxRoutePriPropSheet::DlgProc -- DOWN button pushed \n") ));
  182. //
  183. // handle click here!
  184. //
  185. PFAX_GLOBAL_ROUTING_INFO tempRM;
  186. dwSelectedItem = (DWORD)SendMessage( hwnd, LB_GETCURSEL, 0, 0 );
  187. if( dwSelectedItem != LB_ERR ) {
  188. if( dwSelectedItem < pthis->_iRoutingMethodIndexCount - 1 &&
  189. dwSelectedItem >= 0 ) {
  190. tempRM = pthis->_pRoutingMethodIndex[ dwSelectedItem + 1 ];
  191. pthis->_pRoutingMethodIndex[ dwSelectedItem + 1 ] = pthis->_pRoutingMethodIndex[ dwSelectedItem ];
  192. pthis->_pRoutingMethodIndex[ dwSelectedItem ] = tempRM;
  193. hwndSheet = GetParent( hwndDlg );
  194. pthis->PopulateListBox( hwndDlg );
  195. PropSheet_Changed( hwndSheet, hwndDlg );
  196. SetFocus( hwnd );
  197. SendMessage( hwnd, LB_SETCURSEL, dwSelectedItem + 1 , 0 );
  198. }
  199. }
  200. break;
  201. }
  202. default:
  203. break;
  204. } // switch
  205. break;
  206. }
  207. }
  208. fRet = TRUE;
  209. break;
  210. }
  211. case WM_HELP:
  212. WinHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle,
  213. FAXCFG_HELP_FILENAME,
  214. HELP_WM_HELP,
  215. (ULONG_PTR) &RoutingPriorityHelpIDs);
  216. fRet = TRUE;
  217. break;
  218. case WM_CONTEXTMENU:
  219. WinHelp((HWND) wParam,
  220. FAXCFG_HELP_FILENAME,
  221. HELP_CONTEXTMENU,
  222. (ULONG_PTR) &RoutingPriorityHelpIDs);
  223. fRet = TRUE;
  224. break;
  225. case WM_NOTIFY:
  226. {
  227. // DebugPrint(( TEXT("CFaxRoutePriPropSheet::DlgProc -- WM_NOTIFY\n") ));
  228. CFaxRoutePriPropSheet * pthis =
  229. (CFaxRoutePriPropSheet *)GetWindowLongPtr( hwndDlg,
  230. DWLP_USER );
  231. switch( ((LPNMHDR) lParam)->code ) {
  232. case PSN_APPLY:
  233. // apply changes here!!
  234. DebugPrint(( TEXT(" ++++++++++++++ CFaxRoutePriPropSheet::DlgProc -- APPLY button pushed \n") ));
  235. if( FAILED( pthis->UpdateData( hwndDlg ) ) ) {
  236. fRet = FALSE;
  237. break;
  238. }
  239. // deactivate apply button
  240. hwndSheet = GetParent( hwndDlg );
  241. PropSheet_UnChanged( hwndSheet, hwndDlg );
  242. fRet = TRUE;
  243. break;
  244. case PSN_SETACTIVE:
  245. // refresh the page in case the user enabled some routing methods
  246. DebugPrint(( TEXT(" ++++++++++++++ CFaxRoutePriPropSheet::DlgProc -- PAGE ACTIVATED \n") ));
  247. if( FAILED( pthis->GetData() ) ) {
  248. fRet = FALSE;
  249. break;
  250. }
  251. pthis->PopulateListBox( hwndDlg );
  252. fRet = TRUE;
  253. break;
  254. } // switch
  255. break;
  256. }
  257. case WM_DESTROY:
  258. {
  259. DebugPrint(( TEXT("CFaxRoutePriPropSheet::DlgProc -- WM_DESTROY\n") ));
  260. CFaxRoutePriPropSheet * pthis =
  261. (CFaxRoutePriPropSheet *)GetWindowLongPtr( hwndDlg,
  262. DWLP_USER );
  263. if( pthis != NULL ) {
  264. // MMCFreeNotifyHandle( pthis->_hMmcNotify );
  265. // BUGBUG MMCFreeNotifyHandle is called from the general property page.
  266. // It can only be called ONCE!!!
  267. if( pthis->_pComp != NULL ) {
  268. pthis->_pComp->DecPropSheetCount();
  269. } else {
  270. pthis->_pCompData->DecPropSheetCount();
  271. }
  272. }
  273. fRet = TRUE;
  274. break;
  275. }
  276. } // switch
  277. return fRet;
  278. }
  279. ////////////////////////////////////////////////////////////////////////////////////////////////////
  280. ////////////////////////////////////////////////////////////////////////////////////////////////////
  281. ////////////////////////////////////////////////////////////////////////////////////////////////////
  282. ////////////////////////////////////////////////////////////////////////////////////////////////////
  283. //
  284. //
  285. // Internal Functions.
  286. //
  287. //
  288. HRESULT
  289. CFaxRoutePriPropSheet::UpdateData(
  290. HWND hwndDlg
  291. )
  292. /*++
  293. Routine Description:
  294. This routine writes the data manipulated in the property page out to the
  295. fax service.
  296. The settings are updated in the property sheet because this
  297. allows the property sheet to complete even if the owner node
  298. has already been destroyed.
  299. Arguments:
  300. hwndDlg - the dialog's window handle
  301. Return Value:
  302. HRESULT indicating SUCCEDED() or FAILED()
  303. --*/
  304. {
  305. DebugPrint(( TEXT("Trace: CInternalDevice::UpdateData") ));
  306. HRESULT hr = S_OK;
  307. assert( hwndDlg != NULL );
  308. try {
  309. do {
  310. if( _pCompData->QueryRpcError() == TRUE ) {
  311. assert( FALSE );
  312. hr = E_UNEXPECTED;
  313. break;
  314. }
  315. for( DWORD i = 0; i < _iRoutingMethodIndexCount; i++ ) {
  316. _pRoutingMethodIndex[ i ]->Priority = i + 1;
  317. if( !FaxSetGlobalRoutingInfo( _hFaxServer,
  318. _pRoutingMethodIndex[ i ] )
  319. ) {
  320. if (GetLastError() != ERROR_ACCESS_DENIED) {
  321. _pCompData->NotifyRpcError( TRUE );
  322. assert(FALSE);
  323. }
  324. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  325. hr = E_UNEXPECTED;
  326. break;
  327. }
  328. }
  329. } while( 0 );
  330. } catch( ... ) {
  331. _pCompData->NotifyRpcError( TRUE );
  332. assert(FALSE);
  333. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  334. hr = E_UNEXPECTED;
  335. }
  336. return hr;
  337. }
  338. HRESULT
  339. CFaxRoutePriPropSheet::PopulateListBox(
  340. HWND hwndDlg
  341. )
  342. /*++
  343. Routine Description:
  344. Populates the List Box containg the routing extensions.
  345. Arguments:
  346. hwndDlg - the dialog's window handle
  347. Return Value:
  348. HRESULT indicating SUCCEDED() or FAILED()
  349. --*/
  350. {
  351. HRESULT hr = S_OK;
  352. HWND hwnd;
  353. TCHAR buffer[80];
  354. ZeroMemory( (PVOID)buffer, sizeof( TCHAR ) * 80 );
  355. // populate the list box
  356. do {
  357. hwnd = GetDlgItem( hwndDlg, IDC_ROUTE_EXTS );
  358. // clear the list box
  359. SendMessage( hwnd, LB_RESETCONTENT, 0, 0 );
  360. // verify the index has been created
  361. if( _pRoutingMethodIndex == NULL ) {
  362. assert( FALSE );
  363. hr = E_UNEXPECTED;
  364. break;
  365. }
  366. // insert the string into the list box
  367. for( DWORD i = 0; i < _iRoutingMethodIndexCount; i ++ ) {
  368. if( _pRoutingMethodIndex[i] != NULL ) {
  369. SendMessage( hwnd, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) _pRoutingMethodIndex[i]->FriendlyName );
  370. }
  371. }
  372. } while( 0 );
  373. return hr;
  374. }
  375. HRESULT
  376. CFaxRoutePriPropSheet::GetData()
  377. /*++
  378. Routine Description:
  379. Gets data from the fax service.
  380. Arguments:
  381. None.
  382. Return Value:
  383. HRESULT indicating SUCCEDED() or FAILED()
  384. --*/
  385. {
  386. HRESULT hr = S_OK;
  387. try {
  388. do {
  389. if( _pRoutingMethod != NULL ) {
  390. FaxFreeBuffer( (PVOID)_pRoutingMethod );
  391. _pRoutingMethod = NULL;
  392. _iRoutingMethodCount = 0;
  393. }
  394. if( _pRoutingMethodIndex != NULL ) {
  395. delete _pRoutingMethodIndex;
  396. _pRoutingMethodIndex = NULL;
  397. _iRoutingMethodIndexCount = 0;
  398. }
  399. if( _pCompData->QueryRpcError() == TRUE ) {
  400. assert( FALSE );
  401. hr = E_UNEXPECTED;
  402. break;
  403. }
  404. // get the routing methods
  405. if( !FaxEnumGlobalRoutingInfo( _hFaxServer, &_pRoutingMethod, &_iRoutingMethodCount ) ) {
  406. if (GetLastError() != ERROR_ACCESS_DENIED) {
  407. _pCompData->NotifyRpcError( TRUE );
  408. assert(FALSE);
  409. }
  410. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  411. hr = E_UNEXPECTED;
  412. break;
  413. }
  414. // build the index
  415. _iRoutingMethodIndexCount = _iRoutingMethodCount;
  416. _pRoutingMethodIndex = new PFAX_GLOBAL_ROUTING_INFO[ _iRoutingMethodCount ];
  417. if (!_pRoutingMethodIndex) {
  418. hr = E_OUTOFMEMORY;
  419. break;
  420. }
  421. ZeroMemory( (PVOID) _pRoutingMethodIndex,
  422. sizeof( PFAX_GLOBAL_ROUTING_INFO ) * _iRoutingMethodCount );
  423. // setup the index
  424. for( DWORD i = 0; i < _iRoutingMethodCount; i ++ ) {
  425. _pRoutingMethodIndex[i] = &(_pRoutingMethod[i]);
  426. }
  427. } while( 0 );
  428. } catch( ... ) {
  429. _pCompData->NotifyRpcError( TRUE );
  430. assert(FALSE);
  431. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  432. hr = E_UNEXPECTED;
  433. }
  434. return hr;
  435. }
  436. UINT
  437. CALLBACK
  438. CFaxRoutePriPropSheet::PropSheetPageProc(
  439. HWND hwnd,
  440. UINT uMsg,
  441. LPPROPSHEETPAGE ppsp
  442. )
  443. /*++
  444. Routine Description:
  445. Dialog Init and destroy routine
  446. Arguments:
  447. hwndDlg - the hwnd of the dialog - will be NULL
  448. uMsg - the message PSPCB_CREATE or PSPCB_RELEASE
  449. ppsp - pointer to a PROPERTYSHEETPAGE struct
  450. Return Value:
  451. UINT - nonzero to allow, zero to fail
  452. --*/
  453. {
  454. CFaxRoutePriPropSheet * pthis = NULL;
  455. UINT retval = 1;
  456. // release my property sheet
  457. if( uMsg == PSPCB_RELEASE ) {
  458. try {
  459. pthis = (CFaxRoutePriPropSheet * )(ppsp->lParam);
  460. delete pthis;
  461. } catch( ... ) {
  462. assert( FALSE );
  463. retval = 0;
  464. }
  465. }
  466. return retval;
  467. }