home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F37585_InsSymb.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-16  |  7.6 KB  |  344 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // InsSymb.cpp : Implementation of CInsSymb
  12. #include "stdafx.h"
  13. #include "InsTool.h"
  14. #include "InsSymb.h"
  15. #include "TDialog.h"
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. //const IID IID_Tool = {0x6A48112C,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  19. //const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  20.  
  21.  
  22. // CInsSymb
  23.  
  24. STDMETHODIMP CInsSymb::InterfaceSupportsErrorInfo(REFIID riid)
  25. {
  26.     static const IID* arr[] = 
  27.     {
  28.         &IID_ITurboCADTool,
  29.     };
  30.     for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  31.     {
  32.         if (InlineIsEqualGUID(*arr[i],riid))
  33.             return S_OK;
  34.     }
  35.     return S_FALSE;
  36. }
  37.  
  38.  
  39. STDMETHODIMP CInsSymb::get_ClassID(BSTR* retval)
  40. {
  41.     HRESULT hRes = E_FAIL;
  42.     LPOLESTR olestr = NULL;
  43.  
  44.     try
  45.     {
  46.         *retval = NULL;
  47.  
  48.         hRes = ::StringFromCLSID(CLSID_InsSymb, &olestr);
  49.         CHECK_HRESULT(hRes)
  50.  
  51.         *retval = ::SysAllocString(olestr);
  52.  
  53.         hRes = S_OK;
  54.     }
  55.     catch (...)
  56.     {
  57.     
  58.         TRACE_EXCEPTION("CInsSymb::get_ClassID")
  59.         _clearfp();
  60.     }
  61.  
  62.     if (olestr != NULL)
  63.         CoTaskMemFree(olestr);
  64.  
  65.     return hRes;
  66. }
  67.  
  68. STDMETHODIMP CInsSymb::get_Description( BSTR* retval)
  69. {
  70.     HRESULT hRes = E_FAIL;
  71.     CString strResult;
  72.  
  73.     try
  74.     {
  75.         *retval = NULL;
  76.  
  77.         CString strResult;
  78.         strResult.LoadString(IDS_DESCRIPTION);
  79.         *retval =  strResult.AllocSysString();
  80.         hRes = S_OK;
  81.     }
  82.     catch (...)
  83.     {
  84.         TRACE_EXCEPTION("CInsSymb::get_Description")
  85.         _clearfp();
  86.     }
  87.     return hRes;
  88. }
  89.  
  90. /* ITurboCADTool methods: */
  91. STDMETHODIMP CInsSymb::GetToolInfo(VARIANT FAR* CommandNames,
  92.                                    VARIANT FAR* MenuCaptions,
  93.                                    VARIANT FAR* StatusPrompts,
  94.                                    VARIANT FAR* ToolTips,
  95.                                    VARIANT FAR* Enabled,
  96.                                    VARIANT FAR* WantsUpdates,
  97.                                    long FAR* retval)
  98. {
  99.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  100.  
  101.  
  102.     HRESULT hRes = E_FAIL;
  103.     
  104.     SAFEARRAYBOUND bound = {NUM_TOOLS, 0};
  105.  
  106.     CString cstrText;
  107.     CString cstrTextTemp;
  108.  
  109.     BSTR bstrCommandName = NULL;
  110.     BSTR bstrMenuCaption = NULL;
  111.     BSTR bstrStatusPrompt = NULL;
  112.     BSTR bstrToolTip = NULL;
  113.  
  114.     BOOL bEnabled = TRUE;
  115.     BOOL bWantsUpdates = TRUE;
  116.  
  117.     
  118.     long lIndicies = 0;
  119.     try
  120.     {
  121.         
  122.         hRes = SafeArrayRedim(CommandNames->parray, &bound);
  123.         CHECK_HRESULT(hRes)
  124.  
  125.         hRes = SafeArrayRedim(MenuCaptions->parray, &bound);
  126.         CHECK_HRESULT(hRes)
  127.  
  128.         hRes = SafeArrayRedim(StatusPrompts->parray, &bound);
  129.         CHECK_HRESULT(hRes)
  130.  
  131.         hRes = SafeArrayRedim(ToolTips->parray, &bound);
  132.         CHECK_HRESULT(hRes)
  133.  
  134.         hRes = SafeArrayRedim(Enabled->parray, &bound);
  135.         CHECK_HRESULT(hRes)
  136.  
  137.         hRes = SafeArrayRedim(WantsUpdates->parray, &bound);
  138.         CHECK_HRESULT(hRes)
  139.  
  140.         cstrText.LoadString (IDS_MAINMENU);
  141.         cstrText.Insert(cstrText.GetLength (), '|');
  142.         cstrTextTemp.LoadString (IDS_SUBMENU);
  143.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  144.         cstrText.Insert(cstrText.GetLength (), '|');
  145.         cstrTextTemp.LoadString (IDS_MENUCAPTION);
  146.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  147.         cstrTextTemp.Empty ();
  148.  
  149.         bstrCommandName = cstrText.AllocSysString();
  150.         hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName);
  151.         CHECK_HRESULT(hRes)
  152.  
  153.         cstrText.Empty ();
  154.         cstrText.LoadString (IDS_MENUCAPTION); 
  155.         bstrMenuCaption = cstrText.AllocSysString();
  156.         hRes = SafeArrayPutElement(MenuCaptions->parray, &lIndicies, (void *)bstrMenuCaption);
  157.         CHECK_HRESULT(hRes)
  158.  
  159.         cstrText.Empty ();
  160.          cstrText.LoadString (IDS_PROMT);
  161.         bstrStatusPrompt = cstrText.AllocSysString();
  162.         hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt);
  163.         CHECK_HRESULT(hRes)
  164.  
  165.         cstrText.LoadString (IDS_TOOLTIPS);; 
  166.         bstrToolTip = cstrText.AllocSysString();
  167.         hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip);
  168.         CHECK_HRESULT(hRes)
  169.  
  170.         hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled);
  171.         CHECK_HRESULT(hRes)
  172.  
  173.         hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates);
  174.         CHECK_HRESULT(hRes)
  175.  
  176.         *retval = NUM_TOOLS;
  177.     }
  178.     catch (...)
  179.     {
  180.         if (SUCCEEDED(hRes))
  181.             hRes = E_FAIL;
  182.         TRACE_EXCEPTION("CInsSymb::GetToolInfo")
  183.         _clearfp();
  184.     }
  185.     return hRes;
  186. }
  187.  
  188. STDMETHODIMP CInsSymb::CopyBitmap( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, VARIANT_BOOL FAR* retval)
  189. {
  190.     HRESULT hRes = E_FAIL;
  191.     try
  192.     {
  193.         CHECK_HRESULT(hRes)
  194.         hRes = S_OK;
  195.     }
  196.     catch (...)
  197.     {
  198.         TRACE_EXCEPTION("CInsSymb::CopyBitmap")
  199.         _clearfp();
  200.     }
  201.     return hRes;
  202. }
  203.  
  204. STDMETHODIMP CInsSymb::GetPicture( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch** retval)
  205. {
  206.     HRESULT hRes = E_FAIL;
  207.     try
  208.     {
  209.         CHECK_HRESULT(hRes)
  210.         hRes = S_OK;
  211.     }
  212.     catch (...)
  213.     {
  214.         TRACE_EXCEPTION("CAALBTool::GetPicture")
  215.         _clearfp();
  216.     }
  217.     return hRes;
  218. }
  219.  
  220. STDMETHODIMP CInsSymb::Run( IDispatch* ThisTool, VARIANT_BOOL FAR* retval)
  221. {
  222.     CWnd *pMainWnd = AfxGetMainWnd();
  223.  
  224.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  225.  
  226.     CInsToolApp *pApp = (CInsToolApp *)AfxGetApp();
  227.  
  228.     HRESULT hRes = E_FAIL;
  229.  
  230.     Tool *pThisTool = NULL;
  231.     IApplication *pIApp = NULL;
  232.  
  233.     IGraphic *pIGr = NULL;
  234.     Graphics *pGrs = NULL;
  235.  
  236.     IDrawing *pIDwg = NULL;
  237.  
  238.     Views *pVis = NULL;
  239.     View  *pVi = NULL;
  240.  
  241.     PickResult *pPickRes=NULL;
  242.     PickEntry *pPickEnt=NULL;
  243.  
  244.     RegenMethods *pRegMets=NULL;
  245.     RegenMethod *pIRegMet=NULL;
  246.  
  247.     COleVariant varAperture(0.2);
  248.     COleVariant varItem;
  249.     long lItem = 0;
  250.     long lIndex = 0;
  251.  
  252.     COleVariant varOptional(varMissing);
  253.     COleVariant varType((const long)imsiPolyline);
  254.     
  255.     VARIANT_BOOL    varCopy = FALSE;
  256.     VARIANT_BOOL    varRetval = FALSE;
  257.  
  258.     long lID = 0;
  259.  
  260.     BSTR bstrType = NULL;
  261.     CString    strType;
  262.  
  263.     BSTR bstrDescription=NULL;
  264.     CString strDescription;
  265.  
  266.     BSTR bstrName=NULL;
  267.     CString strName;
  268.  
  269.     HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  270.  
  271.     try
  272.     {
  273.  
  274.         hRes = ThisTool->QueryInterface(IID_Tool, (void **)&pThisTool);
  275.         CHECK_HRESULT(hRes)
  276.  
  277.         hRes = pThisTool->get_Application(&pIApp);
  278.         CHECK_HRESULT(hRes)
  279.  
  280.         CTDialog *pdlg = new CTDialog(this, pMainWnd, pThisTool);
  281.         pdlg->Create(CTDialog::IDD, NULL /*pMainWnd*/);
  282.  
  283.         VARIANT_BOOL    varRetval1 = false;
  284.         
  285.         hRes = UpdateToolStatus(ThisTool, &varRetval1, &varRetval1, &varRetval1);    
  286.         CHECK_HRESULT(hRes)
  287.  
  288.         pThisTool->Release();    
  289.         pThisTool = NULL;
  290.  
  291.         hRes = S_OK;
  292.     }
  293.     catch (...)
  294.     {
  295.         TRACE_EXCEPTION("CInsSymb::Run")
  296.         _clearfp();
  297.     }
  298.  
  299.     RELEASE(pThisTool)
  300.     RELEASE(pIApp)
  301.     ::SetCursor(hOC);
  302.  
  303.     return hRes;
  304. }
  305.  
  306. STDMETHODIMP CInsSymb::UpdateToolStatus(IDispatch* ThisTool, VARIANT_BOOL FAR* Enabled, VARIANT_BOOL FAR* Checked, VARIANT_BOOL FAR* retval)
  307. {
  308.     HRESULT hRes = E_FAIL;
  309.  
  310.     try
  311.     {
  312.         if(m_bRunned == TRUE) 
  313.         {
  314.             (*Enabled) = false;
  315.         }
  316.         *retval = TRUE;
  317.         hRes = S_OK;
  318.     }
  319.     catch (...)
  320.     {
  321.         TRACE_EXCEPTION("CInsSymb::UpdateToolStatus")
  322.         _clearfp();
  323.     }
  324.  
  325.     return hRes;
  326. }
  327.  
  328. STDMETHODIMP CInsSymb::Initialize( IDispatch * ThisTool, VARIANT_BOOL FAR* retval)
  329. {
  330.     HRESULT hRes = E_FAIL;
  331.     try
  332.     {
  333.         m_pTCState = AfxGetModuleState();
  334.         *retval = TRUE;
  335.         hRes = S_OK;
  336.     }
  337.     catch (...)
  338.     {
  339.         TRACE_EXCEPTION("CInsSymb::Initialize")
  340.         _clearfp();
  341.     }
  342.     return hRes;
  343. }
  344.