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 / chap24 / patron / iconsite.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  7KB  |  303 lines

  1. /*
  2.  * ICONSITE.CPP
  3.  * Patron Chapter 24
  4.  *
  5.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  6.  *
  7.  * Kraig Brockschmidt, Microsoft
  8.  * Internet  :  kraigb@microsoft.com
  9.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  10.  */
  11.  
  12.  
  13. #include "patron.h"
  14.  
  15.  
  16. /*
  17.  * CImpIOleControlSite::CImpIOleControlSite
  18.  * CImpIOleControlSite::~CImpIOleControlSite
  19.  *
  20.  * Parameters (Constructor):
  21.  *  pTen            PCTenant of the object we're in.
  22.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  23.  */
  24.  
  25. CImpIOleControlSite::CImpIOleControlSite(PCTenant pTen
  26.     , LPUNKNOWN pUnkOuter)
  27.     {
  28.     m_cRef=0;
  29.     m_pTen=pTen;
  30.     m_pUnkOuter=pUnkOuter;
  31.     return;
  32.     }
  33.  
  34. CImpIOleControlSite::~CImpIOleControlSite(void)
  35.     {
  36.     return;
  37.     }
  38.  
  39.  
  40.  
  41.  
  42. /*
  43.  * CImpIOleControlSite::QueryInterface
  44.  * CImpIOleControlSite::AddRef
  45.  * CImpIOleControlSite::Release
  46.  *
  47.  * Purpose:
  48.  *  Delegating IUnknown members for CImpIOleControlSite.
  49.  */
  50.  
  51. STDMETHODIMP CImpIOleControlSite::QueryInterface(REFIID riid
  52.     , LPVOID *ppv)
  53.     {
  54.     return m_pUnkOuter->QueryInterface(riid, ppv);
  55.     }
  56.  
  57.  
  58. STDMETHODIMP_(ULONG) CImpIOleControlSite::AddRef(void)
  59.     {
  60.     ++m_cRef;
  61.     return m_pUnkOuter->AddRef();
  62.     }
  63.  
  64. STDMETHODIMP_(ULONG) CImpIOleControlSite::Release(void)
  65.     {
  66.     --m_cRef;
  67.     return m_pUnkOuter->Release();
  68.     }
  69.  
  70.  
  71.  
  72.  
  73.  
  74. /*
  75.  * CImpIOleControlSite::OnControlInfoChanged
  76.  *
  77.  * Purpose:
  78.  *  Informs the site that the CONTROLINFO for the control has
  79.  *  changed and we thus need to reload the data.
  80.  *
  81.  * Parameters:
  82.  *  None
  83.  *
  84.  * Return Value:
  85.  *  HRESULT         NOERROR
  86.  */
  87.  
  88. STDMETHODIMP CImpIOleControlSite::OnControlInfoChanged(void)
  89.     {
  90.     //We also update our "have info" flag here.
  91.     m_pTen->m_fHaveControlInfo=SUCCEEDED(m_pTen->m_pIOleControl
  92.         ->GetControlInfo(&m_pTen->m_ctrlInfo));
  93.  
  94.     return NOERROR;
  95.     }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /*
  102.  * CImpIOleControlSite::LockInPlaceActive
  103.  *
  104.  * Purpose:
  105.  *  Forces the container to keep this control in-place active
  106.  *  (but not UI active) regardless of other considerations, or
  107.  *  removes this lock.
  108.  *
  109.  * Parameters:
  110.  *  fLock           BOOL indicating to lock (TRUE) or unlock (FALSE)
  111.  *                  in-place activation.
  112.  *
  113.  * Return Value:
  114.  *  HRESULT         NOERROR
  115.  */
  116.  
  117. STDMETHODIMP CImpIOleControlSite::LockInPlaceActive(BOOL fLock)
  118.     {
  119.     if (fLock)
  120.         m_pTen->m_cLockInPlace++;
  121.     else
  122.         {
  123.         if (0==--m_pTen->m_cLockInPlace)
  124.             {
  125.             //If there's a pending deactivate, do it now.
  126.             if (m_pTen->m_fPendingDeactivate)
  127.                 m_pTen->DeactivateInPlaceObject(TRUE);
  128.             }
  129.         }
  130.  
  131.     return NOERROR;
  132.     }
  133.  
  134.  
  135.  
  136.  
  137.  
  138. /*
  139.  * CImpIOleControlSite::GetExtendedControl
  140.  *
  141.  * Purpose:
  142.  *  Returns a pointer to the container's extended control that wraps
  143.  *  the actual control in this site, if one exists.
  144.  *
  145.  * Parameters:
  146.  *  ppDispatch      LPDISPATCH * in which to return the pointer
  147.  *                  to the extended control's IDispatch interface.
  148.  *
  149.  * Return Value:
  150.  *  HRESULT         NOERROR or a general error value.
  151.  */
  152.  
  153. STDMETHODIMP CImpIOleControlSite::GetExtendedControl(LPDISPATCH
  154.     * ppDispatch)
  155.     {
  156.     *ppDispatch=NULL;
  157.     return ResultFromScode(E_NOTIMPL);
  158.     }
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. /*
  166.  * CImpIOleControlSite::TransformCoords
  167.  *
  168.  * Purpose:
  169.  *  Converts coordinates in HIMETRIC units into those used by the
  170.  *  container.
  171.  *
  172.  * Parameters:
  173.  *  pptlHiMet       POINTL * containing either the coordinates to
  174.  *                  transform to container or where to store the
  175.  *                  transformed container coordinates.
  176.  *  pptlCont        POINTF * containing the container coordinates.
  177.  *  dwFlags         DWORD containing instructional flags.
  178.  *
  179.  * Return Value:
  180.  *  HRESULT         NOERROR or a general error value.
  181.  */
  182.  
  183. STDMETHODIMP CImpIOleControlSite::TransformCoords(POINTL *pptlHiMet
  184.     , POINTF *pptlCont, DWORD dwFlags)
  185.     {
  186.     if (NULL==pptlHiMet || NULL==pptlCont)
  187.         return ResultFromScode(E_POINTER);
  188.  
  189.     /*
  190.      * Convert coordinates.  We use MM_LOMETRIC which means that
  191.      * to convert from HIMETRIC we divide by 10 and negate the y
  192.      * coordinate.  Conversion to HIMETRIC means negate the y
  193.      * and multiply by 10.  Note that size and position are
  194.      * considered the same thing, that is, we don't differentiate
  195.      * the two.
  196.      */
  197.  
  198.     if (XFORMCOORDS_HIMETRICTOCONTAINER & dwFlags)
  199.         {
  200.         pptlCont->x=(float)(pptlHiMet->x/10);
  201.         pptlCont->y=(float)-(pptlHiMet->y/10);
  202.         }
  203.     else
  204.         {
  205.         pptlHiMet->x=(long)(pptlCont->x*10);
  206.         pptlHiMet->y=(long)-(pptlCont->y*10);
  207.         }
  208.  
  209.     return NOERROR;
  210.     }
  211.  
  212.  
  213.  
  214.  
  215.  
  216. /*
  217.  * CImpIOleControlSite::TranslateAccelerator
  218.  *
  219.  * Purpose:
  220.  *  Instructs the container to translate a keyboard accelerator
  221.  *  message that the control has picked up instead.
  222.  *
  223.  * Parameters:
  224.  *  pMsg            LPMSG to the message to translate.
  225.  *  grfModifiers    DWORD flags with additional instructions.
  226.  *
  227.  * Return Value:
  228.  *  HRESULT         NOERROR or a general error value.
  229.  */
  230.  
  231. STDMETHODIMP CImpIOleControlSite::TranslateAccelerator(LPMSG pMsg
  232.     , DWORD grfModifiers)
  233.     {
  234.     /*
  235.      * The control has picked up a keystroke through its own
  236.      * TranslateAccelerator and is now giving us the change to
  237.      * play with it.  Currently there are no flags for
  238.      * grfModifiers, so we ignore them.  Especially since
  239.      * we have nothing to do here ourselves anyway.
  240.      */
  241.     return ResultFromScode(S_FALSE);
  242.     }
  243.  
  244.  
  245.  
  246.  
  247. /*
  248.  * CImpIOleControlSite::OnFocus
  249.  *
  250.  * Purpose:
  251.  *  Informs the container that focus has either been lost or
  252.  *  gained in the control.
  253.  *
  254.  * Parameters:
  255.  *  fGotFocus       BOOL indicating that the control gained (TRUE)
  256.  *                  or lost (FALSE) focus.
  257.  *
  258.  * Return Value:
  259.  *  HRESULT         NOERROR or a general error value.
  260.  */
  261.  
  262. STDMETHODIMP CImpIOleControlSite::OnFocus(BOOL fGotFocus)
  263.     {
  264.     /*
  265.      * Patron doesn't do this, but to handle the default
  266.      * and cancel buttons properly, we normally process RETURN
  267.      * and ESC accelerators to press the right button.
  268.      * This behavior must be disabled when the control with
  269.      * the focus has either CTRLINFO_EATS_RETURN or
  270.      * CTRLINFO_EATS_ESCAPE set.  We tell the frame as
  271.      * we need to when a new control gets the focus.  We
  272.      * do nothing when a control loses the focus.
  273.      */
  274.     return NOERROR;
  275.     }
  276.  
  277.  
  278.  
  279. /*
  280.  * CImpIOleControlSite::ShowPropertyFrame
  281.  *
  282.  * Purpose:
  283.  *  Instructs the container to show the property frame if
  284.  *  this is an extended object and requires its own property
  285.  *  pages.
  286.  *
  287.  * Parameters:
  288.  *  None
  289.  *
  290.  * Return Value:
  291.  *  HRESULT         NOERROR or a general error value.
  292.  */
  293.  
  294. STDMETHODIMP CImpIOleControlSite::ShowPropertyFrame(void)
  295.     {
  296.     /*
  297.      * Returning an error here means that the container has
  298.      * no property pages itself for the control, so the
  299.      * control should display its own.
  300.      */
  301.     return ResultFromScode(E_NOTIMPL);
  302.     }
  303.