📄 bcgpbasecontrolbar.cpp
字号:
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
{
return ((CBCGPOleCntrFrameWnd*) pParentFrame)->
ControlBarFromPoint (point, nSensitivity, bExactBar, pRTCBarType);
}
else
{
ASSERT (FALSE);
}
return FALSE;
}
//*******************************************************************************
BOOL CBCGPBaseControlBar::InsertControlBar (CBCGPBaseControlBar* pControlBar,
CBCGPBaseControlBar* pTarget, BOOL bAfter)
{
CBCGPMultiMiniFrameWnd* pParentMiniFrame =
DYNAMIC_DOWNCAST (CBCGPMultiMiniFrameWnd, GetParentMiniFrame ());
if (pParentMiniFrame != NULL)
{
return pParentMiniFrame->InsertControlBar (pControlBar, pTarget, bAfter);
}
CWnd* pParentFrame = GetDockSite ();
if (pParentFrame == NULL && globalUtils.m_bDialogApp)
{
return TRUE;
}
ASSERT_VALID (pParentFrame);
if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
{
return ((CBCGPFrameWnd*) pParentFrame)->
InsertControlBar (pControlBar, pTarget, bAfter);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
{
return ((CBCGPMDIFrameWnd*) pParentFrame)->
InsertControlBar (pControlBar, pTarget, bAfter);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
{
return ((CBCGPOleIPFrameWnd*) pParentFrame)->
InsertControlBar (pControlBar, pTarget, bAfter);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
{
return ((CBCGPOleDocIPFrameWnd*) pParentFrame)->
InsertControlBar (pControlBar, pTarget, bAfter);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
{
return ((CBCGPMDIChildWnd*) pParentFrame)->
InsertControlBar (pControlBar, pTarget, bAfter);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
{
return ((CBCGPOleCntrFrameWnd*) pParentFrame)->
InsertControlBar (pControlBar, pTarget, bAfter);
}
else
{
ASSERT (FALSE);
}
return FALSE;
}
//*******************************************************************************
void CBCGPBaseControlBar::AdjustDockingLayout (HDWP hdwp)
{
CBCGPMiniFrameWnd* pParentMiniFrame = GetParentMiniFrame ();
if (pParentMiniFrame != NULL)
{
pParentMiniFrame->OnBarRecalcLayout ();
return;
}
CWnd* pParentFrame = GetDockSite ();
if (globalUtils.m_bDialogApp && pParentFrame == NULL)
{
return;
}
ASSERT_VALID (pParentFrame);
if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
{
((CBCGPFrameWnd*) pParentFrame)->AdjustDockingLayout (hdwp);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
{
((CBCGPMDIFrameWnd*) pParentFrame)->AdjustDockingLayout (hdwp);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
{
((CBCGPOleIPFrameWnd*) pParentFrame)->AdjustDockingLayout (hdwp);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
{
((CBCGPOleDocIPFrameWnd*) pParentFrame)->AdjustDockingLayout (hdwp);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
{
((CBCGPMDIChildWnd*) pParentFrame)->AdjustDockingLayout (hdwp);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
{
((CBCGPOleCntrFrameWnd*) pParentFrame)->AdjustDockingLayout (hdwp);
}
else
{
ASSERT (FALSE);
}
}
//*******************************************************************************
void CBCGPBaseControlBar::DockControlBarMap (BOOL bUseDocSite)
{
CWnd* pParentFrame = bUseDocSite ? m_pDockSite : (CWnd*) BCGPGetParentFrame (this);
if (pParentFrame == NULL && globalUtils.m_bDialogApp)
{
return;
}
ASSERT_VALID (pParentFrame);
if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
{
((CBCGPFrameWnd*) pParentFrame)->DockControlBar (this);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
{
((CBCGPMDIFrameWnd*) pParentFrame)->DockControlBar (this);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
{
((CBCGPOleIPFrameWnd*) pParentFrame)->DockControlBar (this);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
{
((CBCGPOleDocIPFrameWnd*) pParentFrame)->DockControlBar (this);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
{
((CBCGPMDIChildWnd*) pParentFrame)->DockControlBar (this);
}
else if (pParentFrame->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
{
((CBCGPOleCntrFrameWnd*) pParentFrame)->DockControlBar (this);
}
else
{
ASSERT (FALSE);
}
}
//*******************************************************************************
void CBCGPBaseControlBar::ShowControlBar (BOOL bShow, BOOL bDelay, BOOL bActivate)
{
int nShowCmd = bShow ? SW_SHOWNOACTIVATE : SW_HIDE;
if (IsFloating () && !IsTabbed ())
{
ShowWindow (nShowCmd);
CWnd* pParent = GetParent ();
ASSERT_VALID (pParent);
pParent->ShowWindow (nShowCmd);
}
else if (m_pParentDockBar != NULL)
{
m_pParentDockBar->ShowControlBar (this, bShow, bDelay, bActivate);
}
else if (IsTabbed ())
{
HWND hWndTab = NULL;
CBCGPBaseTabWnd* pTabParent = GetParentTabWnd (hWndTab);
ASSERT_VALID (pTabParent);
CBCGPBaseTabbedBar* pTabbedControlBar =
DYNAMIC_DOWNCAST (CBCGPBaseTabbedBar, pTabParent->GetParent ());
if (pTabbedControlBar != NULL && !pTabbedControlBar->IsBarVisible () &&
pTabbedControlBar->GetTabsNum () > 1 && bShow)
{
pTabbedControlBar->ShowTab (this, TRUE, bDelay, bActivate);
return;
}
if (pTabbedControlBar != NULL)
{
ASSERT_VALID (pTabbedControlBar);
pTabbedControlBar->ShowTab (this, bShow, bDelay, bActivate);
if (pTabParent->GetVisibleTabsNum () == 0)
{
pTabbedControlBar->ShowControlBar (bShow, bDelay, bActivate);
}
}
else
{
int iTab = pTabParent->GetTabFromHwnd (GetSafeHwnd ());
pTabParent->ShowTab (iTab, bShow, !bDelay);
}
}
else
{
ShowWindow (nShowCmd);
if (!bDelay)
{
AdjustDockingLayout ();
}
}
if (GetDockRow () != NULL)
{
GetDockRow ()->FixupVirtualRects (false);
}
}
//************************************************************************************
LRESULT CBCGPBaseControlBar::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM)
{
// the style must be visible and if it is docked
// the dockbar style must also be visible
if ((GetStyle() & WS_VISIBLE) &&
(m_pParentDockBar == NULL || (m_pParentDockBar->GetStyle() & WS_VISIBLE)))
{
CFrameWnd* pTarget = (CFrameWnd*)GetOwner();
if (pTarget == NULL || !pTarget->IsFrameWnd())
pTarget = BCGPGetParentFrame(this);
if (pTarget != NULL)
OnUpdateCmdUI(pTarget, (BOOL)wParam);
}
return 0L;
}
//*************************************************************************************
void CBCGPBaseControlBar::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
if (m_pDockBarRow != NULL)
{
m_pDockBarRow->OnResizeControlBar (this);
}
}
//*************************************************************************************
void CBCGPBaseControlBar::Serialize (CArchive& ar)
{
CWnd::Serialize (ar);
if (ar.IsLoading ())
{
DWORD dwAlign = 0;
ar >> dwAlign;
m_dwStyle |= dwAlign;
ar >> m_bRecentVisibleState;
}
else
{
ar << (m_dwStyle & CBRS_ALIGN_ANY);
ar << IsVisible ();
}
}
//*************************************************************************************
BOOL CBCGPBaseControlBar::LoadState (LPCTSTR lpszProfileName, int nIndex, UINT uiID)
{
CString strProfileName = ::BCGPGetRegPath (strBaseControlBarProfile, lpszProfileName);
if (nIndex == -1)
{
nIndex = GetDlgCtrlID ();
}
CString strSection;
if (uiID == (UINT) -1)
{
strSection.Format (REG_SECTION_FMT, strProfileName, nIndex);
}
else
{
strSection.Format (REG_SECTION_FMT_EX, strProfileName, nIndex, uiID);
}
CBCGPRegistrySP regSP;
CBCGPRegistry& reg = regSP.Create (FALSE, TRUE);
if (!reg.Open (strSection))
{
return FALSE;
}
reg.Read (_T ("IsVisible"), m_bRecentVisibleState);
m_bIsRestoredFromRegistry = TRUE;
return TRUE;
}
//*************************************************************************************
BOOL CBCGPBaseControlBar::SaveState (LPCTSTR lpszProfileName, int nIndex, UINT uiID)
{
CString strProfileName = ::BCGPGetRegPath (strBaseControlBarProfile, lpszProfileName);
if (nIndex == -1)
{
nIndex = GetDlgCtrlID ();
}
CString strSection;
if (uiID == (UINT) -1)
{
strSection.Format (REG_SECTION_FMT, strProfileName, nIndex);
}
else
{
strSection.Format (REG_SECTION_FMT_EX, strProfileName, nIndex, uiID);
}
CBCGPRegistrySP regSP;
CBCGPRegistry& reg = regSP.Create (FALSE, FALSE);
if (reg.CreateKey (strSection))
{
BOOL bIsVisible = IsVisible ();
reg.Write (_T ("IsVisible"), bIsVisible);
}
return TRUE;
}
//*************************************************************************************
CWnd* CBCGPBaseControlBar::GetDockSite () const
{
if (m_pDockSite == NULL && GetParent ()->IsKindOf (RUNTIME_CLASS (CDialog)))
{
globalUtils.m_bDialogApp = TRUE;
}
return m_pDockSite;
}
//*************************************************************************************
BCGP_DOCK_TYPE CBCGPBaseControlBar::GetDockMode () const
{
if (m_dockMode != DT_UNDEFINED)
{
return m_dockMode;
}
return CBCGPDockManager::m_dockModeGlobal;
}
//*************************************************************************************
BOOL CBCGPBaseControlBar::CanFloat () const
{
if (!IsTabbed ())
{
return m_dwBCGStyle & CBRS_BCGP_FLOAT;
}
HWND hWndTab = NULL;
CBCGPBaseTabWnd* pParentTabWnd = GetParentTabWnd (hWndTab);
if (pParentTabWnd == NULL)
{
return m_dwBCGStyle & CBRS_BCGP_FLOAT;
}
int nTabNum = pParentTabWnd->GetTabFromHwnd (hWndTab);
if (nTabNum == -1)
{
return m_dwBCGStyle & CBRS_BCGP_FLOAT;
}
return pParentTabWnd->IsTabDetachable (nTabNum);
}
//***************************************************************************************
CBCGPBaseTabWnd* CBCGPBaseControlBar::GetParentTabWnd (HWND& hWndTab) const
{
ASSERT_VALID (this);
const CWnd* pWndToCheck = this;
CBCGPDockingCBWrapper* pWrapper = DYNAMIC_DOWNCAST (CBCGPDockingCBWrapper, GetParent ());
if (pWrapper != NULL)
{
pWndToCheck = pWrapper;
hWndTab = pWrapper->GetSafeHwnd ();
}
else
{
hWndTab = GetSafeHwnd ();
}
CBCGPBaseTabWnd* pParentTabWnd = DYNAMIC_DOWNCAST (CBCGPBaseTabWnd, pWndToCheck->GetParent ());
if (pParentTabWnd == NULL)
{
CBCGPBaseTabbedBar* pParentTabBar = DYNAMIC_DOWNCAST (CBCGPBaseTabbedBar, pWndToCheck->GetParent ());
if (pParentTabBar != NULL)
{
return pParentTabBar->GetUnderlinedWindow ();
}
}
return pParentTabWnd;
}
//***************************************************************************************
CBCGPBaseTabbedBar* CBCGPBaseControlBar::GetParentTabbedBar () const
{
HWND hWndTab = NULL;
if (!IsTabbed ())
{
return NULL;
}
CBCGPBaseTabWnd* pTabWnd = GetParentTabWnd (hWndTab);
if (hWndTab == NULL || pTabWnd == NULL)
{
return NULL;
}
ASSERT_VALID (pTabWnd);
return DYNAMIC_DOWNCAST (CBCGPBaseTabbedBar, pTabWnd->GetParent ());
}
//***************************************************************************************
LRESULT CBCGPBaseControlBar::OnHelpHitTest(WPARAM, LPARAM lParam)
{
ASSERT_VALID(this);
int nID = OnToolHitTest((DWORD)lParam, NULL);
if (nID != -1)
return HID_BASE_COMMAND+nID;
nID = _AfxGetDlgCtrlID(m_hWnd);
return nID != 0 ? HID_BASE_CONTROL+nID : 0;
}
//***************************************************************************************
LRESULT CBCGPBaseControlBar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
ASSERT_VALID(this);
LRESULT lResult;
switch (message)
{
case WM_NOTIFY:
case WM_COMMAND:
case WM_DRAWITEM:
case WM_MEASUREITEM:
case WM_DELETEITEM:
case WM_COMPAREITEM:
case WM_VKEYTOITEM:
case WM_CHARTOITEM:
// send these messages to the owner if not handled
if (OnWndMsg(message, wParam, lParam, &lResult))
return lResult;
else
{
// try owner next
lResult = GetOwner()->SendMessage(message, wParam, lParam);
// special case for TTN_NEEDTEXTA and TTN_NEEDTEXTW
if(message == WM_NOTIFY)
{
NMHDR* pNMHDR = (NMHDR*)lParam;
if (pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW)
{
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
if (pNMHDR->code == TTN_NEEDTEXTA)
{
if (pTTTA->hinst == 0 && (!pTTTA->lpszText || !*pTTTA->lpszText))
{
// not handled by owner, so let bar itself handle it
lResult = CWnd::WindowProc(message, wParam, lParam);
}
} else if (pNMHDR->code == TTN_NEEDTEXTW)
{
if (pTTTW->hinst == 0 && (!pTTTW->lpszText || !*pTTTW->lpszText))
{
// not handled by owner, so let bar itself handle it
lResult = CWnd::WindowProc(message, wParam, lParam);
}
}
}
}
return lResult;
}
}
// otherwise, just handle in default way
lResult = CWnd::WindowProc(message, wParam, lParam);
return lResult;
}
//***************************************************************************************
BOOL CBCGPBaseControlBar::PreTranslateMessage(MSG* pMsg)
{
ASSERT_VALID(this);
ASSERT(m_hWnd != NULL);
if (CWnd::PreTranslateMessage(pMsg))
return TRUE;
CWnd* pOwner = GetOwner();
// don't translate dialog messages when in Shift+F1 help mode
CFrameWnd* pFrameWnd = GetTopLevelFrame();
if (pFrameWnd != NULL && pFrameWnd->m_bHelpMode)
return FALSE;
// since 'IsDialogMessage' will eat frame window accelerators,
// we call all frame windows' PreTranslateMessage first
while (pOwner != NULL)
{
// allow owner & frames to translate before IsDialogMessage does
if (pOwner->PreTranslateMessage(pMsg))
return TRUE;
// try parent frames until there are no parent frames
pOwner = pOwner->GetParentFrame();
}
// filter both messages to dialog and from children
return PreTranslateInput(pMsg);
}
//***************************************************************************************
LRESULT CBCGPBaseControlBar::HandleInitDialog(WPARAM, LPARAM)
{
if (m_lpszBarTemplateName != NULL)
{
if (!ExecuteDlgInit(m_lpszBarTemplateName))
{
return FALSE;
}
}
if (!UpdateData(FALSE))
{
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -