home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / DOCKSTAT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  19.6 KB  |  718 lines

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