home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / smobj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-17  |  7.2 KB  |  316 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. // Tool.cpp : Implementation of CDCMTool
  12. #include "stdafx.h"
  13. #include "InsSmObj.h"
  14. #include "SmObj.h"
  15. #include "SdiDialog.h"
  16.  
  17. #include <afxwin.h>
  18.  
  19. const IID IID_Tool = {0x6A48112C,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  20. const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23.  
  24. STDMETHODIMP CInsSmObj::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.     /* ITurboCADTool properties: */
  39. STDMETHODIMP CInsSmObj::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_InsSmObj, &olestr);
  49.         CHECK_HRESULT(hRes)
  50.  
  51.         *retval = ::SysAllocString(olestr);
  52.  
  53.         hRes = S_OK;
  54.     }
  55.     catch (...)
  56.     {
  57.         TRACE_EXCEPTION("CInsSmObj::get_ClassID")
  58.     }
  59.  
  60.     if (olestr != NULL)
  61.         CoTaskMemFree(olestr);
  62.  
  63.     return hRes;
  64. }
  65.  
  66. STDMETHODIMP CInsSmObj::get_Description( BSTR* retval)
  67. {
  68.  
  69.     HRESULT hRes = E_FAIL;
  70.     CString strResult;
  71.     *retval = NULL;
  72.  
  73.     try
  74.     {
  75.         if (strResult.LoadString(IDS_DESCRIPTION))
  76.         {
  77.             hRes = S_OK;
  78.             *retval = strResult.AllocSysString();
  79.         }
  80.     }
  81.     catch (...)
  82.     {
  83.         TRACE_EXCEPTION("CInsSmObj::get_Description")
  84.     }
  85.  
  86.     return hRes;
  87.  
  88. }
  89.  
  90. /* ITurboCADTool methods: */
  91. STDMETHODIMP CInsSmObj::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.     BOOL bEnabled = TRUE;
  114.     BOOL bWantsUpdates = TRUE;
  115.  
  116.     
  117.     long lIndicies = 0;
  118.     try
  119.     {
  120.         
  121.         hRes = SafeArrayRedim(CommandNames->parray, &bound);
  122.         CHECK_HRESULT(hRes)
  123.  
  124.         hRes = SafeArrayRedim(MenuCaptions->parray, &bound);
  125.         CHECK_HRESULT(hRes)
  126.  
  127.         hRes = SafeArrayRedim(StatusPrompts->parray, &bound);
  128.         CHECK_HRESULT(hRes)
  129.  
  130.         hRes = SafeArrayRedim(ToolTips->parray, &bound);
  131.         CHECK_HRESULT(hRes)
  132.  
  133.         hRes = SafeArrayRedim(Enabled->parray, &bound);
  134.         CHECK_HRESULT(hRes)
  135.  
  136.         hRes = SafeArrayRedim(WantsUpdates->parray, &bound);
  137.         CHECK_HRESULT(hRes)
  138.  
  139. // construct menu item for this tool : Main Menu + SubMenu + Menu Caption of this tool
  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.         cstrText += "#CMD_SDKINSERTCUSTOMOBJECT";
  150.  
  151.         bstrCommandName = cstrText.AllocSysString();
  152.         hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName);
  153.         CHECK_HRESULT(hRes)
  154.  
  155.         cstrText.Empty ();
  156.         cstrText.LoadString (IDS_MENUCAPTION); 
  157.         bstrMenuCaption = cstrText.AllocSysString();
  158.         hRes = SafeArrayPutElement(MenuCaptions->parray, &lIndicies, (void *)bstrMenuCaption);
  159.         CHECK_HRESULT(hRes)
  160.  
  161.           cstrText.LoadString (IDS_PROMT);
  162.         bstrStatusPrompt = cstrText.AllocSysString();
  163.         hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt);
  164.         CHECK_HRESULT(hRes)
  165.  
  166.         cstrText.LoadString (IDS_TOOLTIPS);
  167.         bstrToolTip = cstrText.AllocSysString();
  168.         hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip);
  169.         CHECK_HRESULT(hRes)
  170.  
  171.         hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled);
  172.         CHECK_HRESULT(hRes)
  173.  
  174.         hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates);
  175.         CHECK_HRESULT(hRes)
  176.  
  177.         *retval = NUM_TOOLS;
  178.     }
  179.     catch (...)
  180.     {
  181.         if (SUCCEEDED(hRes))
  182.             hRes = E_FAIL;
  183.         TRACE_EXCEPTION("CInsSmObj::GetToolInfo")
  184.     }
  185.     return hRes;
  186. }
  187.  
  188. STDMETHODIMP CInsSmObj::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("CInsSmObj::CopyBitmap")
  199.     }
  200.     return hRes;
  201. }
  202.  
  203. STDMETHODIMP CInsSmObj::GetPicture( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch** retval)
  204. {
  205.     HRESULT hRes = E_FAIL;
  206.     try
  207.     {
  208.         CHECK_HRESULT(hRes)
  209.         hRes = S_OK;
  210.     }
  211.     catch (...)
  212.     {
  213.         TRACE_EXCEPTION("CInsSmObj::GetPicture")
  214.     }
  215.     return hRes;
  216. }
  217.  
  218. STDMETHODIMP CInsSmObj::Run( IDispatch* ThisTool, VARIANT_BOOL FAR* retval)
  219. {
  220.     CWnd *pMainWnd = AfxGetMainWnd();
  221.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  222.  
  223.     HRESULT hRes = E_FAIL;
  224.  
  225.     Tool *pTool = NULL;
  226.     IApplication *pIApp = NULL;
  227.  
  228.     RegenMethods *pRegMets=NULL;
  229.  
  230.     COleVariant varOptional(varMissing);
  231.     COleVariant varType((const long)imsiPolyline);
  232.     
  233.     CString strDescription;
  234.  
  235.     HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  236.  
  237.  
  238.     try
  239.     {
  240.         hRes = ThisTool->QueryInterface(IID_Tool, (void **)&pTool);
  241.         CHECK_HRESULT(hRes)
  242.  
  243.         hRes = pTool->get_Application(&pIApp);
  244.         CHECK_HRESULT(hRes)
  245.  
  246.          hRes = pIApp->get_RegenMethods(&pRegMets);
  247.         CHECK_HRESULT(hRes)
  248.  
  249.         CSdiDialog *pdlg = new CSdiDialog(this, pMainWnd, pRegMets);
  250.  
  251.         pdlg->Create(CSdiDialog::IDD, NULL /*pMainWnd*/);
  252.  
  253.         VARIANT_BOOL    varRetval1 = FALSE;
  254.         
  255.         hRes = UpdateToolStatus(ThisTool, &varRetval1, &varRetval1, &varRetval1);    
  256.         CHECK_HRESULT(hRes)
  257.  
  258.         hRes = S_OK;
  259.     }
  260.     catch (...)
  261.     {
  262.         m_bRunned = FALSE;
  263.         TRACE_EXCEPTION("CInsSmObj::Run")
  264.     }
  265.     ::SetCursor(hOC);
  266.  
  267.     if(pRegMets != NULL)
  268.     {
  269.         pRegMets->Release();    
  270.         pTool = NULL;
  271.     }
  272.  
  273.     RELEASE(pIApp)
  274.     RELEASE(pTool)
  275.  
  276.     return hRes;
  277. }
  278.  
  279. STDMETHODIMP CInsSmObj::UpdateToolStatus(IDispatch* ThisTool, VARIANT_BOOL FAR* Enabled, VARIANT_BOOL FAR* Checked, VARIANT_BOOL FAR* retval)
  280. {
  281.     HRESULT hRes = E_FAIL;
  282.  
  283.     try
  284.     {
  285.         if(m_bRunned == TRUE) 
  286.         {
  287.             *Enabled = FALSE;
  288.         }
  289.         *retval = TRUE;
  290.         hRes = S_OK;
  291.     }
  292.     catch (...)
  293.     {
  294.         TRACE_EXCEPTION("CInsSmObj::UpdateToolStatus")
  295.     }
  296.  
  297.     return hRes;
  298. }
  299.  
  300. STDMETHODIMP CInsSmObj::Initialize( IDispatch * ThisTool, VARIANT_BOOL FAR* retval)
  301. {
  302.     HRESULT hRes = E_FAIL;
  303.  
  304.     try
  305.     {
  306.         *retval = TRUE;
  307.         hRes = S_OK;
  308.  
  309.     }
  310.     catch (...)
  311.     {
  312.         TRACE_EXCEPTION("CInsSmObj::Initialize")
  313.     }
  314.     return hRes;
  315. }
  316.