home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F38805_PSsWizard.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-21  |  11.5 KB  |  471 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. // PSsWizard.cpp : Implementation of CPSsWizard
  12. #include "stdafx.h"
  13. #include "TCPssWiz.h"
  14. #include "PSsWizard.h"
  15. #include "PaperSpaceWizard.h"
  16.  
  17. #include "xdbtool_i.c"
  18. #include "imsigx_i.c"
  19. #include "gxmps_i.c"
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // This example demostrate how to work with drawing's PaperSpaces collection
  23. // It just creates new PaperSpace with simply setting.
  24. // Modify this sample for your needs
  25.  
  26.  
  27. // CPSsWizard
  28.  
  29. COleVariant t(-1L, VT_BOOL);
  30. COleVariant f(0L, VT_BOOL);
  31. COleVariant missing((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34.  
  35.  
  36. STDMETHODIMP CPSsWizard::get_ClassID(BSTR *pVal)
  37. {
  38.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  39.     HRESULT hRes = E_FAIL;
  40.     LPOLESTR olestr = NULL;
  41.  
  42.     try
  43.     {
  44.         if(SUCCEEDED( ::StringFromCLSID(CLSID_PSsWizard, &olestr)))
  45.         {
  46.             *pVal = ::SysAllocString(olestr);
  47.             hRes = S_OK;
  48.         }
  49.     }
  50.     catch (...)
  51.     {
  52.         TRACE_EXCEPTION("CPSsWizard::get_ClassID")
  53.     }
  54.  
  55.     if (olestr != NULL)
  56.     CoTaskMemFree(olestr);
  57.  
  58.     return hRes;
  59. }
  60.  
  61. STDMETHODIMP CPSsWizard::get_Description(BSTR *pVal)
  62. {
  63.     // Get the description from the resource
  64.     HRESULT hRes = E_FAIL;
  65.     CString strResult;
  66.     if (strResult.LoadString(IDS_DESCRIPTION))
  67.     {
  68.         *pVal = strResult.AllocSysString();
  69.         hRes = S_OK;
  70.     }
  71.     return hRes;
  72. }
  73.  
  74. STDMETHODIMP CPSsWizard::GetToolInfo(VARIANT *CommandNames, VARIANT *MenuCaptions, VARIANT *StatusPrompts, VARIANT *ToolTips, VARIANT *Enabled, VARIANT *WantsUpdates, long *ret)
  75. {
  76.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  77.     HRESULT hRes = E_FAIL;
  78.     
  79.     SAFEARRAYBOUND bound = {NUM_TOOLS,0};
  80.     SAFEARRAYBOUND bound1[2] = {{NUM_TOOLS, 0}, {2, 0}};
  81. /*
  82.     bound[0].cElements = NUM_TOOLS;
  83.     bound[0].lLbound = 0;
  84.  
  85.     bound[1].cElements = 2;
  86.     bound[1].lLbound = 0;
  87. */
  88.     CString cstrText;
  89.     CString cstrTextTemp;
  90.  
  91.     BSTR bstrCommandName = NULL;
  92.     BSTR bstrMenuCaption = NULL;
  93.     BSTR bstrStatusPrompt = NULL;
  94.     BSTR bstrToolTip = NULL;
  95.     BOOL bEnabled = TRUE;
  96.     BOOL bWantsUpdates = TRUE;
  97.  
  98.     
  99.     long lIndicies = 0;
  100.     long lIndicies1[2];
  101.     lIndicies1[0] = 0;
  102.     lIndicies1[1] = 0;
  103.     try
  104.     {
  105.         
  106.         hRes = SafeArrayRedim(CommandNames->parray, &bound);
  107.         CHECK_HRESULT(hRes)
  108.  
  109. //        hRes = SafeArrayRedim(MenuCaptions->parray, &bound);
  110. //        CHECK_HRESULT(hRes)
  111.         MenuCaptions->parray = SafeArrayCreate(VT_BSTR, 2, bound1);
  112.  
  113.  
  114.         hRes = SafeArrayRedim(StatusPrompts->parray, &bound);
  115.         CHECK_HRESULT(hRes)
  116.  
  117.         hRes = SafeArrayRedim(ToolTips->parray, &bound);
  118.         CHECK_HRESULT(hRes)
  119.  
  120.         hRes = SafeArrayRedim(Enabled->parray, &bound);
  121.         CHECK_HRESULT(hRes)
  122.  
  123.         hRes = SafeArrayRedim(WantsUpdates->parray, &bound);
  124.         CHECK_HRESULT(hRes)
  125.  
  126.         cstrText.LoadString (IDS_MAINMENU);
  127.         cstrText.Insert(cstrText.GetLength (), '|');
  128.         cstrTextTemp.LoadString (IDS_SUBMENU);
  129.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  130.         cstrText.Insert(cstrText.GetLength (), '|');
  131.         cstrTextTemp.LoadString (IDS_MENUCAPTION);
  132.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  133.         cstrTextTemp.Empty ();
  134.  
  135.         bstrCommandName = cstrText.AllocSysString();
  136.         hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName);
  137.         CHECK_HRESULT(hRes)
  138.  
  139.         cstrText.Empty ();
  140.         cstrText.LoadString (IDS_MENUCAPTION); 
  141.         bstrMenuCaption = cstrText.AllocSysString();
  142.         hRes = SafeArrayPutElement(MenuCaptions->parray, lIndicies1, (void *)bstrMenuCaption);
  143.         CHECK_HRESULT(hRes)
  144.         cstrText.Empty ();
  145.  
  146.          cstrText.LoadString (IDS_PROMT0);
  147.         bstrStatusPrompt = cstrText.AllocSysString();
  148.         hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt);
  149.         CHECK_HRESULT(hRes)
  150.         cstrText.Empty ();
  151.         cstrText.LoadString (IDS_TOOLTIPS);; 
  152.         bstrToolTip = cstrText.AllocSysString();
  153.         hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip);
  154.         CHECK_HRESULT(hRes)
  155.  
  156.         hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled);
  157.         CHECK_HRESULT(hRes)
  158.  
  159.         hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates);
  160.         CHECK_HRESULT(hRes)
  161.  
  162. // put default toolbar name
  163.         lIndicies1[0] = 0;
  164.         lIndicies1[1] = 1;
  165.  
  166.         cstrText.LoadString (IDS_TOOLBAR_NAME); 
  167.         bstrMenuCaption = cstrText.AllocSysString();
  168.  
  169.         hRes = SafeArrayPutElement(MenuCaptions->parray, lIndicies1, (void *)bstrMenuCaption);
  170.         CHECK_HRESULT(hRes)
  171.         cstrText.Empty ();
  172.  
  173.         *ret = NUM_TOOLS;
  174.     }
  175.     catch (...)
  176.     {
  177.         if (SUCCEEDED(hRes))
  178.             hRes = E_FAIL;
  179.         TRACE_EXCEPTION("CPSsWizard::GetToolInfo")
  180.     }
  181.     return hRes;
  182. }
  183.  
  184. STDMETHODIMP CPSsWizard::GetPicture(VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch **ret)
  185. {
  186.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  187.     LPTSTR IDB = 0;
  188.  
  189.     HRESULT hRes = E_FAIL;
  190.     try
  191.     {
  192.         if(LargeButtons)
  193.         {
  194.             IDB = MAKEINTRESOURCE(IDB_BMP2);
  195.         }
  196.         else
  197.         {
  198.             IDB = MAKEINTRESOURCE(IDB_BMP1);
  199.         }
  200.         HBITMAP pBmp = ::LoadBitmap(AfxGetResourceHandle(), IDB);
  201.  
  202.         PICTDESC pict;
  203.         pict.cbSizeofstruct = sizeof(pict);
  204.         pict.picType = PICTYPE_BITMAP;
  205.         pict.bmp.hbitmap = pBmp;
  206.         pict.bmp.hpal = NULL;
  207.  
  208.         hRes = OleCreatePictureIndirect(&pict, IID_IDispatch, TRUE, (void**)ret);
  209.  
  210.         CHECK_HRESULT(hRes)
  211.         hRes = S_OK;
  212.     }
  213.     catch (...)
  214.     {
  215.         TRACE_EXCEPTION("CPSsWizard::GetPicture")
  216.     }
  217.  
  218.     return hRes;
  219. }
  220.  
  221. STDMETHODIMP CPSsWizard::CopyBitmap(VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, VARIANT_BOOL *ret)
  222. {
  223.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  224.  
  225.     // TODO: Add your implementation code here
  226.  
  227.     return S_OK;
  228. }
  229.  
  230. STDMETHODIMP CPSsWizard::UpdateToolStatus(IDispatch *ThisTool, VARIANT_BOOL *Enabled, VARIANT_BOOL *Checked, VARIANT_BOOL *ret)
  231. {
  232.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  233.  
  234.     return S_OK;
  235. }
  236.  
  237. STDMETHODIMP CPSsWizard::Initialize(IDispatch *ThisTool, VARIANT_BOOL *ret)
  238. {
  239.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  240.  
  241.     return S_OK;
  242. }
  243.  
  244. STDMETHODIMP CPSsWizard::Terminate(IDispatch *ThisTool)
  245. {
  246.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  247.  
  248.     return S_OK;
  249. }
  250.  
  251. STDMETHODIMP CPSsWizard::Run(IDispatch *ThisTool, VARIANT_BOOL *ret)
  252. {
  253.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  254.     HRESULT hRes = E_FAIL;
  255.  
  256.  
  257.     Tool *pTool = NULL;
  258.     IApplication *pIApp = NULL;
  259.     IDrawing *pDr = NULL;
  260.     PageSetup *pPageSetup = NULL;
  261.  
  262.     long lPsscount = 0;
  263.     PaperSpaces *pPss = NULL;
  264.     PaperSpace *pPs = NULL;
  265.  
  266.     CString cstrText;
  267.     BSTR bstrStatusPrompt;
  268.     cstrText.LoadString (IDS_PROMT);
  269.     bstrStatusPrompt = cstrText.AllocSysString();
  270.  
  271.     IDispatch *pIDisp = NULL;
  272.     PAPERSPACEINFO pPSInfo;
  273.     IDispatch *pDisp = NULL;
  274.  
  275.     BSTR bstrPsName;
  276.  
  277.     
  278.     try
  279.     {
  280.  
  281.         hRes = ThisTool->QueryInterface(IID_Tool, (void **)&m_pTool);
  282.         CHECK_HRESULT(hRes)
  283.  
  284.         hRes = m_pTool->get_Application(&m_pIApplication);
  285.         CHECK_HRESULT(hRes)
  286.  
  287.         hRes = QueryInterface(IID_IPSsWizard, (void**)&m_pITool);
  288.         CHECK_HRESULT(hRes)
  289.         hRes = m_pIApplication->get_ActiveDrawing(&pDr);
  290.         CHECK_HRESULT(hRes)
  291.  
  292.         hRes = pDr->get_PaperSpaces(&pIDisp);
  293.         CHECK_HRESULT(hRes);
  294.         hRes = pIDisp->QueryInterface (IID_PaperSpaces,(void**)&pPss);
  295.         CHECK_HRESULT(hRes);
  296.         
  297.         RELEASE(pIDisp)
  298.  
  299.         hRes = pPss->get_Count(&lPsscount);
  300.         CHECK_HRESULT(hRes)
  301.  
  302.         CString cstrTextTemp;
  303.         char v[10];
  304.         memset(v, 0, 10);
  305.         lPsscount++;
  306.         _ltoa(lPsscount,v, 10);
  307.         lPsscount--;
  308.  
  309.         CPaperSpaceWizard dlg(IDS_DESCRIPTION,NULL, 0);        
  310.         cstrText.LoadString (IDS_PSNAMETEMPLATE); 
  311.         cstrText.Insert((cstrText.GetLength ()), " ");
  312.         cstrText.Insert((cstrText.GetLength ()), v);
  313.         dlg.m_PSInfo = & pPSInfo;
  314.         dlg.m_pPss = pPss;        
  315.         dlg.m_pPss->AddRef();        
  316.         RELEASE(pPss)
  317.  
  318.         dlg.m_PSInfo->bPaperOrientation = 1; //PaperOrientation - Landscape by default
  319.         dlg.m_PSInfo->cstrPSpaceName = cstrText;
  320.         
  321.         
  322.         int iResponse = dlg.DoModal();
  323.         if (iResponse == ID_WIZFINISH)
  324.         {
  325.  
  326.             bstrPsName = dlg.m_PSInfo->cstrPSpaceName.AllocSysString ();
  327.             hRes = dlg.m_pPss->Add(bstrPsName, &pIDisp);
  328.             CHECK_HRESULT(hRes)
  329.  
  330.             hRes = pIDisp->QueryInterface (IID_PaperSpace, (void**)&pPs);
  331.             CHECK_HRESULT(hRes)
  332.  
  333.             hRes = pPs->Activate();
  334.             CHECK_HRESULT(hRes)
  335.  
  336.             RELEASE(pPs)
  337.             RELEASE(dlg.m_pPss)
  338.                 
  339.             hRes = pDr->get_PageSetup(&pPageSetup);
  340.             CHECK_HRESULT(hRes)
  341.  
  342.             hRes = pPageSetup->put_SheetOrientation((ImsiOrientation)dlg.m_PSInfo->bPaperOrientation) ;
  343.             CHECK_HRESULT(hRes)
  344.  
  345.             hRes = pPageSetup->put_PrinterOrientation((ImsiOrientation)dlg.m_PSInfo->bPaperOrientation) ;
  346.             CHECK_HRESULT(hRes)
  347.             RELEASE(pPageSetup)
  348.  
  349.  
  350.         
  351.         }
  352.     }
  353.     catch (...)
  354.     {
  355.         TRACE_EXCEPTION("CPSsWizard::Run")
  356.     }
  357.  
  358.     RELEASE(pIDisp)
  359.     RELEASE(pPageSetup)
  360.     RELEASE(pPs)
  361.     RELEASE(pDisp)
  362.     RELEASE(pPss);
  363.     RELEASE(pDr);
  364.     RELEASE(m_pIApplication);
  365.  
  366.     return S_OK;
  367. }
  368.  
  369. STDMETHODIMP CPSsWizard::MouseDown(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, short Button, long Shift, long X, long Y, VARIANT_BOOL *Cancel)
  370. {
  371.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  372.  
  373.     // TODO: Add your implementation code here
  374.  
  375.     return S_OK;
  376. }
  377.  
  378. STDMETHODIMP CPSsWizard::MouseUp(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, short Button, long Shift, long X, long Y, VARIANT_BOOL *Cancel)
  379. {
  380.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  381.  
  382.     // TODO: Add your implementation code here
  383.  
  384.     return S_OK;
  385. }
  386.  
  387. STDMETHODIMP CPSsWizard::MouseMove(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, long Shift, long X, long Y, VARIANT_BOOL *pbCancel)
  388. {
  389.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  390.  
  391.     // TODO: Add your implementation code here
  392.  
  393.     return S_OK;
  394. }
  395.  
  396. STDMETHODIMP CPSsWizard::RunTool(IDispatch *ThisTool)
  397. {
  398.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  399.  
  400.     // TODO: Add your implementation code here
  401.  
  402.     return S_OK;
  403. }
  404. void CPSsWizard::ConnectEvents(IDispatch *ThisTool)
  405. {
  406.  
  407.      HRESULT hRes = S_OK;
  408.  
  409.     if (m_dwEventConnection != 0)
  410.         return;
  411.  
  412.     try
  413.     {
  414.         DWORD dwEventMask = imsiEventMouseUp
  415.                              | imsiEventMouseMove
  416.                              | imsiEventMouseDown
  417.                              | imsiEventDrawingDeactivate
  418.                              | imsiEventRunTool
  419.                              | imsiEventBeforeExit;
  420.  
  421.         COleVariant var((long)dwEventMask);
  422.         hRes = m_pIApplication->ConnectEvents(ThisTool,
  423.             &var,
  424.             (long*)&m_dwEventConnection);
  425.         
  426.  
  427.         if (FAILED(hRes))
  428.             return;
  429.     }
  430.     catch (...)
  431.     {
  432.         TRACE_EXCEPTION("CPSsWizard::ConnectEvents")
  433.     }
  434. }
  435.  
  436. void CPSsWizard::DisconnectEvents()
  437. {
  438.     if (m_pIApplication == NULL || m_dwEventConnection == 0)
  439.         return;
  440.     try 
  441.     {
  442.  
  443.         HRESULT    hRes = m_pIApplication->DisconnectEvents(m_dwEventConnection);
  444.         CHECK_HRESULT(hRes)
  445.         if (FAILED(hRes))
  446.             return;
  447.         m_dwEventConnection = 0;
  448.     }
  449.     catch (...)
  450.     {
  451.         TRACE_EXCEPTION("CPSsWizard::DisconnectEvents")
  452.     }
  453. }
  454.  
  455. void CPSsWizard::Destroy()
  456. {
  457.     CString cstrT;
  458.     cstrT.Empty ();
  459.     BSTR bstrPromt = NULL;
  460.     bstrPromt = cstrT.AllocSysString ();
  461.     m_pIToolEvents->ToolChangePrompt(m_pITool,bstrPromt, FALSE);
  462.  
  463.     RELEASE(m_pIToolEvents)
  464. //    DisconnectEvents();
  465.     RELEASE(m_pDragGraphic);
  466.     RELEASE(m_pITool);
  467.     RELEASE(m_pTool);
  468.     RELEASE(m_pIApplication);
  469.         
  470. }
  471.