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.

551 lines
15 KiB

  1. // fcnvw.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "FaxApi.h"
  5. #include "fcnselvw.h"
  6. #include "fcninfvw.h"
  7. #include "exelogvw.h"
  8. #include "rvoutvw.h"
  9. #include "paramvw.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. extern CFaxApiApp * pFaxApiBrowserApp;
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CFaxApiFunctionSelectionFormView
  18. IMPLEMENT_DYNCREATE(CFaxApiFunctionSelectionFormView, CFormView)
  19. CFaxApiFunctionSelectionFormView::CFaxApiFunctionSelectionFormView()
  20. : CFormView(CFaxApiFunctionSelectionFormView::IDD)
  21. {
  22. //{{AFX_DATA_INIT(CFaxApiFunctionSelectionFormView)
  23. // NOTE: the ClassWizard will add member initialization here
  24. //}}AFX_DATA_INIT
  25. }
  26. CFaxApiFunctionSelectionFormView::~CFaxApiFunctionSelectionFormView()
  27. {
  28. }
  29. void CFaxApiFunctionSelectionFormView::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CFormView::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CFaxApiFunctionSelectionFormView)
  33. // NOTE: the ClassWizard will add DDX and DDV calls here
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(CFaxApiFunctionSelectionFormView, CFormView)
  37. //{{AFX_MSG_MAP(CFaxApiFunctionSelectionFormView)
  38. ON_LBN_DBLCLK(IDC_LISTBOX_FAX_API_FUNCTIONS, OnDblclkListboxFaxApiFunctions)
  39. ON_LBN_SELCHANGE(IDC_LISTBOX_FAX_API_FUNCTIONS, OnSelchangeListboxFaxApiFunctions)
  40. ON_BN_CLICKED(IDC_BUTTON_EXECUTE_API_FUNCTION, OnButtonExecuteApiFunction)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CFaxApiFunctionSelectionFormView diagnostics
  45. #ifdef _DEBUG
  46. void CFaxApiFunctionSelectionFormView::AssertValid() const
  47. {
  48. CFormView::AssertValid();
  49. }
  50. void CFaxApiFunctionSelectionFormView::Dump(CDumpContext& dc) const
  51. {
  52. CFormView::Dump(dc);
  53. }
  54. #endif //_DEBUG
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CFaxApiFunctionSelectionFormView message handlers
  57. BOOL CFaxApiFunctionSelectionFormView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  58. {
  59. BOOL fReturnValue;
  60. fReturnValue = CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  61. if ( fReturnValue != (BOOL) FALSE )
  62. {
  63. // Save the handle to this view in the CFaxApiApp object.
  64. pFaxApiBrowserApp->StoreFaxApiFunctionSelectionFormViewHWND( m_hWnd );
  65. int xItemIndex;
  66. int xNumApiFunctions;
  67. // Get a pointer to the Fax Api Function list.
  68. CString csFunctionName;
  69. CListBox * pclbFaxApiFunctionList;
  70. pclbFaxApiFunctionList = (CListBox *) ( (CDialog *) this)->
  71. GetDlgItem( IDC_LISTBOX_FAX_API_FUNCTIONS );
  72. // Is the pointer valid ?
  73. if ( pclbFaxApiFunctionList != (CListBox *) NULL )
  74. {
  75. /* Empty the listbox. */
  76. pclbFaxApiFunctionList->ResetContent();
  77. int xRV;
  78. xNumApiFunctions = pFaxApiBrowserApp->GetNumberOfFaxApiFunctions();
  79. if ( xNumApiFunctions > 0 )
  80. {
  81. CFaxApiFunctionInfo * pcfafiFunctionInfo;
  82. for ( xItemIndex = 0; xItemIndex < xNumApiFunctions; xItemIndex++ )
  83. {
  84. pcfafiFunctionInfo = pFaxApiBrowserApp->GetFaxApiFunctionInfoPointer( xItemIndex );
  85. csFunctionName = pcfafiFunctionInfo->GetFunctionName();
  86. xRV = pclbFaxApiFunctionList->InsertString( xItemIndex,
  87. (LPCTSTR) csFunctionName );
  88. if ( (xRV == LB_ERR) || (xRV == LB_ERRSPACE) )
  89. {
  90. fReturnValue = (BOOL) FALSE;
  91. break; // terminate the loop on error !
  92. }
  93. } // end of for loop
  94. }
  95. /* Disable the "Execute API Function" button. A selection must be made */
  96. /* before the Execute Fax API function button gets enabled. */
  97. DisableExecuteButton();
  98. fReturnValue = (BOOL) TRUE;
  99. }
  100. else
  101. {
  102. fReturnValue = (BOOL) FALSE;
  103. }
  104. }
  105. return ( fReturnValue );
  106. }
  107. /*
  108. * OnSelchangeListboxFaxApiFunctions
  109. *
  110. * Purpose:
  111. * This function handles the LBN_SELCHANGE messages from the
  112. * Fax API function listbox.
  113. *
  114. * Arguments:
  115. * None
  116. *
  117. * Returns:
  118. * None
  119. *
  120. */
  121. void CFaxApiFunctionSelectionFormView::OnSelchangeListboxFaxApiFunctions()
  122. {
  123. // Get a pointer to the Fax API Function Information object.
  124. CFaxApiFunctionInfo * pcfafiFunctionInfo;
  125. pcfafiFunctionInfo = GetSelectedFaxApiFunctionInfoPointer();
  126. // Is the pointer to the Fax API Function Info object valid ?
  127. if ( pcfafiFunctionInfo != (CFaxApiFunctionInfo *) NULL )
  128. {
  129. /*************************************/
  130. /* Update the controls on this view. */
  131. /*************************************/
  132. // Get the name of the selected Fax API function.
  133. CString csFaxApiFunctionName;
  134. csFaxApiFunctionName = pcfafiFunctionInfo->GetFunctionName();
  135. // Update the text of the "execute" button. Start by getting a
  136. // pointer to the button.
  137. CWnd * pcwndExecuteButton;
  138. pcwndExecuteButton = ((CDialog *) this)->
  139. GetDlgItem( IDC_BUTTON_EXECUTE_API_FUNCTION );
  140. // Is the pointer valid ?
  141. if ( pcwndExecuteButton != (CWnd *) NULL )
  142. {
  143. /* Enable the "Execute API Function" button. */
  144. pcwndExecuteButton->EnableWindow( (BOOL) TRUE );
  145. /* Update the text on the button face. */
  146. CString csButtonFace;
  147. // Note: this needs to be smart enough to determine whether the
  148. // string created by the following statement will fit on
  149. // the button face. Call GetTextMetrics
  150. csButtonFace.Format( TEXT("Execute %s"), csFaxApiFunctionName );
  151. pcwndExecuteButton->SetWindowText( csButtonFace );
  152. }
  153. // Update the Remarks edit control. Start by getting a pointer to
  154. // the Remarks edit control.
  155. CEdit * pceRemarksEditCtrl;
  156. pceRemarksEditCtrl = (CEdit *) ((CDialog *) this)->GetDlgItem( IDC_EDIT_REMARKS );
  157. // Is the pointer valid ?
  158. if ( pceRemarksEditCtrl != (CEdit *) NULL )
  159. {
  160. // Update the Remarks edit control.
  161. CString csRemarks;
  162. csRemarks = pcfafiFunctionInfo->GetRemarks();
  163. pceRemarksEditCtrl->SetWindowText( csRemarks );
  164. }
  165. /***************************/
  166. /* Update the other views. */
  167. /***************************/
  168. // Update the CFunctionInfoFormView.
  169. CFunctionInfoFormView * pcFunctionInfoFormView;
  170. // Get a pointer to the CFunctionInfoFormView object.
  171. pcFunctionInfoFormView = (CFunctionInfoFormView *) pFaxApiBrowserApp->
  172. GetFunctionInfoFormViewPointer();
  173. // Is the pointer valid ?
  174. if ( pcFunctionInfoFormView != (CFunctionInfoFormView *) NULL )
  175. {
  176. // Update the Function Prototype edit control.
  177. CString csFaxApiFunctionPrototype;
  178. csFaxApiFunctionPrototype = pcfafiFunctionInfo->GetFunctionPrototype();
  179. pcFunctionInfoFormView->
  180. UpdateFunctionPrototypeEditCtrl( (CString &) csFaxApiFunctionPrototype );
  181. // Update the Return Value Description edit control.
  182. CString csReturnValueDescription;
  183. csReturnValueDescription = pcfafiFunctionInfo->GetReturnValueDescription();
  184. pcFunctionInfoFormView->
  185. UpdateReturnValueDescriptionEditCtrl( (CString &) csReturnValueDescription );
  186. }
  187. // Update the CParameterInfoFormView.
  188. CParameterInfoFormView * pcParameterInfoFormView;
  189. // Get a pointer to the CParameterInfoFormView object.
  190. pcParameterInfoFormView = (CParameterInfoFormView *) pFaxApiBrowserApp->
  191. GetParameterInfoFormViewPointer();
  192. // Is the pointer valid ?
  193. if ( pcParameterInfoFormView != (CParameterInfoFormView *) NULL )
  194. {
  195. // Update the Parameter List.
  196. pcParameterInfoFormView->UpdateParameterListbox( pcfafiFunctionInfo );
  197. // Clear the remainder of the CParameterInfoFormView because
  198. // unless the same Fax Api function has been reselected in the list,
  199. // no parameter can be selected.
  200. // Note: this does NOT clear the parameter list !
  201. pcParameterInfoFormView->ClearParameterEditControlFamily();
  202. }
  203. // Clear the Return Value Output view because selection of a Fax API
  204. // function in this view means that whatever is in the Return Value Output
  205. // Form View is invalid.
  206. CReturnValueOutputFormView * pcReturnValueOutputFormView;
  207. // Get a pointer to the CReturnValueOutputFormView object.
  208. pcReturnValueOutputFormView = (CReturnValueOutputFormView *) pFaxApiBrowserApp->
  209. GetReturnValueOutputFormViewPointer();
  210. // Is the pointer valid ?
  211. if ( pcReturnValueOutputFormView != (CReturnValueOutputFormView *) NULL )
  212. {
  213. pcReturnValueOutputFormView->ClearReturnValueOutputEditCtrl();
  214. }
  215. }
  216. else
  217. {
  218. /* Disable the "Execute API Function" button. */
  219. DisableExecuteButton();
  220. }
  221. }
  222. /*
  223. * DisableExecuteButton
  224. *
  225. * Purpose:
  226. * This function disables the Execute Fax API function button.
  227. *
  228. * Arguments:
  229. * None
  230. *
  231. * Returns:
  232. * TRUE - indicates that the button was disabled succesfully.
  233. * FALSE - indicates that some error occured.
  234. *
  235. */
  236. BOOL CFaxApiFunctionSelectionFormView::DisableExecuteButton( void )
  237. {
  238. BOOL fReturnValue;
  239. // Get a pointer to the Execute Fax API function button.
  240. CWnd * pcwndExecuteButton;
  241. pcwndExecuteButton = ((CDialog *) this)->
  242. GetDlgItem( IDC_BUTTON_EXECUTE_API_FUNCTION );
  243. // Is the pointer valid ?
  244. if ( pcwndExecuteButton != (CWnd *) NULL )
  245. {
  246. /* Update the text on the button face. */
  247. CString csButtonFace;
  248. csButtonFace = (CString) TEXT("Execute Fax API Function");
  249. pcwndExecuteButton->SetWindowText( csButtonFace );
  250. /* Disable the "Execute API Function" button. */
  251. pcwndExecuteButton->EnableWindow( (BOOL) FALSE );
  252. fReturnValue = (BOOL) TRUE;
  253. }
  254. else
  255. fReturnValue = (BOOL) FALSE;
  256. return ( fReturnValue );
  257. }
  258. void CFaxApiFunctionSelectionFormView::OnDblclkListboxFaxApiFunctions()
  259. {
  260. ExecuteFaxApiFunction();
  261. }
  262. void CFaxApiFunctionSelectionFormView::OnButtonExecuteApiFunction()
  263. {
  264. ExecuteFaxApiFunction();
  265. }
  266. BOOL CFaxApiFunctionSelectionFormView::ExecuteFaxApiFunction( void )
  267. {
  268. BOOL fReturnValue;
  269. // Get a pointer to the seleted CFaxApiFunctionInfo object.
  270. CFaxApiFunctionInfo * pcfafiFunctionInfo;
  271. pcfafiFunctionInfo = GetSelectedFaxApiFunctionInfoPointer();
  272. // Is the pointer to the Fax API Function Info object valid ?
  273. if ( pcfafiFunctionInfo != (CFaxApiFunctionInfo *) NULL )
  274. {
  275. /* Update the Output Log view prior to executing the API function. */
  276. // Get a pointer to the CExecutionLogFormView object.
  277. CExecutionLogFormView * pcExecutionLogFormView;
  278. pcExecutionLogFormView = (CExecutionLogFormView *) pFaxApiBrowserApp->
  279. GetExecutionLogFormViewPointer();
  280. // Is the pointer to the CExecutionLogFormView object valid ?
  281. if ( pcExecutionLogFormView != (CExecutionLogFormView *) NULL )
  282. {
  283. pcExecutionLogFormView->UpdateExecutionLogBeforeApiCall( pcfafiFunctionInfo );
  284. /*******************************************/
  285. /* EXECUTE THE SELECTED FAX API FUNCTION ! */
  286. /*******************************************/
  287. //#ifdef TEST
  288. pcfafiFunctionInfo->Execute();
  289. //#endif // TEST
  290. /* Update the Return Value Output view. */
  291. // Get a pointer to the CReturnValueOutputFormView object.
  292. CReturnValueOutputFormView * pcReturnValueOutputFormView;
  293. pcReturnValueOutputFormView = (CReturnValueOutputFormView *) pFaxApiBrowserApp->
  294. GetReturnValueOutputFormViewPointer();
  295. // Is the pointer valid ?
  296. if ( pcReturnValueOutputFormView != (CReturnValueOutputFormView *) NULL )
  297. {
  298. CString csReturnValue;
  299. CString csText;
  300. pcfafiFunctionInfo->FormatReturnValueForOutput( (CString &) csReturnValue );
  301. csText.Format( TEXT("%s"), csReturnValue );
  302. pcReturnValueOutputFormView->
  303. UpdateReturnValueOutputEditCtrl( (CString &) csText );
  304. /* Update the Output Log view with the results of having */
  305. /* called the Fax API function. */
  306. pcExecutionLogFormView->
  307. UpdateExecutionLogAfterApiReturn( pcfafiFunctionInfo );
  308. }
  309. else
  310. {
  311. // Couldn't get a pointer to the CReturnValueOutputFormView object.
  312. fReturnValue = (BOOL) FALSE;
  313. }
  314. }
  315. else
  316. {
  317. // Couldn't get a pointer to the CExecutionLogFormView object.
  318. fReturnValue = (BOOL) FALSE;
  319. }
  320. }
  321. else
  322. {
  323. // Couldn't get a pointer to the CFaxApiFunctionInfo object for the
  324. // selected Fax API function.
  325. fReturnValue = (BOOL) FALSE;
  326. }
  327. return ( fReturnValue );
  328. }
  329. void CFaxApiFunctionSelectionFormView::OnInitialUpdate()
  330. {
  331. CFormView::OnInitialUpdate();
  332. // TODO: Add your specialized code here and/or call the base class
  333. }
  334. /*
  335. * GetSelectedFaxApiFunctionInfoPointer
  336. *
  337. * Purpose:
  338. * This function returns a pointer to the CFaxApiFunctionInfo object
  339. * that corresponds to the Fax API function that is selected in the
  340. * Fax API function listbox.
  341. *
  342. * Arguments:
  343. * None
  344. *
  345. * Returns:
  346. * A pointer to the CFaxApiFunctionInfo object that corresponds to
  347. * the current selection in the Fax API function listbox.
  348. *
  349. * If no function is selected in the listbox or any other error
  350. * occurs, this function returns (CFaxApiFunctionInfo) NULL.
  351. *
  352. */
  353. CFaxApiFunctionInfo * CFaxApiFunctionSelectionFormView::GetSelectedFaxApiFunctionInfoPointer()
  354. {
  355. CFaxApiFunctionInfo * pcfafiFunctionInfo;
  356. // Get a pointer to the Fax API function listbox.
  357. CListBox * pclbFaxApiFunctionList;
  358. pclbFaxApiFunctionList = (CListBox *) ((CDialog *) this)->
  359. GetDlgItem( IDC_LISTBOX_FAX_API_FUNCTIONS );
  360. // Is the pointer to the listbox valid ?
  361. if ( pclbFaxApiFunctionList != (CListBox *) NULL )
  362. {
  363. int xItemIndex;
  364. xItemIndex = pclbFaxApiFunctionList->GetCurSel();
  365. /* Is the item index valid */
  366. if ( xItemIndex != (int) LB_ERR )
  367. {
  368. // Get a pointer to the Fax API Function Information object.
  369. pcfafiFunctionInfo = pFaxApiBrowserApp->GetFaxApiFunctionInfoPointer( xItemIndex );
  370. }
  371. else
  372. {
  373. pcfafiFunctionInfo = (CFaxApiFunctionInfo *) NULL;
  374. }
  375. }
  376. else
  377. {
  378. pcfafiFunctionInfo = (CFaxApiFunctionInfo *) NULL;
  379. }
  380. return ( pcfafiFunctionInfo );
  381. }