dockstat.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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. // CDockState
  21. AFX_STATIC_DATA const TCHAR _afxVisible[] = _T("Visible");
  22. AFX_STATIC_DATA const TCHAR _afxBarSection[] = _T("%s-Bar%d");
  23. AFX_STATIC_DATA const TCHAR _afxSummarySection[] = _T("%s-Summary");
  24. AFX_STATIC_DATA const TCHAR _afxXPos[] = _T("XPos");
  25. AFX_STATIC_DATA const TCHAR _afxYPos[] = _T("YPos");
  26. AFX_STATIC_DATA const TCHAR _afxMRUWidth[] = _T("MRUWidth");
  27. AFX_STATIC_DATA const TCHAR _afxDocking[] = _T("Docking");
  28. AFX_STATIC_DATA const TCHAR _afxMRUDockID[] = _T("MRUDockID");
  29. AFX_STATIC_DATA const TCHAR _afxMRUDockLeftPos[] = _T("MRUDockLeftPos");
  30. AFX_STATIC_DATA const TCHAR _afxMRUDockRightPos[] = _T("MRUDockRightPos");
  31. AFX_STATIC_DATA const TCHAR _afxMRUDockTopPos[] = _T("MRUDockTopPos");
  32. AFX_STATIC_DATA const TCHAR _afxMRUDockBottomPos[] = _T("MRUDockBottomPos");
  33. AFX_STATIC_DATA const TCHAR _afxMRUFloatStyle[] = _T("MRUFloatStyle");
  34. AFX_STATIC_DATA const TCHAR _afxMRUFloatXPos[] = _T("MRUFloatXPos");
  35. AFX_STATIC_DATA const TCHAR _afxMRUFloatYPos[] = _T("MRUFloatYPos");
  36. AFX_STATIC_DATA const TCHAR _afxBarID[] = _T("BarID");
  37. AFX_STATIC_DATA const TCHAR _afxHorz[] = _T("Horz");
  38. AFX_STATIC_DATA const TCHAR _afxFloating[] = _T("Floating");
  39. AFX_STATIC_DATA const TCHAR _afxBars[] = _T("Bars");
  40. AFX_STATIC_DATA const TCHAR _afxScreenCX[] = _T("ScreenCX");
  41. AFX_STATIC_DATA const TCHAR _afxScreenCY[] = _T("ScreenCY");
  42. AFX_STATIC_DATA const TCHAR _afxBar[] = _T("Bar#%d");
  43. CControlBarInfo::CControlBarInfo()
  44. {
  45. m_nBarID = 0;
  46. m_bDockBar = m_bVisible = m_bFloating = m_bHorz = m_bDocking = FALSE;
  47. m_pBar = NULL;
  48. m_pointPos.x = m_pointPos.y = -1;
  49. m_nMRUWidth = 32767;
  50. m_uMRUDockID = 0;
  51. m_rectMRUDockPos.SetRectEmpty();
  52. m_dwMRUFloatStyle = 0;
  53. m_ptMRUFloatPos = CPoint(0,0);
  54. ASSERT(sizeof(DWORD) == sizeof(void*));
  55. }
  56. void CControlBarInfo::Serialize(CArchive& ar, CDockState* pDockState)
  57. {
  58. ASSERT(pDockState!=NULL);
  59. if (ar.IsStoring())
  60. {
  61. ar << (DWORD)m_nBarID;
  62. ar << (DWORD)m_bVisible;
  63. ar << (DWORD)m_bFloating;
  64. ar << (DWORD)m_bHorz;
  65. ar << m_pointPos;
  66. if (pDockState->GetVersion() > 1)
  67. {
  68. ar << (DWORD)m_nMRUWidth;
  69. ar << (DWORD)m_bDocking;
  70. if (m_bDocking)
  71. {
  72. ar << (DWORD)m_uMRUDockID;
  73. ar << m_rectMRUDockPos;
  74. ar << m_dwMRUFloatStyle;
  75. ar << m_ptMRUFloatPos;
  76. }
  77. }
  78. ar << (WORD)m_arrBarID.GetSize();
  79. if (m_arrBarID.GetSize() != 0)
  80. {
  81. #ifdef _AFX_BYTESWAP
  82. if (!ar.IsByteSwapping())
  83. #endif
  84. ar.Write(&m_arrBarID.ElementAt(0),
  85. m_arrBarID.GetSize()*sizeof(DWORD));
  86. #ifdef _AFX_BYTESWAP
  87. else
  88. {
  89. // write each ID individually so that it will be byte-swapped
  90. for (int i = 0; i < m_arrBarID.GetSize(); i++)
  91. ar << (DWORD)m_arrBarID[i];
  92. }
  93. #endif
  94. }
  95. }
  96. else
  97. {
  98. DWORD dw;
  99. ar >> dw;
  100. m_nBarID = (int)dw;
  101. ar >> dw;
  102. m_bVisible = (BOOL)dw;
  103. ar >> dw;
  104. m_bFloating = (BOOL)dw;
  105. ar >> dw;
  106. m_bHorz = (BOOL)dw;
  107. ar >> m_pointPos;
  108. if (pDockState->GetVersion() > 1)
  109. {
  110. pDockState->ScalePoint(m_pointPos);
  111. ar >> dw;
  112. m_nMRUWidth = (int)dw;
  113. ar >> dw;
  114. m_bDocking = (BOOL)dw;
  115. if (m_bDocking)
  116. {
  117. ar >> dw;
  118. m_uMRUDockID = (DWORD)dw;
  119. ar >> m_rectMRUDockPos;
  120. pDockState->ScaleRectPos(m_rectMRUDockPos);
  121. ar >> m_dwMRUFloatStyle;
  122. ar >> m_ptMRUFloatPos;
  123. pDockState->ScalePoint(m_ptMRUFloatPos);
  124. }
  125. }
  126. WORD w;
  127. ar >> w;
  128. m_arrBarID.SetSize(w);
  129. if (w != 0)
  130. {
  131. ar.Read(&m_arrBarID.ElementAt(0),
  132. m_arrBarID.GetSize()*sizeof(DWORD));
  133. #ifdef _AFX_BYTESWAP
  134. if (ar.IsByteSwapping())
  135. {
  136. for (int i = 0; i < m_arrBarID.GetSize(); i++)
  137. _AfxByteSwap((DWORD)m_arrBarID[i], (BYTE*)&m_arrBarID[i]);
  138. }
  139. #endif
  140. }
  141. }
  142. }
  143. BOOL CControlBarInfo::LoadState(LPCTSTR lpszProfileName, int nIndex, CDockState* pDockState)
  144. {
  145. ASSERT(pDockState != NULL);
  146. CWinApp* pApp = AfxGetApp();
  147. TCHAR szSection[256];
  148. wsprintf(szSection, _afxBarSection, lpszProfileName, nIndex);
  149. m_nBarID = pApp->GetProfileInt(szSection, _afxBarID, 0);
  150. m_bVisible = (BOOL) pApp->GetProfileInt(szSection, _afxVisible, TRUE);
  151. m_bHorz = (BOOL) pApp->GetProfileInt(szSection, _afxHorz, TRUE);
  152. m_bFloating = (BOOL) pApp->GetProfileInt(szSection, _afxFloating, FALSE);
  153. m_pointPos = CPoint(
  154. pApp->GetProfileInt(szSection, _afxXPos, -1),
  155. pApp->GetProfileInt(szSection, _afxYPos, -1));
  156. pDockState->ScalePoint(m_pointPos);
  157. m_nMRUWidth = pApp->GetProfileInt(szSection, _afxMRUWidth, 32767);
  158. m_bDocking = pApp->GetProfileInt(szSection, _afxDocking, 0);
  159. if (m_bDocking)
  160. {
  161. m_uMRUDockID = pApp->GetProfileInt(szSection, _afxMRUDockID, 0);
  162. m_rectMRUDockPos = CRect(
  163. pApp->GetProfileInt(szSection, _afxMRUDockLeftPos, 0),
  164. pApp->GetProfileInt(szSection, _afxMRUDockTopPos, 0),
  165. pApp->GetProfileInt(szSection, _afxMRUDockRightPos, 0),
  166. pApp->GetProfileInt(szSection, _afxMRUDockBottomPos, 0));
  167. pDockState->ScaleRectPos(m_rectMRUDockPos);
  168. m_dwMRUFloatStyle = pApp->GetProfileInt(szSection, _afxMRUFloatStyle, 0);
  169. m_ptMRUFloatPos = CPoint(
  170. pApp->GetProfileInt(szSection, _afxMRUFloatXPos, 0),
  171. pApp->GetProfileInt(szSection, _afxMRUFloatYPos, 0));
  172. pDockState->ScalePoint(m_ptMRUFloatPos);
  173. }
  174. int nBars = pApp->GetProfileInt(szSection, _afxBars, 0);
  175. for (int i=0; i < nBars; i++)
  176. {
  177. TCHAR buf[16];
  178. wsprintf(buf, _afxBar, i);
  179. m_arrBarID.Add((void*)pApp->GetProfileInt(szSection, buf, 0));
  180. }
  181. return m_nBarID != 0;
  182. }
  183. BOOL CControlBarInfo::SaveState(LPCTSTR lpszProfileName, int nIndex)
  184. {
  185. TCHAR szSection[256];
  186. wsprintf(szSection, _afxBarSection, lpszProfileName, nIndex);
  187. // delete the section
  188. CWinApp* pApp = AfxGetApp();
  189. pApp->WriteProfileString(szSection, NULL, NULL);
  190. if (m_bDockBar && m_bVisible && !m_bFloating && m_pointPos.x == -1 &&
  191. m_pointPos.y == -1 && m_arrBarID.GetSize() <= 1)
  192. {
  193. return FALSE;
  194. }
  195. pApp->WriteProfileInt(szSection, _afxBarID, m_nBarID);
  196. if (!m_bVisible)
  197. pApp->WriteProfileInt(szSection, _afxVisible, m_bVisible);
  198. if (m_bFloating)
  199. {
  200. pApp->WriteProfileInt(szSection, _afxHorz, m_bHorz);
  201. pApp->WriteProfileInt(szSection, _afxFloating, m_bFloating);
  202. }
  203. if (m_pointPos.x != -1)
  204. pApp->WriteProfileInt(szSection, _afxXPos, m_pointPos.x);
  205. if (m_pointPos.y != -1)
  206. pApp->WriteProfileInt(szSection, _afxYPos, m_pointPos.y);
  207. if (m_nMRUWidth != 32767)
  208. pApp->WriteProfileInt(szSection, _afxMRUWidth, m_nMRUWidth);
  209. if (m_bDocking)
  210. {
  211. pApp->WriteProfileInt(szSection, _afxDocking, m_bDocking);
  212. pApp->WriteProfileInt(szSection, _afxMRUDockID, m_uMRUDockID);
  213. pApp->WriteProfileInt(szSection, _afxMRUDockLeftPos, m_rectMRUDockPos.left);
  214. pApp->WriteProfileInt(szSection, _afxMRUDockTopPos, m_rectMRUDockPos.top);
  215. pApp->WriteProfileInt(szSection, _afxMRUDockRightPos, m_rectMRUDockPos.right);
  216. pApp->WriteProfileInt(szSection, _afxMRUDockBottomPos, m_rectMRUDockPos.bottom);
  217. pApp->WriteProfileInt(szSection, _afxMRUFloatStyle, m_dwMRUFloatStyle);
  218. pApp->WriteProfileInt(szSection, _afxMRUFloatXPos, m_ptMRUFloatPos.x);
  219. pApp->WriteProfileInt(szSection, _afxMRUFloatYPos, m_ptMRUFloatPos.y);
  220. }
  221. if (m_arrBarID.GetSize() > 1) //if ==1 then still empty
  222. {
  223. pApp->WriteProfileInt(szSection, _afxBars, m_arrBarID.GetSize());
  224. for (int i = 0; i < m_arrBarID.GetSize(); i++)
  225. {
  226. TCHAR buf[16];
  227. wsprintf(buf, _afxBar, i);
  228. pApp->WriteProfileInt(szSection, buf, (int)m_arrBarID[i]);
  229. }
  230. }
  231. return TRUE;
  232. }
  233. CDockState::CDockState()
  234. {
  235. m_dwVersion = 2;
  236. m_bScaling = FALSE;
  237. m_rectDevice.left = 0;
  238. m_rectDevice.top = 0;
  239. m_rectDevice.right = GetSystemMetrics(SM_CXSCREEN);
  240. m_rectDevice.bottom = GetSystemMetrics(SM_CYSCREEN);
  241. m_rectClip = m_rectDevice;
  242. m_rectClip.right -= GetSystemMetrics(SM_CXICON);
  243. m_rectClip.bottom -= GetSystemMetrics(SM_CYICON);
  244. }
  245. CDockState::~CDockState()
  246. {
  247. for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
  248. delete (CControlBarInfo*)m_arrBarInfo[i];
  249. }
  250. void CDockState::Serialize(CArchive& ar)
  251. {
  252. // read/write version info
  253. if (ar.IsStoring())
  254. {
  255. ar << m_dwVersion;
  256. if (m_dwVersion > 1)
  257. {
  258. ar << GetScreenSize();
  259. }
  260. // write array contents
  261. ar << (WORD)m_arrBarInfo.GetSize();
  262. for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
  263. ((CControlBarInfo*)m_arrBarInfo[i])->Serialize(ar, this);
  264. }
  265. else
  266. {
  267. Clear(); //empty out dockstate
  268. ar >> m_dwVersion; // read version marker
  269. ASSERT(m_dwVersion == 1 || m_dwVersion == 2);
  270. if (m_dwVersion > 1)
  271. {
  272. CSize size;
  273. ar >> size;
  274. SetScreenSize(size);
  275. }
  276. // read array contents
  277. WORD nOldSize;
  278. ar >> nOldSize;
  279. m_arrBarInfo.SetSize(nOldSize);
  280. for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
  281. {
  282. m_arrBarInfo[i] = new CControlBarInfo;
  283. ((CControlBarInfo*)m_arrBarInfo[i])->Serialize(ar, this);
  284. }
  285. m_dwVersion = 2;
  286. }
  287. }
  288. void CDockState::LoadState(LPCTSTR lpszProfileName)
  289. {
  290. CWinApp* pApp = AfxGetApp();
  291. TCHAR szSection[256];
  292. wsprintf(szSection, _afxSummarySection, lpszProfileName);
  293. int nBars = pApp->GetProfileInt(szSection, _afxBars, 0);
  294. CSize size;
  295. size.cx = pApp->GetProfileInt(szSection, _afxScreenCX, 0);
  296. size.cy = pApp->GetProfileInt(szSection, _afxScreenCY, 0);
  297. SetScreenSize(size);
  298. for (int i = 0; i < nBars; i++)
  299. {
  300. CControlBarInfo* pInfo = new CControlBarInfo;
  301. m_arrBarInfo.Add(pInfo);
  302. pInfo->LoadState(lpszProfileName, i, this);
  303. }
  304. }
  305. void CDockState::SaveState(LPCTSTR lpszProfileName)
  306. {
  307. int nIndex = 0;
  308. for (int i = 0;i < m_arrBarInfo.GetSize(); i++)
  309. {
  310. CControlBarInfo* pInfo = (CControlBarInfo*)m_arrBarInfo[i];
  311. ASSERT(pInfo != NULL);
  312. if (pInfo->SaveState(lpszProfileName, nIndex))
  313. nIndex++;
  314. }
  315. CWinApp* pApp = AfxGetApp();
  316. TCHAR szSection[256];
  317. wsprintf(szSection, _afxSummarySection, lpszProfileName);
  318. pApp->WriteProfileInt(szSection, _afxBars, nIndex);
  319. CSize size = GetScreenSize();
  320. pApp->WriteProfileInt(szSection, _afxScreenCX, size.cx);
  321. pApp->WriteProfileInt(szSection, _afxScreenCY, size.cy);
  322. }
  323. void CDockState::Clear()
  324. {
  325. for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
  326. delete (CControlBarInfo*) m_arrBarInfo[i];
  327. m_arrBarInfo.RemoveAll();
  328. }
  329. DWORD CDockState::GetVersion()
  330. {
  331. return m_dwVersion;
  332. }
  333. void CDockState::ScalePoint(CPoint& pt)
  334. {
  335. if (m_bScaling)
  336. {
  337. CSize sizeDevice = m_rectDevice.Size();
  338. pt.x = MulDiv(pt.x, sizeDevice.cx, m_sizeLogical.cx);
  339. pt.y = MulDiv(pt.y, sizeDevice.cy, m_sizeLogical.cy);
  340. }
  341. if (pt.x > m_rectClip.right)
  342. pt.x = m_rectClip.right;
  343. if (pt.y > m_rectClip.bottom)
  344. pt.y = m_rectClip.bottom;
  345. }
  346. void CDockState::ScaleRectPos(CRect& rect)
  347. {
  348. CPoint pt;
  349. if (m_bScaling)
  350. {
  351. pt = rect.TopLeft();
  352. CSize sizeDevice = m_rectDevice.Size();
  353. pt.x = MulDiv(pt.x, sizeDevice.cx, m_sizeLogical.cx) - rect.left;
  354. pt.y = MulDiv(pt.y, sizeDevice.cy, m_sizeLogical.cy) - rect.top;
  355. rect.OffsetRect(pt);
  356. }
  357. pt.x = pt.y = 0;
  358. if (rect.left > m_rectClip.right)
  359. pt.x = m_rectClip.right - rect.left;
  360. if (rect.top > m_rectClip.bottom)
  361. pt.y = m_rectClip.bottom - rect.top;
  362. if (!((pt.x == 0) && (pt.y == 0)))
  363. rect.OffsetRect(pt);
  364. }
  365. CSize CDockState::GetScreenSize()
  366. {
  367. return m_rectDevice.Size();
  368. }
  369. void CDockState::SetScreenSize(CSize& size)
  370. {
  371. m_sizeLogical = size;
  372. m_bScaling = (size != m_rectDevice.Size());
  373. }
  374. void CFrameWnd::LoadBarState(LPCTSTR lpszProfileName)
  375. {
  376. CDockState state;
  377. state.LoadState(lpszProfileName);
  378. SetDockState(state);
  379. }
  380. void CFrameWnd::SaveBarState(LPCTSTR lpszProfileName) const
  381. {
  382. CDockState state;
  383. GetDockState(state);
  384. state.SaveState(lpszProfileName);
  385. }
  386. void CFrameWnd::SetDockState(const CDockState& state)
  387. {
  388. // first pass through barinfo's sets the m_pBar member correctly
  389. // creating floating frames if necessary
  390. for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
  391. {
  392. CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
  393. ASSERT(pInfo != NULL);
  394. if (pInfo->m_bFloating)
  395. {
  396. // need to create floating frame to match
  397. CMiniDockFrameWnd* pDockFrame = CreateFloatingFrame(
  398. pInfo->m_bHorz ? CBRS_ALIGN_TOP : CBRS_ALIGN_LEFT);
  399. ASSERT(pDockFrame != NULL);
  400. CRect rect(pInfo->m_pointPos, CSize(10, 10));
  401. pDockFrame->CalcWindowRect(&rect);
  402. pDockFrame->SetWindowPos(NULL, rect.left, rect.top, 0, 0,
  403. SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
  404. CDockBar* pDockBar =
  405. (CDockBar*)pDockFrame->GetDlgItem(AFX_IDW_DOCKBAR_FLOAT);
  406. ASSERT(pDockBar != NULL);
  407. ASSERT_KINDOF(CDockBar, pDockBar);
  408. pInfo->m_pBar = pDockBar;
  409. }
  410. else // regular dock bar or toolbar
  411. {
  412. pInfo->m_pBar = GetControlBar(pInfo->m_nBarID);
  413. ASSERT(pInfo->m_pBar != NULL); //toolbar id's probably changed
  414. }
  415. pInfo->m_pBar->m_nMRUWidth = pInfo->m_nMRUWidth;
  416. }
  417. // the second pass will actually dock all of the control bars and
  418. // set everything correctly
  419. for (i = 0; i < state.m_arrBarInfo.GetSize(); i++)
  420. {
  421. CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
  422. ASSERT(pInfo != NULL);
  423. if (pInfo->m_pBar != NULL)
  424. pInfo->m_pBar->SetBarInfo(pInfo, this);
  425. }
  426. // last pass shows all the floating windows that were previously shown
  427. for (i = 0; i < state.m_arrBarInfo.GetSize(); i++)
  428. {
  429. CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
  430. ASSERT(pInfo != NULL);
  431. ASSERT(pInfo->m_pBar != NULL);
  432. if (pInfo->m_bFloating)
  433. {
  434. CFrameWnd* pFrameWnd = pInfo->m_pBar->GetParentFrame();
  435. CDockBar* pDockBar = (CDockBar*)pInfo->m_pBar;
  436. ASSERT_KINDOF(CDockBar, pDockBar);
  437. if (pDockBar->GetDockedVisibleCount() > 0)
  438. {
  439. pFrameWnd->RecalcLayout();
  440. pFrameWnd->ShowWindow(SW_SHOWNA);
  441. }
  442. }
  443. }
  444. DelayRecalcLayout();
  445. }
  446. void CFrameWnd::GetDockState(CDockState& state) const
  447. {
  448. state.Clear(); //make sure dockstate is empty
  449. // get state info for each bar
  450. POSITION pos = m_listControlBars.GetHeadPosition();
  451. while (pos != NULL)
  452. {
  453. CControlBar* pBar = (CControlBar*)m_listControlBars.GetNext(pos);
  454. ASSERT(pBar != NULL);
  455. CControlBarInfo* pInfo = new CControlBarInfo;
  456. pBar->GetBarInfo(pInfo);
  457. state.m_arrBarInfo.Add(pInfo);
  458. }
  459. }
  460. // Note: GetBarInfo and SetBarInfo are not virtual since doing so adds
  461. // to much code to an application which does not save and load docking
  462. // state. For this reason, the CControlBar implementations must
  463. // delagate to CDockBar as appropriate.
  464. void CControlBar::GetBarInfo(CControlBarInfo* pInfo)
  465. {
  466. ASSERT_VALID(this);
  467. // get state info
  468. pInfo->m_nBarID = _AfxGetDlgCtrlID(m_hWnd);
  469. pInfo->m_pBar = this;
  470. pInfo->m_bVisible = IsVisible(); // handles delayed showing and hiding
  471. pInfo->m_nMRUWidth = m_nMRUWidth;
  472. if (m_pDockBar != NULL) // don't need position unless docked
  473. {
  474. CRect rect;
  475. GetWindowRect(&rect);
  476. m_pDockBar->ScreenToClient(&rect);
  477. pInfo->m_pointPos = rect.TopLeft();
  478. ASSERT(m_pDockContext != NULL);
  479. pInfo->m_bDocking = TRUE;
  480. pInfo->m_uMRUDockID = m_pDockContext->m_uMRUDockID;
  481. pInfo->m_rectMRUDockPos = m_pDockContext->m_rectMRUDockPos;
  482. pInfo->m_dwMRUFloatStyle = m_pDockContext->m_dwMRUFloatStyle;
  483. pInfo->m_ptMRUFloatPos = m_pDockContext->m_ptMRUFloatPos;
  484. }
  485. // save dockbar specific parts
  486. if (IsDockBar())
  487. ((CDockBar*)this)->GetBarInfo(pInfo);
  488. }
  489. void CControlBar::SetBarInfo(CControlBarInfo* pInfo, CFrameWnd* pFrameWnd)
  490. {
  491. // dockbars are handled differently
  492. if (IsDockBar())
  493. {
  494. ((CDockBar*)this)->SetBarInfo(pInfo, pFrameWnd);
  495. return;
  496. }
  497. // don't set position when not docked
  498. UINT nFlags = SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER;
  499. if (m_pDockBar == NULL)
  500. nFlags |= SWP_NOMOVE;
  501. m_nMRUWidth = pInfo->m_nMRUWidth;
  502. CalcDynamicLayout(0, LM_HORZ | LM_MRUWIDTH | LM_COMMIT);
  503. if (pInfo->m_bDocking)
  504. {
  505. ASSERT(m_pDockContext != NULL);
  506. // You need to call EnableDocking before calling LoadBarState
  507. m_pDockContext->m_uMRUDockID = pInfo->m_uMRUDockID;
  508. m_pDockContext->m_rectMRUDockPos = pInfo->m_rectMRUDockPos;
  509. m_pDockContext->m_dwMRUFloatStyle = pInfo->m_dwMRUFloatStyle;
  510. m_pDockContext->m_ptMRUFloatPos = pInfo->m_ptMRUFloatPos;
  511. }
  512. // move and show/hide the window
  513. SetWindowPos(NULL, pInfo->m_pointPos.x, pInfo->m_pointPos.y, 0, 0,
  514. nFlags | (pInfo->m_bVisible ? SWP_SHOWWINDOW : SWP_HIDEWINDOW));
  515. }
  516. void CDockBar::GetBarInfo(CControlBarInfo* pInfo)
  517. {
  518. ASSERT_VALID(this);
  519. pInfo->m_bDockBar = TRUE;
  520. pInfo->m_bFloating = m_bFloating;
  521. if (m_bFloating)
  522. {
  523. CRect rect;
  524. GetWindowRect(&rect);
  525. pInfo->m_pointPos = rect.TopLeft();
  526. }
  527. pInfo->m_bHorz = m_dwStyle & CBRS_ORIENT_HORZ ? TRUE : FALSE;
  528. for (int i = 0; i < m_arrBars.GetSize(); i++)
  529. {
  530. CControlBar* pBar = (CControlBar*)m_arrBars[i];
  531. if (pBar != NULL && HIWORD(pBar) == 0)
  532. {
  533. WORD w = LOWORD(((DWORD)pBar));
  534. void* pRememberedID = (void *)MAKELONG(w, 1);
  535. pInfo->m_arrBarID.Add(pRememberedID);
  536. }
  537. else
  538. {
  539. pInfo->m_arrBarID.Add(pBar == NULL ?
  540. 0 : (void*)_AfxGetDlgCtrlID(pBar->m_hWnd));
  541. }
  542. }
  543. }
  544. void CDockBar::SetBarInfo(CControlBarInfo* pInfo, CFrameWnd* pFrameWnd)
  545. {
  546. ASSERT(pFrameWnd != NULL);
  547. ASSERT_VALID(this);
  548. int nSize = pInfo->m_arrBarID.GetSize();
  549. // don't insert trailing NULLs
  550. while (nSize != 0 && (pInfo->m_arrBarID[nSize-1] == NULL ||
  551. pInfo->m_arrBarID[nSize-1] == (void*)MAKELONG(0, 1)))
  552. {
  553. nSize--;
  554. }
  555. // start at 1 to avoid inserting leading NULL
  556. for (int i = 1; i < nSize; i++)
  557. {
  558. CControlBar* pBar = NULL;
  559. if (HIWORD(pInfo->m_arrBarID[i]) == 0)
  560. {
  561. pBar = pFrameWnd->GetControlBar((UINT)pInfo->m_arrBarID[i]);
  562. if (pBar != NULL)
  563. {
  564. if (pBar->GetParent() != this)
  565. pBar->SetParent(this);
  566. if (pBar->m_pDockBar != NULL)
  567. pBar->m_pDockBar->RemoveControlBar(pBar, -1, -1);
  568. //remove the ID place holder if it exists in this dockbar
  569. RemovePlaceHolder(pBar);
  570. pBar->m_pDockBar = this;
  571. // align correctly and turn on all borders
  572. DWORD dwStyle = pBar->GetBarStyle();
  573. dwStyle &= ~(CBRS_ALIGN_ANY);
  574. dwStyle |= (m_dwStyle & CBRS_ALIGN_ANY);
  575. dwStyle |= CBRS_BORDER_ANY;
  576. if (m_bFloating)
  577. dwStyle |= CBRS_FLOATING;
  578. else
  579. dwStyle &= ~CBRS_FLOATING;
  580. pBar->SetBarStyle(dwStyle);
  581. // handle special case for floating toolbars
  582. if (m_bFloating)
  583. {
  584. // set CBRS_FLOAT_MULTI style if docking bar has it
  585. if (pBar->m_dwDockStyle & CBRS_FLOAT_MULTI)
  586. m_dwStyle |= CBRS_FLOAT_MULTI;
  587. // set owner of parent frame as appropriate
  588. CFrameWnd* pDockFrame = pBar->GetParentFrame();
  589. ASSERT_VALID(pDockFrame);
  590. ASSERT(pDockFrame != pBar->m_pDockSite);
  591. if (pDockFrame->m_hWndOwner == NULL)
  592. pDockFrame->m_hWndOwner = pBar->m_hWnd;
  593. if (pBar->m_dwStyle & CBRS_SIZE_DYNAMIC)
  594. pDockFrame->ModifyStyle(MFS_MOVEFRAME, 0);
  595. }
  596. // set initial text of the dock bar
  597. if (i == 1 && !(m_dwStyle & CBRS_FLOAT_MULTI))
  598. {
  599. CString strTitle;
  600. pBar->GetWindowText(strTitle);
  601. AfxSetWindowText(m_hWnd, strTitle);
  602. }
  603. }
  604. }
  605. else
  606. {
  607. WORD w = LOWORD(((DWORD)pInfo->m_arrBarID[i]));
  608. pBar = (CControlBar*)(MAKELONG(w, 0));
  609. RemovePlaceHolder(pBar);
  610. }
  611. m_arrBars.InsertAt(i, pBar);
  612. }
  613. int nArrSize = m_arrBars.GetSize();
  614. if (nSize < nArrSize && m_arrBars[nSize] != NULL)
  615. {
  616. m_arrBars.InsertAt(nSize, (void*)NULL);
  617. nArrSize++;
  618. }
  619. if (m_arrBars[nArrSize-1] != NULL)
  620. m_arrBars.InsertAt(nArrSize, (void*)NULL);
  621. ASSERT_VALID(this);
  622. }
  623. #ifdef AFX_INIT_SEG
  624. #pragma code_seg(AFX_INIT_SEG)
  625. #endif
  626. IMPLEMENT_SERIAL(CDockState, CObject, 0)
  627. /////////////////////////////////////////////////////////////////////////////