home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / dockstat.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  20.0 KB  |  717 lines

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