home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / addins / api2help / options.cpp < prev    next >
C/C++ Source or Header  |  1998-04-02  |  6KB  |  251 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Options.cpp : implementation file
  3. //
  4.  
  5. // Copyright (C) 1992-1998 Microsoft Corporation
  6. // All rights reserved.
  7.  
  8. #include "stdafx.h"
  9. #include "API2Help.h"
  10. #include "Options.h"
  11. #include <afxtempl.h>
  12. #include <afxdlgs.h>
  13. #include "APISplit.h"
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // COptions dialog
  23.  
  24.  
  25. COptions::COptions(CString strSelectedAPI, CWnd* pParent /*=NULL*/)
  26.     : CDialog(COptions::IDD, pParent)
  27. {
  28.     m_strPrototype = strSelectedAPI;
  29.     //{{AFX_DATA_INIT(COptions)
  30.     //}}AFX_DATA_INIT
  31. }
  32.  
  33.  
  34. void COptions::DoDataExchange(CDataExchange* pDX)
  35. {
  36.     CDialog::DoDataExchange(pDX);
  37.     //{{AFX_DATA_MAP(COptions)
  38.     DDX_Control(pDX, IDC_TOPICIDEDIT, m_TopicID);
  39.     DDX_Control(pDX, IDC_TOPICNAME, m_TopicName);
  40.     DDX_Control(pDX, IDC_STATIC4, m_Static4);
  41.     DDX_Control(pDX, IDC_STATIC3, m_Static3);
  42.     DDX_Control(pDX, IDC_STATIC2, m_Static2);
  43.     DDX_Control(pDX, IDC_STATIC1, m_Static1);
  44.     DDX_Control(pDX, IDC_RTFFILENAME, m_RTFFileName);
  45.     DDX_Control(pDX, IDC_RTF, m_RTF);
  46.     DDX_Control(pDX, IDC_HTMLFILENAME, m_HTMLFileName);
  47.     DDX_Control(pDX, IDC_HTML, m_HTML);
  48.     DDX_Control(pDX, IDC_BROWSERTF, m_BrowseRTF);
  49.     DDX_Control(pDX, IDC_BROWSEHTML, m_BrowseHTML);
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53.  
  54. BEGIN_MESSAGE_MAP(COptions, CDialog)
  55.     //{{AFX_MSG_MAP(COptions)
  56.     ON_BN_CLICKED(IDC_HTML, OnHTML)
  57.     ON_BN_CLICKED(IDC_RTF, OnRTF)
  58.     ON_BN_CLICKED(IDC_BROWSEHTML, OnBrowseHTML)
  59.     ON_BN_CLICKED(IDC_BROWSERTF, OnBrowseRTF)
  60.     //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // COptions message handlers
  65.  
  66. void COptions::OnHTML()
  67. {
  68.     if (m_HTML.GetCheck() == 1)
  69.     {
  70.         m_Static3.EnableWindow();
  71.         m_HTMLFileName.EnableWindow();
  72.         m_BrowseHTML.EnableWindow();
  73.     }
  74.     else
  75.     {
  76.         m_Static3.EnableWindow(FALSE);
  77.         m_HTMLFileName.EnableWindow(FALSE);
  78.         m_BrowseHTML.EnableWindow(FALSE);
  79.     }
  80. }
  81.  
  82. void COptions::OnRTF()
  83. {
  84.     if (m_RTF.GetCheck() == 1)
  85.     {
  86.         m_Static1.EnableWindow();
  87.         m_Static2.EnableWindow();
  88.         m_Static4.EnableWindow();
  89.         m_RTFFileName.EnableWindow();
  90.         m_TopicID.EnableWindow();
  91.         m_TopicName.EnableWindow();
  92.         m_BrowseRTF.EnableWindow();
  93.     }
  94.     else
  95.     {
  96.         m_Static1.EnableWindow(FALSE);
  97.         m_Static2.EnableWindow(FALSE);
  98.         m_Static4.EnableWindow(FALSE);
  99.         m_RTFFileName.EnableWindow(FALSE);
  100.         m_TopicID.EnableWindow(FALSE);
  101.         m_TopicName.EnableWindow(FALSE);
  102.         m_BrowseRTF.EnableWindow(FALSE);
  103.     }
  104. }
  105.  
  106. void COptions::OnBrowseHTML()
  107. {
  108.     CString strFileSpec;
  109.     strFileSpec.LoadString(IDS_HTMLFILESPEC);
  110.     CFileDialog Browser(FALSE, "", "", OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  111.             strFileSpec);
  112.     if (Browser.DoModal() == IDOK)
  113.     {
  114.         m_HTMLFileName.SetWindowText(Browser.GetPathName());
  115.     }
  116. }
  117.  
  118. void COptions::OnBrowseRTF()
  119. {
  120.     CString strFileSpec;
  121.     strFileSpec.LoadString(IDS_RTFFILESPEC);
  122.     CFileDialog Browser(FALSE, "", "", OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  123.             strFileSpec);
  124.     if(Browser.DoModal() == IDOK)
  125.     {
  126.         m_RTFFileName.SetWindowText(Browser.GetPathName());
  127.     }
  128. }
  129.  
  130. void COptions::OnOK()
  131. {
  132.     if ((m_RTF.GetCheck() == 0) && (m_HTML.GetCheck() == 0))
  133.     {
  134.         CString strNoneSel;
  135.         strNoneSel.LoadString(IDS_NONESEL);
  136.         AfxMessageBox(strNoneSel);
  137.         return;
  138.     }
  139.     else
  140.     {
  141.         BOOL bRTF = FALSE;
  142.         BOOL bHTML = FALSE;
  143.         CString strFuncName;
  144.         CString strNewFunc;
  145.         CString strReturn;
  146.         CString strSuggestedReturn;
  147.         CString strParameters;
  148.         CArray<CString,CString> Scoping;
  149.         CArray<CString,CString> ReturnsArray;
  150.         CArray<CString,CString> ParamList;
  151.         CArray<CString,CString> ParamNames;
  152.         CArray<CString,CString> ParamDescription;
  153.         int nAppendStar = 0;
  154.  
  155.         ConvertWSToSpace (m_strPrototype);
  156.  
  157.         //Remove all multiple instances of '  ' (double space).
  158.         RemoveUnnecessary(m_strPrototype);
  159.         int nBeginningOfParameters = GetParameters(strParameters, m_strPrototype,
  160.                 ParamList);
  161.  
  162.         strFuncName = m_strPrototype.Left(nBeginningOfParameters);
  163.         GetListOfParamNames(ParamList, ParamNames);
  164.  
  165.         //At this point, all parameters have been located.
  166.         //  Now find the function name
  167.         strFuncName.TrimRight();
  168.         strReturn = strFuncName;
  169.         strFuncName = strFuncName.Right(strFuncName.GetLength()-strFuncName.ReverseFind(' '));
  170.         strFuncName.TrimLeft();
  171.  
  172.         //Check to make sure there is a '(' and a ')', and the '(' is before the ')'
  173.         //strFuncName
  174.  
  175.         //Now, we have a function name, but this function could be of the form
  176.         //      class1::class2::...::classn::function. Try to split off each scope,
  177.         //      and build a list of these scopings (this list is not used in this
  178.         //  version).
  179.         GetFunctAndScope(strFuncName, Scoping, strNewFunc);
  180.  
  181.         //Remove '*' from the function name, and count them for adding
  182.         //  onto the return type.
  183.         if (strNewFunc != "")
  184.         {
  185.             while (strNewFunc[0] == '*')
  186.             {
  187.                 strNewFunc.SetAt(0,' ');
  188.                 strNewFunc.TrimLeft();
  189.                 nAppendStar++;
  190.             }
  191.         }
  192.  
  193.         GetReturnType(strReturn, ReturnsArray, strSuggestedReturn, nAppendStar);
  194.  
  195.         if ((m_RTF.GetCheck() == 0) && (m_HTML.GetCheck() == 0))
  196.             CDialog::OnOK();
  197.  
  198.         if (m_RTF.GetCheck() == 1)
  199.         {
  200.             CString strFileName;
  201.             m_RTFFileName.GetWindowText(strFileName);
  202.             strFileName.TrimLeft();
  203.             strFileName.TrimRight();
  204.             if (strFileName.GetLength() == 0)
  205.             {
  206.                 AfxMessageBox(IDS_NOFILE);
  207.                 return;
  208.             }
  209.             else if(m_TopicID.GetWindowTextLength() == 0)
  210.             {
  211.                 AfxMessageBox(IDS_NOTOPICID);
  212.                 return;
  213.             }
  214.             else if(m_TopicName.GetWindowTextLength() == 0)
  215.             {
  216.                 AfxMessageBox(IDS_NOTOPICNAME);
  217.                 return;
  218.             }
  219.             else
  220.             {
  221.                 CString strID, strTopicName;
  222.                 m_TopicID.GetWindowText(strID);
  223.                 m_TopicName.GetWindowText(strTopicName);
  224.                 GenerateHelpFile(strFileName, strFuncName, strNewFunc, ParamList,
  225.                         ParamNames, strSuggestedReturn, strID, strTopicName);
  226.             }
  227.         }
  228.  
  229.         if (m_HTML.GetCheck() == 1)
  230.         {
  231.             CString strFileName;
  232.             m_HTMLFileName.GetWindowText(strFileName);
  233.             strFileName.TrimLeft();
  234.             strFileName.TrimRight();
  235.             if (strFileName.GetLength() == 0)
  236.             {
  237.                 AfxMessageBox(IDS_NOFILEHTML);
  238.                 return;
  239.             }
  240.             else
  241.             {
  242.                 GenerateHTML(strFileName, strFuncName, strNewFunc, ParamList, ParamNames,
  243.                         strSuggestedReturn);
  244.             }
  245.         }
  246.  
  247.         AfxMessageBox(IDS_FINISHED);
  248.         CDialog::OnOK();
  249.     }
  250. }
  251.