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

  1. /*
  2.  * IIPUIWIN.CPP
  3.  * Patron Chapter 22
  4.  *
  5.  * IOleInPlaceUIWindow interface implementation for Patron's
  6.  * documents.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "patron.h"
  17.  
  18.  
  19. /*
  20.  * CImpIOleInPlaceUIWindow::CImpIOleInPlaceUIWindow
  21.  * CImpIOleInPlaceUIWindow::~CImpIOleInPlaceUIWindow
  22.  *
  23.  * Parameters (Constructor):
  24.  *  pDoc            PCPatronDoc of the document we're in.
  25.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  26.  */
  27.  
  28. CImpIOleInPlaceUIWindow::CImpIOleInPlaceUIWindow(PCPatronDoc pDoc
  29.     , LPUNKNOWN pUnkOuter)
  30.     {
  31.     m_cRef=0;
  32.     m_pDoc=pDoc;
  33.     m_pUnkOuter=pUnkOuter;
  34.     return;
  35.     }
  36.  
  37. CImpIOleInPlaceUIWindow::~CImpIOleInPlaceUIWindow(void)
  38.     {
  39.     return;
  40.     }
  41.  
  42.  
  43.  
  44. /*
  45.  * CImpIOleInPlaceUIWindow::QueryInterface
  46.  * CImpIOleInPlaceUIWindow::AddRef
  47.  * CImpIOleInPlaceUIWindow::Release
  48.  *
  49.  * Purpose:
  50.  *  IUnknown members for CImpIOleInPlaceUIWindow object.
  51.  */
  52.  
  53. STDMETHODIMP CImpIOleInPlaceUIWindow::QueryInterface(REFIID riid
  54.     , PPVOID ppv)
  55.     {
  56.     return m_pUnkOuter->QueryInterface(riid, ppv);
  57.     }
  58.  
  59.  
  60. STDMETHODIMP_(ULONG) CImpIOleInPlaceUIWindow::AddRef(void)
  61.     {
  62.     ++m_cRef;
  63.     return m_pUnkOuter->AddRef();
  64.     }
  65.  
  66. STDMETHODIMP_(ULONG) CImpIOleInPlaceUIWindow::Release(void)
  67.     {
  68.     --m_cRef;
  69.     return m_pUnkOuter->Release();
  70.     }
  71.  
  72.  
  73.  
  74.  
  75. /*
  76.  * CImpIOleInPlaceUIWindow::GetWindow
  77.  *
  78.  * Purpose:
  79.  *  Retrieves the handle of the window associated with the object
  80.  *  on which this interface is implemented.
  81.  *
  82.  * Parameters:
  83.  *  phWnd           HWND * in which to store the window handle.
  84.  *
  85.  * Return Value:
  86.  *  HRESULT         NOERROR if successful, E_FAIL if there is no
  87.  *                  window.
  88.  */
  89.  
  90. STDMETHODIMP CImpIOleInPlaceUIWindow::GetWindow(HWND *phWnd)
  91.     {
  92.     *phWnd=m_pDoc->m_hWnd;
  93.     return NOERROR;
  94.     }
  95.  
  96.  
  97.  
  98.  
  99. /*
  100.  * CImpIOleInPlaceUIWindow::ContextSensitiveHelp
  101.  *
  102.  * Purpose:
  103.  *  Instructs the object on which this interface is implemented to
  104.  *  enter or leave a context-sensitive help mode.
  105.  *
  106.  * Parameters:
  107.  *  fEnterMode      BOOL TRUE to enter the mode, FALSE otherwise.
  108.  *
  109.  * Return Value:
  110.  *  HRESULT         NOERROR or an appropriate error code.
  111.  */
  112.  
  113. STDMETHODIMP CImpIOleInPlaceUIWindow::ContextSensitiveHelp
  114.     (BOOL fEnterMode)
  115.     {
  116.    #ifdef MDI
  117.     //Only MDI documents care
  118.     if (NULL!=m_pDoc->m_pIOleIPActiveObject)
  119.         {
  120.         m_pDoc->m_pIOleIPActiveObject->ContextSensitiveHelp
  121.            (fEnterMode);
  122.         }
  123.    #endif
  124.     return NOERROR;
  125.     }
  126.  
  127.  
  128.  
  129.  
  130. /*
  131.  * CImpIOleInPlaceUIWindow::GetBorder
  132.  *
  133.  * Purpose:
  134.  *  Returns the rectangle in which the container is willing to
  135.  *  negotiate about an object's adornments.
  136.  *
  137.  * Parameters:
  138.  *  prcBorder       LPRECT in which to store the rectangle.
  139.  *
  140.  * Return Value:
  141.  *  HRESULT         NOERROR if all is well, INPLACE_E_NOTOOLSPACE if
  142.  *                  there is no negotiable space.
  143.  */
  144.  
  145. STDMETHODIMP CImpIOleInPlaceUIWindow::GetBorder(LPRECT prcBorder)
  146.     {
  147.     if (NULL==prcBorder)
  148.         return ResultFromScode(E_INVALIDARG);
  149.  
  150.     /*
  151.      * All of the document window space is available for negotiation
  152.      * since we can resize the Pages window to anything we want.  So
  153.      * we just return the entire client rectangle here.
  154.      */
  155.     GetClientRect(m_pDoc->m_hWnd, prcBorder);
  156.     return NOERROR;
  157.     }
  158.  
  159.  
  160.  
  161.  
  162. /*
  163.  * CImpIOleInPlaceUIWindow::RequestBorderSpace
  164.  *
  165.  * Purpose:
  166.  *  Asks the container if it can surrender the amount of space
  167.  *  in pBW that the object would like for it's adornments.  The
  168.  *  container does nothing but validate the spaces on this call.
  169.  *
  170.  * Parameters:
  171.  *  pBW             LPCBORDERWIDTHS containing the requested space.
  172.  *                  The values are the amount of space requested
  173.  *                  from each side of the relevant window.
  174.  *
  175.  * Return Value:
  176.  *  HRESULT         NOERROR if we can give up space,
  177.  *                  INPLACE_E_NOTOOLSPACE otherwise.
  178.  */
  179.  
  180. STDMETHODIMP CImpIOleInPlaceUIWindow::RequestBorderSpace
  181.     (LPCBORDERWIDTHS pBW)
  182.     {
  183.     //We don't have any restrictions, so we always return NOERROR.
  184.     return NOERROR;
  185.     }
  186.  
  187.  
  188.  
  189.  
  190. /*
  191.  * CImpIOleInPlaceUIWindow::SetBorderSpace
  192.  *
  193.  * Purpose:
  194.  *  Called when the object now officially requests that the
  195.  *  container surrender border space it previously allowed in
  196.  *  RequestBorderSpace.  The container should resize windows
  197.  *  appropriately to surrender this space.
  198.  *
  199.  * Parameters:
  200.  *  pBW             LPCBORDERWIDTHS containing the amount of space
  201.  *                  from each side of the relevant window that
  202.  *                  the object is now reserving.
  203.  *
  204.  * Return Value:
  205.  *  HRESULT         NOERROR
  206.  */
  207.  
  208. STDMETHODIMP CImpIOleInPlaceUIWindow::SetBorderSpace
  209.     (LPCBORDERWIDTHS pBW)
  210.     {
  211.     RECT        rc;
  212.     HWND        hWndDoc;
  213.     HWND        hWndPages;
  214.     POINT       pt1, pt2;
  215.  
  216.     if (NULL==pBW)
  217.         return NOERROR;
  218.  
  219.     /*
  220.      * Now we just have to resize the Pages window to make room for
  221.      * the object's tools or resize it to occupy the full document
  222.      * if we're reverting to normal.
  223.      */
  224.  
  225.     hWndDoc=m_pDoc->m_hWnd;
  226.     hWndPages=m_pDoc->m_pPG->Window();
  227.  
  228.     //Get the current offset of the Pages
  229.     GetWindowRect(hWndPages, &rc);
  230.     SETPOINT(pt1, rc.left, rc.top);
  231.     SETPOINT(pt2, rc.right, rc.bottom);
  232.     ScreenToClient(hWndDoc, &pt1);
  233.     ScreenToClient(hWndDoc, &pt2);
  234.  
  235.     GetClientRect(hWndDoc, &rc);
  236.  
  237.     if (NULL!=pBW)
  238.         {
  239.         rc.left+=pBW->left;
  240.         rc.right-=pBW->right;
  241.         rc.top+=pBW->top;
  242.         rc.bottom-=pBW->bottom;
  243.         }
  244.  
  245.     //Only move Pages if necessary
  246.     if (!(pt1.x==rc.left && pt1.y==rc.top
  247.         && pt2.x==rc.right && pt2.y==rc.bottom))
  248.         {
  249.         SendMessage(hWndDoc, WM_SETREDRAW, FALSE, 0L);
  250.         ShowWindow(hWndPages, SW_HIDE);
  251.  
  252.         m_pDoc->m_pPG->RectSet(&rc, FALSE);
  253.  
  254.         /*
  255.          * Scroll the Pages in the opposite direction to keep
  256.          * objects steady.
  257.          */
  258.  
  259.         SendScrollPosition(hWndPages, WM_HSCROLL, pBW->left-pt1.x);
  260.         SendScrollPosition(hWndPages, WM_VSCROLL, pBW->top-pt1.y);
  261.  
  262.         SendMessage(hWndDoc, WM_SETREDRAW, TRUE, 0L);
  263.         ShowWindow(hWndPages, SW_SHOW);
  264.         }
  265.  
  266.  
  267.     return NOERROR;
  268.     }
  269.  
  270.  
  271.  
  272.  
  273. /*
  274.  * CImpIOleInPlaceUIWindow::SetActiveObject
  275.  *
  276.  * Purpose:
  277.  *  Provides the container with the object's IOleInPlaceActiveObject
  278.  *  pointer.
  279.  *
  280.  * Parameters:
  281.  *  pIIPActiveObj   LPOLEINPLACEACTIVEOBJECT of interest.
  282.  *  pszObj          LPCOLESTR naming the object.  Not used.
  283.  *
  284.  * Return Value:
  285.  *  HRESULT         NOERROR
  286.  */
  287.  
  288. STDMETHODIMP CImpIOleInPlaceUIWindow::SetActiveObject(
  289.     LPOLEINPLACEACTIVEOBJECT pIIPActiveObj, LPCOLESTR pszObj)
  290.     {
  291.     if (NULL!=m_pDoc->m_pIOleIPActiveObject)
  292.         m_pDoc->m_pIOleIPActiveObject->Release();
  293.  
  294.     //NULLs m_pIOleIPActiveObject if pIIPActiveObj is NULL
  295.     m_pDoc->m_pIOleIPActiveObject=pIIPActiveObj;
  296.  
  297.     if (NULL!=m_pDoc->m_pIOleIPActiveObject)
  298.         m_pDoc->m_pIOleIPActiveObject->AddRef();
  299.  
  300.     return NOERROR;
  301.     }
  302.