home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // Tool.cpp : Implementation of CDCMTool
- #include "stdafx.h"
- #include "InsSmObj.h"
- #include "SmObj.h"
- #include "SdiDialog.h"
-
- #include <afxwin.h>
-
- const IID IID_Tool = {0x6A48112C,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
- const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- /////////////////////////////////////////////////////////////////////////////
-
- STDMETHODIMP CInsSmObj::InterfaceSupportsErrorInfo(REFIID riid)
- {
- static const IID* arr[] =
- {
- &IID_ITurboCADTool,
- };
- for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
- {
- if (InlineIsEqualGUID(*arr[i],riid))
- return S_OK;
- }
- return S_FALSE;
- }
-
- /* ITurboCADTool properties: */
- STDMETHODIMP CInsSmObj::get_ClassID(BSTR* retval)
- {
- HRESULT hRes = E_FAIL;
- LPOLESTR olestr = NULL;
-
- try
- {
- *retval = NULL;
-
- hRes = ::StringFromCLSID(CLSID_InsSmObj, &olestr);
- CHECK_HRESULT(hRes)
-
- *retval = ::SysAllocString(olestr);
-
- hRes = S_OK;
- }
- catch (...)
- {
- TRACE_EXCEPTION("CInsSmObj::get_ClassID")
- }
-
- if (olestr != NULL)
- CoTaskMemFree(olestr);
-
- return hRes;
- }
-
- STDMETHODIMP CInsSmObj::get_Description( BSTR* retval)
- {
-
- HRESULT hRes = E_FAIL;
- CString strResult;
- *retval = NULL;
-
- try
- {
- if (strResult.LoadString(IDS_DESCRIPTION))
- {
- hRes = S_OK;
- *retval = strResult.AllocSysString();
- }
- }
- catch (...)
- {
- TRACE_EXCEPTION("CInsSmObj::get_Description")
- }
-
- return hRes;
-
- }
-
- /* ITurboCADTool methods: */
- STDMETHODIMP CInsSmObj::GetToolInfo(VARIANT FAR* CommandNames,
- VARIANT FAR* MenuCaptions,
- VARIANT FAR* StatusPrompts,
- VARIANT FAR* ToolTips,
- VARIANT FAR* Enabled,
- VARIANT FAR* WantsUpdates,
- long FAR* retval)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
-
- HRESULT hRes = E_FAIL;
-
- SAFEARRAYBOUND bound = {NUM_TOOLS, 0};
-
- CString cstrText;
- CString cstrTextTemp;
-
- BSTR bstrCommandName = NULL;
- BSTR bstrMenuCaption = NULL;
- BSTR bstrStatusPrompt = NULL;
- BSTR bstrToolTip = NULL;
- BOOL bEnabled = TRUE;
- BOOL bWantsUpdates = TRUE;
-
-
- long lIndicies = 0;
- try
- {
-
- hRes = SafeArrayRedim(CommandNames->parray, &bound);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayRedim(MenuCaptions->parray, &bound);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayRedim(StatusPrompts->parray, &bound);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayRedim(ToolTips->parray, &bound);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayRedim(Enabled->parray, &bound);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayRedim(WantsUpdates->parray, &bound);
- CHECK_HRESULT(hRes)
-
- // construct menu item for this tool : Main Menu + SubMenu + Menu Caption of this tool
- cstrText.LoadString (IDS_MAINMENU);
- cstrText.Insert(cstrText.GetLength (), '|');
- cstrTextTemp.LoadString (IDS_SUBMENU);
- cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
- cstrText.Insert(cstrText.GetLength (), '|');
- cstrTextTemp.LoadString (IDS_MENUCAPTION);
- cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
- cstrTextTemp.Empty ();
-
- cstrText += "#CMD_SDKINSERTCUSTOMOBJECT";
-
- bstrCommandName = cstrText.AllocSysString();
- hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName);
- CHECK_HRESULT(hRes)
-
- cstrText.Empty ();
- cstrText.LoadString (IDS_MENUCAPTION);
- bstrMenuCaption = cstrText.AllocSysString();
- hRes = SafeArrayPutElement(MenuCaptions->parray, &lIndicies, (void *)bstrMenuCaption);
- CHECK_HRESULT(hRes)
-
- cstrText.LoadString (IDS_PROMT);
- bstrStatusPrompt = cstrText.AllocSysString();
- hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt);
- CHECK_HRESULT(hRes)
-
- cstrText.LoadString (IDS_TOOLTIPS);
- bstrToolTip = cstrText.AllocSysString();
- hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled);
- CHECK_HRESULT(hRes)
-
- hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates);
- CHECK_HRESULT(hRes)
-
- *retval = NUM_TOOLS;
- }
- catch (...)
- {
- if (SUCCEEDED(hRes))
- hRes = E_FAIL;
- TRACE_EXCEPTION("CInsSmObj::GetToolInfo")
- }
- return hRes;
- }
-
- STDMETHODIMP CInsSmObj::CopyBitmap( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, VARIANT_BOOL FAR* retval)
- {
- HRESULT hRes = E_FAIL;
- try
- {
- CHECK_HRESULT(hRes)
- hRes = S_OK;
- }
- catch (...)
- {
- TRACE_EXCEPTION("CInsSmObj::CopyBitmap")
- }
- return hRes;
- }
-
- STDMETHODIMP CInsSmObj::GetPicture( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch** retval)
- {
- HRESULT hRes = E_FAIL;
- try
- {
- CHECK_HRESULT(hRes)
- hRes = S_OK;
- }
- catch (...)
- {
- TRACE_EXCEPTION("CInsSmObj::GetPicture")
- }
- return hRes;
- }
-
- STDMETHODIMP CInsSmObj::Run( IDispatch* ThisTool, VARIANT_BOOL FAR* retval)
- {
- CWnd *pMainWnd = AfxGetMainWnd();
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- HRESULT hRes = E_FAIL;
-
- Tool *pTool = NULL;
- IApplication *pIApp = NULL;
-
- RegenMethods *pRegMets=NULL;
-
- COleVariant varOptional(varMissing);
- COleVariant varType((const long)imsiPolyline);
-
- CString strDescription;
-
- HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
-
-
- try
- {
- hRes = ThisTool->QueryInterface(IID_Tool, (void **)&pTool);
- CHECK_HRESULT(hRes)
-
- hRes = pTool->get_Application(&pIApp);
- CHECK_HRESULT(hRes)
-
- hRes = pIApp->get_RegenMethods(&pRegMets);
- CHECK_HRESULT(hRes)
-
- CSdiDialog *pdlg = new CSdiDialog(this, pMainWnd, pRegMets);
-
- pdlg->Create(CSdiDialog::IDD, NULL /*pMainWnd*/);
-
- VARIANT_BOOL varRetval1 = FALSE;
-
- hRes = UpdateToolStatus(ThisTool, &varRetval1, &varRetval1, &varRetval1);
- CHECK_HRESULT(hRes)
-
- hRes = S_OK;
- }
- catch (...)
- {
- m_bRunned = FALSE;
- TRACE_EXCEPTION("CInsSmObj::Run")
- }
- ::SetCursor(hOC);
-
- if(pRegMets != NULL)
- {
- pRegMets->Release();
- pTool = NULL;
- }
-
- RELEASE(pIApp)
- RELEASE(pTool)
-
- return hRes;
- }
-
- STDMETHODIMP CInsSmObj::UpdateToolStatus(IDispatch* ThisTool, VARIANT_BOOL FAR* Enabled, VARIANT_BOOL FAR* Checked, VARIANT_BOOL FAR* retval)
- {
- HRESULT hRes = E_FAIL;
-
- try
- {
- if(m_bRunned == TRUE)
- {
- *Enabled = FALSE;
- }
- *retval = TRUE;
- hRes = S_OK;
- }
- catch (...)
- {
- TRACE_EXCEPTION("CInsSmObj::UpdateToolStatus")
- }
-
- return hRes;
- }
-
- STDMETHODIMP CInsSmObj::Initialize( IDispatch * ThisTool, VARIANT_BOOL FAR* retval)
- {
- HRESULT hRes = E_FAIL;
-
- try
- {
- *retval = TRUE;
- hRes = S_OK;
-
- }
- catch (...)
- {
- TRACE_EXCEPTION("CInsSmObj::Initialize")
- }
- return hRes;
- }
-