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 / iipobj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  5.1 KB  |  228 lines

  1. /*
  2.  * IIPOBJ.CPP
  3.  * Cosmo Chapter 23
  4.  *
  5.  * IOleInPlaceObject 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.  * CImpIOleInPlaceObject::CImpIOleInPlaceObject
  20.  * CImpIOleInPlaceObject::~CImpIOleInPlaceObject
  21.  *
  22.  * Parameters (Constructor):
  23.  *  pObj            PCFigure of the object we're in.
  24.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  25.  */
  26.  
  27. CImpIOleInPlaceObject::CImpIOleInPlaceObject(PCFigure pObj
  28.     , LPUNKNOWN pUnkOuter)
  29.     {
  30.     m_cRef=0;
  31.     m_pObj=pObj;
  32.     m_pUnkOuter=pUnkOuter;
  33.     return;
  34.     }
  35.  
  36. CImpIOleInPlaceObject::~CImpIOleInPlaceObject(void)
  37.     {
  38.     return;
  39.     }
  40.  
  41.  
  42.  
  43. /*
  44.  * CImpIOleInPlaceObject::QueryInterface
  45.  * CImpIOleInPlaceObject::AddRef
  46.  * CImpIOleInPlaceObject::Release
  47.  *
  48.  * Purpose:
  49.  *  IUnknown members for CImpIOleInPlaceObject object.
  50.  */
  51.  
  52. STDMETHODIMP CImpIOleInPlaceObject::QueryInterface(REFIID riid
  53.     , PPVOID ppv)
  54.     {
  55.     return m_pUnkOuter->QueryInterface(riid, ppv);
  56.     }
  57.  
  58.  
  59. STDMETHODIMP_(ULONG) CImpIOleInPlaceObject::AddRef(void)
  60.     {
  61.     ++m_cRef;
  62.     return m_pUnkOuter->AddRef();
  63.     }
  64.  
  65. STDMETHODIMP_(ULONG) CImpIOleInPlaceObject::Release(void)
  66.     {
  67.     --m_cRef;
  68.     return m_pUnkOuter->Release();
  69.     }
  70.  
  71.  
  72.  
  73.  
  74. /*
  75.  * CImpIOleInPlaceObject::GetWindow
  76.  *
  77.  * Purpose:
  78.  *  Retrieves the handle of the window associated with the object
  79.  *  on which this interface is implemented.
  80.  *
  81.  * Parameters:
  82.  *  phWnd           HWND * in which to store the window handle.
  83.  *
  84.  * Return Value:
  85.  *  HRESULT         NOERROR if successful, E_FAIL if there is no
  86.  *                  window.
  87.  */
  88.  
  89. STDMETHODIMP CImpIOleInPlaceObject::GetWindow(HWND *phWnd)
  90.     {
  91.     *phWnd=m_pObj->m_pHW->Window();
  92.     return NOERROR;
  93.     }
  94.  
  95.  
  96.  
  97.  
  98. /*
  99.  * CImpIOleInPlaceObject::ContextSensitiveHelp
  100.  *
  101.  * Purpose:
  102.  *  Instructs the object on which this interface is implemented to
  103.  *  enter or leave a context-sensitive help mode.
  104.  *
  105.  * Parameters:
  106.  *  fEnterMode      BOOL TRUE to enter the mode, FALSE otherwise.
  107.  *
  108.  * Return Value:
  109.  *  HRESULT         NOERROR or an error code
  110.  */
  111.  
  112. STDMETHODIMP CImpIOleInPlaceObject::ContextSensitiveHelp
  113.     (BOOL fEnterMode)
  114.     {
  115.     return ResultFromScode(E_NOTIMPL);
  116.     }
  117.  
  118.  
  119.  
  120.  
  121. /*
  122.  * CImpIOleInPlaceObject::InPlaceDeactivate
  123.  *
  124.  * Purpose:
  125.  *  Instructs the object to deactivate itself from an in-place state
  126.  *  and to discard any Undo state.
  127.  *
  128.  * Parameters:
  129.  *  None
  130.  *
  131.  * Return Value:
  132.  *  HRESULT         NOERROR or an error code
  133.  */
  134.  
  135. STDMETHODIMP CImpIOleInPlaceObject::InPlaceDeactivate(void)
  136.     {
  137.     m_pObj->InPlaceDeactivate();
  138.     return NOERROR;
  139.     }
  140.  
  141.  
  142.  
  143.  
  144. /*
  145.  * CImpIOleInPlaceObject::UIDeactivate
  146.  *
  147.  * Purpose:
  148.  *  Instructs the object to just remove any in-place user interface
  149.  *  but to do no other deactivation.  The object should just hide
  150.  *  the UI components but not destroy them until InPlaceDeactivate
  151.  *  is called.
  152.  *
  153.  * Parameters:
  154.  *  None
  155.  *
  156.  * Return Value:
  157.  *  HRESULT         NOERROR or an error code
  158.  */
  159.  
  160. STDMETHODIMP CImpIOleInPlaceObject::UIDeactivate(void)
  161.     {
  162.     m_pObj->UIDeactivate();
  163.     return NOERROR;
  164.     }
  165.  
  166.  
  167.  
  168.  
  169. /*
  170.  * CImpIOleInPlaceObject::SetObjectRects
  171.  *
  172.  * Purpose:
  173.  *  Provides the object with rectangles describing the position of
  174.  *  the object in the container window as well as its visible area.
  175.  *
  176.  * Parameters:
  177.  *  prcPos          LPCRECT providing the object's full rectangle
  178.  *                  relative to the container document.  The object
  179.  *                  should scale to this rectangle.
  180.  *  prcClip         LPCRECT describing the visible area of the object
  181.  *                  which should not draw outside these areas.
  182.  *
  183.  * Return Value:
  184.  *  HRESULT         NOERROR or an error code
  185.  */
  186.  
  187. STDMETHODIMP CImpIOleInPlaceObject::SetObjectRects(LPCRECT prcPos
  188.     , LPCRECT prcClip)
  189.     {
  190.     /*
  191.      * The idea here is to resize the polyline (editor) window to
  192.      * the position rectangle as that defines the scaling.  We then
  193.      * resize the hatch window, the parent of the editor, to the
  194.      * intersection of the clip rectangle and the position rectangle.
  195.      * Since the polyline is the child of the hatch window, the
  196.      * polyline, while still scaled to the position rectangle, is
  197.      * also clipped to the clip rectangle, providing only a partial
  198.      * view of the correctly scaled presentation.
  199.      *
  200.      * The Hatch window takes care of this.
  201.      */
  202.  
  203.     m_pObj->m_pHW->RectsSet((LPRECT)prcPos, (LPRECT)prcClip);
  204.     return NOERROR;
  205.     }
  206.  
  207.  
  208.  
  209.  
  210. /*
  211.  * CImpIOleInPlaceObject::ReactivateAndUndo
  212.  *
  213.  * Purpose:
  214.  *  Instructs the object to reactivate itself in-place and perform
  215.  *  whatever Undo means for it.
  216.  *
  217.  * Parameters:
  218.  *  None
  219.  *
  220.  * Return Value:
  221.  *  HRESULT         NOERROR or an error code
  222.  */
  223.  
  224. STDMETHODIMP CImpIOleInPlaceObject::ReactivateAndUndo(void)
  225.     {
  226.     return m_pObj->InPlaceActivate(m_pObj->m_pIOleClientSite, TRUE);
  227.     }
  228.