📄 dockstat.cpp
字号:
TCHAR szSection[256];
wsprintf(szSection, _afxSummarySection, lpszProfileName);
pApp->WriteProfileInt(szSection, _afxBars, nIndex);
CSize size = GetScreenSize();
pApp->WriteProfileInt(szSection, _afxScreenCX, size.cx);
pApp->WriteProfileInt(szSection, _afxScreenCY, size.cy);
}
void CDockState::Clear()
{
for (int i = 0; i < m_arrBarInfo.GetSize(); i++)
delete (CControlBarInfo*) m_arrBarInfo[i];
m_arrBarInfo.RemoveAll();
}
DWORD CDockState::GetVersion()
{
return m_dwVersion;
}
void CDockState::ScalePoint(CPoint& pt)
{
if (m_bScaling)
{
CSize sizeDevice = m_rectDevice.Size();
pt.x = MulDiv(pt.x, sizeDevice.cx, m_sizeLogical.cx);
pt.y = MulDiv(pt.y, sizeDevice.cy, m_sizeLogical.cy);
}
if (pt.x > m_rectClip.right)
pt.x = m_rectClip.right;
if (pt.y > m_rectClip.bottom)
pt.y = m_rectClip.bottom;
}
void CDockState::ScaleRectPos(CRect& rect)
{
CPoint pt;
if (m_bScaling)
{
pt = rect.TopLeft();
CSize sizeDevice = m_rectDevice.Size();
pt.x = MulDiv(pt.x, sizeDevice.cx, m_sizeLogical.cx) - rect.left;
pt.y = MulDiv(pt.y, sizeDevice.cy, m_sizeLogical.cy) - rect.top;
rect.OffsetRect(pt);
}
pt.x = pt.y = 0;
if (rect.left > m_rectClip.right)
pt.x = m_rectClip.right - rect.left;
if (rect.top > m_rectClip.bottom)
pt.y = m_rectClip.bottom - rect.top;
if (!((pt.x == 0) && (pt.y == 0)))
rect.OffsetRect(pt);
}
CSize CDockState::GetScreenSize()
{
return m_rectDevice.Size();
}
void CDockState::SetScreenSize(CSize& size)
{
m_sizeLogical = size;
m_bScaling = (size != m_rectDevice.Size());
}
void CFrameWnd::LoadBarState(LPCTSTR lpszProfileName)
{
CDockState state;
state.LoadState(lpszProfileName);
SetDockState(state);
}
void CFrameWnd::SaveBarState(LPCTSTR lpszProfileName) const
{
CDockState state;
GetDockState(state);
state.SaveState(lpszProfileName);
}
void CFrameWnd::SetDockState(const CDockState& state)
{
// first pass through barinfo's sets the m_pBar member correctly
// creating floating frames if necessary
for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
{
CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
ASSERT(pInfo != NULL);
if (pInfo->m_bFloating)
{
// need to create floating frame to match
CMiniDockFrameWnd* pDockFrame = CreateFloatingFrame(
pInfo->m_bHorz ? CBRS_ALIGN_TOP : CBRS_ALIGN_LEFT);
ASSERT(pDockFrame != NULL);
CRect rect(pInfo->m_pointPos, CSize(10, 10));
pDockFrame->CalcWindowRect(&rect);
pDockFrame->SetWindowPos(NULL, rect.left, rect.top, 0, 0,
SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
CDockBar* pDockBar =
(CDockBar*)pDockFrame->GetDlgItem(AFX_IDW_DOCKBAR_FLOAT);
ASSERT(pDockBar != NULL);
ASSERT_KINDOF(CDockBar, pDockBar);
pInfo->m_pBar = pDockBar;
}
else // regular dock bar or toolbar
{
pInfo->m_pBar = GetControlBar(pInfo->m_nBarID);
ASSERT(pInfo->m_pBar != NULL); //toolbar id's probably changed
}
if(pInfo->m_pBar != NULL)
pInfo->m_pBar->m_nMRUWidth = pInfo->m_nMRUWidth;
}
// the second pass will actually dock all of the control bars and
// set everything correctly
for (i = 0; i < state.m_arrBarInfo.GetSize(); i++)
{
CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
ASSERT(pInfo != NULL);
if (pInfo->m_pBar != NULL)
pInfo->m_pBar->SetBarInfo(pInfo, this);
}
// last pass shows all the floating windows that were previously shown
for (i = 0; i < state.m_arrBarInfo.GetSize(); i++)
{
CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
ASSERT(pInfo != NULL);
ASSERT(pInfo->m_pBar != NULL);
if(pInfo->m_pBar != NULL)
{
if (pInfo->m_bFloating)
{
CFrameWnd* pFrameWnd = pInfo->m_pBar->GetParentFrame();
CDockBar* pDockBar = (CDockBar*)pInfo->m_pBar;
ASSERT_KINDOF(CDockBar, pDockBar);
if (pDockBar->GetDockedVisibleCount() > 0)
{
pFrameWnd->RecalcLayout();
pFrameWnd->ShowWindow(SW_SHOWNA);
}
}
}
}
DelayRecalcLayout();
}
void CFrameWnd::GetDockState(CDockState& state) const
{
state.Clear(); //make sure dockstate is empty
// get state info for each bar
POSITION pos = m_listControlBars.GetHeadPosition();
while (pos != NULL)
{
CControlBar* pBar = (CControlBar*)m_listControlBars.GetNext(pos);
ASSERT(pBar != NULL);
CControlBarInfo* pInfo = new CControlBarInfo;
pBar->GetBarInfo(pInfo);
state.m_arrBarInfo.Add(pInfo);
}
}
// Note: GetBarInfo and SetBarInfo are not virtual since doing so adds
// to much code to an application which does not save and load docking
// state. For this reason, the CControlBar implementations must
// delagate to CDockBar as appropriate.
void CControlBar::GetBarInfo(CControlBarInfo* pInfo)
{
ASSERT_VALID(this);
// get state info
pInfo->m_nBarID = _AfxGetDlgCtrlID(m_hWnd);
pInfo->m_pBar = this;
pInfo->m_bVisible = IsVisible(); // handles delayed showing and hiding
pInfo->m_nMRUWidth = m_nMRUWidth;
if (m_pDockBar != NULL) // don't need position unless docked
{
CRect rect;
GetWindowRect(&rect);
m_pDockBar->ScreenToClient(&rect);
pInfo->m_pointPos = rect.TopLeft();
ASSERT(m_pDockContext != NULL);
pInfo->m_bDocking = TRUE;
pInfo->m_uMRUDockID = m_pDockContext->m_uMRUDockID;
pInfo->m_rectMRUDockPos = m_pDockContext->m_rectMRUDockPos;
pInfo->m_dwMRUFloatStyle = m_pDockContext->m_dwMRUFloatStyle;
pInfo->m_ptMRUFloatPos = m_pDockContext->m_ptMRUFloatPos;
}
// save dockbar specific parts
if (IsDockBar())
((CDockBar*)this)->GetBarInfo(pInfo);
}
void CControlBar::SetBarInfo(CControlBarInfo* pInfo, CFrameWnd* pFrameWnd)
{
// dockbars are handled differently
if (IsDockBar())
{
((CDockBar*)this)->SetBarInfo(pInfo, pFrameWnd);
return;
}
// don't set position when not docked
UINT nFlags = SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER;
if (m_pDockBar == NULL)
nFlags |= SWP_NOMOVE;
m_nMRUWidth = pInfo->m_nMRUWidth;
CalcDynamicLayout(0, LM_HORZ | LM_MRUWIDTH | LM_COMMIT);
if (pInfo->m_bDocking)
{
ASSERT(m_pDockContext != NULL);
// You need to call EnableDocking before calling LoadBarState
m_pDockContext->m_uMRUDockID = pInfo->m_uMRUDockID;
m_pDockContext->m_rectMRUDockPos = pInfo->m_rectMRUDockPos;
m_pDockContext->m_dwMRUFloatStyle = pInfo->m_dwMRUFloatStyle;
m_pDockContext->m_ptMRUFloatPos = pInfo->m_ptMRUFloatPos;
}
// move and show/hide the window
SetWindowPos(NULL, pInfo->m_pointPos.x, pInfo->m_pointPos.y, 0, 0,
nFlags | (pInfo->m_bVisible ? SWP_SHOWWINDOW : SWP_HIDEWINDOW));
}
void CDockBar::GetBarInfo(CControlBarInfo* pInfo)
{
ASSERT_VALID(this);
pInfo->m_bDockBar = TRUE;
pInfo->m_bFloating = m_bFloating;
if (m_bFloating)
{
CRect rect;
GetWindowRect(&rect);
pInfo->m_pointPos = rect.TopLeft();
}
pInfo->m_bHorz = m_dwStyle & CBRS_ORIENT_HORZ ? TRUE : FALSE;
for (int i = 0; i < m_arrBars.GetSize(); i++)
{
CControlBar* pBar = (CControlBar*)m_arrBars[i];
if (pBar != NULL && HIWORD(pBar) == 0)
{
WORD w = LOWORD(((DWORD)pBar));
void* pRememberedID = (void *)MAKELONG(w, 1);
pInfo->m_arrBarID.Add(pRememberedID);
}
else
{
pInfo->m_arrBarID.Add(pBar == NULL ?
0 : (void*)_AfxGetDlgCtrlID(pBar->m_hWnd));
}
}
}
void CDockBar::SetBarInfo(CControlBarInfo* pInfo, CFrameWnd* pFrameWnd)
{
ASSERT(pFrameWnd != NULL);
ASSERT_VALID(this);
int nSize = pInfo->m_arrBarID.GetSize();
// don't insert trailing NULLs
while (nSize != 0 && (pInfo->m_arrBarID[nSize-1] == NULL ||
pInfo->m_arrBarID[nSize-1] == (void*)MAKELONG(0, 1)))
{
nSize--;
}
// start at 1 to avoid inserting leading NULL
for (int i = 1; i < nSize; i++)
{
CControlBar* pBar = NULL;
if (HIWORD(pInfo->m_arrBarID[i]) == 0)
{
pBar = pFrameWnd->GetControlBar((UINT)pInfo->m_arrBarID[i]);
if (pBar != NULL)
{
if (pBar->GetParent() != this)
pBar->SetParent(this);
if (pBar->m_pDockBar != NULL)
pBar->m_pDockBar->RemoveControlBar(pBar, -1, -1);
//remove the ID place holder if it exists in this dockbar
RemovePlaceHolder(pBar);
pBar->m_pDockBar = this;
// align correctly and turn on all borders
DWORD dwStyle = pBar->GetBarStyle();
dwStyle &= ~(CBRS_ALIGN_ANY);
dwStyle |= (m_dwStyle & CBRS_ALIGN_ANY);
dwStyle |= CBRS_BORDER_ANY;
if (m_bFloating)
dwStyle |= CBRS_FLOATING;
else
dwStyle &= ~CBRS_FLOATING;
pBar->SetBarStyle(dwStyle);
// handle special case for floating toolbars
if (m_bFloating)
{
// set CBRS_FLOAT_MULTI style if docking bar has it
if (pBar->m_dwDockStyle & CBRS_FLOAT_MULTI)
m_dwStyle |= CBRS_FLOAT_MULTI;
// set owner of parent frame as appropriate
CFrameWnd* pDockFrame = pBar->GetParentFrame();
ASSERT_VALID(pDockFrame);
ASSERT(pDockFrame != pBar->m_pDockSite);
if (pDockFrame->m_hWndOwner == NULL)
pDockFrame->m_hWndOwner = pBar->m_hWnd;
if (pBar->m_dwStyle & CBRS_SIZE_DYNAMIC)
pDockFrame->ModifyStyle(MFS_MOVEFRAME, 0);
}
// set initial text of the dock bar
if (i == 1 && !(m_dwStyle & CBRS_FLOAT_MULTI))
{
CString strTitle;
pBar->GetWindowText(strTitle);
AfxSetWindowText(m_hWnd, strTitle);
}
}
}
else
{
WORD w = LOWORD(((DWORD)pInfo->m_arrBarID[i]));
pBar = (CControlBar*)(MAKELONG(w, 0));
RemovePlaceHolder(pBar);
}
m_arrBars.InsertAt(i, pBar);
}
int nArrSize = m_arrBars.GetSize();
if (nSize < nArrSize && m_arrBars[nSize] != NULL)
{
m_arrBars.InsertAt(nSize, (void*)NULL);
nArrSize++;
}
if (m_arrBars[nArrSize-1] != NULL)
m_arrBars.InsertAt(nArrSize, (void*)NULL);
ASSERT_VALID(this);
}
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
IMPLEMENT_SERIAL(CDockState, CObject, 0)
/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -