home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / oledocip.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  6KB  |  216 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1996-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char BASED_CODE THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. #define new DEBUG_NEW
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // COleDocIPFrameWnd
  22.  
  23. IMPLEMENT_DYNCREATE(COleDocIPFrameWnd, COleIPFrameWnd)
  24.  
  25. BEGIN_MESSAGE_MAP(COleDocIPFrameWnd, COleIPFrameWnd)
  26.     //{{AFX_MSG_MAP(COleDocIPFrameWnd)
  27.         // NOTE - the ClassWizard will add and remove mapping macros here.
  28.     //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30.  
  31. COleDocIPFrameWnd::COleDocIPFrameWnd()
  32. {
  33.     m_hMenuHelpPopup = NULL;
  34. }
  35.  
  36. COleDocIPFrameWnd::~COleDocIPFrameWnd()
  37. {
  38. }
  39.  
  40. void COleDocIPFrameWnd::OnRequestPositionChange(LPCRECT lpRect)
  41. {
  42.     COleServerDoc* pDoc = (COleServerDoc*) GetActiveDocument();
  43.     ASSERT_VALID(pDoc);
  44.     ASSERT_KINDOF(COleServerDoc, pDoc);
  45.  
  46.     // DocObjects don't need to generate OnPosRectChange calls, so we
  47.     // just return if this is a DocObject.
  48.  
  49.     if (pDoc->IsDocObject())
  50.         return;
  51.  
  52.     // The default behavior is to not affect the extent during the
  53.     //  call to RequestPositionChange.  This results in consistent
  54.     //  scaling behavior.
  55.     pDoc->RequestPositionChange(lpRect);
  56. }
  57.  
  58. void COleDocIPFrameWnd::RecalcLayout(BOOL /*bNotify*/)
  59. {
  60.     ASSERT_VALID(this);
  61.  
  62.     COleServerDoc* pDoc = (COleServerDoc*) GetActiveDocument();
  63.     if (pDoc != NULL)
  64.     {
  65.         ASSERT_VALID(pDoc);
  66.         ASSERT_KINDOF(COleServerDoc, pDoc);
  67.     }
  68.  
  69.     // Normal in-place objects put scrollbars on the outside,
  70.     //  DocObjects put them inside
  71.     UINT nAdjustType = (pDoc != NULL && pDoc->IsDocObject())
  72.                                 ? CWnd::adjustBorder : CWnd::adjustOutside;
  73.  
  74.     // better have a parent window (only used for inplace)
  75.     CWnd* pParentWnd = GetParent();
  76.     ASSERT_VALID(pParentWnd);
  77.  
  78.     // first call reposition bars with arbitarily large rect just to
  79.     //  see how much space the bars will take up
  80.     CRect rectBig(0, 0, INT_MAX/2, INT_MAX/2);
  81.     CRect rectLeft;
  82.     RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery,
  83.         &rectLeft, &rectBig);
  84.  
  85.     // grow the rect by the size of the control bars
  86.     CRect rect = m_rectPos;
  87.     rect.left -= rectLeft.left;
  88.     rect.top -= rectLeft.top;
  89.     rect.right += INT_MAX/2 - rectLeft.right;
  90.     rect.bottom += INT_MAX/2 - rectLeft.bottom;
  91.  
  92.     // see how much extra space for non-client areas (such as scrollbars)
  93.     //  that the view needs.
  94.     CWnd* pLeftOver = GetDlgItem(AFX_IDW_PANE_FIRST);
  95.     if (pLeftOver != NULL)
  96.     {
  97.         rectBig = m_rectPos;
  98.         pLeftOver->CalcWindowRect(&rectBig, nAdjustType);
  99.         rect.left -= m_rectPos.left - rectBig.left;
  100.         rect.top -= m_rectPos.top - rectBig.top;
  101.         rect.right += rectBig.right - m_rectPos.right;
  102.         rect.bottom += rectBig.bottom - m_rectPos.bottom;
  103.     }
  104.  
  105.     // adjust for non-client area on the frame window
  106.     CalcWindowRect(&rect, nAdjustType);
  107.  
  108.     // the frame window must be clipped to the visible part in the container
  109.     CRect rectVis;
  110.     rectVis.IntersectRect(&rect, &m_rectClip);
  111.  
  112.     // move the window
  113.     AfxRepositionWindow(NULL, m_hWnd, &rectVis);
  114.  
  115.     // now resize the control bars relative to the (now moved) frame
  116.     pParentWnd->ClientToScreen(&rect);
  117.     ScreenToClient(&rect);
  118.     RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST,
  119.         CWnd::reposDefault, NULL, &rect);
  120. }
  121.  
  122. BOOL COleDocIPFrameWnd::BuildSharedMenu()
  123. {
  124.     HMENU hMenu = GetInPlaceMenu();
  125.  
  126.     // create shared menu
  127.     ASSERT(m_hSharedMenu == NULL);
  128.     if ((m_hSharedMenu = ::CreateMenu()) == NULL)
  129.         return FALSE;
  130.  
  131.     // start out by getting menu from container
  132.     memset(&m_menuWidths, 0, sizeof m_menuWidths);
  133.     if (m_lpFrame->InsertMenus(m_hSharedMenu, &m_menuWidths) != NOERROR)
  134.     {
  135.         ::DestroyMenu(m_hSharedMenu);
  136.         m_hSharedMenu = NULL;
  137.         return FALSE;
  138.     }
  139.  
  140. #ifdef _DEBUG
  141.     // container shouldn't touch these
  142.     ASSERT(m_menuWidths.width[1] == 0);
  143.     ASSERT(m_menuWidths.width[3] == 0);
  144.  
  145.     // container shouldn't touch this unless we're working with a DocObject
  146.     COleServerDoc* pDoc = (COleServerDoc*) GetActiveDocument();
  147.     ASSERT_VALID(pDoc);
  148.     ASSERT_KINDOF(COleServerDoc, pDoc);
  149.     if (!pDoc->IsDocObject())
  150.         ASSERT(m_menuWidths.width[5] == 0);
  151. #endif
  152.  
  153.     // only copy the popups if there is a menu loaded
  154.     if (hMenu == NULL)
  155.         return TRUE;
  156.  
  157.     // insert our menu popups amongst the container menus
  158.     m_hMenuHelpPopup = AfxMergeMenus(m_hSharedMenu, hMenu,
  159.         &m_menuWidths.width[0], 1, TRUE);
  160.  
  161.     // finally create the special OLE menu descriptor
  162.     m_hOleMenu = ::OleCreateMenuDescriptor(m_hSharedMenu, &m_menuWidths);
  163.  
  164.     return m_hOleMenu != NULL;
  165. }
  166.  
  167. void COleDocIPFrameWnd::DestroySharedMenu()
  168. {
  169.     if (m_hSharedMenu == NULL)
  170.     {
  171.         ASSERT(m_hOleMenu == NULL);
  172.         ASSERT(m_hMenuHelpPopup == NULL);
  173.         return;
  174.     }
  175.  
  176.     // get in-place menu to be unmerged (must be same as during activation)
  177.     HMENU hMenu = GetInPlaceMenu();
  178.     if (hMenu == NULL)
  179.         return;
  180.  
  181.     // remove our menu popups from the shared menu
  182.     AfxUnmergeMenus(m_hSharedMenu, hMenu, m_hMenuHelpPopup);
  183.  
  184.     // allow container to remove its items from the menu
  185.     ASSERT(m_lpFrame != NULL);
  186.     VERIFY(m_lpFrame->RemoveMenus(m_hSharedMenu) == NOERROR);
  187.  
  188.     // now destroy the menu
  189.     ::DestroyMenu(m_hSharedMenu);
  190.     m_hSharedMenu = NULL;
  191.     if (m_hOleMenu != NULL)
  192.     {
  193.         VERIFY(::OleDestroyMenuDescriptor(m_hOleMenu) == NOERROR);
  194.         m_hOleMenu = NULL;
  195.     }
  196.     m_hMenuHelpPopup = NULL;
  197. }
  198.  
  199. /////////////////////////////////////////////////////////////////////////////
  200. // COleDocIPFrameWnd diagnostics
  201.  
  202. #ifdef _DEBUG
  203. void COleDocIPFrameWnd::AssertValid() const
  204. {
  205.     COleIPFrameWnd::AssertValid();
  206. }
  207.  
  208. void COleDocIPFrameWnd::Dump(CDumpContext& dc) const
  209. {
  210.     COleIPFrameWnd::Dump(dc);
  211. }
  212. #endif //_DEBUG
  213.  
  214.  
  215. /////////////////////////////////////////////////////////////////////////////
  216.