NGenericDockBar.cpp
上传用户:libwxy
上传日期:2007-01-02
资源大小:200k
文件大小:7k
源码类别:

工具条

开发平台:

Visual C++

  1. // NGenericDockBar.cpp: implementation of the CNGenericDockBar class.
  2. //
  3. /*
  4. Copyright (C) 1998 Tony Hoyle (tmh@netfusion.co.uk)
  5. This program is free software; you can redistribute it and/or modify it under the terms
  6. of the GNU General Public License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  9. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along with this program;
  12. if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  13. */
  14. //////////////////////////////////////////////////////////////////////
  15. #include "stdafx.h"
  16. #include "NGenericDockBar.h"
  17. #include "NGenericToolBar.h"
  18. #include "afxpriv.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[]=__FILE__;
  22. #define new DEBUG_NEW
  23. #endif
  24. IMPLEMENT_DYNCREATE(CNGenericDockBar,CDockBar)
  25. BEGIN_MESSAGE_MAP(CNGenericDockBar,CDockBar)
  26. //{{AFX_MSG_MAP(CNGenericDockBar)
  27. //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29. //////////////////////////////////////////////////////////////////////
  30. // Construction/Destruction
  31. //////////////////////////////////////////////////////////////////////
  32. CNGenericDockBar::CNGenericDockBar()
  33. {
  34. }
  35. CNGenericDockBar::~CNGenericDockBar()
  36. {
  37. }
  38. CSize CNGenericDockBar::CalcFixedLayout( BOOL bStretch, BOOL bHorz )
  39. {
  40. ASSERT_VALID(this);
  41. CSize sizeFixed = CControlBar::CalcFixedLayout(bStretch, bHorz);
  42. // get max size
  43. CSize sizeMax;
  44. if (!m_rectLayout.IsRectEmpty())
  45. sizeMax = m_rectLayout.Size();
  46. else
  47. {
  48. CRect rectFrame;
  49. CFrameWnd* pFrame = GetParentFrame();
  50. pFrame->GetClientRect(&rectFrame);
  51. sizeMax = rectFrame.Size();
  52. }
  53. const int NormalcxBorder2=GetSystemMetrics(SM_CYBORDER)*2;
  54. const int NormalcyBorder2=2;
  55. const int AltcxBorder2=0;
  56. const int AltcyBorder2=0;
  57. int cxBorder2=0;
  58. int cyBorder2=0;
  59. // prepare for layout
  60. AFX_SIZEPARENTPARAMS layout;
  61. layout.hDWP = m_bLayoutQuery ?
  62. NULL : ::BeginDeferWindowPos(m_arrBars.GetSize());
  63. CPoint pt(-cxBorder2, -NormalcyBorder2);
  64. int nWidth = 0;
  65. BOOL bWrapped = FALSE;
  66. // layout all the control bars
  67. for (int nPos = 0; nPos < m_arrBars.GetSize(); nPos++)
  68. {
  69. CControlBar* pBar = GetDockedControlBar(nPos);
  70. void* pVoid = m_arrBars[nPos];
  71. if (pBar != NULL)
  72. {
  73. if (pBar->IsVisible())
  74. {
  75. if(pBar->IsKindOf(RUNTIME_CLASS(CNGenericToolBar)))
  76. {
  77. cxBorder2=AltcxBorder2;
  78. cyBorder2=AltcyBorder2;
  79. }
  80. else
  81. {
  82. cxBorder2=NormalcxBorder2;
  83. cyBorder2=NormalcyBorder2;
  84. }
  85. // get ideal rect for bar
  86. DWORD dwMode = 0;
  87. if ((pBar->m_dwStyle & CBRS_SIZE_DYNAMIC) &&
  88. (pBar->m_dwStyle & CBRS_FLOATING))
  89. dwMode |= LM_HORZ | LM_MRUWIDTH;
  90. else if (pBar->m_dwStyle & CBRS_ORIENT_HORZ)
  91. dwMode |= LM_HORZ | LM_HORZDOCK;
  92. else
  93. dwMode |=  LM_VERTDOCK;
  94. CSize sizeBar = pBar->CalcDynamicLayout(-1, dwMode);
  95. CRect rect(pt, sizeBar);
  96. // get current rect for bar
  97. CRect rectBar;
  98. pBar->GetWindowRect(&rectBar);
  99. ScreenToClient(&rectBar);
  100. if (bHorz)
  101. {
  102. // Offset Calculated Rect out to Actual
  103. if (rectBar.left > rect.left && !m_bFloating)
  104. rect.OffsetRect(rectBar.left - rect.left, 0);
  105. // If ControlBar goes off the right, then right justify
  106. if (rect.right > sizeMax.cx && !m_bFloating)
  107. {
  108. int x = rect.Width() - cxBorder2;
  109. x = max(sizeMax.cx - x, pt.x);
  110. rect.OffsetRect(x - rect.left, 0);
  111. }
  112. // If ControlBar has been wrapped, then left justify
  113. if (bWrapped)
  114. {
  115. bWrapped = FALSE;
  116. rect.OffsetRect(-(rect.left + cxBorder2), 0);
  117. }
  118. // If ControlBar is completely invisible, then wrap it
  119. else if ((rect.left >= (sizeMax.cx - cxBorder2)) &&
  120. (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
  121. {
  122. m_arrBars.InsertAt(nPos, (CObject*)NULL);
  123. pBar = NULL; pVoid = NULL;
  124. bWrapped = TRUE;
  125. }
  126. if (!bWrapped)
  127. {
  128. if (rect != rectBar)
  129. {
  130. if (!m_bLayoutQuery &&
  131. !(pBar->m_dwStyle & CBRS_FLOATING))
  132. {
  133. pBar->m_pDockContext->m_rectMRUDockPos = rect;
  134. }
  135. AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
  136. }
  137. pt.x = rect.left + sizeBar.cx - cxBorder2;
  138. nWidth = max(nWidth, sizeBar.cy);
  139. }
  140. }
  141. else
  142. {
  143. // Offset Calculated Rect out to Actual
  144. if (rectBar.top > rect.top && !m_bFloating)
  145. rect.OffsetRect(0, rectBar.top - rect.top);
  146. // If ControlBar goes off the bottom, then bottom justify
  147. if (rect.bottom > sizeMax.cy && !m_bFloating)
  148. {
  149. int y = rect.Height() - cyBorder2;
  150. y = max(sizeMax.cy - y, pt.y);
  151. rect.OffsetRect(0, y - rect.top);
  152. }
  153. // If ControlBar has been wrapped, then top justify
  154. if (bWrapped)
  155. {
  156. bWrapped = FALSE;
  157. rect.OffsetRect(0, -(rect.top + cyBorder2));
  158. }
  159. // If ControlBar is completely invisible, then wrap it
  160. else if ((rect.top >= (sizeMax.cy - cyBorder2)) &&
  161. (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
  162. {
  163. m_arrBars.InsertAt(nPos, (CObject*)NULL);
  164. pBar = NULL; pVoid = NULL;
  165. bWrapped = TRUE;
  166. }
  167. if (!bWrapped)
  168. {
  169. if (rect != rectBar)
  170. {
  171. if (!m_bLayoutQuery &&
  172. !(pBar->m_dwStyle & CBRS_FLOATING))
  173. {
  174. pBar->m_pDockContext->m_rectMRUDockPos = rect;
  175. }
  176. AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
  177. }
  178. pt.y = rect.top + sizeBar.cy - cyBorder2;
  179. nWidth = max(nWidth, sizeBar.cx);
  180. }
  181. }
  182. }
  183. if (!bWrapped)
  184. {
  185. // handle any delay/show hide for the bar
  186. pBar->RecalcDelayShow(&layout);
  187. }
  188. }
  189. if (pBar == NULL && pVoid == NULL && nWidth != 0)
  190. {
  191. // end of row because pBar == NULL
  192. if (bHorz)
  193. {
  194. pt.y += nWidth - cyBorder2;
  195. sizeFixed.cx = max(sizeFixed.cx, pt.x);
  196. sizeFixed.cy = max(sizeFixed.cy, pt.y);
  197. pt.x = -cxBorder2;
  198. }
  199. else
  200. {
  201. pt.x += nWidth - cxBorder2;
  202. sizeFixed.cx = max(sizeFixed.cx, pt.x);
  203. sizeFixed.cy = max(sizeFixed.cy, pt.y);
  204. pt.y = -cyBorder2;
  205. }
  206. nWidth = 0;
  207. }
  208. }
  209. if (!m_bLayoutQuery)
  210. {
  211. // move and resize all the windows at once!
  212. if (layout.hDWP == NULL || !::EndDeferWindowPos(layout.hDWP))
  213. TRACE0("Warning: DeferWindowPos failed - low system resources.n");
  214. }
  215. // adjust size for borders on the dock bar itself
  216. CRect rect;
  217. rect.SetRectEmpty();
  218. CalcInsideRect(rect, bHorz);
  219. if ((!bStretch || !bHorz) && sizeFixed.cx != 0)
  220. sizeFixed.cx += -rect.right + rect.left;
  221. if ((!bStretch || bHorz) && sizeFixed.cy != 0)
  222. sizeFixed.cy += -rect.bottom + rect.top;
  223. return sizeFixed;
  224. }