bardock.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-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 AFX_CORE3_SEG
  12. #pragma code_seg(AFX_CORE3_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #define new DEBUG_NEW
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CDockBar
  21. BEGIN_MESSAGE_MAP(CDockBar, CControlBar)
  22. //{{AFX_MSG_MAP(CDockBar)
  23. ON_WM_NCCALCSIZE()
  24. ON_WM_NCPAINT()
  25. ON_WM_WINDOWPOSCHANGING()
  26. ON_WM_PAINT()
  27. ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
  28. //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CDockBar construction
  32. CDockBar::CDockBar(BOOL bFloating)
  33. {
  34. m_bFloating = bFloating;
  35. m_bAutoDelete = TRUE;
  36. m_arrBars.Add(NULL);
  37. m_bLayoutQuery = FALSE;
  38. m_rectLayout.SetRectEmpty();
  39. // assume no margins
  40. m_cxLeftBorder = m_cxRightBorder = m_cyBottomBorder = m_cyTopBorder = 0;
  41. }
  42. CDockBar::~CDockBar()
  43. {
  44. for (int i = 0; i < m_arrBars.GetSize(); i++)
  45. {
  46. CControlBar* pBar = GetDockedControlBar(i);
  47. if (pBar != NULL && pBar->m_pDockBar == this)
  48. pBar->m_pDockBar = NULL;
  49. }
  50. }
  51. BOOL CDockBar::Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID)
  52. {
  53. ASSERT(pParentWnd != NULL);
  54. ASSERT_KINDOF(CFrameWnd, pParentWnd);
  55. // save the style
  56. m_dwStyle = (dwStyle & CBRS_ALL);
  57. VERIFY(AfxDeferRegisterClass(AFX_WNDCONTROLBAR_REG));
  58. // create the HWND
  59. CRect rect;
  60. rect.SetRectEmpty();
  61. // Note: Parent must resize itself for control bar to be resized
  62. return CWnd::Create(_afxWndControlBar, NULL, dwStyle, rect, pParentWnd, nID);
  63. }
  64. BOOL CDockBar::IsDockBar() const
  65. {
  66. return TRUE;
  67. }
  68. int CDockBar::GetDockedCount() const
  69. {
  70. int nCount = 0;
  71. for (int i = 0; i < m_arrBars.GetSize(); i++)
  72. {
  73. if (GetDockedControlBar(i) != NULL)
  74. nCount++;
  75. }
  76. return nCount;
  77. }
  78. int CDockBar::GetDockedVisibleCount() const
  79. {
  80. int nCount = 0;
  81. for (int i = 0; i < m_arrBars.GetSize(); i++)
  82. {
  83. CControlBar* pBar = STATIC_DOWNCAST(CControlBar, (CObject*)GetDockedControlBar(i));
  84. if (pBar != NULL && pBar->IsVisible())
  85. nCount++;
  86. }
  87. return nCount;
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CDockBar operations
  91. void CDockBar::DockControlBar(CControlBar* pBar, LPCRECT lpRect)
  92. {
  93. ASSERT_VALID(this);
  94. ASSERT_VALID(pBar);
  95. ASSERT_KINDOF(CControlBar, pBar);
  96. CRect rectBar;
  97. pBar->GetWindowRect(&rectBar);
  98. if (pBar->m_pDockBar == this && (lpRect == NULL || rectBar == *lpRect))
  99. {
  100. // already docked and no change in position
  101. return;
  102. }
  103. // set CBRS_FLOAT_MULTI style if docking bar has it
  104. if (m_bFloating && (pBar->m_dwDockStyle & CBRS_FLOAT_MULTI))
  105. m_dwStyle |= CBRS_FLOAT_MULTI;
  106. m_dwStyle &= ~(CBRS_SIZE_FIXED | CBRS_SIZE_DYNAMIC);
  107. m_dwStyle |= pBar->m_dwStyle & (CBRS_SIZE_FIXED | CBRS_SIZE_DYNAMIC);
  108. if (!(m_dwStyle & CBRS_FLOAT_MULTI))
  109. {
  110. TCHAR szTitle[_MAX_PATH];
  111. pBar->GetWindowText(szTitle, _countof(szTitle));
  112. AfxSetWindowText(m_hWnd, szTitle);
  113. }
  114. // align correctly and turn on all borders
  115. DWORD dwStyle = pBar->GetBarStyle();
  116. dwStyle &= ~(CBRS_ALIGN_ANY);
  117. dwStyle |= (m_dwStyle & CBRS_ALIGN_ANY) | CBRS_BORDER_ANY;
  118. if (m_bFloating)
  119. dwStyle |= CBRS_FLOATING;
  120. else
  121. dwStyle &= ~CBRS_FLOATING;
  122. pBar->SetBarStyle(dwStyle);
  123. // hide first if changing to a new docking site to avoid flashing
  124. BOOL bShow = FALSE;
  125. if (pBar->m_pDockBar != this && pBar->IsWindowVisible())
  126. {
  127. pBar->SetWindowPos(NULL, 0, 0, 0, 0,
  128. SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_HIDEWINDOW);
  129. bShow = TRUE;
  130. }
  131. int nPos = -1;
  132. if (lpRect != NULL)
  133. {
  134. // insert into appropriate row
  135. CRect rect(lpRect);
  136. ScreenToClient(&rect);
  137. CPoint ptMid(rect.left + rect.Width()/2, rect.top + rect.Height()/2);
  138. nPos = Insert(pBar, rect, ptMid);
  139. // position at requested position
  140. pBar->SetWindowPos(NULL, rect.left, rect.top, rect.Width(),
  141. rect.Height(), SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS);
  142. }
  143. else
  144. {
  145. // always add on current row, then create new one
  146. m_arrBars.Add(pBar);
  147. m_arrBars.Add(NULL);
  148. // align off the edge initially
  149. pBar->SetWindowPos(NULL, -afxData.cxBorder2, -afxData.cyBorder2, 0, 0,
  150. SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS);
  151. }
  152. // attach it to the docking site
  153. if (pBar->GetParent() != this)
  154. pBar->SetParent(this);
  155. if (pBar->m_pDockBar == this)
  156. pBar->m_pDockBar->RemoveControlBar(pBar, nPos);
  157. else if (pBar->m_pDockBar != NULL)
  158. pBar->m_pDockBar->RemoveControlBar(pBar, -1, m_bFloating && !pBar->m_pDockBar->m_bFloating);
  159. pBar->m_pDockBar = this;
  160. if (bShow)
  161. {
  162. ASSERT(!pBar->IsWindowVisible());
  163. pBar->SetWindowPos(NULL, 0, 0, 0, 0,
  164. SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
  165. }
  166. // remove any place holder for pBar in this dockbar
  167. RemovePlaceHolder(pBar);
  168. // get parent frame for recalc layout
  169. CFrameWnd* pFrameWnd = GetDockingFrame();
  170. pFrameWnd->DelayRecalcLayout();
  171. }
  172. void CDockBar::ReDockControlBar(CControlBar* pBar, LPCRECT lpRect)
  173. {
  174. ASSERT_VALID(this);
  175. ASSERT_VALID(pBar);
  176. ASSERT_KINDOF(CControlBar, pBar);
  177. ASSERT(pBar->m_pDockBar != this); // can't redock here if already docked here
  178. CRect rectBar;
  179. pBar->GetWindowRect(&rectBar);
  180. if (pBar->m_pDockBar == this && (lpRect == NULL || rectBar == *lpRect))
  181. {
  182. // already docked and no change in position
  183. return;
  184. }
  185. // set CBRS_FLOAT_MULTI style if docking bar has it
  186. if (m_bFloating && (pBar->m_dwDockStyle & CBRS_FLOAT_MULTI))
  187. m_dwStyle |= CBRS_FLOAT_MULTI;
  188. m_dwStyle &= ~(CBRS_SIZE_FIXED | CBRS_SIZE_DYNAMIC);
  189. m_dwStyle |= pBar->m_dwStyle & (CBRS_SIZE_FIXED | CBRS_SIZE_DYNAMIC);
  190. if (!(m_dwStyle & CBRS_FLOAT_MULTI))
  191. {
  192. TCHAR szTitle[_MAX_PATH];
  193. pBar->GetWindowText(szTitle, _countof(szTitle));
  194. AfxSetWindowText(m_hWnd, szTitle);
  195. }
  196. // align correctly and turn on all borders
  197. DWORD dwStyle = pBar->GetBarStyle();
  198. dwStyle &= ~(CBRS_ALIGN_ANY);
  199. dwStyle |= (m_dwStyle & CBRS_ALIGN_ANY) | CBRS_BORDER_ANY;
  200. if (m_bFloating)
  201. dwStyle |= CBRS_FLOATING;
  202. else
  203. dwStyle &= ~CBRS_FLOATING;
  204. pBar->SetBarStyle(dwStyle);
  205. int nPos = FindBar((CControlBar*)_AfxGetDlgCtrlID(pBar->m_hWnd));
  206. if (nPos > 0)
  207. m_arrBars[nPos] = pBar;
  208. if (lpRect != NULL)
  209. {
  210. CRect rect(lpRect);
  211. ScreenToClient(&rect);
  212. if (nPos < 1)
  213. {
  214. CPoint ptMid(rect.left + rect.Width()/2, rect.top + rect.Height()/2);
  215. nPos = Insert(pBar, rect, ptMid);
  216. }
  217. // position at requested position
  218. pBar->SetWindowPos(NULL, rect.left, rect.top, rect.Width(),
  219. rect.Height(), SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS);
  220. }
  221. else
  222. {
  223. if (nPos < 1)
  224. {
  225. // always add on current row, then create new one
  226. m_arrBars.Add(pBar);
  227. m_arrBars.Add(NULL);
  228. }
  229. // align off the edge initially
  230. pBar->SetWindowPos(NULL, -afxData.cxBorder2, -afxData.cyBorder2, 0, 0,
  231. SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS);
  232. }
  233. // attach it to the docking site
  234. if (pBar->GetParent() != this)
  235. pBar->SetParent(this);
  236. if (pBar->m_pDockBar != NULL)
  237. pBar->m_pDockBar->RemoveControlBar(pBar);
  238. pBar->m_pDockBar = this;
  239. // get parent frame for recalc layout
  240. CFrameWnd* pFrameWnd = GetDockingFrame();
  241. pFrameWnd->DelayRecalcLayout();
  242. }
  243. void CDockBar::RemovePlaceHolder(CControlBar* pBar)
  244. {
  245. // remove remembered docking position
  246. if (HIWORD(pBar) != 0)
  247. pBar = (CControlBar*)_AfxGetDlgCtrlID(pBar->m_hWnd);
  248. int nOldPos = FindBar(pBar);
  249. if (nOldPos > 0)
  250. {
  251. m_arrBars.RemoveAt(nOldPos);
  252. // remove section indicator (NULL) if nothing else in section
  253. if (m_arrBars[nOldPos-1] == NULL && m_arrBars[nOldPos] == NULL)
  254. m_arrBars.RemoveAt(nOldPos);
  255. }
  256. }
  257. BOOL CDockBar::RemoveControlBar(CControlBar* pBar, int nPosExclude, int nAddPlaceHolder)
  258. {
  259. ASSERT(nAddPlaceHolder == 1 || nAddPlaceHolder == 0 || nAddPlaceHolder == -1);
  260. ASSERT_VALID(this);
  261. ASSERT(pBar != NULL);
  262. int nPos = FindBar(pBar, nPosExclude);
  263. ASSERT(nPos > 0);
  264. if (nAddPlaceHolder == 1)
  265. {
  266. m_arrBars[nPos] = (void*)_AfxGetDlgCtrlID(pBar->m_hWnd);
  267. // check for already existing place holder
  268. int nPosOld = FindBar((CControlBar*)m_arrBars[nPos], nPos);
  269. if (nPosOld > 0)
  270. {
  271. m_arrBars.RemoveAt(nPos);
  272. // remove section indicator (NULL) if nothing else in section
  273. if (m_arrBars[nPos-1] == NULL && m_arrBars[nPos] == NULL)
  274. m_arrBars.RemoveAt(nPos);
  275. }
  276. }
  277. else
  278. {
  279. m_arrBars.RemoveAt(nPos);
  280. if (m_arrBars[nPos-1] == NULL && m_arrBars[nPos] == NULL)
  281. m_arrBars.RemoveAt(nPos);
  282. // Remove any pre-existing place holders.
  283. if (nAddPlaceHolder != -1)
  284. RemovePlaceHolder(pBar);
  285. }
  286. // don't do anything more in the shutdown case!
  287. if (pBar->m_pDockContext == NULL)
  288. return FALSE;
  289. // get parent frame for recalc layout/frame destroy
  290. CFrameWnd* pFrameWnd = GetDockingFrame();
  291. if (m_bFloating && GetDockedVisibleCount() == 0)
  292. {
  293. if (GetDockedCount() == 0)
  294. {
  295. pFrameWnd->DestroyWindow();
  296. return TRUE; // Self-Destruct
  297. }
  298. else
  299. pFrameWnd->ShowWindow(SW_HIDE);
  300. }
  301. else
  302. pFrameWnd->DelayRecalcLayout();
  303. return FALSE;
  304. }
  305. /////////////////////////////////////////////////////////////////////////////
  306. // CDockBar layout
  307. CSize CDockBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
  308. {
  309. ASSERT_VALID(this);
  310. CSize sizeFixed = CControlBar::CalcFixedLayout(bStretch, bHorz);
  311. // get max size
  312. CSize sizeMax;
  313. if (!m_rectLayout.IsRectEmpty())
  314. sizeMax = m_rectLayout.Size();
  315. else
  316. {
  317. CRect rectFrame;
  318. CFrameWnd* pFrame = GetParentFrame();
  319. pFrame->GetClientRect(&rectFrame);
  320. sizeMax = rectFrame.Size();
  321. }
  322. // prepare for layout
  323. AFX_SIZEPARENTPARAMS layout;
  324. layout.hDWP = m_bLayoutQuery ?
  325. NULL : ::BeginDeferWindowPos(m_arrBars.GetSize());
  326. CPoint pt(-afxData.cxBorder2, -afxData.cyBorder2);
  327. int nWidth = 0;
  328. BOOL bWrapped = FALSE;
  329. // layout all the control bars
  330. for (int nPos = 0; nPos < m_arrBars.GetSize(); nPos++)
  331. {
  332. CControlBar* pBar = GetDockedControlBar(nPos);
  333. void* pVoid = m_arrBars[nPos];
  334. if (pBar != NULL)
  335. {
  336. if (pBar->IsVisible())
  337. {
  338. // get ideal rect for bar
  339. DWORD dwMode = 0;
  340. if ((pBar->m_dwStyle & CBRS_SIZE_DYNAMIC) &&
  341. (pBar->m_dwStyle & CBRS_FLOATING))
  342. dwMode |= LM_HORZ | LM_MRUWIDTH;
  343. else if (pBar->m_dwStyle & CBRS_ORIENT_HORZ)
  344. dwMode |= LM_HORZ | LM_HORZDOCK;
  345. else
  346. dwMode |= LM_VERTDOCK;
  347. CSize sizeBar = pBar->CalcDynamicLayout(-1, dwMode);
  348. CRect rect(pt, sizeBar);
  349. // get current rect for bar
  350. CRect rectBar;
  351. pBar->GetWindowRect(&rectBar);
  352. ScreenToClient(&rectBar);
  353. if (bHorz)
  354. {
  355. // Offset Calculated Rect out to Actual
  356. if (rectBar.left > rect.left && !m_bFloating)
  357. rect.OffsetRect(rectBar.left - rect.left, 0);
  358. // If ControlBar goes off the right, then right justify
  359. if (rect.right > sizeMax.cx && !m_bFloating)
  360. {
  361. int x = rect.Width() - afxData.cxBorder2;
  362. x = max(sizeMax.cx - x, pt.x);
  363. rect.OffsetRect(x - rect.left, 0);
  364. }
  365. // If ControlBar has been wrapped, then left justify
  366. if (bWrapped)
  367. {
  368. bWrapped = FALSE;
  369. rect.OffsetRect(-(rect.left + afxData.cxBorder2), 0);
  370. }
  371. // If ControlBar is completely invisible, then wrap it
  372. else if ((rect.left >= (sizeMax.cx - afxData.cxBorder2)) &&
  373. (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
  374. {
  375. m_arrBars.InsertAt(nPos, (CObject*)NULL);
  376. pBar = NULL; pVoid = NULL;
  377. bWrapped = TRUE;
  378. }
  379. if (!bWrapped)
  380. {
  381. if (rect != rectBar)
  382. {
  383. if (!m_bLayoutQuery &&
  384. !(pBar->m_dwStyle & CBRS_FLOATING))
  385. {
  386. pBar->m_pDockContext->m_rectMRUDockPos = rect;
  387. }
  388. AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
  389. }
  390. pt.x = rect.left + sizeBar.cx - afxData.cxBorder2;
  391. nWidth = max(nWidth, sizeBar.cy);
  392. }
  393. }
  394. else
  395. {
  396. // Offset Calculated Rect out to Actual
  397. if (rectBar.top > rect.top && !m_bFloating)
  398. rect.OffsetRect(0, rectBar.top - rect.top);
  399. // If ControlBar goes off the bottom, then bottom justify
  400. if (rect.bottom > sizeMax.cy && !m_bFloating)
  401. {
  402. int y = rect.Height() - afxData.cyBorder2;
  403. y = max(sizeMax.cy - y, pt.y);
  404. rect.OffsetRect(0, y - rect.top);
  405. }
  406. // If ControlBar has been wrapped, then top justify
  407. if (bWrapped)
  408. {
  409. bWrapped = FALSE;
  410. rect.OffsetRect(0, -(rect.top + afxData.cyBorder2));
  411. }
  412. // If ControlBar is completely invisible, then wrap it
  413. else if ((rect.top >= (sizeMax.cy - afxData.cyBorder2)) &&
  414. (nPos > 0) && (m_arrBars[nPos - 1] != NULL))
  415. {
  416. m_arrBars.InsertAt(nPos, (CObject*)NULL);
  417. pBar = NULL; pVoid = NULL;
  418. bWrapped = TRUE;
  419. }
  420. if (!bWrapped)
  421. {
  422. if (rect != rectBar)
  423. {
  424. if (!m_bLayoutQuery &&
  425. !(pBar->m_dwStyle & CBRS_FLOATING))
  426. {
  427. pBar->m_pDockContext->m_rectMRUDockPos = rect;
  428. }
  429. AfxRepositionWindow(&layout, pBar->m_hWnd, &rect);
  430. }
  431. pt.y = rect.top + sizeBar.cy - afxData.cyBorder2;
  432. nWidth = max(nWidth, sizeBar.cx);
  433. }
  434. }
  435. }
  436. if (!bWrapped)
  437. {
  438. // handle any delay/show hide for the bar
  439. pBar->RecalcDelayShow(&layout);
  440. }
  441. }
  442. if (pBar == NULL && pVoid == NULL && nWidth != 0)
  443. {
  444. // end of row because pBar == NULL
  445. if (bHorz)
  446. {
  447. pt.y += nWidth - afxData.cyBorder2;
  448. sizeFixed.cx = max(sizeFixed.cx, pt.x);
  449. sizeFixed.cy = max(sizeFixed.cy, pt.y);
  450. pt.x = -afxData.cxBorder2;
  451. }
  452. else
  453. {
  454. pt.x += nWidth - afxData.cxBorder2;
  455. sizeFixed.cx = max(sizeFixed.cx, pt.x);
  456. sizeFixed.cy = max(sizeFixed.cy, pt.y);
  457. pt.y = -afxData.cyBorder2;
  458. }
  459. nWidth = 0;
  460. }
  461. }
  462. if (!m_bLayoutQuery)
  463. {
  464. // move and resize all the windows at once!
  465. if (layout.hDWP == NULL || !::EndDeferWindowPos(layout.hDWP))
  466. TRACE0("Warning: DeferWindowPos failed - low system resources.\n");
  467. }
  468. // adjust size for borders on the dock bar itself
  469. CRect rect;
  470. rect.SetRectEmpty();
  471. CalcInsideRect(rect, bHorz);
  472. if ((!bStretch || !bHorz) && sizeFixed.cx != 0)
  473. sizeFixed.cx += -rect.right + rect.left;
  474. if ((!bStretch || bHorz) && sizeFixed.cy != 0)
  475. sizeFixed.cy += -rect.bottom + rect.top;
  476. return sizeFixed;
  477. }
  478. LRESULT CDockBar::OnSizeParent(WPARAM wParam, LPARAM lParam)
  479. {
  480. AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam;
  481. // set m_bLayoutQuery to TRUE if lpLayout->hDWP == NULL
  482. BOOL bLayoutQuery = m_bLayoutQuery;
  483. CRect rectLayout = m_rectLayout;
  484. m_bLayoutQuery = (lpLayout->hDWP == NULL);
  485. m_rectLayout = lpLayout->rect;
  486. LRESULT lResult = CControlBar::OnSizeParent(wParam, lParam);
  487. // restore m_bLayoutQuery
  488. m_bLayoutQuery = bLayoutQuery;
  489. m_rectLayout = rectLayout;
  490. return lResult;
  491. }
  492. /////////////////////////////////////////////////////////////////////////////
  493. // CDockBar message handlers
  494. void CDockBar::OnNcCalcSize(BOOL /*bCalcValidRects*/, NCCALCSIZE_PARAMS* lpncsp)
  495. {
  496. // calculate border space (will add to top/bottom, subtract from right/bottom)
  497. CRect rect;
  498. rect.SetRectEmpty();
  499. CalcInsideRect(rect, m_dwStyle & CBRS_ORIENT_HORZ);
  500. // adjust non-client area for border space
  501. lpncsp->rgrc[0].left += rect.left;
  502. lpncsp->rgrc[0].top += rect.top;
  503. lpncsp->rgrc[0].right += rect.right;
  504. lpncsp->rgrc[0].bottom += rect.bottom;
  505. }
  506. void CDockBar::OnNcPaint()
  507. {
  508. EraseNonClient();
  509. }
  510. void CDockBar::DoPaint(CDC*)
  511. {
  512. // border painting is done in non-client area
  513. }
  514. void CDockBar::OnPaint()
  515. {
  516. // background is already filled in gray
  517. CPaintDC dc(this);
  518. if (IsVisible() && GetDockedVisibleCount() != 0)
  519. DoPaint(&dc); // delegate to paint helper
  520. }
  521. void CDockBar::OnWindowPosChanging(LPWINDOWPOS lpWndPos)
  522. {
  523. // not necessary to invalidate the borders
  524. DWORD dwStyle = m_dwStyle;
  525. m_dwStyle &= ~(CBRS_BORDER_ANY);
  526. CControlBar::OnWindowPosChanging(lpWndPos);
  527. m_dwStyle = dwStyle;
  528. }
  529. /////////////////////////////////////////////////////////////////////////////
  530. // CDockBar utility/implementation
  531. int CDockBar::FindBar(CControlBar* pBar, int nPosExclude)
  532. {
  533. for (int nPos = 0; nPos< m_arrBars.GetSize(); nPos++)
  534. {
  535. if (nPos != nPosExclude && m_arrBars[nPos] == pBar)
  536. return nPos;
  537. }
  538. return -1;
  539. }
  540. void CDockBar::ShowAll(BOOL bShow)
  541. {
  542. for (int nPos = 0; nPos < m_arrBars.GetSize(); nPos++)
  543. {
  544. CControlBar* pBar = GetDockedControlBar(nPos);
  545. if (pBar != NULL)
  546. {
  547. CFrameWnd* pFrameWnd = pBar->GetDockingFrame();
  548. pFrameWnd->ShowControlBar(pBar, bShow, TRUE);
  549. }
  550. }
  551. }
  552. CControlBar* CDockBar::GetDockedControlBar(int nPos) const
  553. {
  554. CControlBar* pResult = (CControlBar*)m_arrBars[nPos];
  555. if (HIWORD(pResult) == 0)
  556. return NULL;
  557. return pResult;
  558. }
  559. int CDockBar::Insert(CControlBar* pBarIns, CRect rect, CPoint ptMid)
  560. {
  561. ASSERT_VALID(this);
  562. ASSERT(pBarIns != NULL);
  563. int nPos = 0;
  564. int nPosInsAfter = 0;
  565. int nWidth = 0;
  566. int nTotalWidth = 0;
  567. BOOL bHorz = m_dwStyle & CBRS_ORIENT_HORZ;
  568. for (nPos = 0; nPos < m_arrBars.GetSize(); nPos++)
  569. {
  570. CControlBar* pBar = GetDockedControlBar(nPos);
  571. if (pBar != NULL && pBar->IsVisible())
  572. {
  573. CRect rectBar;
  574. pBar->GetWindowRect(&rectBar);
  575. ScreenToClient(&rectBar);
  576. nWidth = max(nWidth,
  577. bHorz ? rectBar.Size().cy : rectBar.Size().cx - 1);
  578. if (bHorz ? rect.left > rectBar.left : rect.top > rectBar.top)
  579. nPosInsAfter = nPos;
  580. }
  581. else // end of row because pBar == NULL
  582. {
  583. nTotalWidth += nWidth - afxData.cyBorder2;
  584. nWidth = 0;
  585. if ((bHorz ? ptMid.y : ptMid.x) < nTotalWidth)
  586. {
  587. if (nPos == 0) // first section
  588. m_arrBars.InsertAt(nPosInsAfter+1, (CObject*)NULL);
  589. m_arrBars.InsertAt(nPosInsAfter+1, pBarIns);
  590. return nPosInsAfter+1;
  591. }
  592. nPosInsAfter = nPos;
  593. }
  594. }
  595. // create a new row
  596. m_arrBars.InsertAt(nPosInsAfter+1, (CObject*)NULL);
  597. m_arrBars.InsertAt(nPosInsAfter+1, pBarIns);
  598. return nPosInsAfter+1;
  599. }
  600. void CDockBar::OnUpdateCmdUI(CFrameWnd* /*pTarget*/, BOOL /*bDisableIfNoHndler*/)
  601. {
  602. }
  603. #ifdef _DEBUG
  604. void CDockBar::AssertValid() const
  605. {
  606. CControlBar::AssertValid();
  607. ASSERT(m_arrBars.GetSize() != 0);
  608. ASSERT(m_arrBars[0] == NULL);
  609. ASSERT(m_arrBars[m_arrBars.GetUpperBound()] == NULL);
  610. }
  611. void CDockBar::Dump(CDumpContext& dc) const
  612. {
  613. CControlBar::Dump(dc);
  614. dc << "m_arrBars " << m_arrBars;
  615. dc << "\nm_bFloating " << m_bFloating;
  616. dc << "\n";
  617. }
  618. #endif
  619. /////////////////////////////////////////////////////////////////////////////
  620. // CControlBar docking helpers
  621. void CControlBar::EnableDocking(DWORD dwDockStyle)
  622. {
  623. // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
  624. ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
  625. // CBRS_SIZE_DYNAMIC toolbar cannot have the CBRS_FLOAT_MULTI style
  626. ASSERT(((dwDockStyle & CBRS_FLOAT_MULTI) == 0) || ((m_dwStyle & CBRS_SIZE_DYNAMIC) == 0));
  627. m_dwDockStyle = dwDockStyle;
  628. if (m_pDockContext == NULL)
  629. m_pDockContext = new CDockContext(this);
  630. // permanently wire the bar's owner to its current parent
  631. if (m_hWndOwner == NULL)
  632. m_hWndOwner = ::GetParent(m_hWnd);
  633. }
  634. /////////////////////////////////////////////////////////////////////////////
  635. // CMiniDockFrameWnd
  636. BEGIN_MESSAGE_MAP(CMiniDockFrameWnd, CMiniFrameWnd)
  637. //{{AFX_MSG_MAP(CMiniDockFrameWnd)
  638. ON_WM_CLOSE()
  639. ON_WM_NCLBUTTONDOWN()
  640. ON_WM_NCLBUTTONDBLCLK()
  641. //}}AFX_MSG_MAP
  642. ON_WM_MOUSEACTIVATE()
  643. END_MESSAGE_MAP()
  644. int CMiniDockFrameWnd::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
  645. {
  646. if (nHitTest >= HTSIZEFIRST && nHitTest <= HTSIZELAST) // resizing
  647. return MA_NOACTIVATE;
  648. return CMiniFrameWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
  649. }
  650. CMiniDockFrameWnd::CMiniDockFrameWnd() : m_wndDockBar(TRUE)
  651. {
  652. m_wndDockBar.m_bAutoDelete = FALSE;
  653. }
  654. BOOL CMiniDockFrameWnd::Create(CWnd* pParent, DWORD dwBarStyle)
  655. {
  656. // set m_bInRecalcLayout to avoid flashing during creation
  657. // RecalcLayout will be called once something is docked
  658. m_bInRecalcLayout = TRUE;
  659. DWORD dwStyle = WS_POPUP|WS_CAPTION|WS_SYSMENU|MFS_MOVEFRAME|
  660. MFS_4THICKFRAME|MFS_SYNCACTIVE|MFS_BLOCKSYSMENU|
  661. FWS_SNAPTOBARS;
  662. if (dwBarStyle & CBRS_SIZE_DYNAMIC)
  663. dwStyle &= ~MFS_MOVEFRAME;
  664. DWORD dwExStyle = 0;
  665. if (!CMiniFrameWnd::CreateEx(dwExStyle,
  666. NULL, &afxChNil, dwStyle, rectDefault, pParent))
  667. {
  668. m_bInRecalcLayout = FALSE;
  669. return FALSE;
  670. }
  671. dwStyle = dwBarStyle & (CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT) ?
  672. CBRS_ALIGN_LEFT : CBRS_ALIGN_TOP;
  673. dwStyle |= dwBarStyle & CBRS_FLOAT_MULTI;
  674. CMenu* pSysMenu = GetSystemMenu(FALSE);
  675. pSysMenu->DeleteMenu(SC_SIZE, MF_BYCOMMAND);
  676. pSysMenu->DeleteMenu(SC_MINIMIZE, MF_BYCOMMAND);
  677. pSysMenu->DeleteMenu(SC_MAXIMIZE, MF_BYCOMMAND);
  678. pSysMenu->DeleteMenu(SC_RESTORE, MF_BYCOMMAND);
  679. CString strHide;
  680. if (strHide.LoadString(AFX_IDS_HIDE))
  681. {
  682. pSysMenu->DeleteMenu(SC_CLOSE, MF_BYCOMMAND);
  683. pSysMenu->AppendMenu(MF_STRING|MF_ENABLED, SC_CLOSE, strHide);
  684. }
  685. // must initially create with parent frame as parent
  686. if (!m_wndDockBar.Create(pParent, WS_CHILD | WS_VISIBLE | dwStyle,
  687. AFX_IDW_DOCKBAR_FLOAT))
  688. {
  689. m_bInRecalcLayout = FALSE;
  690. return FALSE;
  691. }
  692. // set parent to CMiniDockFrameWnd
  693. m_wndDockBar.SetParent(this);
  694. m_bInRecalcLayout = FALSE;
  695. return TRUE;
  696. }
  697. void CMiniDockFrameWnd::RecalcLayout(BOOL bNotify)
  698. {
  699. if (!m_bInRecalcLayout)
  700. {
  701. CMiniFrameWnd::RecalcLayout(bNotify);
  702. // syncronize window text of frame window with dockbar itself
  703. TCHAR szTitle[_MAX_PATH];
  704. m_wndDockBar.GetWindowText(szTitle, _countof(szTitle));
  705. AfxSetWindowText(m_hWnd, szTitle);
  706. }
  707. }
  708. void CMiniDockFrameWnd::OnClose()
  709. {
  710. m_wndDockBar.ShowAll(FALSE);
  711. }
  712. void CMiniDockFrameWnd::OnNcLButtonDown(UINT nHitTest, CPoint point)
  713. {
  714. if (nHitTest == HTCAPTION)
  715. {
  716. // special activation for floating toolbars
  717. ActivateTopParent();
  718. // initiate toolbar drag for non-CBRS_FLOAT_MULTI toolbars
  719. if ((m_wndDockBar.m_dwStyle & CBRS_FLOAT_MULTI) == 0)
  720. {
  721. int nPos = 1;
  722. CControlBar* pBar = NULL;
  723. while(pBar == NULL && nPos < m_wndDockBar.m_arrBars.GetSize())
  724. pBar = m_wndDockBar.GetDockedControlBar(nPos++);
  725. ASSERT(pBar != NULL);
  726. ASSERT_KINDOF(CControlBar, pBar);
  727. ASSERT(pBar->m_pDockContext != NULL);
  728. pBar->m_pDockContext->StartDrag(point);
  729. return;
  730. }
  731. }
  732. else if (nHitTest >= HTSIZEFIRST && nHitTest <= HTSIZELAST)
  733. {
  734. // special activation for floating toolbars
  735. ActivateTopParent();
  736. int nPos = 1;
  737. CControlBar* pBar = NULL;
  738. while(pBar == NULL && nPos < m_wndDockBar.m_arrBars.GetSize())
  739. pBar = m_wndDockBar.GetDockedControlBar(nPos++);
  740. ASSERT(pBar != NULL);
  741. ASSERT_KINDOF(CControlBar, pBar);
  742. ASSERT(pBar->m_pDockContext != NULL);
  743. // CBRS_SIZE_DYNAMIC toolbars cannot have the CBRS_FLOAT_MULTI style
  744. ASSERT((m_wndDockBar.m_dwStyle & CBRS_FLOAT_MULTI) == 0);
  745. pBar->m_pDockContext->StartResize(nHitTest, point);
  746. return;
  747. }
  748. CMiniFrameWnd::OnNcLButtonDown(nHitTest, point);
  749. }
  750. void CMiniDockFrameWnd::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
  751. {
  752. if (nHitTest == HTCAPTION)
  753. {
  754. // special activation for floating toolbars
  755. ActivateTopParent();
  756. // initiate toolbar toggle for non-CBRS_FLOAT_MULTI toolbars
  757. if ((m_wndDockBar.m_dwStyle & CBRS_FLOAT_MULTI) == 0)
  758. {
  759. int nPos = 1;
  760. CControlBar* pBar = NULL;
  761. while(pBar == NULL && nPos < m_wndDockBar.m_arrBars.GetSize())
  762. pBar = m_wndDockBar.GetDockedControlBar(nPos++);
  763. ASSERT(pBar != NULL);
  764. ASSERT_KINDOF(CControlBar, pBar);
  765. ASSERT(pBar->m_pDockContext != NULL);
  766. pBar->m_pDockContext->ToggleDocking();
  767. return;
  768. }
  769. }
  770. CMiniFrameWnd::OnNcLButtonDblClk(nHitTest, point);
  771. }
  772. #ifdef AFX_INIT_SEG
  773. #pragma code_seg(AFX_INIT_SEG)
  774. #endif
  775. IMPLEMENT_DYNAMIC(CDockBar, CControlBar)
  776. IMPLEMENT_DYNCREATE(CMiniDockFrameWnd, CMiniFrameWnd)
  777. /////////////////////////////////////////////////////////////////////////////