📄 bcgpcontrolbar.cpp
字号:
// the mouse is out of dock bar in either direction - keep the bar floating
return CS_NOTHING;
}
if (!CanBeDocked (*ppTargetBar))
{
// bar's style does not allow to dock the bar to this dock bar
return CS_NOTHING;
}
// the mouse is getting closer to a dock bar
(*ppTargetBar)->GetWindowRect (&rectDockBarWnd);
if (rectDockBarWnd.PtInRect (ptMousePos))
{
// the mouse is over the dock bar, the bar must be docked
return CS_DOCK_IMMEDIATELY;
}
// check on which side the mouse is relatively to the dock bar
bool bMouseLeft = ptMousePos.x < rectDockBarWnd.left;
bool bMouseRight = ptMousePos.x > rectDockBarWnd.right;
bool bMouseTop = ptMousePos.y < rectDockBarWnd.top;
bool bMouseBottom = ptMousePos.y > rectDockBarWnd.bottom;
double dPixelsOnDock = nOffset;
int nMouseOffset = 0;
if (bMouseLeft)
{
dPixelsOnDock = ((rectBarWnd.right - ptMousePos.x) * 100. /
rectBarWnd.Width ()) / 100. * nOffset;
nMouseOffset = rectDockBarWnd.left - ptMousePos.x;
}
else if (bMouseRight)
{
dPixelsOnDock = ((ptMousePos.x - rectBarWnd.left) * 100. /
rectBarWnd.Width ()) / 100. * nOffset;
nMouseOffset = ptMousePos.x - rectDockBarWnd.right;
}
else if (bMouseTop)
{
dPixelsOnDock = ((rectBarWnd.bottom - ptMousePos.y) * 100. /
rectBarWnd.Height ()) / 100. * nOffset;
nMouseOffset = rectDockBarWnd.top - ptMousePos.y;
}
else if (bMouseBottom)
{
dPixelsOnDock = ((ptMousePos.y - rectBarWnd.top) * 100. /
rectBarWnd.Height ()) / 100. * nOffset;
nMouseOffset = ptMousePos.y - rectDockBarWnd.bottom;
}
if (nMouseOffset <= dPixelsOnDock)
{
return CS_DOCK_IMMEDIATELY;
}
}
return CS_NOTHING;
}
//***********************************************************************************
CBCGPMiniFrameWnd* CBCGPControlBar::CreateDefaultMiniframe (CRect rectInitial)
{
ASSERT_VALID (this);
CRect rectVirtual = rectInitial;
CBCGPMiniFrameWnd* pMiniFrame =
(CBCGPMiniFrameWnd*) m_pMiniFrameRTC->CreateObject ();
if (pMiniFrame != NULL)
{
// it must have valid BCGFrame window as parent
CWnd* pParentFrame = BCGPGetParentFrame (this);
ASSERT_VALID (pParentFrame);
if (!pMiniFrame->Create (NULL, WS_POPUP, rectVirtual, pParentFrame))
{
TRACE0 ("Failed to create miniframe");
delete pMiniFrame;
return NULL;
}
}
else
{
TRACE0 ("Failed to create miniframe using runtime class information \n");
ASSERT (FALSE);
}
return pMiniFrame;
}
//***********************************************************************************
void CBCGPControlBar::UpdateVirtualRect ()
{
ASSERT_VALID (this);
GetWindowRect (m_rectVirtual);
CSize size = CalcFixedLayout (FALSE, IsHorizontal ());
m_rectVirtual.right = m_rectVirtual.left + size.cx;
m_rectVirtual.bottom = m_rectVirtual.top + size.cy;
if (GetParent () != NULL)
{
GetParent ()->ScreenToClient (m_rectVirtual);
}
}
//***********************************************************************************
void CBCGPControlBar::UpdateVirtualRect (CPoint ptOffset)
{
ASSERT_VALID (this);
m_rectVirtual.OffsetRect (ptOffset);
}
//***********************************************************************************//
void CBCGPControlBar::UpdateVirtualRect (CSize sizeNew)
{
ASSERT_VALID (this);
GetWindowRect (m_rectVirtual);
m_rectVirtual.right = m_rectVirtual.left + sizeNew.cx;
m_rectVirtual.bottom = m_rectVirtual.top + sizeNew.cy;
if (GetParent () != NULL)
{
GetParent ()->ScreenToClient (m_rectVirtual);
}
}
//***********************************************************************************
void CBCGPControlBar::GetVirtualRect (CRect& rectVirtual) const
{
ASSERT_VALID (this);
rectVirtual = m_rectVirtual;
ASSERT_VALID (GetParent ());
GetParent ()->ClientToScreen (rectVirtual);
}
//***********************************************************************************
void CBCGPControlBar::SetVirtualRect (const CRect& rect, BOOL bMapToParent)
{
ASSERT_VALID (this);
m_rectVirtual = rect;
ASSERT_VALID (GetParent ());
if (bMapToParent)
{
MapWindowPoints (GetParent (), m_rectVirtual);
}
}
//***********************************************************************************
void CBCGPControlBar::OnDestroy()
{
if (IsTabbed ())
{
CWnd* pParent = GetParent ();
ASSERT_VALID (pParent);
if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPBaseTabWnd)))
{
pParent = pParent->GetParent ();
ASSERT_VALID (pParent);
}
if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPBaseTabbedBar)))
{
CBCGPBaseTabbedBar* pTabbedBar = DYNAMIC_DOWNCAST (CBCGPBaseTabbedBar, pParent);
ASSERT (pTabbedBar != NULL);
HWND hwnd = m_hWnd;
pTabbedBar->RemoveControlBar (this);
if (!IsWindow (hwnd))
{
// the control bar has been destroyed by RemoveControlBar
return;
}
}
}
CBCGPBaseControlBar::OnDestroy();
}
//***********************************************************************************
void CBCGPControlBar::OnNcDestroy()
{
ASSERT_VALID (this);
CBCGPMiniFrameWnd::AddRemoveBarFromGlobalList (this, FALSE /* remove*/);
ASSERT_VALID (this);
CBCGPMiniFrameWnd* pMiniFrame = GetParentMiniFrame (TRUE);
if (pMiniFrame != NULL)
pMiniFrame->RemoveControlBar (this, FALSE);
CBCGPBaseControlBar::OnNcDestroy();
}
//***********************************************************************************
// MFC's control bar compatibility
//***********************************************************************************
BOOL CBCGPControlBar::AllocElements(int nElements, int cbElement)
{
ASSERT_VALID(this);
ASSERT(nElements >= 0 && cbElement >= 0);
ASSERT(m_pData != NULL || m_nCount == 0);
// allocate new data if necessary
void* pData = NULL;
if (nElements > 0)
{
ASSERT(cbElement > 0);
if ((pData = calloc(nElements, cbElement)) == NULL)
return FALSE;
}
free (m_pData); // free old data
// set new data and elements
m_pData = pData;
m_nCount = nElements;
return TRUE;
}
//-------------------------------------------------------------------------------------//
void CBCGPControlBar::CalcInsideRect(CRect& rect, BOOL bHorz) const
{
ASSERT_VALID(this);
DWORD dwStyle = GetBarStyle ();
if (!IsFloating () && !IsTabbed ())
{
if (dwStyle & CBRS_BORDER_LEFT)
rect.left += CX_BORDER;
if (dwStyle & CBRS_BORDER_TOP)
rect.top += CY_BORDER;
if (dwStyle & CBRS_BORDER_RIGHT)
rect.right -= CX_BORDER;
if (dwStyle & CBRS_BORDER_BOTTOM)
rect.bottom -= CY_BORDER;
}
// inset the top and bottom.
if (bHorz)
{
rect.left += m_cxLeftBorder;
rect.top += m_cyTopBorder;
rect.right -= m_cxRightBorder;
rect.bottom -= m_cyBottomBorder;
if ((dwStyle & (CBRS_GRIPPER|CBRS_FLOATING)) == CBRS_GRIPPER)
rect.left += CX_BORDER_GRIPPER+CX_GRIPPER+CX_BORDER_GRIPPER;
}
else
{
rect.left += m_cyTopBorder;
rect.top += m_cxLeftBorder;
rect.right -= m_cyBottomBorder;
rect.bottom -= m_cxRightBorder;
if ((dwStyle & (CBRS_GRIPPER|CBRS_FLOATING)) == CBRS_GRIPPER)
{
rect.top += CY_BORDER_GRIPPER+CY_GRIPPER+CY_BORDER_GRIPPER;
}
}
}
//-------------------------------------------------------------------------------------//
void CBCGPControlBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
OnProcessDblClk ();
if (CanFloat ())
{
FloatControlBar (m_recentDockInfo.m_rectRecentFloatingRect, DM_DBL_CLICK);
CBCGPBaseControlBar::OnLButtonDblClk(nFlags, point);
}
}
//-------------------------------------------------------------------------------------//
void CBCGPControlBar::OnProcessDblClk ()
{
m_bDblClick = true;
StoreRecentDockInfo ();
if (m_bCaptured)
{
ReleaseCapture ();
m_bCaptured = false;
SetDragMode (FALSE);
if (m_hwndMiniFrameToBeClosed != NULL && ::IsWindow (m_hwndMiniFrameToBeClosed))
{
::DestroyWindow (m_hwndMiniFrameToBeClosed);
}
m_hwndMiniFrameToBeClosed = NULL;
}
}
//-------------------------------------------------------------------------------------//
BOOL CBCGPControlBar::IsTabbed () const
{
CWnd* pImmediateParent = GetParent ();
if (pImmediateParent == NULL)
{
return FALSE;
}
CWnd* pNextParent = pImmediateParent->GetParent ();
return (pNextParent != NULL) &&
((pImmediateParent->IsKindOf (RUNTIME_CLASS (CBCGPBaseTabWnd)) &&
(pNextParent->IsKindOf (RUNTIME_CLASS (CBCGPBaseTabbedBar)) ||
pNextParent->IsKindOf (RUNTIME_CLASS (CBCGPTabbedToolbar)))) ||
(pImmediateParent->IsKindOf (RUNTIME_CLASS (CBCGPDockingCBWrapper)) &&
pNextParent->IsKindOf (RUNTIME_CLASS (CBCGPBaseTabWnd))));
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::SetDragMode (BOOL bOnOff)
{
m_bDragMode = bOnOff;
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::OnContextMenu(CWnd* pWnd, CPoint point)
{
if (!CBCGPToolBar::IsCustomizeMode ())
{
CFrameWnd* pParentFrame = DYNAMIC_DOWNCAST (CFrameWnd, m_pDockSite);
if (pParentFrame == NULL)
{
pParentFrame = BCGCBProGetTopLevelFrame (this);
}
if (pParentFrame != NULL)
{
ASSERT_VALID(pParentFrame);
pParentFrame->SendMessage (BCGM_TOOLBARMENU,
(WPARAM) GetSafeHwnd (),
MAKELPARAM(point.x, point.y));
}
}
}
//------------------------------------------------------------------------------------
BOOL CBCGPControlBar::LoadState (LPCTSTR lpszProfileName, int nIndex, UINT uiID)
{
CString strProfileName = ::BCGPGetRegPath (strControlBarProfile, 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 ("ID"), (int&) m_nID);
reg.Read (_T ("RectRecentFloat"), m_recentDockInfo.m_rectRecentFloatingRect);
reg.Read (_T ("RectRecentDocked"), m_rectSavedDockedRect);
// !!!!!! change to appropriate handling for slider/frame
m_recentDockInfo.m_recentSliderInfo.m_rectDockedRect = m_rectSavedDockedRect;
reg.Read (_T ("RecentFrameAlignment"), m_recentDockInfo.m_dwRecentAlignmentToFrame);
reg.Read (_T ("RecentRowIndex"), m_recentDockInfo.m_nRecentRowIndex);
reg.Read (_T ("IsFloating"), m_bRecentFloatingState);
reg.Read (_T ("MRUWidth"), m_nMRUWidth);
reg.Read (_T ("PinState"), m_bPinState);
return CBCGPBaseControlBar::LoadState (lpszProfileName, nIndex, uiID);
}
//------------------------------------------------------------------------------------
BOOL CBCGPControlBar::SaveState (LPCTSTR lpszProfileName, int nIndex, UINT uiID)
{
CString strProfileName = ::BCGPGetRegPath (strControlBarProfile, 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 bFloating = IsFloating ();
if (bFloating)
{
CBCGPMiniFrameWnd* pMiniFrame = GetParentMiniFrame ();
if (pMiniFrame != NULL)
{
pMiniFrame->GetWindowRect (m_recentDockInfo.m_rectRecentFloatingRect);
}
}
else
{
CalcRecentDockedRect ();
if (m_pParentDockBar != NULL)
{
m_recentDockInfo.m_dwRecentAlignmentToFrame = m_pParentDockBar->GetCurrentAlignment ();
m_recentDockInfo.m_nRecentRowIndex = m_pParentDockBar->FindRowIndex (m_pDockBarRow);
}
}
reg.Write (_T ("ID"), (int&)m_nID);
reg.Write (_T ("RectRecentFloat"), m_recentDockInfo.m_rectRecentFloatingRect);
reg.Write (_T ("RectRecentDocked"), m_recentDockInfo.m_recentSliderInfo.m_rectDockedRect);
reg.Write (_T ("RecentFrameAlignment"), m_recentDockInfo.m_dwRecentAlignmentToFrame);
reg.Write (_T ("RecentRowIndex"), m_recentDockInfo.m_nRecentRowIndex);
reg.Write (_T ("IsFloating"), bFloating);
reg.Write (_T ("MRUWidth"), m_nMRUWidth);
reg.Write (_T ("PinState"), m_bPinState);
}
return CBCGPBaseControlBar::SaveState (lpszProfileName, nIndex, uiID);
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::CalcRecentDockedRect ()
{
GetWindowRect (m_recentDockInfo.m_recentSliderInfo.m_rectDockedRect);
if (m_pParentDockBar != NULL)
{
m_pParentDockBar->ScreenToClient (m_recentDockInfo.m_recentSliderInfo.m_rectDockedRect);
}
else if (GetDockSite () != NULL)
{
GetDockSite ()->ScreenToClient (m_recentDockInfo.m_recentSliderInfo.m_rectDockedRect);
}
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::SetDockState (CBCGPDockManager* pDockManager)
{
ASSERT_VALID (this);
if (m_bRecentFloatingState)
{
ShowControlBar (GetRecentVisibleState (), TRUE, FALSE);
}
else
{
CBCGPDockBar* pDockBar =
pDockManager->FindDockBar (m_recentDockInfo.m_dwRecentAlignmentToFrame, TRUE);
if (pDockBar != NULL)
{
pDockManager->DockControlBar (this, pDockBar->GetDockBarID (),
m_recentDockInfo.m_recentSliderInfo.m_rectDockedRect);
}
if (m_pParentDockBar != NULL)
{
m_pParentDockBar->ShowControlBar (this, GetRecentVisibleState (), TRUE, FALSE);
if (m_pDockBarRow != NULL)
{
m_pDockBarRow->ExpandStretchedBars ();
}
}
}
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::OnCancelMode()
{
CBCGPBaseControlBar::OnCancelMode();
if (m_bCaptured)
{
if (GetDockMode () == DT_STANDARD)
{
m_dragFrameImpl.EndDrawDragFrame ();
}
ReleaseCapture ();
m_bCaptured = false;
SetDragMode (FALSE);
if (m_hwndMiniFrameToBeClosed != NULL && ::IsWindow (m_hwndMiniFrameToBeClosed))
{
::DestroyWindow (m_hwndMiniFrameToBeClosed);
}
m_hwndMiniFrameToBeClosed = NULL;
}
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == VK_ESCAPE)
{
OnCancelMode ();
}
CBCGPBaseControlBar::OnChar(nChar, nRepCnt, nFlags);
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::SetActiveInGroup (BOOL bActive)
{
m_bActiveInGroup = bActive;
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::UnDockControlBar (BOOL bDelay)
{
ASSERT_VALID (this);
if (m_pParentDockBar != NULL)
{
m_pParentDockBar->RemoveControlBar (this, DM_UNKNOWN);
}
if (!bDelay)
{
AdjustDockingLayout ();
}
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::AdjustSizeImmediate (BOOL bRecalcLayout)
{
CSize sizeCurr = CalcFixedLayout (FALSE, IsHorizontal ());
CRect rect;
GetWindowRect (rect);
if (rect.Size () != sizeCurr)
{
SetWindowPos (NULL, 0, 0, sizeCurr.cx, sizeCurr.cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
}
if (m_pParentDockBar != NULL)
{
UpdateVirtualRect ();
if (bRecalcLayout)
{
m_pDockBarRow->ArrangeBars(this);
BCGPGetParentFrame (this)->RecalcLayout ();
}
}
}
//------------------------------------------------------------------------------------
void CBCGPControlBar::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
CBCGPBaseControlBar::OnWindowPosChanging(lpwndpos);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -