home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap23 / cosmo / iipaobj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  7.9 KB  |  324 lines

  1. /*
  2.  * IIPAOBJ.CPP
  3.  * Cosmo Chapter 23
  4.  *
  5.  * IOleInPlaceActiveObject interface implementation for Cosmo
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #include "cosmo.h"
  16.  
  17.  
  18. /*
  19.  * CImpIOleInPlaceActiveObject::CImpIOleInPlaceActiveObject
  20.  * CImpIOleInPlaceActiveObject::~CImpIOleInPlaceActiveObject
  21.  *
  22.  * Parameters (Constructor):
  23.  *  pObj            PCFigure of the object we're in.
  24.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  25.  */
  26.  
  27. CImpIOleInPlaceActiveObject::CImpIOleInPlaceActiveObject
  28.     (PCFigure pObj, LPUNKNOWN pUnkOuter)
  29.     {
  30.     m_cRef=0;
  31.     m_pObj=pObj;
  32.     m_pUnkOuter=pUnkOuter;
  33.     return;
  34.     }
  35.  
  36. CImpIOleInPlaceActiveObject::~CImpIOleInPlaceActiveObject(void)
  37.     {
  38.     return;
  39.     }
  40.  
  41.  
  42.  
  43. /*
  44.  * CImpIOleInPlaceActiveObject::QueryInterface
  45.  * CImpIOleInPlaceActiveObject::AddRef
  46.  * CImpIOleInPlaceActiveObject::Release
  47.  *
  48.  * Purpose:
  49.  *  IUnknown members for CImpIOleInPlaceActiveObject object.
  50.  */
  51.  
  52. STDMETHODIMP CImpIOleInPlaceActiveObject::QueryInterface(REFIID riid
  53.     , PPVOID ppv)
  54.     {
  55.     /*
  56.      * This interface should be stand-alone on an object such that
  57.      * a container cannot QueryInterface for it through any other
  58.      * object interface, relying instead of calls to SetActiveObject
  59.      * for it. By implementing QueryInterface here ourselves, we
  60.      * prevent such abuses.  Note that reference counting still
  61.      * uses CFigure.
  62.      */
  63.  
  64.     *ppv=NULL;
  65.  
  66.     if (IID_IUnknown==riid || IID_IOleWindow==riid
  67.         || IID_IOleInPlaceActiveObject==riid)
  68.         *ppv=this;
  69.  
  70.     if (NULL!=*ppv)
  71.         {
  72.         ((LPUNKNOWN)*ppv)->AddRef();
  73.         return NOERROR;
  74.         }
  75.  
  76.     return ResultFromScode(E_NOINTERFACE);
  77.     }
  78.  
  79.  
  80. STDMETHODIMP_(ULONG) CImpIOleInPlaceActiveObject::AddRef(void)
  81.     {
  82.     ++m_cRef;
  83.     return m_pUnkOuter->AddRef();
  84.     }
  85.  
  86. STDMETHODIMP_(ULONG) CImpIOleInPlaceActiveObject::Release(void)
  87.     {
  88.     --m_cRef;
  89.     return m_pUnkOuter->Release();
  90.     }
  91.  
  92.  
  93.  
  94.  
  95. /*
  96.  * CImpIOleInPlaceActiveObject::GetWindow
  97.  *
  98.  * Purpose:
  99.  *  Retrieves the handle of the window associated with the object
  100.  *  on which this interface is implemented.
  101.  *
  102.  * Parameters:
  103.  *  phWnd           HWND * in which to store the window handle.
  104.  *
  105.  * Return Value:
  106.  *  HRESULT         NOERROR if successful, E_FAIL if there is no
  107.  *                  window.
  108.  */
  109.  
  110. STDMETHODIMP CImpIOleInPlaceActiveObject::GetWindow(HWND * phWnd)
  111.     {
  112.     *phWnd=m_pObj->m_pHW->Window();
  113.     return NOERROR;
  114.     }
  115.  
  116.  
  117.  
  118.  
  119. /*
  120.  * CImpIOleInPlaceActiveObject::ContextSensitiveHelp
  121.  *
  122.  * Purpose:
  123.  *  Instructs the object on which this interface is implemented to
  124.  *  enter or leave a context-sensitive help mode.
  125.  *
  126.  * Parameters:
  127.  *  fEnterMode      BOOL TRUE to enter the mode, FALSE otherwise.
  128.  *
  129.  * Return Value:
  130.  *  HRESULT         NOERROR or an error code
  131.  */
  132.  
  133. STDMETHODIMP CImpIOleInPlaceActiveObject::ContextSensitiveHelp
  134.     (BOOL fEnterMode)
  135.     {
  136.     return ResultFromScode(E_NOTIMPL);
  137.     }
  138.  
  139.  
  140.  
  141.  
  142. /*
  143.  * CImpIOleInPlaceActiveObject::TranslateAccelerator
  144.  *
  145.  * Purpose:
  146.  *  Requests that the active in-place object translate the message
  147.  *  given in pMSG if appropriate.
  148.  *
  149.  * Parameters:
  150.  *  pMSG            LPMSG to the message to translate.
  151.  *
  152.  * Return Value:
  153.  *  HRESULT         NOERROR if translates, S_FALSE if not.
  154.  */
  155.  
  156. STDMETHODIMP CImpIOleInPlaceActiveObject::TranslateAccelerator
  157.     (LPMSG pMSG)
  158.     {
  159.     //This is only used for DLL objects.
  160.     return ResultFromScode(S_FALSE);
  161.     }
  162.  
  163.  
  164.  
  165.  
  166. /*
  167.  * CImpIOleInPlaceActiveObject::OnFrameWindowActivate
  168.  *
  169.  * Purpose:
  170.  *  Informs the in-place object that the container's frame window
  171.  *  was either activated or deactivated.  When the frame is
  172.  *  activated, the object can change its toolbar interface to
  173.  *  reflect a non-activated state as desired.  Usually you don't
  174.  *  have to do anything.
  175.  *
  176.  * Parameters:
  177.  *  fActivate       BOOL TRUE if the frame is active, FALSE
  178.  *                  otherwise
  179.  * Return Value:
  180.  *  HRESULT         NOERROR or an error code
  181.  */
  182.  
  183. STDMETHODIMP CImpIOleInPlaceActiveObject::OnFrameWindowActivate
  184.     (BOOL fActivate)
  185.     {
  186.     //Nothing for us to do.
  187.     return NOERROR;
  188.     }
  189.  
  190.  
  191.  
  192.  
  193. /*
  194.  * CImpIOleInPlaceActiveObject::OnDocWindowActivate
  195.  *
  196.  * Purpose:
  197.  *  Informs the in-place object that the document window in the
  198.  *  container is either becoming active or deactive.  On this call
  199.  *  the object must either add or remove frame-level tools,
  200.  *  including the mixed menu, depending on fActivate.
  201.  *
  202.  * Parameters:
  203.  *  fActivate       BOOL TRUE if the document is active, FALSE
  204.  *                  otherwise
  205.  *
  206.  * Return Value:
  207.  *  HRESULT         NOERROR or an error code
  208.  */
  209.  
  210. STDMETHODIMP CImpIOleInPlaceActiveObject::OnDocWindowActivate
  211.     (BOOL fActivate)
  212.     {
  213.     HWND        hWndTB;
  214.  
  215.     if (NULL==m_pObj->m_pIOleIPFrame)
  216.         return NOERROR;
  217.  
  218.     hWndTB=m_pObj->m_pTB->Window();
  219.  
  220.     if (fActivate)
  221.         {
  222.        #ifdef WIN32ANSI
  223.         OLECHAR     szTemp[40];
  224.  
  225.         MultiByteToWideChar(CP_ACP, 0
  226.             , (*m_pObj->m_pST)[IDS_INPLACETITLE], -1, szTemp, 40);
  227.         m_pObj->m_pIOleIPFrame->SetActiveObject(this, szTemp);
  228.        #else
  229.         m_pObj->m_pIOleIPFrame->SetActiveObject(this
  230.             , (*m_pObj->m_pST)[IDS_INPLACETITLE]);
  231.        #endif
  232.  
  233.         m_pObj->m_pIOleIPFrame->SetMenu(m_pObj->m_hMenuShared
  234.             , m_pObj->m_hOLEMenu, m_pObj->m_pFR->Window());
  235.  
  236.         if (m_pObj->InPlaceToolsRenegotiate())
  237.             {
  238.             RECT    rc;
  239.  
  240.             m_pObj->m_pIOleIPFrame->GetBorder(&rc);
  241.             SetWindowPos(hWndTB, NULL, rc.left, rc.top
  242.                 , rc.right-rc.left, rc.top+m_pObj->m_cyBar
  243.                 , SWP_NOZORDER);
  244.  
  245.             ShowWindow(hWndTB, SW_SHOW);
  246.             }
  247.         }
  248.     else
  249.         {
  250.         m_pObj->m_pIOleIPFrame->SetActiveObject(NULL, NULL);
  251.  
  252.         //Hide our tools, but do not call SetMenu
  253.         ShowWindow(hWndTB, SW_HIDE);
  254.         }
  255.  
  256.     return NOERROR;
  257.     }
  258.  
  259.  
  260.  
  261.  
  262. /*
  263.  * CImpIOleInPlaceActiveObject::ResizeBorder
  264.  *
  265.  * Purpose:
  266.  *  Informs the object that the frame or document size changed in
  267.  *  which case the object may need to resize any of its frame or
  268.  *  document-level tools to match.
  269.  *
  270.  * Parameters:
  271.  *  pRect           LPCRECT indicating the new size of the window
  272.  *                  of interest.
  273.  *  pIUIWindow      LPOLEINPLACEUIWINDOW pointing to an
  274.  *                  IOleInPlaceUIWindow interface on the container
  275.  *                  object of interest.  We use this to do border-
  276.  *                  space negotiation.
  277.  *  fFrame          BOOL indicating if the frame was resized (TRUE)
  278.  *                  or the document (FALSE)
  279.  *
  280.  * Return Value:
  281.  *  HRESULT         NOERROR or an error code
  282.  */
  283.  
  284. STDMETHODIMP CImpIOleInPlaceActiveObject::ResizeBorder(LPCRECT pRect
  285.     , LPOLEINPLACEUIWINDOW pIUIWindow, BOOL fFrame)
  286.     {
  287.     //The document case is uninteresting for us.
  288.     if (!fFrame)
  289.         return NOERROR;
  290.  
  291.     if (!m_pObj->InPlaceToolsRenegotiate())
  292.         return ResultFromScode(INPLACE_E_NOTOOLSPACE);
  293.  
  294.     SetWindowPos(m_pObj->m_pTB->Window(), NULL, pRect->left
  295.         , pRect->top, pRect->right-pRect->left, m_pObj->m_cyBar
  296.         , SWP_NOZORDER);
  297.  
  298.     return NOERROR;
  299.     }
  300.  
  301.  
  302.  
  303.  
  304. /*
  305.  * CImpIOleInPlaceActiveObject::EnableModeless
  306.  *
  307.  * Purpose:
  308.  *  Instructs the object to show or hide any modeless popup windows
  309.  *  that it may be using when activated in-place.
  310.  *
  311.  * Parameters:
  312.  *  fEnable         BOOL indicating to enable/show the windows
  313.  *                  (TRUE) or to hide them (FALSE).
  314.  *
  315.  * Return Value:
  316.  *  HRESULT         NOERROR or an error code
  317.  */
  318.  
  319. STDMETHODIMP CImpIOleInPlaceActiveObject::EnableModeless
  320.     (BOOL fActivate)
  321.     {
  322.     return ResultFromScode(E_NOTIMPL);
  323.     }
  324.