oledocip.cpp 5.9 KB

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