OAMDOCKBAR.CPP
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:6k
源码类别:

SNMP编程

开发平台:

C/C++

  1. // OAMDockBar.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "OAMDockBar.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // COAMDockBar
  12. COAMDockBar::COAMDockBar()
  13. {
  14. // TODO: add construction code here.
  15. }
  16. COAMDockBar::~COAMDockBar()
  17. {
  18. // TODO: add destruction code here.
  19. }
  20. IMPLEMENT_DYNAMIC(COAMDockBar, CDockBar)
  21. BEGIN_MESSAGE_MAP(COAMDockBar, CDockBar)
  22. //{{AFX_MSG_MAP(COAMDockBar)
  23. // NOTE - the ClassWizard will add and remove mapping macros here.
  24. //    DO NOT EDIT what you see in these blocks of generated code!
  25. //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // COAMDockBar message handlers
  29. CSize COAMDockBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
  30. {
  31. ASSERT_VALID(this);
  32. CSize sizeFixed = CControlBar::CalcFixedLayout(bStretch, bHorz);
  33. // get max size
  34. CSize sizeMax;
  35. if (!m_rectLayout.IsRectEmpty())
  36. sizeMax = m_rectLayout.Size();
  37. else
  38. {
  39. CRect rectFrame;
  40. CFrameWnd* pFrame = GetParentFrame();
  41. pFrame->GetClientRect(&rectFrame);
  42. sizeMax = rectFrame.Size();
  43. }
  44. // prepare for layout
  45. AFX_SIZEPARENTPARAMS layout;
  46. layout.hDWP = m_bLayoutQuery ?
  47. NULL : ::BeginDeferWindowPos(m_arrBars.GetSize());
  48. int cxBorder = 2, cyBorder = 2;
  49. CPoint pt(-cxBorder, -cyBorder);
  50. int nWidth = 0;
  51. BOOL bWrapped = FALSE;
  52. // layout all the control bars
  53. for (int nPos = 0; nPos < m_arrBars.GetSize(); nPos++)
  54. {
  55. CControlBar* pBar = GetDockedControlBar(nPos);
  56. void* pVoid = m_arrBars[nPos];
  57. if (pBar != NULL)
  58. {
  59. if (pBar->IsKindOf(RUNTIME_CLASS(CToolBar)))
  60. cxBorder = cyBorder = 0;
  61. else
  62. cxBorder = cyBorder = 2;
  63. if (pBar->IsVisible())
  64. {
  65. // get ideal rect for bar
  66. DWORD dwMode = 0;
  67. if ((pBar->m_dwStyle & CBRS_SIZE_DYNAMIC) &&
  68. (pBar->m_dwStyle & CBRS_FLOATING))
  69. dwMode |= LM_HORZ | LM_MRUWIDTH;
  70. else if (pBar->m_dwStyle & CBRS_ORIENT_HORZ)
  71. dwMode |= LM_HORZ | LM_HORZDOCK;
  72. else
  73. dwMode |=  LM_VERTDOCK;
  74. CSize sizeBar = pBar->CalcDynamicLayout(-1, dwMode);
  75. CRect rect(pt, sizeBar);
  76. // get current rect for bar
  77. CRect rectBar;
  78. pBar->GetWindowRect(&rectBar);
  79. ScreenToClient(&rectBar);
  80. if (bHorz)
  81. {
  82. // Offset Calculated Rect out to Actual
  83. if (rectBar.left > rect.left && !m_bFloating)
  84. rect.OffsetRect(rectBar.left - rect.left, 0);
  85. // If ControlBar goes off the right, then right justify
  86. if (rect.right > sizeMax.cx && !m_bFloating)
  87. {
  88. int x = rect.Width() - cxBorder;
  89. x = max(sizeMax.cx - x, pt.x);
  90. rect.OffsetRect(x - rect.left, 0);
  91. }
  92. // If ControlBar has been wrapped, then left justify
  93. if (bWrapped)
  94. {
  95. bWrapped = FALSE;
  96. rect.OffsetRect(-(rect.left + cxBorder), 0);
  97. }
  98. // If ControlBar is completely invisible, then wrap it
  99. else if ((rect.left >= (sizeMax.cx - cxBorder)) &&
  100. (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
  101. {
  102. m_arrBars.InsertAt(nPos, (CObject*)NULL);
  103. pBar = NULL; pVoid = NULL;
  104. bWrapped = TRUE;
  105. }
  106. if (!bWrapped)
  107. {
  108. if (rect != rectBar)
  109. {
  110. if (!m_bLayoutQuery &&
  111. !(pBar->m_dwStyle & CBRS_FLOATING))
  112. {
  113. pBar->m_pDockContext->m_rectMRUDockPos = rect;
  114. }
  115. AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
  116. }
  117. pt.x = rect.left + sizeBar.cx - cxBorder;
  118. nWidth = max(nWidth, sizeBar.cy);
  119. }
  120. }
  121. else
  122. {
  123. // Offset Calculated Rect out to Actual
  124. if (rectBar.top > rect.top && !m_bFloating)
  125. rect.OffsetRect(0, rectBar.top - rect.top);
  126. // If ControlBar goes off the bottom, then bottom justify
  127. if (rect.bottom > sizeMax.cy && !m_bFloating)
  128. {
  129. int y = rect.Height() - cyBorder;
  130. y = max(sizeMax.cy - y, pt.y);
  131. rect.OffsetRect(0, y - rect.top);
  132. }
  133. // If ControlBar has been wrapped, then top justify
  134. if (bWrapped)
  135. {
  136. bWrapped = FALSE;
  137. rect.OffsetRect(0, -(rect.top + cyBorder));
  138. }
  139. // If ControlBar is completely invisible, then wrap it
  140. else if ((rect.top >= (sizeMax.cy - cyBorder)) &&
  141. (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
  142. {
  143. m_arrBars.InsertAt(nPos, (CObject*)NULL);
  144. pBar = NULL; pVoid = NULL;
  145. bWrapped = TRUE;
  146. }
  147. if (!bWrapped)
  148. {
  149. if (rect != rectBar)
  150. {
  151. if (!m_bLayoutQuery &&
  152. !(pBar->m_dwStyle & CBRS_FLOATING))
  153. {
  154. pBar->m_pDockContext->m_rectMRUDockPos = rect;
  155. }
  156. AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
  157. }
  158. pt.y = rect.top + sizeBar.cy - cyBorder;
  159. nWidth = max(nWidth, sizeBar.cx);
  160. }
  161. }
  162. }
  163. if (!bWrapped)
  164. {
  165. // handle any delay/show hide for the bar
  166. pBar->RecalcDelayShow(&layout);
  167. }
  168. }
  169. if (pBar == NULL && pVoid == NULL && nWidth != 0)
  170. {
  171. // end of row because pBar == NULL
  172. if (bHorz)
  173. {
  174. pt.y += nWidth - cyBorder;
  175. sizeFixed.cx = max(sizeFixed.cx, pt.x);
  176. sizeFixed.cy = max(sizeFixed.cy, pt.y);
  177. pt.x = -cxBorder;
  178. }
  179. else
  180. {
  181. pt.x += nWidth - cxBorder;
  182. sizeFixed.cx = max(sizeFixed.cx, pt.x);
  183. sizeFixed.cy = max(sizeFixed.cy, pt.y);
  184. pt.y = -cyBorder;
  185. }
  186. nWidth = 0;
  187. }
  188. }
  189. if (!m_bLayoutQuery)
  190. {
  191. // move and resize all the windows at once!
  192. if (layout.hDWP == NULL || !::EndDeferWindowPos(layout.hDWP))
  193. TRACE0(_T("Warning: DeferWindowPos failed - low system resources.n"));
  194. }
  195. // adjust size for borders on the dock bar itself
  196. CRect rect;
  197. rect.SetRectEmpty();
  198. CalcInsideRect(rect, bHorz);
  199. if ((!bStretch || !bHorz) && sizeFixed.cx != 0)
  200. sizeFixed.cx += -rect.right + rect.left;
  201. if ((!bStretch || bHorz) && sizeFixed.cy != 0)
  202. sizeFixed.cy += -rect.bottom + rect.top;
  203. return sizeFixed;
  204. }