📄 bcgpbasetabwnd.cpp
字号:
if (!ActivateOnBtnUp ())
{
int nTab = GetTabFromPoint (point);
SetActiveTab (point);
bTabWasMoved = (nTab != GetTabFromPoint (point));
m_iHighlighted = -1;
ReleaseCapture ();
}
else
{
m_iPressed = m_iHighlighted;
}
if (iHighlighted != m_iActiveTab)
{
InvalidateTab (iHighlighted);
}
if (!bTabWasMoved)
{
EnterDragMode ();
}
}
}
//***************************************************************************************
void CBCGPBaseTabWnd::EnterDragMode ()
{
m_bReadyToDetach = TRUE;
SetCapture ();
GetCursorPos (&m_ptHot);
CRect rectTab;
GetTabRect (m_iActiveTab, rectTab);
m_iTabBeforeDrag = m_iActiveTab;
ClientToScreen (rectTab);
m_nOffsetFromTabLeft = m_ptHot.x - rectTab.left;
}
//***************************************************************************************
void CBCGPBaseTabWnd::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CWnd::OnLButtonDblClk(nFlags, point);
if (m_bIsInPlaceEdit)
{
int iTab = GetTabFromPoint (point);
if (iTab == GetActiveTab())
{
if (StartRenameTab (iTab))
return;
}
}
else
{
CWnd* pWndTarget = FindTargetWnd (point);
if (pWndTarget == NULL)
{
DetachTab (DM_DBL_CLICK);
}
}
}
//***************************************************************************************
void CBCGPBaseTabWnd::OnLButtonUp(UINT nFlags, CPoint point)
{
if (m_iTabBeforeDrag != m_iActiveTab)
{
CWnd* pWndParent = GetParent ();
ASSERT_VALID (pWndParent);
pWndParent->SendMessage (BCGM_ON_MOVE_TAB, m_iTabBeforeDrag, m_iActiveTab);
if (pWndParent->IsKindOf (RUNTIME_CLASS (CBCGPBaseTabbedBar)))
{
pWndParent = BCGPGetParentFrame (pWndParent);
if (pWndParent != NULL)
{
pWndParent->SendMessage (BCGM_ON_MOVE_TAB, m_iTabBeforeDrag, m_iActiveTab);
}
}
}
if (m_bReadyToDetach)
{
m_bReadyToDetach = FALSE;
ReleaseCapture ();
if (!ActivateOnBtnUp ())
{
m_iPressed = -1;
m_iHighlighted = -1;
}
}
if (ActivateOnBtnUp ())
{
bool bNewActiveTab = m_iActiveTab != m_iHighlighted;
if (m_iHighlighted == m_iPressed)
{
SetActiveTab (point);
}
int iHighlighted = m_iHighlighted;
int iPressed = m_iPressed;
m_iPressed = -1;
if (!IsOneNoteStyle ())
{
m_iHighlighted = -1;
}
ReleaseCapture ();
if (bNewActiveTab)
{
InvalidateTab (iHighlighted);
if (iPressed != iHighlighted)
{
InvalidateTab (iPressed);
}
}
}
CWnd::OnLButtonUp(nFlags, point);
}
//***************************************************************************************
void CBCGPBaseTabWnd::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd::OnMouseMove(nFlags, point);
int iPrevHighlighted = m_iHighlighted;
m_iHighlighted = GetTabFromPoint (point);
if (m_iPressed >= 0 && m_iHighlighted != m_iPressed)
{
m_iHighlighted = -1;
}
if (m_iHighlighted != iPrevHighlighted && m_bHighLightTabs)
{
if (iPrevHighlighted < 0)
{
if (m_iHighlighted >= 0)
{
SetCapture ();
}
}
else
{
if (m_iHighlighted < 0 && m_iPressed < 0)
{
if (!m_bReadyToDetach)
{
ReleaseCapture ();
}
}
}
InvalidateTab (m_iHighlighted);
InvalidateTab (iPrevHighlighted);
}
if (m_bReadyToDetach)
{
int nNumTabs = m_iTabsNum; // how many tabs before detch
// try to rearrange tabs if their number > 1
if (IsPtInTabArea (point) && nNumTabs > 1 && m_bEnableTabSwap)
{
CRect rectTab;
int nTabNum = GetTabFromPoint (point);
if (nTabNum != m_iActiveTab && nTabNum != -1)
{
int nSecondTab = m_iActiveTab;
SwapTabs (nTabNum, nSecondTab);
RecalcLayout ();
SetActiveTab (nTabNum);
int nCurrTabNum = GetTabFromPoint (point);
if (nCurrTabNum != nTabNum)
{
GetTabRect (nTabNum, rectTab);
CPoint ptCursorNewPos = point;
ptCursorNewPos.x = rectTab.left + m_nOffsetFromTabLeft;
ClientToScreen (&ptCursorNewPos);
SetCursorPos (ptCursorNewPos.x, ptCursorNewPos.y);
}
}
return;
}
if (IsPtInTabArea (point))
{
return;
}
BOOL bDetachSucceeded = DetachTab (DM_MOUSE);
if (bDetachSucceeded && nNumTabs <= 2)
{
// last tab was detached successfully - run out, because the control
// jas been destroyed
return;
}
if (bDetachSucceeded)
{
m_bReadyToDetach = FALSE;
}
return;
}
}
//************************************************************************************
void CBCGPBaseTabWnd::OnCancelMode()
{
CWnd::OnCancelMode();
if (m_iHighlighted >= 0)
{
int iTab = m_iHighlighted;
ReleaseCapture ();
m_iHighlighted = -1;
m_iPressed = -1;
InvalidateTab (iTab);
}
if (m_pInPlaceEdit != NULL)
{
m_pInPlaceEdit->DestroyWindow ();
delete m_pInPlaceEdit;
m_pInPlaceEdit = NULL;
m_iEditedTab = -1;
ReleaseCapture ();
}
}
//************************************************************************************
void CBCGPBaseTabWnd::InvalidateTab (int iTab)
{
ASSERT_VALID (this);
if (iTab < 0)
{
return;
}
CRect rectTab;
if (GetTabRect (iTab, rectTab))
{
InvalidateRect (rectTab);
UpdateWindow ();
}
}
//*************************************************************************************
BOOL CBCGPBaseTabWnd::SetActiveTab (CPoint point)
{
ASSERT_VALID (this);
if (m_iHighlighted < 0)
{
return FALSE;
}
CWnd* pWndParent = GetParent ();
ASSERT_VALID (pWndParent);
if (m_iHighlighted != m_iActiveTab && IsPtInTabArea (point))
{
m_iLastActiveTab = m_iActiveTab;
SetActiveTab (m_iHighlighted);
pWndParent->SendMessage (BCGM_CHANGE_ACTIVE_TAB, m_iHighlighted);
}
return TRUE;
}
//*************************************************************************************
void CBCGPBaseTabWnd::OnDestroy()
{
CleanUp ();
CWnd::OnDestroy();
}
//*************************************************************************************
int CBCGPBaseTabWnd::FindTabInfo (int nBarID, CBCGPTabInfo** ppTabInfo)
{
*ppTabInfo = NULL;
for (int i = 0; i < m_arTabs.GetSize (); i++)
{
CBCGPTabInfo* pTabInfo = (CBCGPTabInfo*) m_arTabs.GetAt (i);
ASSERT_VALID (pTabInfo);
if (pTabInfo->m_pWnd != NULL && pTabInfo->m_pWnd->GetDlgCtrlID () == nBarID)
{
*ppTabInfo = pTabInfo;
return i;
}
}
return NULL;
}
//*************************************************************************************
void CBCGPBaseTabWnd::ApplyRestoredTabInfo (BOOL bUseTabIndexes)
{
CBCGPDockManager* pDockManager = globalUtils.GetDockManager (BCGPGetParentFrame (this));
ASSERT_VALID (pDockManager);
for (POSITION pos = m_lstRestoredTabInfo.GetHeadPosition (); pos != NULL;)
{
CBCGPRestoredTabInfo tabInfo = m_lstRestoredTabInfo.GetNext (pos);
CBCGPTabInfo* pCurrTabInfo = NULL;
FindTabInfo (tabInfo.m_nControlBarID, &pCurrTabInfo);
if (pCurrTabInfo != NULL)
{
continue;
}
CBCGPDockingControlBar* pBar = DYNAMIC_DOWNCAST (CBCGPDockingControlBar,
pDockManager->FindBarByID (tabInfo.m_nControlBarID, TRUE));
if (pBar != NULL)
{
if (pBar->IsTabbed ())
{
CBCGPBaseTabWnd* pTabWnd = (CBCGPBaseTabWnd*) pBar->GetParent ();
CBCGPBaseTabbedBar* pTabBar = (CBCGPBaseTabbedBar*) pTabWnd->GetParent ();
ASSERT_VALID (pTabBar);
pBar->SetParent (GetParent ());
pTabBar->RemoveControlBar (pBar);
if (pBar->IsKindOf (RUNTIME_CLASS (CBCGPDockingControlBar)))
{
((CBCGPDockingControlBar*) pBar)->EnableGripper (TRUE);
}
pBar->ShowWindow (SW_SHOW);
}
if (pBar->IsAutoHideMode ())
{
pBar->SetAutoHideMode (FALSE, CBRS_ALIGN_ANY);
}
CBCGPMiniFrameWnd* pMiniFrame = pBar->GetParentMiniFrame ();
if (pMiniFrame != NULL)
{
pMiniFrame->RemoveControlBar (pBar);
}
pBar->SetParent (GetParent ());
CBCGPBaseTabbedBar* pTabbedBar =
DYNAMIC_DOWNCAST (CBCGPBaseTabbedBar, GetParent ());
pBar->AttachToTabWnd (pTabbedBar, DM_SHOW, FALSE);
}
}
int nTabIdx = 0;
for (pos = m_lstRestoredTabInfo.GetHeadPosition (); pos != NULL; nTabIdx++)
{
CBCGPRestoredTabInfo tabInfo = m_lstRestoredTabInfo.GetNext (pos);
CBCGPTabInfo* pCurrTabInfo = NULL;
int nCurIdx = FindTabInfo (tabInfo.m_nControlBarID, &pCurrTabInfo);
if (pCurrTabInfo == NULL)
{
continue;
}
pCurrTabInfo->m_strText = tabInfo.m_strText;
pCurrTabInfo->m_bVisible = tabInfo.m_bVisible;
pCurrTabInfo->m_clrText = tabInfo.m_clrText;
pCurrTabInfo->m_clrBack = tabInfo.m_clrBack;
pCurrTabInfo->m_bIsDetachable = tabInfo.m_bDetachable;
if (bUseTabIndexes && nCurIdx != nTabIdx)
{
SwapTabs (nCurIdx, nTabIdx);
if (pCurrTabInfo->m_pWnd != NULL && nTabIdx == m_nRestoredActiveTabID)
{
pCurrTabInfo->m_pWnd->ShowWindow (SW_SHOW);
}
}
}
if (!SetActiveTab (m_nRestoredActiveTabID))
{
SetActiveTab (0);
}
RecalcLayout ();
}
//*************************************************************************************
void CBCGPBaseTabWnd::Serialize (CArchive& ar)
{
int nTabCount = 0;
if (ar.IsLoading ())
{
m_lstRestoredTabInfo.RemoveAll ();
ar >> nTabCount;
for (int i = 0; i < nTabCount; i++)
{
CBCGPRestoredTabInfo tabInfo;
ar >> tabInfo.m_strText;
ar >> tabInfo.m_bVisible;
ar >> tabInfo.m_nControlBarID;
ar >> tabInfo.m_bDetachable;
ar >> tabInfo.m_clrText;
ar >> tabInfo.m_clrBack;
m_lstRestoredTabInfo.AddTail (tabInfo);
}
ar >> m_nRestoredActiveTabID;
int nLoc = 0;
ar >> nLoc;
m_locationRestored = (Location) nLoc;
}
else
{
nTabCount = m_arTabs.GetSize ();
ar << nTabCount;
for (int i = 0; i < nTabCount; i++)
{
CBCGPTabInfo* pTabInfo = (CBCGPTabInfo*) m_arTabs.GetAt (i);
ASSERT_VALID (pTabInfo);
ar << pTabInfo->m_strText;
ar << pTabInfo->m_bVisible;
ASSERT_VALID (pTabInfo->m_pWnd);
ar << pTabInfo->m_pWnd->GetDlgCtrlID ();
ar << pTabInfo->m_bIsDetachable;
ar << pTabInfo->m_clrText;
ar << pTabInfo->m_clrBack;
}
ar << m_iActiveTab;
ar << m_location;
}
}
//***************************************************************************************
void CBCGPBaseTabWnd::SwapTabs (int nFisrtTabID, int nSecondTabID)
{
CBCGPTabInfo* pTabInfoFirst = (CBCGPTabInfo*) m_arTabs.GetAt (nFisrtTabID);
CBCGPTabInfo* pTabInfoSecond = (CBCGPTabInfo*) m_arTabs.GetAt (nSecondTabID);
m_arTabs.SetAt (nFisrtTabID, pTabInfoSecond);
m_arTabs.SetAt (nSecondTabID, pTabInfoFirst);
}
//***************************************************************************************
void CBCGPBaseTabWnd::MoveTab(int nSource, int nDest) // by Walter Meerschaert
{
CBCGPTabInfo* pSource = (CBCGPTabInfo*) m_arTabs [nSource];
CBCGPTabInfo* pActive = (CBCGPTabInfo*) m_arTabs [m_iActiveTab];
ASSERT (nDest < m_arTabs.GetSize ());
if (nDest == -1)
{
m_arTabs.Add (pSource);
m_arTabs.RemoveAt (nSource);
}
else
{
m_arTabs.RemoveAt (nSource);
m_arTabs.InsertAt (nDest, pSource);
}
for (int iTab = 0; iTab < m_arTabs.GetSize(); iTab++)
{
if (pActive == (CBCGPTabInfo*) m_arTabs [iTab])
{
if (iTab != m_iActiveTab)
{
SetActiveTab (iTab);
GetParent ()->SendMessage (BCGM_CHANGE_ACTIVE_TAB, m_iActiveTab);
}
break;
}
}
RecalcLayout ();
}
//***************************************************************************************
CWnd* CBCGPBaseTabWnd::CreateWrapper (CWnd* pWndToWrap, LPCTSTR lpszTabLabel, BOOL bDetachable)
{
ASSERT_VALID (pWndToWrap);
if (pWndToWrap->IsKindOf (RUNTIME_CLASS (CBCGPDockingControlBar)) ||
!bDetachable || !m_bEnableWrapping)
{
return pWndToWrap;
}
CBCGPDockingCBWrapper* pWrapper = NULL;
if (m_pDockingBarWrapperRTC != NULL)
{
pWrapper = DYNAMIC_DOWNCAST (CBCGPDockingCBWrapper,
m_pDockingBarWrapperRTC->CreateObject ());
}
else
{
pWrapper = new CBCGPDockingCBWrapper;
}
ASSERT_VALID (pWrapper);
CRect rectInit (pWrapper->m_rectInitial);
// create will alter the runtime class, but here we have to save it
// and set back after create
CRuntimeClass* pSaveRTC = pWrapper->GetTabbedControlBarRTC ();
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
if (pWndToWrap->IsKindOf (RUNTIME_CLASS (CBCGPBaseControlBar)))
{
dwStyle |= ((CBCGPBaseControlBar*) pWndToWrap)->GetBarStyle ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -